Replace the Polak-Ribière-Plus (PRP+) conjugate direction update with the Hager-Zhang formula in `mj_solPrimal`.
While this change has negligible effect under float64, it leads to a significant 17.5% throughput speedup over PRP+ under float32 (measured via `engine_cg_convergence_test`). This performance gain is driven by:
* A 9.4% reduction in CG iterations per step.
* A 12.1% reduction in line search evaluations per step.
The full output of the comparison is
```
================================================================
1/4: HZ + float64
================================================================
CG Convergence: 2humanoid100.xml
1000 Newton steps, 100 evaluation points
nv = 654, nq = 756
metric: ||qacc_cg - qacc_newton|| / ||qacc_newton||
Warmstart (tolerance = 0):
Iters | Mean Err | Max Err | Mean Iters | LS evals
-------+-------------+-------------+------------+---------
5 | 3.8532e-01 | 1.4285e+00 | 5.00 | 22368
10 | 2.0809e-01 | 9.9315e-01 | 10.00 | 44591
20 | 6.4977e-02 | 2.3410e-01 | 20.00 | 89417
40 | 5.2839e-03 | 2.1916e-02 | 40.00 | 180984
80 | 3.9709e-05 | 3.0010e-04 | 80.00 | 364241
160 | 3.2498e-09 | 3.5480e-08 | 160.00 | 730131
-------+-------------+-------------+------------+---------
No warmstart (tolerance = 0):
Iters | Mean Err | Max Err | Mean Iters | LS evals
-------+-------------+-------------+------------+---------
5 | 9.0740e-01 | 5.0045e+00 | 5.00 | 22123
10 | 3.9506e-01 | 2.1927e+00 | 10.00 | 44879
20 | 1.2496e-01 | 6.8911e-01 | 20.00 | 90341
40 | 1.2846e-02 | 6.9533e-02 | 40.00 | 182869
80 | 1.0288e-04 | 8.6457e-04 | 80.00 | 368312
160 | 5.9820e-09 | 5.0903e-08 | 160.00 | 738479
-------+-------------+-------------+------------+---------
Tolerance sweep (iterations = 100, warmstart):
Tol | Mean Err | Max Err | Mean Iters | Max Iters | Solver us | LS evals
-----------+-------------+-------------+------------+------------+-------------+---------
1e-04 | 1.1297e-02 | 8.9331e-02 | 34.88 | 51 | 131002.94 | 12052
1e-06 | 1.0907e-03 | 7.7468e-03 | 50.87 | 72 | 184172.44 | 16700
1e-08 | 1.1485e-04 | 1.0085e-03 | 66.82 | 91 | 232189.34 | 20194
1e-10 | 1.1357e-05 | 8.1547e-05 | 81.97 | 100 | 276114.42 | 23264
1e-12 | 3.7695e-06 | 2.8592e-05 | 90.47 | 100 | 299526.58 | 24964
0 | 3.5019e-06 | 2.8592e-05 | 100.00 | 100 | 2062208.36 | 456276
-----------+-------------+-------------+------------+------------+-------------+---------
Total solver time: 3185214.08 us, avg time per iter: 74.9445 us
Pipeline mode (consecutive mj_step, tolerance = 1e-8):
1000 steps, nv = 654
Steps/s : 380
us/step (total) : 2630.0
us/step (constr) : 2103.7 (80.0%)
CG iters/step : 63.28
LS evals/step : 190.75
us/iter : 33.24
================================================================
2/4: PRP+ + float64
================================================================
CG Convergence: 2humanoid100.xml
1000 Newton steps, 100 evaluation points
nv = 654, nq = 756
metric: ||qacc_cg - qacc_newton|| / ||qacc_newton||
Warmstart (tolerance = 0):
Iters | Mean Err | Max Err | Mean Iters | LS evals
-------+-------------+-------------+------------+---------
5 | 3.8533e-01 | 1.4285e+00 | 5.00 | 22228
10 | 2.0808e-01 | 9.9315e-01 | 10.00 | 44873
20 | 6.4978e-02 | 2.3410e-01 | 20.00 | 89349
40 | 5.2895e-03 | 2.1916e-02 | 40.00 | 179827
80 | 4.0188e-05 | 3.0010e-04 | 80.00 | 363740
160 | 3.2891e-09 | 3.5480e-08 | 160.00 | 733905
-------+-------------+-------------+------------+---------
No warmstart (tolerance = 0):
Iters | Mean Err | Max Err | Mean Iters | LS evals
-------+-------------+-------------+------------+---------
5 | 9.0740e-01 | 5.0045e+00 | 5.00 | 22590
10 | 3.9506e-01 | 2.1927e+00 | 10.00 | 45093
20 | 1.2496e-01 | 6.8911e-01 | 20.00 | 90393
40 | 1.2846e-02 | 6.9533e-02 | 40.00 | 182422
80 | 1.0288e-04 | 8.6457e-04 | 80.00 | 367264
160 | 5.9811e-09 | 5.0903e-08 | 160.00 | 739556
-------+-------------+-------------+------------+---------
Tolerance sweep (iterations = 100, warmstart):
Tol | Mean Err | Max Err | Mean Iters | Max Iters | Solver us | LS evals
-----------+-------------+-------------+------------+------------+-------------+---------
1e-04 | 1.1325e-02 | 8.9941e-02 | 34.95 | 52 | 129456.81 | 12060
1e-06 | 1.0910e-03 | 7.7469e-03 | 50.85 | 72 | 181004.51 | 16687
1e-08 | 1.1488e-04 | 1.0085e-03 | 66.83 | 91 | 228183.13 | 20189
1e-10 | 1.1401e-05 | 8.1547e-05 | 81.98 | 100 | 269635.40 | 23259
1e-12 | 3.8040e-06 | 2.8592e-05 | 90.52 | 100 | 293811.25 | 24967
0 | 3.5543e-06 | 2.8592e-05 | 100.00 | 100 | 2051927.47 | 456000
-----------+-------------+-------------+------------+------------+-------------+---------
Total solver time: 3154018.57 us, avg time per iter: 74.1895 us
Pipeline mode (consecutive mj_step, tolerance = 1e-8):
1000 steps, nv = 654
Steps/s : 382
us/step (total) : 2616.6
us/step (constr) : 2091.8 (79.9%)
CG iters/step : 63.57
LS evals/step : 193.35
us/iter : 32.91
================================================================
3/4: HZ + float32
================================================================
CG Convergence: 2humanoid100.xml
1000 Newton steps, 100 evaluation points
nv = 654, nq = 756
metric: ||qacc_cg - qacc_newton|| / ||qacc_newton||
Warmstart (tolerance = 0):
Iters | Mean Err | Max Err | Mean Iters | LS evals
-------+-------------+-------------+------------+---------
5 | 3.6748e-01 | 1.2281e+00 | 5.00 | 19239
10 | 2.0034e-01 | 6.8689e-01 | 10.00 | 39001
20 | 6.1972e-02 | 1.9859e-01 | 20.00 | 80112
40 | 4.0704e-03 | 1.5797e-02 | 40.00 | 168211
80 | 2.4380e-05 | 1.5803e-04 | 79.45 | 347735
160 | 7.7413e-07 | 4.4732e-06 | 157.27 | 704210
-------+-------------+-------------+------------+---------
No warmstart (tolerance = 0):
Iters | Mean Err | Max Err | Mean Iters | LS evals
-------+-------------+-------------+------------+---------
5 | 9.3385e-01 | 4.9648e+00 | 5.00 | 19272
10 | 3.6117e-01 | 1.9618e+00 | 10.00 | 37982
20 | 9.7490e-02 | 5.1451e-01 | 20.00 | 76502
40 | 9.5924e-03 | 5.5088e-02 | 40.00 | 162782
80 | 6.7689e-05 | 5.1113e-04 | 79.91 | 344281
160 | 1.5541e-06 | 7.6955e-06 | 157.30 | 697076
-------+-------------+-------------+------------+---------
Tolerance sweep (iterations = 100, warmstart):
Tol | Mean Err | Max Err | Mean Iters | Max Iters | Solver us | LS evals
-----------+-------------+-------------+------------+------------+-------------+---------
1e-04 | 1.5891e-02 | 1.2929e-01 | 32.56 | 50 | 136254.00 | 10980
1e-06 | 1.5719e-03 | 1.0990e-02 | 47.42 | 68 | 193566.00 | 15418
1e-08 | 1.6260e-04 | 1.0680e-03 | 62.70 | 86 | 252661.00 | 20162
1e-10 | 1.5664e-05 | 1.0999e-04 | 78.10 | 100 | 311535.00 | 24509
1e-12 | 2.8152e-06 | 1.5236e-05 | 90.39 | 100 | 356814.00 | 27902
0 | 2.4989e-06 | 1.5025e-05 | 99.05 | 100 | 1980580.00 | 436825
-----------+-------------+-------------+------------+------------+-------------+---------
Total solver time: 3231410.00 us, avg time per iter: 78.7726 us
Pipeline mode (consecutive mj_step, tolerance = 1e-8):
1000 steps, nv = 654
Steps/s : 349
us/step (total) : 2862.7
us/step (constr) : 2379.3 (83.1%)
CG iters/step : 61.97
LS evals/step : 199.01
us/iter : 38.39
================================================================
4/4: PRP+ + float32
================================================================
CG Convergence: 2humanoid100.xml
1000 Newton steps, 100 evaluation points
nv = 654, nq = 756
metric: ||qacc_cg - qacc_newton|| / ||qacc_newton||
Warmstart (tolerance = 0):
Iters | Mean Err | Max Err | Mean Iters | LS evals
-------+-------------+-------------+------------+---------
5 | 3.6753e-01 | 1.2281e+00 | 5.00 | 19052
10 | 2.0028e-01 | 6.8689e-01 | 10.00 | 38761
20 | 6.1737e-02 | 1.9863e-01 | 20.00 | 79937
40 | 4.0915e-03 | 1.5821e-02 | 39.99 | 168159
80 | 2.4360e-05 | 1.5808e-04 | 79.59 | 348385
160 | 7.8367e-07 | 4.1549e-06 | 157.04 | 700760
-------+-------------+-------------+------------+---------
No warmstart (tolerance = 0):
Iters | Mean Err | Max Err | Mean Iters | LS evals
-------+-------------+-------------+------------+---------
5 | 9.3385e-01 | 4.9648e+00 | 5.00 | 19494
10 | 3.6117e-01 | 1.9618e+00 | 10.00 | 38480
20 | 9.7485e-02 | 5.1451e-01 | 20.00 | 77213
40 | 9.5904e-03 | 5.5078e-02 | 40.00 | 162472
80 | 6.7647e-05 | 5.1087e-04 | 79.87 | 342990
160 | 1.4979e-06 | 7.2291e-06 | 157.92 | 699052
-------+-------------+-------------+------------+---------
Tolerance sweep (iterations = 100, warmstart):
Tol | Mean Err | Max Err | Mean Iters | Max Iters | Solver us | LS evals
-----------+-------------+-------------+------------+------------+-------------+---------
1e-04 | 1.5998e-02 | 1.3172e-01 | 32.49 | 50 | 135111.00 | 10953
1e-06 | 1.5878e-03 | 1.1052e-02 | 47.33 | 67 | 190914.00 | 15418
1e-08 | 1.5901e-04 | 1.0680e-03 | 62.65 | 84 | 250609.00 | 20215
1e-10 | 1.5953e-05 | 1.1116e-04 | 78.01 | 100 | 307067.00 | 24562
1e-12 | 2.8520e-06 | 1.5174e-05 | 90.27 | 100 | 353010.00 | 27931
0 | 2.5161e-06 | 1.5129e-05 | 99.39 | 100 | 1999478.00 | 438790
-----------+-------------+-------------+------------+------------+-------------+---------
Total solver time: 3236189.00 us, avg time per iter: 78.9045 us
Pipeline mode (consecutive mj_step, tolerance = 1e-8):
1000 steps, nv = 654
Steps/s : 298
us/step (total) : 3352.8
us/step (constr) : 2832.0 (84.5%)
CG iters/step : 68.43
LS evals/step : 226.33
us/iter : 41.39
```
PiperOrigin-RevId: 928590104
Change-Id: I1a96730f50f444d6141d8978feb3519009daf320
MuJoCo stands for Multi-Joint dynamics with Contact. It is a general purpose physics engine that aims to facilitate research and development in robotics, biomechanics, graphics and animation, machine learning, and other areas which demand fast and accurate simulation of articulated structures interacting with their environment.
This repository is maintained by Google DeepMind.
MuJoCo has a C API and is intended for researchers and developers. The runtime simulation module is tuned to maximize performance and operates on low-level data structures that are preallocated by the built-in XML compiler. The library includes interactive visualization with a native GUI, rendered in OpenGL. MuJoCo further exposes a large number of utility functions for computing physics-related quantities.
We also provide Python bindings and a plug-in for the Unity game engine.
Documentation
MuJoCo's documentation can be found at mujoco.readthedocs.io. Upcoming features due for the next release can be found in the changelog in the "latest" branch.
Getting Started
There are two easy ways to get started with MuJoCo:
-
Run
simulateon your machine. This video shows a screen capture ofsimulate, MuJoCo's native interactive viewer. Follow the steps described in the Getting Started section of the documentation to getsimulaterunning on your machine. -
Explore our online IPython notebooks. If you are a Python user, you might want to start with our tutorial notebooks running on Google Colab:
- The introductory tutorial teaches MuJoCo basics:
- The Model Editing tutorial shows how to create and edit models procedurally:
- The rollout tutorial shows how to use the multithreaded
rolloutmodule: - The LQR tutorial synthesizes a linear-quadratic controller, balancing a
humanoid on one leg:
- The least-squares tutorial explains how to use the Python-based nonlinear
least-squares solver:
- The MJX tutorial provides usage examples of
MuJoCo XLA, a branch of MuJoCo written in JAX:
- The differentiable physics tutorial trains locomotion policies with
analytical gradients automatically derived from MuJoCo's physics step:
Installation
Prebuilt binaries
Versioned releases are available as precompiled binaries from the GitHub releases page, built for Linux (x86-64 and AArch64), Windows (x86-64 only), and macOS (universal). This is the recommended way to use the software.
Building from source
Users who wish to build MuJoCo from source should consult the build from
source section of the documentation. However, note that the commit at
the tip of the main branch may be unstable.
Python (>= 3.10)
The native Python bindings, which come pre-packaged with a copy of MuJoCo, can be installed from PyPI via:
pip install mujoco
Note that Pre-built Linux wheels target manylinux2014, see
here for compatible distributions. For more
information such as building the bindings from source, see the Python bindings
section of the documentation.
Versioning
We aim to release MuJoCo in the first week of each month. Our versioning standards changed to modified Semantic Versioning in 3.5.0, see versioning for details.
Contributing
We welcome community engagement: questions, requests for help, bug reports and feature requests. To read more about bug reports, feature requests and more ambitious contributions, please see our contributors guide and style guide.
Asking Questions
Questions and requests for help are welcome as a GitHub "Asking for Help" Discussion and should focus on a specific problem or question.
Bug reports and feature requests
GitHub Issues are reserved for bug reports, feature requests and other development-related subjects.
Related software
MuJoCo is the backbone for numerous environment packages. Below we list several bindings and converters.
Bindings
These packages give users of various languages access to MuJoCo functionality:
First-party bindings:
- Python bindings
- dm_control, Google DeepMind's related environment stack, includes PyMJCF, a module for procedural manipulation of MuJoCo models.
- JavaScript bindings and WebAssembly support (inspired stillonearth and zalo's community projects; mjswan extends these with real-time policy control, interactive force application, and more).
- C# bindings and Unity plug-in
Third-party bindings:
- MATLAB Simulink: Simulink Blockset for MuJoCo Simulator by Manoj Velmurugan.
- Swift: swift-mujoco
- Java: mujoco-java
- Julia: MuJoCo.jl
- Rust: MuJoCo-rs
Converters
- OpenSim: MyoConverter converts OpenSim models to MJCF.
- SDFormat: gz-mujoco is a two-way SDFormat <-> MJCF conversion tool.
- OBJ: obj2mjcf a script for converting composite OBJ files into a loadable MJCF model.
- onshape: Onshape to Robot Converts onshape CAD assemblies to MJCF.
Citation
If you use MuJoCo for published research, please cite:
@inproceedings{todorov2012mujoco,
title={MuJoCo: A physics engine for model-based control},
author={Todorov, Emanuel and Erez, Tom and Tassa, Yuval},
booktitle={2012 IEEE/RSJ International Conference on Intelligent Robots and Systems},
pages={5026--5033},
year={2012},
organization={IEEE},
doi={10.1109/IROS.2012.6386109}
}
License and Disclaimer
Copyright 2021 DeepMind Technologies Limited.
Box collision code (engine_collision_box.c)
is Copyright 2016 Svetoslav Kolev.
ReStructuredText documents, images, and videos in the doc directory are made
available under the terms of the Creative Commons Attribution 4.0 (CC BY 4.0)
license. You may obtain a copy of the License at
https://creativecommons.org/licenses/by/4.0/legalcode.
Source code 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 is not an officially supported Google product.
