Index
runtime
¶
ActuatorControl
¶
Bases: Load
Drives an actuator's control input each timestep, writing into mjData.ctrl. Use control_func for an arbitrary control law, or the constant factory for a simple, runtime-mutable set point.
name
instance-attribute
¶
name: str
Unique label used for telemetry column naming and duplicate-registration warnings.
active
class-attribute
instance-attribute
¶
active: bool = True
When False the load is suppressed.
actuator
instance-attribute
¶
actuator: SerializeAsAny[ActuatorBase]
The MJCF actuator this load drives.
control_func
class-attribute
instance-attribute
¶
Callable (user_data, state) -> control value written into mjData.ctrl for this actuator.
user_data
class-attribute
instance-attribute
¶
user_data: SerializeAsAny[UserData] | None = None
Optional strongly-typed payload accessible inside control_func. Passed through unchanged each timestep.
get_visuals
¶
get_visuals(state: MjState) -> list[ArrowConfig]
resolve_ids
¶
apply_load
¶
Evaluates control_func and writes the result into mjData.ctrl[self._aid].
Source code in src/mujoco_mojo/runtime/load.py
| Python | |
|---|---|
request
¶
request(
signal_manager: SignalManager | None = None,
metadata: dict[str, dict[str, Any]] | None = None,
) -> None
Registers the applied control value for logging under Loads/<name>:ctrl.
ctrl's units depend on the driven actuator's transmission and gear/dyntype (the same ambiguity as ActuatorBase.request()'s ctrl channel), so no built-in metadata default is applied. Supply metadata={"ctrl": {...}} yourself if you know it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
signal_manager
|
SignalManager
|
Manager to register the sampler with. If omitted, the |
None
|
metadata
|
dict[str, dict[str, Any]] | None
|
Metadata for the |
None
|
Source code in src/mujoco_mojo/runtime/load.py
constant
classmethod
¶
Drives the actuator with a fixed set point.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Load name used for telemetry column labeling. |
required |
actuator
|
ActuatorBase
|
The MJCF actuator to drive. |
required |
value
|
float | NamedValue[float]
|
Control value written to |
required |
Source code in src/mujoco_mojo/runtime/load.py
BodyReactionForce
¶
Bases: SiteLoad
Load that also applies an equal and opposite reaction to a second body. If xtion_body is None, only the action site receives the force.
name
instance-attribute
¶
name: str
Unique label used for telemetry column naming and duplicate-registration warnings.
active
class-attribute
instance-attribute
¶
active: bool = True
When False the load is suppressed.
action_site
instance-attribute
¶
Site where the force is applied. Its parent body receives the generalized force.
rel_to_site
class-attribute
instance-attribute
¶
Coordinate frame for force/torque components returned by calculate(). When None, components are in the world frame.
user_data
class-attribute
instance-attribute
¶
user_data: SerializeAsAny[UserData] | None = None
Optional strongly-typed payload accessible inside calculate(). Passed through unchanged each timestep.
force_length_scale
class-attribute
instance-attribute
¶
force_length_scale: float | None = None
Length multiplier for this load's force arrow(s), on top of MuJoCo's native scaling. None falls back to VisualizationSettings.force_length_scale.
force_width_scale
class-attribute
instance-attribute
¶
force_width_scale: float | None = None
Width multiplier for this load's force arrow(s), on top of MuJoCo's native scaling. None falls back to VisualizationSettings.force_width_scale.
torque_length_scale
class-attribute
instance-attribute
¶
torque_length_scale: float | None = None
Length multiplier for this load's torque arrow, on top of MuJoCo's native scaling. None falls back to VisualizationSettings.torque_length_scale.
torque_width_scale
class-attribute
instance-attribute
¶
torque_width_scale: float | None = None
Width multiplier for this load's torque arrow, on top of MuJoCo's native scaling. None falls back to VisualizationSettings.torque_width_scale.
xtion_body
class-attribute
instance-attribute
¶
Body that receives the reaction force. When None, no reaction is applied and the force acts on the world.
get_visuals
¶
get_visuals(state: MjState) -> list[ArrowConfig]
Returns a list of arrow configurations for the renderer.
Source code in src/mujoco_mojo/runtime/load.py
calculate
abstractmethod
¶
Calculate the force for the timestep.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
MjState
|
The paired MuJoCo model and data instance. |
required |
Returns:
| Type | Description |
|---|---|
tuple[ndarray, ndarray]
|
tuple[np.ndarray, np.ndarray]: The force and toque vector output. |
Source code in src/mujoco_mojo/runtime/load.py
| Python | |
|---|---|
request
¶
request(
signal_manager: SignalManager | None = None,
channels: list[Literal["force", "torque"]]
| dict[
Literal["force", "torque"], dict[str, Any] | None
] = ["force", "torque"],
)
Registers specific channels for logging.
| Channel | Description | Type |
|---|---|---|
force |
applied force in the world frame | xyzm |
torque |
applied torque in the world frame | xyzm |
Each channel is posted under subgroups=(load_name, channel).
- An
xyzmis a cartesian vector, posted as 4 values (x,y,z, and its magnitudem).
Each signal is tagged with built-in dimension metadata for its channel (force as force, torque as torque).
If signal_manager is omitted, the SignalManager of the active RuntimeManager with block is used. If that RuntimeManager has no SignalManager configured, this is a no-op.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
signal_manager
|
SignalManager | None
|
The signal manager to register the sampler with. |
None
|
channels
|
list[Literal['force', 'torque']] | dict[Literal['force', 'torque'], dict[str, Any] | None]
|
The load data channels to log. Pass a list to select channels, or a dict mapping channel name to metadata overrides (or |
['force', 'torque']
|
Source code in src/mujoco_mojo/runtime/load.py
GeneralLoad
¶
Bases: VectorForce, VectorTorque
Full 6-DOF force and torque with independent callables for each component. Combines VectorForce and VectorTorque into a single load.
name
instance-attribute
¶
name: str
Unique label used for telemetry column naming and duplicate-registration warnings.
active
class-attribute
instance-attribute
¶
active: bool = True
When False the load is suppressed.
action_site
instance-attribute
¶
Site where the force is applied. Its parent body receives the generalized force.
rel_to_site
class-attribute
instance-attribute
¶
Coordinate frame for force/torque components returned by calculate(). When None, components are in the world frame.
user_data
class-attribute
instance-attribute
¶
user_data: SerializeAsAny[UserData] | None = None
Optional strongly-typed payload accessible inside calculate(). Passed through unchanged each timestep.
force_length_scale
class-attribute
instance-attribute
¶
force_length_scale: float | None = None
Length multiplier for this load's force arrow(s), on top of MuJoCo's native scaling. None falls back to VisualizationSettings.force_length_scale.
force_width_scale
class-attribute
instance-attribute
¶
force_width_scale: float | None = None
Width multiplier for this load's force arrow(s), on top of MuJoCo's native scaling. None falls back to VisualizationSettings.force_width_scale.
torque_length_scale
class-attribute
instance-attribute
¶
torque_length_scale: float | None = None
Length multiplier for this load's torque arrow, on top of MuJoCo's native scaling. None falls back to VisualizationSettings.torque_length_scale.
torque_width_scale
class-attribute
instance-attribute
¶
torque_width_scale: float | None = None
Width multiplier for this load's torque arrow, on top of MuJoCo's native scaling. None falls back to VisualizationSettings.torque_width_scale.
xtion_body
class-attribute
instance-attribute
¶
Body that receives the reaction force. When None, no reaction is applied and the force acts on the world.
tx
class-attribute
instance-attribute
¶
Callable (user_data, state) -> X-axis torque component.
ty
class-attribute
instance-attribute
¶
Callable (user_data, state) -> Y-axis torque component.
tz
class-attribute
instance-attribute
¶
Callable (user_data, state) -> Z-axis torque component.
fx
class-attribute
instance-attribute
¶
Callable (user_data, state) -> X-axis force component (N).
fy
class-attribute
instance-attribute
¶
Callable (user_data, state) -> Y-axis force component (N).
fz
class-attribute
instance-attribute
¶
Callable (user_data, state) -> Z-axis force component (N).
get_visuals
¶
get_visuals(state: MjState) -> list[ArrowConfig]
Returns a list of arrow configurations for the renderer.
Source code in src/mujoco_mojo/runtime/load.py
request
¶
request(
signal_manager: SignalManager | None = None,
channels: list[Literal["force", "torque"]]
| dict[
Literal["force", "torque"], dict[str, Any] | None
] = ["force", "torque"],
)
Registers specific channels for logging.
| Channel | Description | Type |
|---|---|---|
force |
applied force in the world frame | xyzm |
torque |
applied torque in the world frame | xyzm |
Each channel is posted under subgroups=(load_name, channel).
- An
xyzmis a cartesian vector, posted as 4 values (x,y,z, and its magnitudem).
Each signal is tagged with built-in dimension metadata for its channel (force as force, torque as torque).
If signal_manager is omitted, the SignalManager of the active RuntimeManager with block is used. If that RuntimeManager has no SignalManager configured, this is a no-op.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
signal_manager
|
SignalManager | None
|
The signal manager to register the sampler with. |
None
|
channels
|
list[Literal['force', 'torque']] | dict[Literal['force', 'torque'], dict[str, Any] | None]
|
The load data channels to log. Pass a list to select channels, or a dict mapping channel name to metadata overrides (or |
['force', 'torque']
|
Source code in src/mujoco_mojo/runtime/load.py
JointFriction
¶
Bases: JointLoad
Joint friction with a pluggable formulation; use the class-method factories to construct.
Works for hinge, slide, and ball joints. The friction_func receives the full generalized velocity vector for the joint's DOFs and returns a generalized force vector of the same length. All built-in formulations use the velocity magnitude as the scalar speed and apply the resulting force magnitude along -vel/|vel|, so they generalize naturally to multi-DOF joints. Use a NamedValue inside the closure to make parameters mutable at runtime.
name
instance-attribute
¶
name: str
Unique label used for telemetry column naming and duplicate-registration warnings.
active
class-attribute
instance-attribute
¶
active: bool = True
When False the load is suppressed.
friction_func
instance-attribute
¶
(vel, state) -> friction force/torque vector in generalized coordinates. Constructed by the named class-method factories.
resolve_ids
¶
Caches the joint ID, DOF address, and DOF count from the compiled MuJoCo model.
Source code in src/mujoco_mojo/runtime/load.py
get_visuals
¶
get_visuals(state: MjState) -> list[ArrowConfig]
apply_load
¶
Evaluates friction_func at the current joint velocity vector and accumulates the result into qfrc_applied.
Source code in src/mujoco_mojo/runtime/load.py
request
¶
request(
signal_manager: SignalManager | None = None,
metadata: dict[str, dict[str, Any]] | None = None,
) -> None
Registers specific channels for logging.
| Channel | Description | Type |
|---|---|---|
friction |
applied friction force/torque in the world frame | xyzm |
Each channel is posted under subgroups=(load_name, channel).
- An
xyzmis a cartesian vector, posted as 4 values (x,y,z, and its magnitudem).
friction is tagged with built-in dimension metadata resolved from the joint's type (force for slide, torque for hinge/ball).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
signal_manager
|
SignalManager
|
Manager to register the sampler with. If omitted, the |
None
|
metadata
|
dict[str, dict[str, Any]] | None
|
Metadata overriding or extending the built-in default for the |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If the joint has no name. |
Source code in src/mujoco_mojo/runtime/load.py
coulomb_simple
classmethod
¶
Constant-magnitude Coulomb (dry) friction opposing motion. Zero force at standstill. Good for brake pads, dry contacts, and cable friction.
"Simple" because the magnitude is a fixed number you choose, not derived from any actual load on the joint. See karnopp for friction that responds to the joint's real bearing/pin reaction load.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Load name used for telemetry column labeling. |
required |
joint
|
Joint
|
The MJCF joint to act on (slide, hinge, or ball). |
required |
magnitude
|
float | NamedValue[float]
|
Friction force or torque magnitude. Accepts |
required |
Source code in src/mujoco_mojo/runtime/load.py
viscous_simple
classmethod
¶
Velocity-proportional viscous damping. Force is continuous through zero with no discontinuity at standstill. Good for grease-lubricated joints and fluid drag.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Load name used for telemetry column labeling. |
required |
joint
|
Joint
|
The MJCF joint to act on (slide, hinge, or ball). |
required |
damping
|
float | NamedValue[float]
|
Damping coefficient (force per velocity, or torque per angular velocity). Accepts |
required |
Source code in src/mujoco_mojo/runtime/load.py
coulomb_viscous_simple
classmethod
¶
coulomb_viscous_simple(
name: str,
joint: Joint,
coulomb: float | NamedValue[float],
viscous: float | NamedValue[float],
) -> Self
Coulomb and viscous friction combined, both at fixed magnitudes you choose. Constant sliding friction plus a velocity-proportional drag term.
"Simple" because neither term is derived from any actual load on the joint. See karnopp for friction that responds to the joint's real bearing/pin reaction load.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Load name used for telemetry column labeling. |
required |
joint
|
Joint
|
The MJCF joint to act on (slide, hinge, or ball). |
required |
coulomb
|
float | NamedValue[float]
|
Coulomb friction force or torque magnitude. Accepts |
required |
viscous
|
float | NamedValue[float]
|
Viscous damping coefficient (force per velocity, or torque per angular velocity). Accepts |
required |
Source code in src/mujoco_mojo/runtime/load.py
stribeck_simple
classmethod
¶
stribeck_simple(
name: str,
joint: Joint,
coulomb: float | NamedValue[float],
static: float | NamedValue[float],
stribeck_velocity: float | NamedValue[float],
viscous: float | NamedValue[float] = 0.0,
) -> Self
Full Stribeck friction model, at fixed magnitudes you choose. Friction peaks at standstill, drops to the kinetic level as motion begins, then rises with speed. Best for brake and clutch models where stick-slip matters.
F = -(coulomb + (static - coulomb) * exp(-|v| / stribeck_velocity) + viscous * |v|) * v / |v|
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Load name used for telemetry column labeling. |
required |
joint
|
Joint
|
The MJCF joint to act on (slide, hinge, or ball). |
required |
coulomb
|
float | NamedValue[float]
|
Kinetic friction force or torque magnitude. Accepts |
required |
static
|
float | NamedValue[float]
|
Peak static friction force or torque at zero velocity. Must be >= |
required |
stribeck_velocity
|
float | NamedValue[float]
|
Characteristic velocity at which friction transitions from static to kinetic. Smaller values give a sharper transition. Accepts |
required |
viscous
|
float | NamedValue[float]
|
Velocity-proportional damping (force per velocity, or torque per angular velocity). Defaults to 0. Accepts |
0.0
|
Source code in src/mujoco_mojo/runtime/load.py
karnopp
classmethod
¶
karnopp(
name: str,
joint: Joint,
mu_kinetic: float | NamedValue[float],
mu_static: float | NamedValue[float],
velocity_threshold: float | NamedValue[float],
viscous: float | NamedValue[float] = 0.0,
) -> Self
Karnopp friction whose normal force is the joint's actual bearing/pin reaction load (Joint.rt_bearing_load), not a fixed magnitude. Responds to ordinary side loads (e.g. a body's weight pressing on a hinge pin, or a side load on a slider) not just a number you pick. Properly distinguishes "stuck" from "sliding" instead of picking a coefficient based on speed alone:
- Sliding (
|v| >= velocity_threshold): ordinary kinetic Coulomb friction,F = -mu_kinetic * bearing_load * v/|v|, plus an optionalviscousterm. - Stuck (
|v| < velocity_threshold): rather than picking a direction from a near-zero (and possibly noisy) velocity, friction is set to exactly cancel whatever other smooth force is currently acting on the joint (qfrc_smooth: passive + actuator + applied + bias), clamped to the static limitmu_static * bearing_load. If the driving force exceeds that limit the joint breaks away and friction saturates at the limit, opposing the driving force.
This avoids the chattering a pure velocity-direction switch can produce right at standstill, since the held force no longer depends on the sign of a near-zero, noisy velocity.
The bearing load comes from Joint.rt_cfrc_int, which refreshes itself on demand via state.ensure_rne_post_constraint(), so no extra wiring is needed regardless of how the simulation is driven. Note that qfrc_smooth reflects the previous step's solve, since this step's values are not yet known when loads are applied; this mirrors the existing one-step lag already inherent in using vel to set this step's force.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Load name used for telemetry column labeling. |
required |
joint
|
Joint
|
The MJCF joint to act on (slide, hinge, or ball). |
required |
mu_kinetic
|
float | NamedValue[float]
|
Friction coefficient applied to the bearing load while sliding. Accepts |
required |
mu_static
|
float | NamedValue[float]
|
Friction coefficient applied to the bearing load that the joint can hold against before breaking away. Accepts |
required |
velocity_threshold
|
float | NamedValue[float]
|
Speed below which the joint is considered stuck rather than sliding. Accepts |
required |
viscous
|
float | NamedValue[float]
|
Velocity-proportional damping added on top of the kinetic term while sliding. Defaults to 0. Accepts |
0.0
|
Source code in src/mujoco_mojo/runtime/load.py
JointLoad
¶
Bases: Load
Abstract base for loads applied directly in generalized-coordinate (joint) space via qfrc_applied. Subclass and implement apply_load().
name
instance-attribute
¶
name: str
Unique label used for telemetry column naming and duplicate-registration warnings.
active
class-attribute
instance-attribute
¶
active: bool = True
When False the load is suppressed.
get_visuals
¶
get_visuals(state: MjState) -> list[ArrowConfig]
resolve_ids
¶
Caches the joint ID, DOF address, and DOF count from the compiled MuJoCo model.
Source code in src/mujoco_mojo/runtime/load.py
apply_load
abstractmethod
¶
Load
¶
Bases: MojoBaseModel, ABC
Abstract base for all load types. Subclass and implement resolve_ids and apply_load.
name
instance-attribute
¶
name: str
Unique label used for telemetry column naming and duplicate-registration warnings.
active
class-attribute
instance-attribute
¶
active: bool = True
When False the load is suppressed.
resolve_ids
abstractmethod
¶
apply_load
abstractmethod
¶
get_visuals
¶
get_visuals(state: MjState) -> list[ArrowConfig]
PointToPointForce
¶
Bases: SiteLoad
Scalar force along the line-of-sight between two sites, with an equal and opposite reaction on xtion_site. Use the class-method factories for standard spring formulations, or supply a custom magnitude_func.
name
instance-attribute
¶
name: str
Unique label used for telemetry column naming and duplicate-registration warnings.
active
class-attribute
instance-attribute
¶
active: bool = True
When False the load is suppressed.
action_site
instance-attribute
¶
Site where the force is applied. Its parent body receives the generalized force.
rel_to_site
class-attribute
instance-attribute
¶
Coordinate frame for force/torque components returned by calculate(). When None, components are in the world frame.
user_data
class-attribute
instance-attribute
¶
user_data: SerializeAsAny[UserData] | None = None
Optional strongly-typed payload accessible inside calculate(). Passed through unchanged each timestep.
force_length_scale
class-attribute
instance-attribute
¶
force_length_scale: float | None = None
Length multiplier for this load's force arrow(s), on top of MuJoCo's native scaling. None falls back to VisualizationSettings.force_length_scale.
force_width_scale
class-attribute
instance-attribute
¶
force_width_scale: float | None = None
Width multiplier for this load's force arrow(s), on top of MuJoCo's native scaling. None falls back to VisualizationSettings.force_width_scale.
torque_length_scale
class-attribute
instance-attribute
¶
torque_length_scale: float | None = None
Length multiplier for this load's torque arrow, on top of MuJoCo's native scaling. None falls back to VisualizationSettings.torque_length_scale.
torque_width_scale
class-attribute
instance-attribute
¶
torque_width_scale: float | None = None
Width multiplier for this load's torque arrow, on top of MuJoCo's native scaling. None falls back to VisualizationSettings.torque_width_scale.
xtion_site
instance-attribute
¶
Site that receives the equal-and-opposite reaction force. Named xtion to avoid ambiguity with rel_to_site.
magnitude_func
instance-attribute
¶
Callable (user_data, state) -> signed force magnitude (N). Positive pushes sites apart.
request
¶
request(
signal_manager: SignalManager | None = None,
channels: list[Literal["force", "torque"]]
| dict[
Literal["force", "torque"], dict[str, Any] | None
] = ["force", "torque"],
)
Registers specific channels for logging.
| Channel | Description | Type |
|---|---|---|
force |
applied force in the world frame | xyzm |
torque |
applied torque in the world frame | xyzm |
Each channel is posted under subgroups=(load_name, channel).
- An
xyzmis a cartesian vector, posted as 4 values (x,y,z, and its magnitudem).
Each signal is tagged with built-in dimension metadata for its channel (force as force, torque as torque).
If signal_manager is omitted, the SignalManager of the active RuntimeManager with block is used. If that RuntimeManager has no SignalManager configured, this is a no-op.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
signal_manager
|
SignalManager | None
|
The signal manager to register the sampler with. |
None
|
channels
|
list[Literal['force', 'torque']] | dict[Literal['force', 'torque'], dict[str, Any] | None]
|
The load data channels to log. Pass a list to select channels, or a dict mapping channel name to metadata overrides (or |
['force', 'torque']
|
Source code in src/mujoco_mojo/runtime/load.py
resolve_ids
¶
Caches the integer IDs from the compiled MuJoCo model.
Source code in src/mujoco_mojo/runtime/load.py
get_visuals
¶
get_visuals(state: MjState) -> list[ArrowConfig]
Returns a list of arrow configurations for the renderer.
Source code in src/mujoco_mojo/runtime/load.py
ideal_spring
classmethod
¶
ideal_spring(
name: str,
action_site: AnySite,
xtion_site: AnySite,
stiffness: float | NamedValue[float] = 0.0,
damping: float | NamedValue[float] = 0.0,
rest_length: float = 0.0,
) -> Self
Bidirectional spring-damper active in both tension and compression. F = -k*(d - d0) - c*v.
Source code in src/mujoco_mojo/runtime/load.py
stroke_compression_spring
classmethod
¶
stroke_compression_spring(
name: str,
action_site: AnySite,
xtion_site: AnySite,
stiffness: float | NamedValue[float] = 0.0,
damping: float | NamedValue[float] = 0.0,
preload: float | NamedValue[float] = 0.0,
max_stroke: float | NamedValue[float] = 0.1,
) -> Self
Compression spring with a finite stroke; only active while the sites are compressed between rest and (rest + max_stroke). Useful for preloaded gas springs and mechanical end-stops.
Source code in src/mujoco_mojo/runtime/load.py
compression_spring
classmethod
¶
compression_spring(
name: str,
action_site: AnySite,
xtion_site: AnySite,
stiffness: float | NamedValue[float] = 0.0,
damping: float | NamedValue[float] = 0.0,
rest_length: float = 0.0,
) -> Self
Creates a spring-damper that only acts when compressed (dist < rest_length). Useful for bumpers, feet, push-off springs, or end-stops.
Source code in src/mujoco_mojo/runtime/load.py
tension_spring
classmethod
¶
tension_spring(
name: str,
action_site: AnySite,
xtion_site: AnySite,
stiffness: float | NamedValue[float] = 0.0,
damping: float | NamedValue[float] = 0.0,
rest_length: float = 0.0,
) -> Self
Creates a spring-damper that only acts when extended (dist > rest_length). Useful for cables, bungees, or tendons.
Source code in src/mujoco_mojo/runtime/load.py
ScalarForce
¶
Bases: BodyReactionForce
Force along the local X-axis of action_site, scaled by scalar_func each timestep.
name
instance-attribute
¶
name: str
Unique label used for telemetry column naming and duplicate-registration warnings.
active
class-attribute
instance-attribute
¶
active: bool = True
When False the load is suppressed.
action_site
instance-attribute
¶
Site where the force is applied. Its parent body receives the generalized force.
rel_to_site
class-attribute
instance-attribute
¶
Coordinate frame for force/torque components returned by calculate(). When None, components are in the world frame.
user_data
class-attribute
instance-attribute
¶
user_data: SerializeAsAny[UserData] | None = None
Optional strongly-typed payload accessible inside calculate(). Passed through unchanged each timestep.
force_length_scale
class-attribute
instance-attribute
¶
force_length_scale: float | None = None
Length multiplier for this load's force arrow(s), on top of MuJoCo's native scaling. None falls back to VisualizationSettings.force_length_scale.
force_width_scale
class-attribute
instance-attribute
¶
force_width_scale: float | None = None
Width multiplier for this load's force arrow(s), on top of MuJoCo's native scaling. None falls back to VisualizationSettings.force_width_scale.
torque_length_scale
class-attribute
instance-attribute
¶
torque_length_scale: float | None = None
Length multiplier for this load's torque arrow, on top of MuJoCo's native scaling. None falls back to VisualizationSettings.torque_length_scale.
torque_width_scale
class-attribute
instance-attribute
¶
torque_width_scale: float | None = None
Width multiplier for this load's torque arrow, on top of MuJoCo's native scaling. None falls back to VisualizationSettings.torque_width_scale.
xtion_body
class-attribute
instance-attribute
¶
Body that receives the reaction force. When None, no reaction is applied and the force acts on the world.
scalar_func
class-attribute
instance-attribute
¶
Callable (user_data, state) -> signed force magnitude (N). Positive is along the site's +X axis.
get_visuals
¶
get_visuals(state: MjState) -> list[ArrowConfig]
Returns a list of arrow configurations for the renderer.
Source code in src/mujoco_mojo/runtime/load.py
request
¶
request(
signal_manager: SignalManager | None = None,
channels: list[Literal["force", "torque"]]
| dict[
Literal["force", "torque"], dict[str, Any] | None
] = ["force", "torque"],
)
Registers specific channels for logging.
| Channel | Description | Type |
|---|---|---|
force |
applied force in the world frame | xyzm |
torque |
applied torque in the world frame | xyzm |
Each channel is posted under subgroups=(load_name, channel).
- An
xyzmis a cartesian vector, posted as 4 values (x,y,z, and its magnitudem).
Each signal is tagged with built-in dimension metadata for its channel (force as force, torque as torque).
If signal_manager is omitted, the SignalManager of the active RuntimeManager with block is used. If that RuntimeManager has no SignalManager configured, this is a no-op.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
signal_manager
|
SignalManager | None
|
The signal manager to register the sampler with. |
None
|
channels
|
list[Literal['force', 'torque']] | dict[Literal['force', 'torque'], dict[str, Any] | None]
|
The load data channels to log. Pass a list to select channels, or a dict mapping channel name to metadata overrides (or |
['force', 'torque']
|
Source code in src/mujoco_mojo/runtime/load.py
ScalarTorque
¶
Bases: BodyReactionForce
Torque about the local X-axis of action_site, scaled by scalar_func each timestep.
name
instance-attribute
¶
name: str
Unique label used for telemetry column naming and duplicate-registration warnings.
active
class-attribute
instance-attribute
¶
active: bool = True
When False the load is suppressed.
action_site
instance-attribute
¶
Site where the force is applied. Its parent body receives the generalized force.
rel_to_site
class-attribute
instance-attribute
¶
Coordinate frame for force/torque components returned by calculate(). When None, components are in the world frame.
user_data
class-attribute
instance-attribute
¶
user_data: SerializeAsAny[UserData] | None = None
Optional strongly-typed payload accessible inside calculate(). Passed through unchanged each timestep.
force_length_scale
class-attribute
instance-attribute
¶
force_length_scale: float | None = None
Length multiplier for this load's force arrow(s), on top of MuJoCo's native scaling. None falls back to VisualizationSettings.force_length_scale.
force_width_scale
class-attribute
instance-attribute
¶
force_width_scale: float | None = None
Width multiplier for this load's force arrow(s), on top of MuJoCo's native scaling. None falls back to VisualizationSettings.force_width_scale.
torque_length_scale
class-attribute
instance-attribute
¶
torque_length_scale: float | None = None
Length multiplier for this load's torque arrow, on top of MuJoCo's native scaling. None falls back to VisualizationSettings.torque_length_scale.
torque_width_scale
class-attribute
instance-attribute
¶
torque_width_scale: float | None = None
Width multiplier for this load's torque arrow, on top of MuJoCo's native scaling. None falls back to VisualizationSettings.torque_width_scale.
xtion_body
class-attribute
instance-attribute
¶
Body that receives the reaction force. When None, no reaction is applied and the force acts on the world.
scalar_func
class-attribute
instance-attribute
¶
Callable (user_data, state) -> signed torque magnitude. Positive follows the right-hand rule about the site's +X axis.
get_visuals
¶
get_visuals(state: MjState) -> list[ArrowConfig]
Returns a list of arrow configurations for the renderer.
Source code in src/mujoco_mojo/runtime/load.py
request
¶
request(
signal_manager: SignalManager | None = None,
channels: list[Literal["force", "torque"]]
| dict[
Literal["force", "torque"], dict[str, Any] | None
] = ["force", "torque"],
)
Registers specific channels for logging.
| Channel | Description | Type |
|---|---|---|
force |
applied force in the world frame | xyzm |
torque |
applied torque in the world frame | xyzm |
Each channel is posted under subgroups=(load_name, channel).
- An
xyzmis a cartesian vector, posted as 4 values (x,y,z, and its magnitudem).
Each signal is tagged with built-in dimension metadata for its channel (force as force, torque as torque).
If signal_manager is omitted, the SignalManager of the active RuntimeManager with block is used. If that RuntimeManager has no SignalManager configured, this is a no-op.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
signal_manager
|
SignalManager | None
|
The signal manager to register the sampler with. |
None
|
channels
|
list[Literal['force', 'torque']] | dict[Literal['force', 'torque'], dict[str, Any] | None]
|
The load data channels to log. Pass a list to select channels, or a dict mapping channel name to metadata overrides (or |
['force', 'torque']
|
Source code in src/mujoco_mojo/runtime/load.py
SiteLoad
¶
Bases: Load
Abstract base for Cartesian-space forcing functions applied at a named site. Subclass and implement calculate() to return (force_world, torque_world); the base class handles mj_applyFT, telemetry, and visualization.
name
instance-attribute
¶
name: str
Unique label used for telemetry column naming and duplicate-registration warnings.
active
class-attribute
instance-attribute
¶
active: bool = True
When False the load is suppressed.
action_site
instance-attribute
¶
Site where the force is applied. Its parent body receives the generalized force.
rel_to_site
class-attribute
instance-attribute
¶
Coordinate frame for force/torque components returned by calculate(). When None, components are in the world frame.
user_data
class-attribute
instance-attribute
¶
user_data: SerializeAsAny[UserData] | None = None
Optional strongly-typed payload accessible inside calculate(). Passed through unchanged each timestep.
force_length_scale
class-attribute
instance-attribute
¶
force_length_scale: float | None = None
Length multiplier for this load's force arrow(s), on top of MuJoCo's native scaling. None falls back to VisualizationSettings.force_length_scale.
force_width_scale
class-attribute
instance-attribute
¶
force_width_scale: float | None = None
Width multiplier for this load's force arrow(s), on top of MuJoCo's native scaling. None falls back to VisualizationSettings.force_width_scale.
torque_length_scale
class-attribute
instance-attribute
¶
torque_length_scale: float | None = None
Length multiplier for this load's torque arrow, on top of MuJoCo's native scaling. None falls back to VisualizationSettings.torque_length_scale.
torque_width_scale
class-attribute
instance-attribute
¶
torque_width_scale: float | None = None
Width multiplier for this load's torque arrow, on top of MuJoCo's native scaling. None falls back to VisualizationSettings.torque_width_scale.
resolve_ids
¶
Caches the integer IDs from the compiled MuJoCo model.
Source code in src/mujoco_mojo/runtime/load.py
calculate
abstractmethod
¶
Calculate the force for the timestep.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
MjState
|
The paired MuJoCo model and data instance. |
required |
Returns:
| Type | Description |
|---|---|
tuple[ndarray, ndarray]
|
tuple[np.ndarray, np.ndarray]: The force and toque vector output. |
Source code in src/mujoco_mojo/runtime/load.py
| Python | |
|---|---|
request
¶
request(
signal_manager: SignalManager | None = None,
channels: list[Literal["force", "torque"]]
| dict[
Literal["force", "torque"], dict[str, Any] | None
] = ["force", "torque"],
)
Registers specific channels for logging.
| Channel | Description | Type |
|---|---|---|
force |
applied force in the world frame | xyzm |
torque |
applied torque in the world frame | xyzm |
Each channel is posted under subgroups=(load_name, channel).
- An
xyzmis a cartesian vector, posted as 4 values (x,y,z, and its magnitudem).
Each signal is tagged with built-in dimension metadata for its channel (force as force, torque as torque).
If signal_manager is omitted, the SignalManager of the active RuntimeManager with block is used. If that RuntimeManager has no SignalManager configured, this is a no-op.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
signal_manager
|
SignalManager | None
|
The signal manager to register the sampler with. |
None
|
channels
|
list[Literal['force', 'torque']] | dict[Literal['force', 'torque'], dict[str, Any] | None]
|
The load data channels to log. Pass a list to select channels, or a dict mapping channel name to metadata overrides (or |
['force', 'torque']
|
Source code in src/mujoco_mojo/runtime/load.py
get_visuals
¶
get_visuals(state: MjState) -> list[ArrowConfig]
Returns a list of arrow configurations for the renderer.
Source code in src/mujoco_mojo/runtime/load.py
VectorForce
¶
Bases: BodyReactionForce
3-axis force with independent per-axis callables. Components are expressed in rel_to_site frame, or world frame if None.
name
instance-attribute
¶
name: str
Unique label used for telemetry column naming and duplicate-registration warnings.
active
class-attribute
instance-attribute
¶
active: bool = True
When False the load is suppressed.
action_site
instance-attribute
¶
Site where the force is applied. Its parent body receives the generalized force.
rel_to_site
class-attribute
instance-attribute
¶
Coordinate frame for force/torque components returned by calculate(). When None, components are in the world frame.
user_data
class-attribute
instance-attribute
¶
user_data: SerializeAsAny[UserData] | None = None
Optional strongly-typed payload accessible inside calculate(). Passed through unchanged each timestep.
force_length_scale
class-attribute
instance-attribute
¶
force_length_scale: float | None = None
Length multiplier for this load's force arrow(s), on top of MuJoCo's native scaling. None falls back to VisualizationSettings.force_length_scale.
force_width_scale
class-attribute
instance-attribute
¶
force_width_scale: float | None = None
Width multiplier for this load's force arrow(s), on top of MuJoCo's native scaling. None falls back to VisualizationSettings.force_width_scale.
torque_length_scale
class-attribute
instance-attribute
¶
torque_length_scale: float | None = None
Length multiplier for this load's torque arrow, on top of MuJoCo's native scaling. None falls back to VisualizationSettings.torque_length_scale.
torque_width_scale
class-attribute
instance-attribute
¶
torque_width_scale: float | None = None
Width multiplier for this load's torque arrow, on top of MuJoCo's native scaling. None falls back to VisualizationSettings.torque_width_scale.
xtion_body
class-attribute
instance-attribute
¶
Body that receives the reaction force. When None, no reaction is applied and the force acts on the world.
fx
class-attribute
instance-attribute
¶
Callable (user_data, state) -> X-axis force component (N).
fy
class-attribute
instance-attribute
¶
Callable (user_data, state) -> Y-axis force component (N).
fz
class-attribute
instance-attribute
¶
Callable (user_data, state) -> Z-axis force component (N).
get_visuals
¶
get_visuals(state: MjState) -> list[ArrowConfig]
Returns a list of arrow configurations for the renderer.
Source code in src/mujoco_mojo/runtime/load.py
request
¶
request(
signal_manager: SignalManager | None = None,
channels: list[Literal["force", "torque"]]
| dict[
Literal["force", "torque"], dict[str, Any] | None
] = ["force", "torque"],
)
Registers specific channels for logging.
| Channel | Description | Type |
|---|---|---|
force |
applied force in the world frame | xyzm |
torque |
applied torque in the world frame | xyzm |
Each channel is posted under subgroups=(load_name, channel).
- An
xyzmis a cartesian vector, posted as 4 values (x,y,z, and its magnitudem).
Each signal is tagged with built-in dimension metadata for its channel (force as force, torque as torque).
If signal_manager is omitted, the SignalManager of the active RuntimeManager with block is used. If that RuntimeManager has no SignalManager configured, this is a no-op.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
signal_manager
|
SignalManager | None
|
The signal manager to register the sampler with. |
None
|
channels
|
list[Literal['force', 'torque']] | dict[Literal['force', 'torque'], dict[str, Any] | None]
|
The load data channels to log. Pass a list to select channels, or a dict mapping channel name to metadata overrides (or |
['force', 'torque']
|
Source code in src/mujoco_mojo/runtime/load.py
VectorTorque
¶
Bases: BodyReactionForce
3-axis torque with independent per-axis callables. Components are expressed in rel_to_site frame, or world frame if None.
name
instance-attribute
¶
name: str
Unique label used for telemetry column naming and duplicate-registration warnings.
active
class-attribute
instance-attribute
¶
active: bool = True
When False the load is suppressed.
action_site
instance-attribute
¶
Site where the force is applied. Its parent body receives the generalized force.
rel_to_site
class-attribute
instance-attribute
¶
Coordinate frame for force/torque components returned by calculate(). When None, components are in the world frame.
user_data
class-attribute
instance-attribute
¶
user_data: SerializeAsAny[UserData] | None = None
Optional strongly-typed payload accessible inside calculate(). Passed through unchanged each timestep.
force_length_scale
class-attribute
instance-attribute
¶
force_length_scale: float | None = None
Length multiplier for this load's force arrow(s), on top of MuJoCo's native scaling. None falls back to VisualizationSettings.force_length_scale.
force_width_scale
class-attribute
instance-attribute
¶
force_width_scale: float | None = None
Width multiplier for this load's force arrow(s), on top of MuJoCo's native scaling. None falls back to VisualizationSettings.force_width_scale.
torque_length_scale
class-attribute
instance-attribute
¶
torque_length_scale: float | None = None
Length multiplier for this load's torque arrow, on top of MuJoCo's native scaling. None falls back to VisualizationSettings.torque_length_scale.
torque_width_scale
class-attribute
instance-attribute
¶
torque_width_scale: float | None = None
Width multiplier for this load's torque arrow, on top of MuJoCo's native scaling. None falls back to VisualizationSettings.torque_width_scale.
xtion_body
class-attribute
instance-attribute
¶
Body that receives the reaction force. When None, no reaction is applied and the force acts on the world.
tx
class-attribute
instance-attribute
¶
Callable (user_data, state) -> X-axis torque component.
ty
class-attribute
instance-attribute
¶
Callable (user_data, state) -> Y-axis torque component.
tz
class-attribute
instance-attribute
¶
Callable (user_data, state) -> Z-axis torque component.
get_visuals
¶
get_visuals(state: MjState) -> list[ArrowConfig]
Returns a list of arrow configurations for the renderer.
Source code in src/mujoco_mojo/runtime/load.py
request
¶
request(
signal_manager: SignalManager | None = None,
channels: list[Literal["force", "torque"]]
| dict[
Literal["force", "torque"], dict[str, Any] | None
] = ["force", "torque"],
)
Registers specific channels for logging.
| Channel | Description | Type |
|---|---|---|
force |
applied force in the world frame | xyzm |
torque |
applied torque in the world frame | xyzm |
Each channel is posted under subgroups=(load_name, channel).
- An
xyzmis a cartesian vector, posted as 4 values (x,y,z, and its magnitudem).
Each signal is tagged with built-in dimension metadata for its channel (force as force, torque as torque).
If signal_manager is omitted, the SignalManager of the active RuntimeManager with block is used. If that RuntimeManager has no SignalManager configured, this is a no-op.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
signal_manager
|
SignalManager | None
|
The signal manager to register the sampler with. |
None
|
channels
|
list[Literal['force', 'torque']] | dict[Literal['force', 'torque'], dict[str, Any] | None]
|
The load data channels to log. Pass a list to select channels, or a dict mapping channel name to metadata overrides (or |
['force', 'torque']
|
Source code in src/mujoco_mojo/runtime/load.py
RequirementSatisfied
¶
Bases: SimulationStopped
Raised when one or more live requirements with terminate_on_pass=True pass, ending the trial early as a normal (successful) completion rather than a failure.
RequirementTerminated
¶
Bases: SimulationStopped
Raised when one or more live requirements with terminate_on_fail=True fail. Subclasses SimulationStopped so existing catch blocks need no changes.
RuntimeManager
dataclass
¶
RuntimeManager(
signal_manager: SignalManager | None = None,
loads: list[Load] = list(),
proximities: list[Proximity] = list(),
tracers: list[Tracer] = list(),
video_recorders: list[VideoRecorder] = list(),
requirements: RequirementsManager = RequirementsManager(),
playback_speed: float = 1.0,
_sync_hook: SyncHook | None = None,
_viewer_lock: Callable[[], AbstractContextManager[Any]]
| None = None,
_skip_recording: bool = False,
_stop_event: Event | None = None,
_resolved: bool = False,
)
__enter__
¶
__enter__() -> Self
Prime the model and prepare results. Also makes this instance available via RuntimeManager.current() for the duration of the with block.
Source code in src/mujoco_mojo/runtime/runtime_manager.py
__exit__
¶
Ensure all telemetry is flushed even if the simulation crashed. Also saves recordings
Source code in src/mujoco_mojo/runtime/runtime_manager.py
current
classmethod
¶
current() -> RuntimeManager
Returns the RuntimeManager of the innermost enclosing with block. Raises if called outside of one.
Source code in src/mujoco_mojo/runtime/runtime_manager.py
resolve
¶
add_requirement
¶
add_requirement(
fn: RequirementFn,
*,
name: str | None = None,
every: int | None = None,
terminate_on_fail: bool = False,
terminate_on_pass: bool = False,
latch_on_fail: bool = True,
latch_on_pass: bool = False,
post_result: bool = True,
) -> None
Register a named pass/fail check evaluated at end of trial and optionally during simulation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fn
|
RequirementFn
|
Callable |
required |
name
|
str | None
|
Label for this check in results and telemetry. Defaults to |
None
|
every
|
int | None
|
If |
None
|
terminate_on_fail
|
bool
|
When |
False
|
terminate_on_pass
|
bool
|
When |
False
|
latch_on_fail
|
bool
|
When |
True
|
latch_on_pass
|
bool
|
When |
False
|
post_result
|
bool
|
Post a telemetry column to the signal manager after evaluating the requirement if True. |
True
|
Source code in src/mujoco_mojo/runtime/runtime_manager.py
requirement
¶
requirement(
name: str | None = None,
*,
every: int | None = None,
terminate_on_fail: bool = False,
terminate_on_pass: bool = False,
latch_on_fail: bool = True,
latch_on_pass: bool = False,
post_result: bool = True,
) -> Callable[[RequirementFn], RequirementFn]
Registers a pass/fail check that runs automatically when the trial ends. Results are collected in requirements.results and written to requirements.json alongside the trial telemetry.
The decorated function must accept (mojo_model: MojoModel, state: MjState, df: MojoDataFrame | None) and return (passed, message) where passed is True, False, or None (undetermined yet; a no-op during live checks, a failure if still undetermined at end of trial). mojo_model provides access to user data and named values. state is the last simulation state. df is the full trial telemetry parquet at end-of-trial, or None during live evaluations (see every).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str | None
|
Label for this check in results and telemetry. Defaults to the function's |
None
|
every
|
int | None
|
When set, the check also runs inside |
None
|
terminate_on_fail
|
bool
|
When |
False
|
terminate_on_pass
|
bool
|
When |
False
|
latch_on_fail
|
bool
|
When |
True
|
latch_on_pass
|
bool
|
When |
False
|
post_result
|
bool
|
Post a telemetry column to the signal manager after evaluating the requirement if True. |
True
|
Example
@rm.requirement(every=100, terminate_on_fail=True)
def upright(mojo_model, state, df): return state.data.qpos[2] > 0.1, "ok"
Source code in src/mujoco_mojo/runtime/runtime_manager.py
last_passed
¶
Returns the cached live-check result for a requirement at the current sim time, or None if there is no verdict yet.
Accepts either the requirement's name or the function itself. The decorator returns the original function unchanged, so the reference from @rm.requirement(...) can be passed directly instead of retyping its name. Passing a function that was never registered raises ValueError.
None covers two cases callers can't tell apart: the check hasn't run at this exact sim time (every > 1 only evaluates on some steps), or it ran and explicitly returned undetermined (None). Either way, treat None as "no verdict yet", not as failure.
Example
Source code in src/mujoco_mojo/runtime/runtime_manager.py
step
¶
step(
state: MjState,
clear_xfrc_applied: bool = True,
clear_qfrc_applied: bool = True,
clear_ctrl: bool = True,
)
Calculates forces, integratess physics, and handles telemetry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
MjState
|
The paired MuJoCo model and data instance. |
required |
clear_xfrc_applied
|
bool
|
If True, zero |
True
|
clear_qfrc_applied
|
bool
|
If True, zero |
True
|
clear_ctrl
|
bool
|
If True, zero |
True
|
Source code in src/mujoco_mojo/runtime/runtime_manager.py
| Python | |
|---|---|
289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 | |
SimulationStopped
¶
Bases: Exception
Raised by RuntimeManager.step to unwind a running simulation when the user requests a stop.
SignalManager
dataclass
¶
SignalManager(
export_path: Path,
target_buffer_bytes: int = 8 * 1024 * 1024,
record_decimation: int = 1,
unit_system: UnitSystem | None = None,
_buffer_row_idx: int = 0,
_step_count: int = -1,
_n_cols: int = 0,
)
target_buffer_bytes
class-attribute
instance-attribute
¶
target_buffer_bytes: int = 8 * 1024 * 1024
Approximate in-memory buffer size, in bytes, before flushing to a part file. The actual row capacity is derived from this and the current column count (see _recompute_capacity), so flush frequency stays roughly memory/file-size bounded as signals are registered, rather than fixed at a row count regardless of width. Defaults to 8 MB.
record_decimation
class-attribute
instance-attribute
¶
record_decimation: int = 1
How many steps between each recording should be performed.
unit_system
class-attribute
instance-attribute
¶
When set, the time column's concrete unit is resolved from unit_system.time (e.g. "second", "millisecond"). Always tagged with dimension="[time]" regardless.
track
¶
track(
getter: Callable[[], float],
category: SignalCategory | str,
subgroups: tuple[str, ...] = (),
*,
attr: str | None = None,
metadata: dict[str, Any] | None = None,
)
Registers getter to be called and posted on every recorded step, under the same category/subgroups/attr namespace as post.
getter is called fresh on every recorded step, so it should look up a value that changes over the course of the simulation (e.g. a variable updated each step, an attribute, or an indexing operation) rather than a constant computed once. If the underlying value never changes after registration, track will simply keep posting that same value every step.
Examples:
| Python Console Session | |
|---|---|
| Python Console Session | |
|---|---|
Source code in src/mujoco_mojo/runtime/signal_manager.py
post
¶
post(
value: float,
category: SignalCategory | str,
subgroups: tuple[str, ...] = (),
*,
attr: str | None = None,
metadata: dict[str, Any] | None = None,
)
Injects a value into the telemetry ledger using a hierarchical namespace.
This method constructs a structured key that the dashboard uses to build a navigable tree view. The naming convention follows a folder-like structure to group related signals (e.g., all axes of a body's position).
Format
Category/Subgroup:Attribute (e.g., "Bodies/Link_1:xpos_x")
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
float
|
The numeric data to record. |
required |
category
|
SignalCategory | str
|
Top level category (e.g., "Bodies") |
required |
subgroups
|
tuple[str, ...]
|
The second-level organizational folders. Defaults to an empty tuple. |
()
|
attr
|
str | None
|
The specific signal or component name (e.g., "qpos" or "x"). Defaults to None. |
None
|
metadata
|
dict[str, Any] | None
|
Arbitrary metadata for this signal, persisted into the telemetry file's footer. Only consulted the first time this signal is registered (ignored on later calls for the same signal). Two keys are validated via Pint if present: |
None
|
Examples:
| Python Console Session | |
|---|---|
| Python Console Session | |
|---|---|
| Python Console Session | |
|---|---|
Source code in src/mujoco_mojo/runtime/signal_manager.py
| Python | |
|---|---|
230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 | |
record
¶
Executes all samplers and advances the buffer index. Flushes if due.
Source code in src/mujoco_mojo/runtime/signal_manager.py
flush
¶
Writes the memory buffer to a new part file; parts are merged into export_path on close().
Source code in src/mujoco_mojo/runtime/signal_manager.py
Tracer
dataclass
¶
Tracer(
target: Traceable,
duration: float = 1.0,
color: Vec4 | None = None,
width: float = 0.005,
fade: bool = True,
record_decimation: int = 1,
)
Draws a fading trail of recent world positions behind a Traceable object (a Body, Site, or Geom).
Typical usage inside a runtime function, within a with runtime_manager as rm: block::
| Text Only | |
|---|---|
1 | |
Sampled once per RuntimeManager.step() and drawn by any VideoRecorder with show_traces=True.
target
instance-attribute
¶
target: Traceable
The object whose world position is followed over time.
duration
class-attribute
instance-attribute
¶
duration: float = 1.0
How many seconds of trailing history to keep.
color
class-attribute
instance-attribute
¶
color: Vec4 | None = None
RGBA color of the trail. Defaults to the user's visualization.trace_line setting.
fade
class-attribute
instance-attribute
¶
fade: bool = True
If True, older segments are drawn more transparent than newer ones.
record_decimation
class-attribute
instance-attribute
¶
record_decimation: int = 1
How many steps between each recorded point. Increase for long, fine-timestep simulations to reduce the number of trail segments.
update
¶
Records the target's current position, then drops points older than duration. Call once per step.
Source code in src/mujoco_mojo/runtime/tracer.py
get_visuals
¶
get_visuals(state: MjState) -> list[LineConfig]
Returns one LineConfig per consecutive pair of recorded positions.
Source code in src/mujoco_mojo/runtime/tracer.py
LabelConfig
¶
Bases: TypedDict
Describes one frame label, returned fresh per-frame by VideoRecorder.frame_label.
position
instance-attribute
¶
position: NotRequired[tuple[int, int]]
Top-left pixel coordinate to draw at. Defaults to (10, 10).
color
instance-attribute
¶
color: NotRequired[Vec3 | Vec4]
Text color, normalized [0, 1] RGB(A) (e.g. Color.WHITE.rgba). Defaults to opaque white.
background_color
instance-attribute
¶
background_color: NotRequired[Vec3 | Vec4 | None]
Optional fill behind the text, normalized [0, 1] RGB(A). An RGBA alpha < 1 is true-blended with the frame beneath it. Defaults to no background.
border_color
instance-attribute
¶
border_color: NotRequired[Vec3 | Vec4 | None]
Optional 1px outline around the padded label box, normalized [0, 1] RGB(A). Defaults to no border.
font_size
instance-attribute
¶
font_size: NotRequired[int]
Font size in pixels. Defaults to 14.
font_path
instance-attribute
¶
font_path: NotRequired[str | Path | None]
Path to a TrueType/OpenType font file, for custom styles/weights. Defaults to PIL's built-in font.
padding
instance-attribute
¶
padding: NotRequired[int]
Padding in pixels around the text when drawing background_color. Defaults to 4.
VideoRecorder
dataclass
¶
VideoRecorder(
path: Path,
camera_name: CameraName,
show_loads: bool = False,
show_net_force: bool = False,
show_contacts: bool = False,
show_proximities: bool = False,
show_traces: bool = False,
fps: float = 30,
playback_speed: float = 1.0,
width: int = 640,
height: int = 480,
recording_trigger: Callable[
[MjState], bool
] = lambda state: True,
frame_label: Callable[[MjState], LabelConfig]
| None = None,
max_frames: int | None = None,
quality: int | None = None,
encode_speed: int | None = None,
_frames: list = list(),
)
Records a MuJoCo simulation to a video file.
Frames are captured at a fixed rate (fps) relative to simulation time, not wall-clock time, so the output plays back at the exact rate specified regardless of how fast the simulation runs. The recorder skips capture_frame calls that fall between the interval boundaries, which prevents duplicate frames when the physics step is finer than 1/fps.
Typical usage inside a runtime function, within a with runtime_manager as rm: block::
| Text Only | |
|---|---|
1 2 3 4 5 6 7 | |
register_to_rm wires the recorder into the RuntimeManager so that capture_frame is called automatically on every physics step and save is called when the simulation finishes. If no runtime_manager is passed, it registers to the RuntimeManager of the active with block.
Supported output formats (determined by the path extension):
.mp4: H.264 via ffmpeg; widest browser and player compatibility..webm: VP9 via ffmpeg; smaller files, fully seekable in the Dojo viewer. Requires ffmpeg with libvpx-vp9 support..gif: via PIL; no audio, loops automatically; large file size, not seekable.
.mp4 and .webm frames are piped to ffmpeg as they're captured rather than buffered in memory, so recording length isn't limited by available RAM. .gif (and any other extension, which falls back to mediapy) still buffers every frame until save is called. quality and encode_speed tune the ffmpeg encoder for .mp4/.webm; both have no effect on .gif.
Visual overlays (contact forces, net forces, custom arrows/lines) are controlled by the show_* flags and the show_loads flag passed to capture_frame.
playback_speed scales the frame rate of the saved video relative to fps: 0.5 plays back in slow motion, 1 is real time, and 2 plays back at double speed. It does not change how many frames are captured per second of simulation time, only how quickly they are played back.
recording_trigger is a function of the current MjState that gates whether a due frame is actually captured, e.g. lambda state: 5.0 <= state.data.time <= 10.0 to only record a window of the simulation.
frame_label, if set, is called with the current MjState and the returned LabelConfig is burned into the frame - text, position, color, an optional (alpha-blended) background, and font are all configurable per-frame.
max_frames caps the number of frames held in memory; once reached, further capture_frame calls are silently ignored (with a one-time warning).
Call close once save has finished to release the renderer's GL context.
path
instance-attribute
¶
path: Path
Output file path. The extension determines the container and codec.
camera_name
instance-attribute
¶
camera_name: CameraName
Name of the MuJoCo camera to render from (must exist in the model).
show_loads
class-attribute
instance-attribute
¶
show_loads: bool = False
Whether to render custom arrow overlays (passed via custom_arrows in capture_frame).
show_net_force
class-attribute
instance-attribute
¶
show_net_force: bool = False
Whether to render net force visualizations (mjVIS_PERTFORCE).
show_contacts
class-attribute
instance-attribute
¶
show_contacts: bool = False
Whether to render contact force visualizations (mjVIS_CONTACTFORCE).
show_proximities
class-attribute
instance-attribute
¶
show_proximities: bool = False
Whether to render custom line overlays (passed via custom_lines in capture_frame).
show_traces
class-attribute
instance-attribute
¶
show_traces: bool = False
Whether to render Tracer trails (passed via custom_traces in capture_frame).
fps
class-attribute
instance-attribute
¶
fps: float = 30
Target frame rate of the output video. Frames are sampled every 1/fps seconds of simulation time.
playback_speed
class-attribute
instance-attribute
¶
playback_speed: float = 1.0
Target for playback speed. If using 0.5 the video will record in "slow motion", 2 will record as occurring twice as fast.
recording_trigger
class-attribute
instance-attribute
¶
Function evaluated against the current MjState on every step. Frames are only captured while it returns True.
frame_label
class-attribute
instance-attribute
¶
frame_label: Callable[[MjState], LabelConfig] | None = None
Optional function returning a LabelConfig to burn into each captured frame, e.g. lambda state: {"text": f"t={state.data.time:.2f}s"}.
max_frames
class-attribute
instance-attribute
¶
max_frames: int | None = None
Optional cap on the number of frames captured. Once reached, further capture_frame calls are ignored. For .gif and other buffered formats this also bounds memory use; .mp4/.webm are streamed to disk as they're captured, so it only bounds recording length for those.
quality
class-attribute
instance-attribute
¶
quality: int | None = None
Override for ffmpeg's -crf (constant rate factor) on .mp4/.webm: lower means higher quality and a larger file. Defaults to a codec-specific value (23 for .mp4/libx264, 33 for .webm/libvpx-vp9) when unset. Useful range is roughly 18-32; has no effect on .gif.
encode_speed
class-attribute
instance-attribute
¶
encode_speed: int | None = None
Override for the .mp4/.webm encoder's speed-vs-compression trade-off, on a 0-8 scale where 0 is slowest/best compression and 8 is fastest/worst (passed straight through as -cpu-used for .webm; mapped to an x264 -preset name for .mp4). Defaults to a codec-specific value (4 for .mp4, 2 for .webm) when unset. Has no effect on .gif.
setup
¶
setup(state: MjState) -> Self
Initializes the MuJoCo renderer for this model. Must be called before the simulation loop.
Source code in src/mujoco_mojo/runtime/video_recorder.py
is_due
¶
is_due(state: MjState) -> bool
Returns whether capture_frame would actually capture a frame for state right now, without any side effects. Lets callers skip expensive work (e.g. building custom_traces) that would otherwise go unused on the steps between frames.
Source code in src/mujoco_mojo/runtime/video_recorder.py
capture_frame
¶
capture_frame(
state: MjState,
custom_arrows: list[ArrowConfig],
custom_lines: list[LineConfig],
custom_traces: list[LineConfig],
)
Captures the current state as a video frame.
Source code in src/mujoco_mojo/runtime/video_recorder.py
snapshot
¶
snapshot(
state: MjState,
path: Path,
custom_arrows: list[ArrowConfig] | None = None,
custom_lines: list[LineConfig] | None = None,
custom_traces: list[LineConfig] | None = None,
)
Renders the current state and saves it as a single image to path, regardless of recording_trigger or fps timing.
Source code in src/mujoco_mojo/runtime/video_recorder.py
save
¶
Finishes writing the video file.
Supported formats:
- .mp4: H.264 via ffmpeg; universally compatible.
- .webm: VP9 via ffmpeg; smaller files and fully seekable.
- .gif: via PIL; no audio, loops automatically, large file size, not seekable.
.mp4 and .webm are encoded incrementally: each frame is piped to ffmpeg as it's captured, so save only needs to close that pipe and wait for ffmpeg to finish. .gif (and any other format) buffers every frame in memory and is only encoded here.
The output format is determined by the extension of path.
Source code in src/mujoco_mojo/runtime/video_recorder.py
close
¶
Releases the GL context held by the underlying MuJoCo renderer, and kills the ffmpeg encoder if save was never called. Call once recording is finished and save has been called.