Repository navigation
[Newton] Generalize solver fault detection and replace NIST reset workaround - #8917
Conversation
[Medium impact] The change affects fault handling in Newton-based vectorized environments. Fix non-finite rewards and missing fault checks in coupled solvers before merging. FindingsSummaryAdds per-world physics fault checks and the
Two gaps need fixes: failed worlds can still return non-finite rewards, and coupled solvers do not forward the new fault hook. Diagram%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Physics step] --> B[Check body state]
A --> C[Ask configured solver for faults]
B --> D[physics_fault mask]
C --> D
D --> E[Compute rewards before reset]
E --> F[Reset selected environments]
F --> G[Compute observations]
G --> H[Return observations and rewards]
Reviews (1) · Last reviewed commit: "Read the last substep's MuJoCo Warp over..." · Reviewed by Greptile |
| See :meth:`~isaaclab_newton.physics.NewtonManager.get_faulted_worlds`. Resetting such an environment restores | ||
| a valid state while the other environments keep running. | ||
| """ | ||
| return wp.to_torch(env.sim.backend_manager.get_faulted_worlds()) |
There was a problem hiding this comment.
Failed worlds still spoil rewards
physics_fault flags a failed world, but ManagerBasedRLEnv.step() computes rewards before resetting it. A reward such as lin_vel_z_l2 still reads the failed velocity and returns NaN or infinity. That reward reaches the learner even though terminated=True.
Add fault-aware reward handling before rewards are returned and logged. Test with a state-based reward; the new test uses rewards = {} and misses this path.
Knowledge Base Used: Manager-based environment orchestration
| outputs=[faulted], | ||
| device=self.device, | ||
| ) | ||
| solver_cfg.class_type.flag_faulted_worlds(solver_cfg, self.solver, faulted) |
There was a problem hiding this comment.
Coupled worlds miss overflow resets
get_faulted_worlds() calls the new hook only on the top-level solver. Both CouplerSolver and CoupledMJWarpVBDSolver inherit the empty default instead of forwarding it to their MJWarp solver. In either supported coupled setup, an njmax overflow that leaves body state finite goes unreported. physics_fault then leaves that world running with dropped constraints.
Forward the hook to the child solvers, as CouplerSolver.check_step() already does for step checks.
Knowledge Base Used: Newton backend
There was a problem hiding this comment.
Isaac Lab Review Bot
All reviewed code categories look good.
- PR description: The title and body match the diff, but
test/physics/test_newton_manager_abstraction.pyis absent; replace it with the actual validated test path. - Design and architecture: Architecture looks good.
- Scope and over-engineering: No over-engineering issues.
- API: API changes look good.
- Compatibility and deprecation: No breaking changes identified.
- Implementation: Implementation looks good.
- Style consistency: Style consistency looks good.
- Test quality: Test quality looks good.
No blocking issues. No inline findings.
Automated review; human maintainers own approval decisions.
There was a problem hiding this comment.
Thanks @Fanxing-LI! Overall I like the idea, but I'm not sure this is the correct form. see comments below:
There was a problem hiding this comment.
Not sure if this fix is general enough to be all the way in the solver.
There was a problem hiding this comment.
Agreed, and the new revision follows that. The MJWarp-specific part (njmax overflow through a NewtonSolver hook that only MJWarp implemented) is removed; overflow is already reported by MuJoCo Warp's own warning and is out of scope here. What remains lives in the backend only: a per-world check that a body pose or velocity in state_0 is finite, which every Newton solver exposes the same way, renamed get_non_finite_worlds as you suggested. Nothing is left in the solver classes.
There was a problem hiding this comment.
Do we need this much tests? I think adding a very simple one-line cpu only test in the solver test should be enough?
There was a problem hiding this comment.
Done. Replaced the environment test with a CPU stub test of NewtonBackend.get_non_finite_worlds in test_newton_manager.py (test_non_finite_worlds_flag_each_non_finite_body_component_and_skip_the_global_world); it covers a NaN translation, rotation and velocity each flagging their world, and a global-world body flagging nothing. The reset path it used to exercise is already owned by the existing environment and solver reset tests.
maxkra15
left a comment
There was a problem hiding this comment.
envs/mdp/terminations.py:25: termination runs before reward computation, but reset runs after it. A failed velocity still returns NaN reward and episode statistics. Handle that transition and add a real reward to the existing regression.
physics/newton_backend.py:525: forward fault reporting through both coupling owners. Their MJWarp overflow flags currently hit the empty default hook.
Rebase the hook onto current solver_ops instance methods.
| from isaaclab.envs import ManagerBasedRLEnv | ||
|
|
||
|
|
||
| def physics_fault(env: ManagerBasedRLEnv) -> torch.Tensor: |
There was a problem hiding this comment.
P1: physics_fault only marks termination. ManagerBasedRLEnv.step computes rewards immediately after terminations and before _reset_idx, and RewardManager neither masks faulted environments nor sanitizes their values. A non-finite body velocity therefore produces a non-finite lin_vel_z_l2 reward and episode sum, both of which reach the learner/logging despite the later successful reset. Handle the invalid transition before these values are returned/accumulated and extend the existing test with a state-based reward; rewards={} currently hides this failure.
There was a problem hiding this comment.
Addressed in 4e859cd. RewardManager.compute now runs nan_to_num_ on the per-term step rewards before the weighted sum and the episodic accumulation, so a non-finite term value counts as zero for that step and reaches neither the learner nor the Episode_Reward sums.
21caef2 to
2638c13
Compare
2638c13 to
12aa303
Compare
maxkra15
left a comment
There was a problem hiding this comment.
Both earlier P1 code fixes are verified. The requested reward regression is still missing. Extend existing test_compute with a NaN/Inf state-based reward; check zero contribution, finite episode sums and the next step after partial reset. No new scene or matrix. The Newton mask test never calls RewardManager. Resolve the failed task CI job too.
@AntoineRichard |
Added the reward regression to test_compute in f18413b. The failing tasks job was a main bug in CPU graph capture, fixed by #9013; merged main in 698db18 to pick it up. |
Flag the worlds holding a body whose pose or velocity is not finite after the last step, so a task can reset just those environments. The check reads the backend's state and needs no solver support.
The term terminates the environments whose solver state is not finite, so only those environments reset while the others keep running.
The CPU test of NewtonBackend.get_non_finite_worlds in test_newton_manager.py covers the check; the environment reset path it exercised is owned by the existing environment and solver reset tests.
A reward term evaluated on a diverged environment returns NaN or infinity, which reached the learner and the episodic sums because the environment computes rewards before it resets terminated environments. RewardManager.compute now counts such a value as zero for that step and reports how often it happened in the reset extras.
Add a state-based speed term that turns NaN and infinite for diverged environments: it contributes nothing on that step, the episodic sums stay finite, and the environment accumulates again after its reset.
ManagerBasedRLEnvCfg.drop_non_finite_values (default True) controls whether RewardManager counts a non-finite term value as zero and whether extras["final_obs"] is sanitized the same way before the reset, so a learner never consumes NaN from a diverged environment. Disabling it lets the values surface for debugging.
08b242c to
d43a4e4
Compare
|
run-ci |
## Summary Use Isaac Lab's shared `ResetStateSampler` for the NIST assembly reset bank. The NIST-owned `BalancedVariantScore` preserves the previous Beta weights and four row/column balancing passes; the shared `SuccessMonitor` still supplies each reset slot's success rate. Register the retained, reset-selectable task as `IsaacContrib-NIST-Franka`. Its composition root is `nist_env_cfg.py:NISTEnvCfg`, with `nist_env.py:NISTEnv`, `nist_scene_cfg.py:NISTSceneCfg`, and `NISTPPORunnerCfg`. Remove the former static Factory implementation and its aliases. The rename preserves the retained task's assembly logic, physics, actions, observations, and reset configuration. Following upstream #8917, solver-fault detection, reward clearing, and final-observation masking use the shared Newton terms; the task-local solver-reset helper is removed. The test for the retired Factory curriculum is removed with its implementation. The external USD assets remain at their existing `/Factory` path. ## Migration Use `--task IsaacContrib-NIST-Franka` for training and playback. Both `IsaacContrib-Factory-Franka` and `IsaacContrib-Factory-Variant-Franka` are retired. The PPO experiment name is now `nist`, and reset diagnostic keys use the `nist_` prefix. The former static task's checkpoints need their saved environment and agent configuration; its policy and observations are not automatically compatible with the retained task. ## Validation - NIST sampler tests: 4 passed on CPU/GPU, including a per-slot probability comparison with the previous formula. - Kitless canonical registration and old-ID/module absence test: passed after rebase. - NIST configuration check: shared solver-fault reset event precedes state reset; reward and termination use the shared Newton functions. - Environment documentation tests: 34 passed; the generated browser lists `IsaacContrib-NIST-Franka`. - Conflict-resolution format and lint hooks, changelog check against `upstream/main`, and generated-browser check: passed after rebase. - Before this rebase, the GPU environment smoke test passed; it has not been rerun on the rebased branch. The shared sampler uses independent per-environment random streams, so a fixed seed can select different exact reset slots while preserving the sampling probabilities. The bank still uses the 0.66 target, 50-outcome monitor, 1e-4 floor, four balancing passes, and uniform playback mode. Prior local GPU selection timing for 8,192 reset states and 4,096 environments: 0.146 ms for the shared sampler versus 0.205 ms for the previous Torch path (50 measured iterations after warmup, device synchronized after each batch). ## Base Rebased on upstream `main` at `6014f5416`, including the shared Newton solver-fault fix in #8917 and the G1 preview-link fix in #9169. No unmerged PR dependency remains.
Description
A Newton world can retain nonfinite MuJoCo solver history while its published body state remains finite. Move NIST's task-local fault detection into the Newton backend and solver integrations, and configure termination, reward clearing and observation masking through shared Newton MDP functions.
get_non_finite_worlds()checks body, joint and particle state, excluding global-world entities. Detection runs lazily once per backendtimestamp, and all consumers share the cached mask. Coupled solvers use entry-local state mappings.qpos,qvel,qacc,qfrc_actuator,qacc_warmstart,qfrc_applied,ctrl,actandxfrc_applied. Existing masked reset clears affected MJWarp worlds. CPU MuJoCo uses global solver history. Other solvers receive shared-state checks; their additional private history is outside this coverage.solver_faultexposes termination.zero_reward_on_solver_fault, configured last among nonzero reward terms, clears reward rows before summation and episode accumulation, without depending on a termination name.zero_final_obs_on_solver_fault, configured as the first reset event, zeros complete faulted rows inextras["final_obs"], including history. It runs before reset events rewrite physics state, preserves unflagged rows and unrelated NaNs, and does nothing when final observations are disabled. Normal reset clears histories and fresh observations are computed from the reset state.solver_reset.py. Core environment and manager implementations remain unchanged.timestamp/_timestamp, using the existingTimestampedBufferconvention without compatibility aliases.Validation
upstream/main.