Skip to content

Fix PhysX rigid-object collection COM and inertia setters - #8131

Merged
StafaH merged 5 commits into
isaac-sim:developfrom
AntoineRichard:antoiner/fix-physx-collection-com-inertia
Oct 3, 2026
Merged

StafaH merged 5 commits into
isaac-sim:developfrom
AntoineRichard:antoiner/fix-physx-collection-com-inertia

Conversation

@AntoineRichard

Copy link
Copy Markdown
Collaborator

Description

isaaclab_physx.assets.RigidObjectCollection has three bugs in its inertial-property setters. #8009 and #8022 found the first one during the test audit (set_coms_index raises KeyError) and left it unfixed.

  1. set_coms_index raises KeyError: <class 'warp._src.types.transformf'>. The COM poses were reshaped into view order but passed to the PhysX tensor API as wp.transformf. Every other view write in this class already calls .view(wp.float32); this path now does too.
  2. A partial COM write zeroes the cached body_com_pose_b. body_com_pose_b is filled lazily from the view. set_coms_index wrote the selected cells into the buffer and then marked it fresh, so cells that had never been read back returned all-zero poses (including a zero quaternion) whenever the setter ran before the first read. An example is a COM randomization event applied to a subset of bodies at startup. The setter no longer marks the cache fresh, so the next read refreshes from the view, which is what RigidObject does.
  3. set_inertias_index fails with Failed to set rigid body inertias in backend. The (num_instances, num_bodies, 9) inertias were flattened with the 2D reshape helper. They now use reshape_data_to_view_3d(..., 9).

Only the PhysX collection is affected. RigidObject and Articulation handle these paths correctly, and the mocked interface tests accept either layout, which is why this was missed.

Testing

A new test, test_inertial_property_subset_writes_reach_selected_view_entries, writes COM and inertia to a non-sorted subset of (env, body) cells. It then checks both the PhysX view readback and the data buffers, on CPU and CUDA. Each bug turns it red on its own:

Code state Result
develop KeyError: transformf in set_coms_index
+ float32 COM view body_com_pose_b mismatch: 4/42 elements (zero quaternion w in unselected cells)
+ cache freshness fix Exception: Failed to set rigid body inertias in backend
+ inertia 3D reshape (this PR) passes
  • source/isaaclab_physx/test/assets/test_rigid_object_collection.py: 40 passed
  • source/isaaclab/test/assets/test_rigid_object_collection_iface.py: 107 passed
  • ./isaaclab.sh -f: all hooks pass

Type of change

  • Bug fix (non-breaking change which fixes an issue)

Release backport

  • Backport this pull request to the active release branch after it merges into develop

Checklist

Docker and GPU tests run on demand. Push the commits you want tested, then
comment run-ci on the pull request.

  • I have read and understood the contribution guidelines
  • I have run the pre-commit checks with uv run isaaclab --format
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have validated the changed behavior with focused coverage and applied the test-audit criteria to any test changes
  • I have added a changelog fragment under source/<pkg>/changelog.d/ for every touched package (do not edit CHANGELOG.rst or bump package versions — CI handles that)
  • I have added my name to the CONTRIBUTORS.md or my name already exists there

RigidObjectCollection.set_coms_index passed wp.transformf data to the
PhysX tensor API, which raises a KeyError. It also marked the lazily
filled body_com_pose_b cache as fresh after a partial write, so the
unselected entries read back as zeros when the cache had not been read
before. set_inertias_index flattened the (num_instances, num_bodies, 9)
inertias with the 2D reshape, which the backend rejects.

Pass the COM poses as float32, let the next read refresh the COM cache
from the view as RigidObject does, and reshape the inertias with the 3D
helper. A new test writes both properties to a non-sorted subset of
(env, body) cells and checks the PhysX view and the data buffers.
@AntoineRichard
AntoineRichard requested a review from a team September 29, 2026 07:49
@github-actions github-actions Bot added bug Something isn't working isaac-lab Related to Isaac Lab team labels Sep 29, 2026
@greptile-apps

greptile-apps Bot commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

[Medium risk] Fixes setter bugs in physics object collection properties.

The PR appears safe to merge; no new actionable issue was identified.

Summary

This PR fixes PhysX rigid-object collection COM writes, COM cache refresh, and inertia layout. It adds a subset-write test; the changes since the previous review clarify the changelog to include mask setters.

Reviews (2) · Last reviewed commit: "Mention the mask setters in the collecti..."

@isaaclab-review-bot isaaclab-review-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isaac Lab Review Bot

The PhysX-only COM and inertia setter fixes are scoped appropriately and covered by a focused regression test. One changed comment inaccurately describes the COM cache behavior and should be corrected before merge.

  • Design and architecture: The changes remain within the PhysX RigidObjectCollection backend and reuse its established reshape and float-view mechanisms without altering shared abstractions or other backend implementations.
  • API: The public signatures, selectors, shapes, dtypes, and mask wrappers for set_coms_index and set_inertias_index remain unchanged. Only PhysX payload layout and internal cache bookkeeping are corrected.
  • Compatibility and deprecation: Breaking changes: none identified. The patch repairs failing setter paths and prevents invalid cached COM values without removing or changing the supported public contract.
  • Implementation: The COM payload is converted to the float32 representation required by the PhysX tensor API, and inertia data now uses the three-dimensional reshape path with width 9. Omitting the premature COM timestamp update allows a previously stale source cache to refresh, while the selected cache cells are still updated by the write kernel.
  • Style consistency: The helper usage, layout comments, and changelog follow adjacent patterns. However, the new comment at line 1035 says the cached buffers are invalidated and the next read refreshes from the view, while the following call only invalidates dependent buffers; _body_com_pose_b itself is deliberately left at its existing timestamp. Reword the comment to describe that distinction accurately.
  • Test quality: The added regression test exercises non-sorted subset selectors and independently checks both PhysX view readback and public COM/inertia buffers on the repository-supported devices. It covers the three reported failures at the owning PhysX boundary without duplicating the existing link-pose subset-write test or mocked interface coverage.

Minor fixes needed. Posted 1 actionable finding inline.

Automated review; human maintainers own approval decisions.

)
# Invalidate the cached buffer
self.data._body_com_pose_b.timestamp = self.data._sim_timestamp
# Invalidate the cached buffers. The next read refreshes from the view, so that a partial write does not

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Suggestion · Style Consistency — Comment overstates COM cache invalidation

The comment says the cached buffers are invalidated and the next read refreshes from the view, but the call below only resets dependents; _body_com_pose_b itself is never invalidated. A refresh happens only when that buffer was already stale, and the described behavior comes from the removed timestamp assignment rather than this call. Reword to state that only dependents are reset and the source is deliberately left unmarked so a stale cache refreshes.

@AntoineRichard
AntoineRichard marked this pull request as ready for review September 30, 2026 13:48
StafaH added a commit that referenced this pull request Oct 3, 2026
# Description

The asset tests repeated expensive scenes, replayed the same contracts
on every backend, and carried custom scaffolding that made them hard to
follow. This PR consolidates them across PhysX, Newton, and OVPhysX into
lean, directly readable tests: cheap mocked contracts own the shared
API, and real-solver tests only cover what needs the real solver.

This is the combined PR for review and merge. The split PRs are not
being updated.

## Test organization

- **One file per asset family and backend.** Every test file pays a
fixed 4–7 s of imports (and a Kit launch for PhysX and in the CI core
job), so tests live in the file that already pays those costs:
unit-level checks sit beside the real-solver tests of the same asset,
rigid objects and rigid-object collections share one file and one scene,
and the shared contracts are two files. The asset tests went from 39
files to 19.
- **Shared contracts** (`source/isaaclab/test/assets/contract/`):
`test_articulation_contract.py` (including joint/body ordering) and
`test_rigid_object_contract.py` (rigid objects and collections, one
factory) run every backend on mocked views. `backends.py` owns the
Kit/kitless bootstrap, backend availability, and the manager doubles;
unavailable backends collect as skips. Newton runs on CPU only, since
its asset code has no CUDA-specific path; PhysX and OVPhysX keep CUDA
rows for their pinned-staging paths.
- **Writers** are one table-driven test per family covering warp and
torch inputs, index and mask selection, partial writes through the
public getters (unselected entries must be untouched), scalar writes,
and oversized-input rejection.
- **Ordering** is a small set of table-driven contracts (property
routing, body-state reads, duplicate selectors, stale staging, reset
rereads) using cyclic orderings, since a reversal is its own inverse and
cannot catch a swapped index map.
- **Backend tests** reuse module-scoped composite scenes, with two
environments so partial writes prove untouched state, and build each
scene on one device unless a Lab code path differs by device (OVPhysX
CPU stage serialization, CUDA-graph capture, CPU-only regressions).
Tests that own a simulation run before the composite scene; PhysX
asserts this so a misplaced test fails loudly.
- **Actuator equivalence** on PhysX and Newton runs on the local two-leg
and cartpole USD fixtures (in `isaaclab_newton/test/assets/data`)
instead of ANYmal.
- **WrenchComposer** keeps literal unit cases and one real PhysX
delivery test. Newton OSC controllers run closed-loop tracking and
gravity compensation on an island of the Newton articulation scene.

## What was removed or merged

- Custom framework: `capabilities.py`, `contract_boot.py`,
`mock_backends.py`, `public_surface.py`, and tests that only exercised
test scaffolding or a copied member inventory.
- Duplicate index/mask, root/body/joint/tendon, and rigid/collection
writer tests; per-helper `_make_*` variants; tests that rebuilt the same
mocked asset to check overlapping properties.
- PhysX: Franka and Shadow Hand scenes (local branching fixture covers
the Jacobian, gravity compensation, and fixed tendons), the 800-step IK
test, ~15 ANYmal actuator simulations reduced to 3, and gravity tests
folded into the shared scenes.
- OVPhysX: unit files merged into the asset files that already pay the
same imports; collection tests share the rigid-object scene;
heterogeneous clone tests share scenes; collision-filter and rejection
variants no longer doubled across devices; reset checks folded into the
wrench tests.
- Newton: rigid-object scenes run on CPU only (CUDA stays covered by the
actuator, CUDA-graph, and capture tests); authoring tests merged into
one table; shorter controller tracking loops; eight files merged into
three.
- A source-inspection WrenchComposer test, and redundant dtype/selector
matrices.
- `device_split` runner support (`tools/_device_split.py`, its test, the
pytest marker, and workflow mentions). No test declares it after the
OVPhysX device fix below.
- `DC_MOTOR_ACTUATORS` and `ActuatorStateResetBase` from
`isaaclab.test.utils.actuator_equivalence`, which no longer have
callers.

Every merged or removed contract has a keeper. Non-obvious merges were
checked with a one-line production mutation that turns the keeper red
(for example, writer kernels ignoring the mask, COM caches not
invalidated, Jacobian link shift skipped, collection COM/inertia fixes
reverted).

Coverage deliberately given up: the Lab-path DelayedPD reset check now
runs on Newton only (PhysX asserts reset forwards environment IDs);
armature-to-mass-matrix invalidation is no longer tested because PhysX
does not reflect armature writes in the mass matrix within one step;
PhysX composite-scene checks run on CUDA only (CPU staging stays covered
by the mocked contracts); OVPhysX collision isolation, mimic fingers,
and non-geometry heterogeneous articulation variants run on CUDA only.

## Runtime changes included in this PR

- Fix PhysX rigid-object-collection COM and inertia setters (stacked
from #8131).
- Allow OVPhysX CPU and CUDA simulations in one process: configure each
USD physics scene for the selected device instead of pinning the process
to its first device or using the sticky CPU mode. Lifecycle coverage
includes CPU → CUDA → CPU.

## Validation

Each file ran in its own process on an NVIDIA RTX PRO 6000 Blackwell
(warm Warp cache), comparing the head of this PR before the cleanup
(`ad9b10a37`) with the current one:

| Scope | Files | Time before → after |
|---|---:|---:|
| Shared contracts | 5 → 2 | 40 s → 17 s |
| Core WrenchComposer, actuators, terminations | 5 → 4 | 19 s → 15 s |
| Newton assets, actuators, controllers | 8 → 3 | 84 s → 42 s |
| PhysX assets | 9 → 5 | 85 s → 40 s |
| OVPhysX assets and physics manager | 12 → 5 | 100 s → 52 s |
| **Asset tests total** | **39 → 19** | **328 s → 166 s** |

Current results: 1,042 passed, 31 skipped, 10 strict xfails, 99
deselected (Newton CUDA contract rows). The OVPhysX sensor, view, and
randomization files are unchanged apart from dropping their device-split
fixtures (~134 s, not counted above). Fewer files also means fewer Kit
launches in CI, where each one costs more than locally.

Formatting, lint, LFS, and whitespace hooks pass. The changelog check
passes against upstream `develop`.

## Known failures pinned as strict xfails

- OVPhysX partial body writes overwrite unselected bodies of the
selected environment (rigid-object collection).
- Newton fixed-tendon mask setters accept data with extra environments.
- PhysX and OVPhysX rigid objects do not reject an enabled articulation
root.
- After a failed PhysX initialization, the first CPU simulation reads
zero poses for kinematic collection bodies. The previous file order
masked this.
- GPU PhysX applies mass and inertia writes to the mass matrix and
gravity compensation on the next step.

Other limitations exposed by the redesign and left out of scope: full
PhysX collection reset leaves wrench composers active; GPU link-frame
wrench delivery can use stale transforms after teleports; Newton
native-actuator reset is model-wide.

## Type of change

- Test-suite redesign and cleanup
- Bug fixes for PhysX collection setters and OVPhysX device lifecycle
- CI tooling cleanup (`device_split` removal)

## Checklist

- [x] Read the contribution guidelines
- [x] Run the formatting and lint checks
- [x] Apply the test-audit criteria and verify keepers with mutations
- [x] Validate the changed tests on CPU and CUDA where configured
- [x] Add changelog fragments for every touched package
- [x] Make corresponding documentation changes for the runtime behavior
- [x] Existing contributor listed in `CONTRIBUTORS.md`

---------

Co-authored-by: Mustafa Haiderbhai <[email protected]>
Co-authored-by: Mustafa H <[email protected]>
@StafaH

StafaH commented Oct 3, 2026

Copy link
Copy Markdown
Collaborator

run-ci

@isaaclab-bot isaaclab-bot Bot added ci:run-docker Trigger the on-demand Docker and GPU CI workflow and removed ci:run-docker Trigger the on-demand Docker and GPU CI workflow labels Oct 3, 2026
@StafaH
StafaH merged commit 10f8651 into isaac-sim:develop Oct 3, 2026
58 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working isaac-lab Related to Isaac Lab team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants