Repository navigation
[Newton] Redesign Newton Manager [2a/N] - #8733
Conversation
The simulation registry owns the shared builder and the NewtonBackend again, as on main. Consumers request them with sim.get_or_create_backend(NewtonBuilderCfg(...)) and NewtonBackendCfg(...), so the get_newton_builder, get_newton_backend and create_newton_backend helpers are gone. NewtonBackendCfg.class_type is NewtonBackend, which takes the cfg, an optional builder and the physics dt. Managers are no longer constructed standalone: NewtonManager() takes no arguments and reads its configuration, device and timestep from the attached simulation, like the other physics managers. This removes the lazy cfg and builder properties and the get_physics_dt override. Independent backends remain possible by constructing NewtonBackend directly from a builder.
Drop the deprecation shims instead of carrying them: get_model, get_state_0, get_state_1, get_control, get_contacts, get_solver, get_num_envs, get_dt, get_solver_dt, cl_register_site and add_frame_transform_sensor. Callers read the NewtonBackend fields and use register_site; the changelog lists each removal as breaking with its replacement.
NewtonBuilderCfg and NewtonBackendCfg move from newton_manager_cfg to newton_builder_cfg and newton_backend_cfg, following the x.py/x_cfg.py layout used across Isaac Lab.
Restore main code that the backend move did not have to touch: the manager close order, decimation guards, docstrings and the visualizer test. Shorten the step-callback comments, and bind the model, state and control once in the asset data simulation bindings.
4df4734 to
01f3e09
Compare
[High impact] The change reaches Newton runtime access across Isaac Lab’s Newton features and integrations. The PR appears safe to merge, with a non-blocking contact-sensor cleanup issue. Findings
SummaryMoves model-bound Newton data from the manager onto
Diagram%%{init: {'theme': 'neutral'}}%%
flowchart LR
S[Simulation registry] --> B[Shared builder]
B --> N[NewtonBackend]
M[NewtonManager] --> N
N --> D[Model, states, control]
N --> R[Solver, contacts, sensors, actuators]
M --> C[Retained clone results]
M --> H[Hard reset]
H --> X[Close old backend]
X --> F[Finalize shared builder again]
F --> N
Reviews (1) · Last reviewed commit: "Trim the Newton backend change to what i..." · Reviewed by Greptile |
|
|
||
| try: | ||
| self._sensor_key = self._backend_manager.add_contact_sensor( | ||
| self._contact_view = self._backend_manager.add_contact_sensor( |
There was a problem hiding this comment.
Stopped sensors retain old handles
ContactSensor now stores the native sensor in _contact_view, but its STOP callback never clears that reference. Closing the backend empties backend.contact_sensors, while the Isaac Lab sensor keeps the old native sensor alive and exposes it through contact_view until initialization succeeds again.
Set _contact_view to None when STOP invalidates the sensor, as the IMU and frame transformer already do for their native handles.
Knowledge Base Used: Newton backend
There was a problem hiding this comment.
Fixed: STOP now clears _contact_view.
| class NewtonBuilderCfg: | ||
| """Share mutable construction data, populated before model allocation and retained across hard resets.""" | ||
|
|
||
| class_type: Callable[[NewtonBuilderCfg], ModelBuilder] | str = "{DIR}.newton_manager:create_newton_builder" |
There was a problem hiding this comment.
is this a class type or function?
There was a problem hiding this comment.
A factory function; it is documented on the field now.
SimulationContext builds its manager with instantiate(cfg.physics), so each manager receives its configuration in __init__ instead of reading sim.cfg.physics during initialize(). NewtonManager acquires the shared builder in initialize() and exposes it with the backend as plain attributes, which Newton-only consumers now read from sim.backend_manager.
Release the contact sensor's native handle on STOP, document the backend and clone record fields, finalize the shared builder inside NewtonBackend instead of taking an unused builder argument, and remove the uncalled get_clone_record accessor.
The builder is now created in NewtonManager.initialize(), before SimulationContext.instance() is set, so the coupler reads its entries from the solver configuration passed to the hook.
Integrate main at a9fb50e. Preserve capture-safe authored-state reads and custom clone namespaces while keeping Newton simulation data on its backend. Migrate the new MPM rendering helper to the backend model accessor.
|
run-ci |
Assign the custom solver to backend.solver in the extension example. Align the slot table and initialization contract with the backend owner.
|
run-ci |
# Description Part 2b of the Newton manager redesign ([overview](#8218 (comment))). Builds on [2a/N] #8733 (merged), which moved Newton's simulation data onto `NewtonBackend`. ## Summary There is now **one `NewtonManager` and one generic solver path for every Newton solver**. The six per-solver manager subclasses (`NewtonMJWarpManager`, `NewtonVBDManager`, ...) are gone. What differs per solver lives in a small, stateless **Isaac Lab solver** class (`MJWarpSolver`, `XPBDSolver`, ...) that the solver configuration selects through `class_type`. Newton's solver is never wrapped: `backend.solver` is Newton's solver. **Why:** most of what Isaac Lab does with a solver is the same for all of them: build it from its config, step it, reset masked worlds, run forward kinematics, collide with Newton's `CollisionPipeline`. The manager's own job (lifecycle, builder, hard reset, callbacks) doesn't depend on the solver at all. So: - `NewtonSolver` holds that generic path as class methods taking the config and Newton's solver; a subclass overrides only where its solver differs; - XPBD and Featherstone are three-line classes; - the solver classes hold no state, so Newton's solver is the only solver object; - a coupler builds each entry through that entry's own config. `CouplerCfg.outer_contact_entry` limits the outer collision pipeline to one entry's shape pairs. ## Before and after ```python # Choosing a solver: unchanged sim_cfg = SimulationCfg(physics=NewtonCfg(solver_cfg=MJWarpSolverCfg())) sim.backend_manager # always a NewtonManager sim.backend_manager.backend.solver # Newton's SolverMuJoCo: unchanged # A simple solver, before: a manager subclass. Now: a solver class and its config. class XPBDSolver(NewtonSolver): solver_class = SolverXPBD deterministic = True @configclass class XPBDSolverCfg(NewtonSolverCfg): class_type: type | str = "{DIR}.xpbd_solver:XPBDSolver" iterations: int = 2 # The manager calls them with the config and Newton's solver. solver_cls = solver_cfg.class_type backend.solver = solver_cls.build(solver_cfg, model, mode) solver_cls.reset(solver_cfg, backend.solver, backend.state_0, backend.world_mask) # A custom solver, before: subclass a manager and override its hooks. Now: subclass the solver. class MyMPMSolver(MPMSolver): @classmethod def build(cls, cfg, model, mode, env_template=None): return MyMPM(model, mpm_solver_config(cfg)) ``` ## What differs between solvers | Solver | Overrides | |---|---| | XPBD, Featherstone | nothing (Featherstone warns that it ignores inertia changes) | | VBD | builder coloring, BVH rebuild before and joint IK after each step | | MJWarp | MuJoCo contacts, warm-start reset, sensors off under determinism, tendon control | | Kamino | loop-closure FK through its reset, optional internal collision detector | | MPM | in-place stepping, collider projection, no per-world reset, grid capture check | | Couplers | build each entry's solver through the entry's own config | ## Breaking changes There are no deprecation shims. Each removal is listed in the changelog with its replacement. | Removed | Use instead | |---|---| | `NewtonMJWarpManager`, `NewtonXPBDManager`, `NewtonVBDManager`, `NewtonFeatherstoneManager`, `NewtonKaminoManager`, `NewtonMPMManager` | `NewtonManager`; the solver config's `class_type` selects `MJWarpSolver`, `XPBDSolver`, ... | | `NewtonSolverCfg.class_type` selecting a manager | it selects the `NewtonSolver`; a custom manager goes on `NewtonCfg.class_type` | | Overriding `_build_solver`, `_step_solver`, ... | Override `build`, `step`, `reset`, ... on a `NewtonSolver` subclass | | `NewtonManager.create_builder` | `isaaclab_newton.physics.create_builder` | | `NewtonManager.create_fixed_tendon_control(articulation)` | `NewtonSolver.fixed_tendon_control(cfg, articulation, model)` | | `NewtonMPMManager.reset_solver_state` | `reset_mpm_solver_state(backend, ...)` | | Contrib `NewtonCouplerManager`, `NewtonCoupledMJWarpVBDManager` | `CouplerSolver`, `CoupledMJWarpVBDSolver`; override `CouplerSolver.build_coupled` for a custom coupled solver | | Modules `mjwarp_manager`, `xpbd_manager`, ..., `*_manager_cfg` | `*_solver` / `*_solver_cfg`; import from `isaaclab_newton.physics` | ## Behavior changes - VBD's per-step preparation runs in both stepping paths, and VBD registers its Newton custom builder attributes. - When determinism is requested, MJWarp is built with its sensor stage disabled instead of raising, and the config is no longer modified. Tasks whose sensors need attributes only that stage fills (IMU/PVA `body_qdd`, joint wrench `body_parent_f`) still raise. - MJWarp with `use_mujoco_cpu=True` steps eagerly instead of capturing a CUDA graph. - `NewtonCfg.collision_cfg` is rejected for any solver that does not use Newton's collision pipeline: MJWarp with MuJoCo contacts (as before), Kamino with its own collision detector, and MPM. - `NewtonCfg.class_type=None` raises; omit it to use `NewtonManager`. - Couplers forward `NewtonCfg.debug_mode` diagnostics to their entries' solvers. - A coupler without proxies steps its entries independently; a coupled MPM entry that doesn't step in place raises. - Coupler `{ENV_REGEX_NS}` selectors expand against the environment template the manager passes in, not a global. ## Testing Targeted tests pass on the branch merged with current `main`: manager abstraction (106), coupler (66), coupler runtime, custom coupling, contrib coupling environments without Isaac Sim, VBD core, MPM reset contract and spawners, MJWarp tendon control, cloner, visualization state, the Newton visualizer tests, and the articulation contract (`-k newton`). The GB300, Rizon coffee, teapot and coupled MJWarp/VBD solvers resolve. Tests that need Isaac Sim (`test_manual_coupling`, `test_newton_solver_reset`, `test_newton_fabric_body_sync`, MPM rendering) were not run locally. ## 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 added changelog fragments
# Description On Newton, a hard `sim.reset()` closes the backend and rebuilds the model, but the sticky graph-replay flag `NewtonManager.transforms_may_change_on_graph_replay` carries over from the discarded graph. `forward()` then runs for the new model before `initialize_solver()` constructs its solver, so an asset pose read during the reset, such as one in a `PHYSICS_READY` callback, raises `RuntimeError: NewtonManager.initialize_solver() must run ...`. `_close_backend()` now clears the flag together with the graph it describes. `initialize_solver()` runs FK for the new model, so nothing pending is lost. The sensor-freshness part of the original PR (#8643) is covered on `main` by #8780 and #8782, and the pending-FK flag now lives on the backend that a hard reset recreates (#8733), so this PR is narrowed to the graph-replay flag. ## Type of change - Bug fix (non-breaking change which fixes an issue) ## Release backport - [x] <!-- backport-active-release --> Backport this pull request to the active release branch after it merges into `main` `release/3.0.0` predates #8733, so its backport clears `kinematics_dirty` and the graph-replay flag in `start_simulation()`. ## Tests `test_newton_manager_abstraction.py::test_reset_binds_consumers_before_constructing_the_solver` now sets the graph-replay flag before the hard reset and calls `forward()` in its `PHYSICS_READY` callback. On `main` (`9860e2bd86`) it fails with that `RuntimeError`; with this PR the file passes (106 passed). ## 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 `uv run isaaclab --format` - [ ] I have made corresponding changes to the documentation - [x] My changes generate no new warnings - [x] I have validated the changed behavior with focused coverage and applied the [test-audit criteria](https://github.com/isaac-sim/IsaacLab/blob/develop/skills/developer/test-audit/SKILL.md) to any test changes - [x] I have added a changelog fragment under `source/<pkg>/changelog.d/` for every touched package (do **not** edit `CHANGELOG.rst` or bump package versions — CI handles that) - [x] I have added my name to the `CONTRIBUTORS.md` or my name already exists there
# Description Part 2c of the Newton manager redesign ([overview](#8218 (comment))). Builds on [2a/N] #8733 and [2b/N] #8734 (both merged). ## Summary `NewtonManager`'s step, reset and contact logic moves onto `NewtonBackend`. A backend now holds everything one model's step needs and the methods that run it, so backends with different solvers can be built and stepped side by side without a manager or simulation context: ```python backend = NewtonBackend(NewtonBackendCfg(physics_cfg=cfg, device="cuda:0"), builder, dt=0.01) backend.init_solver() # solver, contacts, initial FK backend.invalidate_fk(env_mask, articulation_ids=ids) backend.step() # forward + step; captured as a CUDA graph after the first call backend.refit_bvh(timestamp) # shared BVHs, refit once per state ``` **Why:** - **Hard resets are correct by construction.** Step callbacks, solver-init callbacks, pending model changes, the outer-capture flag and the captured graph live on the backend, so they are discarded with the model instead of being cleared by hand in the manager. - **Several simulations per process.** No backend method reads manager or module state (`test_two_backends.py`: MJWarp and Featherstone stepped side by side, eager and captured, with reset masks isolated per backend). - **Groundwork for 2d/2e:** the step becomes one captured graph whose capture the caller can own. The manager keeps what outlives a model (builder, sites, clone record, decimation) and scene-data timestamps. Solver behavior goes through `solver_cfg.class_type` as in 2b. Behavior is unchanged, including the solver-init callback and initial-FK order. `NewtonQueries.run_query` combined a shared BVH refit with each consumer's query capture. It is split: the shared part is `backend.refit_bvh(timestamp)`, and the renderer and ray caster capture their own query, as the frame transformer already did. The Newton viewer now registers its picking forces with each new backend on a hard reset, since state-force callbacks belong to the backend. ## Breaking changes | Removed | Use instead | |---|---| | `NewtonQueries.run_query` | `backend.refit_bvh(timestamp)`, then capture the query with `newton_backend.capture_graph` | | `NewtonQueries.capture_graph`, `._refit_bvh` | `newton_backend.capture_graph`, `backend.refit_bvh` | | `NewtonManager.transforms_may_change_on_graph_replay` | `NewtonBackend.transforms_may_change_on_graph_replay` | | Manager privates (`_simulate_full`, `_graph`, `_post_step_callbacks`, ...) | `backend.step()`, `backend.graph`, `backend.post_step_callbacks`, ... | ## Performance `isaaclab benchmark runtime`, 4096 envs, `physics=newton_mjwarp`, 1000 steps, warm kernel cache, run sequentially: | Task | main | this PR | |---|---|---| | Cartpole | 2.65 M steps/s | 2.69 M steps/s | | Reach-Franka | 1.058 M steps/s | 1.054 M steps/s | | Flat ANYmal-D | 254.6 k steps/s | 254.6 k steps/s | ## Testing Targeted tests pass, run file by file: manager abstraction (106), two backends (3), Newton visualizer adapter, VBD core, MJWarp tendon control, MPM reset masks and object, coupler, coupler runtime, custom coupling, visualization state, articulation (incl. contract `-k newton`), joint coordinates, Newton actuators, BAM actuator, contact sensor, frame transformer, ray caster, IMU, cloner. Tests that need Isaac Sim (renderers, deformable object, `test_newton_solver_reset`) were not run locally. ## 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 added changelog fragments
Description
Part of the Newton manager redesign (overview with API examples:
#8218 (comment)). [1/N] #8711 (merged) made physics managers
instances owned by the simulation as
sim.backend_manager. The former [2/N] #8712 is split into five stacked PRs:This PR is the bottom of the stack and targets
maindirectly.What this PR does
Newton's
Modelstays the immutable description (likemjModel).NewtonBackendbecomes the mutable data boundto one finalized model (like
mjData): state, control, solver, collision pipeline, contacts, sensors, Newton actuatorsand reset masks. The manager reads and writes
backend.*instead of private fields, and a hard reset closes thebackend and finalizes a new one.
sim.get_or_create_backend(NewtonBuilderCfg(...))/sim.get_or_create_backend(NewtonBackendCfg(...))as before.NewtonBackendCfg.class_typeisNewtonBackend, constructed throughinstantiate.NewtonCloneRecord, site index map, world transforms, source builders) are read throughmanager accessors instead of private fields; site and extended-attribute requests persist on the builder across hard
resets, so sensors no longer re-register them.
add_contact_sensor/add_imu_sensorreturn the Newton sensor.NewtonBuilderCfgandNewtonBackendCfgmove into their ownnewton_builder_cfg.py/newton_backend_cfg.py.Type of change
Migration
manager.get_model(),get_state_0(),get_state_1(),get_control(),get_contacts()manager.backend.model,.state_0,.state_1,.control,.contactsmanager._solver,_contacts,_collision_pipeline,_adapter,_world_reset_mask,_fk_reset_mask,kinematics_dirtybackend.solver,.contacts,.collision_pipeline,.actuators,.world_mask,.fk_mask,.kinematics_dirtyget_num_envs(),get_dt(),get_solver_dt()backend.model.world_count,backend.dt,backend.solver_dtcl_register_site(...)register_site(...)add_frame_transform_sensor(...)newton.sensors.SensorFrameTransformonbackend.modeladd_contact_sensor/add_imu_sensorreturning a key or index_cl_site_index_map,_world_xforms,_cl_protos, ...)get_site_index_map(),get_world_xforms(),get_clone_source_builders(),get_clone_record()from isaaclab_newton.physics.newton_manager_cfg import NewtonBuilderCfg, NewtonBackendCfgfrom isaaclab_newton.physics import NewtonBuilderCfg, NewtonBackendCfgbody_qddonSTOPTesting
Every test file in its own process without Isaac Sim (Kit), compared with
main: no file has more failures or fewerpasses, apart from two tests removed with the deprecated accessors. Remaining failures also fail on
mainor needmissing extras (Kit launcher tests, rl_games/sb3,
rerun). Not run: Kit-only tests and the GB300, Rizon coffee andteapot examples.
Checklist
pre-commitchecks with./isaaclab.sh --format