1
0
mirror of https://github.com/gryf/coach.git synced 2025-12-30 02:12:29 +01:00

introduce graph_manager.phase_context; make sure that calls to graph_manager.train automatically set training phase

This commit is contained in:
Zach Dwiel
2018-10-02 16:19:49 -04:00
committed by zach dwiel
parent 7382a142bb
commit 517aac163a
3 changed files with 94 additions and 46 deletions

View File

@@ -0,0 +1,47 @@
import os
import sys
sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(__file__))))
import pytest
from rl_coach.graph_managers.graph_manager import GraphManager, ScheduleParameters
from rl_coach.base_parameters import VisualizationParameters
from rl_coach.core_types import RunPhase
@pytest.mark.unit_test
def test_phase_context():
graph_manager = GraphManager(name='', schedule_params=ScheduleParameters(), vis_params=VisualizationParameters())
assert graph_manager.phase == RunPhase.UNDEFINED
with graph_manager.phase_context(RunPhase.TRAIN):
assert graph_manager.phase == RunPhase.TRAIN
assert graph_manager.phase == RunPhase.UNDEFINED
@pytest.mark.unit_test
def test_phase_context_nested():
graph_manager = GraphManager(name='', schedule_params=ScheduleParameters(), vis_params=VisualizationParameters())
assert graph_manager.phase == RunPhase.UNDEFINED
with graph_manager.phase_context(RunPhase.TRAIN):
assert graph_manager.phase == RunPhase.TRAIN
with graph_manager.phase_context(RunPhase.TEST):
assert graph_manager.phase == RunPhase.TEST
assert graph_manager.phase == RunPhase.TRAIN
assert graph_manager.phase == RunPhase.UNDEFINED
@pytest.mark.unit_test
def test_phase_context_double_nested():
graph_manager = GraphManager(name='', schedule_params=ScheduleParameters(), vis_params=VisualizationParameters())
assert graph_manager.phase == RunPhase.UNDEFINED
with graph_manager.phase_context(RunPhase.TRAIN):
assert graph_manager.phase == RunPhase.TRAIN
with graph_manager.phase_context(RunPhase.TEST):
assert graph_manager.phase == RunPhase.TEST
with graph_manager.phase_context(RunPhase.UNDEFINED):
assert graph_manager.phase == RunPhase.UNDEFINED
assert graph_manager.phase == RunPhase.TEST
assert graph_manager.phase == RunPhase.TRAIN
assert graph_manager.phase == RunPhase.UNDEFINED