Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PyMJCF nested include tags relative to base model #418

Open
guyazran opened this issue Aug 5, 2023 · 0 comments
Open

PyMJCF nested include tags relative to base model #418

guyazran opened this issue Aug 5, 2023 · 0 comments

Comments

@guyazran
Copy link

guyazran commented Aug 5, 2023

PyMJCF does not support nested include tags the same way as the MuJoCo compiler. No matter how deep the include tag is, MuJoCo expects all included models and their assets to be given as paths to the corresponding file relative to the input file parent directory. However, the current implementation of PyMJCF checks paths relative to the current file's parent directory, which MuJoCo does not support.

In the attached scenes.zip file are 3 scenes.

  • my_scene1/scene.xml includes a file in an inner directory that includes another file in yet another inner directory. The internal include tag uses a path relative to the top-level model directory (my_scene1/). This is supported by MuJoCo but PyMJCF fails to parse the scene:
>>> mjcf.Physics.from_xml_path('my_scene1/scene.xml')  # parse using mujoco directly
<dm_control.mjcf.physics.Physics object at 0x7fd0d191b0d0>

>>> mjcf.Physics.from_mjcf_model(mjcf.from_path('my_scene1/scene.xml'))  # parse with PyMJCF then convert to physics
FileNotFoundError: [Errno 2] No such file or directory: 'my_scene1/inner/inner/inner-inner/include.xml'
  • my_scene2/scene.xml is the same as my_scene1/scene.xml but the inner include path is given relative to the current model directory (my_scene2/inner/). PyMJCF supports this but it does not compile natively using MuJoCo.
>>> mjcf.Physics.from_xml_path('my_scene2/scene.xml')  # parse using mujoco directly
ValueError: XML Error: Could not open file 'my_scene2/inner-inner/include.xml'
Element 'include', line 0

>>> mjcf.Physics.from_mjcf_model(mjcf.from_path('my_scene2/scene.xml'))  # parse with PyMJCF then convert to physics
<dm_control.mjcf.physics.Physics object at 0x7fc61f1a6700>
  • my_scene3/scene.xml specifies mesh and texture files in an included file to show that MuJoCo expects these files to be specified relative to the top-level model directory as well.
>>> mjcf.Physics.from_xml_path('my_scene3/scene.xml')  # parse using mujoco directly
<dm_control.mjcf.physics.Physics object at 0x7fc61f1a6f10>

>>> mjcf.Physics.from_mjcf_model(mjcf.from_path('my_scene2/scene.xml'))  # parse with PyMJCF then convert to physics
FileNotFoundError: Line 4: error while parsing element <mesh>: during initialization of attribute 'file' of element <mesh>: [Errno 2] No such file or directory: 'my_scene3/inner/meshes/banana.stl'

In conclusion, models with nested include tags or external assets in included files are parsed differently with MuJoCo than with PyMJCF.

@guyazran guyazran changed the title PyMJCF recursive include tags relative to base model PyMJCF nested include tags relative to base model Aug 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant