Skip to main content

gymnasium-mjx

Reproduces Gymnasium's v5 MuJoCo tasks in pure JAX, on MJX, so that training runs end to end on the GPU: environment and agent compile into one program, and thousands of environments step at once.

This is not a Farama Foundation project. The model files are Gymnasium's, under its MIT licence (LICENSES/Gymnasium.txt).

Why

  • End-to-end JAX. With a JAX agent, one jitted program steps the environments and updates the agent: no Python between steps, no copies between host and device, and vmap runs thousands of environments, or several seeds, at once. A Python environment stops a JAX agent at every step.
  • The same tasks as the papers. JAX training so far meant look-alike tasks (Brax's, MuJoCo Playground's) with other models, rewards and observations, whose returns cannot be compared with published Gymnasium results. Here the model files are Gymnasium's, byte for byte, and the task code is Gymnasium's, translated line by line.

Install

pip install gymnasium-mjx                 # jax, mujoco and mujoco-mjx only
pip install "gymnasium-mjx[playground]"   # and the mujoco_playground adapter
pip install "gymnasium-mjx[warp]"         # and MuJoCo Warp, on an NVIDIA GPU

Python 3.12 or newer, MuJoCo 3.7 to 3.15 (3.14 or newer for Ant and the Humanoids on MuJoCo Warp).

Use it as Gymnasium

The same task ids and keyword arguments as gymnasium.make. The state is passed in and returned, as JAX needs:

# doc: skip (two columns side by side)
# Gymnasium                                   # gymnasium-mjx
env = gymnasium.make("Hopper-v5")             task = gymnasium_mjx.make("Hopper-v5")
obs, info = env.reset(seed=0)                 state = task.reset(jax.random.key(0))
obs, reward, terminated, truncated, info = \  state = task.step(state, action)
    env.step(action)                          # state.obs, state.reward, state.done

state.done is the termination; the time limit, task.episode_length, is the caller's to apply, as Gymnasium's TimeLimit wrapper does. Many environments at once are a vmap, and the whole step can be jitted:

import jax
import gymnasium_mjx

task = gymnasium_mjx.make("Hopper-v5")
states = jax.vmap(task.reset)(jax.random.split(jax.random.key(0), 4096))
actions = jax.numpy.zeros((4096, task.action_size))
states = jax.jit(jax.vmap(task.step))(states, actions)

Tasks

Id Contacts Id Contacts
InvertedPendulum-v5 no Hopper-v5 yes
InvertedDoublePendulum-v5 no Walker2d-v5 yes
Reacher-v5 no Pusher-v5 yes
Swimmer-v5 no Ant-v5 yes
HalfCheetah-v5 yes Humanoid-v5 yes
HumanoidStandup-v5 yes

How close to Gymnasium, and how fast

  • One step from the same state gives Gymnasium's observation, reward and termination to 1e-8 in float64, on every task.
  • The same trained policy, and the same agent trained from scratch, score the same on both sides, on the tasks measured so far (learning curves in docs/checks.md).
  • Where MJX and C MuJoCo still differ, and by how much: docs/differences.md.

All checks, the learning curves, the speed method and the tools: docs/checks.md.

Development

uv sync
uv run pre-commit run --all-files
uv run pytest

Licence

MIT (LICENSE). The model files in src/gymnasium_mjx/assets/ are Gymnasium's, MIT, copyright OpenAI and the Farama Foundation (LICENSES/Gymnasium.txt).

Metadata

Release files for gymnasium-mjx 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for gymnasium-mjx 0.2.0
File Size Uploaded Provenance Actions
gymnasium_mjx-0.2.0.tar.gz 26.6 kB Without provenance Details for gymnasium_mjx-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for gymnasium-mjx 0.2.0
File Interpreter ABI Platform Actions
gymnasium_mjx-0.2.0-py3-none-any.whl Python 3 none any Details for gymnasium_mjx-0.2.0-py3-none-any.whl

Total release size: 62.2 kB

Release files / gymnasium_mjx-0.2.0.tar.gz

Download URL gymnasium_mjx-0.2.0.tar.gz
Size 26.6 kB
Tags Source
SHA-256 checksum
How to use checksums
f201618109f42785b5d1d1a8d1155413ec0671fed564637930f33507c56e9f04
BLAKE2b-256 checksum
How to use checksums
c1467de20813c88556dceaa7963e3da2c9ce6f443fa8419740bb62436047bbd7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.8 {"installer":{"name":"uv","version":"0.13.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / gymnasium_mjx-0.2.0-py3-none-any.whl

Download URL gymnasium_mjx-0.2.0-py3-none-any.whl
Size 35.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e0b8f9847570b9fdf2b96b71c730cb0d0cda5f39b6a935646d69fb347262b905
BLAKE2b-256 checksum
How to use checksums
ba91c97ac61de5b2903d1a5dcf518c5ef38a2a1b8dcfedd8fb4acebb5d8a1856
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.8 {"installer":{"name":"uv","version":"0.13.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for gymnasium-mjx 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page