Implementation:Google deepmind Mujoco Engine Derivative
| Knowledge Sources | |
|---|---|
| Domains | Physics Simulation, Analytical Derivatives, Optimal Control |
| Last Updated | 2026-02-15 04:00 GMT |
Overview
Implements analytical derivatives of MuJoCo's smooth dynamics with respect to velocity, including derivatives of the recursive Newton-Euler algorithm, passive forces, actuator forces, and fluid drag.
Description
This module computes analytical (closed-form) derivatives of the smooth dynamics equations. It provides derivatives of spatial algebra operations (cross products, motion/force transforms), the recursive Newton-Euler algorithm with respect to velocity (mjd_rne_vel, mjd_rne_vel_dense), center-of-mass velocity derivatives (mjd_comVel_vel), quaternion integration derivatives (mjd_quatIntegrate), quaternion subtraction derivatives (mjd_subQuat), passive force derivatives including fluid dynamics models (mjd_passive_vel, mjd_ellipsoidFluid, mjd_inertiaBoxFluid), actuator velocity derivatives (mjd_actuator_vel), and flex interpolation derivatives (mjd_flexInterp_mulKD, mjd_flexInterp_addH). The top-level mjd_smooth_vel assembles the full velocity derivative of smooth dynamics.
Usage
Called during derivative computation to analytically compute the Jacobian of the forward dynamics with respect to generalized velocities. Used by optimal control, system identification, and model-based reinforcement learning algorithms that require efficient gradient computation.
Code Reference
Source Location
- Repository: Google_deepmind_Mujoco
- File: src/engine/engine_derivative.c
- Lines: 1-1812
Key Functions
// Quaternion derivatives
void mjd_subQuat(const mjtNum qa[4], const mjtNum qb[4], mjtNum Da[9], mjtNum Db[9]);
void mjd_quatIntegrate(const mjtNum vel[3], mjtNum scale, mjtNum Dvel[9], mjtNum Dscale[3]);
// Velocity derivatives of smooth dynamics (dense and sparse)
void mjd_smooth_vel(const mjModel* m, mjData* d, int flg_bias);
// Recursive Newton-Euler velocity derivatives
void mjd_rne_vel_dense(const mjModel* m, mjData* d);
// Passive force velocity derivatives
void mjd_passive_vel(const mjModel* m, mjData* d);
// Fluid dynamics derivatives
void mjd_ellipsoidFluid(const mjModel* m, mjData* d, int bodyid);
void mjd_inertiaBoxFluid(const mjModel* m, mjData* d, int i);
// Actuator velocity derivatives
void mjd_actuator_vel(const mjModel* m, mjData* d);
// Flex interpolation derivatives
void mjd_flexInterp_mulKD(const mjModel* m, mjData* d, mjtNum* res,
const mjtNum* vec, mjtNum h);
void mjd_flexInterp_addH(const mjModel* m, mjData* d, mjtNum* H,
const int* dof_indices, int ndof, mjtNum h);
Import
#include "engine/engine_derivative.h"
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| m | const mjModel* | Yes | Physics model with body/joint/actuator definitions |
| d | mjData* | Yes | Simulation state with computed kinematics and velocities |
| flg_bias | int | Varies | Flag to include bias force derivatives in smooth_vel |
Outputs
| Name | Type | Description |
|---|---|---|
| d->qDeriv | mjtNum* | Derivative of smooth dynamics w.r.t. generalized velocity (sparse) |
| Da, Db | mjtNum* | Quaternion derivative matrices (3x3) |
| Dvel, Dscale | mjtNum* | Quaternion integration derivative outputs |