#1386: remove setting of global seed + running pre-commit checks
This commit is contained in:
@@ -248,7 +248,6 @@ class AgentSessionABC(ABC):
|
|||||||
|
|
||||||
agent.session_path = path
|
agent.session_path = path
|
||||||
|
|
||||||
|
|
||||||
return agent
|
return agent
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ class SB3Agent(AgentSessionABC):
|
|||||||
verbose=self.sb3_output_verbose_level,
|
verbose=self.sb3_output_verbose_level,
|
||||||
n_steps=self._training_config.num_steps,
|
n_steps=self._training_config.num_steps,
|
||||||
tensorboard_log=str(self._tensorboard_log_path),
|
tensorboard_log=str(self._tensorboard_log_path),
|
||||||
seed=self._training_config.seed
|
seed=self._training_config.seed,
|
||||||
)
|
)
|
||||||
|
|
||||||
def _save_checkpoint(self):
|
def _save_checkpoint(self):
|
||||||
@@ -121,10 +121,7 @@ class SB3Agent(AgentSessionABC):
|
|||||||
obs = self._env.reset()
|
obs = self._env.reset()
|
||||||
|
|
||||||
for step in range(time_steps):
|
for step in range(time_steps):
|
||||||
action, _states = self._agent.predict(
|
action, _states = self._agent.predict(obs, deterministic=self._training_config.deterministic)
|
||||||
obs,
|
|
||||||
deterministic=self._training_config.deterministic
|
|
||||||
)
|
|
||||||
if isinstance(action, np.ndarray):
|
if isinstance(action, np.ndarray):
|
||||||
action = np.int64(action)
|
action = np.int64(action)
|
||||||
obs, rewards, done, info = self._env.step(action)
|
obs, rewards, done, info = self._env.step(action)
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
"""Main environment module containing the PRIMmary AI Training Evironment (Primaite) class."""
|
"""Main environment module containing the PRIMmary AI Training Evironment (Primaite) class."""
|
||||||
import copy
|
import copy
|
||||||
import logging
|
import logging
|
||||||
import random
|
|
||||||
import uuid as uuid
|
import uuid as uuid
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from random import choice, randint, sample, uniform
|
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.episode_av_reward_writer = SessionOutputWriter(self, transaction_writer=False, learning_session=True)
|
||||||
self.transaction_writer = SessionOutputWriter(self, transaction_writer=True, 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
|
@property
|
||||||
def actual_episode_count(self) -> int:
|
def actual_episode_count(self) -> int:
|
||||||
"""Shifts the episode_count by -1 for RLlib."""
|
"""Shifts the episode_count by -1 for RLlib."""
|
||||||
|
|||||||
@@ -6,15 +6,11 @@ from tests import TEST_CONFIG_ROOT
|
|||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"temp_primaite_session",
|
"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,
|
indirect=True,
|
||||||
)
|
)
|
||||||
def test_seeded_learning(temp_primaite_session):
|
def test_seeded_learning(temp_primaite_session):
|
||||||
"""Test running seeded learning produces the same output when ran twice."""
|
"""Test running seeded learning produces the same output when ran twice."""
|
||||||
|
|
||||||
expected_mean_reward_per_episode = {
|
expected_mean_reward_per_episode = {
|
||||||
1: -90.703125,
|
1: -90.703125,
|
||||||
2: -91.15234375,
|
2: -91.15234375,
|
||||||
@@ -25,26 +21,22 @@ def test_seeded_learning(temp_primaite_session):
|
|||||||
7: -88.984375,
|
7: -88.984375,
|
||||||
8: -88.3203125,
|
8: -88.3203125,
|
||||||
9: -112.79296875,
|
9: -112.79296875,
|
||||||
10: -100.01953125
|
10: -100.01953125,
|
||||||
}
|
}
|
||||||
with temp_primaite_session as session:
|
with temp_primaite_session as session:
|
||||||
assert session._training_config.seed == 67890, \
|
assert session._training_config.seed == 67890, (
|
||||||
"Expected output is based upon a agent that was trained with " \
|
"Expected output is based upon a agent that was trained with " "seed 67890"
|
||||||
"seed 67890"
|
)
|
||||||
session.learn()
|
session.learn()
|
||||||
actual_mean_reward_per_episode = session.learn_av_reward_per_episode()
|
actual_mean_reward_per_episode = session.learn_av_reward_per_episode()
|
||||||
|
|
||||||
assert actual_mean_reward_per_episode == expected_mean_reward_per_episode
|
assert actual_mean_reward_per_episode == expected_mean_reward_per_episode
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.skip(reason="Inconsistent results. Needs someone with RL "
|
@pytest.mark.skip(reason="Inconsistent results. Needs someone with RL " "knowledge to investigate further.")
|
||||||
"knowledge to investigate further.")
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"temp_primaite_session",
|
"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,
|
indirect=True,
|
||||||
)
|
)
|
||||||
def test_deterministic_evaluation(temp_primaite_session):
|
def test_deterministic_evaluation(temp_primaite_session):
|
||||||
|
|||||||
Reference in New Issue
Block a user