From 2cbd92082f8ffb23ec48992889aa2bc8b1595a53 Mon Sep 17 00:00:00 2001 From: Matteo Bettini Date: Tue, 31 Oct 2023 16:54:53 +0000 Subject: [PATCH 1/3] temp --- benchmarl/conf/task/vmas/simple_reference.yaml | 5 +++++ benchmarl/environments/__init__.py | 2 ++ benchmarl/environments/vmas/common.py | 16 +++++++++++----- benchmarl/environments/vmas/simple_reference.py | 12 ++++++++++++ 4 files changed, 30 insertions(+), 5 deletions(-) create mode 100644 benchmarl/conf/task/vmas/simple_reference.yaml create mode 100644 benchmarl/environments/vmas/simple_reference.py diff --git a/benchmarl/conf/task/vmas/simple_reference.yaml b/benchmarl/conf/task/vmas/simple_reference.yaml new file mode 100644 index 00000000..459a0c61 --- /dev/null +++ b/benchmarl/conf/task/vmas/simple_reference.yaml @@ -0,0 +1,5 @@ +defaults: + - _self_ + - vmas_simple_reference_config + +max_steps: 100 diff --git a/benchmarl/environments/__init__.py b/benchmarl/environments/__init__.py index 2024889b..94e8bca2 100644 --- a/benchmarl/environments/__init__.py +++ b/benchmarl/environments/__init__.py @@ -34,6 +34,7 @@ from .vmas.balance import TaskConfig as BalanceConfig from .vmas.navigation import TaskConfig as NavigationConfig from .vmas.sampling import TaskConfig as SamplingConfig +from .vmas.simple_reference import TaskConfig as VmasSimpleReferenceConfig from .vmas.transport import TaskConfig as TransportConfig from .vmas.wheel import TaskConfig as WheelConfig @@ -47,6 +48,7 @@ "vmas_navigation_config": NavigationConfig, "vmas_transport_config": TransportConfig, "vmas_wheel_config": WheelConfig, + "vmas_simple_reference_config": VmasSimpleReferenceConfig, "pettingzoo_multiwalker_config": MultiwalkerConfig, "pettingzoo_waterworld_config": WaterworldConfig, "pettingzoo_simple_adversary_config": SimpleAdversaryConfig, diff --git a/benchmarl/environments/vmas/common.py b/benchmarl/environments/vmas/common.py index ba00c94d..4ab43890 100644 --- a/benchmarl/environments/vmas/common.py +++ b/benchmarl/environments/vmas/common.py @@ -20,6 +20,7 @@ class VmasTask(Task): NAVIGATION = None TRANSPORT = None WHEEL = None + SIMPLE_REFERENCE = None def get_env_fun( self, @@ -51,6 +52,8 @@ def max_steps(self, env: EnvBase) -> int: return self.config["max_steps"] def group_map(self, env: EnvBase) -> Dict[str, List[str]]: + if hasattr(env, "group_map"): + return env.group_map return {"agents": [agent.name for agent in env.agents]} def state_spec(self, env: EnvBase) -> Optional[CompositeSpec]: @@ -61,15 +64,18 @@ def action_mask_spec(self, env: EnvBase) -> Optional[CompositeSpec]: def observation_spec(self, env: EnvBase) -> CompositeSpec: observation_spec = env.unbatched_observation_spec.clone() - if "info" in observation_spec["agents"]: - del observation_spec[("agents", "info")] + for group in self.group_map(env): + if "info" in observation_spec[group]: + del observation_spec[(group, "info")] return observation_spec def info_spec(self, env: EnvBase) -> Optional[CompositeSpec]: info_spec = env.unbatched_observation_spec.clone() - del info_spec[("agents", "observation")] - if "info" in info_spec["agents"]: - return info_spec + for group in self.group_map(env): + del info_spec[(group, "observation")] + for group in self.group_map(env): + if "info" in info_spec[group]: + return info_spec else: return None diff --git a/benchmarl/environments/vmas/simple_reference.py b/benchmarl/environments/vmas/simple_reference.py new file mode 100644 index 00000000..d49ee5c5 --- /dev/null +++ b/benchmarl/environments/vmas/simple_reference.py @@ -0,0 +1,12 @@ +# Copyright (c) Meta Platforms, Inc. and affiliates. +# +# This source code is licensed under the license found in the +# LICENSE file in the root directory of this source tree. +# + +from dataclasses import dataclass, MISSING + + +@dataclass +class TaskConfig: + max_steps: int = MISSING From 5f73e13f2e07813d611dc5d281976751b5f7bf7d Mon Sep 17 00:00:00 2001 From: Matteo Bettini Date: Tue, 26 Dec 2023 13:38:16 +0100 Subject: [PATCH 2/3] Added VMAS MPE tasks --- .../conf/task/vmas/simple_adversary.yaml | 7 ++++++ benchmarl/conf/task/vmas/simple_crypto.yaml | 6 +++++ benchmarl/conf/task/vmas/simple_push.yaml | 5 ++++ .../task/vmas/simple_speaker_listener.yaml | 5 ++++ benchmarl/conf/task/vmas/simple_spread.yaml | 7 ++++++ benchmarl/conf/task/vmas/simple_tag.yaml | 17 +++++++++++++ .../conf/task/vmas/simple_world_comm.yaml | 10 ++++++++ benchmarl/environments/__init__.py | 16 +++++++++++++ benchmarl/environments/vmas/common.py | 7 ++++++ .../environments/vmas/simple_adverasary.py | 14 +++++++++++ benchmarl/environments/vmas/simple_crypto.py | 13 ++++++++++ benchmarl/environments/vmas/simple_push.py | 12 ++++++++++ .../vmas/simple_speaker_listener.py | 12 ++++++++++ benchmarl/environments/vmas/simple_spread.py | 14 +++++++++++ benchmarl/environments/vmas/simple_tag.py | 24 +++++++++++++++++++ .../environments/vmas/simple_world_comm.py | 17 +++++++++++++ test/test_vmas.py | 3 +-- 17 files changed, 187 insertions(+), 2 deletions(-) create mode 100644 benchmarl/conf/task/vmas/simple_adversary.yaml create mode 100644 benchmarl/conf/task/vmas/simple_crypto.yaml create mode 100644 benchmarl/conf/task/vmas/simple_push.yaml create mode 100644 benchmarl/conf/task/vmas/simple_speaker_listener.yaml create mode 100644 benchmarl/conf/task/vmas/simple_spread.yaml create mode 100644 benchmarl/conf/task/vmas/simple_tag.yaml create mode 100644 benchmarl/conf/task/vmas/simple_world_comm.yaml create mode 100644 benchmarl/environments/vmas/simple_adverasary.py create mode 100644 benchmarl/environments/vmas/simple_crypto.py create mode 100644 benchmarl/environments/vmas/simple_push.py create mode 100644 benchmarl/environments/vmas/simple_speaker_listener.py create mode 100644 benchmarl/environments/vmas/simple_spread.py create mode 100644 benchmarl/environments/vmas/simple_tag.py create mode 100644 benchmarl/environments/vmas/simple_world_comm.py diff --git a/benchmarl/conf/task/vmas/simple_adversary.yaml b/benchmarl/conf/task/vmas/simple_adversary.yaml new file mode 100644 index 00000000..a78f9467 --- /dev/null +++ b/benchmarl/conf/task/vmas/simple_adversary.yaml @@ -0,0 +1,7 @@ +defaults: + - _self_ + - vmas_simple_adversary_config + +max_steps: 100 +n_agents: 3 +n_adversaries: 1 diff --git a/benchmarl/conf/task/vmas/simple_crypto.yaml b/benchmarl/conf/task/vmas/simple_crypto.yaml new file mode 100644 index 00000000..4019dd41 --- /dev/null +++ b/benchmarl/conf/task/vmas/simple_crypto.yaml @@ -0,0 +1,6 @@ +defaults: + - _self_ + - vmas_simple_crypto_config + +max_steps: 100 +dim_c: 4 diff --git a/benchmarl/conf/task/vmas/simple_push.yaml b/benchmarl/conf/task/vmas/simple_push.yaml new file mode 100644 index 00000000..f0945f0f --- /dev/null +++ b/benchmarl/conf/task/vmas/simple_push.yaml @@ -0,0 +1,5 @@ +defaults: + - _self_ + - vmas_simple_push_config + +max_steps: 100 diff --git a/benchmarl/conf/task/vmas/simple_speaker_listener.yaml b/benchmarl/conf/task/vmas/simple_speaker_listener.yaml new file mode 100644 index 00000000..9d25fe89 --- /dev/null +++ b/benchmarl/conf/task/vmas/simple_speaker_listener.yaml @@ -0,0 +1,5 @@ +defaults: + - _self_ + - vmas_simple_speaker_listener_config + +max_steps: 100 diff --git a/benchmarl/conf/task/vmas/simple_spread.yaml b/benchmarl/conf/task/vmas/simple_spread.yaml new file mode 100644 index 00000000..1411f1e8 --- /dev/null +++ b/benchmarl/conf/task/vmas/simple_spread.yaml @@ -0,0 +1,7 @@ +defaults: + - _self_ + - vmas_simple_spread_config + +max_steps: 100 +n_agents: 3 +obs_agents: True diff --git a/benchmarl/conf/task/vmas/simple_tag.yaml b/benchmarl/conf/task/vmas/simple_tag.yaml new file mode 100644 index 00000000..59022523 --- /dev/null +++ b/benchmarl/conf/task/vmas/simple_tag.yaml @@ -0,0 +1,17 @@ +defaults: + - _self_ + - vmas_simple_tag_config + +max_steps: 100 +num_good_agents: 1 +num_adversaries: 3 +num_landmarks: 2 +shape_agent_rew: False +shape_adversary_rew: False +agents_share_rew: False +adversaries_share_rew: True +observe_same_team: True +observe_pos: True +observe_vel: True +bound: 1.0 +respawn_at_catch: False diff --git a/benchmarl/conf/task/vmas/simple_world_comm.yaml b/benchmarl/conf/task/vmas/simple_world_comm.yaml new file mode 100644 index 00000000..30d40d34 --- /dev/null +++ b/benchmarl/conf/task/vmas/simple_world_comm.yaml @@ -0,0 +1,10 @@ +defaults: + - _self_ + - vmas_simple_world_comm_config + +max_steps: 100 +num_good_agents: 2 +num_adversaries: 4 +num_landmarks: 1 +num_food: 2 +num_forests: 2 diff --git a/benchmarl/environments/__init__.py b/benchmarl/environments/__init__.py index 94e8bca2..3fcd9f35 100644 --- a/benchmarl/environments/__init__.py +++ b/benchmarl/environments/__init__.py @@ -34,10 +34,19 @@ from .vmas.balance import TaskConfig as BalanceConfig from .vmas.navigation import TaskConfig as NavigationConfig from .vmas.sampling import TaskConfig as SamplingConfig + +from .vmas.simple_adverasary import TaskConfig as VmasSimpleAdversaryConfig +from .vmas.simple_crypto import TaskConfig as VmasSimpleCryptoConfig +from .vmas.simple_push import TaskConfig as VmasSimplePushConfig from .vmas.simple_reference import TaskConfig as VmasSimpleReferenceConfig +from .vmas.simple_speaker_listener import TaskConfig as VmasSimpleSpeakerListenerConfig +from .vmas.simple_spread import TaskConfig as VmasSimpleSpreadConfig +from .vmas.simple_tag import TaskConfig as VmasSimpleTagConfig +from .vmas.simple_world_comm import TaskConfig as VmasSimpleWorldComm from .vmas.transport import TaskConfig as TransportConfig from .vmas.wheel import TaskConfig as WheelConfig + # This is a registry mapping task config schemas names to their python dataclass # It is used by hydra to validate loaded configs. # You will see the "envname_taskname_config" strings in the hydra defaults at the top of yaml files. @@ -48,7 +57,14 @@ "vmas_navigation_config": NavigationConfig, "vmas_transport_config": TransportConfig, "vmas_wheel_config": WheelConfig, + "vmas_simple_adversary_config": VmasSimpleAdversaryConfig, + "vmas_simple_crypto_config": VmasSimpleCryptoConfig, + "vmas_simple_push_config": VmasSimplePushConfig, "vmas_simple_reference_config": VmasSimpleReferenceConfig, + "vmas_simple_speaker_listener_config": VmasSimpleSpeakerListenerConfig, + "vmas_simple_spread_config": VmasSimpleSpreadConfig, + "vmas_simple_tag_config": VmasSimpleTagConfig, + "vmas_simple_world_comm_config": VmasSimpleWorldComm, "pettingzoo_multiwalker_config": MultiwalkerConfig, "pettingzoo_waterworld_config": WaterworldConfig, "pettingzoo_simple_adversary_config": SimpleAdversaryConfig, diff --git a/benchmarl/environments/vmas/common.py b/benchmarl/environments/vmas/common.py index c624164d..b6a12d52 100644 --- a/benchmarl/environments/vmas/common.py +++ b/benchmarl/environments/vmas/common.py @@ -22,7 +22,14 @@ class VmasTask(Task): NAVIGATION = None TRANSPORT = None WHEEL = None + SIMPLE_ADVERSARY = None + SIMPLE_CRYPTO = None + SIMPLE_PUSH = None SIMPLE_REFERENCE = None + SIMPLE_SPEAKER_LISTENER = None + SIMPLE_SPREAD = None + SIMPLE_TAG = None + SIMPLE_WORLD_COMM = None def get_env_fun( self, diff --git a/benchmarl/environments/vmas/simple_adverasary.py b/benchmarl/environments/vmas/simple_adverasary.py new file mode 100644 index 00000000..1dd30651 --- /dev/null +++ b/benchmarl/environments/vmas/simple_adverasary.py @@ -0,0 +1,14 @@ +# Copyright (c) Meta Platforms, Inc. and affiliates. +# +# This source code is licensed under the license found in the +# LICENSE file in the root directory of this source tree. +# + +from dataclasses import dataclass, MISSING + + +@dataclass +class TaskConfig: + max_steps: int = MISSING + n_agents: int = MISSING + n_adversaries: int = MISSING diff --git a/benchmarl/environments/vmas/simple_crypto.py b/benchmarl/environments/vmas/simple_crypto.py new file mode 100644 index 00000000..4c6d020a --- /dev/null +++ b/benchmarl/environments/vmas/simple_crypto.py @@ -0,0 +1,13 @@ +# Copyright (c) Meta Platforms, Inc. and affiliates. +# +# This source code is licensed under the license found in the +# LICENSE file in the root directory of this source tree. +# + +from dataclasses import dataclass, MISSING + + +@dataclass +class TaskConfig: + max_steps: int = MISSING + dim_c: int = MISSING diff --git a/benchmarl/environments/vmas/simple_push.py b/benchmarl/environments/vmas/simple_push.py new file mode 100644 index 00000000..d49ee5c5 --- /dev/null +++ b/benchmarl/environments/vmas/simple_push.py @@ -0,0 +1,12 @@ +# Copyright (c) Meta Platforms, Inc. and affiliates. +# +# This source code is licensed under the license found in the +# LICENSE file in the root directory of this source tree. +# + +from dataclasses import dataclass, MISSING + + +@dataclass +class TaskConfig: + max_steps: int = MISSING diff --git a/benchmarl/environments/vmas/simple_speaker_listener.py b/benchmarl/environments/vmas/simple_speaker_listener.py new file mode 100644 index 00000000..d49ee5c5 --- /dev/null +++ b/benchmarl/environments/vmas/simple_speaker_listener.py @@ -0,0 +1,12 @@ +# Copyright (c) Meta Platforms, Inc. and affiliates. +# +# This source code is licensed under the license found in the +# LICENSE file in the root directory of this source tree. +# + +from dataclasses import dataclass, MISSING + + +@dataclass +class TaskConfig: + max_steps: int = MISSING diff --git a/benchmarl/environments/vmas/simple_spread.py b/benchmarl/environments/vmas/simple_spread.py new file mode 100644 index 00000000..8a244c98 --- /dev/null +++ b/benchmarl/environments/vmas/simple_spread.py @@ -0,0 +1,14 @@ +# Copyright (c) Meta Platforms, Inc. and affiliates. +# +# This source code is licensed under the license found in the +# LICENSE file in the root directory of this source tree. +# + +from dataclasses import dataclass, MISSING + + +@dataclass +class TaskConfig: + max_steps: int = MISSING + obs_agents: bool = MISSING + n_agents: int = MISSING diff --git a/benchmarl/environments/vmas/simple_tag.py b/benchmarl/environments/vmas/simple_tag.py new file mode 100644 index 00000000..ec3b3b33 --- /dev/null +++ b/benchmarl/environments/vmas/simple_tag.py @@ -0,0 +1,24 @@ +# Copyright (c) Meta Platforms, Inc. and affiliates. +# +# This source code is licensed under the license found in the +# LICENSE file in the root directory of this source tree. +# + +from dataclasses import dataclass, MISSING + + +@dataclass +class TaskConfig: + max_steps: int = MISSING + num_good_agents: int = MISSING + num_adversaries: int = MISSING + num_landmarks: int = MISSING + shape_agent_rew: bool = MISSING + shape_adversary_rew: bool = MISSING + agents_share_rew: bool = MISSING + adversaries_share_rew: bool = MISSING + observe_same_team: bool = MISSING + observe_pos: bool = MISSING + observe_vel: bool = MISSING + bound: float = MISSING + respawn_at_catch: bool = MISSING diff --git a/benchmarl/environments/vmas/simple_world_comm.py b/benchmarl/environments/vmas/simple_world_comm.py new file mode 100644 index 00000000..d081b6bf --- /dev/null +++ b/benchmarl/environments/vmas/simple_world_comm.py @@ -0,0 +1,17 @@ +# Copyright (c) Meta Platforms, Inc. and affiliates. +# +# This source code is licensed under the license found in the +# LICENSE file in the root directory of this source tree. +# + +from dataclasses import dataclass, MISSING + + +@dataclass +class TaskConfig: + max_steps: int = MISSING + num_good_agents: int = MISSING + num_adversaries: int = MISSING + num_landmarks: int = MISSING + num_food: int = MISSING + num_forests: int = MISSING diff --git a/test/test_vmas.py b/test/test_vmas.py index 9cad58ea..b88534cb 100644 --- a/test/test_vmas.py +++ b/test/test_vmas.py @@ -13,7 +13,6 @@ IppoConfig, IsacConfig, MaddpgConfig, - MappoConfig, MasacConfig, QmixConfig, VdnConfig, @@ -57,7 +56,7 @@ def test_all_algos( ) experiment.run() - @pytest.mark.parametrize("algo_config", [MappoConfig, QmixConfig]) + @pytest.mark.parametrize("algo_config", [IppoConfig, MasacConfig]) @pytest.mark.parametrize("task", list(VmasTask)) def test_all_tasks( self, From fe7fb188c6142aedf60df39b70cb64eceb2d48fc Mon Sep 17 00:00:00 2001 From: Matteo Bettini Date: Tue, 26 Dec 2023 13:55:41 +0100 Subject: [PATCH 3/3] Install vmas main --- .github/unittest/install_vmas.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/unittest/install_vmas.sh b/.github/unittest/install_vmas.sh index 86c7ebf4..2789fcf6 100644 --- a/.github/unittest/install_vmas.sh +++ b/.github/unittest/install_vmas.sh @@ -1,4 +1,4 @@ -python -m pip install vmas +python -m pip install git+https://github.com/proroklab/VectorizedMultiAgentSimulator.git sudo apt-get update sudo apt-get install python3-opengl xvfb