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 Dm control MJCF Observable

From Leeroopedia
Knowledge Sources
Domains Composer, Observables, MJCF
Last Updated 2026-02-15 04:00 GMT

Overview

The mjcf observable module defines observables that reference MJCF elements directly rather than by string name, enabling type-safe observation definitions that survive model composition and namespace changes.

Description

MJCFFeature takes an mjcf.Element (or iterable of elements) and a kind string (such as 'qpos', 'xpos'), using physics.bind() to access the corresponding attribute at runtime. It supports indexing via __getitem__ to slice specific components from the bound attribute. The _callable method returns a closure that, when called, reads the current value from the physics simulation.

MJCFCamera takes a <camera> MJCF element and renders images with configurable height, width, depth, segmentation, scene options, and render flag overrides. It provides a BoundedArray spec via the array_spec property with appropriate bounds and shapes for RGB (uint8, 3-channel), depth (float32, 1-channel), or segmentation (int32, 2-channel) modes. The _callable method returns a function that calls physics.render() with the configured parameters.

Both classes extend base.Observable and accept standard observable parameters including update_interval, buffer_size, delay, aggregator, and corruptor for integration with the Composer observation buffering system.

Usage

Use MJCFFeature to define observables for any physics quantity associated with MJCF elements (joint positions, body positions, sensor values). Use MJCFCamera to define pixel-based observables from cameras in the scene. These are the preferred observable types in Composer as they remain valid through model attachment and namespace prefixing.

Code Reference

Source Location

Signature

class MJCFFeature(base.Observable):
    def __init__(self, kind, mjcf_element, update_interval=1,
                 buffer_size=None, delay=None,
                 aggregator=None, corruptor=None, index=None):
    def _callable(self, physics):
    def __getitem__(self, key):

class MJCFCamera(base.Observable):
    def __init__(self, mjcf_element, height=240, width=320,
                 update_interval=1, buffer_size=None, delay=None,
                 aggregator=None, corruptor=None, depth=False,
                 segmentation=False, scene_option=None,
                 render_flag_overrides=None):
    @property
    def height(self):
    @property
    def width(self):
    @property
    def depth(self):
    @property
    def segmentation(self):
    @property
    def scene_option(self):
    @property
    def render_flag_overrides(self):
    @property
    def array_spec(self):
    def _callable(self, physics):

Import

from dm_control.composer.observation.observable.mjcf import MJCFFeature
from dm_control.composer.observation.observable.mjcf import MJCFCamera

I/O Contract

Inputs (MJCFFeature)

Name Type Required Description
kind str Yes Name of a bound mjcf.Physics attribute (e.g., 'qpos', 'xpos', 'sensordata')
mjcf_element mjcf.Element or iterable Yes The MJCF element(s) to observe
update_interval int No Simulation steps between updates (default: 1)
buffer_size int No Maximum buffer size (default: DEFAULT_BUFFER_SIZE)
delay int No Additional simulation step delay (default: DEFAULT_DELAY)
aggregator str or callable No Reduction operation over the buffer dimension
corruptor callable No Function to corrupt/noise the observation
index index No Index to apply to the attribute array

Inputs (MJCFCamera)

Name Type Required Description
mjcf_element mjcf.Element Yes A <camera> MJCF element
height int No Rendered image height in pixels (default: 240)
width int No Rendered image width in pixels (default: 320)
depth bool No Render a depth image instead of RGB (default: False)
segmentation bool No Render a segmentation mask (default: False)
scene_option MjvOption No Custom visualization options
render_flag_overrides dict No Rendering flag overrides

Outputs

Name Type Description
MJCFFeature observation numpy.ndarray The physics attribute values for the bound element(s)
MJCFCamera observation numpy.ndarray Rendered pixel array of shape (height, width, channels)
MJCFCamera.array_spec specs.BoundedArray Specification with shape, dtype, and bounds for the camera output

Usage Examples

from dm_control.composer.observation.observable.mjcf import MJCFFeature, MJCFCamera

# Observe joint positions for a set of MJCF joint elements
joint_obs = MJCFFeature('qpos', entity.mjcf_model.find_all('joint'))

# Observe only the first 3 components of a body's position
body_pos = MJCFFeature('xpos', entity.root_body)[0:3]

# Create a camera observable with depth rendering
camera_element = entity.mjcf_model.find('camera', 'front_camera')
camera_obs = MJCFCamera(
    mjcf_element=camera_element,
    height=480,
    width=640,
    depth=True,
)

# Create a segmentation camera
seg_camera = MJCFCamera(
    mjcf_element=camera_element,
    height=240,
    width=320,
    segmentation=True,
)

Related Pages

Page Connections

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