Repository navigation
Fix Newton derived-state refresh boundaries - #6350
Conversation
Greptile SummaryThis PR consolidates task-authored rigid-state writes into a unified
Confidence Score: 4/5Safe 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:
Important Files Changed
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
%%{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
Reviews (1): Last reviewed commit: "Unify Newton authored-state synchronizat..." | Re-trigger Greptile |
| # 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) |
There was a problem hiding this comment.
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.
747bccd to
a62f6ef
Compare
4ba2b62 to
df3d1d1
Compare
df3d1d1 to
baea2b2
Compare
Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
…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.
# 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]>
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 dependentasset.dataproperty callsSimulationManager.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 stalebody_q/body_qd.This change keeps the existing device-resident
_world_reset_maskand_fk_reset_maskand the existing solver-specialized_eval_fkdelegate. It makesforward()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.get_state()andNewtonSceneDataBackendroute raw-state reads through it while preserving the PhysX shadow-state path._needs_fk_before_stepgate 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
Testing
RigidObject, writes a new root pose, callsSimulationContext.render()without a physics step or pose getter, and asserts the actualomni:fabric:worldMatrixconsumed by Kit/RTX. It also replays the production graph-safe writer twice and checks both rendered transforms.3 passed.git diff --check.Checklist
CONTRIBUTORS.md