Skip to content

mujoco_warp: wp.full crashes because eq_active sum promotes to float #890

@ooctipus

Description

@ooctipus

https://github.com/google-deepmind/mujoco/blob/main/mjx/mujoco/mjx/third_party/mujoco_warp/_src/io.py#L811-L812

  d.ne_connect = wp.full(nworld, 3 * np.sum((mjm.eq_type == mujoco.mjtEq.mjEQ_CONNECT) & mjd.eq_active), dtype=int)
  d.ne_weld = wp.full(nworld, 6 * np.sum((mjm.eq_type == mujoco.mjtEq.mjEQ_WELD) & mjd.eq_active), dtype=int)

mjd.eq_active is type array of uint8, and (mjm.eq_type == mujoco.mjtEq.mjEQ_CONNECT) is array of bool, np.sum will return a uint
multiplying a python integer with numpy unsigned int promotes it to float64.

type(np.sum((mjm.eq_type == mujoco.mjtEq.mjEQ_CONNECT) & mjd.eq_active))
<class 'numpy.uint64'>

type(3 * np.sum((mjm.eq_type == mujoco.mjtEq.mjEQ_CONNECT) & mjd.eq_active))
<class 'numpy.float64'>

but np.full will not be happy with float

wp.full(nworld, 3 * np.sum((mjm.eq_type == mujoco.mjtEq.mjEQ_CONNECT) & mjd.eq_active), dtype=int)
Traceback (most recent call last):
  File "/home/zhengyuz/miniconda3/envs/newton_isaaclab/lib/python3.11/site-packages/isaacsim/extscache/omni.warp.core-1.11/warp/_src/types.py", line 3326, in fill_
    cvalue = self.dtype._type_(value)
             ^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: 'numpy.float64' object cannot be interpreted as an integer

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/home/zhengyuz/miniconda3/envs/newton_isaaclab/lib/python3.11/site-packages/isaacsim/extscache/omni.warp.core-1.11/warp/_src/context.py", line 5887, in full
    arr.fill_(value)
  File "/home/zhengyuz/miniconda3/envs/newton_isaaclab/lib/python3.11/site-packages/isaacsim/extscache/omni.warp.core-1.11/warp/_src/types.py", line 3328, in fill_
    raise ValueError(f"Failed to convert the value to the array data type: {e}") from e
ValueError: Failed to convert the value to the array data type: 'numpy.float64' object cannot be interpreted as an integer

the fix seems to just be casting to int to revert the promotion. Im happy to submit a pr if that seems the right fix

  d.ne_connect = wp.full(nworld, 3 * int(np.sum((mjm.eq_type == mujoco.mjtEq.mjEQ_CONNECT) & mjd.eq_active)), dtype=int)
  d.ne_weld = wp.full(nworld, 6 * int(np.sum((mjm.eq_type == mujoco.mjtEq.mjEQ_WELD) & mjd.eq_active)), dtype=int)

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions