SQP with Matlab interface in CasADi

3,943 views
Skip to first unread message

Peter Listov

unread,
Aug 18, 2016, 10:35:37 AM8/18/16
to CasADi
Hello,

I am quite new to CasADi and wonder, does anyone have an experience with using the Matlab interface with SQP solvers? I had a very bad time trying to build WORHP for Matlab (MacOS 10.11, Matlab R2015b). It compiles but crashes in the runtime even for the provided examples. For another maintained solver SNOPT I do not have a licence. 

Would it make sense to work on my own active set SQP implementation using CasADi in Matlab if I want to push for speed and compete with IPOPT?  Or is it better to switch to C++ interface to gain performance.

Also I could not find, how to pass parameters to IPOPT from Matlab.

Thanks. I will really appreciate any help or advice.

Best regards,
Peter 

Joel Andersson

unread,
Aug 18, 2016, 11:21:34 AM8/18/16
to CasADi
Hi Peter!

We have some in-house SQP implementations in CasADi. These are distributed with CasADi and need not be installed separately.

There is "sqpmethod", which is essentially a vanilla SQP method with L1 line-search. It also implements BFGS Hessian approximation. If you are considering writing your own SQP implementation, you could consider just having a look at that one and modify it as you see fit.
Feel free to fork and make pul requests if you fix/improve some feature. Anyway, the code should be clean and well commented. I would say that the main limitation of that code is the globalisation (L1 line-search is not great IMO) and the regularization (convexification). But that can be improved.

A second SQP implementation in CasADi is "scpgen". It's a structure exploiting SQP implementation which projects a block sparse QP to a smaller, dense QP. It relies heavily on C-code generation for efficiency and implements both exact Hessian SQP and a Gauss-Newton SQP approach for sum-of-squares objectives. You need to enter the problem in a special way, using CasADi's "lift" operator to use this method. The main limitation with this code, as with "sqpmethod", is the globalisation and regularization.

Finally, just added to CasADi (if you use CasADi 3.1rc1, you should be able to use it) is a fork of the code "blocksqp", which is an SQP method with filter line-search and a blockwise hybrid BFGS/SR1 Hessian approximation approach. This has shown very promising results in initial testing, but is still work in progress.

Or, you can of course write your own SQP code from scratch, but it's nontrivial of course to write a really good SQP code...

Best regards,
Joel

Peter Listov

unread,
Aug 22, 2016, 12:15:34 PM8/22/16
to CasADi
Hi Joel,

Thank you for the quick and comprehensive reply. 

May I ask yet another question? As a preamble, I am solving a set point stabilisation problem for a nonlinear system with Chebyshev spectral collocation. Having tried the "sqpmethod" with "qpOASES" is a QP solver, I continue to experience some numerical issues. That is the solver complains about rank deficiency in the Hessian. The constraints appear to be linearly independent, also I tried to add a regularisation term and even pass to the solver solution obtained with IPOPT as an initial guess- the problem is still there.

Here is how I create solver:

nlp = struct('x',vertcat(vecx{:}), 'f', obj, 'g', vertcat(g{:}));

solver = nlpsol('solver','sqpmethod',nlp, struct('qpsol', 'qpoases'));


Is there a way to run the solver in a debugging mode to have an access to (or trace) decision vector, Hessian and active constraints in Matlab?  

How would I pass additional variables available for the "sqpmethod" in Matlab?

Thanks a lot for helping out!

Best regards,
Peter

Peter Listov

unread,
Aug 26, 2016, 11:51:48 AM8/26/16
to CasADi
Hello,

Regarding the previous question. After a proper scaling of the NLP, the built-in SQP works fine, although slower then IPOPT. 

Best regards,
Peter

Joel Andersson

unread,
Aug 26, 2016, 12:09:53 PM8/26/16
to CasADi
Hi!

OK, not surprising that it's slower. Note that for "sqpmethod", it matters greatly how you solve the QP. If you use qpOASES without the (recently added) support for sparse QP, it's going to be very inefficient, since it treats the QP as dense.

From my experience, the main advantage of an SQP method over an interior point method is that you can potentially get away with fewer function evaluations. This matters when the runtime is dominated by the time it takes to evaluate the function, which is often the case with direct multiple shooting discretizations. Arguably, there are also smart ways to avoid calculating the exact Hessians (as in e.g. the blocksqp code). With collocation methods, the function evaluation is usually dwarfed by in particular the cost to factorize and solve the linearized KKT system. And then it's hard to beat an IP method, since the total number of linear system solves tend to be smaller..

That being said, the main advantage of using "sqpmethod" at this point, is that it should be easy to hack on, if you want to learn more about SQP or implement your own algorithms. It's not nearly as polished as a code such as IPOPT.

Joel


Hung Tuan

unread,
Oct 19, 2017, 7:39:12 AM10/19/17
to CasADi
Hi Joel,

I am using Casadi in Matlab for my work in MPC and it works very well and is more flexible than ACADO. Thanks for your great work. 
One limitation of my work now is that I use IPOPT as the solver for NLP and it is quite slow (as you know in MPC, we have to run closed loop simulation and every sampling time we have to solve the NLP). I have used ACADO before and see that ACADO with SQP and qpOASES with code generation, it solves NLP very fast. Could you please let me know if the latest Casadi has any support like that of ACADO. 
If not, please let me know more clearly how to build that. Of course, it would be fantastic if we have any code sample for this.

Thank you very much.

Hung   

Joel Andersson

unread,
Oct 19, 2017, 11:04:24 AM10/19/17
to CasADi
Hi,
Please keep an eye on ACADOS (https://github.com/acados/acados), the successor code of ACADO, which uses CasADi for the symbolics (but not for ODE/DAE integration or NLP solution). The downside of using a tool such as ACADOS is that you don't get the flexibility of using CasADi directly.

You don't have to use IPOPT if you're using CasADi for MPC. You can use a different solver or write one yourself. BlockSQP and Scpgen are two solvers in CasADi that exploit the block structure of NLP arising from direct multiple shooting transcriptions. They aren't very stable tho, so I would mostly recommend using them in some collaboration with the developers (group of Prof Sebastian Sager for BlockSQP, me for Scpgen). Efficiency probably depends a lot on how you chose to integrate your system and calculate ODE/DAE sensitivities.

But you can also implement an SQP framework yourself, using CasADi-MATLAB. This doesn't need to be too hard, especially if you choose to work with a Gauss-Newton Hessian approximation. Here is a template code, taking from the second edition of Model Predictive Control: Theory and Design by Rawlings, Mayne & Diehl (currently in print, will make a post when the book is ready to order):


Best regards,
Joel

Joris Gillis

unread,
Oct 19, 2017, 11:11:47 AM10/19/17
to CasADi
Another option is to use Matlab's builtin solvers together with CasADi to evaluate the NLP and its derivatives
In fact, this is anice idea for a blogpost..

Joris

Reply all
Reply to author
Forward
0 new messages