[Bug]: NumPy and Python boolean masks select the wrong environments and joints.
Bug Description
Passing a NumPy boolean environment mask to Scene.reset can reset an unselected environment's state and clock. Python boolean lists and tuples also lose their mask semantics in environment and entity-local indexing. This can silently mix up episodes in batched simulations.
Steps to Reproduce
On the commit below, run:
import numpy as np
import genesis as gs
gs.init(backend=gs.gpu)
scene = gs.Scene(
sim_options=gs.options.SimOptions(
dt=0.01,
),
show_viewer=False,
)
sphere = scene.add_entity(
morph=gs.morphs.Sphere(
pos=(0.0, 0.0, 1.0),
),
)
scene.build(n_envs=3)
for _ in range(10):
scene.step()
scene.reset(envs_idx=np.array([False, True, False]))
print(scene.get_time())
print(sphere.get_pos())
gs.destroy()Expected Behavior
Only environment 1 should reset: the clocks should be [0.1, 0.0, 0.1], its sphere should return to (0, 0, 1), and the other spheres should retain their positions. The NumPy mask should select the same environments as the equivalent Torch boolean tensor.
Relevant log output
The clocks instead become [0.0, 0.0, 0.1]: environment 0 is reset even though its mask entry is False.
Sphere 0 also jumps from its pre-reset height of approximately 0.946045 back to 1.0, just like sphere 1. Sphere 2 remains at its pre-reset height. This reproduces with both GS_ENABLE_NDARRAY=1 and GS_ENABLE_NDARRAY=0.
Environment
- WSL Ubuntu 24.04 CPU: PyTorch 2.11.0+cpu, Quadrants 1.3.3.
- Linux NVIDIA RTX 5090: driver 610.57.04, PyTorch 2.9.1 with CUDA 12.9, Quadrants 1.3.3.
Release version or Commit ID
6b0a0b4f3d626c17aa7e2c7a754512336a611929 (main).
Additional Context
The shared index conversion coerces host boolean masks to integer indices, and treats single-element NumPy boolean masks as scalar indices. Boolean lists/tuples also need to retain their meaning in the field-copy path and when converting entity-local DOFs to global indices.
Source: Genesis-Embodied-AI/genesis-world