Principle:Google deepmind Dm control MJCF Element Query
| Metadata | |
|---|---|
| Knowledge Sources | dm_control |
| Domains | Physics Simulation, Robotics, Model Introspection |
| Last Updated | 2026-02-15 00:00 GMT |
Overview
Searching for and modifying elements within a hierarchical model tree by namespace and identifier enables non-local inspection and mutation of complex simulation models.
Description
Once an MJCF model has been constructed (whether from scratch or by parsing and attaching multiple sub-models), it is often necessary to locate specific elements deep within the tree and read or change their attributes. MJCF Element Query and Modification addresses this need with two complementary search operations and a uniform attribute mutation interface.
Searching by identifier: The find(namespace, identifier) method locates a single element within the subtree rooted at the calling element. The namespace parameter specifies the kind of element (e.g., 'body', 'joint', 'geom', 'actuator', 'site'). The identifier is the element's name. If the identifier contains / separators, the search automatically crosses into attached model scopes, following the hierarchical prefix chain. This makes it possible to locate elements in deeply nested attached models using their fully qualified name.
Searching by type: The find_all(namespace, ...) method returns a list of all elements of a given type within the subtree. Optional flags control whether only immediate children are returned and whether elements belonging to attached models are included.
Modification: Once an element has been located, its attributes can be read and written using standard Python attribute access. Deletion of attributes is also supported via the del statement. Every mutation triggers a name scope revision increment, ensuring that cached identifiers and references stay consistent.
The combination of search and mutation enables powerful model post-processing workflows: adjusting physical parameters based on experimental data, swapping materials, enabling or disabling sensors, and reconfiguring actuator gains -- all without needing to know the exact position of the target element in the tree.
Usage
Element query and modification is used in a wide variety of scenarios:
- Locating a specific joint by name to change its range or damping.
- Finding all geoms of a particular body to change their visual appearance.
- Iterating over all actuators to uniformly scale their gains.
- Accessing elements in attached models by their scoped identifiers.
- Removing elements from the tree to simplify a model for faster simulation.
Theoretical Basis
FUNCTION find(element, namespace, identifier):
IF '/' IN identifier:
scope_name = identifier.split('/')[0]
child_model = element.namescope.get('attached_model', scope_name)
RETURN find(child_model, namespace, identifier after first '/')
ELSE:
result = element.namescope.get(namespace, identifier)
IF result is a descendant of element:
RETURN result
ELSE:
RETURN None
FUNCTION find_all(element, namespace, immediate_only, exclude_attached):
results = []
children = element.own_children IF exclude_attached
ELSE element.all_children
FOR child IN children:
IF child.namespace == namespace:
results.append(child)
IF NOT immediate_only:
results.extend(find_all(child, namespace, ...))
RETURN results
The find operation has O(1) lookup time per scope level because identifiers are stored in dictionaries indexed by namespace. The find_all operation performs a full depth-first traversal, which is O(n) in the number of elements.