Repository navigation
Apply Newton external wrenches on every solver substep - #8269
Conversation
The assets write state_0.body_f once per step, but the substep loop clears the input state's forces after every solver substep, so only the first substep received the wrench. Copy body_f at the start of each step and write it into the input state of every substep.
|
There was a problem hiding this comment.
Isaac Lab Review Bot
The force-staging fix is coherent across single-state, double-buffered, decimation, and graph-capture paths, with focused regression coverage. One minor style fix remains: the expanded _run_solver_substeps docstring narrates operations already evident from the loop and nearby documentation.
- Design and architecture:
NewtonManagerowns the staging buffer across initialization and teardown, and both solver-state modes reuse the same staging mechanism without introducing backend-specific branches. Staging once outside the decimation loop correctly preserves the authored force for the fullstep()call. - API: No public symbol, configuration field, export, or stub changed. The new staging state and helper methods are private internals, while state-force callbacks retain their ordering and add forces after the staged body force is restored.
- Compatibility and deprecation: Breaking changes: none identified. The observable change corrects external wrenches to act on every solver substep and folded decimation iteration while retaining one-write-per-
step()semantics. The package includes the required fix changelog fragment. - Implementation: The staging buffer is allocated before graph capture, copied from
state_0.body_fat each stepping boundary, and restored before each solver substep. The existing post-substep clearing and double-buffer copy/swap logic prevent force leakage into laterstep()calls and preserve the canonical state. - Style consistency: The class-state placement, lifecycle cleanup, and helper structure follow adjacent conventions. However, the added
_run_solver_substepsdocstring paragraph restates the loop sequence—restore staged forces, then invoke callbacks—and duplicates nearby rationale. Remove it or replace it with the non-obvious invariant that callbacks add on top of the staged force. - Test quality: The added regression test protects observable physics behavior and covers two distinct paths: MJWarp single-state substeps and Kamino double-buffering with folded decimation. Existing graph-capture and callback-order tests do not cover the multi-substep force-retention regression, so the new cases are warranted and not duplicative.
Minor fixes needed. Posted 1 actionable finding inline.
Automated review; human maintainers own approval decisions.
AntoineRichard
left a comment
There was a problem hiding this comment.
This looks like a reasonable fix considering the limitations in newton. Thanks @NeoZng. I'll open an issue in newton as well
|
run-ci |
|
run-ci |
|
Backported to |
# Description On Newton, the external wrenches of `Articulation`, `RigidObject` and `RigidObjectCollection` acted only on the first solver substep. The assets write `state_0.body_f` once per step, and `NewtonManager._run_solver_substeps` clears the input state's forces after every substep. A constant wrench therefore delivered 1/`num_substeps` of its impulse, and 1/(decimation x `num_substeps`) when Newton runs the decimation loop, which is the default for supported explicit actuators. `NewtonManager` now copies `state_0.body_f` at the start of each step and writes it into the input state of every solver substep, before the state-force callbacks (viewer picking) add their forces. The copy is allocated in `initialize_solver`, so graph capture allocates nothing. The forces are still cleared after each substep, so a write applies to exactly one `step()` call. Only `body_f` is staged; Isaac Lab writes no particle forces. Draft #8218 re-applies authored forces in its manager rewrite as well; this PR fixes the current manager, so the fix can also be backported. Fixes #8268 ## 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 `develop` ## Tests `test_staged_body_force_acts_on_every_solver_substep` in `source/isaaclab_newton/test/physics/test_newton_manager_abstraction.py` writes a `body_f` that cancels gravity on a 1 kg free body and checks that its velocity stays zero over one step: MJWarp (single state) with 2 substeps, and Kamino (double-buffered) with 3 substeps and a folded decimation of 2. On develop `qd_z` is -0.0245 and -0.0818 m/s. ``` pytest source/isaaclab_newton/test/physics/test_newton_manager_abstraction.py -k test_staged_body_force_acts_on_every_solver_substep # before: 2 failed after: 2 passed ``` The rest of the file and the external-force tests of the rigid object, rigid object collection and articulation pass. The repro in the issue prints 0.100 m/s for 1, 2 and 4 substeps. Cost: one `body_f` copy per step and one per substep; 4096 envs x 8 bodies, 2 substeps: 0.882 -> 0.886 ms per step (measured without a wrench, so both trees integrate the same motion). ## 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 --------- Co-authored-by: Mustafa H <[email protected]> (cherry picked from commit adeb1f2)
Description
On Newton, the external wrenches of
Articulation,RigidObjectandRigidObjectCollectionacted only on the firstsolver substep. The assets write
state_0.body_fonce per step, andNewtonManager._run_solver_substepsclears theinput state's forces after every substep. A constant wrench therefore delivered 1/
num_substepsof its impulse, and1/(decimation x
num_substeps) when Newton runs the decimation loop, which is the default for supported explicitactuators.
NewtonManagernow copiesstate_0.body_fat the start of each step and writes it into the input state of everysolver substep, before the state-force callbacks (viewer picking) add their forces. The copy is allocated in
initialize_solver, so graph capture allocates nothing. The forces are still cleared after each substep, so a writeapplies to exactly one
step()call. Onlybody_fis staged; Isaac Lab writes no particle forces.Draft #8218 re-applies authored forces in its manager rewrite as well; this PR fixes the current manager, so the fix
can also be backported.
Fixes #8268
Type of change
Release backport
developTests
test_staged_body_force_acts_on_every_solver_substepinsource/isaaclab_newton/test/physics/test_newton_manager_abstraction.pywrites abody_fthat cancels gravity on a1 kg free body and checks that its velocity stays zero over one step: MJWarp (single state) with 2 substeps, and Kamino
(double-buffered) with 3 substeps and a folded decimation of 2. On develop
qd_zis -0.0245 and -0.0818 m/s.The rest of the file and the external-force tests of the rigid object, rigid object collection and articulation pass.
The repro in the issue prints 0.100 m/s for 1, 2 and 4 substeps. Cost: one
body_fcopy per step and one persubstep; 4096 envs x 8 bodies, 2 substeps: 0.882 -> 0.886 ms per step (measured without a wrench, so both trees
integrate the same motion).
Checklist
pre-commitchecks withuv run isaaclab --formatsource/<pkg>/changelog.d/for every touched package (do not editCHANGELOG.rstor bump package versions — CI handles that)CONTRIBUTORS.mdor my name already exists there