Skip to content

fix(rotated-bc): warn on non-converged linear KSP#315

Open
lmoresi wants to merge 1 commit into
developmentfrom
bugfix/rotated-freeslip-silent-nonconvergence
Open

fix(rotated-bc): warn on non-converged linear KSP#315
lmoresi wants to merge 1 commit into
developmentfrom
bugfix/rotated-freeslip-silent-nonconvergence

Conversation

@lmoresi

@lmoresi lmoresi commented Jul 4, 2026

Copy link
Copy Markdown
Member

Summary

ksp.solve never raises on KSP_DIVERGED_*, so the two linear paths in
src/underworld3/utilities/rotated_bc.py (the default fieldsplit-Schur iterative
solve in _solve_rotated_iterative and the opt-in direct MUMPS LU in
solve_rotated_freeslip) both returned partial answers silently.

That silence is what let the 3D rotation-nullspace bug fixed by #306 look
like a working solve for as long as it did: on the 3D Zhong
SphericalShellInternalBoundary case (test_1064 setup) the outer Krylov
hit its `ksp_max_it` ceiling (300 in the pre-#306 code) with a residual
around 2.7e-7 (target rtol was 1e-7) while producing rotated-frame
solutions that the caller then rotated back and returned. Diagnosed under
the /remote-control session that surfaced #306.

Change

Add a small _warn_if_ksp_diverged(ksp, kind) helper at the top of the
module and call it immediately after each of the two `ksp.solve` sites.
Rank-0 warning only (via `uw.mpi.pprint`), same style as the existing
nonlinear-driver warning at the tail of `solve_rotated_freeslip_nonlinear`.

Impact

  • Happy path: no behaviour change — the helper is a no-op unless the
    KSP finished on a negative converged-reason.
  • Failure path: a divergence that previously was silent now emits a clear
    rank-0 warning with the reason code, iteration count, and final
    residual, so a caller inspecting stdout can see it.

Tests

`tests/test_1018_rotated_freeslip.py`: 14/14 pass (13 linear + 1
nonlinear-guard, unchanged from post-#306 tip). No new tests here — the
guard fires only on divergence, and forcing a divergence in-test would
require patching in a deliberately-broken preconditioner.

Related

Underworld development team with AI support from Claude Code

`ksp.solve` never raises on `KSP_DIVERGED_*`, so the two linear paths in
`rotated_bc` (the default fieldsplit-Schur iterative solve at
`_solve_rotated_iterative` and the opt-in direct MUMPS LU at
`solve_rotated_freeslip`) both returned partial answers silently.

That silence is what let the 3D rotation-nullspace bug fixed by #306 look
like a working solve for as long as it did: the outer Krylov hit its
`ksp_max_it` ceiling (300 in the pre-#306 code) with a residual well
above tolerance, and neither the KSP nor the caller flagged it. The
solution then propagated into downstream diagnostics that eventually
exposed it as wrong physics rather than as a solver failure.

Add a small `_warn_if_ksp_diverged` helper and call it immediately after
each of the two `ksp.solve` sites. Rank-0 warning only (via `uw.mpi.pprint`),
same style as the existing nonlinear-driver warning at the end of
`solve_rotated_freeslip_nonlinear`. No behaviour change on the happy path;
non-convergence is now loud instead of silent.

test_1018_rotated_freeslip.py: 14/14 pass (2D behaviour unchanged).

Underworld development team with AI support from Claude Code
Copilot AI review requested due to automatic review settings July 4, 2026 03:38

Copilot AI 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.

Pull request overview

Adds a small safety guard to the rotated free-slip linear solves so that PETSc KSP divergences (which ksp.solve() does not raise) are no longer silent, improving diagnosability of partial / non-converged rotated-frame solutions.

Changes:

  • Introduces _warn_if_ksp_diverged(ksp, kind) to emit a rank-0 warning when KSP finishes with a non-converged reason.
  • Calls the helper after both ksp.solve() sites (direct LU path and iterative fieldsplit-Schur path).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +41 to +43
reason = int(ksp.getConvergedReason())
if reason >= 0:
return
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.

2 participants