mjbatch
mjbatch is a Python library for running thousands of MuJoCo simulations in parallel on CPU.
Features include:
- C++ thread pool execution, with the GIL released;
- Live array access to simulation state and controls across the batch, with
bindfor MjData fields; - Per-simulation model parameters, with
expandfor MjModel fields andset_constto recompute derived constants. - Batched queries beyond stepping: site Jacobians with
jac_siteand heightfield sampling withsample_hfield(world/yaw grid alignment); query ops return caller-allocated results without refreshing the bound views. - Per-substep control from Python with
step(..., callback=...). - Optional per-worker CPU pinning on Linux, with
cpu_idsbinding pool workeritocpu_ids[i].
For example:
import mujoco, numpy as np
from mjbatch import Batch
model = mujoco.MjModel.from_xml_path("scene.xml")
batch = Batch(model, num_sims=4096) # threads default to every logical CPU
qpos, ctrl = batch.bind("qpos"), batch.bind("ctrl")
batch.expand("geom_friction")[:, :, 0] = np.random.uniform(0.4, 1.2, (4096, 1))
for _ in range(1000):
ctrl[:] = policy(qpos) # your controller, all 4096 at once
batch.step() # step them in parallel; qpos updates in place
sample_hfield samples a shared heightfield at XY offsets around a body origin,
returning the world z of the sampled surface. alignment="yaw" rotates the
sampling grid by the frame body's yaw about world z, so a per-sim geom_quat
rotates each simulation's scan pattern.
Examples
We showcase a range of applications built using mjbatch: RL, MPC, SysID, and hardware
co-design. Each example is a self-contained, performant implementation. For instance, the Go1
RL controller learns to walk in under a minute on a five-year-old M1 laptop.
|
|
|
| A two-pole cart swung upright with iLQR | A cart-pole swing-up controller using predictive sampling |
|
|
|
| A G1 humanoid tracking a reference backflip with receding-horizon iLQR | A Go1 quadruped joystick controller trained with PPO |
|
|
|
| CEM jointly optimizes a robot arm's proportions, gears, and controls | Damped Gauss–Newton fits a Rizon arm's inertial parameters to synthetic motion data |
Run with uv run examples/<file>.py; some need uv sync --group examples. The ones that open
a window need a display; --headless runs the solver without one.
License
Apache-2.0.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mjbatch_uni-0.0.0.tar.gz.
File metadata
- Download URL: mjbatch_uni-0.0.0.tar.gz
- Upload date:
- Size: 28.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
586d14cdd6fd1d9e243d998a47189845ded45cf145c51f3871140f9a57b99d24
|
|
| MD5 |
107856daaafdc01b69d6189e8003c2e0
|
|
| BLAKE2b-256 |
78646b877f7cbe289c8e1d9fb4d69e587d1353e3334bb43f33b864e4c418184a
|
File details
Details for the file mjbatch_uni-0.0.0-cp313-cp313-manylinux_2_35_x86_64.whl.
File metadata
- Download URL: mjbatch_uni-0.0.0-cp313-cp313-manylinux_2_35_x86_64.whl
- Upload date:
- Size: 169.9 kB
- Tags: CPython 3.13, manylinux: glibc 2.35+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e89501b7dacbdeaaa1b3037ad1f3c7185b8db4eacd8b16a4d03719d77c9713fa
|
|
| MD5 |
695948e870e8efd2b8f9cbbfc6f05a72
|
|
| BLAKE2b-256 |
d6f3a554d79488984d5c6c52f4c13086ce51b40b953a8533c26a9fa187c84683
|