Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Google deepmind Mujoco MJX Constraint

From Leeroopedia
Knowledge Sources
Domains Physics_Simulation, JAX, Constraint_Dynamics
Last Updated 2026-02-15 04:00 GMT

Overview

Core non-smooth constraint functions that build the constraint Jacobian, reference accelerations, and impedance parameters for equality, friction, limit, and contact constraints.

Description

This module constructs the full set of constraint rows (efc_J, efc_aref, efc_D, etc.) used by the MJX solver. It handles equality constraints (connect, weld, joint, tendon), joint/tendon friction loss, joint/tendon limits, and contact constraints in frictionless, pyramidal, and elliptic cone modes. The _Efc PyTreeNode dataclass accumulates intermediate Jacobian rows and solver parameters. Stiffness, damping, and impedance are computed via _kbi() following MuJoCo's solver parameter conventions.

Usage

Invoked as part of mjx.step() after collision detection and before the constraint solver. make_constraint() is the main entry point that assembles all constraint matrices and populates Data fields consumed by the solver.

Code Reference

Source Location

Key Functions

class _Efc(PyTreeNode):
    """Support data for creating constraint matrices."""

def _kbi(m: Model, solref: jax.Array, solimp: jax.Array, pos: jax.Array) -> Tuple[jax.Array, jax.Array, jax.Array]
def _efc_equality_connect(m: Model, d: Data) -> Optional[_Efc]
def _efc_equality_weld(m: Model, d: Data) -> Optional[_Efc]
def _efc_equality_joint(m: Model, d: Data) -> Optional[_Efc]
def _efc_equality_tendon(m: Model, d: Data) -> Optional[_Efc]
def _efc_friction(m: Model, d: Data) -> Optional[_Efc]
def _efc_limit_ball(m: Model, d: Data) -> Optional[_Efc]
def _efc_limit_slide_hinge(m: Model, d: Data) -> Optional[_Efc]
def _efc_limit_tendon(m: Model, d: Data) -> Optional[_Efc]
def _efc_contact_frictionless(m: Model, d: Data) -> Optional[_Efc]
def _efc_contact_pyramidal(m: Model, d: Data, condim: int) -> Optional[_Efc]
def _efc_contact_elliptic(m: Model, d: Data, condim: int) -> Optional[_Efc]
def counts(efc_type: np.ndarray) -> Tuple[int, int, int, int]
def make_efc_type(m: Model, ...) -> np.ndarray
def make_efc_address(m: Model, ...) -> np.ndarray
def make_constraint(m: Model, d: Data) -> Data

Import

from mujoco.mjx._src.constraint import make_constraint
from mujoco.mjx._src.constraint import counts

I/O Contract

Inputs

Name Type Required Description
m mjx.Model Yes JAX model with joint, tendon, equality, and contact definitions
d mjx.Data Yes JAX simulation data with current positions, velocities, and contact info

Outputs

Name Type Description
d mjx.Data Updated data with efc_J, efc_D, efc_aref, efc_type, efc_force, and related constraint arrays

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment