Skip to content

Refactor NewtonManager into solver-specific subclasses - #5439

Merged
AntoineRichard merged 31 commits into
isaac-sim:developfrom
mmichelis:mym/newton_manager_abstraction
May 5, 2026
Merged

AntoineRichard merged 31 commits into
isaac-sim:developfrom
mmichelis:mym/newton_manager_abstraction

Conversation

@mmichelis

Copy link
Copy Markdown
Contributor

Description

Refactors :class:~isaaclab_newton.physics.NewtonManager from a single class with a solver_type if/elif ladder into a solver-agnostic abstract base with one concrete subclass per supported solver:

  • :class:~isaaclab_newton.physics.NewtonMJWarpManager
  • :class:~isaaclab_newton.physics.NewtonXPBDManager
  • :class:~isaaclab_newton.physics.NewtonKaminoManager
  • :class:~isaaclab_newton.physics.NewtonFeatherstoneManager

Each *SolverCfg now declares a class_type field pointing at its matching manager subclass. NewtonCfg.__post_init__ propagates solver_cfg.class_type onto NewtonCfg.class_type so that SimulationContext resolves the right manager through the existing dispatch path. Solver construction is replaced by polymorphic dispatch on _build_solver rather than branching inside initialize_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 NewtonManager behind if 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

NewtonCfg(solver_cfg=MJWarpSolverCfg(...))

keeps working — class_type is wired up automatically.

Type of change

  • New feature (non-breaking change which adds functionality)

Checklist

  • I have read and understood the contribution guidelines
  • I have run the pre-commit checks with ./isaaclab.sh --format
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • I have updated the changelog and the corresponding version in the extension's config/extension.toml file
  • I have added my name to the CONTRIBUTORS.md or my name already exists there

@github-actions github-actions Bot added the isaac-lab Related to Isaac Lab team label Apr 29, 2026

@isaaclab-review-bot isaaclab-review-bot Bot left a comment

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.

🤖 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_type resolution — no changes needed to core framework.
  • External readers: Code that reads NewtonManager._solver, ._model, ._state_0 directly will continue working because lifecycle methods assign through the explicit base class (NewtonManager._foo = ...).
  • Sensor/asset integration: Unchanged — they import NewtonManager and 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_solver being called with correct contacts argument
  • No regression test for MuJoCo internal-contacts mode actually receiving None contacts

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 None

The 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-apps

greptile-apps Bot commented Apr 29, 2026 •

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR refactors NewtonManager from a monolithic class with if solver_type == branches into an abstract base with four concrete subclasses (NewtonMJWarpManager, NewtonXPBDManager, NewtonFeatherstoneManager, NewtonKaminoManager), each owning its own file and _build_solver implementation. The public API is unchanged, and NewtonCfg.__post_init__ correctly auto-derives class_type from solver_cfg.class_type with proper guards for None solver and manual class_type override. The overall design is sound and the previous review findings (dead isinstance guard, stale TODO, __post_init__ null guard, and the removed public method) have been addressed in the current code.

Confidence Score: 5/5

Safe 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

Filename Overview
source/isaaclab_newton/isaaclab_newton/physics/newton_manager.py Refactored to abstract base with polymorphic _build_solver, _step_solver, _solver_specific_clear, and _log_solver_debug hooks; get_solver_convergence_steps public method preserved via hasattr delegation.
source/isaaclab_newton/isaaclab_newton/physics/newton_manager_cfg.py NewtonCfg.post_init correctly guards against manual class_type and missing solver_cfg; auto-propagates solver_cfg.class_type to NewtonCfg.class_type.
source/isaaclab_newton/isaaclab_newton/physics/kamino_manager.py Introduces NewtonKaminoManager with correct _build_solver, _forward_kamino, and Kamino-specific CUDA graph logic, but step() largely duplicates NewtonManager.step() creating a maintenance burden.
source/isaaclab_newton/isaaclab_newton/physics/mjwarp_manager.py Clean specialization: filters solver kwargs via inspect.signature, cross-validates collision_cfg conflict, and correctly handles both MuJoCo-internal and Newton-pipeline contact modes.
source/isaaclab_newton/isaaclab_newton/physics/featherstone_manager.py Minimal correct specialization; always uses CollisionPipeline and separate states.
source/isaaclab_newton/isaaclab_newton/physics/xpbd_manager.py Minimal correct specialization; always uses CollisionPipeline and separate states.
source/isaaclab_newton/test/physics/test_newton_manager_abstraction.py Comprehensive tests covering class_type wiring, hierarchy contracts, and end-to-end solver initialisation for all four solver variants.

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
Loading

Reviews (3): Last reviewed commit: "Style: Add explicit error when no solver..." | Re-trigger Greptile

@isaaclab-review-bot isaaclab-review-bot Bot left a comment

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.

🤖 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_fk inconsistency in kamino_manager.py:91 now correctly uses cls._state_0 for the output argument (line 91 shows cls._state_0 consistently).
  • ⚠️ Not addressed: The Kamino step() 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_graph asymmetry in Kamino manager remains (standard path does replay at line 144, deferred path relies on step() to do it).
  • ✅ Addressed: The _step_solver docstring 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.

@ooctipus

Copy link
Copy Markdown
Collaborator

nice refactor, maybe can we not overuse word manager? maybe just call it kamino_solver, mujoco_solver, ....

@AntoineRichard AntoineRichard left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's a good first step!

@isaaclab-review-bot isaaclab-review-bot Bot left a comment

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.

🤖 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: Kamino step() duplicates ~60 lines from base class (maintainability concern, not a bug)
  • ⚠️ Still present: _capture_or_defer_cuda_graph asymmetry in Kamino manager (replay in standard path at line 144, deferred path relies on step())

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.

@mmichelis

Copy link
Copy Markdown
Contributor Author

nice refactor, maybe can we not overuse word manager? maybe just call it kamino_solver, mujoco_solver, ....

@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?

@isaaclab-review-bot isaaclab-review-bot Bot left a comment

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.

🤖 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.

@mmichelis
mmichelis force-pushed the mym/newton_manager_abstraction branch from f55b0ec to 2e1efe5 Compare May 4, 2026 17:07

@isaaclab-review-bot isaaclab-review-bot Bot left a comment

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.

🤖 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.

@mmichelis

Copy link
Copy Markdown
Contributor Author

@greptile

@isaaclab-review-bot isaaclab-review-bot Bot left a comment

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.

🤖 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.

@mmichelis
mmichelis force-pushed the mym/newton_manager_abstraction branch from 2564413 to d04561c Compare May 5, 2026 07:28
@mmichelis

Copy link
Copy Markdown
Contributor Author

@greptile

@isaaclab-review-bot isaaclab-review-bot Bot left a comment

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.

🤖 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 AntoineRichard left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @mmichelis looks great. Let's get this in!

@isaaclab-review-bot isaaclab-review-bot Bot left a comment

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.

🤖 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.

@isaaclab-review-bot isaaclab-review-bot Bot left a comment

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.

🤖 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.

@AntoineRichard
AntoineRichard merged commit 632d05f into isaac-sim:develop May 5, 2026
34 checks passed
kellyguo11 added a commit that referenced this pull request May 20, 2026
…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]>
@mmichelis
mmichelis deleted the mym/newton_manager_abstraction branch May 22, 2026 09:26
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

None yet

Development

Successfully merging this pull request may close these issues.

3 participants