mjbatch

mjbatch

CPU-parallel batched MuJoCo simulation library

Description

Training RL policies or running MPC sampling, the thing that burns the most is simulation throughput — stepping one MuJoCo environment at a time leaves the CPU mostly idle over thousands of steps, and Python's GIL blocks real multithreading. mjbatch clears that road: a Python library that steps thousands of MuJoCo simulations in parallel on CPU, executing on a C++ thread pool with the GIL released — so it's genuinely all cores at once, not fake parallelism.

The interface stays lean — `Batch(model, num_sims=4096)` opens four thousand environments in one line, `bind` gives you a live array over the whole batch's state and controls, your controller computes all four thousand at once, and `step()` advances them in parallel with `qpos` updated in place. In the author's examples, a Go1 quadruped learns to walk in under a minute on a five-year-old M1 laptop. Useful for RL, MPC, system identification and hardware co-design.

Features



C++ thread pool · GIL released: The batch runs in a native thread pool with the Python GIL released during execution, so it truly saturates every core instead of stalling on the interpreter lock.

Live batched state access: `bind` maps a whole batch of MjData fields (qpos, ctrl, ...) to one live read/write array, so a controller reads and writes all simulations at once with no per-sim copying.

Per-simulation parameters: `expand` sets MjModel fields (e.g. geom_friction) per simulation, and `set_const` recomputes derived constants — domain randomization and parameter sweeps drop right in.

Auto thread fan-out: Threads default to every logical CPU when unspecified, using the whole machine out of the box.

Covers many research settings: Ships self-contained, performant examples for RL, MPC, system identification and hardware co-design.