Repository navigation
Conversation
Coalesce rigid state writes into a device-backed transaction consumed at step and coherent read boundaries. Keep solver-specific synchronization in backend hooks and preserve CUDA graph replay semantics.
Publish every rigid state write independently of asset cache invalidation, preserve partial collection selection, and flush pending synchronization before direct body-state reads.
Greptile SummaryThis PR completes the Newton authored-state boundary contract:
Confidence Score: 4/5The change is well-structured and the test coverage is thorough; the two friction points are a private-API call into SolverMuJoCo that could silently break on an upstream release, and Warp-internal field writes that are carried forward from the previous implementation. The authored-state transaction logic is cleanly isolated, correctly orders flush-before-step, and handles CUDA graph capture and replay properly. The
Important Files Changed
Sequence Diagram%%{init: {'theme': 'neutral'}}%%
sequenceDiagram
participant Asset as Asset (write_*_to_sim)
participant Data as *Data (_reset_pose/vel)
participant SimMgr as SimulationManager
participant AST as AuthoredStateTransaction
participant NM as NewtonManager
participant Solver as Solver (Kamino/MJWarp)
Asset->>Data: "_reset_pose(invalidate_cache=not skip_forward)"
alt "invalidate_cache=True"
Data->>Data: "reset_timestamps() + _fk_timestamp=-1"
end
Data->>SimMgr: invalidate_fk(env_ids, articulation_ids, articulation_selection)
SimMgr->>NM: _mark_transforms_dirty()
SimMgr->>AST: mark_rigid(env_mask/env_ids, articulation_ids, selection)
AST->>AST: launch _mark_from_mask/_mark_from_ids kernel
Note over NM,Solver: Coherent read boundary
alt step()
NM->>NM: _notify_solver_model_changes()
NM->>NM: _flush_pending_changes()
else forward() or sensor read
NM->>NM: _flush_pending_changes()
end
NM->>AST: flush()
AST->>AST: wp.capture_if(pending, _consume)
AST->>NM: _apply_state_writes(world_mask, fk_mask)
NM->>NM: _eval_fk_impl(world_mask, fk_mask)
NM->>Solver: _synchronize_solver_state(solver, world_mask, fk_mask)
AST->>AST: zero world_mask, fk_mask, pending
%%{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_*_to_sim)
participant Data as *Data (_reset_pose/vel)
participant SimMgr as SimulationManager
participant AST as AuthoredStateTransaction
participant NM as NewtonManager
participant Solver as Solver (Kamino/MJWarp)
Asset->>Data: "_reset_pose(invalidate_cache=not skip_forward)"
alt "invalidate_cache=True"
Data->>Data: "reset_timestamps() + _fk_timestamp=-1"
end
Data->>SimMgr: invalidate_fk(env_ids, articulation_ids, articulation_selection)
SimMgr->>NM: _mark_transforms_dirty()
SimMgr->>AST: mark_rigid(env_mask/env_ids, articulation_ids, selection)
AST->>AST: launch _mark_from_mask/_mark_from_ids kernel
Note over NM,Solver: Coherent read boundary
alt step()
NM->>NM: _notify_solver_model_changes()
NM->>NM: _flush_pending_changes()
else forward() or sensor read
NM->>NM: _flush_pending_changes()
end
NM->>AST: flush()
AST->>AST: wp.capture_if(pending, _consume)
AST->>NM: _apply_state_writes(world_mask, fk_mask)
NM->>NM: _eval_fk_impl(world_mask, fk_mask)
NM->>Solver: _synchronize_solver_state(solver, world_mask, fk_mask)
AST->>AST: zero world_mask, fk_mask, pending
|
| outputs=[self._world_mask, self._fk_mask, self._pending], | ||
| device=self._device, | ||
| ) | ||
| elif articulation_ids is not None and env_ids is not None: | ||
| selection = self._empty_selection if articulation_selection is None else articulation_selection | ||
| wp.launch( | ||
| _mark_from_ids, | ||
| dim=env_ids.shape[0], | ||
| inputs=[env_ids, articulation_ids, selection, int(articulation_selection is not None)], | ||
| outputs=[self._world_mask, self._fk_mask, self._pending], | ||
| device=self._device, | ||
| ) | ||
| else: | ||
| # No selection means every world and articulation. | ||
| self._world_mask.fill_(True) | ||
| self._fk_mask.fill_(True) | ||
| self._pending.fill_(1) | ||
|
|
||
| def configure_capture(self, graph_safe: bool, defer: bool = False, enabled: bool = True) -> None: | ||
| """Configure the reusable conditional graph for the active backend.""" | ||
| self._graph = None | ||
| self._graph_safe = graph_safe | ||
| self._capture_state = _CaptureState.DISABLED |
There was a problem hiding this comment.
Redundant
articulation_ids is not None guards after early return
The early return at line 153–157 already handles the articulation_ids is None case. The subsequent if articulation_ids is not None and env_mask is not None / elif articulation_ids is not None and env_ids is not None checks always have articulation_ids is not None as true at that point, making the repeated test a no-op. This can be simplified to if env_mask is not None / elif env_ids is not None to make the branching intent clearer without changing behavior.
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!
|
Closing this implementation because it depends on the discarded authored-state transaction foundation. The proven NewtonSiteFrameView freshness issue will be handled separately as a minimal boundary fix. |
Description
This completes the authored rigid-state boundary contract on top of #6350.
State writers now separate two responsibilities:
skip_forward=Truepreserves the caller-managed asset-cache behavior.Partial
RigidObjectCollectionwrites preserve their selected body columns when marking articulations, including a no-op fast path for empty selections. Direct consumers of live Newton body state—site frames, PVA, ray-caster site transforms, and joint-wrench conversion—flush pending synchronization before reading.This PR does not add optional solver reset, particle-state publication, or coupled deformable synchronization.
Depends on #6350. The commit is intentionally isolated so the displayed diff will reduce to this boundary layer once the dependency merges.
Type of change
Testing
compileall, andgit diff --checkpass.Checklist
CONTRIBUTORS.md