#1386: remove setting of global seed + running pre-commit checks

This commit is contained in:
Czar Echavez
2023-07-06 12:10:26 +01:00
parent 3438ce7e09
commit 99f1f7cfc1
4 changed files with 9 additions and 27 deletions

View File

@@ -248,7 +248,6 @@ class AgentSessionABC(ABC):
agent.session_path = path
return agent
else:

View File

@@ -59,7 +59,7 @@ class SB3Agent(AgentSessionABC):
verbose=self.sb3_output_verbose_level,
n_steps=self._training_config.num_steps,
tensorboard_log=str(self._tensorboard_log_path),
seed=self._training_config.seed
seed=self._training_config.seed,
)
def _save_checkpoint(self):
@@ -121,10 +121,7 @@ class SB3Agent(AgentSessionABC):
obs = self._env.reset()
for step in range(time_steps):
action, _states = self._agent.predict(
obs,
deterministic=self._training_config.deterministic
)
action, _states = self._agent.predict(obs, deterministic=self._training_config.deterministic)
if isinstance(action, np.ndarray):
action = np.int64(action)
obs, rewards, done, info = self._env.step(action)

View File

@@ -2,7 +2,6 @@
"""Main environment module containing the PRIMmary AI Training Evironment (Primaite) class."""
import copy
import logging
import random
import uuid as uuid
from pathlib import Path
from random import choice, randint, sample, uniform
@@ -241,11 +240,6 @@ class Primaite(Env):
self.episode_av_reward_writer = SessionOutputWriter(self, transaction_writer=False, learning_session=True)
self.transaction_writer = SessionOutputWriter(self, transaction_writer=True, learning_session=True)
# set the seed globally if there is one
if self.training_config.seed:
random.seed(self.training_config.seed)
np.random.seed(self.training_config.seed)
@property
def actual_episode_count(self) -> int:
"""Shifts the episode_count by -1 for RLlib."""

View File

@@ -6,15 +6,11 @@ from tests import TEST_CONFIG_ROOT
@pytest.mark.parametrize(
"temp_primaite_session",
[[
TEST_CONFIG_ROOT / "ppo_seeded_training_config.yaml",
dos_very_basic_config_path()
]],
[[TEST_CONFIG_ROOT / "ppo_seeded_training_config.yaml", dos_very_basic_config_path()]],
indirect=True,
)
def test_seeded_learning(temp_primaite_session):
"""Test running seeded learning produces the same output when ran twice."""
expected_mean_reward_per_episode = {
1: -90.703125,
2: -91.15234375,
@@ -25,26 +21,22 @@ def test_seeded_learning(temp_primaite_session):
7: -88.984375,
8: -88.3203125,
9: -112.79296875,
10: -100.01953125
10: -100.01953125,
}
with temp_primaite_session as session:
assert session._training_config.seed == 67890, \
"Expected output is based upon a agent that was trained with " \
"seed 67890"
assert session._training_config.seed == 67890, (
"Expected output is based upon a agent that was trained with " "seed 67890"
)
session.learn()
actual_mean_reward_per_episode = session.learn_av_reward_per_episode()
assert actual_mean_reward_per_episode == expected_mean_reward_per_episode
@pytest.mark.skip(reason="Inconsistent results. Needs someone with RL "
"knowledge to investigate further.")
@pytest.mark.skip(reason="Inconsistent results. Needs someone with RL " "knowledge to investigate further.")
@pytest.mark.parametrize(
"temp_primaite_session",
[[
TEST_CONFIG_ROOT / "ppo_seeded_training_config.yaml",
dos_very_basic_config_path()
]],
[[TEST_CONFIG_ROOT / "ppo_seeded_training_config.yaml", dos_very_basic_config_path()]],
indirect=True,
)
def test_deterministic_evaluation(temp_primaite_session):