From a222a8c58fa8fa3b8a13043327b4211a9ed63d2b Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Mon, 4 Mar 2024 19:43:51 +0000 Subject: [PATCH] Give the UC2 config load function a meaningful name --- src/primaite/cli.py | 4 ++-- src/primaite/config/load.py | 2 +- src/primaite/main.py | 4 ++-- .../notebooks/Data-Manipulation-E2E-Demonstration.ipynb | 4 ++-- .../notebooks/training_example_ray_single_agent.ipynb | 4 ++-- src/primaite/notebooks/training_example_sb3.ipynb | 4 ++-- .../environments/test_rllib_multi_agent_environment.py | 4 ++-- .../environments/test_rllib_single_agent_environment.py | 4 ++-- .../environments/test_sb3_environment.py | 4 ++-- .../configuration_file_parsing/nodes/test_node_config.py | 4 ++-- .../software_installation_and_configuration.py | 4 ++-- 11 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/primaite/cli.py b/src/primaite/cli.py index 81ab2792..18d21f7b 100644 --- a/src/primaite/cli.py +++ b/src/primaite/cli.py @@ -127,10 +127,10 @@ def session( :param config: The path to the config file. Optional, if None, the example config will be used. :type config: Optional[str] """ - from primaite.config.load import example_config_path + from primaite.config.load import data_manipulation_config_path from primaite.main import run if not config: - config = example_config_path() + config = data_manipulation_config_path() print(config) run(config_path=config, agent_load_path=agent_load_file) diff --git a/src/primaite/config/load.py b/src/primaite/config/load.py index b01eb129..6bd0d80d 100644 --- a/src/primaite/config/load.py +++ b/src/primaite/config/load.py @@ -30,7 +30,7 @@ def load(file_path: Union[str, Path]) -> Dict: return config -def example_config_path() -> Path: +def data_manipulation_config_path() -> Path: """ Get the path to the example config. diff --git a/src/primaite/main.py b/src/primaite/main.py index b63227a7..053ed65b 100644 --- a/src/primaite/main.py +++ b/src/primaite/main.py @@ -5,7 +5,7 @@ from pathlib import Path from typing import Optional, Union from primaite import getLogger -from primaite.config.load import example_config_path, load +from primaite.config.load import data_manipulation_config_path, load from primaite.session.session import PrimaiteSession # from primaite.primaite_session import PrimaiteSession @@ -42,6 +42,6 @@ if __name__ == "__main__": args = parser.parse_args() if not args.config: - args.config = example_config_path() + args.config = data_manipulation_config_path() run(args.config) diff --git a/src/primaite/notebooks/Data-Manipulation-E2E-Demonstration.ipynb b/src/primaite/notebooks/Data-Manipulation-E2E-Demonstration.ipynb index 85061b2b..e35e6126 100644 --- a/src/primaite/notebooks/Data-Manipulation-E2E-Demonstration.ipynb +++ b/src/primaite/notebooks/Data-Manipulation-E2E-Demonstration.ipynb @@ -371,7 +371,7 @@ "outputs": [], "source": [ "# Imports\n", - "from primaite.config.load import example_config_path\n", + "from primaite.config.load import data_manipulation_config_path\n", "from primaite.session.environment import PrimaiteGymEnv\n", "from primaite.game.game import PrimaiteGame\n", "import yaml\n", @@ -394,7 +394,7 @@ "outputs": [], "source": [ "# create the env\n", - "with open(example_config_path(), 'r') as f:\n", + "with open(data_manipulation_config_path(), 'r') as f:\n", " cfg = yaml.safe_load(f)\n", " # set success probability to 1.0 to avoid rerunning cells.\n", " cfg['simulation']['network']['nodes'][8]['applications'][0]['options']['data_manipulation_p_of_success'] = 1.0\n", diff --git a/src/primaite/notebooks/training_example_ray_single_agent.ipynb b/src/primaite/notebooks/training_example_ray_single_agent.ipynb index 3c27bdc6..2fe84655 100644 --- a/src/primaite/notebooks/training_example_ray_single_agent.ipynb +++ b/src/primaite/notebooks/training_example_ray_single_agent.ipynb @@ -16,7 +16,7 @@ "source": [ "from primaite.game.game import PrimaiteGame\n", "import yaml\n", - "from primaite.config.load import example_config_path\n", + "from primaite.config.load import data_manipulation_config_path\n", "\n", "from primaite.session.environment import PrimaiteRayEnv\n", "from ray.rllib.algorithms import ppo\n", @@ -26,7 +26,7 @@ "\n", "# If you get an error saying this config file doesn't exist, you may need to run `primaite setup` in your command line\n", "# to copy the files to your user data path.\n", - "with open(example_config_path(), 'r') as f:\n", + "with open(data_manipulation_config_path(), 'r') as f:\n", " cfg = yaml.safe_load(f)\n", "\n", "ray.init(local_mode=True)\n" diff --git a/src/primaite/notebooks/training_example_sb3.ipynb b/src/primaite/notebooks/training_example_sb3.ipynb index 0472854e..cefcc429 100644 --- a/src/primaite/notebooks/training_example_sb3.ipynb +++ b/src/primaite/notebooks/training_example_sb3.ipynb @@ -17,7 +17,7 @@ "metadata": {}, "outputs": [], "source": [ - "from primaite.config.load import example_config_path" + "from primaite.config.load import data_manipulation_config_path" ] }, { @@ -26,7 +26,7 @@ "metadata": {}, "outputs": [], "source": [ - "with open(example_config_path(), 'r') as f:\n", + "with open(data_manipulation_config_path(), 'r') as f:\n", " cfg = yaml.safe_load(f)\n" ] }, diff --git a/tests/e2e_integration_tests/environments/test_rllib_multi_agent_environment.py b/tests/e2e_integration_tests/environments/test_rllib_multi_agent_environment.py index 3934ce5b..84897f9a 100644 --- a/tests/e2e_integration_tests/environments/test_rllib_multi_agent_environment.py +++ b/tests/e2e_integration_tests/environments/test_rllib_multi_agent_environment.py @@ -4,7 +4,7 @@ import yaml from ray import air, tune from ray.rllib.algorithms.ppo import PPOConfig -from primaite.config.load import example_config_path +from primaite.config.load import data_manipulation_config_path from primaite.game.game import PrimaiteGame from primaite.session.environment import PrimaiteRayMARLEnv @@ -13,7 +13,7 @@ from primaite.session.environment import PrimaiteRayMARLEnv def test_rllib_multi_agent_compatibility(): """Test that the PrimaiteRayEnv class can be used with a multi agent RLLIB system.""" - with open(example_config_path(), "r") as f: + with open(data_manipulation_config_path(), "r") as f: cfg = yaml.safe_load(f) game = PrimaiteGame.from_config(cfg) diff --git a/tests/e2e_integration_tests/environments/test_rllib_single_agent_environment.py b/tests/e2e_integration_tests/environments/test_rllib_single_agent_environment.py index 2b12ad98..4c4b8d8d 100644 --- a/tests/e2e_integration_tests/environments/test_rllib_single_agent_environment.py +++ b/tests/e2e_integration_tests/environments/test_rllib_single_agent_environment.py @@ -6,7 +6,7 @@ import ray import yaml from ray.rllib.algorithms import ppo -from primaite.config.load import example_config_path +from primaite.config.load import data_manipulation_config_path from primaite.game.game import PrimaiteGame from primaite.session.environment import PrimaiteRayEnv @@ -14,7 +14,7 @@ from primaite.session.environment import PrimaiteRayEnv @pytest.mark.skip(reason="Slow, reenable later") def test_rllib_single_agent_compatibility(): """Test that the PrimaiteRayEnv class can be used with a single agent RLLIB system.""" - with open(example_config_path(), "r") as f: + with open(data_manipulation_config_path(), "r") as f: cfg = yaml.safe_load(f) game = PrimaiteGame.from_config(cfg) diff --git a/tests/e2e_integration_tests/environments/test_sb3_environment.py b/tests/e2e_integration_tests/environments/test_sb3_environment.py index c48ddbc9..83965191 100644 --- a/tests/e2e_integration_tests/environments/test_sb3_environment.py +++ b/tests/e2e_integration_tests/environments/test_sb3_environment.py @@ -6,14 +6,14 @@ import pytest import yaml from stable_baselines3 import PPO -from primaite.config.load import example_config_path +from primaite.config.load import data_manipulation_config_path from primaite.game.game import PrimaiteGame from primaite.session.environment import PrimaiteGymEnv def test_sb3_compatibility(): """Test that the Gymnasium environment can be used with an SB3 agent.""" - with open(example_config_path(), "r") as f: + with open(data_manipulation_config_path(), "r") as f: cfg = yaml.safe_load(f) gym = PrimaiteGymEnv(game_config=cfg) diff --git a/tests/integration_tests/configuration_file_parsing/nodes/test_node_config.py b/tests/integration_tests/configuration_file_parsing/nodes/test_node_config.py index 8797bf2e..174bd0c0 100644 --- a/tests/integration_tests/configuration_file_parsing/nodes/test_node_config.py +++ b/tests/integration_tests/configuration_file_parsing/nodes/test_node_config.py @@ -1,4 +1,4 @@ -from primaite.config.load import example_config_path +from primaite.config.load import data_manipulation_config_path from primaite.simulator.network.container import Network from primaite.simulator.network.hardware.node_operating_state import NodeOperatingState from primaite.simulator.network.hardware.nodes.host.computer import Computer @@ -7,7 +7,7 @@ from tests.integration_tests.configuration_file_parsing import BASIC_CONFIG, DMZ def test_example_config(): """Test that the example config can be parsed properly.""" - game = load_config(example_config_path()) + game = load_config(data_manipulation_config_path()) network: Network = game.simulation.network assert len(network.nodes) == 10 # 10 nodes in example network diff --git a/tests/integration_tests/configuration_file_parsing/software_installation_and_configuration.py b/tests/integration_tests/configuration_file_parsing/software_installation_and_configuration.py index 7da66547..3aff59af 100644 --- a/tests/integration_tests/configuration_file_parsing/software_installation_and_configuration.py +++ b/tests/integration_tests/configuration_file_parsing/software_installation_and_configuration.py @@ -4,7 +4,7 @@ from typing import Union import yaml -from primaite.config.load import example_config_path +from primaite.config.load import data_manipulation_config_path from primaite.game.agent.data_manipulation_bot import DataManipulationAgent from primaite.game.agent.interface import ProxyAgent, RandomAgent from primaite.game.game import APPLICATION_TYPES_MAPPING, PrimaiteGame, SERVICE_TYPES_MAPPING @@ -37,7 +37,7 @@ def load_config(config_path: Union[str, Path]) -> PrimaiteGame: def test_example_config(): """Test that the example config can be parsed properly.""" - game = load_config(example_config_path()) + game = load_config(data_manipulation_config_path()) assert len(game.agents) == 4 # red, blue and 2 green agents