Principle:Google deepmind Dm control MJCF Structure Building
| Metadata | |
|---|---|
| Knowledge Sources | dm_control |
| Domains | Physics Simulation, Robotics, Model Authoring |
| Last Updated | 2026-02-15 00:00 GMT |
Overview
Incrementally constructing a hierarchical model tree by adding child elements and setting their attributes enables the programmatic assembly of complex articulated systems.
Description
MJCF Structure Building is the process of populating an MJCF model tree after the root element has been created. An MJCF model is a hierarchical tree of typed elements that mirrors the XML schema used by MuJoCo. The primary structural operation is adding child elements to an existing parent element, and the primary data operation is setting attributes on those elements.
Every MJCF element has a spec that defines which child element types it may contain and which attributes it supports. Children come in two flavours:
- Singleton children (non-repeated) -- elements such as
<compiler>,<option>, or<worldbody>that appear at most once under their parent. These are pre-created when the parent is initialised and are accessed directly as attributes. - Repeated children -- elements such as
<body>,<geom>,<joint>, or<site>that may appear multiple times. These are created on demand via theadd()method.
Attributes are strongly typed. The MJCF library provides dedicated attribute classes for strings, integers, floats, arrays, keywords (enumerations), identifiers, references, and file assets. When a value is assigned, it is validated against the attribute's type and constraints. Array attributes accept Python lists or NumPy arrays and store them as NumPy arrays internally.
The combination of add() for children and attribute assignment for data allows the entire MJCF tree to be built incrementally, one element at a time, with full type checking at every step.
Usage
Structure building is used whenever a model needs to be authored or modified in code:
- Adding bodies, geoms, and joints to define a kinematic chain.
- Setting physical properties such as mass, inertia, friction, and damping.
- Adding actuators that reference joints or tendons.
- Adding sensors, equality constraints, and other MJCF components.
Because attribute assignment is validated immediately, errors (wrong type, invalid keyword, duplicate identifier) are caught at the point of assignment rather than at compilation time.
Theoretical Basis
The structure-building process can be modelled as a sequence of tree mutations:
FUNCTION add_child(parent, tag, attributes):
ASSERT tag IN parent.spec.children
child_spec = parent.spec.children[tag]
ASSERT child_spec.repeated OR child does not yet exist
child = new Element(spec=child_spec, parent=parent)
FOR (name, value) IN attributes:
ASSERT name IN child_spec.attributes
child.set_attribute(name, validate(child_spec.attributes[name], value))
parent.children.append(child)
parent.namescope.increment_revision()
RETURN child
FUNCTION set_attribute(element, name, value):
attr_spec = element.spec.attributes[name]
validated = validate(attr_spec, value)
element.attributes[name] = validated
element.namescope.increment_revision()
The key invariant maintained throughout is that the model tree is always schema-conformant: every element's tag is valid for its position in the tree, every attribute value satisfies its type constraint, and every identifier is unique within its namespace.