Skip to content

Fix Newton derived-state refresh boundaries - #6350

Merged
ooctipus merged 5 commits into
isaac-sim:developfrom
ooctipus:zhengyuz/newton-state-pipeline
Jul 13, 2026
Merged

ooctipus merged 5 commits into
isaac-sim:developfrom
ooctipus:zhengyuz/newton-state-pipeline

Conversation

@ooctipus

@ooctipus ooctipus commented Jul 4, 2026 •

Copy link
Copy Markdown
Collaborator

Description

Isaac Lab's Newton asset-data layer already handles lazy derived data correctly: authored joint or root writes invalidate _fk_timestamp, and the next dependent asset.data property calls SimulationManager.forward(). Several manager-level consumers bypass that timestamped layer and read Newton's live state directly, however. Rendering, public state access, and SceneData could therefore observe stale body_q/body_qd.

This change keeps the existing device-resident _world_reset_mask and _fk_reset_mask and the existing solver-specialized _eval_fk delegate. It makes forward() the single mask consumer at the missing boundaries:

  • step() calls it after any deferred graph preparation and immediately before the requested collision detection or solver execution.
  • pre_render() calls it before Fabric synchronization.
  • Newton get_state() and NewtonSceneDataBackend route raw-state reads through it while preserving the PhysX shadow-state path.
  • The solver-type _needs_fk_before_step gate is removed; the device masks now decide which articulations/worlds do work.

Deferred CUDA graph preparation retains its existing ordering ahead of authored-state reconciliation because its warmup and Kamino allocation-pinning replay mutate live solver state. Making capture preparation non-mutating is a separate concern.

CUDA-captured writers already replay the mask-update kernels. A single persistent render-replay marker also re-arms the host Fabric dirty flag when those writers may replay; this avoids introducing a second conditional CUDA graph or a generalized transaction object.

This PR is intentionally limited to refreshing Newton's derived body state. It does not add solver reset, synchronize solver-private mirrors such as sparse-cadence MuJoCo qpos/qvel, change coupled-solver ownership, or add particle-state handling. Those behaviors require focused backend or feature changes.

Type of change

  • Bug fix (non-breaking change)
  • Refactor (non-breaking change)

Testing

  • A real CUDA application regression creates a Newton RigidObject, writes a new root pose, calls SimulationContext.render() without a physics step or pose getter, and asserts the actual omni:fabric:worldMatrix consumed by Kit/RTX. It also replays the production graph-safe writer twice and checks both rendered transforms.
  • The complete Fabric synchronization module passes: 3 passed.
  • The exact application regression fails against the clean unpatched branch point at the Fabric transform assertion: all three translation components remain stale, with a maximum absolute error of 1.5 m.
  • The focused manager and visualization-state regression selections pass. A mock-only graph-order test was removed after review because it asserted infrastructure ordering rather than application behavior.
  • The amended ordering cleanup passes Python syntax parsing and git diff --check.
  • The broader manager abstraction run reached 56 passing tests. Its backend integration failures are caused by the local Newton/Warp/MuJoCo version mismatch and were reproduced on the untouched parent checkout.

Checklist

  • I have read and understood the contribution guidelines
  • I have added focused tests for the changed behavior
  • I have added a changelog fragment for the touched package
  • My name already exists in CONTRIBUTORS.md

@github-actions github-actions Bot added the isaac-lab Related to Isaac Lab team label Jul 4, 2026
@ooctipus ooctipus mentioned this pull request Jul 4, 2026
6 tasks done
@greptile-apps

greptile-apps Bot commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR consolidates task-authored rigid-state writes into a unified AuthoredStateTransaction, replacing the previous _world_reset_mask/_fk_reset_mask/_eval_fk triplet. FK and solver-specific synchronization now happen at explicit coherent boundaries (forward(), step(), pre_render(), and any public state read) rather than scattered across each backend's pre-step logic.

  • AuthoredStateTransaction (_authored_state_transaction.py): device-scalar-gated transaction with CUDA conditional-graph support; marks accumulate on the device so captured writers replay correctly without relying on host-side Python flags.
  • _cuda_graph.py: RTX-safe relaxed-mode graph capture extracted from newton_manager.py into a focused helper, reducing duplication and enabling reuse for the deferred state-graph path.
  • Backend hooks (kamino_manager.py, mjwarp_manager.py, mpm_manager.py): Kamino pre-registers state arrays via _register_builder_attributes (removing the post-capture double-launch workaround); MuJoCo gains _synchronize_solver_state for sparse update_data_interval configurations and a single-world guard for CPU MuJoCo; MPM drops _needs_fk_before_step.

Confidence Score: 4/5

Safe to merge for standard simulation configurations; the sparse MuJoCo update path and the manager-resolution null guard are the two fragile edges.

The refactor is well-structured and the 30-test suite covers the critical ordering and replay invariants. Two areas warrant a second look: _synchronize_solver_state calls private SolverMuJoCo._update_mjc_data, so a Newton-side rename would silently drop authored-state sync for sparse update_data_interval configs (stale qpos/qvel, no exception); and _resolve_active_manager returns None when sim.physics_manager is set to None, producing an opaque AttributeError in forward() during teardown or test isolation.

mjwarp_manager.py (_synchronize_solver_state, private method call) and newton_manager.py (_resolve_active_manager, null-safety gap).

Important Files Changed

Filename Overview
source/isaaclab_newton/isaaclab_newton/physics/_authored_state_transaction.py New device-backed transaction that coalesces authored rigid-state writes and flushes them at coherent boundaries via a CUDA conditional graph. Design is sound: device scalar gates the conditional, _host_pending is an early-exit hint for the eager path, and _writes_may_replay prevents premature short-circuit after any captured writer. Mask zeroing happens inside _consume so a failed _apply leaves masks for retry.
source/isaaclab_newton/isaaclab_newton/physics/_cuda_graph.py Faithful extraction of the RTX-compatible relaxed-capture helper from newton_manager.py. Logic is identical to the original; the only notable change is the loss of the explicit Warp-internals warning at the graph.graph = raw_graph mutation site.
source/isaaclab_newton/isaaclab_newton/physics/newton_manager.py Core refactor replacing the _world_reset_mask/_fk_reset_mask/_eval_fk triplet with the unified AuthoredStateTransaction. _resolve_active_manager has a null-safety gap when sim.physics_manager is None. All flush boundaries are correctly covered.
source/isaaclab_newton/isaaclab_newton/physics/mjwarp_manager.py Adds CPU-MuJoCo single-world guard, _state_write_graph_safe, _supports_cuda_graph_capture, and _synchronize_solver_state. The sparse-update path calls a private Newton method whose graph-safety contract is implicit.
source/isaaclab_newton/isaaclab_newton/physics/kamino_manager.py Adds _register_builder_attributes to pre-register Kamino state arrays before model finalization, replacing the post-capture double-launch workaround. Removes _needs_fk_before_step = True. Clean change.
source/isaaclab_newton/test/physics/test_newton_state_pipeline.py New 624-line focused unit suite covering transaction mark/flush/consume semantics, CUDA conditional-graph replay, render-domain re-arming, model-change fan-out, solver-specific state-sync policy, CPU MuJoCo single-world guard, and ordering invariants between deferred capture, flush, and physics graph capture.

Sequence Diagram

%%{init: {'theme': 'neutral'}}%%
sequenceDiagram
    participant Asset as Asset write
    participant TXN as AuthoredStateTransaction
    participant NM as NewtonManager
    participant BE as Backend hook
    participant WP as Warp / CUDA graph

    Asset->>NM: invalidate_fk(env_mask, articulation_ids)
    NM->>TXN: mark_rigid(...)
    TXN->>WP: _mark_from_mask kernel sets world_mask, fk_mask, pending
    note over TXN: _host_pending=True

    alt step / forward / pre_render / get_state
        NM->>NM: _flush_pending_changes()
        NM->>TXN: flush()
        alt CUDA conditional graph READY
            TXN->>WP: capture_launch → conditional on pending
        else eager
            TXN->>WP: capture_if(pending, _consume)
        end
        TXN-->>BE: _apply_state_writes(world_mask, fk_mask)
        BE->>WP: _eval_fk_impl
        BE->>BE: _synchronize_solver_state
        TXN->>TXN: zero masks and pending
    end
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 Asset as Asset write
    participant TXN as AuthoredStateTransaction
    participant NM as NewtonManager
    participant BE as Backend hook
    participant WP as Warp / CUDA graph

    Asset->>NM: invalidate_fk(env_mask, articulation_ids)
    NM->>TXN: mark_rigid(...)
    TXN->>WP: _mark_from_mask kernel sets world_mask, fk_mask, pending
    note over TXN: _host_pending=True

    alt step / forward / pre_render / get_state
        NM->>NM: _flush_pending_changes()
        NM->>TXN: flush()
        alt CUDA conditional graph READY
            TXN->>WP: capture_launch → conditional on pending
        else eager
            TXN->>WP: capture_if(pending, _consume)
        end
        TXN-->>BE: _apply_state_writes(world_mask, fk_mask)
        BE->>WP: _eval_fk_impl
        BE->>BE: _synchronize_solver_state
        TXN->>TXN: zero masks and pending
    end
Loading

Reviews (1): Last reviewed commit: "Unify Newton authored-state synchronizat..." | Re-trigger Greptile

Comment on lines +84 to +89
# SolverMuJoCo currently exposes that operation only through its
# internal state-conversion helper.
if solver.update_data_interval != 1:
data = solver.mj_data if solver.use_mujoco_cpu else solver.mjw_data
if data is not None:
solver._update_mjc_data(data, cls._model, cls._state_0)

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 Reliance on private _update_mjc_data method

solver._update_mjc_data(...) is a single-underscore private method of SolverMuJoCo. The call site comment correctly acknowledges this, but there are two concrete risks: (1) any upstream Newton refactor that renames or restructures this method silently breaks authored-state sync for all non-default update_data_interval configurations — the failure mode is stale qpos/qvel, not an immediate exception; (2) the graph-safety contract of _update_mjc_data is unknown because it is private, yet this call ends up inside the authored-state conditional graph (captured because _state_write_graph_safe() returns True for GPU MuJoCo). If the helper performs host-side MuJoCo bookkeeping, it would be invalid inside a CUDA graph.

@ooctipus
ooctipus force-pushed the zhengyuz/newton-state-pipeline branch from 747bccd to a62f6ef Compare July 4, 2026 07:08
@ooctipus ooctipus changed the title Unify Newton authored-state synchronization Fix Newton derived-state refresh boundaries Jul 4, 2026
@ooctipus
ooctipus force-pushed the zhengyuz/newton-state-pipeline branch 3 times, most recently from 4ba2b62 to df3d1d1 Compare July 4, 2026 08:32
@ooctipus
ooctipus force-pushed the zhengyuz/newton-state-pipeline branch from df3d1d1 to baea2b2 Compare July 4, 2026 08:59
@ooctipus ooctipus mentioned this pull request Jul 4, 2026
7 tasks done
@kellyguo11 kellyguo11 moved this to Ready to merge in Isaac Lab Jul 7, 2026
ooctipus and others added 3 commits July 7, 2026 10:35
…state-pipeline

# Conflicts:
#	source/isaaclab/test/sim/test_newton_manager_visualization_state.py
develop's _reset_solver_internals now delegates the consumed world mask
to SolverBase.reset before forward() clears it, so the mock-driven test
must provide a solver; the mock records the delegated mask, which also
covers the new hook's mask forwarding.
@ooctipus
ooctipus merged commit 6eb3d3b into isaac-sim:develop Jul 13, 2026
60 of 66 checks passed
@github-project-automation github-project-automation Bot moved this from Ready to merge to Done in Isaac Lab Jul 13, 2026
matthewtrepte pushed a commit to matthewtrepte/IsaacLab that referenced this pull request Aug 4, 2026
# Description

Isaac Lab's Newton asset-data layer already handles lazy derived data
correctly: authored joint or root writes invalidate `_fk_timestamp`, and
the next dependent `asset.data` property calls
`SimulationManager.forward()`. Several manager-level consumers bypass
that timestamped layer and read Newton's live state directly, however.
Rendering, public state access, and SceneData could therefore observe
stale `body_q`/`body_qd`.

This change keeps the existing device-resident `_world_reset_mask` and
`_fk_reset_mask` and the existing solver-specialized `_eval_fk`
delegate. It makes `forward()` the single mask consumer at the missing
boundaries:

- `step()` calls it after any deferred graph preparation and immediately
before the requested collision detection or solver execution.
- `pre_render()` calls it before Fabric synchronization.
- Newton `get_state()` and `NewtonSceneDataBackend` route raw-state
reads through it while preserving the PhysX shadow-state path.
- The solver-type `_needs_fk_before_step` gate is removed; the device
masks now decide which articulations/worlds do work.

Deferred CUDA graph preparation retains its existing ordering ahead of
authored-state reconciliation because its warmup and Kamino
allocation-pinning replay mutate live solver state. Making capture
preparation non-mutating is a separate concern.

CUDA-captured writers already replay the mask-update kernels. A single
persistent render-replay marker also re-arms the host Fabric dirty flag
when those writers may replay; this avoids introducing a second
conditional CUDA graph or a generalized transaction object.

This PR is intentionally limited to refreshing Newton's derived body
state. It does not add solver reset, synchronize solver-private mirrors
such as sparse-cadence MuJoCo `qpos`/`qvel`, change coupled-solver
ownership, or add particle-state handling. Those behaviors require
focused backend or feature changes.

## Type of change

- Bug fix (non-breaking change)
- Refactor (non-breaking change)

## Testing

- A real CUDA application regression creates a Newton `RigidObject`,
writes a new root pose, calls `SimulationContext.render()` without a
physics step or pose getter, and asserts the actual
`omni:fabric:worldMatrix` consumed by Kit/RTX. It also replays the
production graph-safe writer twice and checks both rendered transforms.
- The complete Fabric synchronization module passes: `3 passed`.
- The exact application regression fails against the clean unpatched
branch point at the Fabric transform assertion: all three translation
components remain stale, with a maximum absolute error of 1.5 m.
- The focused manager and visualization-state regression selections
pass. A mock-only graph-order test was removed after review because it
asserted infrastructure ordering rather than application behavior.
- The amended ordering cleanup passes Python syntax parsing and `git
diff --check`.
- The broader manager abstraction run reached 56 passing tests. Its
backend integration failures are caused by the local Newton/Warp/MuJoCo
version mismatch and were reproduced on the untouched parent checkout.

## Checklist

- [x] I have read and understood the contribution guidelines
- [x] I have added focused tests for the changed behavior
- [x] I have added a changelog fragment for the touched package
- [x] My name already exists in `CONTRIBUTORS.md`

---------

Co-authored-by: Claude Sonnet 4.6 <[email protected]>
@ooctipus
ooctipus deleted the zhengyuz/newton-state-pipeline branch October 14, 2026 14:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

isaac-lab Related to Isaac Lab team

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants