From 900bf2bb75f892796bc1634329df54ff2e592446 Mon Sep 17 00:00:00 2001 From: Limmen Date: Sun, 4 Feb 2024 20:15:57 +0100 Subject: [PATCH] tests --- examples/eval/cyborg_scenario_two/evaluate_on_base_env.py | 2 +- examples/plotting/backup_orlando.py | 2 ++ .../run_cyborg_version_two_b_line.py | 2 +- .../libs/csle-agents/src/csle_agents/agents/pomcp/pomcp.py | 5 +++-- .../src/csle_agents/agents/pomcp/pomcp_agent.py | 7 +++++-- 5 files changed, 12 insertions(+), 6 deletions(-) diff --git a/examples/eval/cyborg_scenario_two/evaluate_on_base_env.py b/examples/eval/cyborg_scenario_two/evaluate_on_base_env.py index fd672cd07..68a6151bc 100644 --- a/examples/eval/cyborg_scenario_two/evaluate_on_base_env.py +++ b/examples/eval/cyborg_scenario_two/evaluate_on_base_env.py @@ -7,7 +7,7 @@ from gym_csle_cyborg.envs.cyborg_scenario_two_defender import CyborgScenarioTwoDefender if __name__ == '__main__': - ppo_policy = MetastoreFacade.get_ppo_policy(id=58) + ppo_policy = MetastoreFacade.get_ppo_policy(id=3) config = CSLECyborgConfig( gym_env_name="csle-cyborg-scenario-two-v1", scenario=2, baseline_red_agents=[RedAgentType.B_LINE_AGENT], maximum_steps=100, red_agent_distribution=[1.0], reduced_action_space=True, decoy_state=True, diff --git a/examples/plotting/backup_orlando.py b/examples/plotting/backup_orlando.py index 8689842a2..94dbabe7c 100644 --- a/examples/plotting/backup_orlando.py +++ b/examples/plotting/backup_orlando.py @@ -14,6 +14,7 @@ # experiment_apple_bline_256.to_json_file("/home/kim/orlando_results/15_jan/apple_b_line_256.json") # experiment_apple_meander_256.to_json_file("/home/kim/orlando_results/15_jan/apple_meander_256.json") # experiment_cardiff_b_line_64.to_json_file("/home/kim/orlando_results/16_jan/cardiff_b_line_64.json") + experiment_cardiff_b_line_64.to_json_file("/home/kim/orlando_results/16_jan/cardiff_b_line_64_2.json") # experiment_cardiff_meander_64.to_json_file("/home/kim/orlando_results/16_jan/cardiff_meander_64.json") metric = "average_return" @@ -41,6 +42,7 @@ # print(avg_returns_means.shape) # avg_returns_stds = np.array(list(map(lambda x: PlottingUtil.mean_confidence_interval( # data=x, confidence=confidence)[1], returns))) + b_line_opt = -13.73 for i in range(len(avg_returns_means)): print(f"{i + 1} {avg_returns_means[i]} {avg_returns_means[i] + avg_returns_stds[i]} " f"{avg_returns_means[i] - avg_returns_stds[i]}") diff --git a/examples/training/pomcp/cyborg_scenario_two_defender/run_cyborg_version_two_b_line.py b/examples/training/pomcp/cyborg_scenario_two_defender/run_cyborg_version_two_b_line.py index fb0698aa2..cf39e5428 100644 --- a/examples/training/pomcp/cyborg_scenario_two_defender/run_cyborg_version_two_b_line.py +++ b/examples/training/pomcp/cyborg_scenario_two_defender/run_cyborg_version_two_b_line.py @@ -129,6 +129,6 @@ player_type=PlayerType.DEFENDER, player_idx=0 ) agent = POMCPAgent(emulation_env_config=emulation_env_config, simulation_env_config=simulation_env_config, - experiment_config=experiment_config, save_to_metastore=True) + experiment_config=experiment_config, save_to_metastore=False) experiment_execution = agent.train() MetastoreFacade.save_experiment_execution(experiment_execution) diff --git a/simulation-system/libs/csle-agents/src/csle_agents/agents/pomcp/pomcp.py b/simulation-system/libs/csle-agents/src/csle_agents/agents/pomcp/pomcp.py index fd9935ccc..30cc4ca6f 100644 --- a/simulation-system/libs/csle-agents/src/csle_agents/agents/pomcp/pomcp.py +++ b/simulation-system/libs/csle-agents/src/csle_agents/agents/pomcp/pomcp.py @@ -360,8 +360,9 @@ def update_tree_with_new_samples(self, action_sequence: List[int], observation: count = 0 else: count += 1 - if count >= 20000: - raise ValueError(f"Invalid observation: {o} given state: {root.sample_state()}") + if count >= 80000: + raise ValueError(f"Invalid observation: {o} given state: {root.sample_state()}, " + f"{root.sample_state()}, {root.sample_state()}") new_root.particles += particles # We now prune the old root from the tree diff --git a/simulation-system/libs/csle-agents/src/csle_agents/agents/pomcp/pomcp_agent.py b/simulation-system/libs/csle-agents/src/csle_agents/agents/pomcp/pomcp_agent.py index 0e7cfd0dd..6deb8fe5d 100644 --- a/simulation-system/libs/csle-agents/src/csle_agents/agents/pomcp/pomcp_agent.py +++ b/simulation-system/libs/csle-agents/src/csle_agents/agents/pomcp/pomcp_agent.py @@ -275,11 +275,14 @@ def pomcp(self, exp_result: ExperimentResult, seed: int, action_sequence.append(action) s_prime = info[agents_constants.COMMON.STATE] obs_id = info[agents_constants.COMMON.OBSERVATION] + print(eval_env.get_true_table()) + print(eval_env.get_table()) + from gym_csle_cyborg.util.cyborg_env_util import CyborgEnvUtil + print(CyborgEnvUtil.state_id_to_state_vector(state_id=s_prime)) + print(CyborgEnvUtil.state_id_to_state_vector(state_id=obs_id, observation=True)) pomcp.update_tree_with_new_samples(action_sequence=action_sequence, observation=obs_id) R += r t += 1 - print(eval_env.get_true_table()) - print(eval_env.get_table()) if t % log_steps_frequency == 0: rollout_action = -1 if rollout_policy is not None: