1

I am trying to compare the computational cost of several methods of solving a nonlinear partial differential equation. One of the methods uses scipy.optimize.newton_krylov. The other methods use scipy.sparese.linalg.lgmres.

My first thought was to count the number of iterations of newton_krylov using the 'callback' keyword. This worked, to a point. The counter that I set up counts the number of iterations made by the newton_krylov solver.

I would also like to count the number of steps it takes in each (Newton) iteration to solve the linear system. I thought that I could use a similar counter and try using a keyword like 'inner_callback', but that gave the number of iterations the newton_krylov solver used rather than the number of steps to solve the inner linear system.

It is possible that I don't understand how newton_krylov was implemented and that it is impossible to separate the the two types of iterations (Newton steps vs lgmres steps) but it would be great if there was a way.

I tried posting this on scicomp.stackexchange, but I didn't get any answers. I think that the question might be too specific to Scipy to get a good answer there, so I hope that someone here can help me. Thank you for your help!

Ken
  • 1,778
  • 11
  • 10
  • Well, i suspect one method would be getting scipy's sources, check the sources and add some prints/counters for your analysis and run it. The basic approach should work well on a unix-based system (compilation-hell on windows). The only fear there: if some of this stuff is calculated through fortran which might be a bit cumbersome if you are not familiar with it. – sascha Nov 07 '16 at 11:09
  • @sascha, it is always an option to roll my own Newton-Krylov solver or to modify the source for the Scipy method, but it is far from my favorite option. I can, usually, read fortran, but I'm far from fluent in it. I do run Linux and I almost always use Anaconda for Python since it is easy to get up and running quickly. I hope someone comes up with a creative solution. – Ken Nov 07 '16 at 17:06

0 Answers0