topogym 0.1.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.
Files changed (35) hide show
  1. topogym-0.1.0/LICENSE +202 -0
  2. topogym-0.1.0/PKG-INFO +371 -0
  3. topogym-0.1.0/README.md +347 -0
  4. topogym-0.1.0/pyproject.toml +50 -0
  5. topogym-0.1.0/setup.cfg +4 -0
  6. topogym-0.1.0/tests/test_basemap.py +146 -0
  7. topogym-0.1.0/tests/test_benchmarks.py +74 -0
  8. topogym-0.1.0/tests/test_envs.py +292 -0
  9. topogym-0.1.0/tests/test_generator.py +367 -0
  10. topogym-0.1.0/tests/test_homology.py +173 -0
  11. topogym-0.1.0/topogym/__init__.py +31 -0
  12. topogym-0.1.0/topogym/benchmarks/__init__.py +300 -0
  13. topogym-0.1.0/topogym/core/__init__.py +43 -0
  14. topogym-0.1.0/topogym/core/basemap.py +563 -0
  15. topogym-0.1.0/topogym/core/constants.py +23 -0
  16. topogym-0.1.0/topogym/core/homology.py +382 -0
  17. topogym-0.1.0/topogym/core/metadata.py +126 -0
  18. topogym-0.1.0/topogym/envs/__init__.py +6 -0
  19. topogym-0.1.0/topogym/envs/core.py +267 -0
  20. topogym-0.1.0/topogym/envs/topo2d.py +149 -0
  21. topogym-0.1.0/topogym/envs/topo3d.py +147 -0
  22. topogym-0.1.0/topogym/generation/__init__.py +33 -0
  23. topogym-0.1.0/topogym/generation/config.py +103 -0
  24. topogym-0.1.0/topogym/generation/controls.py +99 -0
  25. topogym-0.1.0/topogym/generation/generator.py +1077 -0
  26. topogym-0.1.0/topogym/generation/graph.py +245 -0
  27. topogym-0.1.0/topogym/generation/shapes.py +193 -0
  28. topogym-0.1.0/topogym/rendering/__init__.py +1 -0
  29. topogym-0.1.0/topogym/rendering/rgb.py +89 -0
  30. topogym-0.1.0/topogym/rendering/svg.py +136 -0
  31. topogym-0.1.0/topogym.egg-info/PKG-INFO +371 -0
  32. topogym-0.1.0/topogym.egg-info/SOURCES.txt +33 -0
  33. topogym-0.1.0/topogym.egg-info/dependency_links.txt +1 -0
  34. topogym-0.1.0/topogym.egg-info/requires.txt +5 -0
  35. topogym-0.1.0/topogym.egg-info/top_level.txt +1 -0
topogym-0.1.0/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
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.
topogym-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,371 @@
1
+ Metadata-Version: 2.4
2
+ Name: topogym
3
+ Version: 0.1.0
4
+ Summary: Gridworld environments and benchmarks for topological exploration in reinforcement learning
5
+ Author: Jason Carlson
6
+ License: Apache-2.0
7
+ Project-URL: Homepage, https://github.com/jcarlson212/TopoGym
8
+ Project-URL: Repository, https://github.com/jcarlson212/TopoGym
9
+ Project-URL: Bug Tracker, https://github.com/jcarlson212/TopoGym/issues
10
+ Keywords: reinforcement-learning,gymnasium,topology,exploration,benchmark,gridworld
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: Intended Audience :: Science/Research
13
+ Classifier: License :: OSI Approved :: Apache Software License
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
16
+ Requires-Python: >=3.9
17
+ Description-Content-Type: text/markdown
18
+ License-File: LICENSE
19
+ Requires-Dist: gymnasium>=0.29
20
+ Requires-Dist: numpy>=1.21
21
+ Provides-Extra: testing
22
+ Requires-Dist: pytest>=7.0; extra == "testing"
23
+ Dynamic: license-file
24
+
25
+ # TopoGym
26
+
27
+ [![CI](https://github.com/jcarlson212/TopoGym/actions/workflows/ci.yml/badge.svg)](https://github.com/jcarlson212/TopoGym/actions/workflows/ci.yml)
28
+ [![License](https://img.shields.io/badge/license-Apache--2.0-blue.svg)](LICENSE)
29
+ [![Python](https://img.shields.io/badge/python-3.9%2B-blue.svg)](pyproject.toml)
30
+
31
+ **Gridworld environments and benchmarks for topological exploration in
32
+ reinforcement learning**, built on the [Gymnasium](https://gymnasium.farama.org)
33
+ API.
34
+
35
+ Every environment is generated on a real base manifold — a torus, a Möbius
36
+ band, a Klein bottle, RP², a sphere, a 3-torus — and carved with holes,
37
+ hidden chambers, and decoys that control its homology exactly. Every
38
+ environment ships with **certified topology metadata**: its Betti numbers
39
+ are *computed* from the actual free-space cubical complex at generation
40
+ time, not assumed.
41
+
42
+ <table>
43
+ <tr>
44
+ <td align="center"><img src="docs/envs/2d_bench_grid_small/square-holes.svg" width="170"/><br><sub><b>square-holes</b></sub></td>
45
+ <td align="center"><img src="docs/envs/2d_bench_grid_small/square-rooms.svg" width="170"/><br><sub><b>square-rooms</b></sub></td>
46
+ <td align="center"><img src="docs/envs/2d_bench_grid_small/annulus.svg" width="170"/><br><sub><b>annulus</b></sub></td>
47
+ <td align="center"><img src="docs/envs/2d_bench_grid_small/plane-6holes.svg" width="170"/><br><sub><b>plane-6holes</b></sub></td>
48
+ </tr>
49
+ <tr>
50
+ <td align="center"><img src="docs/envs/2d_bench_grid_small/cylinder-rooms.svg" width="170"/><br><sub><b>cylinder-rooms</b></sub></td>
51
+ <td align="center"><img src="docs/envs/2d_bench_grid_small/mobius-rooms.svg" width="170"/><br><sub><b>mobius-rooms</b></sub></td>
52
+ <td align="center"><img src="docs/envs/2d_bench_grid_small/torus-holes.svg" width="170"/><br><sub><b>torus-holes</b></sub></td>
53
+ <td align="center"><img src="docs/envs/2d_bench_grid_small/torus-rooms.svg" width="170"/><br><sub><b>torus-rooms</b></sub></td>
54
+ </tr>
55
+ <tr>
56
+ <td align="center"><img src="docs/envs/2d_bench_grid_small/klein-rooms.svg" width="170"/><br><sub><b>klein-rooms</b></sub></td>
57
+ <td align="center"><img src="docs/envs/2d_bench_grid_small/rp2-rooms.svg" width="170"/><br><sub><b>rp2-rooms</b></sub></td>
58
+ <td align="center"><img src="docs/envs/2d_bench_grid_small/sphere-holes.svg" width="170"/><br><sub><b>sphere-holes</b></sub></td>
59
+ <td align="center"><img src="docs/envs/2d_bench_grid_small/sphere-rooms.svg" width="170"/><br><sub><b>sphere-rooms</b></sub></td>
60
+ </tr>
61
+ <tr>
62
+ <td align="center"><img src="docs/envs/2d_bench_grid_small/square-decoyfield.svg" width="170"/><br><sub><b>square-decoyfield</b></sub></td>
63
+ <td align="center"><img src="docs/envs/2d_bench_grid_small/torus-goal-in-chamber.svg" width="170"/><br><sub><b>torus-goal-in-chamber</b></sub></td>
64
+ <td align="center"><img src="docs/envs/2d_bench_grid_small/control-maze.svg" width="170"/><br><sub><b>control-maze</b></sub></td>
65
+ <td align="center"><img src="docs/envs/2d_bench_grid_small/control-zigzag.svg" width="170"/><br><sub><b>control-zigzag</b></sub></td>
66
+ </tr>
67
+ </table>
68
+
69
+ *The `2d_bench_grid_small` benchmark, rendered in reveal mode: walls (gray),
70
+ holes (black), hidden doors (purple — agents see walls until they bump
71
+ through), decoys (dark red — identical to chambers from outside, nothing
72
+ inside), start (blue), goal (green). The full gallery, including the 3D and
73
+ directed suites, is in [`docs/envs/`](docs/envs/README.md).*
74
+
75
+ ## Why
76
+
77
+ Exploration methods increasingly claim to exploit the *shape* of an
78
+ environment — loops that shouldn't be re-searched, enclosed regions that
79
+ must be entered to be known, irreversible passages that deserve caution.
80
+ Testing those claims needs environments whose topology is **known, varied,
81
+ and controllable**:
82
+
83
+ - **Known**: every env carries certified Betti numbers (over ℤ/2, with
84
+ integral homology and torsion where the math allows certification),
85
+ Euler characteristic, orientability, genus, and a canonical description
86
+ of any directional asymmetry.
87
+ - **Varied**: seven 2D base manifolds and four 3D ones, from a plain square
88
+ to RP², all built from one gluing-spec abstraction you can extend.
89
+ - **Controllable**: a seeded generator that hits target Betti numbers and
90
+ places chambers, decoys, hidden doors, one-way doors, and trapdoors —
91
+ same config + same seed = byte-identical environment.
92
+
93
+ And because "my agent understands topology" must beat "my agent is good at
94
+ generic novelty-seeking", every benchmark includes **size-matched control
95
+ environments** that are hard to explore but topologically trivial.
96
+
97
+ ## Install
98
+
99
+ ```bash
100
+ # directly from GitHub (no clone needed):
101
+ pip install git+https://github.com/jcarlson212/TopoGym.git
102
+
103
+ # or for development:
104
+ git clone https://github.com/jcarlson212/TopoGym.git && cd TopoGym
105
+ pip install -e ".[testing]"
106
+ ```
107
+
108
+ `pip install topogym` from PyPI lands with the first tagged release.
109
+ Dependencies: `gymnasium`, `numpy`. Nothing else.
110
+
111
+ ## Quick start
112
+
113
+ ```python
114
+ import gymnasium as gym
115
+ import topogym # registers the TopoGym/* env ids
116
+
117
+ # A torus with 2 holes, a hidden chamber, and a decoy — fixed layout.
118
+ env = gym.make("TopoGym/Grid2D-v0", base="torus", size=17,
119
+ n_holes=2, n_chambers=1, n_decoys=1, layout_seed=7)
120
+ obs, info = env.reset(seed=0)
121
+
122
+ print(info["topology"]["betti_z2"]) # [1, 5, 0] — certified
123
+ print(info["topology"]["genus"]) # 1
124
+ print(info["topology"]["homology"]) # {'H0': 'Z', 'H1': 'Z^5', 'H2': '0'}
125
+
126
+ obs, reward, terminated, truncated, info = env.step(2) # forward
127
+ print(env.unwrapped.visited_betti()) # topology of the region seen so far
128
+ ```
129
+
130
+ Or run a frozen benchmark:
131
+
132
+ ```python
133
+ import topogym.benchmarks as bench
134
+
135
+ for entry in bench.get_benchmark("2d_bench_grid_small"):
136
+ env = entry.make()
137
+ obs, info = env.reset(seed=0)
138
+ print(f"{entry.name:24s} b={info['topology']['betti_z2']}")
139
+
140
+ rows = bench.benchmark_metadata("2d_bench_grid_small") # dicts, pandas-ready
141
+ ```
142
+
143
+ More in [`examples/`](examples/).
144
+
145
+ ## Environments
146
+
147
+ **`TopoGym/Grid2D-v0`** — an egocentric agent on a 2D base manifold.
148
+ Actions `Discrete(3)`: turn left / turn right / forward. The agent carries
149
+ a local frame that is parallel-transported as it moves: crossing a
150
+ Möbius/Klein/RP² seam **mirrors its view** (non-orientability is
151
+ experienced, not just declared), and walking a loop around a cube-sphere
152
+ corner rotates it by 90° (curvature). Observations are egocentric
153
+ `(2r+1, 2r+1)` patches, occluded by walls — chamber interiors must be
154
+ discovered, and decoys are visually identical to chambers until you try
155
+ every wall.
156
+
157
+ **`TopoGym/Grid3D-v0`** — a free agent in a 3D base manifold. Actions
158
+ `Discrete(6)`: moves along ±x/±y/±z. Observations are centered, occluded
159
+ `(2r+1)³` patches.
160
+
161
+ Both support `obs_mode="global"` (full grid + agent channel, for debugging
162
+ or fully-observable baselines), `reward_mode="goal"` (MiniGrid-style
163
+ success reward) or `"none"` (reward-free exploration), procedural layouts
164
+ (a new layout every `reset`) or pinned ones (`layout_seed=...`).
165
+
166
+ ### Doors and asymmetric traversability
167
+
168
+ | mechanic | observed as | behavior |
169
+ |---|---|---|
170
+ | **hidden door** (`bump`) | wall, until opened | opens permanently after `tries` bumps — persistence is rewarded |
171
+ | **one-way door** | valve (visible) | enterable from exactly one side, forever |
172
+ | **trapdoor** | trapdoor (visible) | passable once; seals the moment you step off it |
173
+
174
+ Room features built from these: **chambers** (hidden interiors behind bump
175
+ doors), **decoys** (chamber look-alikes with nothing inside), **trap rooms**
176
+ (one-way in — an absorbing region), **airlocks** (one-way in, one-way out —
177
+ a directed circuit that stays strongly connected), and **trapdoor rooms**
178
+ (the way in seals; a hidden escape hatch leads out).
179
+
180
+ Door state never changes the free space's homology — a door cell is a free
181
+ cell either way. Doors gate *coverage* and *reversibility*, and that is
182
+ exactly what the metadata separates: Betti numbers describe the undirected
183
+ shape; the `asymmetry` block describes the directed dynamics.
184
+
185
+ ### Bridges and the observed region
186
+
187
+ **Partitions** divide the world with narrow passages: dumbbells (one gap),
188
+ passage pairs (two gaps close a loop: b₁ + 1), hidden bridges (bump-door
189
+ gaps), on any base — a meridian wall on a torus makes closing the loop
190
+ require the wraparound. Partitions come in two materials: **wall** (opaque)
191
+ and **moat** (a pit — blocks movement but *not sight*, so the far side is
192
+ visible before it is reachable).
193
+
194
+ Bridges are not a separate kind of topology. During exploration, every
195
+ passage discovery is exactly one of: **frontier growth** (far side
196
+ unknown), an **H₀ merge** (two known regions join), or an **H₁ birth** (a
197
+ loop closure between already-connected regions). The envs track the
198
+ *observed region* — everything seen and believed free — as a monotone
199
+ filtration: `info["known_components"]` and `info["h0_merges"]` are
200
+ maintained incrementally, and `env.observed_betti()` gives the full
201
+ picture (its b₁ jumps are loop closures). Hidden doors participate
202
+ naturally: a closed bump-door is believed to be a wall, so opening it *is*
203
+ the discovery event.
204
+
205
+ What the metadata certifies instead is **difficulty**: the `connectivity`
206
+ block reports graph bridges, articulation points, biconnected components,
207
+ and `max_bridge_split` (the largest "smaller side" any single bridge
208
+ separates) of the free-cell graph — how rare and late the homological
209
+ events will be under naive exploration.
210
+
211
+ ## Base manifolds
212
+
213
+ Every 2D base except the sphere is one rectangular fundamental domain plus
214
+ a gluing rule per axis — that is the abstraction to extend if you want new
215
+ surfaces:
216
+
217
+ | base | gluing (x, y) | χ | orientable | genus | b(ℤ/2) | H₁ torsion |
218
+ |---|---|---|---|---|---|---|
219
+ | `square` | wall, wall | 1 | yes | 0 | (1, 0, 0) | — |
220
+ | `cylinder` | wrap, wall | 0 | yes | 0 | (1, 1, 0) | — |
221
+ | `torus` | wrap, wrap | 0 | yes | 1 | (1, 2, 1) | — |
222
+ | `mobius` | flip, wall | 0 | no | ✝1 | (1, 1, 0) | — |
223
+ | `klein` | flip, wrap | 0 | no | ✝2 | (1, 2, 1) | ℤ/2 |
224
+ | `rp2` | flip, flip | 1 | no | ✝1 | (1, 1, 1) | ℤ/2 |
225
+ | `sphere` | cube surface | 2 | yes | 0 | (1, 0, 1) | — |
226
+
227
+ ✝ = demigenus (crosscap number). Note RP² and the Klein bottle: their
228
+ interesting H₁ is torsion, invisible to rational Betti numbers — which is
229
+ why TopoGym certifies homology over ℤ/2 and reports torsion explicitly.
230
+
231
+ 3D bases: `box` (trivial), `solid_torus` (wrap one axis, b₁=1 — the 3D
232
+ annulus), `torus3` (wrap all axes, b₁=3), plus presets `annulus`,
233
+ `x_holes` (2D) and `shell` (3D, b₂=1) built from large intrinsic holes.
234
+
235
+ ## The generator
236
+
237
+ ```python
238
+ from topogym.generation import TopoGenConfig2D, generate_2d
239
+
240
+ cfg = TopoGenConfig2D(
241
+ base="klein", size=19,
242
+ n_holes=2, hole_shapes=("rect", "disc", "blob", "plus"), hole_size=(2, 4),
243
+ n_chambers=2, n_decoys=1, door_tries=(2, 5),
244
+ n_trap_rooms=0, n_airlocks=1, # directed features
245
+ # target_b1=7, # or: solve n_holes for me
246
+ )
247
+ layout = generate_2d(cfg, seed=42) # deterministic
248
+ print(layout.metadata.betti_z2) # computed AND verified
249
+ ```
250
+
251
+ Placement works by parallel transport, so shapes wrap seams and cross
252
+ cube-sphere edges correctly; margins keep every obstacle's homology
253
+ contribution independent; the generator retries until the *computed*
254
+ homology matches the analytic expectation, then certifies it. Each
255
+ feature's contribution:
256
+
257
+ | feature | 2D | 3D |
258
+ |---|---|---|
259
+ | hole / blob | +1 b₁ | +1 b₂ |
260
+ | ring | — | +1 b₁, +1 b₂ |
261
+ | chamber / decoy / trap room | +1 b₁ | +1 b₂ |
262
+ | airlock / trapdoor room | +2 b₁ | +1 b₁, +1 b₂ |
263
+ | partition, K gaps (attached) | +(K−1) b₁ | +(K−1) b₁ |
264
+ | partition, K gaps (ring/belt) | +K b₁ | — |
265
+
266
+ ## Certified metadata
267
+
268
+ `env.unwrapped.topology` (also in `info["topology"]` at reset, as a plain
269
+ dict) — designed to be swept over programmatically:
270
+
271
+ ```python
272
+ {
273
+ "dim": 2, "base_map": "torus", "size": [17, 17], "style": "rooms",
274
+ "layout_seed": 7, "n_holes": 2, "n_chambers": 1, "n_decoys": 1,
275
+ "door_tries": [3], "n_cells": 289, "n_free_cells": 243,
276
+ "betti_z2": [1, 5, 0], # certified: computed from the complex
277
+ "euler_characteristic": -4,
278
+ "orientable": true, "genus": 1, "demigenus": null,
279
+ "n_boundary_components": 4,
280
+ "betti_q": [1, 5, 0], "h1_torsion": [], "homology": {"H0": "Z", "H1": "Z^5", "H2": "0"},
281
+ "asymmetry": {
282
+ "is_symmetric": true, "mechanisms": [], "n_sccs": 1,
283
+ "largest_scc_frac": 1.0, "n_absorbing_sccs": 0,
284
+ "goal_in_start_scc": true, "n_consumable_transitions": 0,
285
+ "feature_counts": {"trap_room": 0, "airlock": 0, "trapdoor_room": 0}
286
+ },
287
+ "connectivity": {
288
+ "n_bridges": 0, "n_articulation_points": 0,
289
+ "n_biconnected_components": 1, "max_bridge_split": 0
290
+ },
291
+ "n_partitions": 0,
292
+ "certified": {"betti_z2": true, "betti_q": true, "h1_torsion": true,
293
+ "asymmetry": true, "connectivity": true, "genus": true},
294
+ "base": {"name": "torus", "orientable": true, "genus": 1, "...": "..."}
295
+ }
296
+ ```
297
+
298
+ Certification levels: `betti_z2` and `asymmetry` (SCC condensation of the
299
+ actual directed transition graph) are always computed. `betti_q`, torsion,
300
+ genus/orientability are certified for all 2D environments (surface
301
+ classification) and obstacle-free 3D bases; 3D-with-obstacles reports
302
+ `betti_q_expected` instead and says so in `certified`.
303
+
304
+ ## Benchmarks
305
+
306
+ | collection | envs | contents |
307
+ |---|---|---|
308
+ | `2d_bench_grid_small` | 16 | all 7 bases, holes/chambers/decoys, goal-in-chamber, 2 controls |
309
+ | `3d_bench_grid_small` | 8 | rings (b₁), voids (b₂), rooms, solid torus, 3-torus, shell, control |
310
+ | `2d_bench_grid_small_directed` | 8 | trap rooms, airlocks, trapdoor rooms on 4 bases |
311
+ | `3d_bench_grid_small_directed` | 4 | the same mechanics in 3D |
312
+ | `2d_bench_grid_small_bridges` | 8 | dumbbells, passage pairs, moats, hidden bridges, torus meridian, sphere belt |
313
+ | `3d_bench_grid_small_bridges` | 4 | tunnel dumbbells, tunnel pairs, hidden tunnels, solid-torus gate |
314
+
315
+ Each entry pins `(config, layout_seed)` — everyone runs byte-identical
316
+ environments — and is registered as a Gymnasium id
317
+ (`TopoGym/Bench2DSmall-torus-rooms-v0`, ...). Browse them all in the
318
+ [gallery](docs/envs/README.md).
319
+
320
+ **Suggested protocol** (we follow it in `examples/`): fix ≥5 agent seeds
321
+ per environment; report mean ± std; use reward-free mode with coverage /
322
+ `visited_betti()` curves for exploration claims (time-to-discover each
323
+ homology class is the interesting curve); report absorbing-region outcomes
324
+ in directed envs explicitly (an agent that dies in a trap room is a data
325
+ point, not a dropped run); always include the controls.
326
+
327
+ ## Contributing 🤝
328
+
329
+ Contributions are very welcome — this project is designed to be built on:
330
+
331
+ - **Add an environment** (no code needed): design it with
332
+ [`scripts/new_env.py`](scripts/new_env.py), iterate on seeds, submit the
333
+ frozen entry. Full walkthrough:
334
+ [docs/contributing_environments.md](docs/contributing_environments.md).
335
+ - **Add a base manifold, hole shape, or door mechanic**: the extension
336
+ points are documented in the same guide; if the generator isn't general
337
+ enough for your idea, generalize it and send that too.
338
+ - **Add benchmarks**: propose a collection (bigger sizes, new mechanic
339
+ mixes) via a [new-environment issue](.github/ISSUE_TEMPLATE/new_environment.md).
340
+
341
+ See [CONTRIBUTING.md](CONTRIBUTING.md) for dev setup and the PR checklist.
342
+ All new topology must come with certified tests — the homology engine is
343
+ the referee.
344
+
345
+ ## Roadmap
346
+
347
+ - Genus-g surfaces (polygon gluings beyond rectangles)
348
+ - Non-orientable 3D bases (frame transport in 3D)
349
+ - Persistent-homology observers / wrappers for visited-region analysis
350
+ - Vectorized generation, larger benchmark tiers (`*_medium`, `*_large`)
351
+ - Community benchmark collection
352
+
353
+ ## Citation
354
+
355
+ If you use TopoGym in your research, please cite it (see also
356
+ [`CITATION.cff`](CITATION.cff)):
357
+
358
+ ```bibtex
359
+ @software{carlson2026topogym,
360
+ author = {Carlson, Jason},
361
+ title = {TopoGym: Environments and Benchmarks for Topological
362
+ Exploration in Reinforcement Learning},
363
+ year = {2026},
364
+ url = {https://github.com/jcarlson212/TopoGym},
365
+ version = {0.1.0}
366
+ }
367
+ ```
368
+
369
+ ## License
370
+
371
+ [Apache 2.0](LICENSE).