1566 - added test file and edited configs to include types of num steps and modifed agents to use correct step and episode counts
This commit is contained in:
@@ -348,8 +348,8 @@ class HardCodedAgentSessionABC(AgentSessionABC):
|
|||||||
self._env.set_as_eval() # noqa
|
self._env.set_as_eval() # noqa
|
||||||
self.is_eval = True
|
self.is_eval = True
|
||||||
|
|
||||||
time_steps = self._training_config.num_steps
|
time_steps = self._training_config.num_eval_steps
|
||||||
episodes = self._training_config.num_episodes
|
episodes = self._training_config.num_eval_episodes
|
||||||
|
|
||||||
obs = self._env.reset()
|
obs = self._env.reset()
|
||||||
for episode in range(episodes):
|
for episode in range(episodes):
|
||||||
|
|||||||
@@ -107,13 +107,13 @@ class RLlibAgent(AgentSessionABC):
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
self._agent_config.training(train_batch_size=self._training_config.num_steps)
|
self._agent_config.training(train_batch_size=self._training_config.num_train_steps)
|
||||||
self._agent_config.framework(framework="tf")
|
self._agent_config.framework(framework="tf")
|
||||||
|
|
||||||
self._agent_config.rollouts(
|
self._agent_config.rollouts(
|
||||||
num_rollout_workers=1,
|
num_rollout_workers=1,
|
||||||
num_envs_per_worker=1,
|
num_envs_per_worker=1,
|
||||||
horizon=self._training_config.num_steps,
|
horizon=self._training_config.num_train_steps,
|
||||||
)
|
)
|
||||||
self._agent: Algorithm = self._agent_config.build(logger_creator=_custom_log_creator(self.learning_path))
|
self._agent: Algorithm = self._agent_config.build(logger_creator=_custom_log_creator(self.learning_path))
|
||||||
|
|
||||||
@@ -121,7 +121,7 @@ class RLlibAgent(AgentSessionABC):
|
|||||||
checkpoint_n = self._training_config.checkpoint_every_n_episodes
|
checkpoint_n = self._training_config.checkpoint_every_n_episodes
|
||||||
episode_count = self._current_result["episodes_total"]
|
episode_count = self._current_result["episodes_total"]
|
||||||
if checkpoint_n > 0 and episode_count > 0:
|
if checkpoint_n > 0 and episode_count > 0:
|
||||||
if (episode_count % checkpoint_n == 0) or (episode_count == self._training_config.num_episodes):
|
if (episode_count % checkpoint_n == 0) or (episode_count == self._training_config.num_train_episodes):
|
||||||
self._agent.save(str(self.checkpoints_path))
|
self._agent.save(str(self.checkpoints_path))
|
||||||
|
|
||||||
def learn(
|
def learn(
|
||||||
@@ -133,8 +133,8 @@ class RLlibAgent(AgentSessionABC):
|
|||||||
|
|
||||||
:param kwargs: Any agent-specific key-word args to be passed.
|
:param kwargs: Any agent-specific key-word args to be passed.
|
||||||
"""
|
"""
|
||||||
time_steps = self._training_config.num_steps
|
time_steps = self._training_config.num_train_steps
|
||||||
episodes = self._training_config.num_episodes
|
episodes = self._training_config.num_train_episodes
|
||||||
|
|
||||||
_LOGGER.info(f"Beginning learning for {episodes} episodes @" f" {time_steps} time steps...")
|
_LOGGER.info(f"Beginning learning for {episodes} episodes @" f" {time_steps} time steps...")
|
||||||
for i in range(episodes):
|
for i in range(episodes):
|
||||||
|
|||||||
@@ -53,11 +53,12 @@ class SB3Agent(AgentSessionABC):
|
|||||||
session_path=self.session_path,
|
session_path=self.session_path,
|
||||||
timestamp_str=self.timestamp_str,
|
timestamp_str=self.timestamp_str,
|
||||||
)
|
)
|
||||||
|
|
||||||
self._agent = self._agent_class(
|
self._agent = self._agent_class(
|
||||||
PPOMlp,
|
PPOMlp,
|
||||||
self._env,
|
self._env,
|
||||||
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_eval_steps,
|
||||||
tensorboard_log=str(self._tensorboard_log_path),
|
tensorboard_log=str(self._tensorboard_log_path),
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -82,8 +83,8 @@ class SB3Agent(AgentSessionABC):
|
|||||||
|
|
||||||
:param kwargs: Any agent-specific key-word args to be passed.
|
:param kwargs: Any agent-specific key-word args to be passed.
|
||||||
"""
|
"""
|
||||||
time_steps = self._training_config.num_steps
|
time_steps = self._training_config.num_train_steps
|
||||||
episodes = self._training_config.num_episodes
|
episodes = self._training_config.num_train_episodes
|
||||||
self.is_eval = False
|
self.is_eval = False
|
||||||
_LOGGER.info(f"Beginning learning for {episodes} episodes @" f" {time_steps} time steps...")
|
_LOGGER.info(f"Beginning learning for {episodes} episodes @" f" {time_steps} time steps...")
|
||||||
for i in range(episodes):
|
for i in range(episodes):
|
||||||
@@ -104,8 +105,8 @@ class SB3Agent(AgentSessionABC):
|
|||||||
:param deterministic: Whether the evaluation is deterministic.
|
:param deterministic: Whether the evaluation is deterministic.
|
||||||
:param kwargs: Any agent-specific key-word args to be passed.
|
:param kwargs: Any agent-specific key-word args to be passed.
|
||||||
"""
|
"""
|
||||||
time_steps = self._training_config.num_steps
|
time_steps = self._training_config.num_eval_steps
|
||||||
episodes = self._training_config.num_episodes
|
episodes = self._training_config.num_eval_episodes
|
||||||
self._env.set_as_eval()
|
self._env.set_as_eval()
|
||||||
self.is_eval = True
|
self.is_eval = True
|
||||||
if deterministic:
|
if deterministic:
|
||||||
|
|||||||
@@ -60,11 +60,17 @@ class TrainingConfig:
|
|||||||
action_type: ActionType = ActionType.ANY
|
action_type: ActionType = ActionType.ANY
|
||||||
"The ActionType to use"
|
"The ActionType to use"
|
||||||
|
|
||||||
num_episodes: int = 10
|
num_train_episodes: int = 10
|
||||||
"The number of episodes to train over"
|
"The number of episodes to train over during an training session"
|
||||||
|
|
||||||
num_steps: int = 256
|
num_train_steps: int = 256
|
||||||
"The number of steps in an episode"
|
"The number of steps in an episode during an training session"
|
||||||
|
|
||||||
|
num_eval_episodes: int = 10
|
||||||
|
"The number of episodes to train over during an evaluation session"
|
||||||
|
|
||||||
|
num_eval_steps: int = 256
|
||||||
|
"The number of steps in an episode during an evaluation session"
|
||||||
|
|
||||||
checkpoint_every_n_episodes: int = 5
|
checkpoint_every_n_episodes: int = 5
|
||||||
"The agent will save a checkpoint every n episodes"
|
"The agent will save a checkpoint every n episodes"
|
||||||
@@ -230,8 +236,17 @@ class TrainingConfig:
|
|||||||
tc += f"{self.hard_coded_agent_view}, "
|
tc += f"{self.hard_coded_agent_view}, "
|
||||||
tc += f"{self.action_type}, "
|
tc += f"{self.action_type}, "
|
||||||
tc += f"observation_space={self.observation_space}, "
|
tc += f"observation_space={self.observation_space}, "
|
||||||
tc += f"{self.num_episodes} episodes @ "
|
if self.session_type.name == "TRAIN":
|
||||||
tc += f"{self.num_steps} steps"
|
tc += f"{self.num_train_episodes} episodes @ "
|
||||||
|
tc += f"{self.num_train_steps} steps"
|
||||||
|
elif self.session_type.name == "EVAL":
|
||||||
|
tc += f"{self.num_eval_episodes} episodes @ "
|
||||||
|
tc += f"{self.num_eval_steps} steps"
|
||||||
|
else:
|
||||||
|
tc += f"Training: {self.num_eval_episodes} episodes @ "
|
||||||
|
tc += f"{self.num_eval_steps} steps"
|
||||||
|
tc += f"Evaluation: {self.num_eval_episodes} episodes @ "
|
||||||
|
tc += f"{self.num_eval_steps} steps"
|
||||||
return tc
|
return tc
|
||||||
|
|
||||||
|
|
||||||
@@ -320,7 +335,8 @@ def _get_new_key_from_legacy(legacy_key: str) -> str:
|
|||||||
"""
|
"""
|
||||||
key_mapping = {
|
key_mapping = {
|
||||||
"agentIdentifier": None,
|
"agentIdentifier": None,
|
||||||
"numEpisodes": "num_episodes",
|
"numEpisodes": "num_train_episodes",
|
||||||
|
"numSteps": "num_train_steps",
|
||||||
"timeDelay": "time_delay",
|
"timeDelay": "time_delay",
|
||||||
"configFilename": None,
|
"configFilename": None,
|
||||||
"sessionType": "session_type",
|
"sessionType": "session_type",
|
||||||
|
|||||||
@@ -85,7 +85,12 @@ class Primaite(Env):
|
|||||||
_LOGGER.info(f"Using: {str(self.training_config)}")
|
_LOGGER.info(f"Using: {str(self.training_config)}")
|
||||||
|
|
||||||
# Number of steps in an episode
|
# Number of steps in an episode
|
||||||
self.episode_steps = self.training_config.num_steps
|
if self.training_config.session_type == SessionType.TRAIN:
|
||||||
|
self.episode_steps = self.training_config.num_train_steps
|
||||||
|
elif self.training_config.session_type == SessionType.EVAL:
|
||||||
|
self.episode_steps = self.training_config.num_eval_steps
|
||||||
|
else:
|
||||||
|
self.episode_steps = self.training_config.num_train_steps
|
||||||
|
|
||||||
super(Primaite, self).__init__()
|
super(Primaite, self).__init__()
|
||||||
|
|
||||||
@@ -254,6 +259,7 @@ class Primaite(Env):
|
|||||||
self.episode_count = 0
|
self.episode_count = 0
|
||||||
self.step_count = 0
|
self.step_count = 0
|
||||||
self.total_step_count = 0
|
self.total_step_count = 0
|
||||||
|
self.episode_steps = self.training_config.num_eval_steps
|
||||||
|
|
||||||
def reset(self):
|
def reset(self):
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -20,10 +20,17 @@ agent_identifier: PPO
|
|||||||
# "ACL"
|
# "ACL"
|
||||||
# "ANY" node and acl actions
|
# "ANY" node and acl actions
|
||||||
action_type: ANY
|
action_type: ANY
|
||||||
# Number of episodes to run per session
|
# Number of episodes for training to run per session
|
||||||
num_episodes: 10
|
num_train_episodes: 10
|
||||||
# Number of time_steps per episode
|
|
||||||
num_steps: 256
|
# Number of time_steps for training per episode
|
||||||
|
num_train_steps: 256
|
||||||
|
|
||||||
|
# Number of episodes for evaluation to run per session
|
||||||
|
num_eval_episodes: 10
|
||||||
|
|
||||||
|
# Number of time_steps for evaluation per episode
|
||||||
|
num_eval_steps: 256
|
||||||
# Time delay between steps (for generic agents)
|
# Time delay between steps (for generic agents)
|
||||||
time_delay: 10
|
time_delay: 10
|
||||||
# Type of session to be run (TRAINING or EVALUATION)
|
# Type of session to be run (TRAINING or EVALUATION)
|
||||||
|
|||||||
@@ -22,10 +22,17 @@ agent_identifier: A2C
|
|||||||
# "ACL"
|
# "ACL"
|
||||||
# "ANY" node and acl actions
|
# "ANY" node and acl actions
|
||||||
action_type: ANY
|
action_type: ANY
|
||||||
# Number of episodes to run per session
|
# Number of episodes for training to run per session
|
||||||
num_episodes: 1
|
num_train_episodes: 10
|
||||||
# Number of time_steps per episode
|
|
||||||
num_steps: 5
|
# Number of time_steps for training per episode
|
||||||
|
num_train_steps: 256
|
||||||
|
|
||||||
|
# Number of episodes for evaluation to run per session
|
||||||
|
num_eval_episodes: 10
|
||||||
|
|
||||||
|
# Number of time_steps for evaluation per episode
|
||||||
|
num_eval_steps: 256
|
||||||
|
|
||||||
|
|
||||||
observation_space:
|
observation_space:
|
||||||
|
|||||||
@@ -22,10 +22,17 @@ agent_identifier: RANDOM
|
|||||||
# "ACL"
|
# "ACL"
|
||||||
# "ANY" node and acl actions
|
# "ANY" node and acl actions
|
||||||
action_type: ANY
|
action_type: ANY
|
||||||
# Number of episodes to run per session
|
# Number of episodes for training to run per session
|
||||||
num_episodes: 1
|
num_train_episodes: 10
|
||||||
# Number of time_steps per episode
|
|
||||||
num_steps: 5
|
# Number of time_steps for training per episode
|
||||||
|
num_train_steps: 256
|
||||||
|
|
||||||
|
# Number of episodes for evaluation to run per session
|
||||||
|
num_eval_episodes: 10
|
||||||
|
|
||||||
|
# Number of time_steps for evaluation per episode
|
||||||
|
num_eval_steps: 256
|
||||||
|
|
||||||
observation_space:
|
observation_space:
|
||||||
components:
|
components:
|
||||||
|
|||||||
@@ -22,10 +22,17 @@ agent_identifier: RANDOM
|
|||||||
# "ACL"
|
# "ACL"
|
||||||
# "ANY" node and acl actions
|
# "ANY" node and acl actions
|
||||||
action_type: ANY
|
action_type: ANY
|
||||||
# Number of episodes to run per session
|
# Number of episodes for training to run per session
|
||||||
num_episodes: 1
|
num_train_episodes: 10
|
||||||
# Number of time_steps per episode
|
|
||||||
num_steps: 5
|
# Number of time_steps for training per episode
|
||||||
|
num_train_steps: 256
|
||||||
|
|
||||||
|
# Number of episodes for evaluation to run per session
|
||||||
|
num_eval_episodes: 10
|
||||||
|
|
||||||
|
# Number of time_steps for evaluation per episode
|
||||||
|
num_eval_steps: 256
|
||||||
|
|
||||||
observation_space:
|
observation_space:
|
||||||
components:
|
components:
|
||||||
|
|||||||
@@ -22,10 +22,17 @@ agent_identifier: RANDOM
|
|||||||
# "ACL"
|
# "ACL"
|
||||||
# "ANY" node and acl actions
|
# "ANY" node and acl actions
|
||||||
action_type: ANY
|
action_type: ANY
|
||||||
# Number of episodes to run per session
|
# Number of episodes for training to run per session
|
||||||
num_episodes: 1
|
num_train_episodes: 10
|
||||||
# Number of time_steps per episode
|
|
||||||
num_steps: 5
|
# Number of time_steps for training per episode
|
||||||
|
num_train_steps: 256
|
||||||
|
|
||||||
|
# Number of episodes for evaluation to run per session
|
||||||
|
num_eval_episodes: 10
|
||||||
|
|
||||||
|
# Number of time_steps for evaluation per episode
|
||||||
|
num_eval_steps: 256
|
||||||
# Time delay between steps (for generic agents)
|
# Time delay between steps (for generic agents)
|
||||||
time_delay: 1
|
time_delay: 1
|
||||||
# Type of session to be run (TRAINING or EVALUATION)
|
# Type of session to be run (TRAINING or EVALUATION)
|
||||||
|
|||||||
@@ -22,10 +22,17 @@ agent_identifier: DUMMY
|
|||||||
# "ACL"
|
# "ACL"
|
||||||
# "ANY" node and acl actions
|
# "ANY" node and acl actions
|
||||||
action_type: NODE
|
action_type: NODE
|
||||||
# Number of episodes to run per session
|
# Number of episodes for training to run per session
|
||||||
num_episodes: 1
|
num_train_episodes: 10
|
||||||
# Number of time_steps per episode
|
|
||||||
num_steps: 15
|
# Number of time_steps for training per episode
|
||||||
|
num_train_steps: 256
|
||||||
|
|
||||||
|
# Number of episodes for evaluation to run per session
|
||||||
|
num_eval_episodes: 10
|
||||||
|
|
||||||
|
# Number of time_steps for evaluation per episode
|
||||||
|
num_eval_steps: 256
|
||||||
# Time delay between steps (for generic agents)
|
# Time delay between steps (for generic agents)
|
||||||
time_delay: 1
|
time_delay: 1
|
||||||
|
|
||||||
|
|||||||
@@ -22,10 +22,17 @@ agent_identifier: RANDOM
|
|||||||
# "ACL"
|
# "ACL"
|
||||||
# "ANY" node and acl actions
|
# "ANY" node and acl actions
|
||||||
action_type: ANY
|
action_type: ANY
|
||||||
# Number of episodes to run per session
|
# Number of episodes for training to run per session
|
||||||
num_episodes: 1
|
num_train_episodes: 10
|
||||||
# Number of time_steps per episode
|
|
||||||
num_steps: 15
|
# Number of time_steps for training per episode
|
||||||
|
num_train_steps: 256
|
||||||
|
|
||||||
|
# Number of episodes for evaluation to run per session
|
||||||
|
num_eval_episodes: 10
|
||||||
|
|
||||||
|
# Number of time_steps for evaluation per episode
|
||||||
|
num_eval_steps: 256
|
||||||
# Time delay between steps (for generic agents)
|
# Time delay between steps (for generic agents)
|
||||||
time_delay: 1
|
time_delay: 1
|
||||||
# Type of session to be run (TRAINING or EVALUATION)
|
# Type of session to be run (TRAINING or EVALUATION)
|
||||||
|
|||||||
@@ -22,10 +22,17 @@ agent_identifier: RANDOM
|
|||||||
# "ACL"
|
# "ACL"
|
||||||
# "ANY" node and acl actions
|
# "ANY" node and acl actions
|
||||||
action_type: ANY
|
action_type: ANY
|
||||||
# Number of episodes to run per session
|
# Number of episodes for training to run per session
|
||||||
num_episodes: 1
|
num_train_episodes: 10
|
||||||
# Number of time_steps per episode
|
|
||||||
num_steps: 5
|
# Number of time_steps for training per episode
|
||||||
|
num_train_steps: 256
|
||||||
|
|
||||||
|
# Number of episodes for evaluation to run per session
|
||||||
|
num_eval_episodes: 10
|
||||||
|
|
||||||
|
# Number of time_steps for evaluation per episode
|
||||||
|
num_eval_steps: 256
|
||||||
# Time delay between steps (for generic agents)
|
# Time delay between steps (for generic agents)
|
||||||
time_delay: 1
|
time_delay: 1
|
||||||
# Type of session to be run (TRAINING or EVALUATION)
|
# Type of session to be run (TRAINING or EVALUATION)
|
||||||
|
|||||||
@@ -28,10 +28,17 @@ random_red_agent: True
|
|||||||
# "ACL"
|
# "ACL"
|
||||||
# "ANY" node and acl actions
|
# "ANY" node and acl actions
|
||||||
action_type: NODE
|
action_type: NODE
|
||||||
# Number of episodes to run per session
|
# Number of episodes for training to run per session
|
||||||
num_episodes: 2
|
num_train_episodes: 10
|
||||||
# Number of time_steps per episode
|
|
||||||
num_steps: 15
|
# Number of time_steps for training per episode
|
||||||
|
num_train_steps: 256
|
||||||
|
|
||||||
|
# Number of episodes for evaluation to run per session
|
||||||
|
num_eval_episodes: 10
|
||||||
|
|
||||||
|
# Number of time_steps for evaluation per episode
|
||||||
|
num_eval_steps: 256
|
||||||
# Time delay between steps (for generic agents)
|
# Time delay between steps (for generic agents)
|
||||||
time_delay: 1
|
time_delay: 1
|
||||||
|
|
||||||
|
|||||||
153
tests/config/train_episode_step.yaml
Normal file
153
tests/config/train_episode_step.yaml
Normal file
@@ -0,0 +1,153 @@
|
|||||||
|
# Training Config File
|
||||||
|
|
||||||
|
# Sets which agent algorithm framework will be used.
|
||||||
|
# Options are:
|
||||||
|
# "SB3" (Stable Baselines3)
|
||||||
|
# "RLLIB" (Ray RLlib)
|
||||||
|
# "CUSTOM" (Custom Agent)
|
||||||
|
agent_framework: SB3
|
||||||
|
|
||||||
|
# Sets which deep learning framework will be used (by RLlib ONLY).
|
||||||
|
# Default is TF (Tensorflow).
|
||||||
|
# Options are:
|
||||||
|
# "TF" (Tensorflow)
|
||||||
|
# TF2 (Tensorflow 2.X)
|
||||||
|
# TORCH (PyTorch)
|
||||||
|
deep_learning_framework: TF2
|
||||||
|
|
||||||
|
# Sets which Agent class will be used.
|
||||||
|
# Options are:
|
||||||
|
# "A2C" (Advantage Actor Critic coupled with either SB3 or RLLIB agent_framework)
|
||||||
|
# "PPO" (Proximal Policy Optimization coupled with either SB3 or RLLIB agent_framework)
|
||||||
|
# "HARDCODED" (The HardCoded agents coupled with an ACL or NODE action_type)
|
||||||
|
# "DO_NOTHING" (The DoNothing agents coupled with an ACL or NODE action_type)
|
||||||
|
# "RANDOM" (primaite.agents.simple.RandomAgent)
|
||||||
|
# "DUMMY" (primaite.agents.simple.DummyAgent)
|
||||||
|
agent_identifier: PPO
|
||||||
|
|
||||||
|
# Sets whether Red Agent POL and IER is randomised.
|
||||||
|
# Options are:
|
||||||
|
# True
|
||||||
|
# False
|
||||||
|
random_red_agent: False
|
||||||
|
|
||||||
|
# Sets what view of the environment the deterministic hardcoded agent has. The default is BASIC.
|
||||||
|
# Options are:
|
||||||
|
# "BASIC" (The current observation space only)
|
||||||
|
# "FULL" (Full environment view with actions taken and reward feedback)
|
||||||
|
hard_coded_agent_view: FULL
|
||||||
|
|
||||||
|
# Sets How the Action Space is defined:
|
||||||
|
# "NODE"
|
||||||
|
# "ACL"
|
||||||
|
# "ANY" node and acl actions
|
||||||
|
action_type: NODE
|
||||||
|
# observation space
|
||||||
|
observation_space:
|
||||||
|
# flatten: true
|
||||||
|
components:
|
||||||
|
- name: NODE_LINK_TABLE
|
||||||
|
# - name: NODE_STATUSES
|
||||||
|
# - name: LINK_TRAFFIC_LEVELS
|
||||||
|
|
||||||
|
|
||||||
|
# Number of episodes for training to run per session
|
||||||
|
num_train_episodes: 30
|
||||||
|
|
||||||
|
# Number of time_steps for training per episode
|
||||||
|
num_train_steps: 1
|
||||||
|
|
||||||
|
# Number of episodes for evaluation to run per session
|
||||||
|
num_eval_episodes: 10
|
||||||
|
|
||||||
|
# Number of time_steps for evaluation per episode
|
||||||
|
num_eval_steps: 10
|
||||||
|
|
||||||
|
# Sets how often the agent will save a checkpoint (every n time episodes).
|
||||||
|
# Set to 0 if no checkpoints are required. Default is 10
|
||||||
|
checkpoint_every_n_episodes: 10
|
||||||
|
|
||||||
|
# Time delay (milliseconds) between steps for CUSTOM agents.
|
||||||
|
time_delay: 5
|
||||||
|
|
||||||
|
# Type of session to be run. Options are:
|
||||||
|
# "TRAIN" (Trains an agent)
|
||||||
|
# "EVAL" (Evaluates an agent)
|
||||||
|
# "TRAIN_EVAL" (Trains then evaluates an agent)
|
||||||
|
session_type: EVAL
|
||||||
|
|
||||||
|
# Environment config values
|
||||||
|
# The high value for the observation space
|
||||||
|
observation_space_high_value: 1000000000
|
||||||
|
|
||||||
|
# The Stable Baselines3 learn/eval output verbosity level:
|
||||||
|
# Options are:
|
||||||
|
# "NONE" (No Output)
|
||||||
|
# "INFO" (Info Messages (such as devices and wrappers used))
|
||||||
|
# "DEBUG" (All Messages)
|
||||||
|
sb3_output_verbose_level: NONE
|
||||||
|
|
||||||
|
# Reward values
|
||||||
|
# Generic
|
||||||
|
all_ok: 0
|
||||||
|
# Node Hardware State
|
||||||
|
off_should_be_on: -10
|
||||||
|
off_should_be_resetting: -5
|
||||||
|
on_should_be_off: -2
|
||||||
|
on_should_be_resetting: -5
|
||||||
|
resetting_should_be_on: -5
|
||||||
|
resetting_should_be_off: -2
|
||||||
|
resetting: -3
|
||||||
|
# Node Software or Service State
|
||||||
|
good_should_be_patching: 2
|
||||||
|
good_should_be_compromised: 5
|
||||||
|
good_should_be_overwhelmed: 5
|
||||||
|
patching_should_be_good: -5
|
||||||
|
patching_should_be_compromised: 2
|
||||||
|
patching_should_be_overwhelmed: 2
|
||||||
|
patching: -3
|
||||||
|
compromised_should_be_good: -20
|
||||||
|
compromised_should_be_patching: -20
|
||||||
|
compromised_should_be_overwhelmed: -20
|
||||||
|
compromised: -20
|
||||||
|
overwhelmed_should_be_good: -20
|
||||||
|
overwhelmed_should_be_patching: -20
|
||||||
|
overwhelmed_should_be_compromised: -20
|
||||||
|
overwhelmed: -20
|
||||||
|
# Node File System State
|
||||||
|
good_should_be_repairing: 2
|
||||||
|
good_should_be_restoring: 2
|
||||||
|
good_should_be_corrupt: 5
|
||||||
|
good_should_be_destroyed: 10
|
||||||
|
repairing_should_be_good: -5
|
||||||
|
repairing_should_be_restoring: 2
|
||||||
|
repairing_should_be_corrupt: 2
|
||||||
|
repairing_should_be_destroyed: 0
|
||||||
|
repairing: -3
|
||||||
|
restoring_should_be_good: -10
|
||||||
|
restoring_should_be_repairing: -2
|
||||||
|
restoring_should_be_corrupt: 1
|
||||||
|
restoring_should_be_destroyed: 2
|
||||||
|
restoring: -6
|
||||||
|
corrupt_should_be_good: -10
|
||||||
|
corrupt_should_be_repairing: -10
|
||||||
|
corrupt_should_be_restoring: -10
|
||||||
|
corrupt_should_be_destroyed: 2
|
||||||
|
corrupt: -10
|
||||||
|
destroyed_should_be_good: -20
|
||||||
|
destroyed_should_be_repairing: -20
|
||||||
|
destroyed_should_be_restoring: -20
|
||||||
|
destroyed_should_be_corrupt: -20
|
||||||
|
destroyed: -20
|
||||||
|
scanning: -2
|
||||||
|
# IER status
|
||||||
|
red_ier_running: -5
|
||||||
|
green_ier_blocked: -10
|
||||||
|
|
||||||
|
# Patching / Reset durations
|
||||||
|
os_patching_duration: 5 # The time taken to patch the OS
|
||||||
|
node_reset_duration: 5 # The time taken to reset a node (hardware)
|
||||||
|
service_patching_duration: 5 # The time taken to patch a service
|
||||||
|
file_system_repairing_limit: 5 # The time take to repair the file system
|
||||||
|
file_system_restoring_limit: 5 # The time take to restore the file system
|
||||||
|
file_system_scanning_limit: 5 # The time taken to scan the file system
|
||||||
153
tests/config/train_eval_check_episode_step.yaml
Normal file
153
tests/config/train_eval_check_episode_step.yaml
Normal file
@@ -0,0 +1,153 @@
|
|||||||
|
# Training Config File
|
||||||
|
|
||||||
|
# Sets which agent algorithm framework will be used.
|
||||||
|
# Options are:
|
||||||
|
# "SB3" (Stable Baselines3)
|
||||||
|
# "RLLIB" (Ray RLlib)
|
||||||
|
# "CUSTOM" (Custom Agent)
|
||||||
|
agent_framework: SB3
|
||||||
|
|
||||||
|
# Sets which deep learning framework will be used (by RLlib ONLY).
|
||||||
|
# Default is TF (Tensorflow).
|
||||||
|
# Options are:
|
||||||
|
# "TF" (Tensorflow)
|
||||||
|
# TF2 (Tensorflow 2.X)
|
||||||
|
# TORCH (PyTorch)
|
||||||
|
deep_learning_framework: TF2
|
||||||
|
|
||||||
|
# Sets which Agent class will be used.
|
||||||
|
# Options are:
|
||||||
|
# "A2C" (Advantage Actor Critic coupled with either SB3 or RLLIB agent_framework)
|
||||||
|
# "PPO" (Proximal Policy Optimization coupled with either SB3 or RLLIB agent_framework)
|
||||||
|
# "HARDCODED" (The HardCoded agents coupled with an ACL or NODE action_type)
|
||||||
|
# "DO_NOTHING" (The DoNothing agents coupled with an ACL or NODE action_type)
|
||||||
|
# "RANDOM" (primaite.agents.simple.RandomAgent)
|
||||||
|
# "DUMMY" (primaite.agents.simple.DummyAgent)
|
||||||
|
agent_identifier: PPO
|
||||||
|
|
||||||
|
# Sets whether Red Agent POL and IER is randomised.
|
||||||
|
# Options are:
|
||||||
|
# True
|
||||||
|
# False
|
||||||
|
random_red_agent: False
|
||||||
|
|
||||||
|
# Sets what view of the environment the deterministic hardcoded agent has. The default is BASIC.
|
||||||
|
# Options are:
|
||||||
|
# "BASIC" (The current observation space only)
|
||||||
|
# "FULL" (Full environment view with actions taken and reward feedback)
|
||||||
|
hard_coded_agent_view: FULL
|
||||||
|
|
||||||
|
# Sets How the Action Space is defined:
|
||||||
|
# "NODE"
|
||||||
|
# "ACL"
|
||||||
|
# "ANY" node and acl actions
|
||||||
|
action_type: NODE
|
||||||
|
# observation space
|
||||||
|
observation_space:
|
||||||
|
# flatten: true
|
||||||
|
components:
|
||||||
|
- name: NODE_LINK_TABLE
|
||||||
|
# - name: NODE_STATUSES
|
||||||
|
# - name: LINK_TRAFFIC_LEVELS
|
||||||
|
|
||||||
|
|
||||||
|
# Number of episodes for training to run per session
|
||||||
|
num_train_episodes: 30
|
||||||
|
|
||||||
|
# Number of time_steps for training per episode
|
||||||
|
num_train_steps: 1
|
||||||
|
|
||||||
|
# Number of episodes for evaluation to run per session
|
||||||
|
num_eval_episodes: 10
|
||||||
|
|
||||||
|
# Number of time_steps for evaluation per episode
|
||||||
|
num_eval_steps: 10
|
||||||
|
|
||||||
|
# Sets how often the agent will save a checkpoint (every n time episodes).
|
||||||
|
# Set to 0 if no checkpoints are required. Default is 10
|
||||||
|
checkpoint_every_n_episodes: 10
|
||||||
|
|
||||||
|
# Time delay (milliseconds) between steps for CUSTOM agents.
|
||||||
|
time_delay: 5
|
||||||
|
|
||||||
|
# Type of session to be run. Options are:
|
||||||
|
# "TRAIN" (Trains an agent)
|
||||||
|
# "EVAL" (Evaluates an agent)
|
||||||
|
# "TRAIN_EVAL" (Trains then evaluates an agent)
|
||||||
|
session_type: TRAIN
|
||||||
|
|
||||||
|
# Environment config values
|
||||||
|
# The high value for the observation space
|
||||||
|
observation_space_high_value: 1000000000
|
||||||
|
|
||||||
|
# The Stable Baselines3 learn/eval output verbosity level:
|
||||||
|
# Options are:
|
||||||
|
# "NONE" (No Output)
|
||||||
|
# "INFO" (Info Messages (such as devices and wrappers used))
|
||||||
|
# "DEBUG" (All Messages)
|
||||||
|
sb3_output_verbose_level: NONE
|
||||||
|
|
||||||
|
# Reward values
|
||||||
|
# Generic
|
||||||
|
all_ok: 0
|
||||||
|
# Node Hardware State
|
||||||
|
off_should_be_on: -10
|
||||||
|
off_should_be_resetting: -5
|
||||||
|
on_should_be_off: -2
|
||||||
|
on_should_be_resetting: -5
|
||||||
|
resetting_should_be_on: -5
|
||||||
|
resetting_should_be_off: -2
|
||||||
|
resetting: -3
|
||||||
|
# Node Software or Service State
|
||||||
|
good_should_be_patching: 2
|
||||||
|
good_should_be_compromised: 5
|
||||||
|
good_should_be_overwhelmed: 5
|
||||||
|
patching_should_be_good: -5
|
||||||
|
patching_should_be_compromised: 2
|
||||||
|
patching_should_be_overwhelmed: 2
|
||||||
|
patching: -3
|
||||||
|
compromised_should_be_good: -20
|
||||||
|
compromised_should_be_patching: -20
|
||||||
|
compromised_should_be_overwhelmed: -20
|
||||||
|
compromised: -20
|
||||||
|
overwhelmed_should_be_good: -20
|
||||||
|
overwhelmed_should_be_patching: -20
|
||||||
|
overwhelmed_should_be_compromised: -20
|
||||||
|
overwhelmed: -20
|
||||||
|
# Node File System State
|
||||||
|
good_should_be_repairing: 2
|
||||||
|
good_should_be_restoring: 2
|
||||||
|
good_should_be_corrupt: 5
|
||||||
|
good_should_be_destroyed: 10
|
||||||
|
repairing_should_be_good: -5
|
||||||
|
repairing_should_be_restoring: 2
|
||||||
|
repairing_should_be_corrupt: 2
|
||||||
|
repairing_should_be_destroyed: 0
|
||||||
|
repairing: -3
|
||||||
|
restoring_should_be_good: -10
|
||||||
|
restoring_should_be_repairing: -2
|
||||||
|
restoring_should_be_corrupt: 1
|
||||||
|
restoring_should_be_destroyed: 2
|
||||||
|
restoring: -6
|
||||||
|
corrupt_should_be_good: -10
|
||||||
|
corrupt_should_be_repairing: -10
|
||||||
|
corrupt_should_be_restoring: -10
|
||||||
|
corrupt_should_be_destroyed: 2
|
||||||
|
corrupt: -10
|
||||||
|
destroyed_should_be_good: -20
|
||||||
|
destroyed_should_be_repairing: -20
|
||||||
|
destroyed_should_be_restoring: -20
|
||||||
|
destroyed_should_be_corrupt: -20
|
||||||
|
destroyed: -20
|
||||||
|
scanning: -2
|
||||||
|
# IER status
|
||||||
|
red_ier_running: -5
|
||||||
|
green_ier_blocked: -10
|
||||||
|
|
||||||
|
# Patching / Reset durations
|
||||||
|
os_patching_duration: 5 # The time taken to patch the OS
|
||||||
|
node_reset_duration: 5 # The time taken to reset a node (hardware)
|
||||||
|
service_patching_duration: 5 # The time taken to patch a service
|
||||||
|
file_system_repairing_limit: 5 # The time take to repair the file system
|
||||||
|
file_system_restoring_limit: 5 # The time take to restore the file system
|
||||||
|
file_system_scanning_limit: 5 # The time taken to scan the file system
|
||||||
153
tests/config/training_config_main.yaml
Normal file
153
tests/config/training_config_main.yaml
Normal file
@@ -0,0 +1,153 @@
|
|||||||
|
# Training Config File
|
||||||
|
|
||||||
|
# Sets which agent algorithm framework will be used.
|
||||||
|
# Options are:
|
||||||
|
# "SB3" (Stable Baselines3)
|
||||||
|
# "RLLIB" (Ray RLlib)
|
||||||
|
# "CUSTOM" (Custom Agent)
|
||||||
|
agent_framework: SB3
|
||||||
|
|
||||||
|
# Sets which deep learning framework will be used (by RLlib ONLY).
|
||||||
|
# Default is TF (Tensorflow).
|
||||||
|
# Options are:
|
||||||
|
# "TF" (Tensorflow)
|
||||||
|
# TF2 (Tensorflow 2.X)
|
||||||
|
# TORCH (PyTorch)
|
||||||
|
deep_learning_framework: TF2
|
||||||
|
|
||||||
|
# Sets which Agent class will be used.
|
||||||
|
# Options are:
|
||||||
|
# "A2C" (Advantage Actor Critic coupled with either SB3 or RLLIB agent_framework)
|
||||||
|
# "PPO" (Proximal Policy Optimization coupled with either SB3 or RLLIB agent_framework)
|
||||||
|
# "HARDCODED" (The HardCoded agents coupled with an ACL or NODE action_type)
|
||||||
|
# "DO_NOTHING" (The DoNothing agents coupled with an ACL or NODE action_type)
|
||||||
|
# "RANDOM" (primaite.agents.simple.RandomAgent)
|
||||||
|
# "DUMMY" (primaite.agents.simple.DummyAgent)
|
||||||
|
agent_identifier: PPO
|
||||||
|
|
||||||
|
# Sets whether Red Agent POL and IER is randomised.
|
||||||
|
# Options are:
|
||||||
|
# True
|
||||||
|
# False
|
||||||
|
random_red_agent: False
|
||||||
|
|
||||||
|
# Sets what view of the environment the deterministic hardcoded agent has. The default is BASIC.
|
||||||
|
# Options are:
|
||||||
|
# "BASIC" (The current observation space only)
|
||||||
|
# "FULL" (Full environment view with actions taken and reward feedback)
|
||||||
|
hard_coded_agent_view: FULL
|
||||||
|
|
||||||
|
# Sets How the Action Space is defined:
|
||||||
|
# "NODE"
|
||||||
|
# "ACL"
|
||||||
|
# "ANY" node and acl actions
|
||||||
|
action_type: NODE
|
||||||
|
# observation space
|
||||||
|
observation_space:
|
||||||
|
# flatten: true
|
||||||
|
components:
|
||||||
|
- name: NODE_LINK_TABLE
|
||||||
|
# - name: NODE_STATUSES
|
||||||
|
# - name: LINK_TRAFFIC_LEVELS
|
||||||
|
|
||||||
|
|
||||||
|
# Number of episodes for training to run per session
|
||||||
|
num_train_episodes: 10
|
||||||
|
|
||||||
|
# Number of time_steps for training per episode
|
||||||
|
num_train_steps: 256
|
||||||
|
|
||||||
|
# Number of episodes for evaluation to run per session
|
||||||
|
num_eval_episodes: 10
|
||||||
|
|
||||||
|
# Number of time_steps for evaluation per episode
|
||||||
|
num_eval_steps: 256
|
||||||
|
|
||||||
|
# Sets how often the agent will save a checkpoint (every n time episodes).
|
||||||
|
# Set to 0 if no checkpoints are required. Default is 10
|
||||||
|
checkpoint_every_n_episodes: 10
|
||||||
|
|
||||||
|
# Time delay (milliseconds) between steps for CUSTOM agents.
|
||||||
|
time_delay: 5
|
||||||
|
|
||||||
|
# Type of session to be run. Options are:
|
||||||
|
# "TRAIN" (Trains an agent)
|
||||||
|
# "EVAL" (Evaluates an agent)
|
||||||
|
# "TRAIN_EVAL" (Trains then evaluates an agent)
|
||||||
|
session_type: TRAIN
|
||||||
|
|
||||||
|
# Environment config values
|
||||||
|
# The high value for the observation space
|
||||||
|
observation_space_high_value: 1000000000
|
||||||
|
|
||||||
|
# The Stable Baselines3 learn/eval output verbosity level:
|
||||||
|
# Options are:
|
||||||
|
# "NONE" (No Output)
|
||||||
|
# "INFO" (Info Messages (such as devices and wrappers used))
|
||||||
|
# "DEBUG" (All Messages)
|
||||||
|
sb3_output_verbose_level: NONE
|
||||||
|
|
||||||
|
# Reward values
|
||||||
|
# Generic
|
||||||
|
all_ok: 0
|
||||||
|
# Node Hardware State
|
||||||
|
off_should_be_on: -10
|
||||||
|
off_should_be_resetting: -5
|
||||||
|
on_should_be_off: -2
|
||||||
|
on_should_be_resetting: -5
|
||||||
|
resetting_should_be_on: -5
|
||||||
|
resetting_should_be_off: -2
|
||||||
|
resetting: -3
|
||||||
|
# Node Software or Service State
|
||||||
|
good_should_be_patching: 2
|
||||||
|
good_should_be_compromised: 5
|
||||||
|
good_should_be_overwhelmed: 5
|
||||||
|
patching_should_be_good: -5
|
||||||
|
patching_should_be_compromised: 2
|
||||||
|
patching_should_be_overwhelmed: 2
|
||||||
|
patching: -3
|
||||||
|
compromised_should_be_good: -20
|
||||||
|
compromised_should_be_patching: -20
|
||||||
|
compromised_should_be_overwhelmed: -20
|
||||||
|
compromised: -20
|
||||||
|
overwhelmed_should_be_good: -20
|
||||||
|
overwhelmed_should_be_patching: -20
|
||||||
|
overwhelmed_should_be_compromised: -20
|
||||||
|
overwhelmed: -20
|
||||||
|
# Node File System State
|
||||||
|
good_should_be_repairing: 2
|
||||||
|
good_should_be_restoring: 2
|
||||||
|
good_should_be_corrupt: 5
|
||||||
|
good_should_be_destroyed: 10
|
||||||
|
repairing_should_be_good: -5
|
||||||
|
repairing_should_be_restoring: 2
|
||||||
|
repairing_should_be_corrupt: 2
|
||||||
|
repairing_should_be_destroyed: 0
|
||||||
|
repairing: -3
|
||||||
|
restoring_should_be_good: -10
|
||||||
|
restoring_should_be_repairing: -2
|
||||||
|
restoring_should_be_corrupt: 1
|
||||||
|
restoring_should_be_destroyed: 2
|
||||||
|
restoring: -6
|
||||||
|
corrupt_should_be_good: -10
|
||||||
|
corrupt_should_be_repairing: -10
|
||||||
|
corrupt_should_be_restoring: -10
|
||||||
|
corrupt_should_be_destroyed: 2
|
||||||
|
corrupt: -10
|
||||||
|
destroyed_should_be_good: -20
|
||||||
|
destroyed_should_be_repairing: -20
|
||||||
|
destroyed_should_be_restoring: -20
|
||||||
|
destroyed_should_be_corrupt: -20
|
||||||
|
destroyed: -20
|
||||||
|
scanning: -2
|
||||||
|
# IER status
|
||||||
|
red_ier_running: -5
|
||||||
|
green_ier_blocked: -10
|
||||||
|
|
||||||
|
# Patching / Reset durations
|
||||||
|
os_patching_duration: 5 # The time taken to patch the OS
|
||||||
|
node_reset_duration: 5 # The time taken to reset a node (hardware)
|
||||||
|
service_patching_duration: 5 # The time taken to patch a service
|
||||||
|
file_system_repairing_limit: 5 # The time take to repair the file system
|
||||||
|
file_system_restoring_limit: 5 # The time take to restore the file system
|
||||||
|
file_system_scanning_limit: 5 # The time taken to scan the file system
|
||||||
@@ -163,8 +163,9 @@ def run_generic(env, config_values):
|
|||||||
"""Run against a generic agent."""
|
"""Run against a generic agent."""
|
||||||
# Reset the environment at the start of the episode
|
# Reset the environment at the start of the episode
|
||||||
# env.reset()
|
# env.reset()
|
||||||
for episode in range(0, config_values.num_episodes):
|
print(config_values.num_train_episodes, "how many episodes")
|
||||||
for step in range(0, config_values.num_steps):
|
for episode in range(0, config_values.num_train_episodes):
|
||||||
|
for step in range(0, config_values.num_train_steps):
|
||||||
# Send the observation space to the agent to get an action
|
# Send the observation space to the agent to get an action
|
||||||
# TEMP - random action for now
|
# TEMP - random action for now
|
||||||
# action = env.blue_agent_action(obs)
|
# action = env.blue_agent_action(obs)
|
||||||
|
|||||||
@@ -12,8 +12,8 @@ def run_generic_set_actions(env: Primaite):
|
|||||||
# Reset the environment at the start of the episode
|
# Reset the environment at the start of the episode
|
||||||
# env.reset()
|
# env.reset()
|
||||||
training_config = env.training_config
|
training_config = env.training_config
|
||||||
for episode in range(0, training_config.num_episodes):
|
for episode in range(0, training_config.num_train_episodes):
|
||||||
for step in range(0, training_config.num_steps):
|
for step in range(0, training_config.num_train_steps):
|
||||||
# Send the observation space to the agent to get an action
|
# Send the observation space to the agent to get an action
|
||||||
# TEMP - random action for now
|
# TEMP - random action for now
|
||||||
# action = env.blue_agent_action(obs)
|
# action = env.blue_agent_action(obs)
|
||||||
|
|||||||
46
tests/test_train_eval_episode_steps.py
Normal file
46
tests/test_train_eval_episode_steps.py
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
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__)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
"temp_primaite_session",
|
||||||
|
[[TEST_CONFIG_ROOT / "train_episode_step.yaml", dos_very_basic_config_path()]],
|
||||||
|
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()
|
||||||
|
|
||||||
|
"""
|
||||||
|
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.
|
||||||
|
"""
|
||||||
|
assert env.episode_steps == 10 # 30
|
||||||
|
# assert env.actual_episode_count == 10 # should be 10
|
||||||
|
|
||||||
|
|
||||||
|
@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)
|
||||||
|
|
||||||
|
print(env.actual_episode_count, env.step_count, env.total_step_count)
|
||||||
Reference in New Issue
Block a user