Skip to content

Migrate OVPhysX frame-transformer sensor onto OvPhysxView (view series, part 5)#6231

Open
AntoineRichard wants to merge 12 commits into
isaac-sim:developfrom
AntoineRichard:antoiner/feat/ovphysx_frame_transformer_view
Open

Migrate OVPhysX frame-transformer sensor onto OvPhysxView (view series, part 5)#6231
AntoineRichard wants to merge 12 commits into
isaac-sim:developfrom
AntoineRichard:antoiner/feat/ovphysx_frame_transformer_view

Conversation

@AntoineRichard

Copy link
Copy Markdown
Collaborator

🔗 Stacked on top of #6224 (Part 1 — OvPhysxView)

Branched off #6224 as a sibling of the asset migrations (#6225/#6226/#6227). Targets develop; until #6224 merges, the diff below includes the Part 1 OvPhysxView commits. Please review #6224 first.

Description

Part 5 of the OVPhysX view-migration series — route the frame-transformer sensor's tensor-binding management through OvPhysxView. Internal refactor; no public API change (sensors do not expose a root_view).

  • _initialize_impl builds one OvPhysxView instead of separate create_tensor_binding calls; binding handles come from binding_for.
  • Pose/state reads route through read_into (cached float32 reinterpret, typed off the binding shape), replacing the manual wp.array(ptr=...) reinterpret views.
  • All pose bindings are GPU-resident state; no CPU staging. One view per tracked body.
  • Numeric behavior unchanged.

Type of change

  • This change requires no public API change (internal refactor)

Checklist

  • I have run the pre-commit checks with ./isaaclab.sh --format
  • My changes generate no new warnings
  • I have added a changelog fragment (.skip — internal refactor, no user-facing change / no bump)

Testing

test_frame_transformer.py — cpu: 12 passed, cuda: 12 passed.

OVPhysX exposes physics attributes as a loose dict of TensorType ->
TensorBinding with no view object, unlike Newton's
selection.ArticulationView and PhysX's typed tensor views. OvPhysxView
wraps the bindings for one prim pattern behind a string-keyed
get_attribute / set_attribute surface, addressing attributes by the
lowercased TensorType enum name (e.g. "articulation_dof_stiffness").
It needs no Model/State/Control source object because the TensorType
already implies where the data lives.

Prototype per docs/superpowers/specs/2026-06-17-ovphysx-view-design.md.
Adds unit tests covering name<->enum resolution, the read-only guard,
discoverability, and get/set dispatch against a fake binding (no native
simulation required).
Reworks the view from a convenience wrapper into a layer that can back the
OVPhysX asset/data classes, per the PR review of isaac-sim#6224:

- read_into(name, dst): zero-copy fill of a caller-owned, possibly
  structured-dtype buffer (e.g. wp.transformf) via a float32 reinterpret
  view -- the mechanism the data containers use today.
- set_attribute: accepts structured-dtype sources via the same reinterpret;
  non-float32-width buffers are rejected rather than silently bit-cast.
- prim_paths + key_aliases: support the fused multi-prim binding form
  (create_tensor_binding(prim_paths=[...])) and storing a binding under a
  different TensorType key, as RigidObjectCollection needs.
- binding_for(): raw TensorBinding accessor for adoption.
- _CPU_ONLY_NAMES is now derived from tensor_types._CPU_ONLY_TYPES (no drift).
- Added joint/tendon/is_fixed_base metadata passthrough; eager construction
  raises if it creates zero bindings; get_attribute allocates a fresh buffer
  (no aliasing); nested error hierarchy; PhysX/binding Protocols.

Device policy: no implicit CPU<->GPU conversion. CPU-resident property types
are read/written on CPU; a buffer on the wrong device raises DeviceMismatch
instead of being staged. Device-less host data (numpy/list) is materialized
on the binding's native device.
The OvPhysxView addition is a significant new public surface for the OVPhysX
backend, so promote the changelog fragment from a minor to a major bump.
Reword the entry to describe the binding-manager surface (read_into, the
no-device-conversion policy) and drop the internal design-note path from the
user-facing changelog.
From the second PR review of isaac-sim#6224:

- Critical: _as_binding_view now requires a float32 scalar dtype before the
  zero-copy reinterpret. A same-byte-width wrong dtype (int32) previously passed
  the count-only guard and was bit-reinterpreted into garbage on the write path;
  sub-4-byte dtypes (float16) produced a misleading "0 elements" error. Both are
  now rejected with a clear message. Regression tests added (verified failing
  without the guard).
- _resolve enforces the str | TensorType union and raises UnknownAttribute on
  anything else, instead of letting a bogus key reach the wheel.
- _binding accesses binding.count directly (a malformed binding surfaces instead
  of being masked as a phantom no-match) and surfaces the underlying
  create_tensor_binding exception in the AttributeUnavailable message.
- Added docstrings to the six metadata properties; dropped the unused
  runtime_checkable decorator.
- Tests: same-byte/sub-4-byte dtype rejection, get_attribute(out=) wrong device,
  both indices+mask forwarded, read/write through a prim_paths+key_aliases view,
  non-str/non-TensorType key, and a read-only-names-are-valid-vocabulary check.
From the API-hardening review of isaac-sim#6224. Validate at the boundary and fail loud
instead of silently corrupting, mis-binding, or no-op'ing:

- Reject non-contiguous buffers in _as_binding_view (a strided/sliced source would
  be reinterpreted as contiguous and read/write the wrong memory).
- Canonicalize the device (wp.get_device) so a "cuda" view accepts a "cuda:0"
  buffer instead of raising a spurious, unsatisfiable DeviceMismatch; falls back
  to the raw string when the device can't be resolved locally.
- Reject TensorType.INVALID via the member path too (string path already did).
- Normalize key_aliases to TensorType members so string keys are honored rather
  than silently dropped, and reject aliases that cross the CPU/GPU residency or
  read-only boundary (the device/read-only guards key on the requested type).
- Reject empty pattern/prim_paths and tensor_types-without-eager at construction.
- Eager construction with an explicit tensor_types list now surfaces a failing
  type instead of swallowing it at debug level (default sweep still skips
  inapplicable types).
- Document binding_for as an unguarded escape hatch, get_attribute's native-device
  return, and the has_attribute name-validity-vs-availability split.

Adds regression tests for each (contiguity and INVALID verified failing without
the guard).
Surfaced by dogfooding the view in the articulation migration: the assets branch
on a "binding or None" pattern for optional/absent bindings (tendon types on a
tendon-less articulation, not-yet-created bindings), which the raising binding_for
can't express. try_binding_for returns None when the attribute is valid but not
available for the view's prims, while still raising UnknownAttribute for an invalid
name (a programming error, not an availability question).
…xView

read_into now reuses the float32 reinterpret of a destination buffer
across calls (keyed by buffer id, with a pointer-staleness guard), so the
wheel's object-identity read cache stays warm even when callers hand a
structured buffer each step -- they no longer need to maintain their own
reinterpret cache. get_attribute returns a typed array for attributes with
a known structured layout (transformf for poses, spatial_vectorf for
velocities, via a hand-maintained _ATTR_DTYPE map) and flat float32
otherwise.

This lets the asset data containers drop their bespoke _get_read_view
caching and read structured buffers straight through the view.
@github-actions github-actions Bot added the isaac-lab Related to Isaac Lab team label Jun 22, 2026
OvPhysxView (and OvPhysxFrameView) live in isaaclab_ovphysx.sim.views,
which had no API-docs page. Add the automodule stub and wire it into the
isaaclab_ovphysx autosummary so the new binding-manager view shows up in
the rendered API reference alongside assets / cloner / physics.
Three fixes from the Part 1 review:

- get_attribute (no out): route the freshly allocated buffer through
  _as_binding_view directly instead of the id()-keyed read cache. A fresh
  buffer can never hit the cache and would leak one entry (keeping the
  buffer alive) per call in a step loop; the cache only pays off for a
  reused out/dst buffer. Add a regression test asserting the no-out path
  leaves _read_views empty.

- Raise a dedicated DtypeMismatch instead of ShapeMismatch when a buffer's
  scalar element type is not float32, so a dtype error no longer reads as a
  dimensions error. Update the affected tests and the Raises docstrings.

- Make the view Warp-native: drop the fragile __module__ string-match that
  auto-converted Torch tensors on writes. Callers bridge a Torch tensor
  with wp.from_torch(t), keeping the device policy explicit and avoiding an
  optional Torch dependency.
Documentation/comment clarifications from the isaac-sim#6224 review (no behavior change):

- Narrow the documented contract to float32-only: attribute_names/has_attribute
  and the module docstring now state that a listed name is name-validity, not a
  dtype-support promise; non-float dtype handling awaits wheel dtype metadata.
- Mark _READ_ONLY_NAMES explicitly temporary; name the three access modes
  (read/write, read-only, write-only) and the wheel access_mode enum that should
  replace the table.
- Document key_aliases as an internal collection adapter, not general public API,
  pending descriptor metadata.
- Make the view test scope explicit: mock API mechanics here; live
  CPU-only-on-GPU / read-only+write-only / structured read_into coverage lives in
  the asset-integration tests.
…through OvPhysxView

Replace the per-body create_tensor_binding calls and read-time
wp.transformf reinterprets in the OVPhysX FrameTransformer with one
OvPhysxView per tracked body. Each view's binding_for(TT.RIGID_BODY_POSE)
supplies .count during initialization, and read_into fills a structured
(num_envs,) wp.transformf buffer directly, dropping the manual view().
No public API or numeric behavior change.
@AntoineRichard AntoineRichard force-pushed the antoiner/feat/ovphysx_frame_transformer_view branch from 98bed48 to 0653e79 Compare June 23, 2026 10:01
@github-actions github-actions Bot added the documentation Improvements or additions to documentation label Jun 23, 2026
@AntoineRichard AntoineRichard marked this pull request as ready for review June 25, 2026 11:25
@greptile-apps

greptile-apps Bot commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR introduces OvPhysxView, a string-keyed binding manager over OVPhysX TensorBinding handles, and migrates the frame-transformer sensor to use it — replacing per-body create_tensor_binding calls with a single OvPhysxView per tracked body whose read_into fills a structured wp.transformf buffer directly.

  • OvPhysxView adds lazy/eager binding creation, structured-dtype reinterpret (wp.transformf / wp.spatial_vectorf), a float32 reinterpret cache (_read_view) for wheel object-identity read-cache warmth, and explicit CPU↔GPU device guards for CPU-only property types.
  • frame_transformer.py replaces _body_bindings: list[Any] with _body_views: list[OvPhysxView]; read_buf is now (num_envs,) wp.transformf instead of (num_envs, 7) float32, eliminating the manual .view(wp.transformf) call before the kernel launch.
  • A 30-test suite (test_ovphysx_view.py) covers construction, get/set/read-into dispatch, device policy, dtype safety, and adversarial construction — but does not exercise cross-attribute reuse of the same destination buffer, leaving the _read_view cache's missing shape-validation gap untested.

Confidence Score: 4/5

The frame-transformer migration is correct and the test suite passes. The new OvPhysxView class has a gap in its read-view cache that does not affect the current frame-transformer usage but could silently corrupt data for other assets that reuse a destination buffer across attributes with different shapes.

Each read_buf in frame_transformer.py is dedicated to a single attribute (RIGID_BODY_POSE), so the cross-attribute cache issue never triggers there. The concern is in the general OvPhysxView surface being adopted by other assets. The missing binding-shape check on cache hit in _read_view means that a caller passing the same wp.array to read_into for two different attributes gets back a stale view sized for the first attribute, causing the wheel to write the wrong number of floats. The fix is a one-line shape guard on the cache-hit path.

source/isaaclab_ovphysx/isaaclab_ovphysx/sim/views/ovphysx_view.py (_read_view cache, lines 839–855) and a corresponding missing test case in test_ovphysx_view.py for cross-attribute buffer reuse.

Important Files Changed

Filename Overview
source/isaaclab_ovphysx/isaaclab_ovphysx/sim/views/ovphysx_view.py New OvPhysxView class: well-documented binding manager with lazy/eager creation, structured dtype reinterpret, and device guards. The _read_view cache keyed by id(dst)+ptr is missing a binding-shape check, risking stale views for cross-attribute reuse of the same buffer.
source/isaaclab_ovphysx/isaaclab_ovphysx/sensors/frame_transformer/frame_transformer.py Migrated from raw create_tensor_binding to OvPhysxView; read_buf changed from (N,7) float32 to (N,) transformf. Logic is correct for the single-attribute-per-buffer usage; error message for AttributeUnavailable is slightly misleading.
source/isaaclab_ovphysx/test/sim/test_ovphysx_view.py Comprehensive unit test suite with 30+ tests covering construction, get/set/read_into dispatch, device policy, dtype safety, discoverability, and edge cases against fake bindings. No test for cross-attribute buffer reuse.
source/isaaclab_ovphysx/isaaclab_ovphysx/sensors/frame_transformer/kernels.py Doc-comment-only update to reflect that pose_buffer is now a structured (num_envs,) transformf array filled by OvPhysxView.read_into. No logic changes.
source/isaaclab_ovphysx/isaaclab_ovphysx/sim/views/init.pyi Type stub updated to export OvPhysxView alongside OvPhysxFrameView; consistent with the lazy_export() in init.py.

Sequence Diagram

%%{init: {'theme': 'neutral'}}%%
sequenceDiagram
    participant FT as FrameTransformer._update_buffers
    participant OV as OvPhysxView
    participant BC as _bindings cache
    participant RV as _read_views cache
    participant PX as TensorBinding (wheel)
    participant K as gather_body_pose_kernel

    Note over FT,K: Per-step update loop (one iteration per tracked body)

    FT->>OV: read_into(TT.RIGID_BODY_POSE, read_buf)
    OV->>BC: _binding(RIGID_BODY_POSE)
    BC-->>OV: cached TensorBinding (created on first access)
    OV->>OV: _check_device(read_buf, native_device)
    OV->>RV: _read_view(read_buf, binding)
    alt first call or ptr changed or shape mismatch
        RV->>RV: _as_binding_view → float32 reinterpret of transformf buf
        RV-->>OV: float32 view (cached by id(read_buf))
    else subsequent calls (same ptr and shape)
        RV-->>OV: same float32 view object (cache hit)
    end
    OV->>PX: binding.read(float32_view)
    PX-->>OV: fills read_buf in place
    FT->>K: "wp.launch(gather_body_pose_kernel, inputs=[env_mask, read_buf, dst_indices, raw_transforms])"
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 FT as FrameTransformer._update_buffers
    participant OV as OvPhysxView
    participant BC as _bindings cache
    participant RV as _read_views cache
    participant PX as TensorBinding (wheel)
    participant K as gather_body_pose_kernel

    Note over FT,K: Per-step update loop (one iteration per tracked body)

    FT->>OV: read_into(TT.RIGID_BODY_POSE, read_buf)
    OV->>BC: _binding(RIGID_BODY_POSE)
    BC-->>OV: cached TensorBinding (created on first access)
    OV->>OV: _check_device(read_buf, native_device)
    OV->>RV: _read_view(read_buf, binding)
    alt first call or ptr changed or shape mismatch
        RV->>RV: _as_binding_view → float32 reinterpret of transformf buf
        RV-->>OV: float32 view (cached by id(read_buf))
    else subsequent calls (same ptr and shape)
        RV-->>OV: same float32 view object (cache hit)
    end
    OV->>PX: binding.read(float32_view)
    PX-->>OV: fills read_buf in place
    FT->>K: "wp.launch(gather_body_pose_kernel, inputs=[env_mask, read_buf, dst_indices, raw_transforms])"
Loading

Comments Outside Diff (1)

  1. source/isaaclab_ovphysx/isaaclab_ovphysx/sim/views/ovphysx_view.py, line 839-855 (link)

    P1 Stale cached view on cross-attribute reuse

    _read_view is keyed by id(dst) + ptr but not by binding.shape. If the same wp.array object is passed to read_into for two different attributes with different shapes (e.g. rigid_body_pose with shape (N, 7) and then rigid_body_velocity with shape (N, 6)), the cache hits and returns the stale (N, 7) float32 view while the velocity binding expects an (N, 6) view. The wheel then either silently reads the wrong number of floats into the buffer (stale trailing element) or raises an unexpected shape error — neither is correct.

    The frame_transformer.py usage is safe (each read_buf is dedicated to one attribute), but OvPhysxView is a general class. The fix is to add a shape check on cache hit so a mismatched binding rebuilds the view:

    if cached is not None and cached.ptr == dst.ptr and tuple(cached.shape) == tuple(binding.shape): return cached

Reviews (1): Last reviewed commit: "Merge branch 'develop' into antoiner/fea..." | Re-trigger Greptile

Comment on lines 252 to +255
raise RuntimeError(
f"FrameTransformer: TT.RIGID_BODY_POSE binding for pattern {pattern!r} matched zero bodies."
" Verify the prim has UsdPhysics.RigidBodyAPI."
)
) from exc

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 The error message hard-codes "matched zero bodies" but OvPhysxView.AttributeUnavailable is also raised when create_tensor_binding itself throws (e.g. ABI / OOM / init failure), so the message misleads debugging in those cases. The chained exception exposes the real cause, but the primary message is incorrect. Consider making the message more general.

Suggested change
raise RuntimeError(
f"FrameTransformer: TT.RIGID_BODY_POSE binding for pattern {pattern!r} matched zero bodies."
" Verify the prim has UsdPhysics.RigidBodyAPI."
)
) from exc
raise RuntimeError(
f"FrameTransformer: TT.RIGID_BODY_POSE binding for pattern {pattern!r} is not available"
" (no matching prims or binding creation failed)."
" Verify the prim has UsdPhysics.RigidBodyAPI."
) from exc

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

@AntoineRichard

Copy link
Copy Markdown
Collaborator Author

Re the read-view cache's missing shape re-check (and the untested cross-attribute reuse): verified latent, not a live bug. The wheel validates tensor shape in native code before copying and raises RuntimeError on a mismatch (not silent), and no shipped caller reuses one buffer across two attributes — each buffer owns a single attribute, and a binding's flat shape is fixed for a session (it only changes on a full reset, which rebuilds the view). We opted not to add a per-hit guard (hot-path cost for an unreachable case); dtype-aware narrowing is a wheel-metadata follow-up. We did add reset-boundary tidiness (clearing the view on _invalidate_initialize_callback) across the consumers — frame_transformer already clears _body_views.

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.

1 participant