Skip to content

Commit b9c3d2f

Browse files
Setup retcode for Krylov.jl
This solves #297. KrylovKit.jl already throws `ReturnCode.Failure` if it doesn't converge, IterativeSolvers.jl doesn't have it possible, and now Krylov.jl is using retcodes. So now nothing is silent on non-convergence when it's possible to be known from the solver. This also fixes #298
1 parent 5426cdd commit b9c3d2f

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/iterative_wrappers.jl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,18 @@ function SciMLBase.solve!(cache::LinearCache, alg::KrylovJL; kwargs...)
270270
stats = @get_cacheval(cache, :KrylovJL_GMRES).stats
271271
resid = stats.residuals |> last
272272

273+
retcode = if !stats.solved
274+
if stats.status == "maximum number of iterations exceeded"
275+
ReturnCode.MaxIters
276+
elseif stats.status == "solution good enough given atol and rtol"
277+
ReturnCode.ConvergenceFailure
278+
else
279+
ReturnCode.Failure
280+
end
281+
else
282+
ReturnCode.Success
283+
end
284+
273285
return SciMLBase.build_linear_solution(alg, cache.u, resid, cache;
274286
iters = stats.niter)
275287
end

0 commit comments

Comments
 (0)