embotech / ecos

A lightweight conic solver for second-order cone programming.
GNU General Public License v3.0
471 stars 123 forks source link

How to carry out repeated solves without additional memory allocation? #69

Closed mageecoe closed 10 years ago

mageecoe commented 10 years ago

Hi,

In the ECC paper from 2013, it is mentioned that ECOS has the three routines setup, solve, and cleanup. Furthermore, it is stated that "Once the problem has been set up (possibly accomplished by a code generator), different problem instances can be solved without the need for dynamic memory allocation (and without the Setup overhead)."

This is something that I am interested in, but I haven't yet understood if there is a routine that updates the required mywork members based on new information from my problem matrices c, A, b, G, h, without allocating additional memory, or if this is something I would need to carry out "manually" before a repeated solve (e.g., by "copying" ECOS_setup but stripping it from the MALLOCs).

So, my question is: Do you have a recommended procedure to carry out repeated solves without additional memory allocation?

Best, Magnus Nilsson, Viktoria Swedish ICT

adomahidi commented 10 years ago

Hi Magnus, This is currently not implemented yet - you'd have to figure out where to put the data exactly. Which data is changing? The vectors c,h and b are easier to replace than the matrices A,G.

adomahidi commented 10 years ago

There's an API function called ecos_updateDataEntry_h that updates an element in h. Similar things are easy to add for c and b.

mageecoe commented 10 years ago

Thank for the quick reply Alexander. I'll figure something out based on your info. (Sent from my smart phone, so excuse my brevity.)

mageecoe commented 10 years ago

By the way Alexander, for your information:

I am (quite loosely) investigating if QCML and ECOS can be combined with a Level-2 S-function in MATLAB with the goal to quickly prototype different optimization problems (e.g., that arise in vehicle energy-management). That could possibly be used in early stages of research and development. If it is possible (which I think), it would then be nice to only allocate memory during initialization and deallocate it at termination of a simulation (e.g., when estimating performance).

It seems as both ECOS (as you confirmed) and QCML do not yet support repeated solves without re-allocation. The function ECOS_setup and qc_XXX2qcml are the functions I have ended up looking at more closely to conclude this, where XXX is the name of the QCML problem.

Since my problem formulation is not currenlty specific, I am not yet certain which data will be changing.

This is not a crucial issue at this stage of my investigation, however. I think I can live with repeated mallocs and frees to start with.

Thanks for pointing out the ecos_updateDataEntry_h function. I found it after I updated from an old ECOS version that I was using.

Best, Magnus

adomahidi commented 10 years ago

I see. Is it a predictive control problem you're solving?

mageecoe commented 10 years ago

Yes, me and a friend want to try that. But I may (for example) also use it to repeatedly minimize the Hamiltonian in optimal-control formulations, where I assume that the values for the adjoint states are estimated from some supervisory layer in a control hierarchy.

I would say that we are newbies when it comes to algorithms and would, for example, like to get first-hand experience on how ECOS performs compared with LP and QP solvers. Either by comparing performance for the same problem formulations, or by comparing ECOS for an SOCP formulation (if/when that arises) with LP/QP solvers for problem formulations that apply piecewise linear approximations.

We got some inspiration from a recent workshop in Freiburg initiated by Moritz Diehl that I attended. I am sure you personally know many of the participants. My friend has been playing around with some LP/QP-solvers since then and is now looking at FORCES. I have an interest in distributed algorithms as well. I think that the S-function would enable us to quickly be able to play around with different problem formulations and get simulations to run.

adomahidi commented 10 years ago

Hi Magnus,

When it comes to optimal control formulations you usually have to discretize your inputs at some points, which means you will end up having a stage-wise problem formulation, for which FORCES is optimized. On some test problems FORCES was therefore about 10x faster than ECOS, but this strongly depends on the level of sparsity (FORCES currently assumes dense sub-matrices in your dynamics, for example). If you're looking for quick prototyping of optimal control problems in Simulink, you might want to try FORCES Pro (http://www.embotech.com/FORCES-Pro), which comes with a Simulink interface, which is even auto-generated for your problem. You can shoot me an email if you have troubles using it.

Regarding the approximation SOCP vs QP/LP, I strongly believe that SOCPs (or QCQPs) are better whenever the original problem has these convex constraints (so you would use sequential convex programming instead of sequential quadratic programming to solve the NLPs).

Anyways, let me know how it goes!

Best, Alex

mageecoe commented 10 years ago

Thanks for your suggestions Alexander! In a couple of weeks we will meet up and start testing this more thoroughly, and hopefully confirm your statements. I think my friend is using FORCES Pro, I'll be able to confirm that after the vacations. I'll let you know how it goes.

Btw, based on ECOS and QCML I was able to write a Python class that auto-generate scripts and C-code that give me an S-function. Seems to work (only tested on a simple problem). I think we may get SOC constraints in some of our problems. We'll see if it becomes useful for us during fall.

echu commented 10 years ago

Wow! Glad QCML was of use! I believe you'll get better mileage out of FORCES, but the nice thing is you can try both! Let us know which approach you end up using; be interested to know if our intuition is right here.

On Tue, Aug 5, 2014 at 11:50 PM, mageecoe notifications@github.com wrote:

Thanks for your suggestions Alexander! In a couple of weeks we will meet up and start testing this more thoroughly, and hopefully confirm your statements. I think my friend is using FORCES Pro, I'll be able to confirm that after the vacations. I'll let you know how it goes.

Btw, based on ECOS and QCML I was able to write a Python class that auto-generate scripts and C-code that give me an S-function. Seems to work (only tested on a simple problem). I think we may get SOC constraints in some of our problems. We'll see if it becomes useful for us during fall.

— Reply to this email directly or view it on GitHub https://github.com/ifa-ethz/ecos/issues/69#issuecomment-51299704.