Skip to main content

MuJoDiCo (Multi-Joint dynamics with Differentiable Contact)

PyPI Python Version PyPI version

This package extends MuJoCo with differentiable contact dynamics and provides trajectory optimization algorithms for contact-rich dynamical systems. Gradients are computed using the implicit function theorem rather than differentiating through the solver rollout.

Installation

The recommended way to install this package is via PyPI:

pip install mujodico

For local development, install from a checkout:

git clone https://github.com/trustworthyrobotics/mujodico.git
cd mujodico
pip install -e .

Usage

MuJoDiCo is a drop-in replacement for MuJoCo MJX that provides differentiable contact dynamics. You can simply replace from mujoco import mjx with from mujodico import mjx. For example:

import jax
import jax.numpy as jnp
import mujoco
from mujodico import mjx

model = mujoco.MjModel.from_xml_string(XML)

mjx_model = mjx.put_model(model)

def f(x, u):
    nq, nv = mjx_model.nq, mjx_model.nv
    d = mjx.make_data(mjx_model)
    d = d.replace(qpos=x[:nq], qvel=x[nq:nq+nv], act=x[nq+nv:], ctrl=u)
    d = mjx.step(mjx_model, d)
    x_next = jnp.concatenate((d.qpos, d.qvel, d.act))
    return x_next

x = jnp.zeros(mjx_model.nq + mjx_model.nv + mjx_model.na)
u = jnp.zeros(mjx_model.nu)

A, B = jax.jacfwd(f, argnums=(0,1))(x, u)

MuJoDiCo computes dynamics Jacobian using the implicit function theorem. Both forward-mode (jax.jacfwd) and reverse-mode (jax.jacrev) differentiation are supported. The differentiable contact models are configurable through XML custom fields. Add these to your model before loading it:

<custom>
  <text name="contact_approx" data="hunt-crossley"/>
  <numeric name="contact_smoothing" data="1e-5"/>
</custom>

contact_approx specifies the contact model used for the dynamics. Supported options are mujoco, conic, log-barrier, kelvin-voigt, and hunt-crossley (defaults to mujoco). hunt-crossley is recommended for most applications.

contact_smoothing adds artificial smoothing to the contact model to make the resulting dynamics C¹-continuous (defaults to zero smoothing). A value of κ can be interpreted as applying a force of κ newtons over a distance of 1 meter. For forward simulation, where differentiability is not required, use a value of 0.0. For trajectory optimization or other gradient-based methods that require C¹-continuous dynamics, a value of 1e-5 is a good starting point, providing smooth dynamics while introducing relatively little unphysical behavior.

Examples

JAX_ENABLE_X64=1 python -m mujodico.examples --method IppasLiftedMultipleShooting --task AllegroBall --tests 10

For more options, see

python -m mujodico.examples --help

Versioning

The major.minor.micro portion of the version number matches the version of MuJoCo. Optionally, if we release updates to MuJoDiCo that target the same version of MuJoCo, a .postN suffix is added, for example 3.15.0.post2 represents the second update to MuJoDiCo for MuJoCo 3.15.0.

License and Disclaimer

MuJoDiCo is licensed under the Apache License, Version 2.0. You may obtain a copy of the License at https://www.apache.org/licenses/LICENSE-2.0.

This project includes code adapted from MuJoCo, which is licensed under Apache License, Version 2.0. You may obtain a copy of the License at https://www.apache.org/licenses/LICENSE-2.0.

Metadata

Release files for mujodico 4.0.0

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

Source distribution (sdist)

Source distribution for mujodico 4.0.0
File Size Uploaded Provenance Actions
mujodico-4.0.0.tar.gz 6.8 MB Without provenance Details for mujodico-4.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for mujodico 4.0.0
File Interpreter ABI Platform Actions
mujodico-4.0.0-py3-none-any.whl Python 3 none any Details for mujodico-4.0.0-py3-none-any.whl

Total release size: 13.7 MB

Release files / mujodico-4.0.0.tar.gz

Download URL mujodico-4.0.0.tar.gz
Size 6.8 MB
Tags Source
SHA-256 checksum
How to use checksums
c46838ed3a591318e6bf51f7d70d542eafdf5af6a960831d97c5741dc4bd89de
BLAKE2b-256 checksum
How to use checksums
303cebfb1d3719b57da3011129c8d4be5ea6dc4952535af00e69de55f085d76a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.0

Release files / mujodico-4.0.0-py3-none-any.whl

Download URL mujodico-4.0.0-py3-none-any.whl
Size 6.9 MB
Tags Python 3
SHA-256 checksum
How to use checksums
9a28550240581b369e1fc8913eb7bfa140dc9a506586d4ddbc6ae7da44a7e611
BLAKE2b-256 checksum
How to use checksums
7c306dae886e9e0153f07f526f42f929c0ebba3202f2f63286b94e701aa1d64c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.0

Security for mujodico 4.0.0

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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