Skip to content

Recompile does not apply in-place updates to model and data  #1870

@bikcrum

Description

@bikcrum

Branch: main (9febd76)

I am adding a geom to the existing model and runningrecompile(model, data) to obtain the updated model. However, the updates are not being applied in-place contrary to the documentation https://mujoco.readthedocs.io/en/latest/APIreference/APIfunctions.html#mj-recompile. This issue is also mentioned in #1822, which was closed without any comment.

Code to reproduce:

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: []"

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions