Skip to main content

MuJoDiCo (Multi-Joint dynamics with Differentiable Contact)

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/wei-chen-li/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,
    contact_approximation='Hunt-Crossley',
    contact_smoothing=0.0,
)

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.

Contact Modeling

MuJoDiCo provides configurable contact models through two parameters:

  • contact_approximation — specifies the contact model used for the dynamics. 'Hunt-Crossley' is recommended for most applications.
  • contact_smoothing — adds artificial smoothing to the contact model to make the resulting dynamics C¹-continuous.

The contact_smoothing=κ parameter controls the amount of regularization. It can be interpreted as applying a force of κ newtons over a distance of 1 meter.

For forward simulation, where differentiability is not required, use contact_smoothing=0.0. For trajectory optimization or other gradient-based methods that require C¹-continuous dynamics, contact_smoothing=1e-5 is a good starting point, providing smooth dynamics while introducing relatively little unphysical behavior.

Examples

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. 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 3.17.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 3.17.0
File Size Uploaded Provenance Actions
mujodico-3.17.0.tar.gz 6.8 MB Without provenance Details for mujodico-3.17.0.tar.gz

Built distribution (wheel)

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

Total release size: 13.6 MB

Release files / mujodico-3.17.0.tar.gz

Download URL mujodico-3.17.0.tar.gz
Size 6.8 MB
Tags Source
SHA-256 checksum
How to use checksums
2e298283cdde921a1b07d041b61073fc27d46df5741a5f9c3495b4dd3c0411c7
BLAKE2b-256 checksum
How to use checksums
e0ef982a67f86684fa5b8229a36ce60ebf015104b149f4f137936ad43e194905
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.13

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

Download URL mujodico-3.17.0-py3-none-any.whl
Size 6.8 MB
Tags Python 3
SHA-256 checksum
How to use checksums
c63f2c29762c5d89be1e91ffd312d46421107be91cd799752b17037045964842
BLAKE2b-256 checksum
How to use checksums
4adb26a522fd38e6204053a0442eb81f71f6221669a8fd8ebfcc1dc4fe8e047b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.13

Security for mujodico 3.17.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