Is there a way to benefit from closed form analytic solution of system dynamics when solving OCP?

Dear all,

I am wondering if there is a way to benefit from the fact that I could find an analytic solution for the system response in Acados or any other tool for solving an NMPC problem?

More in detail, the solution is only valid under constant control inputs, so I would expect in principle that by using a multiple shooting approach for discretization could work.
Instead of an integrator, I could directly use the analytic expression to get an exact solution (possibly trading many Runge-Kutta function evaluations for only one, possibly more expensive function call).

I would be happy for advice if this is feasible and beneficial! And of course, hints if ACADOS could do the job or if I would need to go to a lower level solver…

Thanks,
KR
Max

Hi Max,

If I understand correctly, you have an analytic expression which expresses the evolution of your system for a given control input, i.e.

x_{i+1} = f_{\mathrm{analytic}}(x_i, u_i)

Did you consider formulating your problem with the discrete dynamics module? See Section 2.3. here: https://github.com/acados/acados/blob/master/docs/problem_formulation/problem_formulation_ocp_mex.pdf

Best,
Jonathan

Thanks Jonathan,

yes that is in principle what I need, thanks.
The only thing is that my expression contains Bessel functions of the first and second kind, and as far as I could see, the CasADi expression needed in ACADOS does not support Bessel functions.

Hence I would be interested in
(1) how much one can benefit in general from having the discrete expression
(2) if there is a way around CasADi expressions in ACADOS

Thanks,
Max

Hi Max,

That’s probably right!

I guess this depends on:
a) How computationally expensive is your integrator
b) How computationally expensive is the corresponding discrete dynamics expression

This is not straight forward and depends on the interface you want to use it with. (For reference C-Functions instead of Casadi)
Note that you would also need the Jacobians of your discrete dynamics function.

Another idea to use that solution would be to initialize the states in the solver with the exact simulation of your dynamic system.

Best,
Jonathan

Thank you so much.

The C-code instead of CasADi option seems not viable in this project then.

I did not quite get how I could initialize the states in the solver except from the starting point? In my MHE problem, I calculate this only once for each time my horizon shifts - what makes the optimization currently prohibitively slow are - I guess - the many integration steps necessary during the iterations.

I am aware this is beyond the topic of this discussion, but maybe you could give some advice concerning the general question of how to proceed in my situation:
The reason why I was looking into that solution was because in my current implementation as multiple shooting in CasADi becomes really slow (order of 2-3 seconds) when formulating it as DAE compared to using a ODE formulation (order of 100ms). The DAE formulation is to make use of an available measurement of an algebraic state in my NMHE problem.

Maybe you can point me in a direction how to speed up things - and if it is worth giving ACADOS a try. If yes, any working example of a NMHE problem would be very beneficial, I could not find anything so far.

Thank you so much!
Kindest regards,
M

Hi Max,

you are welcome!

Which interface are you using?
The .set() routine with field “x” and stage index should do the job though.

you can also verify that by evaluating the timings.
There is time_tot (overall time for last solver call) and time_sim for the part that is spend in the integrator.

There are simple MHE examples for both Matlab and Python.
What is the main challenge for formulating your NMHE problem in acados?

It might make sense to open a new topic for that though.

Best,
Jonathan

Thanks again for your time and patience.

I am using the Matlab interface on Windows.

Regarding your comments, I must admit I did not quite understand your comment:
“The .set() routine with field “x” and stage index should do the job though.”.
Was this referring to the initialization suggestion?
And are you referring to Casadi, Ipopt or IDAS?

Regarding time_tot and time_sim: I guess that is what Ipopt prints on the console at higher verbosity levels (still trying to figure out how I can bring the CaSaDi solver in the Matlab Interface to give this as an output too). Anyhow, since I typically get something like the following output of a single iteration:
Total CPU secs in IPOPT (w/o function evaluations) = 0.073
Total CPU secs in NLP function evaluations = 1.572

Now before investing a lot of time and effort into solving the problem with ACADOS, and I don’t plan to run the code on an embedded platform, I would need more understanding of where the time is lost.

Is it solving the DAE in general? Then I would not expect ACADOS to bring any benefit if under the hood, ACADOS solver needs similar amount of function evaluations wtih the same DAE solver.

Is it because in my setting, using the Matlab Interface, the DAE evaluations (including the sensitivities) are just by far slower running in the virtual environment? I am clearly lacking understanding of what exactly is already running a C-code in CasADi and what will be differnt here.

Is it because ACADOS solver will need by far less function evaluations? This seems to be case using the RTI scheme, where one would stop after the first iteration - but this only works for quadradic costs, right?

Another path I am considering to take is formulating the problem with a collocation method to get around the slow solution of the DAEs, but this is new to me as well.

I do not expect you to answer all my questions, and I know this cannot be answered in general.
Nevertheless, it might be helpful for you to know which kind of questions unexerienced users like me are facing.

I will try open a new thread with this topic, since I belief more users might have the same challenges.

Kind regards,
Max

Hi Max,

That, as well as what I wrote about timings was refering to acados. I somehow thought you already have an acados formulation…

Note that acados comes with its own integration methods. I never did a thorough comparison of acados vs CasADi integrators.
But it was reported that acados integrators can be “orders of magnitude faster than those available in casadi”, see Acados integrators in casadi

It might be that acados needs less function evaluations, I am really not sure what the CasADi integrators do internally and how you configured them.

Did you try to just simulate your DAE in acados yet?!
I hope this encourages you to try!

No, you can apply RTI for any cost function, afaik.

I am wondering why you are using a virtual environment…

Best,
Jonathan