Repository navigation
Refactor NewtonManager into solver-specific subclasses - #5439
Conversation
There was a problem hiding this comment.
🤖 Isaac Lab Review Bot
Summary
This PR refactors NewtonManager from a monolithic class with solver-type branching into an abstract base class with four concrete subclasses (NewtonMJWarpManager, NewtonXPBDManager, NewtonFeatherstoneManager, NewtonKaminoManager). The dispatch mechanism uses class_type propagation from *SolverCfg through NewtonCfg.__post_init__. The implementation is architecturally sound, but there are critical correctness issues in the Kamino manager's duplicated step logic and missing state assignment patterns.
Architecture Impact
- SimulationContext dispatch: Works through existing
class_typeresolution — no changes needed to core framework. - External readers: Code that reads
NewtonManager._solver,._model,._state_0directly will continue working because lifecycle methods assign through the explicit base class (NewtonManager._foo = ...). - Sensor/asset integration: Unchanged — they import
NewtonManagerand read class attributes. - Risk: The Kamino subclass overrides
step()entirely rather than just the solver-specific parts, creating maintenance burden and subtle divergence risks.
Implementation Verdict
Significant concerns — The Kamino manager duplicates ~60 lines of step logic that will drift from the base class. There's also a bug in _step_solver where contacts are passed incorrectly for MuJoCo internal-contacts mode.
Test Coverage
Good parametrized coverage of the dispatch wiring (test_solver_cfg_class_type_resolves_to_subclass, test_newton_cfg_post_init_propagates_class_type). The end-to-end test (test_initialize_solver_populates_canonical_state) validates solver construction and one step. However:
- No test for the Kamino-specific
step()override behavior (warm-start reset) - No test for
_step_solverbeing called with correct contacts argument - No regression test for MuJoCo internal-contacts mode actually receiving
Nonecontacts
CI Status
No CI checks available yet — cannot verify tests pass.
Findings
🔴 Critical: kamino_manager.py:91-92 — eval_fk passes wrong state output argument
eval_fk(cls._model, cls._state_0.joint_q, cls._state_0.joint_qd, NewtonManager._state_0, cls._fk_reset_mask)This mixes cls._state_0 (input) with NewtonManager._state_0 (output). While they currently resolve to the same object, this is inconsistent with the base class at newton_manager.py:389 which uses cls._state_0 for both. If a subclass ever shadows _state_0, this will silently write to the wrong state. Should be cls._state_0 for consistency.
🔴 Critical: newton_manager.py:1033-1035 — _step_solver always passes cls._contacts for collision-pipeline solvers, but MuJoCo internal-contacts mode expects contacts to be populated differently
def _step_solver(cls, state_0: State, state_1: State, control: Control, substep_dt: float) -> None:
contacts = cls._contacts if cls._needs_collision_pipeline else None
cls._solver.step(state_0, state_1, control, contacts, substep_dt)When _needs_collision_pipeline=False (MuJoCo internal contacts), this passes None to solver.step(). However, mjwarp_manager.py:64-71 allocates NewtonManager._contacts specifically for update_contacts() later. The solver step itself handles contacts internally, so None is correct for the step call, but the logic is fragile — if _contacts is allocated before _step_solver runs (which it is in _initialize_contacts), readers might assume it's populated during stepping. This isn't a bug but the comment at line 1030 is misleading.
🟡 Warning: kamino_manager.py:49-109 — Entire step() method is duplicated from base class
The Kamino manager overrides step() with ~60 lines that are nearly identical to the base class, just with _forward_kamino() added at the start. This violates DRY and will cause maintenance drift. The base class should provide a hook (e.g., _pre_step_solver()) that Kamino overrides, rather than duplicating the entire method. Future fixes to base step() (e.g., new model-change handling, timing changes) won't propagate to Kamino.
🟡 Warning: newton_manager.py:1019-1024 — Abstract _build_solver has incorrect signature in docstring
def _build_solver(cls, model: Model, solver_cfg) -> tuple[SolverBase | None, bool, bool]:The solver_cfg parameter has no type hint, but the docstring says it's "the manager-specific NewtonSolverCfg subclass." The actual subclass implementations use specific types (MJWarpSolverCfg, etc.). Consider using NewtonSolverCfg as the base type annotation for clarity.
🟡 Warning: kamino_manager.py:117-154 — _capture_or_defer_cuda_graph duplicates base class with Kamino-specific replay
The Kamino manager overrides _capture_or_defer_cuda_graph() to add wp.capture_launch(cls._graph) after standard capture. However, this same replay is also done in Kamino's step() at line 80-82 during deferred capture. The standard-mode path at line 144 does the replay, but the deferred path at lines 146-153 does NOT do it here (it's done in step() instead). This asymmetry is confusing and error-prone.
🔵 Improvement: newton_manager.py:434-480 — clear() should call cls._solver_specific_clear() before clearing base state
Currently _solver_specific_clear() is called at the end of clear(). If a subclass's clear method needs to reference cls._solver or other state before it's nulled, the ordering matters. Consider calling it first, or documenting the expected order.
🔵 Improvement: test_newton_manager_abstraction.py:265-266 — Kamino internal-contacts case skips _contacts assertion without explanation
if expected_solver_cls is not SolverKamino:
assert NewtonManager._contacts is not NoneThe comment says "Kamino with internal contacts does not currently set NewtonManager._contacts" but this is a semantic gap — should Kamino set _contacts for contact sensor reporting? The test documents current behavior but doesn't verify it's intentional.
🔵 Improvement: newton_manager_cfg.py:519-536 — __post_init__ validation duplicates runtime validation
The cross-config validation (use_mujoco_contacts=True + collision_cfg) is now done in NewtonCfg.__post_init__, but the original validation was in initialize_solver() (now removed). This is better (fail-fast at config time), but the error message text changed slightly — ensure any documentation referencing the old error is updated.
Greptile SummaryThis PR refactors Confidence Score: 5/5Safe to merge; the refactor is internally consistent, the public API is preserved, and prior review concerns are resolved. The abstraction is well-structured: each subclass correctly populates the canonical NewtonManager base-class slots, the post_init guard prevents misconfiguration, and get_solver_convergence_steps is retained as a public delegating method. The one remaining observation — NewtonKaminoManager.step() duplicating most of the base step() body — is a maintainability concern but does not introduce incorrect behavior today. source/isaaclab_newton/isaaclab_newton/physics/kamino_manager.py — the overridden step() mirrors the base class method almost entirely; future changes to NewtonManager.step() must be manually reflected here. Important Files Changed
Class Diagram%%{init: {'theme': 'neutral'}}%%
classDiagram
class NewtonManager {
<<abstract>>
+_solver: SolverBase
+_state_0: State
+_model: Model
+initialize()
+reset()
+step()
+_build_solver()*
+_step_solver()
+_solver_specific_clear()
+_log_solver_debug()
+get_solver_convergence_steps()
}
class NewtonMJWarpManager {
+_build_solver()
+_initialize_contacts()
+_log_solver_debug()
+_get_solver_convergence_steps()
}
class NewtonXPBDManager {
+_build_solver()
}
class NewtonFeatherstoneManager {
+_build_solver()
}
class NewtonKaminoManager {
+_build_solver()
+_forward_kamino()
+step()
+_capture_or_defer_cuda_graph()
}
NewtonManager <|-- NewtonMJWarpManager
NewtonManager <|-- NewtonXPBDManager
NewtonManager <|-- NewtonFeatherstoneManager
NewtonManager <|-- NewtonKaminoManager
Reviews (3): Last reviewed commit: "Style: Add explicit error when no solver..." | Re-trigger Greptile |
There was a problem hiding this comment.
🤖 Isaac Lab Review Bot
Summary
This is a follow-up review. The new commits address some previous concerns but introduce one new issue.
Previous Concerns Status
- ✅ Addressed: The
eval_fkinconsistency inkamino_manager.py:91now correctly usescls._state_0for the output argument (line 91 showscls._state_0consistently). ⚠️ Not addressed: The Kaminostep()method still duplicates ~60 lines from the base class (kamino_manager.py:49-109). This remains a maintenance risk.⚠️ Not addressed: The_capture_or_defer_cuda_graphasymmetry in Kamino manager remains (standard path does replay at line 144, deferred path relies onstep()to do it).- ✅ Addressed: The
_step_solverdocstring concern is moot — the return type annotation was already removed in the abstract method signature.
New Findings
🟡 Warning: newton_manager.py:1033 — Comment is stale/misleading
# By default one collision per timestep, not recomputed during substeps. None if manager does not own the
# collision pipeline (e.g. MuJoCo with ``use_mujoco_contacts=True``, which handles contacts internally).This comment is accurate but the variable contacts is a local that shadows the broader context. The next line passes contacts to solver.step(), but for MuJoCo internal-contacts mode, the solver ignores this parameter entirely and uses its own internal contact buffer. The comment could clarify that None is passed because the solver's step() signature requires a contacts argument but doesn't use it in internal-contacts mode.
Implementation Verdict
Minor fixes needed — The duplicated Kamino step() is a design choice (not a bug), and the remaining issues are documentation/maintainability concerns rather than correctness problems. The core refactor is sound and tests pass the parametrized matrix.
|
nice refactor, maybe can we not overuse word |
AntoineRichard
left a comment
There was a problem hiding this comment.
I think it's a good first step!
There was a problem hiding this comment.
🤖 Isaac Lab Review Bot
Summary
This is a follow-up review. The new commits (61bcace8) show no substantive changes from the previous review — the code structure remains identical.
Previous Concerns Status
⚠️ Still present: Kaminostep()duplicates ~60 lines from base class (maintainability concern, not a bug)⚠️ Still present:_capture_or_defer_cuda_graphasymmetry in Kamino manager (replay in standard path at line 144, deferred path relies onstep())
These are design tradeoffs rather than correctness issues. The Kamino-specific solver.reset() call genuinely needs to run before the shared logic, making full extraction non-trivial.
Implementation Verdict
Ship it — The refactor is architecturally sound, well-tested, and the remaining concerns are maintainability preferences rather than bugs. The test matrix comprehensively covers all solver configurations.
@ooctipus I originally wanted this, but since the backend is chosen based on if the manager starts with "newton..." or "physx..." the manager needs to start with newton for now. We could rework this as well, and maybe ideally have a backend property per manager that is read instead of the classname string search. Does that make sense? |
There was a problem hiding this comment.
🤖 Isaac Lab Review Bot
Summary
Follow-up review of commit f55b0ec1. No substantive code changes from the previous review — the diff appears identical to the earlier revision.
Previous Concerns Status
The two maintainability concerns noted previously (Kamino step() duplication and _capture_or_defer_cuda_graph asymmetry) remain as-is. These are acceptable design tradeoffs given Kamino's unique solver.reset() requirement.
Implementation Verdict
Ship it — The refactor is solid, test coverage is comprehensive, and no new issues introduced. Ready to merge.
f55b0ec to
2e1efe5
Compare
There was a problem hiding this comment.
🤖 Isaac Lab Review Bot
Summary
Follow-up review of commit 50bc1990. The diff is identical to the previous review — no substantive code changes detected.
Implementation Verdict
Ship it — Previous review approved, no new changes to evaluate. The refactor is ready to merge.
There was a problem hiding this comment.
🤖 Isaac Lab Review Bot
Summary
Follow-up review of commit 0f85150b. The diff is identical to the previous review — no substantive code changes detected between 50bc1990 and 0f85150b.
Implementation Verdict
Ship it — Previous review approved the refactor. No new changes to evaluate. The solver-specific manager subclass design is clean and well-tested.
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
…ractive scene) Co-authored-by: Copilot <[email protected]>
…y in NewtonManager and not subclass
…t reset, but the properties of the state are.
2564413 to
d04561c
Compare
There was a problem hiding this comment.
🤖 Isaac Lab Review Bot
Summary
Follow-up review of commit d04561c. The diff is identical to the previous review (0f85150b) — no substantive code changes detected.
Implementation Verdict
Ship it — The solver-specific manager subclass refactor remains clean and well-tested. No new issues introduced.
AntoineRichard
left a comment
There was a problem hiding this comment.
Thanks @mmichelis looks great. Let's get this in!
There was a problem hiding this comment.
🤖 Isaac Lab Review Bot
Summary
Follow-up review of commit 2f5bcf2. The diff is identical to the previous review — no substantive code changes detected since the last "Ship it" verdict.
Implementation Verdict
Ship it — The solver-specific manager subclass refactor remains clean, well-structured, and thoroughly tested. No new issues introduced.
There was a problem hiding this comment.
🤖 Isaac Lab Review Bot
Summary
Follow-up review of commit 1d3fc45. The diff is identical to the previous review — no substantive code changes detected since the last "Ship it" verdict.
Implementation Verdict
Ship it — The solver-specific manager subclass refactor remains clean and well-tested. No new issues introduced since the previous approval.
…ling (#5443) # Description Introduces experimental Newton-backend deformable simulation alongside the existing PhysX deformables, refactors deformable APIs to be backend-neutral, and adds the manager-based Franka soft-body lifting environment used to validate two-way coupling. ### Backend-neutral deformable APIs (`isaaclab`) - Moved deformable schemas, materials, spawners, and `DeformableObjectCfg` out of `isaaclab_physx` into `isaaclab.sim` / `isaaclab.assets` so user code imports a single backend-agnostic API. - **Breaking (PhysX):** `isaaclab_physx.sim.DeformableBodyPropertiesCfg`, `DeformableObjectSpawnerCfg`, `DeformableBodyMaterialCfg`, `SurfaceDeformableBodyMaterialCfg`, `spawn_deformable_body_material`, `define/modify_deformable_body_properties` and `isaaclab_physx.assets.DeformableObjectCfg` are now imported from `isaaclab.sim` / `isaaclab.assets`. See `docs/source/migration/migrating_deformables.rst`. - USD spawners now support assets that embed tetrahedral mesh data, with automatic surface-mesh extraction. - Added `pytetwild` dependency for tet-mesh generation. ### Newton manager abstraction (`isaaclab_newton`) - Added deformable registration hooks to Newton cloning + Fabric sync fixes for particle meshes and particle-only scenes. ### Experimental Newton deformables (`isaaclab_contrib.deformable`) - `DeformableObject` (Newton backend), `VBDSolverCfg`, and coupled solver configs `CoupledMJWarpVBDSolverCfg` / `CoupledFeatherstoneVBDSolverCfg` providing one- and two-way rigid–deformable coupling. - New docs: `docs/source/features/newton-physics-integration/using-vbd-solver.rst` (VBD solver tuning + Franka soft-body lift guidance). ### Tasks, demos, tutorials - Added `Isaac-Lift-Soft-Franka-v0` (manager-based), the documented rigid–deformable coupling task. - Updated `scripts/demos/deformables.py`, the `01_assets/run_deformable_object` tutorial, and `00_sim/spawn_prims` to use the backend-neutral API with selectable PhysX or Newton backends. - Added IK + video-record state-machine demo `scripts/environments/state_machine/lift_franka_soft.py`. Continues on #5439 adding VBD solver and coupled MJWarp + VBD solver as newton managers in isaaclab_contrib. Fixes #5285 ## Type of change - New feature (non-breaking change which adds functionality) - Breaking change: Moved deformable schemas, materials, spawners, and `DeformableObjectCfg` out of `isaaclab_physx` into `isaaclab.sim` / `isaaclab.assets` so user code imports a single backend-agnostic API. ## Test plan - [x] `./isaaclab.sh -p -m pytest source/isaaclab/test/sim/test_deformable_backend_split.py` - [x] `./isaaclab.sh -p -m pytest source/isaaclab_physx/test/assets/test_deformable_object.py` - [x] `./isaaclab.sh -p -m pytest source/isaaclab_contrib/test/deformable/` - [x] Run `scripts/demos/deformables.py` against PhysX and Newton backends - [x] Run `Isaac-Lift-Soft-Franka-v0` training for sanity-check rollout ## Checklist - [x] I have read and understood the [contribution guidelines](https://isaac-sim.github.io/IsaacLab/main/source/refs/contributing.html) - [x] I have run the [`pre-commit` checks](https://pre-commit.com/) with `./isaaclab.sh --format` - [x] I have made corresponding changes to the documentation - [x] My changes generate no new warnings - [x] I have added tests that prove my fix is effective or that my feature works - [x] I have updated the changelog and the corresponding version in the extension's `config/extension.toml` file - [x] I have added my name to the `CONTRIBUTORS.md` or my name already exists there --------- Signed-off-by: Mike Yan Michelis <[email protected]> Signed-off-by: Kelly Guo <[email protected]> Co-authored-by: Copilot <[email protected]> Co-authored-by: Donglai <[email protected]> Co-authored-by: Anka Chen <[email protected]> Co-authored-by: Kelly Guo <[email protected]> Co-authored-by: ooctipus <[email protected]> Co-authored-by: mingxueg <[email protected]>
Description
Refactors :class:
~isaaclab_newton.physics.NewtonManagerfrom a single class with asolver_typeif/elif ladder into a solver-agnostic abstract base with one concrete subclass per supported solver:~isaaclab_newton.physics.NewtonMJWarpManager~isaaclab_newton.physics.NewtonXPBDManager~isaaclab_newton.physics.NewtonKaminoManager~isaaclab_newton.physics.NewtonFeatherstoneManagerEach
*SolverCfgnow declares aclass_typefield pointing at its matching manager subclass.NewtonCfg.__post_init__propagatessolver_cfg.class_typeontoNewtonCfg.class_typeso thatSimulationContextresolves the right manager through the existing dispatch path. Solver construction is replaced by polymorphic dispatch on_build_solverrather than branching insideinitialize_solver.Motivation. The previous design forced every solver-specific concern (buffer allocation, contact-pipeline plumbing, Kamino's FK reset path, MJWarp's debug convergence logging) to live in
NewtonManagerbehindif solver_type == ...branches. Adding a new solver meant editing the base class. With the refactor each solver owns its own file and overrides only what it needs.User-facing API is unchanged. Existing user code such as
keeps working — class_type is wired up automatically.
Type of change
Checklist
pre-commitchecks with./isaaclab.sh --formatconfig/extension.tomlfileCONTRIBUTORS.mdor my name already exists there