Skip to content

Stop cg_lanczos! resolving to the shifted workspace - #1251

Merged
ChrisRackauckas merged 1 commit into
SciML:mainfrom
AJ0070:fix/554-cg-lanczos-mapping
Aug 24, 2026
Merged

Stop cg_lanczos! resolving to the shifted workspace#1251
ChrisRackauckas merged 1 commit into
SciML:mainfrom
AJ0070:fix/554-cg-lanczos-mapping

Conversation

@AJ0070

@AJ0070 AJ0070 commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

Checklist

  • Appropriate tests were added
  • Any code changes were done in a way that does not break public API
  • All documentation related to code changes were updated
  • The new code follows the
    contributor guidelines, in particular the SciML Style Guide and
    COLPRAC.
  • Any new documentation only uses public API

Additional context

get_KrylovJL_solver matched cg_lanczos! twice. The first branch returned the shifted workspace and won, so the correct branch below it was dead code. Since cg_lanczos! is listed in the KrylovJL docstring, KrylovJL(KrylovAlg = Krylov.cg_lanczos!) threw a MethodError from the workspace constructor. Dropping the stray branch fixes it.

The shifted variants stay unmapped on purpose: they take a shifts argument this wrapper never passes, and they are not in the documented list.

Spotted in #554, which is otherwise superseded now that block GMRES and MINRES are reached by passing a matrix b to KrylovJL_GMRES/KrylovJL_MINRES.

AI Disclosure: Used Opus 5

`get_KrylovJL_solver` tested `KrylovAlg === Krylov.cg_lanczos!` twice. The
first branch returned `CgLanczosShiftWorkspace`, so it won, and the second
branch returning `CgLanczosWorkspace` was unreachable.

`cg_lanczos!` is listed in the `KrylovJL` docstring as a supported
`KrylovAlg`, so this is reachable from documented usage:

    solve(LinearProblem(A, b), KrylovJL(KrylovAlg = Krylov.cg_lanczos!))
    MethodError: no method matching CgLanczosShiftWorkspace(::Matrix{Float64}, ::Vector{Float64})

Dropping the first branch lets it fall through to the right workspace. The
solve then succeeds, to a relative error of 5.9e-9 on a symmetric positive
definite system.

`cg_lanczos_shift!` and `cgls_lanczos_shift!` are deliberately left
unmapped. Both exist in Krylov 0.10, but they take a `shifts` argument that
this wrapper never passes, and neither appears in the docstring's list, so
they keep hitting "Invalid Krylov method detected" rather than being
advertised and broken.

Spotted in SciML#554, which is otherwise superseded: block GMRES and MINRES are
already interfaced through `BlockGmresWorkspace` and `BlockMinresWorkspace`
for a matrix right-hand side.
@ChrisRackauckas
ChrisRackauckas merged commit 53fcf8f into SciML:main Aug 24, 2026
59 of 62 checks passed
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