multi-agent-rlenv 3.7.2__tar.gz → 3.7.4__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. multi_agent_rlenv-3.7.4/PKG-INFO +156 -0
  2. multi_agent_rlenv-3.7.4/README.md +117 -0
  3. {multi_agent_rlenv-3.7.2 → multi_agent_rlenv-3.7.4}/pyproject.toml +5 -6
  4. multi_agent_rlenv-3.7.4/src/marlenv/__init__.py +167 -0
  5. {multi_agent_rlenv-3.7.2 → multi_agent_rlenv-3.7.4}/src/marlenv/adapters/__init__.py +15 -0
  6. {multi_agent_rlenv-3.7.2 → multi_agent_rlenv-3.7.4}/src/marlenv/adapters/smac_adapter.py +1 -1
  7. multi_agent_rlenv-3.7.4/src/marlenv/catalog/__init__.py +51 -0
  8. {multi_agent_rlenv-3.7.2 → multi_agent_rlenv-3.7.4}/src/marlenv/models/__init__.py +11 -0
  9. {multi_agent_rlenv-3.7.2 → multi_agent_rlenv-3.7.4}/src/marlenv/models/step.py +9 -0
  10. {multi_agent_rlenv-3.7.2 → multi_agent_rlenv-3.7.4}/tests/test_adapters.py +1 -1
  11. multi_agent_rlenv-3.7.2/PKG-INFO +0 -144
  12. multi_agent_rlenv-3.7.2/README.md +0 -104
  13. multi_agent_rlenv-3.7.2/src/marlenv/__init__.py +0 -118
  14. multi_agent_rlenv-3.7.2/src/marlenv/catalog/__init__.py +0 -30
  15. {multi_agent_rlenv-3.7.2 → multi_agent_rlenv-3.7.4}/.github/workflows/ci.yaml +0 -0
  16. {multi_agent_rlenv-3.7.2 → multi_agent_rlenv-3.7.4}/.github/workflows/docs.yaml +0 -0
  17. {multi_agent_rlenv-3.7.2 → multi_agent_rlenv-3.7.4}/.gitignore +0 -0
  18. {multi_agent_rlenv-3.7.2 → multi_agent_rlenv-3.7.4}/LICENSE +0 -0
  19. {multi_agent_rlenv-3.7.2 → multi_agent_rlenv-3.7.4}/src/marlenv/adapters/gym_adapter.py +0 -0
  20. {multi_agent_rlenv-3.7.2 → multi_agent_rlenv-3.7.4}/src/marlenv/adapters/pettingzoo_adapter.py +0 -0
  21. {multi_agent_rlenv-3.7.2 → multi_agent_rlenv-3.7.4}/src/marlenv/adapters/pymarl_adapter.py +0 -0
  22. {multi_agent_rlenv-3.7.2 → multi_agent_rlenv-3.7.4}/src/marlenv/catalog/connectn/__init__.py +0 -0
  23. {multi_agent_rlenv-3.7.2 → multi_agent_rlenv-3.7.4}/src/marlenv/catalog/connectn/board.py +0 -0
  24. {multi_agent_rlenv-3.7.2 → multi_agent_rlenv-3.7.4}/src/marlenv/catalog/connectn/env.py +0 -0
  25. {multi_agent_rlenv-3.7.2 → multi_agent_rlenv-3.7.4}/src/marlenv/catalog/coordinated_grid.py +0 -0
  26. {multi_agent_rlenv-3.7.2 → multi_agent_rlenv-3.7.4}/src/marlenv/catalog/deepsea.py +0 -0
  27. {multi_agent_rlenv-3.7.2 → multi_agent_rlenv-3.7.4}/src/marlenv/catalog/matrix_game.py +0 -0
  28. {multi_agent_rlenv-3.7.2 → multi_agent_rlenv-3.7.4}/src/marlenv/catalog/two_steps.py +0 -0
  29. {multi_agent_rlenv-3.7.2 → multi_agent_rlenv-3.7.4}/src/marlenv/env_builder.py +0 -0
  30. {multi_agent_rlenv-3.7.2 → multi_agent_rlenv-3.7.4}/src/marlenv/env_pool.py +0 -0
  31. {multi_agent_rlenv-3.7.2 → multi_agent_rlenv-3.7.4}/src/marlenv/exceptions.py +0 -0
  32. {multi_agent_rlenv-3.7.2 → multi_agent_rlenv-3.7.4}/src/marlenv/mock_env.py +0 -0
  33. {multi_agent_rlenv-3.7.2 → multi_agent_rlenv-3.7.4}/src/marlenv/models/env.py +0 -0
  34. {multi_agent_rlenv-3.7.2 → multi_agent_rlenv-3.7.4}/src/marlenv/models/episode.py +0 -0
  35. {multi_agent_rlenv-3.7.2 → multi_agent_rlenv-3.7.4}/src/marlenv/models/observation.py +0 -0
  36. {multi_agent_rlenv-3.7.2 → multi_agent_rlenv-3.7.4}/src/marlenv/models/spaces.py +0 -0
  37. {multi_agent_rlenv-3.7.2 → multi_agent_rlenv-3.7.4}/src/marlenv/models/state.py +0 -0
  38. {multi_agent_rlenv-3.7.2 → multi_agent_rlenv-3.7.4}/src/marlenv/models/transition.py +0 -0
  39. {multi_agent_rlenv-3.7.2 → multi_agent_rlenv-3.7.4}/src/marlenv/py.typed +0 -0
  40. {multi_agent_rlenv-3.7.2 → multi_agent_rlenv-3.7.4}/src/marlenv/utils/__init__.py +0 -0
  41. {multi_agent_rlenv-3.7.2 → multi_agent_rlenv-3.7.4}/src/marlenv/utils/cached_property_collector.py +0 -0
  42. {multi_agent_rlenv-3.7.2 → multi_agent_rlenv-3.7.4}/src/marlenv/utils/import_placeholders.py +0 -0
  43. {multi_agent_rlenv-3.7.2 → multi_agent_rlenv-3.7.4}/src/marlenv/utils/schedule.py +0 -0
  44. {multi_agent_rlenv-3.7.2 → multi_agent_rlenv-3.7.4}/src/marlenv/wrappers/__init__.py +0 -0
  45. {multi_agent_rlenv-3.7.2 → multi_agent_rlenv-3.7.4}/src/marlenv/wrappers/action_randomizer.py +0 -0
  46. {multi_agent_rlenv-3.7.2 → multi_agent_rlenv-3.7.4}/src/marlenv/wrappers/agent_id_wrapper.py +0 -0
  47. {multi_agent_rlenv-3.7.2 → multi_agent_rlenv-3.7.4}/src/marlenv/wrappers/available_actions_mask.py +0 -0
  48. {multi_agent_rlenv-3.7.2 → multi_agent_rlenv-3.7.4}/src/marlenv/wrappers/available_actions_wrapper.py +0 -0
  49. {multi_agent_rlenv-3.7.2 → multi_agent_rlenv-3.7.4}/src/marlenv/wrappers/blind_wrapper.py +0 -0
  50. {multi_agent_rlenv-3.7.2 → multi_agent_rlenv-3.7.4}/src/marlenv/wrappers/centralised.py +0 -0
  51. {multi_agent_rlenv-3.7.2 → multi_agent_rlenv-3.7.4}/src/marlenv/wrappers/delayed_rewards.py +0 -0
  52. {multi_agent_rlenv-3.7.2 → multi_agent_rlenv-3.7.4}/src/marlenv/wrappers/last_action_wrapper.py +0 -0
  53. {multi_agent_rlenv-3.7.2 → multi_agent_rlenv-3.7.4}/src/marlenv/wrappers/paddings.py +0 -0
  54. {multi_agent_rlenv-3.7.2 → multi_agent_rlenv-3.7.4}/src/marlenv/wrappers/penalty_wrapper.py +0 -0
  55. {multi_agent_rlenv-3.7.2 → multi_agent_rlenv-3.7.4}/src/marlenv/wrappers/potential_shaping.py +0 -0
  56. {multi_agent_rlenv-3.7.2 → multi_agent_rlenv-3.7.4}/src/marlenv/wrappers/rlenv_wrapper.py +0 -0
  57. {multi_agent_rlenv-3.7.2 → multi_agent_rlenv-3.7.4}/src/marlenv/wrappers/state_counter.py +0 -0
  58. {multi_agent_rlenv-3.7.2 → multi_agent_rlenv-3.7.4}/src/marlenv/wrappers/time_limit.py +0 -0
  59. {multi_agent_rlenv-3.7.2 → multi_agent_rlenv-3.7.4}/src/marlenv/wrappers/video_recorder.py +0 -0
  60. {multi_agent_rlenv-3.7.2 → multi_agent_rlenv-3.7.4}/tests/__init__.py +0 -0
  61. {multi_agent_rlenv-3.7.2 → multi_agent_rlenv-3.7.4}/tests/test_catalog.py +0 -0
  62. {multi_agent_rlenv-3.7.2 → multi_agent_rlenv-3.7.4}/tests/test_deepsea.py +0 -0
  63. {multi_agent_rlenv-3.7.2 → multi_agent_rlenv-3.7.4}/tests/test_episode.py +0 -0
  64. {multi_agent_rlenv-3.7.2 → multi_agent_rlenv-3.7.4}/tests/test_models.py +0 -0
  65. {multi_agent_rlenv-3.7.2 → multi_agent_rlenv-3.7.4}/tests/test_others.py +0 -0
  66. {multi_agent_rlenv-3.7.2 → multi_agent_rlenv-3.7.4}/tests/test_pool.py +0 -0
  67. {multi_agent_rlenv-3.7.2 → multi_agent_rlenv-3.7.4}/tests/test_schedules.py +0 -0
  68. {multi_agent_rlenv-3.7.2 → multi_agent_rlenv-3.7.4}/tests/test_serialization.py +0 -0
  69. {multi_agent_rlenv-3.7.2 → multi_agent_rlenv-3.7.4}/tests/test_spaces.py +0 -0
  70. {multi_agent_rlenv-3.7.2 → multi_agent_rlenv-3.7.4}/tests/test_wrappers.py +0 -0
  71. {multi_agent_rlenv-3.7.2 → multi_agent_rlenv-3.7.4}/tests/utils.py +0 -0
@@ -0,0 +1,156 @@
1
+ Metadata-Version: 2.4
2
+ Name: multi-agent-rlenv
3
+ Version: 3.7.4
4
+ Summary: A strongly typed Multi-Agent Reinforcement Learning framework
5
+ Project-URL: repository, https://github.com/yamoling/multi-agent-rlenv
6
+ Author-email: Yannick Molinghen <yannick.molinghen@ulb.be>
7
+ License-File: LICENSE
8
+ Classifier: Operating System :: OS Independent
9
+ Classifier: Programming Language :: Python :: 3
10
+ Requires-Python: <4,>=3.12
11
+ Requires-Dist: numpy>=2.0.0
12
+ Requires-Dist: opencv-python>=4.0
13
+ Requires-Dist: typing-extensions>=4.0
14
+ Provides-Extra: all
15
+ Requires-Dist: gymnasium>0.29.1; extra == 'all'
16
+ Requires-Dist: laser-learning-environment>=2.6.1; extra == 'all'
17
+ Requires-Dist: overcooked>=0.1.0; extra == 'all'
18
+ Requires-Dist: pettingzoo>=1.20; extra == 'all'
19
+ Requires-Dist: pymunk>=6.0; extra == 'all'
20
+ Requires-Dist: scipy>=1.10; extra == 'all'
21
+ Requires-Dist: smacv2; extra == 'all'
22
+ Requires-Dist: torch>=2.0; extra == 'all'
23
+ Provides-Extra: gym
24
+ Requires-Dist: gymnasium>=0.29.1; extra == 'gym'
25
+ Provides-Extra: lle
26
+ Requires-Dist: laser-learning-environment>=2.6.1; extra == 'lle'
27
+ Provides-Extra: overcooked
28
+ Requires-Dist: overcooked>=0.1.0; extra == 'overcooked'
29
+ Provides-Extra: pettingzoo
30
+ Requires-Dist: pettingzoo>=1.20; extra == 'pettingzoo'
31
+ Requires-Dist: pymunk>=6.0; extra == 'pettingzoo'
32
+ Requires-Dist: scipy>=1.10; extra == 'pettingzoo'
33
+ Provides-Extra: smac
34
+ Requires-Dist: pysc2; extra == 'smac'
35
+ Requires-Dist: smacv2; extra == 'smac'
36
+ Provides-Extra: torch
37
+ Requires-Dist: torch>=2.0; extra == 'torch'
38
+ Description-Content-Type: text/markdown
39
+
40
+ # `marlenv` - A unified framework for muti-agent reinforcement learning
41
+ **Documentation: [https://yamoling.github.io/multi-agent-rlenv](https://yamoling.github.io/multi-agent-rlenv)**
42
+
43
+ `marlenv` is a strongly typed library for multi-agent and multi-objective reinforcement learning.
44
+
45
+ Install the library with
46
+ ```sh
47
+ $ pip install multi-agent-rlenv # Basics
48
+ $ pip install multi-agent-rlenv[all] # With all optional dependecies
49
+ $ pip install multi-agent-rlenv[smac,overcooked] # Only SMACv2 & Overcooked
50
+ ```
51
+
52
+ It aims to provide a simple and consistent interface for reinforcement learning environments by providing abstraction models such as `Observation`s or `Episode`s. `marlenv` provides adapters for popular libraries such as `gym` or `pettingzoo` and provides utility wrappers to add functionalities such as video recording or limiting the number of steps.
53
+
54
+ Almost every class is a dataclass to enable seemless serialiation with the `orjson` library.
55
+
56
+ # Fundamentals
57
+ ## States & Observations
58
+ `MARLEnv.reset()` returns a pair of `(Observation, State)` and `MARLEnv.step()` returns a `Step`.
59
+
60
+ - `Observation` contains:
61
+ - `data`: shape `[n_agents, *observation_shape]`
62
+ - `available_actions`: boolean mask `[n_agents, n_actions]`
63
+ - `extras`: extra features per agent (default shape `(n_agents, 0)`)
64
+ - `State` represents the environment state and can also carry `extras`.
65
+ - `Step` bundles `obs`, `state`, `reward`, `done`, `truncated`, and `info`.
66
+
67
+ Rewards are stored as `np.float32` arrays. Multi-objective envs use reward vectors with `reward_space.size > 1`.
68
+
69
+ ## Extras
70
+ Extras are auxiliary features appended by wrappers (agent id, last action, time ratio, available actions, ...).
71
+ Wrappers that add extras must update both `extras_shape` and `extras_meanings` so downstream users can interpret them.
72
+ `State` extras should stay in sync with `Observation` extras when applicable.
73
+
74
+ # Environment catalog
75
+ `marlenv.catalog` exposes curated environments and lazily imports optional dependencies.
76
+
77
+ ```python
78
+ from marlenv import catalog
79
+
80
+ env1 = catalog.overcooked().from_layout("scenario4")
81
+ env2 = catalog.lle().level(6)
82
+ env3 = catalog.DeepSea(mex_depth=5)
83
+ ```
84
+
85
+ Catalog entries require their corresponding extras at install time (e.g., `marlenv[overcooked]`, `marlenv[lle]`).
86
+
87
+ # Wrappers & builders
88
+ Wrappers are composable through `RLEnvWrapper` and can be chained via `Builder` for fluent configuration.
89
+
90
+ ```python
91
+ from marlenv import Builder
92
+ from marlenv.adapters import SMAC
93
+
94
+ env = (
95
+ Builder(SMAC("3m"))
96
+ .agent_id()
97
+ .time_limit(20)
98
+ .available_actions()
99
+ .build()
100
+ )
101
+ ```
102
+
103
+ Common wrappers include time limits, delayed rewards, masking available actions, and video recording.
104
+
105
+ # Using the library
106
+ ## Adapters for existing libraries
107
+ Adapters normalize external APIs into `MARLEnv`:
108
+
109
+ ```python
110
+ import marlenv
111
+
112
+ gym_env = marlenv.make("CartPole-v1", seed=25)
113
+
114
+ from marlenv.adapters import SMAC
115
+ smac_env = SMAC("3m", debug=True, difficulty="9")
116
+
117
+ from pettingzoo.sisl import pursuit_v4
118
+ from marlenv.adapters import PettingZoo
119
+ env = PettingZoo(pursuit_v4.parallel_env())
120
+ ```
121
+
122
+ ## Designing a custom environment
123
+ Create a custom environment by inheriting from `MARLEnv` and implementing `reset`, `step`, `get_observation`, and `get_state`.
124
+
125
+ ```python
126
+ import numpy as np
127
+ from marlenv import MARLEnv, DiscreteSpace, Observation, State, Step
128
+
129
+ class CustomEnv(MARLEnv[DiscreteSpace]):
130
+ def __init__(self):
131
+ super().__init__(
132
+ n_agents=3,
133
+ action_space=DiscreteSpace.action(5).repeat(3),
134
+ observation_shape=(4,),
135
+ state_shape=(2,),
136
+ )
137
+ self.t = 0
138
+
139
+ def reset(self):
140
+ self.t = 0
141
+ return self.get_observation(), self.get_state()
142
+
143
+ def step(self, action):
144
+ self.t += 1
145
+ return Step(self.get_observation(), self.get_state(), reward=0.0, done=False)
146
+
147
+ def get_observation(self):
148
+ return Observation(np.zeros((3, 4), dtype=np.float32), self.available_actions())
149
+
150
+ def get_state(self):
151
+ return State(np.array([self.t, 0], dtype=np.float32))
152
+ ```
153
+
154
+ # Related projects
155
+ - MARL: Collection of multi-agent reinforcement learning algorithms based on `marlenv` [https://github.com/yamoling/marl](https://github.com/yamoling/marl)
156
+ - Laser Learning Environment: a multi-agent gridworld that leverages `marlenv`'s capabilities [https://pypi.org/project/laser-learning-environment/](https://pypi.org/project/laser-learning-environment/)
@@ -0,0 +1,117 @@
1
+ # `marlenv` - A unified framework for muti-agent reinforcement learning
2
+ **Documentation: [https://yamoling.github.io/multi-agent-rlenv](https://yamoling.github.io/multi-agent-rlenv)**
3
+
4
+ `marlenv` is a strongly typed library for multi-agent and multi-objective reinforcement learning.
5
+
6
+ Install the library with
7
+ ```sh
8
+ $ pip install multi-agent-rlenv # Basics
9
+ $ pip install multi-agent-rlenv[all] # With all optional dependecies
10
+ $ pip install multi-agent-rlenv[smac,overcooked] # Only SMACv2 & Overcooked
11
+ ```
12
+
13
+ It aims to provide a simple and consistent interface for reinforcement learning environments by providing abstraction models such as `Observation`s or `Episode`s. `marlenv` provides adapters for popular libraries such as `gym` or `pettingzoo` and provides utility wrappers to add functionalities such as video recording or limiting the number of steps.
14
+
15
+ Almost every class is a dataclass to enable seemless serialiation with the `orjson` library.
16
+
17
+ # Fundamentals
18
+ ## States & Observations
19
+ `MARLEnv.reset()` returns a pair of `(Observation, State)` and `MARLEnv.step()` returns a `Step`.
20
+
21
+ - `Observation` contains:
22
+ - `data`: shape `[n_agents, *observation_shape]`
23
+ - `available_actions`: boolean mask `[n_agents, n_actions]`
24
+ - `extras`: extra features per agent (default shape `(n_agents, 0)`)
25
+ - `State` represents the environment state and can also carry `extras`.
26
+ - `Step` bundles `obs`, `state`, `reward`, `done`, `truncated`, and `info`.
27
+
28
+ Rewards are stored as `np.float32` arrays. Multi-objective envs use reward vectors with `reward_space.size > 1`.
29
+
30
+ ## Extras
31
+ Extras are auxiliary features appended by wrappers (agent id, last action, time ratio, available actions, ...).
32
+ Wrappers that add extras must update both `extras_shape` and `extras_meanings` so downstream users can interpret them.
33
+ `State` extras should stay in sync with `Observation` extras when applicable.
34
+
35
+ # Environment catalog
36
+ `marlenv.catalog` exposes curated environments and lazily imports optional dependencies.
37
+
38
+ ```python
39
+ from marlenv import catalog
40
+
41
+ env1 = catalog.overcooked().from_layout("scenario4")
42
+ env2 = catalog.lle().level(6)
43
+ env3 = catalog.DeepSea(mex_depth=5)
44
+ ```
45
+
46
+ Catalog entries require their corresponding extras at install time (e.g., `marlenv[overcooked]`, `marlenv[lle]`).
47
+
48
+ # Wrappers & builders
49
+ Wrappers are composable through `RLEnvWrapper` and can be chained via `Builder` for fluent configuration.
50
+
51
+ ```python
52
+ from marlenv import Builder
53
+ from marlenv.adapters import SMAC
54
+
55
+ env = (
56
+ Builder(SMAC("3m"))
57
+ .agent_id()
58
+ .time_limit(20)
59
+ .available_actions()
60
+ .build()
61
+ )
62
+ ```
63
+
64
+ Common wrappers include time limits, delayed rewards, masking available actions, and video recording.
65
+
66
+ # Using the library
67
+ ## Adapters for existing libraries
68
+ Adapters normalize external APIs into `MARLEnv`:
69
+
70
+ ```python
71
+ import marlenv
72
+
73
+ gym_env = marlenv.make("CartPole-v1", seed=25)
74
+
75
+ from marlenv.adapters import SMAC
76
+ smac_env = SMAC("3m", debug=True, difficulty="9")
77
+
78
+ from pettingzoo.sisl import pursuit_v4
79
+ from marlenv.adapters import PettingZoo
80
+ env = PettingZoo(pursuit_v4.parallel_env())
81
+ ```
82
+
83
+ ## Designing a custom environment
84
+ Create a custom environment by inheriting from `MARLEnv` and implementing `reset`, `step`, `get_observation`, and `get_state`.
85
+
86
+ ```python
87
+ import numpy as np
88
+ from marlenv import MARLEnv, DiscreteSpace, Observation, State, Step
89
+
90
+ class CustomEnv(MARLEnv[DiscreteSpace]):
91
+ def __init__(self):
92
+ super().__init__(
93
+ n_agents=3,
94
+ action_space=DiscreteSpace.action(5).repeat(3),
95
+ observation_shape=(4,),
96
+ state_shape=(2,),
97
+ )
98
+ self.t = 0
99
+
100
+ def reset(self):
101
+ self.t = 0
102
+ return self.get_observation(), self.get_state()
103
+
104
+ def step(self, action):
105
+ self.t += 1
106
+ return Step(self.get_observation(), self.get_state(), reward=0.0, done=False)
107
+
108
+ def get_observation(self):
109
+ return Observation(np.zeros((3, 4), dtype=np.float32), self.available_actions())
110
+
111
+ def get_state(self):
112
+ return State(np.array([self.t, 0], dtype=np.float32))
113
+ ```
114
+
115
+ # Related projects
116
+ - MARL: Collection of multi-agent reinforcement learning algorithms based on `marlenv` [https://github.com/yamoling/marl](https://github.com/yamoling/marl)
117
+ - Laser Learning Environment: a multi-agent gridworld that leverages `marlenv`'s capabilities [https://pypi.org/project/laser-learning-environment/](https://pypi.org/project/laser-learning-environment/)
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "multi-agent-rlenv"
3
- version = "3.7.2"
3
+ version = "3.7.4"
4
4
  description = "A strongly typed Multi-Agent Reinforcement Learning framework"
5
5
  authors = [
6
6
  { "name" = "Yannick Molinghen", "email" = "yannick.molinghen@ulb.be" },
@@ -17,7 +17,7 @@ dependencies = ["numpy>=2.0.0", "opencv-python>=4.0", "typing_extensions>=4.0"]
17
17
 
18
18
  [project.optional-dependencies]
19
19
  gym = ["gymnasium>=0.29.1"]
20
- smac = ["smac", "pysc2"]
20
+ smac = ["smacv2", "pysc2"]
21
21
  pettingzoo = ["pettingzoo>=1.20", "pymunk>=6.0", "scipy>=1.10"]
22
22
  overcooked = ["overcooked>=0.1.0"]
23
23
  lle = ["laser-learning-environment>=2.6.1"]
@@ -26,8 +26,7 @@ all = [
26
26
  "gymnasium>0.29.1",
27
27
  "pettingzoo>=1.20",
28
28
  "overcooked>=0.1.0",
29
- "smac",
30
- "pysc2",
29
+ "smacv2",
31
30
  "laser-learning-environment>=2.6.1",
32
31
  "pymunk>=6.0",
33
32
  "scipy>=1.10",
@@ -52,8 +51,8 @@ pythonpath = "src"
52
51
  filterwarnings = "ignore::DeprecationWarning"
53
52
 
54
53
  [tool.uv.sources]
55
- smac = { git = "https://github.com/oxwhirl/smac.git" }
56
- pysc2 = { git = "https://github.com/google-deepmind/pysc2.git" }
54
+ smacv2 = { git = "https://github.com/oxwhirl/smacv2.git", rev = "577ab5a" }
55
+ pysc2 = { git = "https://github.com/google-deepmind/pysc2.git", rev = "0df53d3" }
57
56
 
58
57
 
59
58
  [dependency-groups]
@@ -0,0 +1,167 @@
1
+ """
2
+ `marlenv` is a strongly typed library for multi-agent and multi-objective reinforcement learning.
3
+
4
+ Install the library with
5
+ ```sh
6
+ $ pip install multi-agent-rlenv # Basics
7
+ $ pip install multi-agent-rlenv[all] # With all optional dependecies
8
+ $ pip install multi-agent-rlenv[smac,overcooked] # Only SMACv2 & Overcooked
9
+ ```
10
+
11
+ It aims to provide a simple and consistent interface for reinforcement learning environments by providing abstraction models such as `Observation`s or `Episode`s. `marlenv` provides adapters for popular libraries such as `gym` or `pettingzoo` and provides utility wrappers to add functionalities such as video recording or limiting the number of steps.
12
+
13
+ Almost every class is a dataclass to enable seemless serialiation with the `orjson` library.
14
+
15
+ # Fundamentals
16
+ ## States & Observations
17
+ `MARLEnv.reset()` returns a pair of `(Observation, State)` and `MARLEnv.step()` returns a `Step`.
18
+
19
+ - `Observation` contains:
20
+ - `data`: shape `[n_agents, *observation_shape]`
21
+ - `available_actions`: boolean mask `[n_agents, n_actions]`
22
+ - `extras`: extra features per agent (default shape `(n_agents, 0)`)
23
+ - `State` represents the environment state and can also carry `extras`.
24
+ - `Step` bundles `obs`, `state`, `reward`, `done`, `truncated`, and `info`.
25
+
26
+ Rewards are stored as `np.float32` arrays. Multi-objective envs use reward vectors with `reward_space.size > 1`.
27
+
28
+ ## Extras
29
+ Extras are auxiliary features appended by wrappers (agent id, last action, time ratio, available actions, ...).
30
+ Wrappers that add extras must update both `extras_shape` and `extras_meanings` so downstream users can interpret them.
31
+ `State` extras should stay in sync with `Observation` extras when applicable.
32
+
33
+ # Environment catalog
34
+ `marlenv.catalog` exposes curated environments and lazily imports optional dependencies.
35
+
36
+ ```python
37
+ from marlenv import catalog
38
+
39
+ env1 = catalog.overcooked().from_layout("scenario4")
40
+ env2 = catalog.lle().level(6)
41
+ env3 = catalog.DeepSea(mex_depth=5)
42
+ ```
43
+
44
+ Catalog entries require their corresponding extras at install time (e.g., `marlenv[overcooked]`, `marlenv[lle]`).
45
+
46
+ # Wrappers & builders
47
+ Wrappers are composable through `RLEnvWrapper` and can be chained via `Builder` for fluent configuration.
48
+
49
+ ```python
50
+ from marlenv import Builder
51
+ from marlenv.adapters import SMAC
52
+
53
+ env = (
54
+ Builder(SMAC("3m"))
55
+ .agent_id()
56
+ .time_limit(20)
57
+ .available_actions()
58
+ .build()
59
+ )
60
+ ```
61
+
62
+ Common wrappers include time limits, delayed rewards, masking available actions, and video recording.
63
+
64
+ # Using the library
65
+ ## Adapters for existing libraries
66
+ Adapters normalize external APIs into `MARLEnv`:
67
+
68
+ ```python
69
+ import marlenv
70
+
71
+ gym_env = marlenv.make("CartPole-v1", seed=25)
72
+
73
+ from marlenv.adapters import SMAC
74
+ smac_env = SMAC("3m", debug=True, difficulty="9")
75
+
76
+ from pettingzoo.sisl import pursuit_v4
77
+ from marlenv.adapters import PettingZoo
78
+ env = PettingZoo(pursuit_v4.parallel_env())
79
+ ```
80
+
81
+ ## Designing a custom environment
82
+ Create a custom environment by inheriting from `MARLEnv` and implementing `reset`, `step`, `get_observation`, and `get_state`.
83
+
84
+ ```python
85
+ import numpy as np
86
+ from marlenv import MARLEnv, DiscreteSpace, Observation, State, Step
87
+
88
+ class CustomEnv(MARLEnv[DiscreteSpace]):
89
+ def __init__(self):
90
+ super().__init__(
91
+ n_agents=3,
92
+ action_space=DiscreteSpace.action(5).repeat(3),
93
+ observation_shape=(4,),
94
+ state_shape=(2,),
95
+ )
96
+ self.t = 0
97
+
98
+ def reset(self):
99
+ self.t = 0
100
+ return self.get_observation(), self.get_state()
101
+
102
+ def step(self, action):
103
+ self.t += 1
104
+ return Step(self.get_observation(), self.get_state(), reward=0.0, done=False)
105
+
106
+ def get_observation(self):
107
+ return Observation(np.zeros((3, 4), dtype=np.float32), self.available_actions())
108
+
109
+ def get_state(self):
110
+ return State(np.array([self.t, 0], dtype=np.float32))
111
+ ```
112
+ """
113
+
114
+ from importlib.metadata import version, PackageNotFoundError
115
+
116
+ try:
117
+ __version__ = version("multi-agent-rlenv")
118
+ except PackageNotFoundError:
119
+ __version__ = "0.0.0" # fallback for CI
120
+
121
+
122
+ from . import models
123
+ from .models import (
124
+ spaces,
125
+ MARLEnv,
126
+ State,
127
+ Step,
128
+ Observation,
129
+ Episode,
130
+ Transition,
131
+ DiscreteSpace,
132
+ ContinuousSpace,
133
+ Space,
134
+ MultiDiscreteSpace,
135
+ )
136
+
137
+
138
+ from . import wrappers
139
+ from . import adapters
140
+ from .env_builder import Builder
141
+ from .wrappers import RLEnvWrapper
142
+ from .mock_env import DiscreteMockEnv, DiscreteMOMockEnv
143
+ from . import catalog
144
+ from .adapters import make
145
+
146
+ __all__ = [
147
+ "models",
148
+ "make",
149
+ "catalog",
150
+ "wrappers",
151
+ "adapters",
152
+ "spaces",
153
+ "Builder",
154
+ "MARLEnv",
155
+ "Step",
156
+ "State",
157
+ "Observation",
158
+ "Episode",
159
+ "Transition",
160
+ "DiscreteSpace",
161
+ "ContinuousSpace",
162
+ "DiscreteMockEnv",
163
+ "DiscreteMOMockEnv",
164
+ "RLEnvWrapper",
165
+ "Space",
166
+ "MultiDiscreteSpace",
167
+ ]
@@ -1,3 +1,18 @@
1
+ """
2
+ Adapters for external RL libraries.
3
+
4
+ This submodule provides optional wrappers that normalize third-party APIs into
5
+ `MARLEnv`. Adapters are imported lazily via `try/except` so the base install
6
+ remains lightweight. The availability flags (`HAS_GYM`, `HAS_PETTINGZOO`,
7
+ `HAS_SMAC`) reflect whether the corresponding extra was installed.
8
+
9
+ Install extras to enable adapters with `uv` or `pip`:
10
+ - `multi-agent-rlenv[all]` for all optional dependencies
11
+ - `multi-agent-rlenv[gym]` for Gymnasium
12
+ - `multi-agent-rlenv[pettingzoo]` for PettingZoo
13
+ - `multi-agent-rlenv[smac]` for SMAC
14
+ """
15
+
1
16
  from .pymarl_adapter import PymarlAdapter
2
17
  from marlenv.utils import dummy_function
3
18
 
@@ -3,7 +3,7 @@ from typing import overload
3
3
 
4
4
  import numpy as np
5
5
  import numpy.typing as npt
6
- from smac.env import StarCraft2Env # pyright: ignore[reportMissingImports]
6
+ from smacv2.env import StarCraft2Env
7
7
 
8
8
  from marlenv.models import MARLEnv, Observation, State, Step, MultiDiscreteSpace, DiscreteSpace
9
9
 
@@ -0,0 +1,51 @@
1
+ """
2
+ Environment catalog for `marlenv`.
3
+
4
+ This submodule exposes curated environments and provides lazy imports for optional
5
+ dependencies to keep the base install lightweight. Use the catalog to construct
6
+ environments without importing their packages directly.
7
+
8
+ Examples:
9
+ ```python
10
+ from marlenv import catalog
11
+
12
+ env1 = catalog.DeepSea(mex_depth=5)
13
+ env2 = catalog.CoordinatedGrid()
14
+ env3 = catalog.connect_n()(width=7, height=6, n_to_connect=4)
15
+ env4 = catalog.smac()("3m")
16
+ ```
17
+
18
+ Optional entries such as `smac`, `lle`, and `overcooked` require installing their
19
+ corresponding extras (e.g., `marlenv[smac]`, `marlenv[lle]`, `marlenv[overcooked]`).
20
+ """
21
+
22
+ from .deepsea import DeepSea
23
+ from .matrix_game import MatrixGame
24
+ from .coordinated_grid import CoordinatedGrid
25
+
26
+
27
+ __all__ = ["smac", "DeepSea", "lle", "overcooked", "MatrixGame", "connect_n", "CoordinatedGrid"]
28
+
29
+
30
+ def smac():
31
+ from marlenv.adapters import SMAC
32
+
33
+ return SMAC
34
+
35
+
36
+ def lle():
37
+ from lle import LLE # pyright: ignore[reportMissingImports]
38
+
39
+ return LLE
40
+
41
+
42
+ def overcooked():
43
+ from overcooked import Overcooked # pyright: ignore[reportMissingImports]
44
+
45
+ return Overcooked
46
+
47
+
48
+ def connect_n():
49
+ from .connectn import ConnectN
50
+
51
+ return ConnectN
@@ -1,3 +1,14 @@
1
+ """
2
+ Core data models for the `marlenv` API.
3
+
4
+ This package defines the typed containers and interfaces shared across adapters,
5
+ wrappers, and environments:
6
+ - `MARLEnv`: the abstract environment contract.
7
+ - `Observation` / `State`: structured inputs to agents and state tracking.
8
+ - `Step` / `Transition` / `Episode`: execution results and replayable logs.
9
+ - `Space` variants: action/reward space definitions.
10
+ """
11
+
1
12
  from .spaces import DiscreteSpace, ContinuousSpace, MultiDiscreteSpace, Space
2
13
  from .observation import Observation
3
14
  from .step import Step
@@ -9,6 +9,15 @@ from .state import State
9
9
 
10
10
  @dataclass
11
11
  class Step:
12
+ """
13
+ The result of performing a step in the environment:
14
+ - the new observation
15
+ - the new state
16
+ - the reward received for the step performed
17
+ - whether the episode is done or truncated
18
+ - some info (mainly for logging purposes)
19
+ """
20
+
12
21
  obs: Observation
13
22
  """The new observation (1 per agent) of the environment resulting from the agent's action."""
14
23
  state: State
@@ -114,7 +114,7 @@ def _check_env_3m(env):
114
114
 
115
115
  @pytest.mark.skipif(skip_smac, reason="SMAC is not installed")
116
116
  def test_smac_from_class():
117
- from smac.env import StarCraft2Env # pyright: ignore[reportMissingImports]
117
+ from smacv2.env import StarCraft2Env # pyright: ignore[reportMissingImports]
118
118
  from marlenv.adapters import SMAC
119
119
 
120
120
  env = SMAC(StarCraft2Env("3m"))
@@ -1,144 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: multi-agent-rlenv
3
- Version: 3.7.2
4
- Summary: A strongly typed Multi-Agent Reinforcement Learning framework
5
- Project-URL: repository, https://github.com/yamoling/multi-agent-rlenv
6
- Author-email: Yannick Molinghen <yannick.molinghen@ulb.be>
7
- License-File: LICENSE
8
- Classifier: Operating System :: OS Independent
9
- Classifier: Programming Language :: Python :: 3
10
- Requires-Python: <4,>=3.12
11
- Requires-Dist: numpy>=2.0.0
12
- Requires-Dist: opencv-python>=4.0
13
- Requires-Dist: typing-extensions>=4.0
14
- Provides-Extra: all
15
- Requires-Dist: gymnasium>0.29.1; extra == 'all'
16
- Requires-Dist: laser-learning-environment>=2.6.1; extra == 'all'
17
- Requires-Dist: overcooked>=0.1.0; extra == 'all'
18
- Requires-Dist: pettingzoo>=1.20; extra == 'all'
19
- Requires-Dist: pymunk>=6.0; extra == 'all'
20
- Requires-Dist: pysc2; extra == 'all'
21
- Requires-Dist: scipy>=1.10; extra == 'all'
22
- Requires-Dist: smac; extra == 'all'
23
- Requires-Dist: torch>=2.0; extra == 'all'
24
- Provides-Extra: gym
25
- Requires-Dist: gymnasium>=0.29.1; extra == 'gym'
26
- Provides-Extra: lle
27
- Requires-Dist: laser-learning-environment>=2.6.1; extra == 'lle'
28
- Provides-Extra: overcooked
29
- Requires-Dist: overcooked>=0.1.0; extra == 'overcooked'
30
- Provides-Extra: pettingzoo
31
- Requires-Dist: pettingzoo>=1.20; extra == 'pettingzoo'
32
- Requires-Dist: pymunk>=6.0; extra == 'pettingzoo'
33
- Requires-Dist: scipy>=1.10; extra == 'pettingzoo'
34
- Provides-Extra: smac
35
- Requires-Dist: pysc2; extra == 'smac'
36
- Requires-Dist: smac; extra == 'smac'
37
- Provides-Extra: torch
38
- Requires-Dist: torch>=2.0; extra == 'torch'
39
- Description-Content-Type: text/markdown
40
-
41
- # `marlenv` - A unified framework for muti-agent reinforcement learning
42
- **Documentation: [https://yamoling.github.io/multi-agent-rlenv](https://yamoling.github.io/multi-agent-rlenv)**
43
-
44
- The objective of `marlenv` is to provide a common (typed) interface for many different reinforcement learning environments.
45
-
46
- As such, `marlenv` provides high level abstractions of RL concepts such as `Observation`s or `Transition`s that are commonly represented as mere (confusing) lists or tuples.
47
-
48
- ## Installation
49
- Install with you preferred package manager (`uv`, `pip`, `poetry`, ...):
50
- ```bash
51
- $ pip install marlenv[all] # Enable all features
52
- $ pip install marlenv # Basic installation
53
- ```
54
-
55
- There are multiple optional dependencies if you want to support specific libraries and environments. Available options are:
56
- - `smac` for StarCraft II environments
57
- - `gym` for OpenAI Gym environments
58
- - `pettingzoo` for PettingZoo environments
59
- - `overcooked` for Overcooked environments
60
-
61
- Install them with:
62
- ```bash
63
- $ pip install marlenv[smac] # Install SMAC
64
- $ pip install marlenv[gym,smac] # Install Gym & smac support
65
- ```
66
-
67
- ## Using the `marlenv` environment catalog
68
- Some environments are registered in the `marlenv` and can be easily instantiated via its catalog.
69
-
70
- ```python
71
- from marlenv import catalog
72
-
73
- env1 = catalog.Overcooked.from_layout("scenario4")
74
- env2 = catalog.LLE.level(6)
75
- env3 = catalog.DeepSea(mex_depth=5)
76
- ```
77
- Note that using the catalog requires the corresponding environment package to be installed. For instance you need to install the `laser-learning-environment` package to use `catalog.LLE`, which can be done by using the corresponding feature when at installation as shown below.
78
- ```bash
79
- pip install multi-agent-rlenv[lle]
80
- ```
81
-
82
-
83
- ## Using `marlenv` with existing libraries
84
- `marlenv` provides adapters from most popular libraries to unify them under a single interface. Namely, `marlenv` supports `smac`, `gymnasium` and `pettingzoo`.
85
-
86
- ```python
87
- import marlenv
88
-
89
- # You can instanciate gymnasium environments directly via their registry ID
90
- gym_env = marlenv.make("CartPole-v1", seed=25)
91
-
92
- # You can seemlessly instanciate a SMAC environment and directly pass your required arguments
93
- from marlenv.adapters import SMAC
94
- smac_env = SMAC("3m", debug=True, difficulty="9")
95
-
96
- # pettingzoo is also supported
97
- from pettingzoo.sisl import pursuit_v4
98
- from marlenv.adapters import PettingZoo
99
- pz_env = PettingZoo(pursuit_v4.parallel_env())
100
- ```
101
-
102
-
103
- ## Designing custom environments
104
- You can create your own custom environment by inheriting from the `RLEnv` class. The below example illustrates a gridworld with a discrete action space. Note that other methods such as `step` or `render` must also be implemented.
105
- ```python
106
- import numpy as np
107
- from marlenv import RLEnv, DiscreteActionSpace, Observation
108
-
109
- N_AGENTS = 3
110
- N_ACTIONS = 5
111
-
112
- class CustomEnv(MARLEnv[DiscreteActionSpace]):
113
- def __init__(self, width: int, height: int):
114
- super().__init__(
115
- action_space=DiscreteActionSpace(N_AGENTS, N_ACTIONS),
116
- observation_shape=(height, width),
117
- state_shape=(1,),
118
- )
119
- self.time = 0
120
-
121
- def reset(self) -> Observation:
122
- self.time = 0
123
- ...
124
- return obs
125
-
126
- def get_state(self):
127
- return np.array([self.time])
128
- ```
129
-
130
- ## Useful wrappers
131
- `marlenv` comes with multiple common environment wrappers, check the documentation for a complete list. The preferred way of using the wrappers is through a `marlenv.Builder`. The below example shows how to add a time limit (in number of steps) and an agent id to the observations of a SMAC environment.
132
-
133
- ```python
134
- from marlenv import Builder
135
- from marlenv.adapters import SMAC
136
-
137
- env = Builder(SMAC("3m")).agent_id().time_limit(20).build()
138
- print(env.extras_shape) # -> (4, ) because there are 3 agents and the time counter
139
- ```
140
-
141
-
142
- # Related projects
143
- - MARL: Collection of multi-agent reinforcement learning algorithms based on `marlenv` [https://github.com/yamoling/marl](https://github.com/yamoling/marl)
144
- - Laser Learning Environment: a multi-agent gridworld that leverages `marlenv`'s capabilities [https://pypi.org/project/laser-learning-environment/](https://pypi.org/project/laser-learning-environment/)
@@ -1,104 +0,0 @@
1
- # `marlenv` - A unified framework for muti-agent reinforcement learning
2
- **Documentation: [https://yamoling.github.io/multi-agent-rlenv](https://yamoling.github.io/multi-agent-rlenv)**
3
-
4
- The objective of `marlenv` is to provide a common (typed) interface for many different reinforcement learning environments.
5
-
6
- As such, `marlenv` provides high level abstractions of RL concepts such as `Observation`s or `Transition`s that are commonly represented as mere (confusing) lists or tuples.
7
-
8
- ## Installation
9
- Install with you preferred package manager (`uv`, `pip`, `poetry`, ...):
10
- ```bash
11
- $ pip install marlenv[all] # Enable all features
12
- $ pip install marlenv # Basic installation
13
- ```
14
-
15
- There are multiple optional dependencies if you want to support specific libraries and environments. Available options are:
16
- - `smac` for StarCraft II environments
17
- - `gym` for OpenAI Gym environments
18
- - `pettingzoo` for PettingZoo environments
19
- - `overcooked` for Overcooked environments
20
-
21
- Install them with:
22
- ```bash
23
- $ pip install marlenv[smac] # Install SMAC
24
- $ pip install marlenv[gym,smac] # Install Gym & smac support
25
- ```
26
-
27
- ## Using the `marlenv` environment catalog
28
- Some environments are registered in the `marlenv` and can be easily instantiated via its catalog.
29
-
30
- ```python
31
- from marlenv import catalog
32
-
33
- env1 = catalog.Overcooked.from_layout("scenario4")
34
- env2 = catalog.LLE.level(6)
35
- env3 = catalog.DeepSea(mex_depth=5)
36
- ```
37
- Note that using the catalog requires the corresponding environment package to be installed. For instance you need to install the `laser-learning-environment` package to use `catalog.LLE`, which can be done by using the corresponding feature when at installation as shown below.
38
- ```bash
39
- pip install multi-agent-rlenv[lle]
40
- ```
41
-
42
-
43
- ## Using `marlenv` with existing libraries
44
- `marlenv` provides adapters from most popular libraries to unify them under a single interface. Namely, `marlenv` supports `smac`, `gymnasium` and `pettingzoo`.
45
-
46
- ```python
47
- import marlenv
48
-
49
- # You can instanciate gymnasium environments directly via their registry ID
50
- gym_env = marlenv.make("CartPole-v1", seed=25)
51
-
52
- # You can seemlessly instanciate a SMAC environment and directly pass your required arguments
53
- from marlenv.adapters import SMAC
54
- smac_env = SMAC("3m", debug=True, difficulty="9")
55
-
56
- # pettingzoo is also supported
57
- from pettingzoo.sisl import pursuit_v4
58
- from marlenv.adapters import PettingZoo
59
- pz_env = PettingZoo(pursuit_v4.parallel_env())
60
- ```
61
-
62
-
63
- ## Designing custom environments
64
- You can create your own custom environment by inheriting from the `RLEnv` class. The below example illustrates a gridworld with a discrete action space. Note that other methods such as `step` or `render` must also be implemented.
65
- ```python
66
- import numpy as np
67
- from marlenv import RLEnv, DiscreteActionSpace, Observation
68
-
69
- N_AGENTS = 3
70
- N_ACTIONS = 5
71
-
72
- class CustomEnv(MARLEnv[DiscreteActionSpace]):
73
- def __init__(self, width: int, height: int):
74
- super().__init__(
75
- action_space=DiscreteActionSpace(N_AGENTS, N_ACTIONS),
76
- observation_shape=(height, width),
77
- state_shape=(1,),
78
- )
79
- self.time = 0
80
-
81
- def reset(self) -> Observation:
82
- self.time = 0
83
- ...
84
- return obs
85
-
86
- def get_state(self):
87
- return np.array([self.time])
88
- ```
89
-
90
- ## Useful wrappers
91
- `marlenv` comes with multiple common environment wrappers, check the documentation for a complete list. The preferred way of using the wrappers is through a `marlenv.Builder`. The below example shows how to add a time limit (in number of steps) and an agent id to the observations of a SMAC environment.
92
-
93
- ```python
94
- from marlenv import Builder
95
- from marlenv.adapters import SMAC
96
-
97
- env = Builder(SMAC("3m")).agent_id().time_limit(20).build()
98
- print(env.extras_shape) # -> (4, ) because there are 3 agents and the time counter
99
- ```
100
-
101
-
102
- # Related projects
103
- - MARL: Collection of multi-agent reinforcement learning algorithms based on `marlenv` [https://github.com/yamoling/marl](https://github.com/yamoling/marl)
104
- - Laser Learning Environment: a multi-agent gridworld that leverages `marlenv`'s capabilities [https://pypi.org/project/laser-learning-environment/](https://pypi.org/project/laser-learning-environment/)
@@ -1,118 +0,0 @@
1
- """
2
- `marlenv` is a strongly typed library for multi-agent and multi-objective reinforcement learning.
3
-
4
- It aims to provide a simple and consistent interface for reinforcement learning environments by providing abstraction models such as `Observation`s or `Episode`s. `marlenv` provides adapters for popular libraries such as `gym` or `pettingzoo` and provides utility wrappers to add functionalities such as video recording or limiting the number of steps.
5
-
6
- Almost every class is a dataclassto enable seemless serialiation with the `orjson` library.
7
-
8
- # Existing environments
9
- The `MARLEnv` class represents a multi-agent RL environment and is at the center of this library, and `marlenv` provides an adapted implementation of multiple common MARL environments (gym, pettingzoo, smac and overcooked) in `marlenv.adapters`. Note that these adapters will only work if you have the corresponding library installed.
10
-
11
- ```python
12
- from marlenv.adapters import Gym, PettingZoo, SMAC, Overcooked
13
- import marlenv
14
-
15
- env1 = Gym("CartPole-v1")
16
- env2 = marlenv.make("CartPole-v1")
17
- env3 = PettingZoo("prospector_v4")
18
- env4 = SMAC("3m")
19
- env5 = Overcooked.from_layout("cramped_room")
20
- ```
21
-
22
- # Wrappers & Builder
23
- To facilitate the create of an environment with common wrappers, `marlenv` provides a `Builder` class that can be used to chain the creation of multiple wrappers.
24
-
25
- ```python
26
- from marlenv import make, Builder
27
-
28
- env = <your env>
29
- env = Builder(env).agent_id().time_limit(50).record("videos").build()
30
- ```
31
-
32
- # Using the library
33
- A typical environment loop would look like this:
34
-
35
- ```python
36
- from marlenv import DiscreteMockEnv, Builder, Episode
37
-
38
- env = Builder(DicreteMockEnv()).agent_id().build()
39
- obs, state = env.reset()
40
- terminated = False
41
- episode = Episode.new(obs, state)
42
- while not episode.is_finished:
43
- action = env.sample_action() # a valid random action
44
- step = env.step(action) # Step data `step.obs`, `step.reward`, ...
45
- episode.add(step, action) # Progressively build the episode
46
- ```
47
-
48
- # Extras
49
- To cope with complex observation spaces, `marlenv` distinguishes the "main" observation data from the "extra" observation data. A typical example would be the observation of a gridworld environment with a time limit. In that case, the main observation has shape (height, width), i.e. the content of the grid, but the current time is an extra observation data of shape (1, ).
50
-
51
- ```python
52
- env = GridWorldEnv()
53
- print(env.observation_shape) # (height, width)
54
- print(env.extras_shape) # (0, )
55
-
56
- env = Builder(env).time_limit(25).build()
57
- print(env.observation_shape) # (height, width)
58
- print(env.extras_shape) # (1, )
59
- ```
60
-
61
- # Creating a new environment
62
- If you want to create a new environment, you can simply create a class that inherits from `MARLEnv`. If you want to create a wrapper around an existing `MARLEnv`, you probably want to subclass `RLEnvWrapper` which implements a default behaviour for every method.
63
- """
64
-
65
- from importlib.metadata import version, PackageNotFoundError
66
-
67
- try:
68
- __version__ = version("multi-agent-rlenv")
69
- except PackageNotFoundError:
70
- __version__ = "0.0.0" # fallback for CI
71
-
72
-
73
- from . import models
74
- from .models import (
75
- spaces,
76
- MARLEnv,
77
- State,
78
- Step,
79
- Observation,
80
- Episode,
81
- Transition,
82
- DiscreteSpace,
83
- ContinuousSpace,
84
- Space,
85
- MultiDiscreteSpace,
86
- )
87
-
88
-
89
- from . import wrappers
90
- from . import adapters
91
- from .env_builder import Builder
92
- from .wrappers import RLEnvWrapper
93
- from .mock_env import DiscreteMockEnv, DiscreteMOMockEnv
94
- from . import catalog
95
- from .adapters import make
96
-
97
- __all__ = [
98
- "models",
99
- "make",
100
- "catalog",
101
- "wrappers",
102
- "adapters",
103
- "spaces",
104
- "Builder",
105
- "MARLEnv",
106
- "Step",
107
- "State",
108
- "Observation",
109
- "Episode",
110
- "Transition",
111
- "DiscreteSpace",
112
- "ContinuousSpace",
113
- "DiscreteMockEnv",
114
- "DiscreteMOMockEnv",
115
- "RLEnvWrapper",
116
- "Space",
117
- "MultiDiscreteSpace",
118
- ]
@@ -1,30 +0,0 @@
1
- from .deepsea import DeepSea
2
- from .matrix_game import MatrixGame
3
- from .coordinated_grid import CoordinatedGrid
4
-
5
-
6
- __all__ = ["smac", "DeepSea", "lle", "overcooked", "MatrixGame", "connect_n", "CoordinatedGrid"]
7
-
8
-
9
- def smac():
10
- from marlenv.adapters import SMAC
11
-
12
- return SMAC
13
-
14
-
15
- def lle():
16
- from lle import LLE # pyright: ignore[reportMissingImports]
17
-
18
- return LLE
19
-
20
-
21
- def overcooked():
22
- from overcooked import Overcooked # pyright: ignore[reportMissingImports]
23
-
24
- return Overcooked
25
-
26
-
27
- def connect_n():
28
- from .connectn import ConnectN
29
-
30
- return ConnectN