Repository navigation
Enable OVPhysX rigid-object-collection material test via OvPhysxView - #6241
Conversation
5412625 to
f4475c7
Compare
Greptile SummaryThis PR promotes
Confidence Score: 3/5Safe to review but two correctness issues in the collection and its test need fixing before merge. The rigid_object_collection.py (_get_binding None-dereference) and test_rigid_object_collection.py (missing skipif for old wheel). Important Files Changed
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)
%%{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)
|
| 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) |
There was a problem hiding this comment.
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")| 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() |
There was a problem hiding this comment.
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.
f4475c7 to
f51a13e
Compare
…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).
f51a13e to
c05a011
Compare
> **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.
…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.
…#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.
What
The ovphysx wheel now exposes per-collision-shape rigid-body material as the
RIGID_BODY_SHAPE_FRICTION_AND_RESTITUTIONtensor type. This closes the gap that kept the collection'stest_set_material_propertiesxfailed (it was an emptyNotImplementedErrorstub written against the PhysX-onlyroot_view.get/set_material_properties()API).tensor_typesaliasRIGID_BODY_SHAPE_FRICTION_AND_RESTITUTION, guarded withtry/except AttributeError(shared with the sibling material PRs; documented there).test_set_material_properties, mirroring the PhysX backend but reading/writing the material throughOvPhysxView.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 withreshape_data_to_view_3dand its inverse.Verification
OVPhysX runs the PhysX solver. The material round-trip passes on both
cpuandcuda:0fornum_envs1/3 ×num_cubes1/2.The changelog fragment is a
.skipbecause the only user-facing addition (the alias) is documented by the sibling material PRs; this PR is test enablement.