Skip to main content

mjbatch

Build PyPI version

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 bind for MjData fields;
  • Per-simulation model parameters, with expand for MjModel fields and set_const to recompute derived constants.
  • Batched queries beyond stepping: site Jacobians with jac_site and heightfield sampling with sample_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_ids binding pool worker i to cpu_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.

cart-pole swing-up cart-pole MPC
A two-pole cart swung upright with iLQR A cart-pole swing-up controller using predictive sampling
G1 backflip Go1 joystick
A G1 humanoid tracking a reference backflip with receding-horizon iLQR A Go1 quadruped joystick controller trained with PPO
throwing arm co-design Rizon inertia identification
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

mjbatch_uni-0.0.0.tar.gz (28.9 kB view details)

Uploaded Source

Built Distribution

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

mjbatch_uni-0.0.0-cp313-cp313-manylinux_2_35_x86_64.whl (169.9 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.35+ x86-64

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

Hashes for mjbatch_uni-0.0.0.tar.gz
Algorithm Hash digest
SHA256 586d14cdd6fd1d9e243d998a47189845ded45cf145c51f3871140f9a57b99d24
MD5 107856daaafdc01b69d6189e8003c2e0
BLAKE2b-256 78646b877f7cbe289c8e1d9fb4d69e587d1353e3334bb43f33b864e4c418184a

See more details on using hashes here.

File details

Details for the file mjbatch_uni-0.0.0-cp313-cp313-manylinux_2_35_x86_64.whl.

File metadata

File hashes

Hashes for mjbatch_uni-0.0.0-cp313-cp313-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 e89501b7dacbdeaaa1b3037ad1f3c7185b8db4eacd8b16a4d03719d77c9713fa
MD5 695948e870e8efd2b8f9cbbfc6f05a72
BLAKE2b-256 d6f3a554d79488984d5c6c52f4c13086ce51b40b953a8533c26a9fa187c84683

See more details on using hashes here.

Release history Release notifications | RSS feed

0.2.1

13 files

0.2.0

13 files

0.1.0

13 files

This release

0.0.0 This release

2 files

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