mosaic-multigrid 0.2.0__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.
- mosaic_multigrid-0.2.0/LICENSE +202 -0
- mosaic_multigrid-0.2.0/MANIFEST.in +5 -0
- mosaic_multigrid-0.2.0/NOTICE +15 -0
- mosaic_multigrid-0.2.0/PKG-INFO +299 -0
- mosaic_multigrid-0.2.0/README.md +259 -0
- mosaic_multigrid-0.2.0/figures/collect.png +0 -0
- mosaic_multigrid-0.2.0/figures/collect_2.png +0 -0
- mosaic_multigrid-0.2.0/figures/soccer.png +0 -0
- mosaic_multigrid-0.2.0/figures/soccer_2.png +0 -0
- mosaic_multigrid-0.2.0/figures/soccer_3.png +0 -0
- mosaic_multigrid-0.2.0/figures/soccer_4.png +0 -0
- mosaic_multigrid-0.2.0/mosaic_multigrid/__init__.py +1 -0
- mosaic_multigrid-0.2.0/mosaic_multigrid/base.py +932 -0
- mosaic_multigrid-0.2.0/mosaic_multigrid/core/__init__.py +33 -0
- mosaic_multigrid-0.2.0/mosaic_multigrid/core/actions.py +15 -0
- mosaic_multigrid-0.2.0/mosaic_multigrid/core/agent.py +311 -0
- mosaic_multigrid-0.2.0/mosaic_multigrid/core/constants.py +109 -0
- mosaic_multigrid-0.2.0/mosaic_multigrid/core/grid.py +364 -0
- mosaic_multigrid-0.2.0/mosaic_multigrid/core/mission.py +136 -0
- mosaic_multigrid-0.2.0/mosaic_multigrid/core/world_object.py +587 -0
- mosaic_multigrid-0.2.0/mosaic_multigrid/envs/__init__.py +31 -0
- mosaic_multigrid-0.2.0/mosaic_multigrid/envs/collect_game.py +183 -0
- mosaic_multigrid-0.2.0/mosaic_multigrid/envs/soccer_game.py +241 -0
- mosaic_multigrid-0.2.0/mosaic_multigrid/multigrid.py +1442 -0
- mosaic_multigrid-0.2.0/mosaic_multigrid/pettingzoo/__init__.py +164 -0
- mosaic_multigrid-0.2.0/mosaic_multigrid/rendering.py +118 -0
- mosaic_multigrid-0.2.0/mosaic_multigrid/rllib/__init__.py +136 -0
- mosaic_multigrid-0.2.0/mosaic_multigrid/utils/__init__.py +1 -0
- mosaic_multigrid-0.2.0/mosaic_multigrid/utils/enum.py +45 -0
- mosaic_multigrid-0.2.0/mosaic_multigrid/utils/misc.py +30 -0
- mosaic_multigrid-0.2.0/mosaic_multigrid/utils/obs.py +349 -0
- mosaic_multigrid-0.2.0/mosaic_multigrid/utils/random.py +64 -0
- mosaic_multigrid-0.2.0/mosaic_multigrid/utils/rendering.py +108 -0
- mosaic_multigrid-0.2.0/mosaic_multigrid/window.py +99 -0
- mosaic_multigrid-0.2.0/mosaic_multigrid/wrappers.py +209 -0
- mosaic_multigrid-0.2.0/mosaic_multigrid.egg-info/PKG-INFO +299 -0
- mosaic_multigrid-0.2.0/mosaic_multigrid.egg-info/SOURCES.txt +45 -0
- mosaic_multigrid-0.2.0/mosaic_multigrid.egg-info/dependency_links.txt +1 -0
- mosaic_multigrid-0.2.0/mosaic_multigrid.egg-info/requires.txt +15 -0
- mosaic_multigrid-0.2.0/mosaic_multigrid.egg-info/top_level.txt +1 -0
- mosaic_multigrid-0.2.0/pyproject.toml +58 -0
- mosaic_multigrid-0.2.0/setup.cfg +4 -0
- mosaic_multigrid-0.2.0/setup.py +34 -0
- mosaic_multigrid-0.2.0/tests/test_base.py +379 -0
- mosaic_multigrid-0.2.0/tests/test_core.py +435 -0
- mosaic_multigrid-0.2.0/tests/test_envs.py +275 -0
- mosaic_multigrid-0.2.0/tests/test_wrappers.py +186 -0
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
MiniGrid: Copyright 2020 Maxime Chevalier-Boisvert
|
|
190
|
+
Multi-agent Extension (MultiGrid): Copyright 2020 Arnaud Fickinger
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
mosaic_multigrid
|
|
2
|
+
Copyright 2026 Abdulhamid Mousa
|
|
3
|
+
|
|
4
|
+
This product is a derivative work based on gym-multigrid, which includes
|
|
5
|
+
the following software:
|
|
6
|
+
|
|
7
|
+
Multi-Agent Gridworld Environment (MultiGrid)
|
|
8
|
+
Copyright 2020 Arnaud Fickinger
|
|
9
|
+
https://github.com/ArnaudFickinger/gym-multigrid
|
|
10
|
+
|
|
11
|
+
MiniGrid
|
|
12
|
+
Copyright 2020 Maxime Chevalier-Boisvert
|
|
13
|
+
https://github.com/maximecb/gym-minigrid
|
|
14
|
+
|
|
15
|
+
Licensed under the Apache License, Version 2.0.
|
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: mosaic_multigrid
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: Research-grade multi-agent gridworld environments for reproducible RL experiments
|
|
5
|
+
Home-page: https://github.com/Abdulhamid97Mousa/mosaic_multigrid
|
|
6
|
+
Author: Abdulhamid Mousa
|
|
7
|
+
Author-email: Abdulhamid Mousa <abdulhamid97mousa@gmail.com>
|
|
8
|
+
License: Apache-2.0
|
|
9
|
+
Project-URL: Homepage, https://github.com/Abdulhamid97Mousa/mosaic_multigrid
|
|
10
|
+
Project-URL: Repository, https://github.com/Abdulhamid97Mousa/mosaic_multigrid
|
|
11
|
+
Keywords: reinforcement-learning,multi-agent,gymnasium,gridworld,soccer,competitive
|
|
12
|
+
Classifier: Development Status :: 3 - Alpha
|
|
13
|
+
Classifier: Intended Audience :: Science/Research
|
|
14
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
20
|
+
Requires-Python: >=3.8
|
|
21
|
+
Description-Content-Type: text/markdown
|
|
22
|
+
License-File: LICENSE
|
|
23
|
+
License-File: NOTICE
|
|
24
|
+
Requires-Dist: aenum>=1.3.0
|
|
25
|
+
Requires-Dist: numba>=0.53.0
|
|
26
|
+
Requires-Dist: numpy>=1.18.0
|
|
27
|
+
Requires-Dist: gymnasium>=0.26
|
|
28
|
+
Requires-Dist: pygame>=2.2.0
|
|
29
|
+
Provides-Extra: rllib
|
|
30
|
+
Requires-Dist: ray[rllib]>=2.0; extra == "rllib"
|
|
31
|
+
Provides-Extra: pettingzoo
|
|
32
|
+
Requires-Dist: pettingzoo>=1.22; extra == "pettingzoo"
|
|
33
|
+
Provides-Extra: dev
|
|
34
|
+
Requires-Dist: pytest>=7.0; extra == "dev"
|
|
35
|
+
Requires-Dist: pytest-timeout>=2.0; extra == "dev"
|
|
36
|
+
Dynamic: author
|
|
37
|
+
Dynamic: home-page
|
|
38
|
+
Dynamic: license-file
|
|
39
|
+
Dynamic: requires-python
|
|
40
|
+
|
|
41
|
+
# mosaic_multigrid
|
|
42
|
+
|
|
43
|
+
**Research-grade multi-agent gridworld environments for reproducible RL experiments.**
|
|
44
|
+
|
|
45
|
+
A maintained fork of [gym-multigrid](https://github.com/ArnaudFickinger/gym-multigrid) by Arnaud Fickinger (2020), modernized to the Gymnasium API with Numba JIT-accelerated observations, reproducible seeding, and multi-agent framework adapters.
|
|
46
|
+
|
|
47
|
+
This fork is developed as part of the [MOSAIC](https://github.com/Abdulhamid97Mousa/MOSAIC) project (Multi-Agent Orchestration System).
|
|
48
|
+
|
|
49
|
+
## What Changed from Upstream
|
|
50
|
+
|
|
51
|
+
| Aspect | Upstream (Fickinger 2020) | This Fork |
|
|
52
|
+
|--------|--------------------------|-----------|
|
|
53
|
+
| API | Old Gym 4-tuple, list-based | Gymnasium 5-tuple, dict-keyed per agent |
|
|
54
|
+
| Actions | 8 (still=0..done=7) | 7 (left=0..done=6), no "still" |
|
|
55
|
+
| Observations | `(view, view, 6)` list | `(view, view, 3)` dict with `image`, `direction`, `mission` |
|
|
56
|
+
| `reset()` | `List[obs]` | `(Dict[int, obs], Dict[int, info])` |
|
|
57
|
+
| `step()` | `(List[obs], ndarray, bool, dict)` | `(Dict, Dict, Dict, Dict, Dict)` |
|
|
58
|
+
| Render | `render(mode='human')` param | `render_mode` constructor param |
|
|
59
|
+
| Seeding | `env.seed(42)` + broken global RNG | `reset(seed=42)` + `self.np_random` |
|
|
60
|
+
| Window | matplotlib | pygame |
|
|
61
|
+
| Performance | Pure Python loops | Numba JIT on observation generation |
|
|
62
|
+
| Structure | 1 monolithic 1442-line file | ~20 focused modules |
|
|
63
|
+
| Dependencies | `gym>=0.9.6, numpy` | `gymnasium>=0.26, numpy, numba, pygame, aenum` |
|
|
64
|
+
|
|
65
|
+
### Bugs Fixed
|
|
66
|
+
|
|
67
|
+
1. **Reproducibility bug** (critical): `step()` used `np.random.permutation()` (global RNG) for action ordering. Now uses `self.np_random.random(size=N).argsort()` to respect environment seeding.
|
|
68
|
+
2. **No `render_mode`**: Constructor now accepts `render_mode='rgb_array'` or `render_mode='human'`, following Gymnasium convention.
|
|
69
|
+
3. **Legacy 4-tuple**: `step()` returns Gymnasium 5-tuple `(obs, rewards, terminated, truncated, info)` with per-agent dicts.
|
|
70
|
+
|
|
71
|
+
## Included Environments
|
|
72
|
+
|
|
73
|
+
### SoccerGame
|
|
74
|
+
|
|
75
|
+
<p align="center">
|
|
76
|
+
<img src="figures/soccer.png" width="200">
|
|
77
|
+
<img src="figures/soccer_2.png" width="200">
|
|
78
|
+
<img src="figures/soccer_4.png" width="200">
|
|
79
|
+
</p>
|
|
80
|
+
|
|
81
|
+
Team-based competitive environment. Agents score by dropping the ball at the opposing team's goal. Supports ball passing, stealing, and zero-sum team rewards.
|
|
82
|
+
|
|
83
|
+
**Default variant:** `SoccerGame4HEnv10x15N2` -- 4 agents (2v2), 15x10 grid, 1 ball.
|
|
84
|
+
|
|
85
|
+
### CollectGame
|
|
86
|
+
|
|
87
|
+
<p align="center">
|
|
88
|
+
<img src="figures/collect.png" width="200">
|
|
89
|
+
<img src="figures/collect_2.png" width="200">
|
|
90
|
+
</p>
|
|
91
|
+
|
|
92
|
+
Cooperative/competitive collection. Agents earn rewards for picking up same-color balls and penalties for different-color balls.
|
|
93
|
+
|
|
94
|
+
**Default variant:** `CollectGame4HEnv10x10N2` -- 4 agents, 10x10 grid, 2 ball colors.
|
|
95
|
+
|
|
96
|
+
## Installation
|
|
97
|
+
|
|
98
|
+
### From PyPI (recommended)
|
|
99
|
+
|
|
100
|
+
```bash
|
|
101
|
+
pip install mosaic-multigrid
|
|
102
|
+
|
|
103
|
+
# With optional framework adapters
|
|
104
|
+
pip install mosaic-multigrid[rllib] # Ray RLlib support
|
|
105
|
+
pip install mosaic-multigrid[pettingzoo] # PettingZoo support
|
|
106
|
+
pip install mosaic-multigrid[dev] # pytest
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
### From source
|
|
110
|
+
|
|
111
|
+
```bash
|
|
112
|
+
git clone https://github.com/Abdulhamid97Mousa/mosaic_multigrid.git
|
|
113
|
+
cd mosaic_multigrid
|
|
114
|
+
pip install -e .
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
## Quick Start
|
|
118
|
+
|
|
119
|
+
```python
|
|
120
|
+
from mosaic_multigrid.envs import SoccerGame4HEnv10x15N2
|
|
121
|
+
|
|
122
|
+
env = SoccerGame4HEnv10x15N2(render_mode='rgb_array')
|
|
123
|
+
obs, info = env.reset(seed=42)
|
|
124
|
+
|
|
125
|
+
# obs is a dict keyed by agent index: {0: {...}, 1: {...}, 2: {...}, 3: {...}}
|
|
126
|
+
# Each agent's obs has 'image', 'direction', 'mission' keys
|
|
127
|
+
|
|
128
|
+
actions = {i: env.action_space[i].sample() for i in range(env.num_agents)}
|
|
129
|
+
obs, rewards, terminated, truncated, info = env.step(actions)
|
|
130
|
+
|
|
131
|
+
# Render RGB frame
|
|
132
|
+
frame = env.render() # Returns numpy array (H, W, 3)
|
|
133
|
+
env.close()
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
### Reproducibility
|
|
137
|
+
|
|
138
|
+
```python
|
|
139
|
+
# Same seed → identical trajectories (reproducibility bug is fixed)
|
|
140
|
+
for trial in range(2):
|
|
141
|
+
env = SoccerGame4HEnv10x15N2(render_mode='rgb_array')
|
|
142
|
+
obs, _ = env.reset(seed=42)
|
|
143
|
+
for step in range(100):
|
|
144
|
+
actions = {i: 2 for i in range(4)} # all forward
|
|
145
|
+
obs, *_ = env.step(actions)
|
|
146
|
+
# obs will be identical across trials
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
## Architecture
|
|
150
|
+
|
|
151
|
+
```
|
|
152
|
+
gym_multigrid/
|
|
153
|
+
├── base.py # MultiGridEnv (Gymnasium-compliant base)
|
|
154
|
+
├── core/
|
|
155
|
+
│ ├── constants.py # Type, Color, State, Direction enums
|
|
156
|
+
│ ├── actions.py # Action enum (7 actions, no "still")
|
|
157
|
+
│ ├── world_object.py # WorldObj numpy-subclass + all object types
|
|
158
|
+
│ ├── agent.py # Agent + AgentState (vectorized, team_index)
|
|
159
|
+
│ ├── grid.py # Grid (numpy state + world_objects cache)
|
|
160
|
+
│ └── mission.py # Mission + MissionSpace
|
|
161
|
+
├── utils/
|
|
162
|
+
│ ├── enum.py # IndexedEnum (aenum-based, dynamically extensible)
|
|
163
|
+
│ ├── rendering.py # Tile rendering (fill_coords, downsample, etc.)
|
|
164
|
+
│ ├── random.py # RandomMixin (seeded RNG utilities)
|
|
165
|
+
│ ├── obs.py # Numba JIT observation generation (hot path)
|
|
166
|
+
│ └── misc.py # front_pos, PropertyAlias
|
|
167
|
+
├── envs/
|
|
168
|
+
│ ├── soccer_game.py # SoccerGameEnv + variants
|
|
169
|
+
│ └── collect_game.py # CollectGameEnv + variants
|
|
170
|
+
├── wrappers.py # FullyObs, ImgObs, OneHotObs, SingleAgent
|
|
171
|
+
├── pettingzoo/ # PettingZoo ParallelEnv adapter
|
|
172
|
+
└── rllib/ # Ray RLlib MultiAgentEnv adapter
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
### Core Design Decisions
|
|
176
|
+
|
|
177
|
+
**Agent-not-in-grid**: Agents are NOT stored on the grid (following multigrid-ini). Agent positions are tracked via `AgentState.pos`. The observation generator inserts agents into the observation grid dynamically. This avoids grid corruption when agents overlap.
|
|
178
|
+
|
|
179
|
+
**numpy subclass pattern**: `WorldObj(np.ndarray)` and `AgentState(np.ndarray)` — domain objects ARE their numerical encoding. No serialization overhead.
|
|
180
|
+
|
|
181
|
+
**team_index separation**: `agent.index` (unique identity) vs `agent.team_index` (team membership). The original code conflated these — your agent index WAS your team.
|
|
182
|
+
|
|
183
|
+
**Numba JIT**: All observation generation functions use `@nb.njit(cache=True)`. Enum values are extracted to plain `int` constants at module level because Numba cannot access Python enum attributes.
|
|
184
|
+
|
|
185
|
+
## Action Space
|
|
186
|
+
|
|
187
|
+
### Action Enum Comparison
|
|
188
|
+
|
|
189
|
+
| Action | Upstream (Fickinger 2020) | mosaic_multigrid (this fork) | multigrid-ini (Oguntola 2023) |
|
|
190
|
+
|--------|---:|---:|---:|
|
|
191
|
+
| still | **0** | -- | -- |
|
|
192
|
+
| left | 1 | **0** | **0** |
|
|
193
|
+
| right | 2 | **1** | **1** |
|
|
194
|
+
| forward | 3 | **2** | **2** |
|
|
195
|
+
| pickup | 4 | **3** | **3** |
|
|
196
|
+
| drop | 5 | **4** | **4** |
|
|
197
|
+
| toggle | 6 | **5** | **5** |
|
|
198
|
+
| done | 7 | **6** | **6** |
|
|
199
|
+
| **Total** | **8** | **7** | **7** |
|
|
200
|
+
|
|
201
|
+
The `still` action (do nothing) was removed. Agents that need to skip a turn send `Action.done` instead. This aligns with multigrid-ini and shrinks the action space from 8 to 7.
|
|
202
|
+
|
|
203
|
+
> **Migration note:** All action indices shifted down by 1 compared to the upstream code. Any pre-trained policy or hardcoded action mapping from the old environment will need updating.
|
|
204
|
+
|
|
205
|
+
## Observation Space
|
|
206
|
+
|
|
207
|
+
Each agent receives a partial observation dict:
|
|
208
|
+
|
|
209
|
+
```python
|
|
210
|
+
{
|
|
211
|
+
'image': np.ndarray, # (view_size, view_size, 3) — [Type, Color, State] per cell
|
|
212
|
+
'direction': int, # Agent facing direction (0=right, 1=down, 2=left, 3=up)
|
|
213
|
+
'mission': str, # Mission string
|
|
214
|
+
}
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
The default `view_size=7` gives each agent a 7x7 partial view. Each cell encodes 3 values (Type index, Color index, State index), down from 6 in the original.
|
|
218
|
+
|
|
219
|
+
## Wrappers
|
|
220
|
+
|
|
221
|
+
| Wrapper | Description |
|
|
222
|
+
|---------|-------------|
|
|
223
|
+
| `FullyObsWrapper` | Full grid observation instead of partial agent view |
|
|
224
|
+
| `ImgObsWrapper` | Returns only the image array (drops direction/mission) |
|
|
225
|
+
| `OneHotObsWrapper` | One-hot encodes the observation image (Numba JIT) |
|
|
226
|
+
| `SingleAgentWrapper` | Unwraps multi-agent dict for single-agent use |
|
|
227
|
+
|
|
228
|
+
## Framework Adapters
|
|
229
|
+
|
|
230
|
+
### PettingZoo
|
|
231
|
+
|
|
232
|
+
```python
|
|
233
|
+
from gym_multigrid.pettingzoo import to_pettingzoo_env
|
|
234
|
+
|
|
235
|
+
env = to_pettingzoo_env('MosaicMultiGrid-Soccer-v0', render_mode='rgb_array')
|
|
236
|
+
# Returns a PettingZoo ParallelEnv
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
### Ray RLlib
|
|
240
|
+
|
|
241
|
+
```python
|
|
242
|
+
from gym_multigrid.rllib import to_rllib_env
|
|
243
|
+
|
|
244
|
+
env_cls = to_rllib_env('MosaicMultiGrid-Soccer-v0')
|
|
245
|
+
# Returns an RLlib MultiAgentEnv class (adds __all__ keys to terminated/truncated)
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
## Requirements
|
|
249
|
+
|
|
250
|
+
- Python >= 3.9
|
|
251
|
+
- gymnasium >= 0.26
|
|
252
|
+
- numpy >= 1.18
|
|
253
|
+
- numba >= 0.53
|
|
254
|
+
- pygame >= 2.2
|
|
255
|
+
- aenum >= 1.3
|
|
256
|
+
|
|
257
|
+
**Optional:**
|
|
258
|
+
- `ray[rllib] >= 2.0` (for RLlib adapter)
|
|
259
|
+
- `pettingzoo >= 1.22` (for PettingZoo adapter)
|
|
260
|
+
|
|
261
|
+
## Tests
|
|
262
|
+
|
|
263
|
+
```bash
|
|
264
|
+
pip install -e ".[dev]"
|
|
265
|
+
pytest tests/ -v
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
94 tests covering: Action enum, Type/Color/State/Direction enums, WorldObj encode/decode, Grid operations, AgentState vectorized ops, Agent team_index, Mission/MissionSpace, MultiGridEnv reset/step/render, pickup/drop mechanics, Numba JIT observations, rendering dimensions, and reproducibility.
|
|
269
|
+
|
|
270
|
+
## Citation
|
|
271
|
+
|
|
272
|
+
If you use this environment, please cite both the original work and this fork:
|
|
273
|
+
|
|
274
|
+
```bibtex
|
|
275
|
+
@misc{gym_multigrid,
|
|
276
|
+
author = {Fickinger, Arnaud},
|
|
277
|
+
title = {Multi-Agent Gridworld Environment for OpenAI Gym},
|
|
278
|
+
year = {2020},
|
|
279
|
+
publisher = {GitHub},
|
|
280
|
+
journal = {GitHub repository},
|
|
281
|
+
howpublished = {\url{https://github.com/ArnaudFickinger/gym-multigrid}},
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
@misc{mosaic_multigrid,
|
|
285
|
+
author = {Mousa, Abdulhamid},
|
|
286
|
+
title = {mosaic\_multigrid: Research-Grade Multi-Agent Gridworld Environments},
|
|
287
|
+
year = {2026},
|
|
288
|
+
publisher = {GitHub},
|
|
289
|
+
journal = {GitHub repository},
|
|
290
|
+
howpublished = {\url{https://github.com/Abdulhamid97Mousa/mosaic_multigrid}},
|
|
291
|
+
}
|
|
292
|
+
```
|
|
293
|
+
|
|
294
|
+
## License
|
|
295
|
+
|
|
296
|
+
Apache License 2.0 -- see [LICENSE](LICENSE) for details.
|
|
297
|
+
|
|
298
|
+
**Original work:** MiniGrid (Copyright 2020 Maxime Chevalier-Boisvert), MultiGrid extension (Copyright 2020 Arnaud Fickinger).
|
|
299
|
+
**This fork:** Copyright 2026 Abdulhamid Mousa.
|