Differentiable Simulation of Hard Contacts with Soft Gradients
for Learning and Control
Anselm Paulus*, A. René Geist*, Pierre Schumacher, Vít Musil, Simon Rappenecker, Georg Martius
Anselm Paulus*, A. René Geist*, Pierre Schumacher, Vít Musil, Simon Rappenecker, Georg Martius
ICLR 2026
Top: Gradient-based MPC using CFD
Combining CFD with MJX enables gradient-based MPC of a musculo-skeletal robot using only a single distance between ball and goal as cost.
For hard contact settings or small simulation stepsizes, the gradients provided by MuJoCo XLA are erroneous. These errors stem from discontinuities in the system dynamics introduced by contacts, which affect the accuracy of numerical integration.
DiffMJX integrates Diffrax - an library providing numerical differential equation solvers - atop MuJoCo XLA.
In turn, DiffMJX adds the following functionalities to MuJoCo XLA:
Tradeoff simulation / gradient accuracy for compute time via adaptive stepsize controllers during integration.
Tradeoff GPU memory consumption for compile / compute time by using advanced checkpointing methods.
Switch between different methods for computing adjoints for backpropagation.
In addition, we show how to smoothen collision detection via Softjax.
Left: Real-world cube parameter estimation
Estimation of cube parameters in MuJoCo via DiffMJX from real-world data of a cube being thrown onto a table. After training, the MuJoCo simulation accurately predicts the real-world trajectories. Despite contacts, the parameters are learned via run-of-the-mill gradient descent.
For using robot simulation in an optimization, we would like to have informative gradients. In particular, if two objects are not in contact, then the simulator gradients between the object states are zero. To obtain gradients between Contacts From a Distance (CFD), we extend MuJoCo's contact model to create small contact forces for positive signed-distances. By resorting to straight-through estimation, this softened contact model is only used when computing simulator gradients keeping the forward simulation untouched.
Top: Robot hovers due to applying large artifical contact forces in the simulation.
Left: Illustration of CFD
During backpropagation the gradients of the forward simulation are replaced by the gradients of the soft forward simulation.
Comparisons of sampling-based MPC to gradient-based MPC with CFD
Ball catch
Switch ball positions in-hand
Bionic tennis
Cube reorientation on plane
Cube reorientation in-hand