You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Recompile does not apply in-place updates to model and data #1870
import mujoco as mj
# Define a simple model
model_string = """
<mujoco>
<worldbody>
<body>
<freejoint/>
<geom size=".15" mass="1" type="sphere"/>
</body>
</worldbody>
</mujoco>
"""
# Compile the model
spec = mj.MjSpec()
spec.from_string(model_string)
model = spec.compile()
data = mj.MjData(model)
# Add a geom to the world body
body = spec.worldbody
geom = body.add_geom()
geom.name = 'my_geom'
geom.size[0] = 1
geom.pos = [1, 1, 0]
# Recompile the model
new_model, new_data = spec.recompile(model, data)
new_model.geom('my_geom') # No error
model.geom('my_geom')
Error:
# KeyError: "Invalid name 'my_geom'. Valid names: []"
changed the title [-]Recompile is not doing in-place update of model and data [/-][+]Recompile does not apply in-place updates to model and data [/+]on Aug 1, 2024
They will not be true in-place operations anyway because sizes change, causing possible issues with variables referencing the old mjData which would become invalid without the user explicitly being aware of it.
As @quagla explained, there are technical issues preventing in-place updates in Python. I suspect the dangling reference issue could easily cause segfault. Perhaps @saran-t can expand more on the (im?)possibility of doing this...
Closing for now.
Regarding
This issue is also mentioned in #1822, which was closed without any comment.
Not true, it was closed with a comment saying it was completed and referencing the fix:
Activity
[-]Recompile is not doing in-place update of model and data [/-][+]Recompile does not apply in-place updates to model and data [/+]quagla commentedon Aug 1, 2024
It happens in place only in C (which is the function described in the docs), not in Python.
quagla commentedon Aug 1, 2024
Here is how the C function is wrapped in the bindings if you wish to have a look at what happens under the hood
https://github.com/google-deepmind/mujoco/blob/main/python/mujoco/structs.cc#L454
bikcrum commentedon Aug 1, 2024
@quagla Is it possible to edit this function to perform in-place operations for Python as well? Is there something preventing this?
quagla commentedon Aug 7, 2024
They will not be true in-place operations anyway because sizes change, causing possible issues with variables referencing the old mjData which would become invalid without the user explicitly being aware of it.
yuvaltassa commentedon Aug 14, 2024
As @quagla explained, there are technical issues preventing in-place updates in Python. I suspect the dangling reference issue could easily cause segfault. Perhaps @saran-t can expand more on the (im?)possibility of doing this...
Closing for now.
Regarding
Not true, it was closed with a comment saying it was completed and referencing the fix: