Skip to content

Support OVPhysX in randomize_rigid_body_material MDP event - #6243

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

AntoineRichard merged 3 commits into
isaac-sim:developfrom
AntoineRichard:antoiner/feat/ovphysx_mdp_material_randomization

Conversation

@AntoineRichard

Copy link
Copy Markdown
Collaborator

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.

@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_mdp_material_randomization branch from 1f2766a to 5c30fc6 Compare June 23, 2026 10:04
@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 activates the previously no-op randomize_rigid_body_material MDP event on the OVPhysX backend by introducing _RandomizeRigidBodyMaterialOvPhysx, which mirrors the PhysX bucket approach and writes per-shape friction/restitution through the new OvPhysxView binding manager. The change also lands a significant refactor of Articulation, RigidObject, and their data containers: the raw _bindings: dict is replaced by a proper OvPhysxView that centralises binding creation, the CPU/GPU device policy, and the read-cache.

  • New OvPhysxView (sim/views/ovphysx_view.py): string-keyed wrapper over OVPhysX TensorBinding handles with explicit device guards, read-only protection, zero-copy read cache, and structured-dtype support. This becomes the root_view exposed by both asset classes.
  • _RandomizeRigidBodyMaterialOvPhysx: pre-samples num_buckets materials at init, assigns them randomly per-shape via a read-modify-write on the [N, S, 3] material buffer; raises NotImplementedError for per-body selection since OVPhysX exposes no per-body shape counts.
  • Asset refactor: Articulation and RigidObject and their data containers replace _bindings: dict with _root_view: OvPhysxView, removing hand-rolled _get_read_view caches that are now subsumed by OvPhysxView.read_into.

Confidence Score: 3/5

The 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 _RandomizeRigidBodyMaterialOvPhysx.__init__ accesses ovphysx_tt.SHAPE_FRICTION_AND_RESTITUTION unconditionally, but that attribute is only conditionally defined in tensor_types.py (guarded with try/except AttributeError for wheels older than 0.4.13). An older wheel will crash at MDP init with a bare AttributeError where it previously emitted a warning and silently no-oped. Everything else — the OvPhysxView design, the asset migration, the tests — looks correct and clean.

source/isaaclab/isaaclab/envs/mdp/events.py — specifically the _RandomizeRigidBodyMaterialOvPhysx.__init__ tensor-type lookup. The rest of the changed files are safe.

Important Files Changed

Filename Overview
source/isaaclab/isaaclab/envs/mdp/events.py Adds _RandomizeRigidBodyMaterialOvPhysx backend class and wires it into randomize_rigid_body_material. Missing guard for optional tensor type aliases that are wheel-version gated, causing a regression crash for users on ovphysx < 0.4.13.
source/isaaclab_ovphysx/isaaclab_ovphysx/sim/views/ovphysx_view.py New OvPhysxView string-keyed binding manager wrapping OVPhysX TensorBindings. Well-designed with explicit device policy, read-only guards, structured-dtype support, and zero-copy read cache. TODOs for hand-maintained tables are clearly documented.
source/isaaclab_ovphysx/isaaclab_ovphysx/tensor_types.py Adds SHAPE_FRICTION_AND_RESTITUTION and RIGID_BODY_SHAPE_FRICTION_AND_RESTITUTION aliases guarded with try/except AttributeError for wheel < 0.4.13 compatibility. Clean pattern consistent with other optional aliases.
source/isaaclab_ovphysx/isaaclab_ovphysx/assets/articulation/articulation.py Replaces _bindings: dict with _root_view: OvPhysxView, updating root_view property return type and all write paths to use set_attribute. Logic is consistent and well-migrated throughout.
source/isaaclab_ovphysx/isaaclab_ovphysx/assets/rigid_object/rigid_object.py Same _bindings → _root_view: OvPhysxView migration as articulation, with all write paths updated. Clean refactor.
source/isaaclab_ovphysx/isaaclab_ovphysx/assets/articulation/articulation_data.py Switches ArticulationData from a raw bindings dict to OvPhysxView, removing the hand-rolled _get_read_view cache (replaced by OvPhysxView.read_into's built-in reinterpret cache). Simpler and correct.
source/isaaclab_ovphysx/test/test_randomize_rigid_body_material_mdp.py New real-backend test for OVPhysX material randomization. Tests range bounds and the body_ids rejection. Stubs cfg/env/asset_cfg correctly. Missing a test for the missing-wheel-version path.
source/isaaclab_ovphysx/isaaclab_ovphysx/test/mock_interfaces/views/mock_ovphysx_bindings.py Adds MockOvPhysxView test double mirroring OvPhysxView's public surface. _resolve can raise StopIteration instead of a clear error when constructed with empty bindings.

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
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 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
Loading

Reviews (1): Last reviewed commit: "feat(mdp): support OVPhysX in randomize_..." | Re-trigger Greptile

Comment on lines +380 to +399
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]

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

Comment on lines +176 to +183
"""

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):

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

@AntoineRichard
AntoineRichard force-pushed the antoiner/feat/ovphysx_mdp_material_randomization branch from 5c30fc6 to 7cf011d Compare July 2, 2026 15:07
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.
@AntoineRichard
AntoineRichard force-pushed the antoiner/feat/ovphysx_mdp_material_randomization branch from 7cf011d to facb794 Compare July 7, 2026 14:27
Mark the OVPhysX package change as test-only so the per-package changelog validation recognizes the new coverage without requesting a version bump.
@AntoineRichard
AntoineRichard merged commit f92249a into isaac-sim:develop Jul 8, 2026
37 checks passed
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