agentleFS
Google DeepMindKnown publishergoogle-deepmind/mujoco/doc/skills/accelerated/SKILL.md

mujoco-accelerated

Skill15k starsChanged 3 months agoApache-2.0View on GitHub

GPU and TPU batch simulation, MJX (JAX), MJWarp (CUDA), parallel rollouts (jax.vmap), trajectory scan (jax.lax.scan), differentiability, device memory (put_model, put_data), njmax contact pre-allocation, float32 precision, XLA compilation caching. Use for RL environment batches, GPU rollouts, differentiable physics. Do NOT use for CPU simulation, noslip/PGS solvers (mujoco-python), rendering (mujoco-rendering), or GUI (mujoco-gui).

Trending

Quiet since August.thin dataabout the whole repository

Dec 2025: 1 mentionJan 2026: 0 mentionsFeb 2026: 0 mentionsMar 2026: 0 mentionsApr 2026: 2 mentionsMay 2026: 0 mentionsJun 2026: 0 mentionsJul 2026: 1 mentionAug 2026: 1 mentionSep 2026: 0 mentionsOct 2026: 0 mentionsNov 2026: 0 mentions
Dec 2025Jun 2026Nov 2026
Mentions a month of the google-deepmind/mujoco repository that our weekly crawl found: only 13 in all, so this is a hint, not a trend. There is no adoption data for this file yet.

Who's talking about google-deepmind/mujoco

The biggest 5 of 13 mentions linking to the repository that our crawl found. Each line is their own headline.

See all 13

Talked about on GitHub, Hacker News and Bluesky (13 times).

On GitHub · 10

5 more on GitHub

On Hacker News · 2

On Bluesky · 1

The file

We split this skill into the rules it gives an agent

2 rules. About 0 are common, 2 are distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈2

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    PGS solver: Not available on GPU backends.

    line 174
  2. Distinctive:

    Compilation caching: Avoid long recompilations on startup by enabling persistent XLA caching:

    line 187

≈ “Common” is an estimate: at least 1 in 5 of the 213,895 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

MuJoCo Accelerated: MJX & MJWarp GPU Backends

[!TIP]

Related skills:

  • mujoco-python — CPU physics simulation, kinematics, and full solver suite.
  • mujoco-studio — Interactive simulation and Studio viewer plugins.

[!IMPORTANT]

MJX and MJWarp are Python-only GPU acceleration backends. Standard CPU simulation runs in full float64 via import mujoco.

1. Backend Comparison: C++ vs MJX vs MJWarp

FeatureC++ Engine (Default)MJX (JAX)MJWarp (CUDA)
Importimport mujocofrom mujoco import mjximport mujoco_warp as mjw
HardwareCPUGPU / TPUNVIDIA GPU
Precisionfloat64float32float32
Differentiable❌ No✅ Yes (JAX gradients)❌ No
Batch Stepping❌ Serial / multi-threaded✅ jax.vmap✅ Native CUDA batches
SolversNewton, CG, PGS, noslipNewton, CGNewton, CG
Constraint Islands✅ Yes❌ No❌ No
PluginsAll engine plugins❌ NoSDF plugins only

2. MJX Workflow (JAX)

MJX translates MuJoCo data structures into immutable JAX pytrees that execute natively on GPUs and TPUs.

import mujoco
from mujoco import mjx

# 1. Load CPU model and data
model = mujoco.MjModel.from_xml_path('scene.xml')
data = mujoco.MjData(model)

# 2. Transfer to device (GPU/TPU)
# ALWAYS specify njmax when contacts are present
mjx_model = mjx.put_model(model)
mjx_data = mjx.put_data(model, data, njmax=500)

# 3. Step on device (functional paradigm returns new data)
mjx_data = mjx.step(mjx_model, mjx_data)

# 4. Copy data back to host CPU
mjx.get_data_into(data, model, mjx_data)
print(data.body('torso').xpos)

3. High-Throughput Rollouts: jax.vmap and jax.lax.scan

Parallel Batches (jax.vmap)

import jax
from mujoco import mjx

# Vectorize step over batch dimension (model unbatched, data batched)
batched_step = jax.vmap(mjx.step, in_axes=(None, 0))

# JIT-compile for maximum device throughput
batched_step_jit = jax.jit(batched_step)
batch_data = batched_step_jit(mjx_model, batch_data)

Multi-Step Trajectory Rollouts (jax.lax.scan)

For RL environment steps, avoid Python loops by scanning across steps:

def rollout(model: mjx.Model, init_data: mjx.Data, ctrl_sequence: jax.Array):
  def step_fn(d, ctrl):
    d = d.replace(ctrl=ctrl)
    d = mjx.step(model, d)
    return d, (d.qpos, d.sensordata)

  final_data, trajectory = jax.lax.scan(step_fn, init_data, ctrl_sequence)
  return final_data, trajectory

4. Contact Pre-allocation (The njmax Gotcha)

[!CAUTION]

mjx.put_data() pre-allocates GPU memory for contacts based on data.ncon. On a newly initialized MjData, data.ncon is 0. If njmax is omitted, the device contact buffer size is 0 and contacts will be silently ignored.

Always provide njmax:

# ✅ RIGHT — allocates capacity for up to 500 contacts
mjx_data = mjx.put_data(model, data, njmax=500)

A standard rule of thumb is 2× to 5× the expected peak number of contacts.

5. MJX Named Access & bind()

MJX provides declarative named access over JAX arrays via bind():

spec = mujoco.MjSpec.from_file('model.xml')
model = spec.compile()
data = mujoco.MjData(model)

mx = mjx.put_model(model)
dx = mjx.put_data(model, data, njmax=500)

# Read body positions from JAX device arrays
torso_pos = dx.bind(mx, spec.body('torso')).xpos

# Functional update of control inputs
dx = dx.bind(mx, spec.actuators).set('ctrl', [1.0, 0.5])

6. MJWarp Guide (NVIDIA CUDA)

MJWarp (mujoco_warp) provides a CUDA-native simulator optimized for maximum batch throughput on NVIDIA hardware without JAX:

import mujoco
import mujoco_warp as mjw

model = mujoco.MjModel.from_xml_path('scene.xml')
batch_size = 4096

# Transfer batch to CUDA
mjw_model = mjw.put_model(model)
mjw_data = mjw.put_data(model, batch_size)

# Advance all 4096 environments in parallel
mjw.step(mjw_model, mjw_data)

# Extract states directly into GPU tensors or NumPy arrays
qpos_tensor = mjw_data.qpos

7. Supported Geometries & Feature Gaps

Collision Geom Support Matrix

Geometry PairMJX (JAX)MJWarp (CUDA)
Sphere - Sphere✅ Supported✅ Supported
Sphere - Plane✅ Supported✅ Supported
Capsule - Capsule✅ Supported✅ Supported
Capsule - Plane✅ Supported✅ Supported
Box - Plane✅ Supported✅ Supported
Mesh - Primitive✅ Convex meshes✅ Convex meshes
Mesh - Mesh⚠️ Performance sensitive✅ Warp accelerated

Solvers Not Available on GPU

  • noslip solver: Available only in C++ engine. If exact frictional stick conditions without sliding drift are required, use CPU.
  • PGS solver: Not available on GPU backends.
  • Constraint Islands: Handled monolithically on GPU.

8. Common Gotchas & Numerical Stability

  1. Float32 precision: GPU backends run in single precision (float32). Stiff systems may experience numerical drift or NaN errors. Counteract this by increasing model.opt.iterations or decreasing model.opt.timestep.
  2. Immutability in MJX: mjx.Data is a JAX pytree. In-place assignments fail; use .replace():
    mjx_data = mjx_data.replace(qpos=new_qpos)
  3. Compilation caching: Avoid long recompilations on startup by enabling persistent XLA caching:
    import jax
    jax.config.update('jax_compilation_cache_dir', '/tmp/jax_cache')

9. Key References

Documentation

  • MJX Guide
  • Python Bindings Reference

Source Code Examples

  • MJX Support Tests

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.