Repository navigation
Support OVPhysX in randomize_rigid_body_material MDP event - #6243
AntoineRichard merged 3 commits into
Conversation
1f2766a to
5c30fc6
Compare
Greptile SummaryThis PR activates the previously no-op
Confidence Score: 3/5The OvPhysxView refactor and the new MDP implementation are well-structured, but one change in events.py introduces a crash for any user running an ovphysx wheel older than 0.4.13 — a wheel version that previously produced only a warning. That breakage warrants a fix before merging. The
Important Files Changed
Sequence Diagram%%{init: {'theme': 'neutral'}}%%
sequenceDiagram
participant MDP as randomize_rigid_body_material
participant Impl as _RandomizeRigidBodyMaterialOvPhysx
participant Asset as RigidObject / Articulation
participant View as OvPhysxView
participant Binding as TensorBinding (ovphysx wheel)
MDP->>Impl: __init__(cfg, env, asset, asset_cfg)
Impl->>Impl: pre-sample material_buckets [num_buckets, 3]
Impl->>Impl: resolve _material_type
MDP->>Impl: __call__(env, env_ids, ...)
Impl->>Asset: root_view
Asset-->>Impl: OvPhysxView
Impl->>View: get_attribute(material_type)
View->>Binding: create (lazy) + read → [N, S, 3] warp array
Binding-->>View: filled array
View-->>Impl: wp.array [N, S, 3]
Impl->>Impl: wp.to_torch → tensor, sample bucket_ids, assign material_samples[env_ids]
Impl->>View: set_attribute(material_type, wp.from_torch(modified_tensor))
View->>Binding: write [N, S, 3] → PhysX notified
%%{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 MDP as randomize_rigid_body_material
participant Impl as _RandomizeRigidBodyMaterialOvPhysx
participant Asset as RigidObject / Articulation
participant View as OvPhysxView
participant Binding as TensorBinding (ovphysx wheel)
MDP->>Impl: __init__(cfg, env, asset, asset_cfg)
Impl->>Impl: pre-sample material_buckets [num_buckets, 3]
Impl->>Impl: resolve _material_type
MDP->>Impl: __call__(env, env_ids, ...)
Impl->>Asset: root_view
Asset-->>Impl: OvPhysxView
Impl->>View: get_attribute(material_type)
View->>Binding: create (lazy) + read → [N, S, 3] warp array
Binding-->>View: filled array
View-->>Impl: wp.array [N, S, 3]
Impl->>Impl: wp.to_torch → tensor, sample bucket_ids, assign material_samples[env_ids]
Impl->>View: set_attribute(material_type, wp.from_torch(modified_tensor))
View->>Binding: write [N, S, 3] → PhysX notified
Reviews (1): Last reviewed commit: "feat(mdp): support OVPhysX in randomize_..." | Re-trigger Greptile |
| if isinstance(asset, BaseArticulation) | ||
| else ovphysx_tt.RIGID_BODY_SHAPE_FRICTION_AND_RESTITUTION | ||
| ) | ||
|
|
||
| def __call__( | ||
| self, | ||
| env: ManagerBasedEnv, | ||
| env_ids: torch.Tensor | None, | ||
| static_friction_range: tuple[float, float], | ||
| dynamic_friction_range: tuple[float, float], | ||
| restitution_range: tuple[float, float], | ||
| num_buckets: int, | ||
| asset_cfg: SceneEntityCfg, | ||
| make_consistent: bool = False, | ||
| ): | ||
| view = self.asset.root_view | ||
| # read the current per-shape material [N, S, 3] on the binding's native (sim) device | ||
| materials = wp.to_torch(view.get_attribute(self._material_type)) | ||
| num_instances, num_shapes = materials.shape[0], materials.shape[1] | ||
|
|
There was a problem hiding this comment.
Unguarded access to optional tensor type aliases
ovphysx_tt.SHAPE_FRICTION_AND_RESTITUTION and ovphysx_tt.RIGID_BODY_SHAPE_FRICTION_AND_RESTITUTION are defined with a try/except AttributeError guard in tensor_types.py because they require ovphysx ≥ 0.4.13. If a user's wheel is older, the attributes simply don't exist on the module, and this __init__ will raise AttributeError: module 'isaaclab_ovphysx.tensor_types' has no attribute 'SHAPE_FRICTION_AND_RESTITUTION' — a cryptic error with no hint to upgrade. Previously (the no-op path), an older wheel would silently warn and continue. This is a regression: environments that were working (warn + skip) will now crash on init. A hasattr check followed by a clear RuntimeError("randomize_rigid_body_material on OVPhysX requires ovphysx >= 0.4.13 …") would preserve the upgrade path without confusing users.
| """ | ||
|
|
||
| def __init__(self, bindings: dict[int, MockTensorBinding]): | ||
| self._bindings = bindings | ||
|
|
||
| def _resolve(self, name): | ||
| """Resolve a TensorType member or its lowercased name to the member.""" | ||
| if isinstance(name, str): |
There was a problem hiding this comment.
StopIteration on empty bindings dict in _resolve
type(next(iter(self._bindings))) will raise StopIteration if MockOvPhysxView is constructed with an empty dict. Any test that constructs the mock without pre-populated bindings and then calls get_attribute, set_attribute, or similar will get a confusing StopIteration instead of a clear "no bindings" error. Adding an early guard (if not self._bindings: raise KeyError(…)) before the next(iter(…)) line would make such test failures immediately obvious.
5c30fc6 to
7cf011d
Compare
OVPhysX runs the PhysX solver, so the material-randomization event now samples materials in buckets (PhysX's 64000-material limit applies) and writes per-shape friction/restitution through the asset's OvPhysxView on the shape_friction_and_restitution binding, replacing the previous no-op. Randomizes all shapes; per-body selection via asset_cfg.body_ids raises NotImplementedError because the ovphysx wheel exposes no per-body shape counts. Adds a real-backend test exercising the implementation against an OVPhysX RigidObject on both cpu and cuda:0.
7cf011d to
facb794
Compare
Mark the OVPhysX package change as test-only so the per-package changelog validation recognizes the new coverage without requesting a version bump.
…#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
randomize_rigid_body_materialpreviously 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:num_bucketsmaterials and randomly assigns them to shapes;(static_friction, dynamic_friction, restitution)through the asset'sOvPhysxView(set_attributeonSHAPE_FRICTION_AND_RESTITUTIONfor articulations,RIGID_BODY_SHAPE_FRICTION_AND_RESTITUTIONfor 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) raisesNotImplementedError— the ovphysx wheel exposes no per-body shape counts (unlike PhysX'slink_physx_view.max_shapes/ Newton'snum_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 OVPhysXRigidObject: it asserts the written friction/restitution land within the sampled ranges, and that a per-body selection fails loud. Passes on bothcpuandcuda:0. The PhysX and Newton paths are untouched.