rofunc.utils.robolab.formatter.mjcf_parser.element#

Classes to represent MJCF elements in the object model.

1.  Module Contents#

1.1.  Classes#

RootElement

The root <mujoco> element of an MJCF model.

1.2.  Functions#

property

Modifies @property to keep track of any AttributeError raised.

1.3.  API#

rofunc.utils.robolab.formatter.mjcf_parser.element.property(method)#

Modifies @property to keep track of any AttributeError raised.

Our Element implementations overrides the __getattr__ method. This does not interact well with @property: if a property’s code is buggy so as to raise an AttributeError, then Python would silently discard it and redirect to our __getattr__ instead, leading to an uninformative stack trace. This makes it very difficult to debug issues that involve properties.

To remedy this, we modify @property within this module to store any AttributeError raised within the respective Element object. Then, in our __getattr__ logic, we could re-raise it to preserve the original stack trace.

The reason that this is not implemented as a different decorator is that we could accidentally use @property on a new method. This would work fine until someone triggers a subtle bug. This is when a proper trace would be most useful, but we would still end up with a strange undebuggable stack trace anyway.

Note that at the end of this module, we have a del property to prevent this override from being broadcasted externally.

Args:

method: The method that is being decorated.

Returns:

A property corresponding to the decorated method.

class rofunc.utils.robolab.formatter.mjcf_parser.element.RootElement(model=None, model_dir='', assets=None)[source]#

Bases: rofunc.utils.robolab.formatter.mjcf_parser.element._ElementImpl

The root <mujoco> element of an MJCF model.

Initialization

property namescope#
property root#
property model#
attach(other)[source]#
detach()[source]#
include_copy(other, override_attributes=False)[source]#
property parent_model#

The RootElement of the MJCF model to which this one is attached.

property root_model#
get_assets()[source]#

Returns a dict containing the binary assets referenced in this model.

This will contain {vfs_filename: contents} pairs. vfs_filename will be the name of the asset in MuJoCo’s Virtual File System, which corresponds to the filename given in the XML returned by to_xml_string(). contents is a bytestring.

This dict can be used together with the result of to_xml_string() to construct a mujoco.Physics instance:

```python physics = mujoco.Physics.from_xml_string(

xml_string=mjcf_model.to_xml_string(), assets=mjcf_model.get_assets())

```

get_assets_map()[source]#
property full_identifier#
is_same_as(other)[source]#