Skip to main content

A reinforcement learning environment for simulating target-MDP environments (Airplane, Car, Bicycle), with gymnasium and gymnax support

Project description

🎯 TargetGym: Reinforcement Learning Environments for Target MDPs

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).

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.

Currently included environments:

  • 🛩 Plane – control of a 2D Airbus A320-like aircraft - Stable-Target-MDP
  • 🚗 Car – maintain a desired speed on a road - Stable-Target-MDP
  • 🚲 Bike – stabilize and steer a 2D bicycle model - Unstable-Target-MDP (from Randlov et al.)

As well as environments adapted from Process-Control Gym (with gymnax support for faster speeds):

  • 🧪 CSTR - control of a chemical reaction in a continuous stirred-tank reactor (CSTR).
  • More to come
Environment Target Type Action Dim State Dim Steps / Second (1 env - $10^8$ steps - CPU)
🛩 Plane Stable-Target-MDP 2 (power, stick) 9 (z, ż, ẋ, θ, θ̇, …) ~0.54M
🚗 Car Stable-Target-MDP 1 (throttle/brake) 12 (velocity, lidar, …) ~0.85M
🚲 Bike Unstable-Target-MDP 2 (torque, displacement) 5 (angle, angular vel, pos, …) ~1.77M
🧪 CSTR Stable-Target-MDP 1 (coolant temperature) 3 (concentration, temperature, target temperature) ~1.49M

Plane

Car

Bike

CSTR

Features

  • Fast & parallelizable with JAX — scale to thousands of parallel environments on GPU/TPU.
  • Physics-based: Derived from modeling equations, not arcade physics.
  • Reliable: Unit-tested for stability and reproducibility.
  • Target MDP focus: Each task is about reaching and maintaining target states.
  • Challenging dynamics: Captures irrecoverable states, and momentum effects.
  • Visualization: All environments come with visualization.
  • Compatible with RL libraries: Offers Gymnax and Gymnasium interfaces.
  • 📦 Upcoming features: Environmental perturbations (wind, turbulence, bumpy road) and fuel consumption.

Stability

TargetGym offers a variety of stable-target-MDPs. This can be seen in the evolution of the target variable under constant policies for all environments:


Plane

Bike

Car

CSTR

Some environments like Plane and Bike offer 2D-actions, for example power and stick for Plane:


Installation

Once released on PyPI, install with:

# Using pip
pip install target-gym

# Or with Poetry
poetry add target-gym

Usage

Here’s a minimal example of running an episode in the Plane environment and saving a video:

from target_gym import Plane, PlaneParams

# Create env
env = Plane()
seed = 42
env_params = PlaneParams(max_steps_in_episode=1_000)

# Simple constant policy with 80% power and 0° stick input
action = (0.8, 0.0)

# Save the video
env.save_video(lambda o: action, seed, folder="videos", episode_index=0, params=env_params, format="gif")

Or train an agent using your favorite RL library (example with stable-baselines3):

from target_gym import GymnasiumPlane
from stable_baselines3 import SAC

env = GymnasiumPlane()
model = SAC("MlpPolicy", env, verbose=1)
model.learn(total_timesteps=10_000, log_interval=4)
model.save("sac_plane")

obs, info = env.reset()
while True:
    action, _states = model.predict(obs, deterministic=True)
    obs, reward, terminated, truncated, info = env.step(action)
    if terminated or truncated:
        break

Challenges Modeled

TargetGym tasks are designed to expose RL agents to realistic control challenges:

  • Delays: Inputs (like engine power) take time to fully apply.
  • Partial observability: Some parts of the state cannot be directly measured.
  • Competing objectives: Reach the target state quickly while minimizing overshoot or cost.
  • Momentum effects: Physical inertia delays control effectiveness.
  • Irrecoverable states: Certain trajectories inevitably lead to failure.
  • Non-stationarity: Introduce perturbations in the environments.

Roadmap

  • Add perturbations (wind, turbulence, uneven terrain) for non-stationary dynamics.
  • Easier interface for creating partially-observable variants.
  • Provide benchmark results for popular RL baselines.
  • Add fuel consumption and resource constraints.
  • Add more PC-gym tasks.

🤝 Contributing

Contributions are welcome! Open an issue or PR if you have suggestions, bug reports, or new features.

For development you need to install the dev dependencies, which include test, lint and agent dependencies.

git clone https://github.com/YannBerthelot/TargetGym.git
cd TargetGym

# Using Poetry (recommended)
poetry install --with dev

# Using pip
python -m pip install -e ".[dev]"

📖 Citation

If you use TargetGym in your research or project, please cite it as:

@misc{targetgym2025,
  title        = {TargetGym: Reinforcement Learning Environments for Target MDPs},
  author       = {Yann Berthelot},
  year         = {2025},
  url          = {https://github.com/YannBerthelot/TargetGym},
  note         = {Lightweight physics-based RL environments for aircraft, car, and bike control}
}

📜 License

MIT License – free to use in research and projects.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

target_gym-0.3.1.tar.gz (45.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

target_gym-0.3.1-py3-none-any.whl (61.0 kB view details)

Uploaded Python 3

File details

Details for the file target_gym-0.3.1.tar.gz.

File metadata

  • Download URL: target_gym-0.3.1.tar.gz
  • Upload date:
  • Size: 45.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.2.0 CPython/3.12.11 Linux/6.11.0-1018-azure

File hashes

Hashes for target_gym-0.3.1.tar.gz
Algorithm Hash digest
SHA256 a3f17cb237bcb9f4662fb048615f956878c7cbc4f7798d62e555b5ce37f3fb6d
MD5 9f7932737ff0756c10ac6bccf162534d
BLAKE2b-256 4816f8bff96423998e3f923f36f6126ae5f6ed7be2e8144bc875bebca7794235

See more details on using hashes here.

File details

Details for the file target_gym-0.3.1-py3-none-any.whl.

File metadata

  • Download URL: target_gym-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 61.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.2.0 CPython/3.12.11 Linux/6.11.0-1018-azure

File hashes

Hashes for target_gym-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 cd8132b77654202b5ad6a25be1ae6fe9f03c62566b3a18a07c4caaece7e974b7
MD5 dbbfd89628eb646ac3a8e5e6bc652517
BLAKE2b-256 57910492bfb6d0dfe0191f76ee2ae9639cb098649a5d8d609914287c587d2e32

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page