diff --git a/src/primaite/config/_package_data/example_config.yaml b/src/primaite/config/_package_data/example_config.yaml index 443b0efe..f167dc2f 100644 --- a/src/primaite/config/_package_data/example_config.yaml +++ b/src/primaite/config/_package_data/example_config.yaml @@ -15,7 +15,8 @@ io_settings: checkpoint_interval: 5 -game_config: +game: + max_episode_length: 256 ports: - ARP - DNS @@ -26,523 +27,523 @@ game_config: - TCP - UDP - agents: - - ref: client_1_green_user - team: GREEN - type: GreenWebBrowsingAgent - observation_space: - type: UC2GreenObservation - action_space: - action_list: - - type: DONOTHING - # - # - type: NODE_LOGON - # - type: NODE_LOGOFF - # - type: NODE_APPLICATION_EXECUTE - # options: - # execution_definition: - # target_address: arcd.com +agents: + - ref: client_1_green_user + team: GREEN + type: GreenWebBrowsingAgent + observation_space: + type: UC2GreenObservation + action_space: + action_list: + - type: DONOTHING + # + # - type: NODE_LOGON + # - type: NODE_LOGOFF + # - type: NODE_APPLICATION_EXECUTE + # options: + # execution_definition: + # target_address: arcd.com - options: - nodes: - - node_ref: client_2 - max_folders_per_node: 1 - max_files_per_folder: 1 - max_services_per_node: 1 - max_nics_per_node: 2 - max_acl_rules: 10 + options: + nodes: + - node_ref: client_2 + max_folders_per_node: 1 + max_files_per_folder: 1 + max_services_per_node: 1 + max_nics_per_node: 2 + max_acl_rules: 10 - reward_function: - reward_components: - - type: DUMMY + reward_function: + reward_components: + - type: DUMMY - agent_settings: - start_step: 5 - frequency: 4 - variance: 3 + agent_settings: + start_step: 5 + frequency: 4 + variance: 3 - - ref: client_1_data_manipulation_red_bot - team: RED - type: RedDatabaseCorruptingAgent + - ref: client_1_data_manipulation_red_bot + team: RED + type: RedDatabaseCorruptingAgent - observation_space: - type: UC2RedObservation - options: - nodes: - - node_ref: client_1 + observation_space: + type: UC2RedObservation + options: + nodes: + - node_ref: client_1 + observations: + - logon_status + - operating_status + services: + - service_ref: data_manipulation_bot observations: - - logon_status - - operating_status - services: - - service_ref: data_manipulation_bot - observations: - operating_status - health_status - folders: {} + operating_status + health_status + folders: {} - action_space: - action_list: - - type: DONOTHING - # Tuple[ObsType, SupportsFloat, bool, bool, Dict[str, Any]]: @@ -28,24 +26,24 @@ class PrimaiteGymEnv(gymnasium.Env): # make ProxyAgent store the action chosen my the RL policy self.agent.store_action(action) # apply_agent_actions accesses the action we just stored - self.session.apply_agent_actions() - self.session.advance_timestep() - state = self.session.get_sim_state() - self.session.update_agents(state) + self.game.apply_agent_actions() + self.game.advance_timestep() + state = self.game.get_sim_state() + self.game.update_agents(state) next_obs = self._get_obs() reward = self.agent.reward_function.current_reward terminated = False - truncated = self.session.calculate_truncated() + truncated = self.game.calculate_truncated() info = {} return next_obs, reward, terminated, truncated, info def reset(self, seed: Optional[int] = None) -> Tuple[ObsType, Dict[str, Any]]: """Reset the environment.""" - self.session.reset() - state = self.session.get_sim_state() - self.session.update_agents(state) + self.game.reset() + state = self.game.get_sim_state() + self.game.update_agents(state) next_obs = self._get_obs() info = {} return next_obs, info diff --git a/src/primaite/game/game.py b/src/primaite/game/game.py index 7dd50924..e260285f 100644 --- a/src/primaite/game/game.py +++ b/src/primaite/game/game.py @@ -177,7 +177,7 @@ class PrimaiteGame: :rtype: PrimaiteSession """ game = cls() - game.options = PrimaiteGameOptions(cfg["game"]) + game.options = PrimaiteGameOptions(**cfg["game"]) # 1. create simulation sim = game.simulation @@ -305,8 +305,7 @@ class PrimaiteGame: game.ref_map_links[link_cfg["ref"]] = new_link.uuid # 3. create agents - game_cfg = cfg["game_config"] - agents_cfg = game_cfg["agents"] + agents_cfg = cfg["agents"] for agent_cfg in agents_cfg: agent_ref = agent_cfg["ref"] # noqa: F841 diff --git a/src/primaite/notebooks/train_rllib_single_agent.ipynb b/src/primaite/notebooks/train_rllib_single_agent.ipynb index 3b608a52..709e6e6f 100644 --- a/src/primaite/notebooks/train_rllib_single_agent.ipynb +++ b/src/primaite/notebooks/train_rllib_single_agent.ipynb @@ -4,19 +4,7 @@ "cell_type": "code", "execution_count": 1, "metadata": {}, - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "/home/cade/repos/PrimAITE/venv/lib/python3.10/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n", - " from .autonotebook import tqdm as notebook_tqdm\n", - "2023-11-18 09:06:45,876\tINFO util.py:159 -- Missing packages: ['ipywidgets']. Run `pip install -U ipywidgets`, then restart the notebook server for rich notebook output.\n", - "2023-11-18 09:06:48,446\tINFO util.py:159 -- Missing packages: ['ipywidgets']. Run `pip install -U ipywidgets`, then restart the notebook server for rich notebook output.\n", - "2023-11-18 09:06:48,692\tWARNING __init__.py:10 -- PG has/have been moved to `rllib_contrib` and will no longer be maintained by the RLlib team. You can still use it/them normally inside RLlib util Ray 2.8, but from Ray 2.9 on, all `rllib_contrib` algorithms will no longer be part of the core repo, and will therefore have to be installed separately with pinned dependencies for e.g. ray[rllib] and other packages! See https://github.com/ray-project/ray/tree/master/rllib_contrib#rllib-contrib for more information on the RLlib contrib effort.\n" - ] - } - ], + "outputs": [], "source": [ "from primaite.game.game import PrimaiteGame\n", "from primaite.game.environment import PrimaiteGymEnv\n", @@ -56,7 +44,7 @@ "with open(example_config_path(), 'r') as f:\n", " cfg = yaml.safe_load(f)\n", "\n", - "sess = PrimaiteGame.from_config(cfg)" + "game = PrimaiteGame.from_config(cfg)" ] }, { @@ -65,44 +53,8 @@ "metadata": {}, "outputs": [], "source": [ - "sess.env = PrimaiteGymEnv(session=sess, agents=sess.rl_agents)" + "gym = PrimaiteGymEnv(game=game, agents=game.rl_agents)" ] - }, - { - "cell_type": "code", - "execution_count": 5, - "metadata": {}, - "outputs": [], - "source": [ - "env = sess.env" - ] - }, - { - "cell_type": "code", - "execution_count": 6, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "" - ] - }, - "execution_count": 6, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "env" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] } ], "metadata": {