-
Notifications
You must be signed in to change notification settings - Fork 135
Description
Description:
I encountered a ValueError when attempting to use mjw.get_data_into with a MuJoCo model that does not define any tendons. The error message indicates a shape mismatch during the data transfer for ten_J (tendon Jacobian).
Steps to reproduce:
- Define a simple MuJoCo model without any tendons:
mj_model = mujoco.MjModel.from_xml_string("""
<mujoco>
<option timestep="0.01666"/> <!-- ~60 hz -->
<worldbody>
<light name="top" pos="0 0 1"/>
<body name="box_and_sphere" euler="0 0 -30">
<joint name="swing" type="hinge" axis="1 -1 0" pos="-.2 -.2 -.2"/>
<geom name="red_box" type="box" size=".2 .2 .2" rgba="1 0 0 1"/>
<geom name="green_sphere" pos="-.2 -.2 -.2" size=".1" rgba="0 1 0 1"/>
</body>
</worldbody>
</mujoco>
""")
- Initialise
mj_data,mjw.Model, andmjw.Data:
mj_data = mujoco.MjData(mj_model)
model = mjw.put_model(mj_model)
data = mjw.put_data(mj_model, mj_data)
- Attempt to step the simulation using
mjw.stepand then transfer data back tomj_datausingmjw.get_data_into:
mjw.reset_data(model, data)
# Looping for multiple steps, the error occurs on the first call to get_data_into
mjw.step(model, data)
mjw.get_data_into(mj_data, mj_model, data) # This line throws the error
Expected behavior:
mjw.get_data_into should successfully transfer data from the mujoco_warp.Data object to the mujoco.MjData object without error, even when the model has no tendons. In such cases, the tendon-related fields in mj_data (like ten_J) should remain empty or be handled appropriately.
Observed behavior:
The following ValueError is raised:
ValueError: could not broadcast input array from shape (0,1) into shape (0,)
Traceback (partial, relevant lines):
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
[/tmp/ipython-input-3920325754.py](https://localhost:8080/#) in <cell line: 0>()
3 for _ in range(3 * 60):
4 mjw.step(model, data)
----> 5 mjw.get_data_into(mj_data, mj_model, data)
6 renderer.update_scene(mj_data)
7 frames.append(renderer.render())
[/usr/local/lib/python3.12/dist-packages/mujoco_warp/_src/io.py](https://localhost:8080/#) in get_data_into(result, mjm, d, world_id)
1173 # tendon
1174 result.ten_length[:] = d.ten_length.numpy()[world_id]
-> 1175 result.ten_J[:] = d.ten_J.numpy()[world_id]
1176 result.ten_wrapadr[:] = d.ten_wrapadr.numpy()[world_id]
1177 result.ten_wrapnum[:] = d.ten_wrapnum.numpy()[world_id]
ValueError: could not broadcast input array from shape (0,1) into shape (0,)
It appears that for models without tendons (mjm.nten == 0), mj_data.ten_J has a shape of (0,), while d.ten_J.numpy()[world_id] might be returning a shape of (0,1) for empty tendon data, leading to the broadcast error.
Environment:
- Google Colab (GPU runtime)
mujoco_warp(installed via!uv pip install "git+https://github.com/google-deepmind/mujoco_warp.git")mujoco(version as installed bymujoco_warp)warp-lang(version as installed bymujoco_warp)