Skip to content

[Newton] Generalize solver fault detection and replace NIST reset workaround - #8917

Merged
ooctipus merged 19 commits into
isaac-sim:mainfrom
Fanxing-LI:fansing/newton-physics-fault
Nov 22, 2026
Merged

ooctipus merged 19 commits into
isaac-sim:mainfrom
Fanxing-LI:fansing/newton-physics-fault

Conversation

@Fanxing-LI

@Fanxing-LI Fanxing-LI commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

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 backend timestamp, and all consumers share the cached mask. Coupled solvers use entry-local state mappings.
  • MuJoCo also checks qpos, qvel, qacc, qfrc_actuator, qacc_warmstart, qfrc_applied, ctrl, act and xfrc_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_fault exposes 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 in extras["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.
  • NIST configures this event before its state-reset event, retains direct observation terms and deletes its local solver_reset.py. Core environment and manager implementations remain unchanged.
  • Rename the backend state counter and asset accessors to timestamp / _timestamp, using the existing TimestampedBuffer convention without compatibility aliases.
@configclass
class EventsCfg:
    solver_fault_observations = EventTerm(
        func="isaaclab_newton.envs.mdp:zero_final_obs_on_solver_fault", mode="reset"
    )
    # Declare physics reset events below this term.

@configclass
class TerminationsCfg:
    solver_fault = DoneTerm(func="isaaclab_newton.envs.mdp:solver_fault")

@configclass
class RewardsCfg:
    # Declare task reward terms above this final term.
    solver_fault_reward = RewTerm(func="isaaclab_newton.envs.mdp:zero_reward_on_solver_fault", weight=1.0)

Validation

  • The GPU MJWarp fault regression passes with real event, observation and reward managers. It verifies terminal history-row masking for tensor and dictionary groups, preservation of healthy NaNs and source/history storage, one shared lazy scan, the no-final-observation case, and selective recovery matching a clean solve.
  • NIST configuration construction confirms the terminal-observation event precedes state reset. Core observation configuration, manager and tests are restored to upstream; the group callback API and its feature files are removed.
  • Earlier focused checks cover global-entity exclusion, body/joint/particle faults, CPU MuJoCo recovery, coupled entry mapping, and timestamp consumers across backend lifecycle, assets and benchmarks.
  • Repository formatting and pre-commit checks pass against upstream/main.
  • Restricted evaluation checkpoint references retain repository/revision/directory information without presenting inaccessible URLs as public links; the edited documentation page passes Lychee v0.24.2.

@Fanxing-LI
Fanxing-LI requested a review from a team November 3, 2026 11:22
@Fanxing-LI Fanxing-LI added bug Something isn't working asset New asset feature or request dev team Issue or pull request created by the dev team isaac-lab Related to Isaac Lab team infrastructure labels Nov 3, 2026
@github-actions github-actions Bot added the documentation Improvements or additions to documentation label Nov 3, 2026
@greptile-apps

greptile-apps Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 3/5

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

Findings

  1. P1 Failed worlds still spoil rewards ▶
  2. P1 Coupled worlds miss overflow resets ▶

Summary

Adds per-world physics fault checks and the physics_fault termination term.

  • Newton marks worlds with non-finite body states as faulted.
  • MuJoCo Warp flags worlds that exceed their constraint capacity.
  • Faulted Newton environments now trigger selective resets.

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]
Loading

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())

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.

P1 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)

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.

P1 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

@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

All reviewed code categories look good.

  • PR description: The title and body match the diff, but test/physics/test_newton_manager_abstraction.py is 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.

@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 @Fanxing-LI! Overall I like the idea, but I'm not sure this is the correct form. see comments below:

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.

Not sure if this fix is general enough to be all the way in the solver.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

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.

Do we need this much tests? I think adding a very simple one-line cpu only test in the solver test should be enough?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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

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:

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.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

@Fanxing-LI
Fanxing-LI force-pushed the fansing/newton-physics-fault branch from 21caef2 to 2638c13 Compare November 10, 2026 02:27
@maxkra15
maxkra15 self-requested a review November 11, 2026 11:10
@Fanxing-LI
Fanxing-LI force-pushed the fansing/newton-physics-fault branch from 2638c13 to 12aa303 Compare November 11, 2026 15:00

@maxkra15 maxkra15 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.

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 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 like this better! It looks mostly good to go, though it would be great if we could make the nan-checks optional for rewards.

Optional extras["final_obs"] is computed before reset, so it can still contain NaNs if a learner consumes it.

@Fanxing-LI

Fanxing-LI commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor Author

I like this better! It looks mostly good to go, though it would be great if we could make the nan-checks optional for rewards.

Optional extras["final_obs"] is computed before reset, so it can still contain NaNs if a learner consumes it.

@AntoineRichard
Done in 08b242c: ManagerBasedRLEnvCfg.drop_non_finite_values (default True) controls it and also sanitizes final_obs.

@Fanxing-LI

Copy link
Copy Markdown
Contributor Author

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.

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.

@Fanxing-LI
Fanxing-LI requested a review from maxkra15 November 20, 2026 02:34

@maxkra15 maxkra15 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.

reward regression covers the partial-reset case now, lg

Fanxing-LI and others added 7 commits November 20, 2026 23:14
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.
@ooctipus
ooctipus force-pushed the fansing/newton-physics-fault branch from 08b242c to d43a4e4 Compare November 21, 2026 07:29
@ooctipus ooctipus changed the title [Newton] Add physics_fault termination to reset only the faulted environments [Newton] Generalize solver fault detection and replace NIST reset workaround Nov 21, 2026
@ooctipus

Copy link
Copy Markdown
Collaborator

run-ci

@isaaclab-bot isaaclab-bot Bot added ci:run-docker Trigger the on-demand Docker and GPU CI workflow and removed ci:run-docker Trigger the on-demand Docker and GPU CI workflow labels Nov 22, 2026
@ooctipus
ooctipus merged commit 81c3302 into isaac-sim:main Nov 22, 2026
75 of 95 checks passed
ooctipus added a commit that referenced this pull request Nov 23, 2026
## 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

asset New asset feature or request bug Something isn't working dev team Issue or pull request created by the dev team documentation Improvements or additions to documentation infrastructure isaac-lab Related to Isaac Lab team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants