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, kelvin-voigt, hunt-crossley, and linear-elastic (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

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.

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.1

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

Built distribution (wheel)

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

Total release size: 13.8 MB

Release files / mujodico-4.0.1.tar.gz

Download URL mujodico-4.0.1.tar.gz
Size 6.8 MB
Tags Source
SHA-256 checksum
How to use checksums
66879a699fc28af6fe9827ff3cf2b3f11e1c0a86e88c77fb43401778629778d6
BLAKE2b-256 checksum
How to use checksums
6f8623a51bcffce8a92ec1ae2a624a09459c8eb2b4ef77082655e786349819dd
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.1-py3-none-any.whl

Download URL mujodico-4.0.1-py3-none-any.whl
Size 6.9 MB
Tags Python 3
SHA-256 checksum
How to use checksums
1fae26c8e0cf87db8db62298092f15b54ad1d3c5161f6936ff6294e88e9ba0e4
BLAKE2b-256 checksum
How to use checksums
9ba20e862e83995b2af4a72041729eba9d2602e7cf22427f5120f421c843b1f3
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.1

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