Is there any way to reset solver in Python?

Hello, I’ve faced some problems.
First of all, I have no idea how to call generated solver from python script without regenerating the solver.

The other problem is in fact, that I can’t reinitialize solver \ set to initial state (just like after generation)?
It would be grate if anybody could help me.

Hi,

for resetting you can do store_iterate() right after the creation and then do load_iterate().
Those routines load (and store) the initial guess (iterate) of the SQP method.

You can try to use the build keyword argument of the constructor of OCP solver.
Not sure if this works, since I haven’t tried it myself and still need to check this PR: Fix build=false when creating AcadosOcpSolver by gijskoning · Pull Request #780 · acados/acados · GitHub

Cheers!

Thanks for your replay. I saw no problems with c++ implementation (by using C interface). I’ll the trick described by you. I hope it will help me to reset a solver in python interface.

UPD: It really works. If you call store_iterate() just after the solver was created and use load_iterate() before each solver call, the solver will backup to the stored state. It’s a bit unintuitive but works just great_)

Hi @FreyJo,

do you know if we could implement this in the Simulink S-Function implementation?
During running online on an engine, this would be really helpful. Otherwise, you need to restart the engine RCP controller every time, e.g. the MABX from dSPACE.

Cheers,
Alex

Hi @AlexWin ,

for now the Sfunction has the option to be generated with the fields x_init and u_init.
It would be straight forward to add similar fields for the multipliers.
Then you could just pass zeros for those fields to reset the solver.

Do you think that would work?
An S Function block is not as flexible as a Python class.
The latter has different member functions solve(), load_iterate(), …
S Functions could maybe call some reset functionality based on a flag though.
We can talk about this more once I am back at the university.
But feel free to mess with the Simulink interface!

Hi @FreyJo,

thanks for your answer.
So I guess I would have to add “lam” and “pi” inputs / setter in the ocp_create.c (interface/acados_matlab_octave), simulink_deafult_opts.json and in the acados_solver_sfun.in.c (interface/acados_templated/c_templates_tera)?
Would that be it?

Thanks for your offer, I will come back to it for sure!

,
Alex

I think you only need to change
simulink_deafult_opts.json
and
acados_solver_sfun.in.c

ocp_create.c is for the native MEX interface and it should already be possible to set the multipliers there.

Hi @DrShiki , @FreyJo

i have same problem like you
but i can’t understand where to put store_iterate() and load_iterate() function in my code
can you share the example code which you use above functions

Thanks for your reply

You may put store_iterate() just after you’ve created the solver and use load_iterate() right before the solver is calling (Be aware to use load_iterate before you initialize the solver with your data, otherwise you will get empty problem).
In other words:
Fist step:
You create the solver
Use store_iterate()
Second step (whenever you think to call the solver):
You use load_iterate()
Initialize the solver
Call the solver

Thank you for reply.
let me try it
sorry for late.