Skip to content

Enable OVPhysX rigid-object shape-material tests via OvPhysxView - #6240

Merged
AntoineRichard merged 2 commits into
isaac-sim:developfrom
AntoineRichard:antoiner/feat/ovphysx_rigidobject_materials
Jul 8, 2026
Merged

AntoineRichard merged 2 commits into
isaac-sim:developfrom
AntoineRichard:antoiner/feat/ovphysx_rigidobject_materials

Conversation

@AntoineRichard

Copy link
Copy Markdown
Collaborator

Stacked on #6226 (OVPhysX RigidObject → OvPhysxView), which is stacked on #6224 (OvPhysxView). Review/merge those first — the diff here collapses to a single commit once they land. Sibling of #6239 (the articulation equivalent).

What

The ovphysx wheel now exposes per-collision-shape rigid-body material as the RIGID_BODY_SHAPE_FRICTION_AND_RESTITUTION tensor type (shape [N, S, 3] = static friction, dynamic friction, restitution). This closes the gap that kept five rigid-object material tests xfailed — they were empty NotImplementedError stubs written against the PhysX-only root_view.get/set_material_properties() / max_shapes view API.

  • Add the tensor_types alias RIGID_BODY_SHAPE_FRICTION_AND_RESTITUTION, guarded with try/except AttributeError so the module stays import-safe against older wheels.
  • Implement, mirroring the PhysX backend but reading/writing the material through OvPhysxView.get_attribute / set_attribute:
    • test_rigid_body_set_material_properties and test_set_material_properties_via_view — set/get round-trip.
    • test_rigid_body_no_friction, test_rigid_body_with_static_friction, test_rigid_body_with_restitution — physical-behavior tests.
  • Ground planes use the solver-common RigidBodyMaterialBaseCfg; masses come from data.body_mass. The no-friction test settles the cube and uses zero restitution so the resting contact is clean before asserting the sliding velocity is preserved.

Verification

OVPhysX runs the PhysX solver, so the physical tests use the PhysX reference tolerances. All five pass on both cpu and cuda:0 for num_cubes 1 and 2. Full test_rigid_object.py is green (53 passed on cpu, no regressions).

@github-actions github-actions Bot added documentation Improvements or additions to documentation isaac-lab Related to Isaac Lab team labels Jun 23, 2026
@AntoineRichard
AntoineRichard force-pushed the antoiner/feat/ovphysx_rigidobject_materials branch from e7e3dcd to a58ea99 Compare June 23, 2026 10:02
@AntoineRichard
AntoineRichard marked this pull request as ready for review July 2, 2026 08:12
@greptile-apps

greptile-apps Bot commented Jul 2, 2026 •

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR introduces OvPhysxView, a string-keyed binding manager that wraps the per-tensor-type TensorBinding handles OVPhysX exposes, and uses it to migrate RigidObject / RigidObjectData off the raw dict[TensorType, TensorBinding] they previously owned. On top of the refactor it adds RIGID_BODY_SHAPE_FRICTION_AND_RESTITUTION to tensor_types and implements the five rigid-object material tests that were previously xfail stubs.

  • OvPhysxView (ovphysx_view.py): new 705-line class with get_attribute / read_into / set_attribute surface, device-mismatch and dtype-reinterpret guards, an object-identity read-cache for structured dst buffers, and comprehensive unit tests in test_ovphysx_view.py.
  • RigidObject / RigidObjectData: all binding.write() / binding.read() call sites replaced with set_attribute / read_into through the view; the CPU-only property staging path is preserved.
  • Five material tests promoted from xfail stubs to full implementations using the new RIGID_BODY_SHAPE_FRICTION_AND_RESTITUTION tensor type.

Confidence Score: 4/5

Safe to merge; the refactor is mechanical and all call-sites are accounted for, with five previously-stubbed tests now passing.

The OvPhysxView implementation is thorough and the migration of RigidObject / RigidObjectData is consistent across every call site. Two non-blocking concerns: the five material tests access TT.RIGID_BODY_SHAPE_FRICTION_AND_RESTITUTION without a skipif guard, so they would error rather than skip on a wheel older than 0.4.13; and the _read_views dict in OvPhysxView has no eviction path, which is fine for its intended persistent-buffer use but could surprise callers using temporary buffers in a loop.

The five new material tests in test_rigid_object.py and the _read_view caching logic in ovphysx_view.py are worth a second look before merging.

Important Files Changed

Filename Overview
source/isaaclab_ovphysx/isaaclab_ovphysx/sim/views/ovphysx_view.py New 705-line string-keyed binding manager wrapping OVPhysX TensorBindings; core dispatch logic is well-tested, but the _read_views cache has no eviction path for callers that use read_into with temporary buffers.
source/isaaclab_ovphysx/test/assets/test_rigid_object.py Five xfail stubs replaced with full implementations; missing skipif guard for RIGID_BODY_SHAPE_FRICTION_AND_RESTITUTION means tests fail with AttributeError (not skip) on wheels older than 0.4.13.
source/isaaclab_ovphysx/isaaclab_ovphysx/assets/rigid_object/rigid_object.py Migrates all binding.write() call sites from a raw dict[TensorType, TensorBinding] to OvPhysxView.set_attribute(); refactoring is mechanical and correct.
source/isaaclab_ovphysx/isaaclab_ovphysx/assets/rigid_object/rigid_object_data.py Replaces self._bindings[tt] dict access with self._view.binding_for(tt) / read_into(); CPU-only staging path correctly preserved with no behavioral change.
source/isaaclab_ovphysx/isaaclab_ovphysx/tensor_types.py Adds RIGID_BODY_SHAPE_FRICTION_AND_RESTITUTION constant behind a try/except AttributeError guard; correctly excluded from _CPU_ONLY_TYPES.
source/isaaclab_ovphysx/test/sim/test_ovphysx_view.py Comprehensive 587-line unit test suite for OvPhysxView using fake bindings; covers device policy, dtype safety, cache behaviour, key aliases, and error paths thoroughly.
source/isaaclab_ovphysx/isaaclab_ovphysx/sim/views/init.pyi Exports OvPhysxView from the stub — straightforward addition mirroring the new module.

Sequence Diagram

%%{init: {'theme': 'neutral'}}%%
sequenceDiagram
    participant RO as RigidObject
    participant ROD as RigidObjectData
    participant View as OvPhysxView
    participant PX as OVPhysX (PhysX C++)

    Note over RO,PX: Initialization (_initialize_impl)
    RO->>View: OvPhysxView(physx, pattern, device)
    RO->>View: binding_for(RIGID_BODY_POSE) [eager prefetch]
    View->>PX: create_tensor_binding(RIGID_BODY_POSE)
    PX-->>View: TensorBinding (cached)
    View-->>RO: binding

    Note over RO,PX: State write (set_attribute path)
    RO->>View: "set_attribute(RIGID_BODY_POSE, values, indices=)"
    View->>View: _resolve / _check_device / _as_binding_view
    View->>PX: binding.write(float32_view, indices)

    Note over ROD,PX: Data read (read_into path)
    ROD->>View: read_into(RIGID_BODY_POSE, dst)
    View->>View: _read_view(dst) reuses cached float32 reinterpret
    View->>PX: binding.read(float32_view)

    Note over ROD,PX: CPU-only property read (mass / inertia / CoM)
    ROD->>ROD: "staging <- _cpu_staging_buffers[tt]"
    ROD->>View: read_into(RIGID_BODY_MASS, staging[cpu])
    View->>PX: binding.read(staging)
    ROD->>ROD: wp.copy(dst[gpu], staging)

    Note over RO,PX: Material write (new path)
    RO->>View: set_attribute(RIGID_BODY_SHAPE_FRICTION_AND_RESTITUTION, [N,S,3])
    View->>PX: binding.write(float32 [N,S,3])
Loading
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
sequenceDiagram
    participant RO as RigidObject
    participant ROD as RigidObjectData
    participant View as OvPhysxView
    participant PX as OVPhysX (PhysX C++)

    Note over RO,PX: Initialization (_initialize_impl)
    RO->>View: OvPhysxView(physx, pattern, device)
    RO->>View: binding_for(RIGID_BODY_POSE) [eager prefetch]
    View->>PX: create_tensor_binding(RIGID_BODY_POSE)
    PX-->>View: TensorBinding (cached)
    View-->>RO: binding

    Note over RO,PX: State write (set_attribute path)
    RO->>View: "set_attribute(RIGID_BODY_POSE, values, indices=)"
    View->>View: _resolve / _check_device / _as_binding_view
    View->>PX: binding.write(float32_view, indices)

    Note over ROD,PX: Data read (read_into path)
    ROD->>View: read_into(RIGID_BODY_POSE, dst)
    View->>View: _read_view(dst) reuses cached float32 reinterpret
    View->>PX: binding.read(float32_view)

    Note over ROD,PX: CPU-only property read (mass / inertia / CoM)
    ROD->>ROD: "staging <- _cpu_staging_buffers[tt]"
    ROD->>View: read_into(RIGID_BODY_MASS, staging[cpu])
    View->>PX: binding.read(staging)
    ROD->>ROD: wp.copy(dst[gpu], staging)

    Note over RO,PX: Material write (new path)
    RO->>View: set_attribute(RIGID_BODY_SHAPE_FRICTION_AND_RESTITUTION, [N,S,3])
    View->>PX: binding.write(float32 [N,S,3])
Loading

Comments Outside Diff (1)

  1. source/isaaclab_ovphysx/isaaclab_ovphysx/sim/views/ovphysx_view.py, line 1197-1203 (link)

    P2 _read_views cache has no eviction path for temporary buffers

    The cache is keyed by id(dst). For the intended use-case (persistent per-attribute buffers allocated once in a data container) this is bounded and correct. However, if a caller passes many unique dst buffers to read_into in a loop—e.g. a scratch buffer freshly allocated each step—the dict grows monotonically and each entry also keeps the corresponding reinterpret view (and potentially the backing dst array) alive. The existing test test_get_attribute_no_out_does_not_grow_read_cache validates only the get_attribute no-out path; the analogous guarantee for read_into is unverified. A short docstring note (or a weakref-keyed cache) would make the constraint explicit and prevent silent regression if someone calls read_into with ephemeral buffers.

    Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Reviews (1): Last reviewed commit: "test(ovphysx): enable rigid-object shape..." | Re-trigger Greptile

Comment on lines +177 to +185
def _num_shapes(cube_object) -> int:
"""Per-body collision-shape count, from the material binding's ``[N, S, 3]`` shape."""
return cube_object.root_view.binding_for(TT.RIGID_BODY_SHAPE_FRICTION_AND_RESTITUTION).shape[1]


def _write_shape_material(cube_object, materials_nS3: torch.Tensor) -> None:
"""Write a full ``[N, S, 3]`` (static friction, dynamic friction, restitution) tensor via the view."""
cube_object.root_view.set_attribute(
TT.RIGID_BODY_SHAPE_FRICTION_AND_RESTITUTION, wp.from_torch(materials_nS3.contiguous(), dtype=wp.float32)

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.

P2 Unguarded access to RIGID_BODY_SHAPE_FRICTION_AND_RESTITUTION on older wheels

tensor_types.py silently omits RIGID_BODY_SHAPE_FRICTION_AND_RESTITUTION via try/except AttributeError: pass on wheels older than 0.4.13. The five material tests (helpers _num_shapes, _write_shape_material, _read_shape_material plus the test bodies) then dereference TT.RIGID_BODY_SHAPE_FRICTION_AND_RESTITUTION without checking whether it exists, so they'd fail with AttributeError rather than a clean skip on any wheel that satisfies the importorskip("ovphysx.types") guard but predates 0.4.13. Adding a module-level pytest.mark.skipif(not hasattr(TT, "RIGID_BODY_SHAPE_FRICTION_AND_RESTITUTION"), reason="Requires ovphysx>=0.4.13") (or a per-test skip mark) would make the suite fail gracefully in that scenario.

@AntoineRichard
AntoineRichard force-pushed the antoiner/feat/ovphysx_rigidobject_materials branch from a58ea99 to 829f197 Compare July 2, 2026 15:03
The ovphysx wheel now exposes per-shape rigid-body material as the
RIGID_BODY_SHAPE_FRICTION_AND_RESTITUTION tensor type, closing the gap that
kept five rigid-object material tests xfailed (they were empty stubs).

- Add the tensor_types alias RIGID_BODY_SHAPE_FRICTION_AND_RESTITUTION
  (guarded for older wheels).
- Implement test_rigid_body_set_material_properties,
  test_set_material_properties_via_view, test_rigid_body_no_friction,
  test_rigid_body_with_static_friction and test_rigid_body_with_restitution,
  mirroring the PhysX backend but reading/writing the material through
  OvPhysxView.get_attribute / set_attribute on the new tensor type. Ground
  planes use the solver-common RigidBodyMaterialBaseCfg; masses come from
  data.body_mass. The no-friction test settles the cube and zeroes restitution
  so the resting contact is clean before asserting the sliding velocity holds.

Verified all five on both cpu and cuda:0 (num_cubes 1 and 2).
@AntoineRichard
AntoineRichard force-pushed the antoiner/feat/ovphysx_rigidobject_materials branch from 829f197 to d25684e Compare July 7, 2026 14:27
AntoineRichard added a commit that referenced this pull request Jul 8, 2026
…6241)

> **Stacked on #6227** (OVPhysX `RigidObjectCollection` →
`OvPhysxView`), which is stacked on #6224 (`OvPhysxView`). Review/merge
those first. Sibling of #6239 (articulation) and #6240 (rigid object).

## What

The ovphysx wheel now exposes per-collision-shape rigid-body material as
the `RIGID_BODY_SHAPE_FRICTION_AND_RESTITUTION` tensor type. This closes
the gap that kept the collection's `test_set_material_properties`
`xfail`ed (it was an empty `NotImplementedError` stub written against
the PhysX-only `root_view.get/set_material_properties()` API).

- Add the `tensor_types` alias
`RIGID_BODY_SHAPE_FRICTION_AND_RESTITUTION`, guarded with `try/except
AttributeError` (shared with the sibling material PRs; documented
there).
- Implement `test_set_material_properties`, mirroring the PhysX backend
but reading/writing the material through `OvPhysxView.get_attribute` /
`set_attribute`. The collection's fused binding is body-major flat, so
data `[num_envs, num_cubes, 3]` is mapped to/from the view layout with
`reshape_data_to_view_3d` and its inverse.

## Verification

OVPhysX runs the PhysX solver. The material round-trip passes on both
`cpu` and `cuda:0` for `num_envs` 1/3 × `num_cubes` 1/2.

The changelog fragment is a `.skip` because the only user-facing
addition (the alias) is documented by the sibling material PRs; this PR
is test enablement.
@AntoineRichard
AntoineRichard merged commit a22f83e into isaac-sim:develop Jul 8, 2026
37 checks passed
AntoineRichard added a commit that referenced this pull request Jul 8, 2026
> **Stacked on #6239 (articulation material) and #6240 (rigid-object
material)** — this branch merges both so the MDP term has
`Articulation.root_view` + `RigidObject.root_view` (the #6225/#6226
migrations) and the material aliases. Review/merge those (and their
bases #6224/#6225/#6226) first; the diff here collapses to a single
commit once they land. (#6241/collection is **not** needed — this MDP
term targets `RigidObject`/`Articulation`, not collections.)

## What

`randomize_rigid_body_material` previously **no-op'd on the OVPhysX
backend** (the wheel lacked a material binding). The wheel now exposes
per-shape material as `*_SHAPE_FRICTION_AND_RESTITUTION`, so this
replaces the no-op with a real implementation.

OVPhysX runs the PhysX solver, so the new
`_RandomizeRigidBodyMaterialOvPhysx`:
- mirrors the **PhysX bucket approach** (PhysX's 64000 unique-material
limit applies): pre-samples `num_buckets` materials and randomly assigns
them to shapes;
- writes per-shape `(static_friction, dynamic_friction, restitution)`
through the asset's `OvPhysxView` (`set_attribute` on
`SHAPE_FRICTION_AND_RESTITUTION` for articulations,
`RIGID_BODY_SHAPE_FRICTION_AND_RESTITUTION` for rigid objects),
read-modify-writing the full `[N, S, 3]` buffer so non-selected envs are
preserved.

### Limitation
Randomizes **all shapes** only. Per-body selection
(`asset_cfg.body_ids`) raises `NotImplementedError` — the ovphysx wheel
exposes no per-body shape counts (unlike PhysX's
`link_physx_view.max_shapes` / Newton's `num_shapes_per_body`), so
body→shape ranges can't be indexed.

## Verification

New real-backend test (`test_randomize_rigid_body_material_mdp.py`)
drives the implementation against an OVPhysX `RigidObject`: it asserts
the written friction/restitution land within the sampled ranges, and
that a per-body selection fails loud. Passes on both `cpu` and `cuda:0`.
The PhysX and Newton paths are untouched.
matthewtrepte pushed a commit to matthewtrepte/IsaacLab that referenced this pull request Aug 4, 2026
…saac-sim#6241)

> **Stacked on isaac-sim#6227** (OVPhysX `RigidObjectCollection` →
`OvPhysxView`), which is stacked on isaac-sim#6224 (`OvPhysxView`). Review/merge
those first. Sibling of isaac-sim#6239 (articulation) and isaac-sim#6240 (rigid object).

## What

The ovphysx wheel now exposes per-collision-shape rigid-body material as
the `RIGID_BODY_SHAPE_FRICTION_AND_RESTITUTION` tensor type. This closes
the gap that kept the collection's `test_set_material_properties`
`xfail`ed (it was an empty `NotImplementedError` stub written against
the PhysX-only `root_view.get/set_material_properties()` API).

- Add the `tensor_types` alias
`RIGID_BODY_SHAPE_FRICTION_AND_RESTITUTION`, guarded with `try/except
AttributeError` (shared with the sibling material PRs; documented
there).
- Implement `test_set_material_properties`, mirroring the PhysX backend
but reading/writing the material through `OvPhysxView.get_attribute` /
`set_attribute`. The collection's fused binding is body-major flat, so
data `[num_envs, num_cubes, 3]` is mapped to/from the view layout with
`reshape_data_to_view_3d` and its inverse.

## Verification

OVPhysX runs the PhysX solver. The material round-trip passes on both
`cpu` and `cuda:0` for `num_envs` 1/3 × `num_cubes` 1/2.

The changelog fragment is a `.skip` because the only user-facing
addition (the alias) is documented by the sibling material PRs; this PR
is test enablement.
matthewtrepte pushed a commit to matthewtrepte/IsaacLab that referenced this pull request Aug 4, 2026
…ac-sim#6240)

> **Stacked on isaac-sim#6226** (OVPhysX `RigidObject` → `OvPhysxView`), which is
stacked on isaac-sim#6224 (`OvPhysxView`). Review/merge those first — the diff
here collapses to a single commit once they land. Sibling of isaac-sim#6239 (the
articulation equivalent).

## What

The ovphysx wheel now exposes per-collision-shape rigid-body material as
the `RIGID_BODY_SHAPE_FRICTION_AND_RESTITUTION` tensor type (shape `[N,
S, 3]` = static friction, dynamic friction, restitution). This closes
the gap that kept **five** rigid-object material tests `xfail`ed — they
were empty `NotImplementedError` stubs written against the PhysX-only
`root_view.get/set_material_properties()` / `max_shapes` view API.

- Add the `tensor_types` alias
`RIGID_BODY_SHAPE_FRICTION_AND_RESTITUTION`, guarded with `try/except
AttributeError` so the module stays import-safe against older wheels.
- Implement, mirroring the PhysX backend but reading/writing the
material through `OvPhysxView.get_attribute` / `set_attribute`:
- `test_rigid_body_set_material_properties` and
`test_set_material_properties_via_view` — set/get round-trip.
- `test_rigid_body_no_friction`, `test_rigid_body_with_static_friction`,
`test_rigid_body_with_restitution` — physical-behavior tests.
- Ground planes use the solver-common `RigidBodyMaterialBaseCfg`; masses
come from `data.body_mass`. The no-friction test settles the cube and
uses zero restitution so the resting contact is clean before asserting
the sliding velocity is preserved.

## Verification

OVPhysX runs the PhysX solver, so the physical tests use the PhysX
reference tolerances. All five pass on both `cpu` and `cuda:0` for
`num_cubes` 1 and 2. Full `test_rigid_object.py` is green (53 passed on
cpu, no regressions).
matthewtrepte pushed a commit to matthewtrepte/IsaacLab that referenced this pull request Aug 4, 2026
…#6243)

> **Stacked on isaac-sim#6239 (articulation material) and isaac-sim#6240 (rigid-object
material)** — this branch merges both so the MDP term has
`Articulation.root_view` + `RigidObject.root_view` (the isaac-sim#6225/isaac-sim#6226
migrations) and the material aliases. Review/merge those (and their
bases isaac-sim#6224/isaac-sim#6225/isaac-sim#6226) first; the diff here collapses to a single
commit once they land. (isaac-sim#6241/collection is **not** needed — this MDP
term targets `RigidObject`/`Articulation`, not collections.)

## What

`randomize_rigid_body_material` previously **no-op'd on the OVPhysX
backend** (the wheel lacked a material binding). The wheel now exposes
per-shape material as `*_SHAPE_FRICTION_AND_RESTITUTION`, so this
replaces the no-op with a real implementation.

OVPhysX runs the PhysX solver, so the new
`_RandomizeRigidBodyMaterialOvPhysx`:
- mirrors the **PhysX bucket approach** (PhysX's 64000 unique-material
limit applies): pre-samples `num_buckets` materials and randomly assigns
them to shapes;
- writes per-shape `(static_friction, dynamic_friction, restitution)`
through the asset's `OvPhysxView` (`set_attribute` on
`SHAPE_FRICTION_AND_RESTITUTION` for articulations,
`RIGID_BODY_SHAPE_FRICTION_AND_RESTITUTION` for rigid objects),
read-modify-writing the full `[N, S, 3]` buffer so non-selected envs are
preserved.

### Limitation
Randomizes **all shapes** only. Per-body selection
(`asset_cfg.body_ids`) raises `NotImplementedError` — the ovphysx wheel
exposes no per-body shape counts (unlike PhysX's
`link_physx_view.max_shapes` / Newton's `num_shapes_per_body`), so
body→shape ranges can't be indexed.

## Verification

New real-backend test (`test_randomize_rigid_body_material_mdp.py`)
drives the implementation against an OVPhysX `RigidObject`: it asserts
the written friction/restitution land within the sampled ranges, and
that a per-body selection fails loud. Passes on both `cpu` and `cuda:0`.
The PhysX and Newton paths are untouched.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation isaac-lab Related to Isaac Lab team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants