diff --git a/source/isaaclab/changelog.d/jichuanh-mask-writers-no-ids.skip b/source/isaaclab/changelog.d/jichuanh-mask-writers-no-ids.skip new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/source/isaaclab/test/assets/contract/articulation_factory.py b/source/isaaclab/test/assets/contract/articulation_factory.py index 160f1546fa6b..10e1c6b6deee 100644 --- a/source/isaaclab/test/assets/contract/articulation_factory.py +++ b/source/isaaclab/test/assets/contract/articulation_factory.py @@ -114,6 +114,9 @@ def _physx_articulation(N, J, B, FT, ST, device, is_fixed_base, joint_ordering, articulation._ALL_JOINT_INDICES = indices(J, device) articulation._ALL_FIXED_TENDON_INDICES = indices(FT, device) articulation._ALL_SPATIAL_TENDON_INDICES = indices(ST, device) + articulation._ALL_ENV_MASK = wp.ones(N, dtype=wp.bool, device=device) + articulation._ALL_FIXED_TENDON_MASK = wp.ones(FT, dtype=wp.bool, device=device) + articulation._ALL_SPATIAL_TENDON_MASK = wp.ones(ST, dtype=wp.bool, device=device) for name in ("joint_pos_target", "joint_vel_target", "joint_effort_target", "body_wrench_force"): setattr(articulation, f"_{name}_backend", None) articulation._body_wrench_torque_backend = None diff --git a/source/isaaclab/test/assets/contract/test_articulation_contract.py b/source/isaaclab/test/assets/contract/test_articulation_contract.py index d518b609b145..f6e7d6682a5d 100644 --- a/source/isaaclab/test/assets/contract/test_articulation_contract.py +++ b/source/isaaclab/test/assets/contract/test_articulation_contract.py @@ -34,7 +34,7 @@ pytestmark = pytest.mark.integration # Distinct instance, joint, body, and tendon counts so any swapped axis shows up. -N, J, B, FT, ST = 2, 6, 7, 3, 2 +N, J, B, FT, ST = 2, 6, 7, 3, 4 _AXIS_COUNTS = {"joint": J, "body": B, "fixed_tendon": FT, "spatial_tendon": ST} @@ -154,9 +154,25 @@ def test_resolvers_select_from_their_own_cached_indices(monkeypatch, backend): @pytest.mark.parametrize("backend", backends("physx", "ovphysx")) def test_commanding_a_tendon_target_schedules_the_write(monkeypatch, backend): + """Index and masked length targets schedule the tendon write that ``write_data_to_sim`` performs. + + A masked target buffers ``rest_length - target`` for the selected environments and tendons only. + """ art, _ = _articulation(backend, "cpu", monkeypatch, num_fixed_tendons=2) art.set_fixed_tendon_position_target_index(target=torch.zeros((N, 2))) assert art._fixed_tendon_target_dirty is True + art.write_data_to_sim() + assert art._fixed_tendon_target_dirty is False + + rest_length = art.data.fixed_tendon_rest_length.torch.clone() + expected = art.data.fixed_tendon_offset.torch.clone() + target = torch.arange(2 * N, dtype=torch.float32).reshape(N, 2) + 0.5 + art.set_fixed_tendon_position_target_mask( + target=target, env_mask=_mask(N, [1], "cpu"), fixed_tendon_mask=_mask(2, [1], "cpu") + ) + expected[1, 1] = rest_length[1, 1] - target[1, 1] + torch.testing.assert_close(art.data.fixed_tendon_offset.torch, expected) + assert art._fixed_tendon_target_dirty is True @requires("newton") @@ -540,6 +556,57 @@ def read() -> ProxyArray: method(**{kwarg: wp.from_torch(extra_env.contiguous(), dtype=dtype)}) +_TENDON_MASK_SETTERS = [ + *[writer for writer in _WRITERS if writer[2] in ("fixed_tendon", "spatial_tendon")], + ("set_fixed_tendon_position_target", "target", "fixed_tendon", 0, wp.float32, "data.fixed_tendon_offset"), +] + + +@pytest.mark.parametrize("backend", backends("physx")) +@pytest.mark.parametrize( + "writer, kwarg, axis, trailing, dtype, getter", _TENDON_MASK_SETTERS, ids=[w[0] for w in _TENDON_MASK_SETTERS] +) +def test_tendon_mask_setters_write_only_what_short_masks_cover( + monkeypatch, backend, writer, kwarg, axis, trailing, dtype, getter +): + """Masks shorter than their axes write only the entries they cover, like the Newton kernel writers. + + Masks and data are views into full-size arrays, so a launch past the mask lengths would write defined values. + """ + art, _ = _articulation(backend, "cpu", monkeypatch) + count = _AXIS_COUNTS[axis] + push = getattr(art, f"write_{axis}_properties_to_sim_index") + push() + expected = attrgetter(getter)(art).torch.clone() + values = _payload((N, count), trailing, dtype, "cpu", offset=100.0) + data = wp.from_torch(values.contiguous(), dtype=dtype) + covered = (slice(N - 1), slice(count - 1)) + if writer == "set_fixed_tendon_position_target": + expected[covered] = art.data.fixed_tendon_rest_length.torch[covered] - values[covered] + else: + data = data[covered] + expected[covered] = values[covered] + setter = getattr(art, f"{writer}_mask") + env_mask = _mask(N, range(N), "cpu")[: N - 1] + tendon_mask = _mask(count, range(count), "cpu")[: count - 1] + if axis == "fixed_tendon": + setter(**{kwarg: data}, env_mask=env_mask, fixed_tendon_mask=tendon_mask) + else: + setter(**{kwarg: data}, env_mask=env_mask, spatial_tendon_mask=tendon_mask) + push() + _assert_reads_back(attrgetter(getter)(art), expected, writer) + + +@pytest.mark.parametrize("backend", backends("physx")) +def test_tendon_position_limit_mask_accepts_strided_torch_limits(monkeypatch, backend): + """A torch view whose limit pairs are not adjacent in memory writes like contiguous data, as the index setter.""" + art, _ = _articulation(backend, "cpu", monkeypatch) + limit = _payload((N, FT), 2, wp.vec2f, "cpu") + art.set_fixed_tendon_position_limit_mask(limit=torch.stack((limit, limit), dim=-1)[..., 0]) + art.write_fixed_tendon_properties_to_sim_index() + _assert_reads_back(art.data.fixed_tendon_pos_limits, limit, "strided limit") + + @pytest.mark.parametrize("backend", backends("physx", "ovphysx")) @pytest.mark.parametrize("selection", ["index", "mask"]) def test_friction_mixed_inputs_preserve_other_cells_and_components(monkeypatch, backend, selection): diff --git a/source/isaaclab_physx/changelog.d/jichuanh-mask-writers-no-ids.changed.rst b/source/isaaclab_physx/changelog.d/jichuanh-mask-writers-no-ids.changed.rst new file mode 100644 index 000000000000..d65e46aedc6f --- /dev/null +++ b/source/isaaclab_physx/changelog.d/jichuanh-mask-writers-no-ids.changed.rst @@ -0,0 +1,2 @@ +* Changed the :class:`~isaaclab_physx.assets.Articulation` fixed and spatial tendon mask setters to write the + tendon buffers through the masks instead of converting them to indices, removing a host wait per call. diff --git a/source/isaaclab_physx/isaaclab_physx/assets/articulation/articulation.py b/source/isaaclab_physx/isaaclab_physx/assets/articulation/articulation.py index 78bb4f5131d7..75cfd556d573 100644 --- a/source/isaaclab_physx/isaaclab_physx/assets/articulation/articulation.py +++ b/source/isaaclab_physx/isaaclab_physx/assets/articulation/articulation.py @@ -27,8 +27,9 @@ from isaaclab.utils.string import resolve_matching_names, resolve_matching_names_values from isaaclab.utils.version import get_isaac_sim_version, has_kit from isaaclab.utils.warp import ProxyArray, memory +from isaaclab.utils.warp import kernels as warp_kernels from isaaclab.utils.warp import math as warp_math -from isaaclab.utils.warp.memory import resolve_ids +from isaaclab.utils.warp.memory import resolve_1d_mask, resolve_ids, write_2d_with_mask from isaaclab.utils.wrench_composer import WrenchComposer from isaaclab_physx.assets import kernels as shared_kernels @@ -2633,22 +2634,15 @@ def set_fixed_tendon_stiffness_mask( .. note:: This method expects full data. - .. tip:: - For maximum performance we recommend using the index method. This is because in PhysX, the tensor API - is only supporting indexing, hence masks need to be converted to indices. - Args: stiffness: Fixed tendon stiffness. Shape is (num_instances, num_fixed_tendons). fixed_tendon_mask: Fixed tendon mask. If None, then all fixed tendons are used. env_mask: Environment mask. If None, then all the instances are updated. Shape is (num_instances,). """ - # Resolve masks. - env_ids = self._resolve_env_ids(env_mask=env_mask) - fixed_tendon_ids = self._resolve_fixed_tendon_ids(fixed_tendon_mask=fixed_tendon_mask) - # Set full data to True to ensure the right code path is taken inside the kernel. - self.set_fixed_tendon_stiffness_index( - stiffness=stiffness, fixed_tendon_ids=fixed_tendon_ids, env_ids=env_ids, full_data=True - ) + env_mask = self._resolve_mask(env_mask, self._ALL_ENV_MASK) + fixed_tendon_mask = self._resolve_mask(fixed_tendon_mask, self._ALL_FIXED_TENDON_MASK) + self.assert_shape_and_dtype_mask(stiffness, (env_mask, fixed_tendon_mask), wp.float32, "stiffness") + write_2d_with_mask(stiffness, env_mask, fixed_tendon_mask, self.data._fixed_tendon_stiffness) def set_fixed_tendon_damping_index( self, @@ -2711,22 +2705,15 @@ def set_fixed_tendon_damping_mask( .. note:: This method expects full data. - .. tip:: - For maximum performance we recommend using the index method. This is because in PhysX, the tensor API - is only supporting indexing, hence masks need to be converted to indices. - Args: damping: Fixed tendon damping. Shape is (num_instances, num_fixed_tendons). fixed_tendon_mask: Fixed tendon mask. If None, then all fixed tendons are used. env_mask: Environment mask. If None, then all the instances are updated. Shape is (num_instances,). """ - # Resolve masks. - env_ids = self._resolve_env_ids(env_mask=env_mask) - fixed_tendon_ids = self._resolve_fixed_tendon_ids(fixed_tendon_mask=fixed_tendon_mask) - # Set full data to True to ensure the right code path is taken inside the kernel. - self.set_fixed_tendon_damping_index( - damping=damping, fixed_tendon_ids=fixed_tendon_ids, env_ids=env_ids, full_data=True - ) + env_mask = self._resolve_mask(env_mask, self._ALL_ENV_MASK) + fixed_tendon_mask = self._resolve_mask(fixed_tendon_mask, self._ALL_FIXED_TENDON_MASK) + self.assert_shape_and_dtype_mask(damping, (env_mask, fixed_tendon_mask), wp.float32, "damping") + write_2d_with_mask(damping, env_mask, fixed_tendon_mask, self.data._fixed_tendon_damping) def set_fixed_tendon_limit_stiffness_index( self, @@ -2797,22 +2784,15 @@ def set_fixed_tendon_limit_stiffness_mask( .. note:: This method expects full data. - .. tip:: - For maximum performance we recommend using the index method. This is because in PhysX, the tensor API - is only supporting indexing, hence masks need to be converted to indices. - Args: limit_stiffness: Fixed tendon limit stiffness. Shape is (num_instances, num_fixed_tendons). fixed_tendon_mask: Fixed tendon mask. If None, then all fixed tendons are used. env_mask: Environment mask. If None, then all the instances are updated. Shape is (num_instances,). """ - # Resolve masks. - env_ids = self._resolve_env_ids(env_mask=env_mask) - fixed_tendon_ids = self._resolve_fixed_tendon_ids(fixed_tendon_mask=fixed_tendon_mask) - # Set full data to True to ensure the right code path is taken inside the kernel. - self.set_fixed_tendon_limit_stiffness_index( - limit_stiffness=limit_stiffness, fixed_tendon_ids=fixed_tendon_ids, env_ids=env_ids, full_data=True - ) + env_mask = self._resolve_mask(env_mask, self._ALL_ENV_MASK) + fixed_tendon_mask = self._resolve_mask(fixed_tendon_mask, self._ALL_FIXED_TENDON_MASK) + self.assert_shape_and_dtype_mask(limit_stiffness, (env_mask, fixed_tendon_mask), wp.float32, "limit_stiffness") + write_2d_with_mask(limit_stiffness, env_mask, fixed_tendon_mask, self.data._fixed_tendon_limit_stiffness) def set_fixed_tendon_position_limit_index( self, @@ -2874,23 +2854,18 @@ def set_fixed_tendon_position_limit_mask( .. note:: This method expects full data. - .. tip:: - For maximum performance we recommend using the index method. This is because in PhysX, the tensor API - is only supporting indexing, hence masks need to be converted to indices. - Args: limit: Fixed tendon position limits ``[lower, upper]`` [m]. Shape is (num_instances, num_fixed_tendons) with dtype wp.vec2f. A torch tensor has a trailing dimension of 2. fixed_tendon_mask: Fixed tendon mask. If None, then all fixed tendons are used. env_mask: Environment mask. If None, then all the instances are updated. Shape is (num_instances,). """ - # Resolve masks. - env_ids = self._resolve_env_ids(env_mask=env_mask) - fixed_tendon_ids = self._resolve_fixed_tendon_ids(fixed_tendon_mask=fixed_tendon_mask) - # Set full data to True to ensure the right code path is taken inside the kernel. - self.set_fixed_tendon_position_limit_index( - limit=limit, fixed_tendon_ids=fixed_tendon_ids, env_ids=env_ids, full_data=True - ) + if isinstance(limit, float): + raise ValueError("Fixed tendon position limits must be a tensor or array, not a float.") + env_mask = self._resolve_mask(env_mask, self._ALL_ENV_MASK) + fixed_tendon_mask = self._resolve_mask(fixed_tendon_mask, self._ALL_FIXED_TENDON_MASK) + self.assert_shape_and_dtype_mask(limit, (env_mask, fixed_tendon_mask), wp.vec2f, "limit") + write_2d_with_mask(limit, env_mask, fixed_tendon_mask, self.data._fixed_tendon_pos_limits.view(wp.vec2f)) def set_fixed_tendon_rest_length_index( self, @@ -2959,22 +2934,15 @@ def set_fixed_tendon_rest_length_mask( .. note:: This method expects full data. - .. tip:: - For maximum performance we recommend using the index method. This is because in PhysX, the tensor API - is only supporting indexing, hence masks need to be converted to indices. - Args: rest_length: Fixed tendon rest length. Shape is (num_instances, num_fixed_tendons). fixed_tendon_mask: Fixed tendon mask. If None, then all fixed tendons are used. env_mask: Environment mask. If None, then all the instances are updated. Shape is (num_instances,). """ - # Resolve masks. - env_ids = self._resolve_env_ids(env_mask=env_mask) - fixed_tendon_ids = self._resolve_fixed_tendon_ids(fixed_tendon_mask=fixed_tendon_mask) - # Set full data to True to ensure the right code path is taken inside the kernel. - self.set_fixed_tendon_rest_length_index( - rest_length=rest_length, fixed_tendon_ids=fixed_tendon_ids, env_ids=env_ids, full_data=True - ) + env_mask = self._resolve_mask(env_mask, self._ALL_ENV_MASK) + fixed_tendon_mask = self._resolve_mask(fixed_tendon_mask, self._ALL_FIXED_TENDON_MASK) + self.assert_shape_and_dtype_mask(rest_length, (env_mask, fixed_tendon_mask), wp.float32, "rest_length") + write_2d_with_mask(rest_length, env_mask, fixed_tendon_mask, self.data._fixed_tendon_rest_length) def set_fixed_tendon_position_target_index( self, @@ -3096,12 +3064,20 @@ def set_fixed_tendon_position_target_mask( fixed_tendon_mask: Fixed tendon mask. If None, then all the fixed tendons are commanded. env_mask: Environment mask. If None, then all the instances are commanded. """ - self.set_fixed_tendon_position_target_index( - target=target, - fixed_tendon_ids=self._resolve_fixed_tendon_ids(fixed_tendon_mask=fixed_tendon_mask), - env_ids=self._resolve_env_ids(env_mask=env_mask), - full_data=True, + self.assert_shape_and_dtype(target, (self.num_instances, self.num_fixed_tendons), wp.float32, "target") + env_mask = self._resolve_mask(env_mask, self._ALL_ENV_MASK) + fixed_tendon_mask = self._resolve_mask(fixed_tendon_mask, self._ALL_FIXED_TENDON_MASK) + # buffer only; ``write_data_to_sim`` pushes the offset with the other tendon properties + offset = self.data._fixed_tendon_offset_scratch + wp.launch( + warp_kernels.subtract_2d, + dim=(self.num_instances, self.num_fixed_tendons), + inputs=[self.data._fixed_tendon_rest_length, target], + outputs=[offset], + device=self.device, ) + write_2d_with_mask(offset, env_mask, fixed_tendon_mask, self.data._fixed_tendon_offset) + self._fixed_tendon_target_dirty = True def set_fixed_tendon_offset_mask( self, @@ -3119,22 +3095,15 @@ def set_fixed_tendon_offset_mask( .. note:: This method expects full data. - .. tip:: - For maximum performance we recommend using the index method. This is because in PhysX, the tensor API - is only supporting indexing, hence masks need to be converted to indices. - Args: offset: Fixed tendon offset. Shape is (num_instances, num_fixed_tendons). fixed_tendon_mask: Fixed tendon mask. If None, then all fixed tendons are used. env_mask: Environment mask. If None, then all the instances are updated. Shape is (num_instances,). """ - # Resolve masks. - env_ids = self._resolve_env_ids(env_mask=env_mask) - fixed_tendon_ids = self._resolve_fixed_tendon_ids(fixed_tendon_mask=fixed_tendon_mask) - # Set full data to True to ensure the right code path is taken inside the kernel. - self.set_fixed_tendon_offset_index( - offset=offset, fixed_tendon_ids=fixed_tendon_ids, env_ids=env_ids, full_data=True - ) + env_mask = self._resolve_mask(env_mask, self._ALL_ENV_MASK) + fixed_tendon_mask = self._resolve_mask(fixed_tendon_mask, self._ALL_FIXED_TENDON_MASK) + self.assert_shape_and_dtype_mask(offset, (env_mask, fixed_tendon_mask), wp.float32, "offset") + write_2d_with_mask(offset, env_mask, fixed_tendon_mask, self.data._fixed_tendon_offset) def write_fixed_tendon_properties_to_sim_index( self, @@ -3262,22 +3231,15 @@ def set_spatial_tendon_stiffness_mask( .. note:: This method expects full data. - .. tip:: - For maximum performance we recommend using the index method. This is because in PhysX, the tensor API - is only supporting indexing, hence masks need to be converted to indices. - Args: stiffness: Spatial tendon stiffness. Shape is (num_instances, num_spatial_tendons). spatial_tendon_mask: Spatial tendon mask. If None, then all spatial tendons are used. env_mask: Environment mask. If None, then all the instances are updated. Shape is (num_instances,). """ - # Resolve masks. - env_ids = self._resolve_env_ids(env_mask=env_mask) - spatial_tendon_ids = self._resolve_spatial_tendon_ids(spatial_tendon_mask=spatial_tendon_mask) - # Set full data to True to ensure the right code path is taken inside the kernel. - self.set_spatial_tendon_stiffness_index( - stiffness=stiffness, spatial_tendon_ids=spatial_tendon_ids, env_ids=env_ids, full_data=True - ) + env_mask = self._resolve_mask(env_mask, self._ALL_ENV_MASK) + spatial_tendon_mask = self._resolve_mask(spatial_tendon_mask, self._ALL_SPATIAL_TENDON_MASK) + self.assert_shape_and_dtype_mask(stiffness, (env_mask, spatial_tendon_mask), wp.float32, "stiffness") + write_2d_with_mask(stiffness, env_mask, spatial_tendon_mask, self.data._spatial_tendon_stiffness) def set_spatial_tendon_damping_index( self, @@ -3340,22 +3302,15 @@ def set_spatial_tendon_damping_mask( .. note:: This method expects full data. - .. tip:: - For maximum performance we recommend using the index method. This is because in PhysX, the tensor API - is only supporting indexing, hence masks need to be converted to indices. - Args: damping: Spatial tendon damping. Shape is (num_instances, num_spatial_tendons). spatial_tendon_mask: Spatial tendon mask. If None, then all spatial tendons are used. env_mask: Environment mask. If None, then all the instances are updated. Shape is (num_instances,). """ - # Resolve masks. - env_ids = self._resolve_env_ids(env_mask=env_mask) - spatial_tendon_ids = self._resolve_spatial_tendon_ids(spatial_tendon_mask=spatial_tendon_mask) - # Set full data to True to ensure the right code path is taken inside the kernel. - self.set_spatial_tendon_damping_index( - damping=damping, spatial_tendon_ids=spatial_tendon_ids, env_ids=env_ids, full_data=True - ) + env_mask = self._resolve_mask(env_mask, self._ALL_ENV_MASK) + spatial_tendon_mask = self._resolve_mask(spatial_tendon_mask, self._ALL_SPATIAL_TENDON_MASK) + self.assert_shape_and_dtype_mask(damping, (env_mask, spatial_tendon_mask), wp.float32, "damping") + write_2d_with_mask(damping, env_mask, spatial_tendon_mask, self.data._spatial_tendon_damping) def set_spatial_tendon_limit_stiffness_index( self, @@ -3427,22 +3382,17 @@ def set_spatial_tendon_limit_stiffness_mask( .. note:: This method expects full data. - .. tip:: - For maximum performance we recommend using the index method. This is because in PhysX, the tensor API - is only supporting indexing, hence masks need to be converted to indices. - Args: limit_stiffness: Spatial tendon limit stiffness. Shape is (num_instances, num_spatial_tendons). spatial_tendon_mask: Spatial tendon mask. If None, then all spatial tendons are used. env_mask: Environment mask. If None, then all the instances are updated. Shape is (num_instances,). """ - # Resolve masks. - env_ids = self._resolve_env_ids(env_mask=env_mask) - spatial_tendon_ids = self._resolve_spatial_tendon_ids(spatial_tendon_mask=spatial_tendon_mask) - # Set full data to True to ensure the right code path is taken inside the kernel. - self.set_spatial_tendon_limit_stiffness_index( - limit_stiffness=limit_stiffness, spatial_tendon_ids=spatial_tendon_ids, env_ids=env_ids, full_data=True + env_mask = self._resolve_mask(env_mask, self._ALL_ENV_MASK) + spatial_tendon_mask = self._resolve_mask(spatial_tendon_mask, self._ALL_SPATIAL_TENDON_MASK) + self.assert_shape_and_dtype_mask( + limit_stiffness, (env_mask, spatial_tendon_mask), wp.float32, "limit_stiffness" ) + write_2d_with_mask(limit_stiffness, env_mask, spatial_tendon_mask, self.data._spatial_tendon_limit_stiffness) def set_spatial_tendon_offset_index( self, @@ -3505,22 +3455,15 @@ def set_spatial_tendon_offset_mask( .. note:: This method expects full data. - .. tip:: - For maximum performance we recommend using the index method. This is because in PhysX, the tensor API - is only supporting indexing, hence masks need to be converted to indices. - Args: offset: Spatial tendon offset. Shape is (num_instances, num_spatial_tendons). spatial_tendon_mask: Spatial tendon mask. If None, then all spatial tendons are used. env_mask: Environment mask. If None, then all the instances are updated. Shape is (num_instances,). """ - # Resolve masks. - env_ids = self._resolve_env_ids(env_mask=env_mask) - spatial_tendon_ids = self._resolve_spatial_tendon_ids(spatial_tendon_mask=spatial_tendon_mask) - # Set full data to True to ensure the right code path is taken inside the kernel. - self.set_spatial_tendon_offset_index( - offset=offset, spatial_tendon_ids=spatial_tendon_ids, env_ids=env_ids, full_data=True - ) + env_mask = self._resolve_mask(env_mask, self._ALL_ENV_MASK) + spatial_tendon_mask = self._resolve_mask(spatial_tendon_mask, self._ALL_SPATIAL_TENDON_MASK) + self.assert_shape_and_dtype_mask(offset, (env_mask, spatial_tendon_mask), wp.float32, "offset") + write_2d_with_mask(offset, env_mask, spatial_tendon_mask, self.data._spatial_tendon_offset) def write_spatial_tendon_properties_to_sim_index( self, @@ -3683,6 +3626,9 @@ def _create_buffers(self): self._ALL_SPATIAL_TENDON_INDICES = wp.array( np.arange(self.num_spatial_tendons, dtype=np.int32), device=self.device ) + self._ALL_ENV_MASK = wp.ones(self.num_instances, dtype=wp.bool, device=self.device) + self._ALL_FIXED_TENDON_MASK = wp.ones(self.num_fixed_tendons, dtype=wp.bool, device=self.device) + self._ALL_SPATIAL_TENDON_MASK = wp.ones(self.num_spatial_tendons, dtype=wp.bool, device=self.device) self._sim_env_ids = wp.empty(self.num_instances, dtype=wp.int32, device=self.device) self._sim_env_ids_views: dict[int, wp.array] = {} self._cpu_env_ids_all = wp.zeros(self.num_instances, dtype=wp.int32, device="cpu", pinned=True) @@ -4211,6 +4157,18 @@ def _resolve_spatial_tendon_ids( """ return resolve_ids(ids=spatial_tendon_ids, mask=spatial_tendon_mask, all_ids=self._ALL_SPATIAL_TENDON_INDICES) + def _resolve_mask(self, mask: wp.array | torch.Tensor | None, all_mask: wp.array) -> wp.array: + """Resolve a mask to a boolean warp array on the device. + + Args: + mask: Boolean mask. If None, then :paramref:`all_mask` is used. + all_mask: All-true mask of the same axis. + + Returns: + A boolean warp array on the device. + """ + return resolve_1d_mask(mask=mask, all_mask=all_mask) + """ Deprecated methods. """ diff --git a/source/isaaclab_physx/isaaclab_physx/assets/articulation/articulation_data.py b/source/isaaclab_physx/isaaclab_physx/assets/articulation/articulation_data.py index 78325c5c5f75..5eafbba2378e 100644 --- a/source/isaaclab_physx/isaaclab_physx/assets/articulation/articulation_data.py +++ b/source/isaaclab_physx/isaaclab_physx/assets/articulation/articulation_data.py @@ -1769,6 +1769,8 @@ def _create_buffers(self) -> None: self._fixed_tendon_rest_length = wp.clone(self._root_view.get_fixed_tendon_rest_lengths(), device=device) self._fixed_tendon_offset = wp.clone(self._root_view.get_fixed_tendon_offsets(), device=device) self._fixed_tendon_pos_limits = wp.clone(self._root_view.get_fixed_tendon_limits(), device=device) + # scratch for the masked target setter: rest_length - target before the masked write + self._fixed_tendon_offset_scratch = wp.zeros_like(self._fixed_tendon_offset) else: self._fixed_tendon_stiffness = None self._fixed_tendon_damping = None @@ -1776,6 +1778,7 @@ def _create_buffers(self) -> None: self._fixed_tendon_rest_length = None self._fixed_tendon_offset = None self._fixed_tendon_pos_limits = None + self._fixed_tendon_offset_scratch = None # -- Spatial tendon properties if self._num_spatial_tendons > 0: self._spatial_tendon_stiffness = wp.clone(self._root_view.get_spatial_tendon_stiffnesses(), device=device)