Repository navigation
Refactor and simplify OV cloning and stage ownership - #8232
Conversation
|
There was a problem hiding this comment.
Isaac Lab Review Bot
The clone-preparation move into OvrtxReplicateContext is consistent with the existing backend dispatch boundary, and no compatibility break was identified. Before merge, remove two implementation/configuration-shape assertions that do not protect observable behavior and complete the public context method’s argument documentation.
- Design and architecture: The new priority-100 clone context gives plan interpretation and routed-copy preparation a single owner, while
OVRTXBackendstores the prepared copies, environment paths, and positions for either native scene implementation. The grouping, covered-child suppression, self-copy filtering, and parent-before-child ordering follow the adjacent clone-context architecture. - API: The exported
ovrtx_replicate,ovstage_replicate, andOvrtxReplicateContextare additive, and the removed renderer helper was private. The native operations document their copy and placement contracts, but the publicOvrtxReplicateContext.replicatemethod should add Google-style documentation forplanandasset_prototype_idsand clearly describe the backend state it publishes. - Compatibility and deprecation: Breaking changes: none identified. The deleted
_clone_sourceshelper was private, the newcloning_contextsdefault preserves automatic clone preparation, and both native operations retain clone-before-placement ordering for legacy OVRTX and OVStage. - Implementation: The prepared-copy path was traced through world grouping, routed asset filtering, ancestor coverage suppression, depth ordering, backend publication, stage export, and final native execution. The implementation keeps clone-plan interpretation out of the two native execution functions and preserves the renderer’s clone-then-partition flow.
- Style consistency: Naming, placement, type annotations, and deferred optional-runtime imports match the adjacent
OvPhysxReplicateContextandovphysx_replicatepatterns. The publicreplicatedocstring is incomplete relative to the repository’s Google-style public API requirements and its documented sibling. - Test quality: The routing matrix, export exclusion case, native OVRTX/OVStage execution coverage, and GPU integration hookup exercise distinct behavior. Remove
test_native_cloners_keep_plan_interpretation_in_the_context, which AST-greps names and private code shape rather than behavior, and remove thecloning_contextsprefix assertion from the geometry-binding test, which merely restates configuration and is vacuous for an empty tuple.
Minor fixes needed. Posted 3 actionable findings inline.
Automated review; human maintainers own approval decisions.
| assert not exported.GetPrimAtPath(f"{root}/Object_env{env_id}_only") | ||
|
|
||
|
|
||
| def test_native_cloners_keep_plan_interpretation_in_the_context(): |
There was a problem hiding this comment.
🟡 Warning · Test Quality — Structural source-grep test asserts code shape
This case asserts the absence of symbol names that never existed, checks OVRTXRenderer lacks a private method, and AST-greps the two native functions for identifiers named plan/cloner. It protects no observable behavior: a behavior-preserving rename turns it red, while a plan-interpreting implementation under other names passes. The clone-context routing and native-replication cases already own this contract; remove it.
| def __init__(self, sim_context: SimulationContext): | ||
| self._sim = sim_context | ||
|
|
||
| def replicate(self, plan: ClonePlan, asset_prototype_ids: tuple[int, ...]) -> None: |
There was a problem hiding this comment.
🔵 Suggestion · Style Consistency — New public replicate omits Args documentation
OvPhysxReplicateContext directly above documents sim_context in __init__ and both plan and asset_prototype_ids under Args:. This new public context documents neither, and its docstring states a refactoring rule for renderers rather than the method contract or the backend fields it populates. Add the Args: section and describe the published state, leaving design history in the changelog fragment.
| use_ovstage = mode == "ovstage" | ||
| assert not renderer.cfg.cloning_contexts | ||
| # Geometry reaches OVRTX through SDP, so no Newton clone context may be declared for it. | ||
| assert all(str(context).startswith("isaaclab_ov.cloner:") for context in renderer.cfg.cloning_contexts) |
There was a problem hiding this comment.
🔵 Suggestion · Test Quality — Config restatement inside geometry-binding test
The assertion only restates the new cloning_contexts default via a string prefix, inside a test that owns mixed SDP point publication. It passes vacuously for an empty tuple, fails if a context is declared as a class object rather than a string, and never checks the Newton claim in the adjacent comment. Drop the assertion and comment; clone-context coverage belongs in the clone-plan tests.
| if self.ordinal: | ||
| return |
There was a problem hiding this comment.
Shared stage retains stale geometry
On a forced OVPhysX re-warm after the authored USD changes, the shared stage already has a nonzero ordinal. populate(stage_usda) therefore returns without importing the newly serialized scene, and physics reattaches the old bodies and geometry. The simulation then runs against a scene that no longer matches the current USD.
There was a problem hiding this comment.
the bot here is actually right
| raise RuntimeError("Scene not initialized. Call initialize() first.") | ||
| if self.backend.renderer is None or not self._camera_render_data: | ||
| return | ||
| products = {camera.render_product_path for camera in self._camera_render_data} |
There was a problem hiding this comment.
Shared engine omits camera products
When cameras with different OVRTX product configurations share one native engine, each renderer instance submits only its own products. A product that leaves and later re-enters the submission set can incur the expensive restart that all-products-per-step batching is meant to avoid.
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!
| from ..cloner.replicate_session import _prepare_clone_contexts # noqa: PLC0415 | ||
| from ..sim import SimulationContext # noqa: PLC0415 |
There was a problem hiding this comment.
Is it necessary to defer these imports?
| self._sim.physics_manager._clone_recipes.extend(recipes) | ||
|
|
||
|
|
||
| class OvrtxReplicateContext: |
There was a problem hiding this comment.
Hey @ooctipus more of a high level question. I see "replicate" and "clone" used interchangeably throughout the code base. Do they mean the same thing? Would it make sense to converge on one term?
There was a problem hiding this comment.
yes they mean the same thing
|
@r-schmitt were you working on something similar? sharing of ovstage.Stage between ovphysx and ovrtx |
| plan: Replication layout shared by every clone backend. | ||
| asset_prototype_ids: Asset definitions routed to native OVRTX scenes. | ||
| """ | ||
| from isaaclab_ov.renderers.ovrtx_renderer_cfg import OVRTXBackendCfg # noqa: PLC0415 |
There was a problem hiding this comment.
Does this import need to be inline here?
| Args: | ||
| usda: USD scene containing the routed prototypes and their materials. | ||
| """ | ||
| from isaaclab_ov.cloner import ovstage_replicate # noqa: PLC0415 |
| if self.ordinal: | ||
| return |
There was a problem hiding this comment.
the bot here is actually right
| raise RuntimeError("Scene not initialized. Call initialize() first.") | ||
| if self.backend.renderer is None or not self._camera_render_data: | ||
| return | ||
| products = {camera.render_product_path for camera in self._camera_render_data} |
There was a problem hiding this comment.
After thinking about this, maybe the products should be added to OVRTXBackend rather than here.
| } | ||
| # Backend packages own selection rules; core preparation has no optional SDK dependencies. | ||
| for context in tuple(routing): | ||
| if context in routing and (prepare := getattr(context, "prepare", None)) is not None: |
| from isaaclab_ov.renderers.ovrtx_renderer_cfg import OVRTXBackendCfg, OVRTXRendererCfg # noqa: PLC0415 | ||
| from isaaclab_ov.stage import OvstageBackendCfg # noqa: PLC0415 | ||
|
|
||
| renderers = [(cfg, renderer) for cfg, renderer in sim._backend_registry if isinstance(cfg, OVRTXRendererCfg)] |
There was a problem hiding this comment.
I think in sim you added close_backend and get_or_create_backend, instead of accessing directly the backend registry, maybe you can just add a third get_backend to help you here instead of accessing _backend_registry?
| import ovstage # noqa: PLC0415 | ||
|
|
||
| from isaaclab_ov.renderers.ovrtx_renderer import ( # noqa: PLC0415 | ||
| _read_gpu_transforms_enabled, |
There was a problem hiding this comment.
_ method is being imported. I saw this pattern in a few places, if something is meant to be public, drop the _
| replicate_priority = 100 | ||
|
|
||
| @staticmethod | ||
| def prepare(sim: SimulationContext, routing: dict[type, set[int]]) -> None: |
There was a problem hiding this comment.
Side thought: I wonder if we should have prepare not be static and have core call prepare, and the replication context can then keep a reference to the backend it creates. (might be worth investigating)
| scene = sim.get_or_create_backend(OvstageBackendCfg(scene_key=backend_cfg)) if use_ovstage else None | ||
| renderer.backend = sim.get_or_create_backend(backend_cfg) | ||
| renderer.scene = scene if use_ovstage else renderer.backend | ||
| renderer._use_ovstage = use_ovstage |
There was a problem hiding this comment.
Late cameras lose scene contents
A renderer registered after clone dispatch gets a new backend without the active plan's copies. This affects standalone cameras added after scene construction and cameras using a new OVRTXRendererCfg after physics starts. prepare_clone_contexts() allocates resources but never calls _prepare_scene_copies(), leaving clone_copies and the environment paths empty.
For multiple environments, prepare_stage() then exports with no sources and removes the scene's environment contents. The camera cannot render the cloned scene. Prepare the active plan's rendering routes for each new backend before exporting it, without replaying physics cloning.
c514f89 to
f23aecd
Compare
|
run-ci |
f23aecd to
2fd269c
Compare
|
run-ci |
|
run-ci |
|
run-ci |
# Description Adds opt-in sharing of one simulation-owned OVStage between OVPhysX and OVRTX. Clone preparation combines their asset routes, populates both USD domains, and clones once. The default paths remain separate. Enable sharing with `ISAAC_LAB_SHARE_OVSTAGE=1`. This requires OVPhysX and selects OVStage rendering regardless of `ISAAC_LAB_OVRTX_USE_OVSTAGE`. Configure cameras and flags before the first reset. Without flags, OVPhysX keeps separate physics and rendering stages; Newton uses native OVRTX cloning. The RTX flag alone selects independent OVStage rendering. - Camera construction resolves PPISP and authors RTX exposure settings before cloning or importing the scene, including existing cameras (`spawn=None`). Renderers consume the prepared configuration during normal initialization. The redundant `prepare_cameras()` phase is removed: custom renderer runtime setup belongs in `create_render_data()`, with the stage available through `self._sim.stage`. Author PPISP attributes before constructing the sensor. - Shared-stage cameras borrow one OVRTX engine; native logging and transform-cache settings must agree. Rendering reuses the populated scene without another USD export unless a debug dump was requested. - Private and shared physics stages use `OvstageBackend` for population, queries, write ordinals and cleanup. `OvPhysxBackend.load()` owns detach, rebuild and attach; the manager no longer implements separate stage setup or an ordinal counter. Physics owns private stages and borrows shared ones. - Full-stage physics imports are rejected before population because prototype-only cloning would discard authored environment overrides. Disable sharing for those scenes. - Native setup imports its dependencies directly and registers the schema paths selected by the existing SDK compatibility layer. Binding cleanup uses the renderer’s resource stack and propagates failures after releasing resources. Includes the merged #8232 foundation through the base branch; this diff contains only the sharing feature. ## Performance: sharing remains opt-in Kuka Allegro Lift camera, OVPhysX 0.6.3, OVRTX 0.5.0.377615, OVStage 0.2.0.377349, RTX 5090, `single_camera,rgb64`: | Measured revision / cloning | Startup, 128 envs | Startup, 1,024 envs | Step, 1,024 envs | |---|---:|---:|---:| | Develop `c9a40a1de`, separate OVPhysX + OVStage rendering | 24.1 s | 70.1 s | 80.4 ms | | Foundation `0018ae99d`, separate OVPhysX + OVStage rendering | 22.0 s | 70.8 s | 81.3 ms | | Shared feature `eee513324`, shared OVStage | 51.7 s | Stopped at a 180 s process limit before the first image | Unavailable | Historical diagnostic runs, one process per configuration. Step time is the median of 60 synchronized steps after 15 warmups. Startup covers environment construction, reset and first image, excluding imports; the process limit includes imports. These runs predate flag separation and were not repeated for this cleanup. At 128 environments, the physics pose binding used by rendering took 31.14 s with sharing versus 0.63 s without it. The 1,024-environment shared run was still creating physics tensor bindings when stopped. Sharing remains opt-in until upstream cold-binding and shared-stage update performance are fixed and validated; no SDK fix or speedup is assumed. ## Validation **48 focused cases passed** for `2a9784981`: camera construction/output contracts, PPISP configuration, exposure and GPU kernels, Newton lens distortion, Newton and Kit RTX PPISP rendering, and shared OVStage rendering/reset. Existing tests now cover pipeline reuse across image resolutions and preservation of USD schema list edits. The schema-edit regression fails against the old manual metadata merger and passes with `AddAppliedSchema()`. The earlier construction regression also fails with the pre-fix constructor. The follow-up removed another 117 production lines net (98 net including tests and changelogs): the extra camera preparation phase, cached stage alias, two controller helpers, repeated normalization after USD discovery, and generic exposure conversion/schema merging. Standalone pipeline normalization is retained for callers passing partial configurations. The preceding `373c7c4e1` passed 196 focused lifecycle, SDP, renderer, native-view, SDK compatibility, material and shared-stage cases. Test files ran in separate processes; native GPU checks used **GPU0** with OVPhysX 0.6.4, OVRTX 0.5.1, and OVStage 0.2.1. The integration tests cover contact isolation, calibration, shared-engine submission, gravity changes, soft reset, forced reload and USD debug dumps. Schema tests retain host-plugin conflict coverage; version selection is covered at its existing compatibility boundary. The existing renderer lifetime test now verifies failure propagation and complete cleanup, and fails for the intended reason when the previous shutdown implementation is restored. `uv run isaaclab -f`, changelog validation and `git diff --check` passed. Documentation builds are left to CI. These correctness checks do not establish that the historical sharing performance issues are resolved. ## Checklist - [x] I have read and understood the contribution guidelines - [x] I have run the pre-commit checks with `uv run isaaclab --format` - [x] I have made corresponding changes to the documentation - [ ] My changes generate no new warnings (native runs include existing SDK and Torch warnings) - [x] I have validated the changed behavior with focused coverage - [x] I have added changelog fragments for the changed packages - [x] My name already exists in `CONTRIBUTORS.md`
# Description Restore native OVRTX cloning when `ISAAC_LAB_OVRTX_USE_OVSTAGE` is unset. #8232 changed the default to independent OVStage rendering for OVPhysX, so existing nightly camera benchmarks silently switched rendering paths and lost throughput. Explicit `ISAAC_LAB_OVRTX_USE_OVSTAGE=1` and `ISAAC_LAB_SHARE_OVSTAGE=1` remain supported. Update the existing default-routing regression case, the clone-routing documentation, and the package changelog. No backport is needed: `release/3.0.0` still has the legacy default. The investigation compared `cff854ab` with develop `0ab97e9c811` on an RTX PRO 6000 Blackwell, with fixed dependencies, 256 environments, 50 warmup steps, 300 measured steps, and seed 42. Throughput is in environment steps/s: | Task | Last good, legacy | Develop, explicit legacy | Develop, unset (OVStage) | | --- | ---: | ---: | ---: | | Isaac-Reorient-Cube-Shadow-Camera-Direct (RGB 120×120) | 7,019 | 7,028 | 6,057 | | Isaac-Lift-KukaAllegro-Camera (single RGB 64×64) | 2,999 | 2,993 | 2,875 | The fix restores the selection used by the explicit-legacy column; these performance measurements were taken during the investigation before this patch. ## Validation - The updated `ovphysx-default` case fails on the original production code because it selects `OvstageReplicateContext` instead of `OvrtxReplicateContext`. - `uv run --no-sync python -m pytest source/isaaclab_ov/test/test_ovrtx_renderer_contract.py -q`: **53 passed**. Existing TorchScript deprecation warnings remain. - `ISAACLAB_CHANGELOG_BASE_REF=origin/develop uv run --no-sync isaaclab --format`: passed across the repository. - `uv run --no-sync python tools/changelog/cli.py check origin/develop --include-worktree`: passed. - Clean Sphinx HTML build with warnings treated as errors (`-W --keep-going -j 4`): passed. Documentation dependencies ran in an isolated uv overlay; the simulation environment was not synchronized. ## Type of change - Bug fix - Documentation update ## Release backport - [ ] <!-- backport-active-release --> Backport this pull request to the active release branch after it merges into `develop` ## Checklist - [x] Read the contribution guidelines. - [x] Ran the repository formatting and lint checks. - [x] Updated the documentation. - [x] No new warnings introduced by this change. - [x] Validated the changed behavior and applied the test-audit criteria to the existing regression case. - [x] Added a changelog fragment for the changed package. - [x] Contributor is already listed in `CONTRIBUTORS.md`.
Description
Clone preparation now resolves native representations before initialization, and the simulation registry owns OVStage resources. This PR contains the cloning foundation and its simplification. Shared OVPhysX/OVRTX stages remain isolated in #8279.
Without flags, OVPhysX keeps native physics cloning and OVRTX uses an independent rendering OVStage; Newton uses native OVRTX cloning.
ISAAC_LAB_OVRTX_USE_OVSTAGE=0or1overrides the rendering path without changing physics ownership. This policy is resolved inOvrtxReplicateContext.prepare, inisaaclab_ov/cloner/replicate.py, before backend initialization. The renderer-side switch helper was removed. #8279 adds separate opt-in flags for sharing.ReplicateContextgives USD, PhysX, Newton, OVPhysX, OVRTX and OVStage one explicit preparation/dispatch contract. Removed optional method discovery and duplicate constructors. Preparation is inline before context construction, standalone reset and late renderer initialization. Custom contexts must inherit the base and implementreplicate; no compatibility shim was added.OvstageBackendowns population, prepared copies, queries/path lists and write ordinals. Contexts useSimulationContext.get_backends(); renderers own bindings and borrow resources. OVRTX constructors declare requirements without allocating native engines.InteractiveSceneauthors prototypes only. SDP reads the environment count fromClonePlan, including native copies absent from USD. Backends apply planned placement and create required frames in private exports. Removed recursive deactivation and environment-frame capture/restore. Routed prototypes are still selected correctly after USD replication. Deformable discovery and Newton import use authored source frames rather than infer them from planned destination poses.Based on
developatc1e69cc45, including #8585 and #8686. Scene-owned cameras and the RTX viewer use the same rendering stage; the reusableOvstageBackendowns its resources. The rebase preserves renderer-owned markers and runtime geometry, explicit simulation ownership, scene lighting, and authored environment-root transforms and metadata. Physics/rendering stage sharing remains in #8279, which needs to be restacked on this revision.Size
Against
develop: 491 fewer production lines, 117 additional test lines and 103 documentation/metadata lines: 271 fewer lines overall, across 61 files (+1,932/-2,203). The OVPhysX physics manager, camera implementation and Newton visualizer matchdevelop; shared-stage coordination stays in #8279.The benchmark results below are historical measurements at the named revisions, not new measurements of this rebase.
Rendering defaults and Kuka measurements
Matched Kuka Allegro Lift camera runs (
single_camera,rgb64), 1,024 environments, median full environment-step time:c9a40a1de0018ae99dOVPhysX used one diagnostic process per path. Newton used two per path in reversed order. Each measured 60 synchronized steps after 15 warmup steps. At 128 environments, Newton measured 12.2 ms with OVRTX cloning versus 14.1 ms with OVStage rendering. Newton was 1.6.1rc1 (
dff296359), MuJoCo/MuJoCo Warp 3.12.0, using the same OV library versions and GPU below; both Newton paths used an isolated kernel cache with fresh LTO artifacts after resolving a pre-existing compiler-cache mismatch.With independent OVStage rendering, OVPhysX Kuka startup and stepping were essentially unchanged by the foundation: develop 70.1 s / 80.4 ms versus #8232 70.8 s / 81.3 ms at 1,024 environments. These measurements justify backend-specific rendering defaults; they do not justify enabling physics/rendering sharing. Shared-stage measurements are in #8279.
Native-cloning startup
Compared
developatc9a40a1dewith this foundation at0018ae99d. Three measured fresh processes per revision and environment count, alternating revision order, after one excluded warmup pair per count. Both use native cloning (ISAAC_LAB_OVRTX_USE_OVSTAGE=0). The 128-environment timings overlap; the larger counts show improvement. These are startup measurements, not shared-stage or steady-state throughput claims.Eight rigid cubes per environment, dome lighting, and a tiled 64×64 diffuse/depth camera. Timing covers simulation/scene construction, reset and the first synchronized image; imports are excluded. All 24 runs, including warmups, checked 4.5 m center depth in every environment.
Threadripper PRO 7965WX; RTX 5090 GPU 1; driver 580.173.02; Python 3.12.12; OVPhysX 0.6.3, OVRTX 0.5.0.377615, OVStage 0.2.0.377349, Warp 1.17.0, Torch 2.12.0+cu130. Both revisions used the same environment and GPU. No tests or other work used that GPU during timing. The SDK reports existing CPU powersave/device-masking warnings.
Startup reproduction harness
Save as
benchmark_startup.py. Use one environment with the dependency versions above for both checkouts:Repeat at 128, 1024 and 4096 environments: one warmup pair, then three measured pairs; alternate the order of base and PR runs. Compare
scene_to_image_s.Validation
The three previously failing Franka soft/cloth/cable native-OVRTX golden-image cases passed on GPU0, along with 152 focused clone, renderer, USD-export and scene-data tests. The environment-count regression failed before the fix and passed afterward. Existing coverage was extended; no test files or image tolerances were added. The stale
OvstageBackend.resetautodoc reference was removed; the full docs build runs in CI.Earlier checks passed 110 profiling-target checks, 71 clone/renderer/binding checks, 10 Newton cloning tests (plus four subtests), and all seven RTX viewer integration cases. The Newton placement regression failed before the fix and passed afterward. Existing tests were extended; no new test files were added.
On GPU0, Shadow Hand passed with OVRTX and Newton rendering. Cartpole passed 15 cases; its OVStage constant-diffuse comparison failed identically on
develop. Kuka's remaining image-comparison failures also reproduced ondevelop; no image tolerances were changed.Earlier rebase validation passed 217 focused cases, including both RTX scene paths, native physics/rendering ownership, camera calibration, lighting, material synchronization and lifecycle checks. The Coffee GPU capture reproduction also passed: moving particles changed recorded pixels without drawing a window. Native validation used GPU0, OVPhysX 0.6.4, OVRTX 0.5.1 and OVStage 0.2.1.
Formatting, changelog validation and
git diff --checkpassed. Documentation builds are left to CI.Checklist
uv run isaaclab --formatCONTRIBUTORS.md