modelon-community / Assimulo

Assimulo is a simulation package for solving ordinary differential equations.
https://jmodelica.org/assimulo/index.html
GNU Lesser General Public License v3.0
66 stars 16 forks source link

SPGMR solvers are not using the user defined setup_jacobian function #73

Closed andreamola closed 8 months ago

andreamola commented 8 months ago

Hi everyone, I am trying to use Assimulo to use Kinsol and IDA functions in python. I recently installed the package through anaconda (mamba install -c conda-forge assimulo) on a Debian 12 distribution. Apparently the installation went through, but I somehow cannot get the package to work properly. In fact, in all the KINSOL examples I try to run, whenever the SPGMR solver is selected, I observe that the setup_jacobian function is never called, nor is the preconditioner solve. As a consequence, there is a high number of linear solver failures reported, and the final result accuracy is way higher than the specified tolerance. For instance, this is the output of the kinsol_ors example

No initialization defined for the problem.
No finalization defined for the problem.
Final Run Statistics: ORS Example 

 Number of function evaluations              : 68
 Number of Nonlinear Iterations              : 67
 Number of Backtrack Operations (Linesearch) : 0
 Number of Beta-condition Failures           : 0
 Number of Jacobian*Vector Evaluations       : 713
 Number of F-Eval During Jac*Vec-Eval        : 68
 Number of Linear Iterations                 : 646
 Number of Linear Convergence Failures       : 64

Solver options:

 Solver                  : Kinsol
 Linear Solver           : SPGMR
 Globalization Strategy  : NONE
 Function Tolerances     : 1.2947195696248386e-08
 Step Tolerances         : 3.666852862501036e-11
 Variable Scaling        : [1. 1. 1. ... 1. 1. 1.]
 Function Scaling        : [1. 1. 1. ... 1. 1. 1.]

Elapsed simulation time: 1.0814493019715883 seconds.
No initialization defined for the problem.
No finalization defined for the problem.
Final Run Statistics: ORS Example (Preconditioned) 

 Number of function evaluations              : 68
 Number of Nonlinear Iterations              : 67
 Number of Backtrack Operations (Linesearch) : 0
 Number of Beta-condition Failures           : 0
 Number of Jacobian*Vector Evaluations       : 713
 Number of F-Eval During Jac*Vec-Eval        : 68
 Number of Linear Iterations                 : 646
 Number of Linear Convergence Failures       : 64

Solver options:

 Solver                  : Kinsol
 Linear Solver           : SPGMR
 Globalization Strategy  : NONE
 Function Tolerances     : 1.2947195696248386e-08
 Step Tolerances         : 3.666852862501036e-11
 Variable Scaling        : [1. 1. 1. ... 1. 1. 1.]
 Function Scaling        : [1. 1. 1. ... 1. 1. 1.]

Elapsed simulation time: 1.2607804519939236 seconds.
Error                 , in y:  0.000541712298832705
Error (preconditioned), in y:  0.000541712298832705

As can be seen, it is way different from the one reported here https://jmodelica.org/assimulo/EXAMPLE_kinsol_ors.html

In addition, the same behavior is observed when I run the tests, in which I have

Ran 291 tests in 21.166s

FAILED (errors=22, failures=10)

Again, I think this is due to the fact that user prescribed jacobian and preconditioner functions are ignored during the computations. Has this behavior ever been observed? I must say that I have an independent installation of sundials 6.5.0 (which I use for C++ simulations): could this interfere with the anaconda install? Thank you very much for the help, and sorry for the lengthy message.

Andrea
PeterMeisrimelModelon commented 8 months ago

I agree with your assessment that the prescribed jacobians seem to be ignored, there should not be any F-evals in the run statistics with a user supplied Jacobian.

This exact issue has not been reported previously (to my knowledge), but might possibly be related to https://github.com/modelon-community/Assimulo/issues/55

Can you provide us with a list of the tests that are failing?

andreamola commented 8 months ago

Thanks Peter, I took a look at #55 but I am not entirely sure the two problems have the same root. I attached here a list of what I think are the failed tests. The nosestests output is way heavier, as it is full of deprecation messages for np.float use.

failed_tests.txt

Let me know if this helps, and thanks again.

PeterMeisrimelModelon commented 8 months ago

The numpy.float issue should be fixed on master already. As for the other tests, it does look like there are some more changes required to get full Sundials 6.x support.

We currently have not work planned to enhance support for Sundials 6.x. Our main focus is compliance with Sundials 2.7, see also "Sundials compliance" in the README. We would suggest trying a lower Sundials version.

andreamola commented 8 months ago

Thank you very much for the clarification, Peter. I'll make sure thet Sundials 2.7 is used then.