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.0.1.post2 represents the second update to MuJoDiCo for MuJoCo 3.0.1.
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 3.15.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| mujodico-3.15.0.tar.gz | 6.7 MB | Without provenance | Details for mujodico-3.15.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| mujodico-3.15.0-py3-none-any.whl | Python 3 | none | any | Details for mujodico-3.15.0-py3-none-any.whl |
Total release size: 13.6 MB
Release files / mujodico-3.15.0.tar.gz
| Download URL | mujodico-3.15.0.tar.gz |
|---|---|
| Size | 6.7 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8f22f801e27a8c923db26f9fa8b83f554d0a232d3d9dffcf9ffc8c9d0038f335
|
|
BLAKE2b-256 checksum How to use checksums |
a4a07e50166424d11082abe0dd5f0c956e0c268bc1645be71579f49b2b94b354
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.15
|
Release files / mujodico-3.15.0-py3-none-any.whl
| Download URL | mujodico-3.15.0-py3-none-any.whl |
|---|---|
| Size | 6.8 MB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0bce4d575a586b9d3ec4422af9f13daeb7405e2915a361974fcc283381a770db
|
|
BLAKE2b-256 checksum How to use checksums |
8c921e16f9ab863095e6ebfd8c3d9049742e335767af6de4bac9d35aadd55553
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.15
|
Security for mujodico 3.15.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.