Repository navigation
Enable OVPhysX rigid-object shape-material tests via OvPhysxView - #6240
Conversation
e7e3dcd to
a58ea99
Compare
Greptile SummaryThis PR introduces
Confidence Score: 4/5Safe to merge; the refactor is mechanical and all call-sites are accounted for, with five previously-stubbed tests now passing. The The five new material tests in Important Files Changed
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])
%%{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])
|
| 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) |
There was a problem hiding this comment.
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.
a58ea99 to
829f197
Compare
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).
829f197 to
d25684e
Compare
…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.
> **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.
…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).
…#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 (shape[N, S, 3]= static friction, dynamic friction, restitution). This closes the gap that kept five rigid-object material testsxfailed — they were emptyNotImplementedErrorstubs written against the PhysX-onlyroot_view.get/set_material_properties()/max_shapesview API.tensor_typesaliasRIGID_BODY_SHAPE_FRICTION_AND_RESTITUTION, guarded withtry/except AttributeErrorso the module stays import-safe against older wheels.OvPhysxView.get_attribute/set_attribute:test_rigid_body_set_material_propertiesandtest_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.RigidBodyMaterialBaseCfg; masses come fromdata.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
cpuandcuda:0fornum_cubes1 and 2. Fulltest_rigid_object.pyis green (53 passed on cpu, no regressions).