Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
5676dd1
Add resolve_ids next to resolve_1d_mask as the shared id and mask hel…
hujc7 Oct 26, 2026
97e5662
Resolve sensor, camera and wrench composer selections through the sha…
hujc7 Oct 26, 2026
92590d0
Fix the deformable mask writers that raised on any env mask
hujc7 Oct 26, 2026
f044c92
Resolve Newton selections through the shared helpers and write its ma…
hujc7 Oct 26, 2026
7b48c38
Resolve OVPhysX selections through the shared helpers
hujc7 Oct 26, 2026
3d3661f
Resolve PhysX selections through the shared helpers
hujc7 Oct 26, 2026
43bb968
Merge remote-tracking branch 'upstream/main' into jichuanh/id-mask
hujc7 Oct 26, 2026
e390289
Trim duplicate id-resolution and mask-writer tests
hujc7 Oct 27, 2026
13ec11c
Accept every id form main accepted in resolve_1d_mask
hujc7 Oct 27, 2026
784b0a2
Refresh the solver on every replay of the Newton tendon mask writer
hujc7 Oct 27, 2026
6a4f173
Tidy the mask writers, their docs and the selection tests
hujc7 Oct 27, 2026
bc9a8bb
Reject Newton masks whose length differs from the asset dimension
hujc7 Oct 27, 2026
981e3a4
Accept strided torch limits in the Newton tendon position limit mask …
hujc7 Oct 27, 2026
cff8f86
Run the tendon replay test before the module's shared scene opens
hujc7 Oct 27, 2026
bbb5104
Revert "Reject Newton masks whose length differs from the asset dimen…
hujc7 Oct 27, 2026
029ee47
Resolve the Newton collection writer masks inline again
hujc7 Oct 27, 2026
551e508
Launch the rewritten Newton mask writers over the mask lengths
hujc7 Oct 27, 2026
86ce1c9
Write the rewritten Newton mask writers through a core masked write
hujc7 Oct 27, 2026
b37d231
Merge upstream main 6ef40d19a6f into jichuanh/id-mask
hujc7 Oct 28, 2026
dc2aba6
Align resolve_ids and write_2d_with_mask with the shared memory helpers
hujc7 Oct 29, 2026
92a413e
Write strided vector components through scalar views instead of copyi…
hujc7 Oct 29, 2026
efee1b9
Update camera poses on reset through the resolved mask
hujc7 Oct 29, 2026
b7d5295
Merge remote-tracking branch 'upstream/main' into jichuanh/id-mask
hujc7 Oct 29, 2026
c5299e5
Pass the short test mask as an explicit env_mask keyword
hujc7 Nov 2, 2026
3635089
Merge remote-tracking branch 'upstream/main' into jichuanh/id-mask
hujc7 Nov 2, 2026
ddcd317
Merge remote-tracking branch 'upstream/main' into jichuanh/id-mask
hujc7 Nov 2, 2026
12270ab
Describe the Newton collection and FK changes after the main merge
hujc7 Nov 2, 2026
22b9aed
Merge main 299af193136 into jichuanh/id-mask
hujc7 Nov 9, 2026
c94a9f3
Restore main's FK launch size
hujc7 Nov 9, 2026
6afa0a2
Pass every selection form on and let each consumer pick its own
hujc7 Nov 9, 2026
47b5499
Describe resolve_ids' slice(None) all_ids in the changelog
hujc7 Nov 9, 2026
b75b5a8
Register tendon property writes as a model change as main does
hujc7 Nov 9, 2026
2a65a30
Merge main 2742c2d5e6b into jichuanh/id-mask
hujc7 Nov 10, 2026
84470f4
Drop the invalidate_fk changelog line: its launch size is main's again
hujc7 Nov 10, 2026
11d840a
Reject masks longer than the destination and leave the slice(None) al…
hujc7 Nov 10, 2026
f522b47
Merge main 616f517707d into jichuanh/id-mask
hujc7 Nov 12, 2026
e6e178c
Refresh the solver on every replay of a captured model-property write
hujc7 Nov 12, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions source/isaaclab/changelog.d/jichuanh-id-mask.added.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
* Added :func:`~isaaclab.utils.warp.memory.resolve_ids`, which resolves an index selection given as ids or as a
boolean mask to ids on a device, as :func:`~isaaclab.utils.warp.memory.resolve_1d_mask` does to a mask.
* Added :func:`~isaaclab.utils.warp.memory.write_2d_with_mask`, which writes 2-D data or one scalar into a Warp array
where a row mask and a column mask are both true, launching over the mask lengths.
15 changes: 15 additions & 0 deletions source/isaaclab/changelog.d/jichuanh-id-mask.changed.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
* Changed the env selection helpers of :class:`~isaaclab.utils.wrench_composer.WrenchComposer` and
:class:`~isaaclab.sensors.Camera` to resolve ``env_ids`` and ``env_mask`` through
:func:`~isaaclab.utils.warp.memory.resolve_ids` and :func:`~isaaclab.utils.warp.memory.resolve_1d_mask`.
Any integer sequence and slices with a negative step are accepted, ids on another device are moved to the owner's
device, and a :class:`~isaaclab.utils.warp.ProxyArray` is rejected with a :class:`TypeError`. The
:class:`~isaaclab.sensors.Camera` now rejects floating-point ``env_ids`` with a :class:`TypeError` and
multi-dimensional ``env_ids`` with a :class:`ValueError` instead of casting and flattening them.
* Changed :class:`~isaaclab.utils.wrench_composer.WrenchComposer` to resolve ``body_ids`` through
:func:`~isaaclab.utils.warp.memory.resolve_ids` as well, so slices other than ``slice(None)`` are accepted.
* Changed :func:`~isaaclab.utils.warp.memory.resolve_1d_mask` to make ``scratch_mask`` optional for callers that never
pass ids. Their masks are returned as given. Ids without a ``scratch_mask`` raise a :class:`ValueError`, and so
does a mask longer than ``all_mask``.
* Changed :func:`~isaaclab.utils.warp.memory.resolve_ids` to use given ids over a mask: the mask is converted to ids
only when no ids (or ``slice(None)``) are given. When both ``env_ids`` and ``env_mask`` are given, PhysX assets now
use the ids, which their views take without a host synchronization; mask-native consumers still use the mask.
4 changes: 4 additions & 0 deletions source/isaaclab/changelog.d/jichuanh-id-mask.fixed.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
* Fixed the ``write_nodal_*_to_sim_mask`` methods of :class:`~isaaclab.assets.BaseDeformableObject`, which the
OVPhysX deformable object inherits, raising a :class:`RuntimeError` whenever ``env_mask`` was given.
* Fixed :meth:`~isaaclab.sensors.Camera.reset` with an ``env_mask`` on another device than the camera: the camera
poses are now updated through the mask resolved on the camera's device, like the timestamps and buffers.
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

from ...utils import math as math_utils
from ...utils.warp import ProxyArray
from ...utils.warp.memory import resolve_ids
from ..asset_base import AssetBase

if TYPE_CHECKING:
Expand Down Expand Up @@ -200,6 +201,9 @@ def write_nodal_kinematic_target_to_sim_index(

"""
Operations - Write to simulation (mask variants).

These convert the mask to ids, which waits for the device, and call the index variants.
Backends with a mask write path override them.
"""

def write_nodal_state_to_sim_mask(
Expand All @@ -214,10 +218,7 @@ def write_nodal_state_to_sim_mask(
Shape is (num_instances, max_sim_vertices_per_body, 6).
env_mask: Environment mask. If None, then all indices are used.
"""
if env_mask is not None:
env_ids = wp.nonzero(env_mask)
else:
env_ids = self._ALL_INDICES
env_ids = resolve_ids(mask=env_mask, all_ids=self._ALL_INDICES)
self.write_nodal_state_to_sim_index(nodal_state, env_ids=env_ids, full_data=True)

def write_nodal_pos_to_sim_mask(
Expand All @@ -232,10 +233,7 @@ def write_nodal_pos_to_sim_mask(
Shape is (num_instances, max_sim_vertices_per_body, 3).
env_mask: Environment mask. If None, then all indices are used.
"""
if env_mask is not None:
env_ids = wp.nonzero(env_mask)
else:
env_ids = self._ALL_INDICES
env_ids = resolve_ids(mask=env_mask, all_ids=self._ALL_INDICES)
self.write_nodal_pos_to_sim_index(nodal_pos, env_ids=env_ids, full_data=True)

def write_nodal_velocity_to_sim_mask(
Expand All @@ -250,10 +248,7 @@ def write_nodal_velocity_to_sim_mask(
Shape is (num_instances, max_sim_vertices_per_body, 3).
env_mask: Environment mask. If None, then all indices are used.
"""
if env_mask is not None:
env_ids = wp.nonzero(env_mask)
else:
env_ids = self._ALL_INDICES
env_ids = resolve_ids(mask=env_mask, all_ids=self._ALL_INDICES)
self.write_nodal_velocity_to_sim_index(nodal_vel, env_ids=env_ids, full_data=True)

def write_nodal_kinematic_target_to_sim_mask(
Expand All @@ -268,10 +263,7 @@ def write_nodal_kinematic_target_to_sim_mask(
Shape is (num_instances, max_sim_vertices_per_body, 4).
env_mask: Environment mask. If None, then all indices are used.
"""
if env_mask is not None:
env_ids = wp.nonzero(env_mask)
else:
env_ids = self._ALL_INDICES
env_ids = resolve_ids(mask=env_mask, all_ids=self._ALL_INDICES)
self.write_nodal_kinematic_target_to_sim_index(targets, env_ids=env_ids, full_data=True)

"""
Expand Down
25 changes: 3 additions & 22 deletions source/isaaclab/isaaclab/sensors/camera/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
quat_from_matrix,
)
from ...utils.warp import ProxyArray
from ...utils.warp.memory import resolve_1d_indices, resolve_ids
from ..sensor_base import SensorBase
from .camera_data import CameraData, RenderBufferKind

Expand Down Expand Up @@ -641,7 +642,7 @@ def reset(self, env_ids: Sequence[int] | slice | None = None, env_mask: wp.array
# reset the data
# note: this recomputation is useful if one performs events such as randomizations on the camera poses.
if env_mask is not None:
self._update_poses(env_mask=env_mask, frame_op=2)
self._update_poses(env_mask=reset_mask, frame_op=2)
elif env_ids is None:
self._update_poses(frame_op=2)
else:
Expand Down Expand Up @@ -1002,27 +1003,7 @@ def _resolve_env_ids_wp(self, env_ids: Sequence[int] | torch.Tensor | wp.array |
"""Resolve camera indices to a Warp ``int32`` array."""
if env_ids is None:
return None
if isinstance(env_ids, wp.array):
if env_ids.dtype != wp.int32:
raise TypeError(f"Unsupported wp.array dtype for env_ids: {env_ids.dtype}. Expected wp.int32.")
if env_ids.ndim != 1:
raise ValueError("Warp camera indices must be a one-dimensional array.")
if str(env_ids.device) == str(self._device):
return env_ids
return env_ids.to(self._device)
elif isinstance(env_ids, torch.Tensor):
env_ids = env_ids.to(device=self._device, dtype=torch.int32).reshape(-1)
if not env_ids.is_contiguous():
env_ids = env_ids.contiguous()
return wp.from_torch(env_ids, dtype=wp.int32)
elif isinstance(env_ids, slice) and (env_ids.step or 1) > 0:
return wp.from_torch(wp.to_torch(self._ALL_INDICES)[env_ids])
elif isinstance(env_ids, slice):
# Torch cannot slice with a negative step.
env_ids = np.arange(self._view.count, dtype=np.int32)[env_ids]
else:
env_ids = np.asarray(env_ids, dtype=np.int32).reshape(-1)
return wp.array(env_ids, dtype=wp.int32, device=self._device)
return resolve_1d_indices(resolve_ids(ids=env_ids, all_ids=self._ALL_INDICES))

def _env_mask_has_any(self, env_mask: wp.array) -> bool:
"""Return whether the mask selects any camera."""
Expand Down
124 changes: 112 additions & 12 deletions source/isaaclab/isaaclab/utils/warp/memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import warp as wp

from .index_kernel import selector_dtype
from .proxy_array import ProxyArray

_CONCAT_TILE_SIZE = 32

Expand Down Expand Up @@ -290,6 +291,37 @@ def fill(
return fill


def write_2d_with_mask(
data: "float | torch.Tensor | wp.array",
row_mask: wp.array,
column_mask: wp.array,
out: wp.array,
) -> None:
"""Write ``data`` into ``out`` where both masks are true, launching over the mask lengths.

A mask shorter than ``out`` writes only the rows or columns it covers. Callers resolve the masks and check the
data shape.

Args:
data: Values of shape ``(row_mask.shape[0], column_mask.shape[0])`` in the dtype of ``out``, as a ``wp.array``
or a ``torch.Tensor`` with the dtype's trailing dimensions, or one scalar for every selected entry.
row_mask: Boolean mask over the first dimension of ``out``.
column_mask: Boolean mask over the second dimension of ``out``.
out: Output array. The launch runs on its device.
"""
dim = (row_mask.shape[0], column_mask.shape[0])
if isinstance(data, (int, float)):
kernel = make_masked_fill(out.dtype, 2)
elif isinstance(data, torch.Tensor) and data.ndim > 2 and data.stride(-1) != 1:
# a vector-typed argument needs packed components; copy strided ones through scalar views instead
scalar = out.dtype._wp_scalar_type_
kernel, dim = make_masked_copy(scalar, 3), (*dim, data.shape[-1])
data, out = wp.from_torch(data, dtype=scalar), out.view(scalar)
else:
kernel = make_masked_copy(out.dtype, 2)
wp.launch(kernel, dim=dim, inputs=[data, row_mask, column_mask], outputs=[out], device=out.device)


@cache
def _make_populate_mask(dtype) -> wp.Kernel:
@wp.kernel(module="unique")
Expand All @@ -316,11 +348,11 @@ def resolve_1d_mask(
ids: "Sequence[int] | slice | torch.Tensor | wp.array | None" = None,
mask: "wp.array | torch.Tensor | None" = None,
all_mask: wp.array,
scratch_mask: wp.array,
scratch_mask: wp.array | None = None,
) -> wp.array:
"""Resolve a selection using caller-owned boolean storage on its device.

An explicit boolean mask takes precedence. ``None`` and ``slice(None)`` return
A given boolean mask is used as given, so a mask consumer converts no ids. ``None`` and ``slice(None)`` return
the identical ``all_mask`` object. Boolean selectors are masks; signed int32/int64
selectors are indices, supporting negatives and duplicates. Index values must be
in ``[-size, size)``; invalid device indices are ignored without a host sync.
Expand All @@ -329,21 +361,32 @@ def resolve_1d_mask(
storage. Host sequences and device transfers are eager-only and may allocate.
Temporary CUDA index uploads synchronize their stream before releasing storage;
preallocated device selectors avoid this synchronization.
Integer widths and strides are preserved. Masks must have the destination shape
and boolean dtype. The returned scratch storage is reused, so this is not reentrant.
Integer widths and strides are preserved. Masks use the boolean dtype and are never
longer than ``all_mask``; with a ``scratch_mask`` they have its exact shape. The returned
scratch storage is reused, so this is not reentrant.
Callers that never select by ids may omit ``scratch_mask``; their masks, which may be
shorter than ``all_mask``, are then returned as given, and the callers launch over the
mask lengths, so a short mask writes only the rows it covers.

Raises:
ValueError: If ids or a slice select a subset of elements and no ``scratch_mask`` is given,
or a boolean mask is longer than ``all_mask`` or differs from a given ``scratch_mask`` shape.
"""
device = scratch_mask.device
if scratch_mask.ndim != 1 or scratch_mask.dtype != wp.bool:
raise ValueError("scratch_mask must be a rank-1 boolean Warp array")
if all_mask.shape != scratch_mask.shape or all_mask.dtype != wp.bool or all_mask.device != device:
raise ValueError("all_mask must match scratch_mask shape, dtype and device")
device = all_mask.device
if scratch_mask is not None:
if scratch_mask.ndim != 1 or scratch_mask.dtype != wp.bool:
raise ValueError("scratch_mask must be a rank-1 boolean Warp array")
if all_mask.shape != scratch_mask.shape or all_mask.dtype != wp.bool or all_mask.device != scratch_mask.device:
raise ValueError("all_mask must match scratch_mask shape, dtype and device")

temporary_input = False
selection = mask if mask is not None else ids
if selection is None or (isinstance(selection, slice) and selection == slice(None)):
return all_mask
if isinstance(selection, slice):
start, stop, step = selection.indices(scratch_mask.shape[0])
start, stop, step = selection.indices(all_mask.shape[0])
if scratch_mask is None:
raise ValueError("resolve_1d_mask needs a scratch_mask to write ids into.")
scratch_mask.zero_()
count = len(range(start, stop, step))
if count:
Expand Down Expand Up @@ -381,11 +424,15 @@ def resolve_1d_mask(
if selection.ndim != 1:
raise ValueError("Selectors must be rank-1 arrays")
if mask is not None or selection.dtype == wp.bool:
if selection.dtype != wp.bool or selection.shape != scratch_mask.shape:
raise ValueError("Boolean masks must match the destination shape and dtype")
size = all_mask.shape[0] # the scratch_mask length when one is given
fits = selection.shape[0] == size if scratch_mask is not None else selection.shape[0] <= size
if selection.dtype != wp.bool or not fits:
raise ValueError("Boolean masks must fit the destination shape and use the boolean dtype")
return selection
if selection.dtype not in (wp.int32, wp.int64):
raise TypeError("Index arrays must use signed int32 or int64 values")
if scratch_mask is None:
raise ValueError("resolve_1d_mask needs a scratch_mask to write ids into.")
scratch_mask.zero_()
if selection.size:
wp.launch(
Expand All @@ -395,3 +442,56 @@ def resolve_1d_mask(
# Eager uploads must outlive scatter even on imported nonblocking CUDA streams.
wp.synchronize_stream(wp.get_stream(device))
return scratch_mask


def resolve_ids(
*,
ids: "Sequence[int] | slice | torch.Tensor | wp.array | None" = None,
mask: "wp.array | torch.Tensor | None" = None,
all_ids: wp.array,
) -> "wp.array | torch.Tensor":
"""Resolve ids/mask into ids on the device of ``all_ids``. Given ids are used as given: a consumer of ids takes
them without converting the mask, which happens only when no ids (or ``slice(None)``) are given.

Pass the result to :func:`resolve_1d_indices` where contiguous int32 ids are needed.

Args:
ids: Index ids. Accepts ``Sequence[int]``, ``slice``, ``torch.Tensor``, ``wp.array``,
or ``None`` (all elements). Tensors and warp arrays keep their integer dtype.
mask: Boolean mask. Its ids are found with :func:`torch.nonzero`, which waits for
the device.
all_ids: Pre-allocated ids of every element, returned as-is when *ids* and *mask*
select every element.

Returns:
``all_ids``, a ``torch.Tensor`` or a ``wp.array`` of ids on the device of ``all_ids``.
A mask resolves to an int64 ``torch.Tensor``; lists and slices resolve to ``wp.int32``.

Raises:
TypeError: If *ids* is a :class:`ProxyArray`, which is output-only, or *mask* is
neither a ``wp.array`` nor a ``torch.Tensor``.
"""
device = all_ids.device
if mask is not None and (ids is None or (isinstance(ids, slice) and ids == slice(None))):
if isinstance(mask, wp.array):
mask = wp.to_torch(mask)
elif not isinstance(mask, torch.Tensor):
raise TypeError(f"Unsupported mask type: {type(mask)}")
return torch.nonzero(mask.to(wp.device_to_torch(device))).squeeze(-1)
if isinstance(ids, torch.Tensor):
return ids if str(ids.device) == str(device) else ids.to(wp.device_to_torch(device))
if ids is None:
return all_ids
if isinstance(ids, wp.array):
return ids if ids.device == device else ids.to(device)
if isinstance(ids, ProxyArray):
raise TypeError("ProxyArray is output-only; pass .warp or .torch explicitly.")
if isinstance(ids, slice):
if ids == slice(None):
return all_ids
start, stop, step = ids.indices(all_ids.shape[0])
if step > 0:
# a strided view of the caller's all-ids, no copy
return wp.from_torch(wp.to_torch(all_ids)[start:stop:step])
return wp.array(list(range(start, stop, step)), dtype=wp.int32, device=device)
return wp.array(list(ids), dtype=wp.int32, device=device)
40 changes: 6 additions & 34 deletions source/isaaclab/isaaclab/utils/wrench_composer.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

from .warp import ProxyArray
from .warp.index_kernel import selector_dtype
from .warp.memory import resolve_ids
from .warp.wrench import (
add_raw_wrench_buffers,
compose_wrench_to_body_frame,
Expand Down Expand Up @@ -573,7 +574,7 @@ def reset(
flags. Other ``env_ids`` or ``env_mask`` values perform a partial reset on the specified environments using
the reset kernels. An inactive composer already holds zero buffers, so any reset of it is a no-op.

.. caution:: If both ``env_ids`` and ``env_mask`` are provided, ``env_mask`` takes precedence.
.. caution:: If both ``env_ids`` and ``env_mask`` are provided, the mask is used: the kernels take it.

Args:
env_ids: Environment indices. Defaults to None (all environments).
Expand Down Expand Up @@ -700,24 +701,9 @@ def _resolve_env_ids(self, env_ids: wp.array | torch.Tensor | list | slice | Non
Environment indices.

Raises:
TypeError: If ``env_ids`` is an unsupported type.
TypeError: If ``env_ids`` is a :class:`~isaaclab.utils.warp.ProxyArray`.
"""
if env_ids is None:
return self._ALL_ENV_INDICES
# Check tensor types before slice comparison (tensor == slice crashes)
if isinstance(env_ids, torch.Tensor):
return env_ids
if isinstance(env_ids, wp.array):
return env_ids
if env_ids == slice(None):
return self._ALL_ENV_INDICES
if isinstance(env_ids, slice):
return wp.from_torch(wp.to_torch(self._ALL_ENV_INDICES)[env_ids])
if isinstance(env_ids, list):
return wp.array(env_ids, dtype=wp.int32, device=self.device)
raise TypeError(
f"env_ids must be None, slice(None), list, torch.Tensor, or wp.array, got {type(env_ids).__name__}"
)
return resolve_ids(ids=env_ids, all_ids=self._ALL_ENV_INDICES)

def _resolve_body_ids(
self, body_ids: Sequence[int] | torch.Tensor | wp.array | slice | None
Expand All @@ -731,23 +717,9 @@ def _resolve_body_ids(
Body indices.

Raises:
TypeError: If ``body_ids`` is an unsupported type.
TypeError: If ``body_ids`` is a :class:`~isaaclab.utils.warp.ProxyArray`.
"""
if body_ids is None:
return self._ALL_BODY_INDICES
if isinstance(body_ids, ProxyArray):
raise TypeError("ProxyArray is output-only; pass .warp or .torch explicitly.")
if isinstance(body_ids, torch.Tensor):
return body_ids
if isinstance(body_ids, wp.array):
return body_ids
if body_ids == slice(None):
return self._ALL_BODY_INDICES
if isinstance(body_ids, Sequence):
return wp.array(body_ids, dtype=wp.int32, device=self.device)
raise TypeError(
f"body_ids must be None, slice(None), a sequence, torch.Tensor, or wp.array, got {type(body_ids).__name__}"
)
return resolve_ids(ids=body_ids, all_ids=self._ALL_BODY_INDICES)

def _ensure_composed(self):
"""Compose input buffers into output buffers if dirty."""
Expand Down
Loading
Loading