target-gym 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.
@@ -0,0 +1,186 @@
1
+ Metadata-Version: 2.1
2
+ Name: target-gym
3
+ Version: 0.2.0
4
+ Summary: A reinforcement learning environment for simulating target-MDP environments (Airplane, Car, Bicycle), with gymnasium and gymnax support
5
+ Home-page: https://github.com/yannberthelot/Plane
6
+ Keywords: reinforcement-learning,gymnasium,jax,airplane,car,simulation,bike
7
+ Author: Yann Berthelot
8
+ Author-email: yannberthelot1@gmail.com
9
+ Requires-Python: >=3.10,<3.13
10
+ Classifier: Development Status :: 3 - Alpha
11
+ Classifier: Intended Audience :: Science/Research
12
+ Classifier: License :: OSI Approved :: MIT License
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3.10
15
+ Classifier: Programming Language :: Python :: 3.11
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
18
+ Requires-Dist: distrax (>=0.1.5,<0.2.0)
19
+ Requires-Dist: gymnasium (>=1.2.0,<2.0.0)
20
+ Requires-Dist: gymnax (>=0.0.9,<0.0.10)
21
+ Requires-Dist: jax (<7.0)
22
+ Requires-Dist: matplotlib (>=3.8.1,<4.0.0)
23
+ Requires-Dist: moviepy (>=2.2.1,<3.0.0)
24
+ Requires-Dist: numpy (>=1.26.1,<2.0.0)
25
+ Requires-Dist: pygame (>=2.6.1,<3.0.0)
26
+ Requires-Dist: six (>=1.16.0,<2.0.0)
27
+ Project-URL: Repository, https://github.com/yannberthelot/Plane
28
+ Description-Content-Type: text/markdown
29
+
30
+ # ๐ŸŽฏ TargetGym: Reinforcement Learning Environments for Target MDPs
31
+
32
+
33
+
34
+ **TargetGym** is a lightweight yet realistic collection of **reinforcement learning environments** designed around **target MDPs** โ€” tasks where the objective is to **reach and maintain a specific subset of states** (target states).
35
+
36
+ Environments are built to be **fast, parallelizable, and physics-based**, enabling large-scale RL research while capturing the core challenges of real-world control systems such as **delays, irrecoverable states, partial observability, and competing objectives**.
37
+
38
+ Currently included environments:
39
+
40
+ * ๐Ÿ›ฉ **Plane** โ€“ control of a 2D Airbus A320-like aircraft - Stable-Target-MDP
41
+ * ๐Ÿš— **Car** โ€“ maintain a desired speed on a road - Stable-Target-MDP
42
+ * ๐Ÿšฒ **Bike** โ€“ stabilize and steer a 2D bicycle model - Unstable-Target-MDP (from [Randlov et al.](https://gwern.net/doc/reinforcement-learning/model-free/1998-randlov.pdf))
43
+
44
+ <p align="center">
45
+ <img src="videos/plane/output.gif" width="40%"/>
46
+ <img src="videos/car/output.gif" width="40%"/>
47
+ </p>
48
+
49
+ ---
50
+
51
+ ## โœจ Features
52
+
53
+ * โšก **Fast & parallelizable** with JAX โ€” scale to thousands of parallel environments on GPU/TPU.
54
+ * ๐Ÿ“ **Physics-based**: Derived from modeling equations, not arcade physics.
55
+ * ๐Ÿงช **Reliable**: Unit-tested for stability and reproducibility.
56
+ * ๐ŸŽฏ **Target MDP focus**: Each task is about reaching and maintaining target states.
57
+ * ๐ŸŒ€ **Challenging dynamics**: Captures irrecoverable states, and momentum effects.
58
+ * ๐Ÿ”„ **Compatible with RL libraries**: Offers [Gymnax](https://github.com/RobertTLange/gymnax) and [Gymnasium](https://github.com/Farama-Foundation/Gymnasium) interfaces.
59
+ * ๐ŸŒŸ **Upcoming features**: Environmental perturbations (wind, turbulence, bumpy road) and fuel consumption.
60
+
61
+ ---
62
+
63
+ ## ๐Ÿ“Š Example: Stable Altitude in Plane
64
+
65
+ Below is an example of how stable altitude changes with engine power and pitch in the **Plane** environment:
66
+
67
+ <p align="center">
68
+ <img src="figures/plane/3d_altitude.png" width="70%"/>
69
+ </p>
70
+
71
+ <p align="center">
72
+ <img src="figures/plane/power_trajectories.png" width="60%"/>
73
+ </p>
74
+
75
+
76
+ This illustrates **multi-stability**: with fixed power and pitch, the aircraft naturally converges to a stable altitude. Similar properties can be found in Car environment
77
+
78
+ ---
79
+
80
+ ## ๐Ÿš€ Installation
81
+
82
+ Once released on PyPI, install with:
83
+
84
+ ```bash
85
+ # Using pip
86
+ pip install target-gym
87
+
88
+ # Or with Poetry
89
+ poetry add target-gym
90
+ ```
91
+
92
+ ---
93
+
94
+ ## ๐ŸŽฎ Usage
95
+
96
+ Hereโ€™s a minimal example of running an episode in the **Plane** environment and saving a video:
97
+
98
+ ```python
99
+ from target_gym import Plane, PlaneParams
100
+
101
+ # Create env
102
+ env = Plane()
103
+ seed = 42
104
+ env_params = PlaneParams(max_steps_in_episode=1_000)
105
+
106
+ # Simple constant policy with 80% power and 0ยฐ stick input
107
+ action = (0.8, 0.0)
108
+
109
+ # Save the video
110
+ env.save_video(lambda o: action, seed, folder="videos", episode_index=0, params=env_params, format="gif")
111
+ ```
112
+
113
+ Or train an agent using your favorite RL library (example with stable-baselines3):
114
+
115
+ ```python
116
+ from target_gym import PlaneGymnasium, PlaneParams
117
+ from stable_baselines3 import SAC
118
+
119
+ env = PlaneGymnasium()
120
+ model = SAC("MlpPolicy", env, verbose=1)
121
+ model.learn(total_timesteps=10_000, log_interval=4)
122
+ model.save("sac_plane")
123
+
124
+ obs, info = env.reset()
125
+ while True:
126
+ action, _states = model.predict(obs, deterministic=True)
127
+ obs, reward, terminated, truncated, info = env.step(action)
128
+ if terminated or truncated:
129
+ break
130
+ ```
131
+
132
+ ---
133
+
134
+ ## ๐Ÿงฉ Challenges Modeled
135
+
136
+ TargetGym tasks are designed to expose RL agents to **realistic control challenges**:
137
+
138
+ * โณ **Delays**: Inputs (like engine power) take time to fully apply.
139
+ * ๐Ÿ‘€ **Partial observability**: Some parts of the state cannot be directly measured.
140
+ * ๐Ÿ **Competing objectives**: Reach the target state quickly while minimizing overshoot or cost.
141
+ * ๐ŸŒ€ **Momentum effects**: Physical inertia delays control effectiveness.
142
+ * โš ๏ธ **Irrecoverable states**: Certain trajectories inevitably lead to failure.
143
+
144
+ ---
145
+
146
+ ## ๐Ÿ“ฆ Roadmap
147
+
148
+ * [ ] Add perturbations (wind, turbulence, uneven terrain) for non-stationary dynamics.
149
+ * [ ] Easier interface for creating partially-observable variants.
150
+ * [ ] Provide benchmark results for popular RL baselines.
151
+ * [ ] Add fuel consumption and resource constraints.
152
+ * [ ] Add more tasks.
153
+
154
+ ---
155
+
156
+ ## ๐Ÿค Contributing
157
+
158
+ Contributions are welcome!
159
+ Open an issue or PR if you have suggestions, bug reports, or new features.
160
+
161
+ ---
162
+
163
+
164
+ ## ๐Ÿ“– Citation
165
+
166
+ If you use **TargetGym** in your research or project, please cite it as:
167
+
168
+ ```bibtex
169
+ @misc{targetgym2025,
170
+ title = {TargetGym: Reinforcement Learning Environments for Target MDPs},
171
+ author = {Yann Berthelot},
172
+ year = {2025},
173
+ url = {https://github.com/YannBerthelot/TargetGym},
174
+ note = {Lightweight physics-based RL environments for aircraft, car, and bike control}
175
+ }
176
+ ```
177
+
178
+
179
+ ---
180
+
181
+ ## ๐Ÿ“œ License
182
+
183
+ MIT License โ€“ free to use in research and projects.
184
+
185
+
186
+
@@ -0,0 +1,156 @@
1
+ # ๐ŸŽฏ TargetGym: Reinforcement Learning Environments for Target MDPs
2
+
3
+
4
+
5
+ **TargetGym** is a lightweight yet realistic collection of **reinforcement learning environments** designed around **target MDPs** โ€” tasks where the objective is to **reach and maintain a specific subset of states** (target states).
6
+
7
+ Environments are built to be **fast, parallelizable, and physics-based**, enabling large-scale RL research while capturing the core challenges of real-world control systems such as **delays, irrecoverable states, partial observability, and competing objectives**.
8
+
9
+ Currently included environments:
10
+
11
+ * ๐Ÿ›ฉ **Plane** โ€“ control of a 2D Airbus A320-like aircraft - Stable-Target-MDP
12
+ * ๐Ÿš— **Car** โ€“ maintain a desired speed on a road - Stable-Target-MDP
13
+ * ๐Ÿšฒ **Bike** โ€“ stabilize and steer a 2D bicycle model - Unstable-Target-MDP (from [Randlov et al.](https://gwern.net/doc/reinforcement-learning/model-free/1998-randlov.pdf))
14
+
15
+ <p align="center">
16
+ <img src="videos/plane/output.gif" width="40%"/>
17
+ <img src="videos/car/output.gif" width="40%"/>
18
+ </p>
19
+
20
+ ---
21
+
22
+ ## โœจ Features
23
+
24
+ * โšก **Fast & parallelizable** with JAX โ€” scale to thousands of parallel environments on GPU/TPU.
25
+ * ๐Ÿ“ **Physics-based**: Derived from modeling equations, not arcade physics.
26
+ * ๐Ÿงช **Reliable**: Unit-tested for stability and reproducibility.
27
+ * ๐ŸŽฏ **Target MDP focus**: Each task is about reaching and maintaining target states.
28
+ * ๐ŸŒ€ **Challenging dynamics**: Captures irrecoverable states, and momentum effects.
29
+ * ๐Ÿ”„ **Compatible with RL libraries**: Offers [Gymnax](https://github.com/RobertTLange/gymnax) and [Gymnasium](https://github.com/Farama-Foundation/Gymnasium) interfaces.
30
+ * ๐ŸŒŸ **Upcoming features**: Environmental perturbations (wind, turbulence, bumpy road) and fuel consumption.
31
+
32
+ ---
33
+
34
+ ## ๐Ÿ“Š Example: Stable Altitude in Plane
35
+
36
+ Below is an example of how stable altitude changes with engine power and pitch in the **Plane** environment:
37
+
38
+ <p align="center">
39
+ <img src="figures/plane/3d_altitude.png" width="70%"/>
40
+ </p>
41
+
42
+ <p align="center">
43
+ <img src="figures/plane/power_trajectories.png" width="60%"/>
44
+ </p>
45
+
46
+
47
+ This illustrates **multi-stability**: with fixed power and pitch, the aircraft naturally converges to a stable altitude. Similar properties can be found in Car environment
48
+
49
+ ---
50
+
51
+ ## ๐Ÿš€ Installation
52
+
53
+ Once released on PyPI, install with:
54
+
55
+ ```bash
56
+ # Using pip
57
+ pip install target-gym
58
+
59
+ # Or with Poetry
60
+ poetry add target-gym
61
+ ```
62
+
63
+ ---
64
+
65
+ ## ๐ŸŽฎ Usage
66
+
67
+ Hereโ€™s a minimal example of running an episode in the **Plane** environment and saving a video:
68
+
69
+ ```python
70
+ from target_gym import Plane, PlaneParams
71
+
72
+ # Create env
73
+ env = Plane()
74
+ seed = 42
75
+ env_params = PlaneParams(max_steps_in_episode=1_000)
76
+
77
+ # Simple constant policy with 80% power and 0ยฐ stick input
78
+ action = (0.8, 0.0)
79
+
80
+ # Save the video
81
+ env.save_video(lambda o: action, seed, folder="videos", episode_index=0, params=env_params, format="gif")
82
+ ```
83
+
84
+ Or train an agent using your favorite RL library (example with stable-baselines3):
85
+
86
+ ```python
87
+ from target_gym import PlaneGymnasium, PlaneParams
88
+ from stable_baselines3 import SAC
89
+
90
+ env = PlaneGymnasium()
91
+ model = SAC("MlpPolicy", env, verbose=1)
92
+ model.learn(total_timesteps=10_000, log_interval=4)
93
+ model.save("sac_plane")
94
+
95
+ obs, info = env.reset()
96
+ while True:
97
+ action, _states = model.predict(obs, deterministic=True)
98
+ obs, reward, terminated, truncated, info = env.step(action)
99
+ if terminated or truncated:
100
+ break
101
+ ```
102
+
103
+ ---
104
+
105
+ ## ๐Ÿงฉ Challenges Modeled
106
+
107
+ TargetGym tasks are designed to expose RL agents to **realistic control challenges**:
108
+
109
+ * โณ **Delays**: Inputs (like engine power) take time to fully apply.
110
+ * ๐Ÿ‘€ **Partial observability**: Some parts of the state cannot be directly measured.
111
+ * ๐Ÿ **Competing objectives**: Reach the target state quickly while minimizing overshoot or cost.
112
+ * ๐ŸŒ€ **Momentum effects**: Physical inertia delays control effectiveness.
113
+ * โš ๏ธ **Irrecoverable states**: Certain trajectories inevitably lead to failure.
114
+
115
+ ---
116
+
117
+ ## ๐Ÿ“ฆ Roadmap
118
+
119
+ * [ ] Add perturbations (wind, turbulence, uneven terrain) for non-stationary dynamics.
120
+ * [ ] Easier interface for creating partially-observable variants.
121
+ * [ ] Provide benchmark results for popular RL baselines.
122
+ * [ ] Add fuel consumption and resource constraints.
123
+ * [ ] Add more tasks.
124
+
125
+ ---
126
+
127
+ ## ๐Ÿค Contributing
128
+
129
+ Contributions are welcome!
130
+ Open an issue or PR if you have suggestions, bug reports, or new features.
131
+
132
+ ---
133
+
134
+
135
+ ## ๐Ÿ“– Citation
136
+
137
+ If you use **TargetGym** in your research or project, please cite it as:
138
+
139
+ ```bibtex
140
+ @misc{targetgym2025,
141
+ title = {TargetGym: Reinforcement Learning Environments for Target MDPs},
142
+ author = {Yann Berthelot},
143
+ year = {2025},
144
+ url = {https://github.com/YannBerthelot/TargetGym},
145
+ note = {Lightweight physics-based RL environments for aircraft, car, and bike control}
146
+ }
147
+ ```
148
+
149
+
150
+ ---
151
+
152
+ ## ๐Ÿ“œ License
153
+
154
+ MIT License โ€“ free to use in research and projects.
155
+
156
+
@@ -0,0 +1,89 @@
1
+ [tool.poetry]
2
+ name = "target-gym"
3
+ version = "0.2.0"
4
+ description = "A reinforcement learning environment for simulating target-MDP environments (Airplane, Car, Bicycle), with gymnasium and gymnax support" # Add a description
5
+ authors = ["Yann Berthelot <yannberthelot1@gmail.com>"]
6
+ readme = "README.md"
7
+ homepage = "https://github.com/yannberthelot/Plane" # Add your repository URL
8
+ repository = "https://github.com/yannberthelot/Plane"
9
+ keywords = ["reinforcement-learning", "gymnasium", "jax", "airplane", "car", "simulation", "bike"] # Add relevant keywords
10
+ classifiers = [ # Add relevant classifiers
11
+ "Development Status :: 3 - Alpha",
12
+ "Intended Audience :: Science/Research",
13
+ "License :: OSI Approved :: MIT License",
14
+ "Programming Language :: Python :: 3",
15
+ "Topic :: Scientific/Engineering :: Artificial Intelligence",
16
+ ]
17
+
18
+ packages = [
19
+ { include = "target_gym", from = "src" }, # This tells Poetry where to find the package
20
+ ]
21
+
22
+ [tool.poetry.dependencies]
23
+ python = "<3.13,>=3.10"
24
+ gymnax = "^0.0.9"
25
+ numpy = "^1.26.1"
26
+ six = "^1.16.0"
27
+ matplotlib = "^3.8.1"
28
+ gymnasium = "^1.2.0"
29
+ distrax = "^0.1.5"
30
+ jax = "<7.0"
31
+ moviepy = "^2.2.1"
32
+ pygame = "^2.6.1"
33
+
34
+ [tool.black]
35
+ line-length = 88
36
+ target-version = ['py310']
37
+ include = '\.pyi?$'
38
+ exclude = '''
39
+ /(
40
+ \.eggs
41
+ | \.git
42
+ | \.hg
43
+ | \.mypy_cache
44
+ | \.tox
45
+ | \.venv
46
+ | _build
47
+ | buck-out
48
+ | build
49
+ | dist
50
+ )/
51
+ '''
52
+
53
+ [tool.poetry.group.dev.dependencies]
54
+ pytest = "^7.4.3"
55
+ isort = "^5.12.0"
56
+ pre-commit = "^3.5.0"
57
+ mypy = "^1.6.1"
58
+ codecov = "^2.1.13"
59
+ coverage = "^7.3.2"
60
+ pytest-cov = "^4.1.0"
61
+ pytest-readme = "^1.0.2"
62
+ flake8 = "^7.3.0"
63
+ ruff = "^0.12.11"
64
+ black = "^25.1.0"
65
+
66
+ [tool.poetry.group.agent.dependencies]
67
+ stable-baselines3 = "^2.7.0"
68
+ tensorboard = "^2.20.0"
69
+
70
+
71
+ [tool.poetry.group.readme.dependencies]
72
+ pytest-readme = "^1.0.2"
73
+
74
+
75
+ [tool.poetry.group.wandb.dependencies]
76
+ wandb = "^0.21.3"
77
+
78
+ [[tool.poetry.source]]
79
+ name = "jax"
80
+ url = "https://storage.googleapis.com/jax-releases/jax_cuda_releases.html"
81
+ priority = "primary"
82
+
83
+ [[tool.poetry.source]]
84
+ name = "PyPI"
85
+ priority = "supplemental"
86
+
87
+ [build-system]
88
+ requires = ["poetry-core"]
89
+ build-backend = "poetry.core.masonry.api"
@@ -0,0 +1,17 @@
1
+ from target_gym.bicycle.env import EnvParams as BikeParams
2
+ from target_gym.bicycle.env_jax import RandlovBicycle as Bike
3
+ from target_gym.car.env import EnvParams as CarParams
4
+ from target_gym.car.env_jax import Car2D as Car
5
+ from target_gym.plane.env import EnvParams as PlaneParams
6
+ from target_gym.plane.env_gymnasium import Airplane2D as PlaneGymnasium
7
+ from target_gym.plane.env_jax import Airplane2D as Plane
8
+
9
+ __all__ = (
10
+ "Car",
11
+ "PlaneGymnasium",
12
+ "Plane",
13
+ "Bike",
14
+ "PlaneParams",
15
+ "CarParams",
16
+ "BikeParams",
17
+ ) # Make Flake8 Happy