<div dir="ltr"><div><br></div><div><br></div>Hello,<br><br><div>I am trying to catch the "not converged" error in a loop with the `ksp_error_if_not_converged` option on. However, it seems that PETSc only raises the exception once, even though the solver does not converge after that. Is this expected behavior? Can I make it raise an exception every time?</div><div><br></div><div>I have included a code snippet of the loop below, and the complete code is attached:</div><div>```python<br></div><div>for i in range(3):<br> printf(f"Loop i = {i}")<br> try:<br> solver.solve()<br> except ConvergenceError:<br> printf(f" Error from Firedrake: solver did not converged: {get_ksp_reason(solver)}")<br> except PETSc.Error as e:<br> if e.ierr == 91:<br> printf(f" Error from PETSc: solver did not converged: {get_ksp_reason(solver)}")<br> else:<br> raise<br><div><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr">```</div><div dir="ltr"><br></div><div dir="ltr"><div>The output of the code looks like this:</div><div>```python</div><div>(complex-int32-mkl) $ python test_error.py<br>Loop i = 0<br> Linear solve did not converge due to DIVERGED_ITS iterations 4<br> Error from PETSc: solver did not converged: DIVERGED_MAX_IT<br>Loop i = 1<br> Linear solve did not converge due to DIVERGED_ITS iterations 4<br> Error from Firedrake: solver did not converged: DIVERGED_MAX_IT<br>Loop i = 2<br> Linear solve did not converge due to DIVERGED_ITS iterations 4<br> Error from Firedrake: solver did not converged: DIVERGED_MAX_IT<br></div></div><div dir="ltr">```</div><div dir="ltr"><br></div><div dir="ltr">Best wishes,<div>Zongze</div></div></div></div></div></div>