Skip to content

Enable OVPhysX rigid-object-collection material test via OvPhysxView - #6241

Merged
AntoineRichard merged 1 commit into
isaac-sim:developfrom
AntoineRichard:antoiner/feat/ovphysx_rigidobjectcollection_materials
Jul 8, 2026
Merged

AntoineRichard merged 1 commit into
isaac-sim:developfrom
AntoineRichard:antoiner/feat/ovphysx_rigidobjectcollection_materials

Conversation

@AntoineRichard

Copy link
Copy Markdown
Collaborator

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 xfailed (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.

@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_rigidobjectcollection_materials branch from 5412625 to f4475c7 Compare June 23, 2026 10:03
@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 promotes RigidObjectCollection's material test from an xfail stub to a live test by implementing the RIGID_BODY_SHAPE_FRICTION_AND_RESTITUTION tensor-type binding, and introduces OvPhysxView — a string-keyed manager over OVPhysX TensorBinding handles — replacing the raw dict[TensorType, TensorBinding] that RigidObjectCollection used internally.

  • OvPhysxView (new): wraps fused multi-prim bindings behind a string-keyed surface with explicit device/dtype/shape guards and a step-loop read-cache; adopted by both RigidObjectCollection and RigidObjectCollectionData in place of the previous raw dict + _binding_getter callback.
  • tensor_types.py: adds RIGID_BODY_SHAPE_FRICTION_AND_RESTITUTION under the existing try/except AttributeError guard for wheel-version safety.
  • test_set_material_properties: real round-trip test replaces the NotImplementedError stub; writes per-cube material via reshape_data_to_view_3d → set_attribute, reads back via get_attribute, and verifies the inverse reshape matches.

Confidence Score: 3/5

Safe to review but two correctness issues in the collection and its test need fixing before merge.

The OvPhysxView implementation and its unit tests are solid, and the tensor_types.py guard follows the established wheel-version pattern correctly. However, RigidObjectCollection._get_binding now dereferences self._root_view without a None check — before _initialize_impl runs the attribute is None, so any early call (e.g. from a registered callback) would raise AttributeError where the old dict-based path silently returned None. Separately, test_set_material_properties removed the xfail without adding a skipif for old wheels: when RIGID_BODY_SHAPE_FRICTION_AND_RESTITUTION is absent the try/except: pass guard leaves the name undefined, and the test crashes with AttributeError instead of being cleanly skipped.

rigid_object_collection.py (_get_binding None-dereference) and test_rigid_object_collection.py (missing skipif for old wheel).

Important Files Changed

Filename Overview
source/isaaclab_ovphysx/isaaclab_ovphysx/sim/views/ovphysx_view.py New 704-line string-keyed binding manager over OVPhysX TensorBindings; well-tested, clear device/dtype/shape guards, and a documented read-cache for step-loop efficiency.
source/isaaclab_ovphysx/isaaclab_ovphysx/assets/rigid_object_collection/rigid_object_collection.py Migrated from raw _bindings dict to OvPhysxView; _get_binding now dereferences _root_view without a None guard, crashing instead of returning None when called before initialization.
source/isaaclab_ovphysx/test/assets/test_rigid_object_collection.py Replaces xfail stub with a real material round-trip test; missing skip guard for old wheel versions lacking RIGID_BODY_SHAPE_FRICTION_AND_RESTITUTION will cause an AttributeError crash instead of a clean skip.
source/isaaclab_ovphysx/isaaclab_ovphysx/tensor_types.py Adds RIGID_BODY_SHAPE_FRICTION_AND_RESTITUTION alias guarded by try/except AttributeError, consistent with existing pattern for optional wheel attributes.
source/isaaclab_ovphysx/isaaclab_ovphysx/assets/rigid_object_collection/rigid_object_collection_data.py Migrated from _bindings dict + _binding_getter callback to a clean OvPhysxView; removes dead _binding_getter code cleanly.
source/isaaclab_ovphysx/test/sim/test_ovphysx_view.py Comprehensive unit tests for OvPhysxView covering name resolution, device policy, dtype guards, read-cache warmth, key aliases, and adversarial construction; well-structured and thorough.

Sequence Diagram

%%{init: {'theme': 'neutral'}}%%
sequenceDiagram
    participant Test as test_set_material_properties
    participant ROC as RigidObjectCollection
    participant View as OvPhysxView
    participant Binding as TensorBinding (fused)
    participant OVPx as OVPhysX wheel

    Test->>ROC: reshape_data_to_view_3d(materials[N,B,3], 3)
    ROC-->>Test: "view_materials[B*N, 3] (body-major)"

    Test->>View: set_attribute(RIGID_BODY_SHAPE_FRICTION_AND_RESTITUTION, view_materials)
    View->>View: _resolve(TensorType)
    View->>View: _as_binding_view — float32 reinterpret
    View->>Binding: binding.write(float32_view)
    Binding->>OVPx: flush to PhysX solver

    Test->>Test: sim.step() + collection.update()

    Test->>View: get_attribute(RIGID_BODY_SHAPE_FRICTION_AND_RESTITUTION)
    View->>Binding: binding.read(alloc_buf)
    Binding->>OVPx: read from PhysX solver
    View-->>Test: "wp.array[B*N, 3]"

    Test->>Test: reshape(B,N,3).transpose(0,1) to [N,B,3]
    Test->>Test: assert_close(materials_check, materials)
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 Test as test_set_material_properties
    participant ROC as RigidObjectCollection
    participant View as OvPhysxView
    participant Binding as TensorBinding (fused)
    participant OVPx as OVPhysX wheel

    Test->>ROC: reshape_data_to_view_3d(materials[N,B,3], 3)
    ROC-->>Test: "view_materials[B*N, 3] (body-major)"

    Test->>View: set_attribute(RIGID_BODY_SHAPE_FRICTION_AND_RESTITUTION, view_materials)
    View->>View: _resolve(TensorType)
    View->>View: _as_binding_view — float32 reinterpret
    View->>Binding: binding.write(float32_view)
    Binding->>OVPx: flush to PhysX solver

    Test->>Test: sim.step() + collection.update()

    Test->>View: get_attribute(RIGID_BODY_SHAPE_FRICTION_AND_RESTITUTION)
    View->>Binding: binding.read(alloc_buf)
    Binding->>OVPx: read from PhysX solver
    View-->>Test: "wp.array[B*N, 3]"

    Test->>Test: reshape(B,N,3).transpose(0,1) to [N,B,3]
    Test->>Test: assert_close(materials_check, materials)
Loading

Comments Outside Diff (1)

  1. source/isaaclab_ovphysx/isaaclab_ovphysx/assets/rigid_object_collection/rigid_object_collection.py, line 1206-1208 (link)

    P1 _get_binding crashes instead of returning None before initialization

    self._root_view is initialized to None and only set in _initialize_impl. Any call to _get_binding before initialize() runs (e.g. from a callback registered in __init__ via _register_callbacks) will crash with AttributeError: 'NoneType' object has no attribute 'try_binding_for'. The old implementation (self._bindings.get(tensor_type)) returned None safely on an empty dict — callers like _write_binding and apply_wrench explicitly guard on if binding is None: return. That contract is now silently broken.

    A minimal fix:

    def _get_binding(self, tensor_type: int):
        if self._root_view is None:
            return None
        return self._root_view.try_binding_for(tensor_type)

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

Comment on lines 759 to +794
def test_set_material_properties(num_envs, num_cubes, device):
"""Test getting and setting material properties of rigid object."""
raise NotImplementedError(_MATERIAL_GAP_REASON)
"""Test getting and setting per-shape material properties of a rigid object collection.

OVPhysX exposes per-collision-shape material as the
``rigid_body_shape_friction_and_restitution`` tensor binding, addressed through the
fused :class:`~isaaclab_ovphysx.sim.views.OvPhysxView`. The binding is body-major flat,
so data ``[num_envs, num_cubes, 3]`` is mapped to/from the view layout with
:meth:`~isaaclab_ovphysx.assets.RigidObjectCollection.reshape_data_to_view_3d` and its
inverse. (The PhysX backend uses ``root_view.get/set_material_properties``.)
"""
with _ovphysx_sim_context(device=device, add_ground_plane=True, auto_add_lighting=True) as sim:
object_collection, _ = generate_cubes_scene(num_envs=num_envs, num_cubes=num_cubes, device=device)

# Play sim
sim.reset()

# Random material per object: (static_friction, dynamic_friction, restitution), on the sim device.
static_friction = torch.empty(num_envs, num_cubes, 1, device=device).uniform_(0.4, 0.8)
dynamic_friction = torch.empty(num_envs, num_cubes, 1, device=device).uniform_(0.4, 0.8)
restitution = torch.empty(num_envs, num_cubes, 1, device=device).uniform_(0.0, 0.2)
materials = torch.cat([static_friction, dynamic_friction, restitution], dim=-1) # [num_envs, num_cubes, 3]

# Map data -> body-major view layout, write through the view.
view_materials = object_collection.reshape_data_to_view_3d(wp.from_torch(materials, dtype=wp.float32), 3)
object_collection.root_view.set_attribute(TT.RIGID_BODY_SHAPE_FRICTION_AND_RESTITUTION, view_materials)

# Simulate physics
sim.step()
object_collection.update(sim.cfg.dt)

# Read back and map view -> data layout (inverse of reshape_data_to_view_3d), then verify.
view_check = wp.to_torch(
object_collection.root_view.get_attribute(TT.RIGID_BODY_SHAPE_FRICTION_AND_RESTITUTION)
)
materials_check = view_check.reshape(num_cubes, num_envs, 3).transpose(0, 1).contiguous()
torch.testing.assert_close(materials_check, materials)

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.

P1 Missing skip guard for old wheel versions

TT.RIGID_BODY_SHAPE_FRICTION_AND_RESTITUTION is defined in tensor_types.py under a try/except AttributeError: pass guard. When the installed wheel pre-dates 0.4.13, the module attribute is simply not set — so accessing it here raises AttributeError at test runtime (the test errors rather than skips cleanly). The xfail marker was removed without adding a corresponding skipif. The existing pytest.importorskip("ovphysx.types") only checks wheel presence, not its version.

Add an early skip at the top of the test body:

if not hasattr(TT, "RIGID_BODY_SHAPE_FRICTION_AND_RESTITUTION"):
    pytest.skip("RIGID_BODY_SHAPE_FRICTION_AND_RESTITUTION not available in this wheel version")

Comment on lines +790 to +793
view_check = wp.to_torch(
object_collection.root_view.get_attribute(TT.RIGID_BODY_SHAPE_FRICTION_AND_RESTITUTION)
)
materials_check = view_check.reshape(num_cubes, num_envs, 3).transpose(0, 1).contiguous()

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 Implicit S=1 assumption in the readback reshape

view_check.reshape(num_cubes, num_envs, 3) works only when each rigid body has exactly one collision shape (S=1). If the binding's shape is (num_envs * num_cubes, S, 3) with S>1, the reshape silently produces an incorrect materials_check (or fails with a size error). The test uses simple unit cubes so S=1 holds today, but this assumption is undocumented and will break for any mesh with compound collision geometry. Consider asserting view_check.shape == (num_cubes * num_envs, 3) before the reshape, or factoring S out explicitly.

@AntoineRichard
AntoineRichard force-pushed the antoiner/feat/ovphysx_rigidobjectcollection_materials branch from f4475c7 to f51a13e Compare July 2, 2026 15:01
…sxView

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 the collection's material test xfailed (it was an empty stub).

- Add the tensor_types alias RIGID_BODY_SHAPE_FRICTION_AND_RESTITUTION
  (guarded for older wheels; shared with the sibling material PRs).
- Implement test_set_material_properties, mirroring the PhysX backend but
  reading/writing the material through OvPhysxView.get_attribute /
  set_attribute on the new tensor type. The fused collection 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.

Verified on both cpu and cuda:0 (num_envs 1/3, num_cubes 1/2).
@AntoineRichard
AntoineRichard force-pushed the antoiner/feat/ovphysx_rigidobjectcollection_materials branch from f51a13e to c05a011 Compare July 7, 2026 14:27
@AntoineRichard
AntoineRichard merged commit 9ce4097 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
…#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