From bf88561e7c9237d702718d67103e0084f37ca1e9 Mon Sep 17 00:00:00 2001 From: Steffen Illium Date: Tue, 24 Oct 2023 13:37:35 +0200 Subject: [PATCH 1/2] small adjustments and "DestinationReachAny" as replacement for "DestinationDone" --- marl_factory_grid/configs/default_config.yaml | 2 +- marl_factory_grid/environment/rules.py | 2 +- marl_factory_grid/modules/destinations/constants.py | 6 +++--- marl_factory_grid/modules/doors/rules.py | 2 +- marl_factory_grid/quickstart.py | 1 - 5 files changed, 6 insertions(+), 7 deletions(-) diff --git a/marl_factory_grid/configs/default_config.yaml b/marl_factory_grid/configs/default_config.yaml index e8687ff..5e7b152 100644 --- a/marl_factory_grid/configs/default_config.yaml +++ b/marl_factory_grid/configs/default_config.yaml @@ -63,7 +63,7 @@ Rules: Collision: done_at_collisions: false AssignGlobalPositions: {} - DestinationDone: {} + DestinationReachAny: {} DestinationReach: n_dests: 1 DestinationSpawn: diff --git a/marl_factory_grid/environment/rules.py b/marl_factory_grid/environment/rules.py index 1fadc6a..79d4e27 100644 --- a/marl_factory_grid/environment/rules.py +++ b/marl_factory_grid/environment/rules.py @@ -59,7 +59,7 @@ class SpawnAgents(Rule): while True: try: pos = positions.pop() - except IndexError as e: + except IndexError: raise ValueError(f'It was not possible to spawn an Agent on the available position: ' f'\n{agent_name[agent_name]["positions"].copy()}') if agents.by_pos(pos) and state.check_pos_validity(pos): diff --git a/marl_factory_grid/modules/destinations/constants.py b/marl_factory_grid/modules/destinations/constants.py index 5202b35..87a8e48 100644 --- a/marl_factory_grid/modules/destinations/constants.py +++ b/marl_factory_grid/modules/destinations/constants.py @@ -1,9 +1,9 @@ # Destination Env -DESTINATION = 'Destinations' -DEST_SYMBOL = 1 +DESTINATION = 'Destinations' +DEST_SYMBOL = 1 -WAIT_ON_DEST = 'WAIT' +WAIT_ON_DEST = 'WAIT' MODE_SINGLE = 'SINGLE' MODE_GROUPED = 'GROUPED' diff --git a/marl_factory_grid/modules/doors/rules.py b/marl_factory_grid/modules/doors/rules.py index 282cb57..babe61f 100644 --- a/marl_factory_grid/modules/doors/rules.py +++ b/marl_factory_grid/modules/doors/rules.py @@ -17,7 +17,7 @@ class DoorAutoClose(Rule): doors_that_ticked = [key for key, val in doors_tick_result.items() if val] state.print(f'{doors_that_ticked} were auto-closed' if doors_that_ticked else 'No Doors were auto-closed') - return [TickResult(self.name, validity=c.VALID, value=0)] + return [TickResult(self.name, validity=c.VALID, value=1)] state.print('There are no doors, but you loaded the corresponding Module') return [] diff --git a/marl_factory_grid/quickstart.py b/marl_factory_grid/quickstart.py index d07c3d9..7e44610 100644 --- a/marl_factory_grid/quickstart.py +++ b/marl_factory_grid/quickstart.py @@ -17,4 +17,3 @@ def init(): shutil.copytree(template_path, cwd) print(f'Templates copied to {cwd}"/"{template_path.name}') print(':wave:') - From 9420986230deb13ea2ae569141a84e1d8f3ff0b5 Mon Sep 17 00:00:00 2001 From: Steffen Illium Date: Tue, 24 Oct 2023 13:40:45 +0200 Subject: [PATCH 2/2] random_testrun.py added as starting point and eval. setting for dev. --- random_testrun.py | 60 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 random_testrun.py diff --git a/random_testrun.py b/random_testrun.py new file mode 100644 index 0000000..9bebf17 --- /dev/null +++ b/random_testrun.py @@ -0,0 +1,60 @@ +from pathlib import Path +from random import randint +from tqdm import trange + +from marl_factory_grid.environment.factory import Factory + +from marl_factory_grid.utils.logging.envmonitor import EnvMonitor +from marl_factory_grid.utils.logging.recorder import EnvRecorder +from marl_factory_grid.utils.tools import ConfigExplainer + + +if __name__ == '__main__': + # Render at each step? + render = True + # Reveal all possible Modules (Entities, Rules, Agents[Actions, Observations], etc.) + explain_config = False + # Collect statistics? + monitor = False + # Record as Protobuf? + record = False + + run_path = Path('study_out') + + if explain_config: + ce = ConfigExplainer() + ce.save_all(run_path / 'all_out.yaml') + + # Path to config File + path = Path('marl_factory_grid/configs/narrow_corridor.yaml') + + # Env Init + factory = Factory(path) + + # Record and Monitor + if monitor: + factory = EnvMonitor(factory) + if record: + factory = EnvRecorder(factory) + + # RL learn Loop + for episode in trange(500): + _ = factory.reset() + done = False + if render: + factory.render() + action_spaces = factory.action_space + while not done: + a = [randint(0, x.n - 1) for x in action_spaces] + obs_type, _, _, done, info = factory.step(a) + if render: + factory.render() + if done: + print(f'Episode {episode} done...') + break + + if monitor: + factory.save_run(run_path / 'test.pkl') + if record: + factory.save_records(run_path / 'test.pb') + print('Done!!! Goodbye....')