From 3441dd25092aff65c7c9f5e9e0d11855f7bad8d7 Mon Sep 17 00:00:00 2001 From: Nick Todd Date: Mon, 5 Aug 2024 17:45:01 +0100 Subject: [PATCH] #2777: Code review changes. --- CHANGELOG.md | 4 ++-- .../game/agent/scripted_agents/probabilistic_agent.py | 2 +- src/primaite/session/environment.py | 7 +++---- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c52f4678..8b3cfbb6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] - +### Added +- Random Number Generator Seeding by specifying a random number seed in the config file. ### Changed - Removed the install/uninstall methods in the node class and made the software manager install/uninstall handle all of their functionality. @@ -22,7 +23,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Tests to verify that airspace bandwidth is applied correctly and can be configured via YAML - Agent logging for agents' internal decision logic - Action masking in all PrimAITE environments -- Random Number Generator Seeding by specifying a random number seed in the config file. ### Changed - Application registry was moved to the `Application` class and now updates automatically when Application is subclassed - Databases can no longer respond to request while performing a backup diff --git a/src/primaite/game/agent/scripted_agents/probabilistic_agent.py b/src/primaite/game/agent/scripted_agents/probabilistic_agent.py index ab2e69ef..cd44644f 100644 --- a/src/primaite/game/agent/scripted_agents/probabilistic_agent.py +++ b/src/primaite/game/agent/scripted_agents/probabilistic_agent.py @@ -68,7 +68,7 @@ class ProbabilisticAgent(AbstractScriptedAgent): self.probabilities = np.asarray(list(self.settings.action_probabilities.values())) super().__init__(agent_name, action_space, observation_space, reward_function) - self.logger.info(f"ProbabilisticAgent RNG seed: {rng_seed}") + self.logger.debug(f"ProbabilisticAgent RNG seed: {rng_seed}") def get_action(self, obs: ObsType, timestep: int = 0) -> Tuple[str, Dict]: """ diff --git a/src/primaite/session/environment.py b/src/primaite/session/environment.py index a12d2eb7..c66663e3 100644 --- a/src/primaite/session/environment.py +++ b/src/primaite/session/environment.py @@ -44,9 +44,8 @@ def set_random_seed(seed: int) -> Union[None, int]: # if torch not installed don't set random seed. if sys.modules["torch"]: th.manual_seed(seed) - - th.backends.cudnn.deterministic = True - th.backends.cudnn.benchmark = False + th.backends.cudnn.deterministic = True + th.backends.cudnn.benchmark = False return seed @@ -64,7 +63,7 @@ class PrimaiteGymEnv(gymnasium.Env): super().__init__() self.episode_scheduler: EpisodeScheduler = build_scheduler(env_config) """Object that returns a config corresponding to the current episode.""" - self.seed = self.episode_scheduler(0).get("game").get("seed") + self.seed = self.episode_scheduler(0).get("game", {}).get("seed") """Get RNG seed from config file. NB: Must be before game instantiation.""" self.seed = set_random_seed(self.seed) self.io = PrimaiteIO.from_config(self.episode_scheduler(0).get("io_settings", {}))