Skip to main content

mjbatch-uni

Build PyPI version

mjbatch-uni 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.
  • Same-layout compiler-coherent mesh variants, with VariantPack.from_specs() and Batch.from_variant_pack().
  • Explicit topology-affine groups, with ModelAffineBatch routing global ids to incompatible layouts.
  • 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=...).
  • Opt-in split substeps with fresh position/velocity sensor views for body wrench control.
  • 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

Callbacks can also consume tracked sensors at the exact state they are controlling. With Euler, substep_sensor_copyout=(start, stop) splits each substep at mj_step1 / mj_step2, copies the declared sensor columns into a fourth callback view, and applies ctrl plus bound inputs such as xfrc_applied to that substep:

xfrc = batch.bind("xfrc_applied")

def control(k, state, ctrl, sensor):
  ctrl[:] = impedance(sensor)       # position/velocity sensors match state
  xfrc[:, body_id] = wrench(sensor)

batch.step(callback=control, substep_sensor_copyout=(sensor_start, sensor_stop))

Acceleration-stage sensors and contact forces are not available before mj_step2 and may be stale in that view. The default callback path and all outputs are unchanged unless the optional range is passed.

After a normal step() with forward=False, selected position- and velocity-stage sensor columns can be refreshed from the final integration state without a full mj_forward:

batch.refresh_sensor_range(ids, (sensor_start, sensor_stop))

The refresh runs in native worker threads, copies only the requested columns into the bound sensordata view, and leaves acceleration-stage sensors (including contact forces) and all other bound fields unchanged. Disjoint ranges can be refreshed in one dispatch with refresh_sensor_ranges(ids, (start0, stop0, start1, stop1, ...)).

Model randomization and variants

expand(field) returns a live (num_sims, ...) view of a non-asset MjModel field. Rows are applied before each selected simulation runs. model_field_specs() describes the shape, dtype, writability, and recompute dependency of every field. Declare the fields being written to model_update; like mjlab event terms, mjbatch computes the strongest recompute level and runs one conservative stock-MuJoCo mj_setConst pass.

from mjbatch import RecomputeLevel

assert batch.model_field_specs()["body_mass"].recompute == RecomputeLevel.SET_CONST
with batch.model_update("body_mass", "geom_friction", ids=reset_envs):
  batch.expand("body_mass")[reset_envs, body_id] *= 1.1
  batch.expand("geom_friction")[reset_envs, :, 0] = friction_samples

For mesh-only differences, VariantPack.from_specs() independently compiles each source spec, pools and deduplicates meshes, aligns named geom slots, disables missing optional slots, and scatters compiler-derived geometry and inertia fields. Batch.from_variant_pack() applies its fixed assignment and initial recompute.

from mjbatch import Batch, VariantPack

pack = VariantPack.from_specs([tool_spec_0, tool_spec_1, tool_spec_2])
batch = Batch.from_variant_pack(pack, num_sims, np.arange(num_sims) % 3)

Truly incompatible topologies are not silently padded. Put each one in its own Batch and route fixed global assignments through ModelAffineBatch. State and field views remain on each TopologyGroup; global history is rejected.

from mjbatch import ModelAffineBatch

sharded = ModelAffineBatch([batch_a, batch_b], names=["one_joint", "two_joint"])
sharded.step(np.array([0, 3, 4]))
state_a, state_b = sharded["one_joint"].state, sharded["two_joint"].state

Reproducible cold-start, RSS, stepping, and model-field-update measurements:

uv run python benchmarks/topology_groups.py --num-sims 512 --threads 4

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.

Metadata

Release files for mjbatch-uni 0.2.3

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

Source distribution (sdist)

Source distribution for mjbatch-uni 0.2.3
File Size Uploaded
mjbatch_uni-0.2.3.tar.gz 43.7 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for mjbatch-uni 0.2.3
File
mjbatch_uni-0.2.3-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl CPython 3.13 CPython 3.13 Linux glibc 2.27+ x86-64, Linux glibc 2.28+ x86-64 Details
mjbatch_uni-0.2.3-cp313-cp313-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl CPython 3.13 CPython 3.13 Linux glibc 2.28+ ARM64, Linux glibc 2.26+ ARM64 Details
mjbatch_uni-0.2.3-cp313-cp313-macosx_11_0_arm64.whl CPython 3.13 CPython 3.13 macOS 11.0+ ARM64 Details
mjbatch_uni-0.2.3-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl CPython 3.12 CPython 3.12 Linux glibc 2.28+ x86-64, Linux glibc 2.27+ x86-64 Details
mjbatch_uni-0.2.3-cp312-cp312-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl CPython 3.12 CPython 3.12 Linux glibc 2.28+ ARM64, Linux glibc 2.26+ ARM64 Details
mjbatch_uni-0.2.3-cp312-cp312-macosx_11_0_arm64.whl CPython 3.12 CPython 3.12 macOS 11.0+ ARM64 Details
mjbatch_uni-0.2.3-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl CPython 3.11 CPython 3.11 Linux glibc 2.27+ x86-64, Linux glibc 2.28+ x86-64 Details
mjbatch_uni-0.2.3-cp311-cp311-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl CPython 3.11 CPython 3.11 Linux glibc 2.28+ ARM64, Linux glibc 2.26+ ARM64 Details
mjbatch_uni-0.2.3-cp311-cp311-macosx_11_0_arm64.whl CPython 3.11 CPython 3.11 macOS 11.0+ ARM64 Details
mjbatch_uni-0.2.3-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl CPython 3.10 CPython 3.10 Linux glibc 2.27+ x86-64, Linux glibc 2.28+ x86-64 Details
mjbatch_uni-0.2.3-cp310-cp310-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl CPython 3.10 CPython 3.10 Linux glibc 2.28+ ARM64, Linux glibc 2.26+ ARM64 Details
mjbatch_uni-0.2.3-cp310-cp310-macosx_11_0_arm64.whl CPython 3.10 CPython 3.10 macOS 11.0+ ARM64 Details

Total release size: 2.2 MB

Release files / mjbatch_uni-0.2.3.tar.gz

Download URL mjbatch_uni-0.2.3.tar.gz
Size 43.7 kB
Tags Source
SHA-256 checksum
How to use checksums
06f2b2eac3cca1f9b6e49590d4e5806bcc0f810751388299152e351e8f2304a5
BLAKE2b-256 checksum
How to use checksums
c84b25045002da76322f335ca5a2fa537e4cc742ad60013db8df0a90227eb2bf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.13

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 20, 2026.

Transparency log

Release files / mjbatch_uni-0.2.3-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl

Download URL mjbatch_uni-0.2.3-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Size 196.0 kB
Tags CPython 3.13 Linux glibc 2.27+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
245854cf34f5e4600e747ef78c4e7986d14aa68a91f34760ae7585dd4dc05b38
BLAKE2b-256 checksum
How to use checksums
ebafaed3093b9b60f2a30ff9be3b67d6f413ecf6835e384c3126dcf27a15add9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.13

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 20, 2026.

Transparency log

Release files / mjbatch_uni-0.2.3-cp313-cp313-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl

Download URL mjbatch_uni-0.2.3-cp313-cp313-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl
Size 185.2 kB
Tags CPython 3.13 Linux glibc 2.26+ ARM64 Linux glibc 2.28+ ARM64
SHA-256 checksum
How to use checksums
f86430d883a28d6d8890c6b31bdbe227b99179112ea2fd7533ab2e285aea78f8
BLAKE2b-256 checksum
How to use checksums
f32ea918d549bd4e16d7def0d4f4ed5d17e927aeb5547816842455796bbd1f92
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.13

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 20, 2026.

Transparency log

Release files / mjbatch_uni-0.2.3-cp313-cp313-macosx_11_0_arm64.whl

Download URL mjbatch_uni-0.2.3-cp313-cp313-macosx_11_0_arm64.whl
Size 155.8 kB
Tags CPython 3.13 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
0b9f08e67d4eddcbdbc5b732e2fbead2ba7c203bddbcb3a266216db8d843cf03
BLAKE2b-256 checksum
How to use checksums
901359dfa3f147b3c70e15e46c3ed3ca9524fad2443b3d3d45edc2785fae0a66
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.13

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 20, 2026.

Transparency log

Release files / mjbatch_uni-0.2.3-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl

Download URL mjbatch_uni-0.2.3-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Size 196.0 kB
Tags CPython 3.12 Linux glibc 2.27+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
e50d39a3393f7c2bc623a85db3426e64807d001b1bc8e373f6e90c3c973484a5
BLAKE2b-256 checksum
How to use checksums
ceb5d37c4355468455aa7d0aa8240ba1b80eb415efb247a7be12bbef59b56f2e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.13

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 20, 2026.

Transparency log

Release files / mjbatch_uni-0.2.3-cp312-cp312-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl

Download URL mjbatch_uni-0.2.3-cp312-cp312-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl
Size 185.2 kB
Tags CPython 3.12 Linux glibc 2.26+ ARM64 Linux glibc 2.28+ ARM64
SHA-256 checksum
How to use checksums
079e415b0f510912a63ccc2589eb0da0aa97af70928b889c92c6df6d21940822
BLAKE2b-256 checksum
How to use checksums
68c08dcedd090bcfc166453b1632baa37b4437a2cd9436d8239ccaac326924bb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.13

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 20, 2026.

Transparency log

Release files / mjbatch_uni-0.2.3-cp312-cp312-macosx_11_0_arm64.whl

Download URL mjbatch_uni-0.2.3-cp312-cp312-macosx_11_0_arm64.whl
Size 155.8 kB
Tags CPython 3.12 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
dc95a5b920b066ecc87c7436416a0b426e21af6331b162d9c38a53e50084e26c
BLAKE2b-256 checksum
How to use checksums
c273f36f56b4eb231d2d307f43a71be15107d2742fbcaaa3faddf419b8b12928
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.13

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 20, 2026.

Transparency log

Release files / mjbatch_uni-0.2.3-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl

Download URL mjbatch_uni-0.2.3-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Size 196.4 kB
Tags CPython 3.11 Linux glibc 2.27+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
81c6fe9dc66c05f1850088f05605688a7dc2274b047f0841a536f48faa9ad0b5
BLAKE2b-256 checksum
How to use checksums
eb3d5a0f6d9e280e94f57d805e3fa028fe1c716483ec796260d5735b4bfca11f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.13

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 20, 2026.

Transparency log

Release files / mjbatch_uni-0.2.3-cp311-cp311-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl

Download URL mjbatch_uni-0.2.3-cp311-cp311-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl
Size 186.2 kB
Tags CPython 3.11 Linux glibc 2.26+ ARM64 Linux glibc 2.28+ ARM64
SHA-256 checksum
How to use checksums
8be976f40a2f9ec6f5ed0018f89a373ded8c466d0950cdb52023b04293508b86
BLAKE2b-256 checksum
How to use checksums
2bfdb1ca7575f6a7008e5ab95f53c7f65f08f710f828865965a972a831d06eea
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.13

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 20, 2026.

Transparency log

Release files / mjbatch_uni-0.2.3-cp311-cp311-macosx_11_0_arm64.whl

Download URL mjbatch_uni-0.2.3-cp311-cp311-macosx_11_0_arm64.whl
Size 156.5 kB
Tags CPython 3.11 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
9ad7598d0f429bbc0efd8999ba031f8baec0772e97702a87a0090762e821bd54
BLAKE2b-256 checksum
How to use checksums
a4d531f6b07bcd0d8052f48e85075eae536f4f20780ce21658ed4959a5a87473
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.13

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 20, 2026.

Transparency log

Release files / mjbatch_uni-0.2.3-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl

Download URL mjbatch_uni-0.2.3-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Size 196.6 kB
Tags CPython 3.10 Linux glibc 2.27+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
dd7a3dd8e702e79dac5e65e9b5c641e52fcd40ccbb5e46ab62fab30f3a302716
BLAKE2b-256 checksum
How to use checksums
e043193224d78f14ccccb4c0d8a84624468cc7456fbc716f53639437f913b6e7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.13

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 20, 2026.

Transparency log

Release files / mjbatch_uni-0.2.3-cp310-cp310-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl

Download URL mjbatch_uni-0.2.3-cp310-cp310-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl
Size 186.4 kB
Tags CPython 3.10 Linux glibc 2.26+ ARM64 Linux glibc 2.28+ ARM64
SHA-256 checksum
How to use checksums
9ac6af4c049b7d911351ca1f57ab6459c1e189055069a345d74f11e25f64be2d
BLAKE2b-256 checksum
How to use checksums
7522a219ab113dcfb4ccd5cea4093c156ae3eb64f99bb949849907834d54bd3a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.13

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 20, 2026.

Transparency log

Release files / mjbatch_uni-0.2.3-cp310-cp310-macosx_11_0_arm64.whl

Download URL mjbatch_uni-0.2.3-cp310-cp310-macosx_11_0_arm64.whl
Size 156.9 kB
Tags CPython 3.10 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
a6954156646aaf14bfe2850df0e80d15b431912f31f810cabf0dd7feb917daf7
BLAKE2b-256 checksum
How to use checksums
b4b62d4a56df2e2ea8036fda965a83f6965fda58271cf03dbf625951e6ab6323
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.13

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 20, 2026.

Transparency log

Release history Release notifications | RSS feed

0.2.4

13 release files

This release

0.2.3 This release

13 release files

0.2.2

13 release files

0.2.1

13 release files

0.2.0

13 release files

0.1.0

13 release files

0.0.0

2 release 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