Repository navigation
Conversation
|
| elif hasattr(entity, "num_bodies"): | ||
| self.body_ids_wp = wp.array(list(range(entity.num_bodies)), dtype=wp.int32, device=scene.device) | ||
| if self.body_ids != slice(None) or hasattr(entity, "num_bodies"): | ||
| num_bodies = len(entity.body_names) |
There was a problem hiding this comment.
| joint_ids_list = ( | ||
| list(range(entity.num_joints)[self.joint_ids]) | ||
| if isinstance(self.joint_ids, slice) | ||
| else [index % entity.num_joints for index in self.joint_ids] |
There was a problem hiding this comment.
Invalid IDs select other joints
On a three-joint articulation, an out-of-range joint ID of 3 now becomes 0 through modulo. The Warp selector and joint mask then target joint 0 instead of rejecting the invalid selection. The body-ID conversion below has the same wrapping problem, so invalid configurations can silently target the wrong body too.
There was a problem hiding this comment.
Isaac Lab Review Bot
Reviewed the new resolved-selector cache design across SceneEntityCfg, migrated Torch consumers, serialization/copy behavior, and the experimental Warp frontend. No candidate findings were supplied, and the patch consistently preserves host selectors while adding cached device selectors.
- Design and architecture: The parallel host/device selector model is coherent: existing
*_idsvalues remain suitable for scalar access, names, and metadata, while*_ids_torchserves vector tensor and writer paths. Full slices retain view semantics, and partial or negative selections are materialized consistently. - API: The four
*_ids_torchaccessors are additive and documented, unresolved calls retain host-selector fallback, and runtime caches are excluded from configuration serialization. Copy, replacement, re-resolution, and experimental stable-to-Warp conversion paths were checked for compatibility. - Implementation: The resolver clears stale caches before validation, rebuilds selectors on the scene device, expands partial slices, normalizes negative indices, and preserves ordering, duplicates, and empty selections. Migrated core/task consumers, descriptors, the IK tutorial, and Warp construction follow the intended host-versus-device boundary; the remaining tradeoff is that cached tensors rely on the documented read-only lifecycle and explicit re-resolution after selector mutation.
No blocking issues. No inline issue met the actionable-evidence threshold; the assessment above records the review feedback.
Automated review; human maintainers own approval decisions.
|
Closing in favor of #8087 |
# Description Finalize resolved scene-entity selections to device tensors, following Newton's build-then-finalize model. Manager terms index with the existing `*_ids` fields and no longer upload indices or synchronize CUDA on every call. No second field or helper is needed. Alternative A to #8088, which adds separate `*_ids_torch` fields. Related: #8039, #8089. ## Design - **Build:** `SceneEntityCfg.resolve(scene)` is unchanged. It fills `joint_ids`, `body_ids`, `fixed_tendon_ids`, and `object_collection_ids` with host lists. Class-based terms can read these lists in `__init__`. - **Finalize:** once every term is constructed, `ManagerBase` calls the new `SceneEntityCfg.finalize(device)` on the configurations it resolved. Each list becomes a `torch.long` tensor on the simulation device, shared by the terms that use it, and slices stay slices. Finalization is one-way, and calling it again does nothing. Configurations resolved outside managers, such as by action or command terms, are left unchanged. - **Consumers:** term calls use `data[:, cfg.joint_ids]` and pass `cfg.joint_ids` to asset write methods as before. Tensors compare unequal to `slice(None)`, so the existing `ids == slice(None)` checks continue to work. - **No per-step host reads:** a scalar selection such as `data[:, cfg.body_ids[0]]` would read a CUDA tensor back to the host, so these reads become device gathers: `data[:, cfg.body_ids][:, 0]`. Event terms that previously rebuilt index tensors on each call now use the finalized tensors directly; every backend accepts int64 index tensors. - **Scope:** 13 files, all in `isaaclab` and `isaaclab_tasks`. Backend asset APIs, `isaaclab_experimental` (whose managers are a separate implementation), and serialization helpers are unchanged. ### Why tensors rather than `ProxyArray` or a wrapper | Design | Call site | `joint_pos` (µs/call) | `joint_pos_limits` (µs/call) | Syncs/call | | --- | --- | ---: | ---: | ---: | | develop (host lists) | `data[:, cfg.joint_ids]` | 383 † | 1470–1566 † | 1 / 4 | | Previous revision: `IndexSequence` wrapper | `data[:, cfg.joint_ids]` | 8.45–8.50 | 64.4–65.7 | 0 | | #8088: separate `*_ids_torch` | `data[:, cfg.joint_ids_torch]` | 5.34–5.99 | 47.95–48.83 | 0 | | **This PR: finalized tensors** | `data[:, cfg.joint_ids]` | **5.32–6.38** | **48.00–49.19** | 0 | Finalized tensors match #8088 with a single field. A finalized `ProxyArray` was also prototyped. Indexing with it directly cost about 2 µs more per index (7.7 µs vs. 5.3–6.1 µs), because it dispatches through `ProxyArray`'s deprecated Torch bridge, and asset write methods reject it. It would therefore need an explicit accessor at every call site. No consumer used its Warp view. Benchmark: RTX PRO 6000 Blackwell, PyTorch 2.12.0+cu130. Real `joint_pos` observation and `joint_pos_limits` reward, `(4096, 32)` CUDA data, joints `[15, 2, 29, 5, 22, 11, 30, 0]`. Each fresh process ran 200 warmup calls, then five blocks of 2,000 calls. Figures are median block times from two or more processes per design, run in alternating order. Synchronizations were counted with PyTorch's sync-debug mode. † The GPU was fully utilized by unrelated processes during these runs, which inflates develop's synchronizing path. On an idle GPU, the same benchmark previously measured develop at 13.05–13.11 µs. The synchronization-free designs are CPU-bound and are comparable with one another. ## Type of change - New feature - Breaking change: term calls receive finalized `torch.long` tensors instead of host lists. Migration: - Replace per-step scalar reads such as `data[:, cfg.body_ids[0]]` with `data[:, cfg.body_ids][:, 0]`, or read host values in the term's `__init__`. - Replace `torch.tensor(cfg.body_ids)` with `cfg.body_ids`; the finalized selection is already a device tensor. - Replace `isinstance(ids, list)` checks with `isinstance(ids, slice)`. - Class terms can still read host lists in `__init__`. - Documentation update ## Validation - 206 focused tests passed: managers (event, observation, reward, termination, base, scene selection), dict, configclass, wrench composer, gravity observations, and Lift configuration. - New tests cover: - finalization of ordering, slices, empty selections, and copies; - that class terms see host lists while term calls see device tensors, whether the manager is created while the simulation is playing or deferred until physics is ready; - a real `joint_pos` consumer and a device gather under CUDA sync-debug `error` mode; - external-force sizing for a finalized body subset. - All six new tests fail when `finalize` is disabled. - Newton/MJWarp runtime smoke tests passed with 64 environments, seed 42, 20 warmup and 100 measured steps, and no renderer, for `Isaac-Lift-KukaAllegro`, `Isaac-Velocity-Flat-AnymalD`, and `Isaac-Open-Drawer-Franka`. The last exercises the changed drawer-joint gather. No implicit `ProxyArray` deprecation warnings were emitted. - `uv run --frozen isaaclab -f` passed, including changelog checks. - Not run: the full documentation build, PhysX/OVPhysX runtime, and `test_recorder_manager_integration` (requires full Isaac Sim). Reproduce the smoke test: ```bash uv run --frozen isaaclab benchmark runtime \ --task Isaac-Lift-KukaAllegro --num_envs 64 --num_steps 100 \ --warmup_steps 20 --seed 42 --device cuda:0 --visualizer none \ --output_path /tmp/scene-selector-smoke physics=newton_mjwarp ``` ## Known limitations - Serializing a finalized configuration emits tensors for its selections, following the existing `class_to_dict` tensor handling. No code in this repository serializes term configurations after finalization. - Finalized tensors are read-only by convention. Calling `resolve()` after `finalize()` is unsupported. - A few class terms copy selection fields in `__init__` and therefore keep the host list or their own tensor. Two of these, NIST `reset_end_effector_around_asset` and PhysX `randomize_rigid_body_material`, keep host lists: the first can adopt the finalized tensor in a follow-up, while the second iterates backend body IDs on the CPU and should stay on the host. ## Release backport - [x] <!-- backport-active-release --> Backport this pull request to the active release branch after it merges into `develop` ## Checklist - [x] I have read and understood the contribution guidelines. - [x] I have run the pre-commit checks with `uv run --frozen isaaclab -f`. - [x] I have made corresponding changes to the documentation. - [x] I have added tests that prove the behavior and checked them against the change disabled. - [x] I have added a changelog fragment for every touched source package. - [x] My name already exists in `CONTRIBUTORS.md`.
# Description Finalize resolved scene-entity selections to device tensors, following Newton's build-then-finalize model. Manager terms index with the existing `*_ids` fields and no longer upload indices or synchronize CUDA on every call. No second field or helper is needed. Alternative A to #8088, which adds separate `*_ids_torch` fields. Related: #8039, #8089. ## Design - **Build:** `SceneEntityCfg.resolve(scene)` is unchanged. It fills `joint_ids`, `body_ids`, `fixed_tendon_ids`, and `object_collection_ids` with host lists. Class-based terms can read these lists in `__init__`. - **Finalize:** once every term is constructed, `ManagerBase` calls the new `SceneEntityCfg.finalize(device)` on the configurations it resolved. Each list becomes a `torch.long` tensor on the simulation device, shared by the terms that use it, and slices stay slices. Finalization is one-way, and calling it again does nothing. Configurations resolved outside managers, such as by action or command terms, are left unchanged. - **Consumers:** term calls use `data[:, cfg.joint_ids]` and pass `cfg.joint_ids` to asset write methods as before. Tensors compare unequal to `slice(None)`, so the existing `ids == slice(None)` checks continue to work. - **No per-step host reads:** a scalar selection such as `data[:, cfg.body_ids[0]]` would read a CUDA tensor back to the host, so these reads become device gathers: `data[:, cfg.body_ids][:, 0]`. Event terms that previously rebuilt index tensors on each call now use the finalized tensors directly; every backend accepts int64 index tensors. - **Scope:** 13 files, all in `isaaclab` and `isaaclab_tasks`. Backend asset APIs, `isaaclab_experimental` (whose managers are a separate implementation), and serialization helpers are unchanged. ### Why tensors rather than `ProxyArray` or a wrapper | Design | Call site | `joint_pos` (µs/call) | `joint_pos_limits` (µs/call) | Syncs/call | | --- | --- | ---: | ---: | ---: | | develop (host lists) | `data[:, cfg.joint_ids]` | 383 † | 1470–1566 † | 1 / 4 | | Previous revision: `IndexSequence` wrapper | `data[:, cfg.joint_ids]` | 8.45–8.50 | 64.4–65.7 | 0 | | #8088: separate `*_ids_torch` | `data[:, cfg.joint_ids_torch]` | 5.34–5.99 | 47.95–48.83 | 0 | | **This PR: finalized tensors** | `data[:, cfg.joint_ids]` | **5.32–6.38** | **48.00–49.19** | 0 | Finalized tensors match #8088 with a single field. A finalized `ProxyArray` was also prototyped. Indexing with it directly cost about 2 µs more per index (7.7 µs vs. 5.3–6.1 µs), because it dispatches through `ProxyArray`'s deprecated Torch bridge, and asset write methods reject it. It would therefore need an explicit accessor at every call site. No consumer used its Warp view. Benchmark: RTX PRO 6000 Blackwell, PyTorch 2.12.0+cu130. Real `joint_pos` observation and `joint_pos_limits` reward, `(4096, 32)` CUDA data, joints `[15, 2, 29, 5, 22, 11, 30, 0]`. Each fresh process ran 200 warmup calls, then five blocks of 2,000 calls. Figures are median block times from two or more processes per design, run in alternating order. Synchronizations were counted with PyTorch's sync-debug mode. † The GPU was fully utilized by unrelated processes during these runs, which inflates develop's synchronizing path. On an idle GPU, the same benchmark previously measured develop at 13.05–13.11 µs. The synchronization-free designs are CPU-bound and are comparable with one another. ## Type of change - New feature - Breaking change: term calls receive finalized `torch.long` tensors instead of host lists. Migration: - Replace per-step scalar reads such as `data[:, cfg.body_ids[0]]` with `data[:, cfg.body_ids][:, 0]`, or read host values in the term's `__init__`. - Replace `torch.tensor(cfg.body_ids)` with `cfg.body_ids`; the finalized selection is already a device tensor. - Replace `isinstance(ids, list)` checks with `isinstance(ids, slice)`. - Class terms can still read host lists in `__init__`. - Documentation update ## Validation - 206 focused tests passed: managers (event, observation, reward, termination, base, scene selection), dict, configclass, wrench composer, gravity observations, and Lift configuration. - New tests cover: - finalization of ordering, slices, empty selections, and copies; - that class terms see host lists while term calls see device tensors, whether the manager is created while the simulation is playing or deferred until physics is ready; - a real `joint_pos` consumer and a device gather under CUDA sync-debug `error` mode; - external-force sizing for a finalized body subset. - All six new tests fail when `finalize` is disabled. - Newton/MJWarp runtime smoke tests passed with 64 environments, seed 42, 20 warmup and 100 measured steps, and no renderer, for `Isaac-Lift-KukaAllegro`, `Isaac-Velocity-Flat-AnymalD`, and `Isaac-Open-Drawer-Franka`. The last exercises the changed drawer-joint gather. No implicit `ProxyArray` deprecation warnings were emitted. - `uv run --frozen isaaclab -f` passed, including changelog checks. - Not run: the full documentation build, PhysX/OVPhysX runtime, and `test_recorder_manager_integration` (requires full Isaac Sim). Reproduce the smoke test: ```bash uv run --frozen isaaclab benchmark runtime \ --task Isaac-Lift-KukaAllegro --num_envs 64 --num_steps 100 \ --warmup_steps 20 --seed 42 --device cuda:0 --visualizer none \ --output_path /tmp/scene-selector-smoke physics=newton_mjwarp ``` ## Known limitations - Serializing a finalized configuration emits tensors for its selections, following the existing `class_to_dict` tensor handling. No code in this repository serializes term configurations after finalization. - Finalized tensors are read-only by convention. Calling `resolve()` after `finalize()` is unsupported. - A few class terms copy selection fields in `__init__` and therefore keep the host list or their own tensor. Two of these, NIST `reset_end_effector_around_asset` and PhysX `randomize_rigid_body_material`, keep host lists: the first can adopt the finalized tensor in a follow-up, while the second iterates backend body IDs on the CPU and should stay on the host. ## Release backport - [x] <!-- backport-active-release --> Backport this pull request to the active release branch after it merges into `develop` ## Checklist - [x] I have read and understood the contribution guidelines. - [x] I have run the pre-commit checks with `uv run --frozen isaaclab -f`. - [x] I have made corresponding changes to the documentation. - [x] I have added tests that prove the behavior and checked them against the change disabled. - [x] I have added a changelog fragment for every touched source package. - [x] My name already exists in `CONTRIBUTORS.md`. (cherry picked from commit 10fdf81)
Description
Finalize the separate-tensor design for resolved scene selections. This centralizes selector caching in
SceneEntityCfg, preserving Python lists/slices for scalar access, names, metadata, and existing custom consumers.Related: #8039. Design comparisons: #8087 (automatic wrapper), #8089 (native tensors). Merged
developat0cdc1e810; this PR uses the existingindex_fill_implementation.Implementation
joint_ids_torch,body_ids_torch,fixed_tendon_ids_torch, andobject_collection_ids_torchonce on the scene device. They expose ordinarytorch.longtensors, with no dispatch wrapper or global cache registry.slice(None)as a slice. Expand partial/reverse slices and normalize negative device indices for native indexing and writer APIs; preserve the original host selections, ordering, duplicates, and empty selections.copy/replaceclear caches;deepcopyretains independent tensors. Mutating a selection requires re-resolution; there is no per-step mutation tracking.Performance
RTX PRO 6000 Blackwell, PyTorch 2.12.0+cu130. Real
joint_posMDP function,(4096, 32)CUDA input, eight shuffled selected joints; 200 warmup calls, five blocks of 2,000 calls, synchronized at block boundaries.e140fa930The final 50-call profile contains no index uploads or per-call stream synchronizations; the profiler's final device synchronization is excluded. Earlier comparisons are retained as historical measurements, not a new end-to-end benchmark. The native-tensor prototype offers similar vector indexing but costs more for host consumers and scalar selection; details are in #8089. No end-to-end speedup is claimed from the smoke runs.
Validation
index_select,index_fill_, and host serialization under synchronization-error mode.uv run --frozen isaaclab -fpassed, including changelog checks.uv run --frozen --isolated --extra dev -- make -C docs current-docs 'SPHINXOPTS=-j 4'.Reproduce either smoke run:
uv run --frozen isaaclab benchmark runtime \ --task Isaac-Lift-KukaAllegro --num_envs 64 --num_steps 100 \ --warmup_steps 20 --seed 42 --device cuda:0 --visualizer none \ --output_path /tmp/scene-selector-smoke physics=newton_mjwarp # Also run with --task Isaac-Velocity-Flat-AnymalD.Type of change
Release backport
developChecklist
uv run --frozen isaaclab -f.CONTRIBUTORS.md.