How to reset solver after nan occured in the output of AcadosSim?

Hi :wave:

I’m using acados Simulator for Parameter Estimation via GitHub - FreyJo/casados-integrators. It’s hard to give a code for my question so I’ll try to be precise:

I use Callback as in casados-integratos to wrap output of the AcadosSimSolver and let nlpsol of the Casadi to generate jacobian and hessian that it requires. I noticed, that as soon as IRK simulator fails (starts to return nan vectors after solve()) any further AcadosSimSolver.solve() calls will return nans. However solution for that is quite simple: I had to use AcadosSimSolver.set(“xdot”) to “reset” solver and the behavior of the solver returned to normal. I assume, that it happens, because there is some kind of cached memory , right?

Now here comes the issue, which is pretty strange: I let my Casadi.nlpsol with IPOPT run the parameter estimation. On one Linux PC (Arch x64) everything works perfectly. On Ubuntu PC, as soon as optimizer runs once into unfeasible solution (AcadosSimSolver returns nan), it continues to return nans on any following solve call(). It is really strange behavior, I tested bunch of stuff and getting less and less new ideas. I imagine it’s not a problem of Python or acados, because on both PCs I use same Python 3.9, and same versions of acados v.0.1.9 and almost same Cmake … Maybe it is caused by some Casadi Callback bug? Basically I just need to know which difference between PCs can cause such an issue…

I would appreciate any kind of new ideas.

Best
Vova

Update: the problem is probably caused by ForwardCallback function link casados. The CasadosIntegratorSensForw continues to return nans after first nan occurrence.

I basically solved my problem by reinitializing CallbackFunction after every optimization run, reusing the same C code AcadosSimSolver(acados_sim, json_file, generate=False, build=False). So it looks like a problem is somewhere between Callback and acados.

Hi Vova,

I think that AcadosSimSolver.set(“xdot”) should be sufficient to reset the integrator.
I also did a quick test just now and also the sensitivities are back to normal.

I am on the latest acados version and use Ubuntu.
If there is a difference between your two machines, I really don’t know what it can be.

Are you sure that you are using the same acados version?

That is surely a safe option to reset it. But it will take some additional time for memory reallocation.

Best,
Jonathan