Repository navigation
[Newton] Redesign Newton Manager [2d/N] - #8736
Conversation
d816383 to
138cda6
Compare
# 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: | PR | Stage | |---|---| | [2a/N] **#8733 (this PR)** | Move Newton simulation data onto NewtonBackend | | [2b/N] #8734 | Describe Newton solvers with solver specifications | | [2c/N] #8735 | Move Newton manager logic into backend functions | | [2d/N] #8736 | Capture Newton model changes and Torch work in the step | | [2e/N] #8737 | Run each Newton step as one step graph | This PR is the bottom of the stack and targets `main` directly. ## What this PR does Newton's `Model` stays the immutable description (like `mjModel`). **`NewtonBackend`** becomes the mutable data bound to one finalized model (like `mjData`): state, control, solver, collision pipeline, contacts, sensors, Newton actuators and reset masks. The manager reads and writes `backend.*` instead of private fields, and a hard reset closes the backend and finalizes a new one. - The simulation registry still owns the builder and backend: consumers call `sim.get_or_create_backend(NewtonBuilderCfg(...))` / `sim.get_or_create_backend(NewtonBackendCfg(...))` as before. `NewtonBackendCfg.class_type` is `NewtonBackend`, constructed through `instantiate`. - Replication outputs (`NewtonCloneRecord`, site index map, world transforms, source builders) are read through manager 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_sensor` return the Newton sensor. - `NewtonBuilderCfg` and `NewtonBackendCfg` move into their own `newton_builder_cfg.py` / `newton_backend_cfg.py`. - The per-solver manager subclasses and their hooks are unchanged apart from operating on the backend. ## Type of change - Breaking change. No deprecation shims: removed APIs are listed below with their replacements. ## Migration | Before | Now | |---|---| | `manager.get_model()`, `get_state_0()`, `get_state_1()`, `get_control()`, `get_contacts()` | `manager.backend.model`, `.state_0`, `.state_1`, `.control`, `.contacts` | | `manager._solver`, `_contacts`, `_collision_pipeline`, `_adapter`, `_world_reset_mask`, `_fk_reset_mask`, `kinematics_dirty` | `backend.solver`, `.contacts`, `.collision_pipeline`, `.actuators`, `.world_mask`, `.fk_mask`, `.kinematics_dirty` | | `get_num_envs()`, `get_dt()`, `get_solver_dt()` | `backend.model.world_count`, `backend.dt`, `backend.solver_dt` | | `cl_register_site(...)` | `register_site(...)` | | `add_frame_transform_sensor(...)` | construct `newton.sensors.SensorFrameTransform` on `backend.model` | | `add_contact_sensor` / `add_imu_sensor` returning a key or index | both return the Newton sensor | | private replication fields (`_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, NewtonBackendCfg` | `from isaaclab_newton.physics import NewtonBuilderCfg, NewtonBackendCfg` | | sensors re-registering sites / `body_qdd` on `STOP` | not needed; requests persist on the builder | ## Testing Every test file in its own process without Isaac Sim (Kit), compared with `main`: no file has more failures or fewer passes, apart from two tests removed with the deprecated accessors. Remaining failures also fail on `main` or need missing extras (Kit launcher tests, rl_games/sb3, `rerun`). Not run: Kit-only tests and the GB300, Rizon coffee and teapot examples. ## 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 --------- Co-authored-by: Maximilian Krause <[email protected]>
|
run-ci |
The cache checks compare against _sim_timestamp as on main; the stamp now folds in the backend state version, and the plain simulated time used for finite differencing moves to _sim_time.
_sim_timestamp is the plain simulated time again, as on main. Derived-data caches compare against _state_version, which every step and FK advance, so simulated time adds nothing to the key.
Type the graph keys, keep public backend methods before private ones, drop an unused test stub attribute, and fix stale callback names in a test and the changelog.
|
run-ci |
AntoineRichard
left a comment
There was a problem hiding this comment.
I'm not sure about the names of some methods actuator vs control, step_1 and step_2. The timestamps are not timestamps anymore for newton, but they still are for physx and ovphysx? Maybe we should also move all of them to this system in a future PR? If so can we open an issue so that we do not loose track of it?
Keep the pre_actuator/post_actuator callback names from main, since the hooks are defined by where they run relative to the Newton actuators. Rename _step1/_step2 to _before_actuators/_after_actuators.
|
@AntoineRichard Renamed in 5b11365: the callbacks keep the |
|
At examples/tablecloth.py:1376, looks like this call got missed in the rename. |
|
run-ci |
|
run-ci |
# Description Part 2d-ii of the Newton manager redesign ([overview](#8218 (comment))). Follows [2d/N] #8736 (merged). `NewtonSolver` was a class that was never instantiated: every call passed the solver configuration and Newton's solver back in, e.g. `cfg.class_type.pre_step(cfg, solver, state)`. It is now a driver built once from its configuration and model, so the backend calls `backend.solver_ops.pre_step(state)`. ## Changes - **`NewtonSolver(cfg, model, mode, env_template)`** stores `cfg` and builds Newton's solver into `native` through the overridable `build(model, mode, env_template)`. Per-solver methods (`init_state`, `pre_step`, `step`, `post_step`, `reset`, `eval_fk`, `check_step`, contact and capture queries) are instance methods, and each driver narrows `cfg` to its configuration type. - **Configuration-level hooks stay classmethods** (`solver_classes`, `prepare_builder`, `applied_deterministic_mode`, `shares_materials`, `coupling_error`, `fixed_tendon_control`): they need no built solver. - **`NewtonBackend.solver_ops`** holds the driver; `NewtonBackend.solver` stays Newton's solver. - **Couplers hold their entries' drivers.** `CouplerSolver` keeps one driver per entry and `CoupledMJWarpVBDSolver` keeps its rigid and soft drivers, instead of re-deriving them from configurations and `solver.solver(name)`. - MJWarp, Kamino, MPM, VBD, the coffee-task MPM solver, the teapot example's coupler and the Newton visualizer follow the new API. ## Breaking Custom solvers override `build(self, model, mode, env_template)` and instance methods such as `pre_step(self, state)`, reading `self.cfg` and `self.native`. Code that called `cfg.class_type.<method>(cfg, solver, ...)` calls `backend.solver_ops.<method>(...)`. ## Validation Targeted tests, one file at a time: `test_newton_manager.py` (50), `test_newton_solvers.py` (36), `test_vbd_core.py` (8), `test_mpm_reset_mask_contract.py` (4), `test_mjwarp_tendon_control.py` (10), `test_coupler.py` (66), `custom_coupling/test_manager.py` (9), `test_articulation.py` (42), `test_rigid_object.py` (22), asset contract tests (296 + 146), all passing. ## Type of change - Breaking change (existing functionality will not work without user modification) ## Checklist - [x] I have read and understood the contribution guidelines - [x] I have run the `pre-commit` checks with `./isaaclab.sh --format` - [x] I have added changelog fragments under each touched package's `changelog.d/`
Description
Part 2d of the Newton manager redesign (overview).
Follows [2c-iii/N] #8884 (merged) and folds in [2e/N] #8737. Builds on @maxkra15's captured-runtime work and its
regression coverage.
Newton's step folds the decimation loop even when some actuators cannot be captured, and the step, BVH refits, sensor
queries and derived asset data work inside a CUDA graph recorded by a caller, such as a whole environment step. Capture follows the Warp, Newton and MuJoCo Warp examples: Warp owns the capture
(
wp.ScopedCapture/wp.capture_launch), Torch actuators that are not graphable stay eager, and Warp's blockingstream orders work with Torch's default stream.
Changes
_before_actuators()(solverpre_step, collision,pre-actuator callbacks), the Newton actuators, then
_after_actuators()(post-actuator callbacks, solver substeps);_finish_step()runs post-step callbacks and sensors once. With capture-safe actuators the whole decimation loopreplays from one graph, as before. Actuators that cannot be captured (Torch networks) now run eagerly between captured
_before_actuatorsand_after_actuatorsgraphs instead of disabling the folded loop, sohandles_decimation()holds whenever Newton actuators run in the step. Registering a callback or reallocating contacts captures again.
NewtonBackend.step,refit_bvh, the Newton Warp renderer and the ray casterrecord their work into a caller's capture instead of starting or replaying their own graph. Recorded BVH refits run
on every replay, because replays cannot consult host timestamps. Solver status checks run only outside capture.
NewtonBackend.liveis true during a step and while a graph is recorded. Derived assetproperties (link velocities, COM poses, heading, projected gravity, body-frame velocities, state concatenations)
recompute on read in that interval, so step callbacks see the current substep and replays refresh them. Outside it
the timestamp caches apply as before. This replaces the
capture_unsafeguards that raised during capture.forward(),scene-data state read or step, through
NewtonBackend.notify_model_changes. Fixed-root pose writes queue their editinstead of notifying the solver on every write.
invalidate_fkmaps articulation-view rows to worlds throughmodel.articulation_world, so views over a subset or reordering of worlds reset the right worlds, and globalarticulations get FK without resetting the global world.
Performance
RTX PRO 6000 Blackwell, Warp 1.17.0,
mainate44437edc.isaaclab benchmark runtime --task <task> --num_envs 4096 --num_steps 1000 --warmup_steps 100 --visualizer none physics=newton_mjwarp, two alternating sequential rounds after awarm-up run (steps/s):
mainThis PR enables, rather than delivers, the larger gain: capturing the whole environment step, recorded by the caller,
in a later stage.
Testing
Targeted tests pass, run file by file: Newton manager, solvers, VBD, MJWarp tendon control, MPM reset masks,
coupler and custom coupling, visualization state, articulation and rigid object contracts, articulation, rigid object,
cable, joint coordinates, Newton actuators, BAM actuator, MPM object, contact sensor, frame transformer, ray caster,
IMU, cloner and the visualizer adapter. New coverage includes the decimation order with capture-safe and eager actuators, an outer capture of two backends side by side, FK over
reordered view rows with a global articulation, and a derived heading refreshed inside a replayed step.
Checklist
pre-commitchecks with./isaaclab.sh --format