#1566 - Refactored the test_train_eval_episode_steps.py to sue TempPrimaiteSession.

- Fixed all errors that were caused b fixing the above.
- Some tests still fail, these are for SS to fix.
- Dropped the old run_generic stuff from conftest.py
This commit is contained in:
Chris McCarthy
2023-07-07 15:50:14 +01:00
parent d49f73f139
commit 40381833d3
15 changed files with 69 additions and 279 deletions

View File

@@ -3,7 +3,6 @@ import pytest
from primaite import getLogger
from primaite.config.lay_down_config import dos_very_basic_config_path
from tests import TEST_CONFIG_ROOT
from tests.conftest import run_generic
_LOGGER = getLogger(__name__)
@@ -14,33 +13,30 @@ _LOGGER = getLogger(__name__)
indirect=True,
)
def test_eval_steps_differ_from_training(temp_primaite_session):
"""Uses PrimaiteSession class to compare number of episodes used for training and evaluation."""
with temp_primaite_session as train_session:
env = train_session.env
train_session.learn()
"""Uses PrimaiteSession class to compare number of episodes used for training and evaluation.
"""
Train_episode_step.yaml main config:
num_train_steps = 1
num_eval_steps = 10
When the YAML file changes from TRAIN to EVAL the episode step changes and uses the other config value.
The test is showing that 10 steps are running for evaluation and NOT 1 step as EVAL has been selected in the config.
num_train_steps = 25
num_train_episodes = 3
num_eval_steps = 17
num_eval_episodes = 1
"""
assert env.episode_steps == 10 # 30
# assert env.actual_episode_count == 10 # should be 10
expected_learning_metadata = {"total_episodes": 3, "total_time_steps": 75}
expected_evaluation_metadata = {"total_episodes": 1, "total_time_steps": 17}
with temp_primaite_session as session:
# Run learning and check episode and step counts
session.learn()
assert session.env.actual_episode_count == expected_learning_metadata["total_episodes"]
assert session.env.total_step_count == expected_learning_metadata["total_time_steps"]
@pytest.mark.parametrize(
"temp_primaite_session",
[[TEST_CONFIG_ROOT / "train_episode_step.yaml", dos_very_basic_config_path()]],
indirect=True,
)
def test_train_eval_config_option(temp_primaite_session):
"""Uses PrimaiteSession class to test number of episodes and steps used for TRAIN and EVAL option."""
with temp_primaite_session as train_session:
env = train_session.env
run_generic(env, env.training_config)
# Run evaluation and check episode and step counts
session.evaluate()
assert session.env.actual_episode_count == expected_evaluation_metadata["total_episodes"]
assert session.env.total_step_count == expected_evaluation_metadata["total_time_steps"]
print(env.actual_episode_count, env.step_count, env.total_step_count)
# Load the session_metadata.json file and check that the both the
# learning and evaluation match what is expected above
metadata = session.metadata_file_as_dict()
assert metadata["learning"] == expected_learning_metadata
assert metadata["evaluation"] == expected_evaluation_metadata