# How to monitor convergence?

**URL:** <https://bempp.discourse.group/t/how-to-monitor-convergence/148>\
**Category:** Applications\
**Created:** [28 October 2022 01:32 UTC](https://bempp.discourse.group/t/how-to-monitor-convergence/148 "2022-10-28T01:32:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![chellia](https://avatars.discourse-cdn.com/v4/letter/c/3e96dc/32.png) [@chellia](https://bempp.discourse.group/u/chellia)\
**Post date:** [28 October 2022 01:32 UTC](https://bempp.discourse.group/t/how-to-monitor-convergence/148/1 "2022-10-28T01:32:39Z")

</div>

Hi. Thanks for the wonderful software. I am wondering if there is a way to monitor the convergence of the solver. I am solving a quite large problem (just a plane wave scattering problem on an object at 8kHz - it takes about two days to finish running) and wondering if there is a way to monitor the progress. Like a residual vs iter\_count. I am using gmres solver.  
Thanks.

---

<div class="post-metadata">

**Author:** ![Elwin](https://yyz2.discourse-cdn.com/free1/user_avatar/bempp.discourse.group/elwin/32/38_2.png) [@Elwin](https://bempp.discourse.group/u/Elwin)\
**Post date:** [28 October 2022 10:42 UTC](https://bempp.discourse.group/t/how-to-monitor-convergence/148/2 "2022-10-28T10:42:11Z")

</div>

You can use the built-in logger of bempp to monitor the convergence of GMRES.  
Instead of

```auto
from bempp.api.linalg import gmres
sol, info = gmres(lhs, rhs)

```

you can use

```auto
from bempp.api.linalg import gmres
bempp.api.enable_console_logging()
sol, info = gmres(lhs, rhs)

```

to monitor the iteration count. If you want to monitor the residual norm as well, use

```auto
from bempp.api.linalg import gmres
bempp.api.enable_console_logging()
sol, info, res = gmres(lhs, rhs, return_residuals=True)

```

Alternatively, you can use the Scipy implementation of Gmres and make a custom callback function:

```auto
from scipy.sparse.linalg import gmres
def my_callback(args):
    ...
    return
sol, info = gmres(lhs.strong_form(), rhs.coefficients, callback=my_callback)

```

This functionality also works with other iterative solvers like CG.

---

<div class="post-metadata">

**Author:** ![chellia](https://avatars.discourse-cdn.com/v4/letter/c/3e96dc/32.png) [@chellia](https://bempp.discourse.group/u/chellia)\
**Post date:** [28 October 2022 20:21 UTC](https://bempp.discourse.group/t/how-to-monitor-convergence/148/3 "2022-10-28T20:21:47Z")

</div>

Thank you so much @Elwin . That’s very helpful! I’ll enable the built-in logger with return\_residuals=True and try it. Thank you!
