Skip to content

fix(loop-interpolation): report failed solves, keep the chosen solver, NaN for NaN points - #413

Merged
lachlangrose merged 4 commits into
masterfrom
fix/interp-solver-status
Nov 26, 2026
Merged

lachlangrose merged 4 commits into
masterfrom
fix/interp-solver-status

Conversation

@lachlangrose

Copy link
Copy Markdown
Member

Fixes five problems found in a repo audit. Several of them meant a solve that did not converge, or that failed, was used as the result with no warning.

  • lsmr at its iteration limit counted as success. Stop code 7 is now a failure, with a warning. Example: maxiter=2 returned True and up_to_date=True with a field value of 0.229 where the data says 1.0.
  • admm without inequalities always failed. The fallback checked Q is None, but the matrix is (0, dof). solve_system now switches to lsmr up front, in one solve. The first version called solve_system("lsmr") recursively and scaled the result twice; review caught this. It also drops the admm-only kwargs, so admm_abs_tol no longer raises TypeError.
  • A failed solve was silently replaced by a different solver. update() re-solved with the default cg and default kwargs. solve_system now stores the requested solver and kwargs, and update() reuses them. A failed re-solve is not repeated on every evaluate: it runs again only after the constraints, the setup or up_to_date change, and it logs one warning.
  • NaN input points evaluated to 0. They now give NaN for both value and gradient, the same as points outside the box.
  • FDI built an unused KD-tree weighting on every setup (9.7 s at 2M nodes). It is now built only when use_regularisation_weight_scale is on, as P1 already does.

Behaviour change: an lsmr solve that hits a user-set maxiter now reports failure and up_to_date=False, where before the field was kept silently. Default configs are not affected: the builder's default solver is cg, and lsmr's default maxiter converged on the claudius model.

Overlap: #378 and #379 have the Q is None line as context, so expect a one-line conflict there.

Tests: packages/loop_interpolation/tests/test_solver_status.py adds 6 tests; each failed before its fix. Targeted package tests: 115 passed, 8 skipped. test_fault_restoration_uses_current_frame[FDI] passes, with the same number of solves as master (9). The full loop_interpolation and LoopStructural suites were not run locally because they are too slow; please rely on CI. Reviewed by a second agent; the review's two findings are fixed in 89723de and 0ff3dc0.

🤖 Generated with Claude Code

lachlangrose and others added 4 commits November 25, 2026 18:09
…in update

- lsmr at the iteration limit (istop 7) now returns False and logs a warning.
- admm with no inequality rows now falls back to lsmr (Q has 0 rows, not None).
- solve_system stores the solver, tol and solver_kwargs; update() uses them
  and logs a warning when the new solve fails.
- NaN input points give NaN values and gradients, not 0.
- FDI builds the KD-tree weighting only when use_regularisation_weight_scale is on.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The old fallback called solve_system again, so the scaling was applied
twice and the field had the wrong size. ADMM keys also went to lsmr and
raised TypeError. Now solve_system changes the solver to lsmr and removes
the ADMM keys.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
update() now solves again only once after a change. If that solve fails,
it logs one warning and keeps the field until the next solve or
constraint change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…D supports work

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@lachlangrose
lachlangrose merged commit d3b5f84 into master Nov 26, 2026
46 checks passed
@lachlangrose
lachlangrose deleted the fix/interp-solver-status branch November 26, 2026 00:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant