Matrix vs symbolic expressions

Hello everyone :wave:

I have been using the acados Python interface to prototype a trajectory optimization approach for my project. It has been extremely productive to use CasADi for rapidly making changes to the NLP formulation for which I can quickly generate and run a solver
to verify convergence. I then link the solver with a C++ executable for my application.

I am wondering if using symbolic expressions for everything has a “price”.

Let’s say we have some polytopic constraints that could be expressed in matrix form, but we use symbolic expressions for convenience. Will we be missing out on anything?

I read that using cost module auto converts cost functions that can be expressed as least squares to matrix form, so I assume there is an advantage to this. I suppose that it would come from skipping the linearization step. Does acados do this behind the scenes for constraints as well?

Thanks in advance :pray:

Seb

Hi Seb,

Yes! I think this auto feature is only available in Matlab/Octave for now.
Using directly some matrices to define the cost function instead of generated CasADi functions should speed up the linearization part of the SQP algorithm.
But this is only possible for linear least squares cost terms.
The cost is a less convenient interface, the advantage some computational speedup.

For constraints, it is similar. You could define all constraints as nonlinear constraints h, then those are generated as CasADi functions.
It is computationally more beneficial to define linear constraints or bound constraints as such.

You can assess before making such changes the percentage of computation time spent in the linearization step (time_lin), vs time_tot.

Best,
Jonathan

1 Like