MCPcopy Create free account
hub / github.com/google-deepmind/dm_control / commit_defaults

Function commit_defaults

dm_control/mjcf/traversal_utils.py:54–81  ·  view source on GitHub ↗

Commits default values into attributes of the specified element. Args: element: A PyMJCF element. attributes: (optional) A list of strings specifying the attributes to be copied from defaults, or `None` if all attributes should be copied.

(element, attributes=None)

Source from the content-addressed store, hash-verified

52
53
54def commit_defaults(element, attributes=None):
55 """Commits default values into attributes of the specified element.
56
57 Args:
58 element: A PyMJCF element.
59 attributes: (optional) A list of strings specifying the attributes to be
60 copied from defaults, or `None` if all attributes should be copied.
61 """
62 dclass = element.dclass
63 parent = element.parent
64 while dclass is None and parent != element.root:
65 dclass = getattr(parent, 'childclass', None)
66 parent = parent.parent
67 if dclass is None:
68 dclass = element.root.default
69
70 while dclass != element.root:
71 if element.tag in _ACTUATOR_TAGS:
72 tags = _ACTUATOR_TAGS
73 else:
74 tags = (element.tag,)
75 for tag in tags:
76 default_element = getattr(dclass, tag)
77 for name, value in default_element.get_attributes().items():
78 if attributes is None or name in attributes:
79 if hasattr(element, name) and getattr(element, name) is None:
80 setattr(element, name, value)
81 dclass = dclass.parent

Callers

nothing calls this directly

Calls 2

itemsMethod · 0.80
get_attributesMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…