From 789e9934fdf36141ea91d71968bf0b8b97639844 Mon Sep 17 00:00:00 2001 From: Chanumask Date: Fri, 10 Nov 2023 12:19:52 +0100 Subject: [PATCH] added test hooks (like rules) --- marl_factory_grid/environment/tests.py | 1 + marl_factory_grid/testing/test_config.yaml | 82 +++++++++++++--------- marl_factory_grid/testing/test_run.py | 2 +- marl_factory_grid/utils/config_parser.py | 4 +- 4 files changed, 53 insertions(+), 36 deletions(-) diff --git a/marl_factory_grid/environment/tests.py b/marl_factory_grid/environment/tests.py index ee615c3..b6252af 100644 --- a/marl_factory_grid/environment/tests.py +++ b/marl_factory_grid/environment/tests.py @@ -38,5 +38,6 @@ class Test(abc.ABC): class FirstTest(Test): def __init__(self): + print("firstTest") super().__init__() pass diff --git a/marl_factory_grid/testing/test_config.yaml b/marl_factory_grid/testing/test_config.yaml index 060ead2..5c6c8e0 100644 --- a/marl_factory_grid/testing/test_config.yaml +++ b/marl_factory_grid/testing/test_config.yaml @@ -22,26 +22,41 @@ Agents: - Inventory - DropOffLocations - Maintainers + # This is special for agents, as each one is different and can act as an adversary e.g. + Positions: + - (16, 7) + - (16, 6) + - (16, 3) + - (16, 4) + - (16, 5) Entities: Batteries: initial_charge: 0.8 per_action_costs: 0.02 - ChargePods: {} - Destinations: {} + ChargePods: + coords_or_quantity: 2 + Destinations: + coords_or_quantity: 1 + spawn_mode: GROUPED DirtPiles: + coords_or_quantity: 10 + initial_amount: 2 clean_amount: 1 dirt_spawn_r_var: 0.1 - initial_amount: 2 - initial_dirt_ratio: 0.05 max_global_amount: 20 max_local_amount: 5 - Doors: {} - DropOffLocations: {} + Doors: + DropOffLocations: + coords_or_quantity: 1 + max_dropoff_storage_size: 0 GlobalPositions: {} Inventories: {} - Items: {} - Machines: {} - Maintainers: {} + Items: + coords_or_quantity: 5 + Machines: + coords_or_quantity: 2 + Maintainers: + coords_or_quantity: 1 Zones: {} General: @@ -49,33 +64,34 @@ General: individual_rewards: true level_name: large pomdp_r: 3 - verbose: false - tests: true + verbose: True + tests: false Rules: - SpawnAgents: {} - DoneAtBatteryDischarge: {} - Collision: - done_at_collisions: false - AssignGlobalPositions: {} - DoneAtDestinationReachAny: {} - DestinationReachReward: {} - SpawnDestinations: - n_dests: 1 - spawn_mode: GROUPED - DoneOnAllDirtCleaned: {} - SpawnDirt: - spawn_freq: 15 + # Environment Dynamics EntitiesSmearDirtOnMove: smear_ratio: 0.2 DoorAutoClose: close_frequency: 10 - ItemRules: - max_dropoff_storage_size: 0 - n_items: 5 - n_locations: 5 - spawn_frequency: 15 - MaxStepsReached: - max_steps: 10 -# AgentSingleZonePlacement: -# n_zones: 4 + MoveMaintainers: + + # Respawn Stuff + RespawnDirt: + respawn_freq: 15 + RespawnItems: + respawn_freq: 15 + + # Utilities + WatchCollisions: + done_at_collisions: false + + # Done Conditions + DoneAtDestinationReachAny: + DoneOnAllDirtCleaned: + DoneAtBatteryDischarge: + DoneAtMaintainerCollision: + DoneAtMaxStepsReached: + max_steps: 500 + +Tests: + FirstTest: {} \ No newline at end of file diff --git a/marl_factory_grid/testing/test_run.py b/marl_factory_grid/testing/test_run.py index 35112ca..caf25d3 100644 --- a/marl_factory_grid/testing/test_run.py +++ b/marl_factory_grid/testing/test_run.py @@ -7,7 +7,7 @@ from marl_factory_grid.environment.factory import Factory if __name__ == '__main__': # Render at each step? - render = True + render = False # Path to config File path = Path('test_config.yaml') diff --git a/marl_factory_grid/utils/config_parser.py b/marl_factory_grid/utils/config_parser.py index 5cad113..f54c9ab 100644 --- a/marl_factory_grid/utils/config_parser.py +++ b/marl_factory_grid/utils/config_parser.py @@ -161,8 +161,8 @@ class FactoryConfigParser(object): return self._load_smth(rules, Rule) - def load_env_tests(self) -> List[Rule]: - return self._load_smth(self.tests, None) # Test + def load_env_tests(self) -> List[Test]: + return self._load_smth(self.tests, Test) def _load_smth(self, config, class_obj): rules = list()