krypy
krypy copied to clipboard
Provide example for catching ConvergenceError
We should add an example to the documentation for catching a ConvergenceError. A lot of people are unfamiliar with try/except so we can probably help them here a bit.
@zimoun What do you think?
@zimoun: something like this should do the trick:
from krypy.utils import ConvergenceError
import warnings
# run a solver and catch ConvergenceErrors
def solve_unsafe(Solver, linear_system, **kwargs):
try:
return Solver(linear_system, **kwargs)
except ConvergenceError as e:
# warn the user (probably we should add more information to the message)
warnings.warn('Solver did not converge.')
# use solver of exception
return e.solver
solver = solve_unsafe(Minres, linear_system, maxiter=5)
yes, this kind of trick.
In my branch converr, I do that in the solver itself but it is not clean.
So, maybe, you could add this snippet of code in linsys.py or just in an example.
+1 for example, that's the most visible way.