need to clean up each time?

90 views
Skip to first unread message

Liangliang Zhang

unread,
Oct 2, 2018, 5:13:55 AM10/2/18
to OSQP
In the given demo example, a few lines of code are used to clean up:
// Cleanup
    osqp_cleanup(work);
    c_free(data->A);
    c_free(data->P);
    c_free(data);
    c_free(settings);
I am calling osqp_solve(work) multiple times, do I need to clean it up each time? Thanks!

Goran Banjac

unread,
Oct 2, 2018, 5:32:02 AM10/2/18
to OSQP
If you are using the solve function multiple times, then there is no need to free the memory after each solve. You can use update functions to modify your problem data or settings, and then solve the updated problem. This approach is much more efficient than if you free the memory, create a new workspace, and run the setup function again.

Note that you can easily update vectors q, l and u. You can also update matrices P and A, but only if the sparsity patterns of the matrices do not change.

Best,
Goran

Liangliang (Gmail)

unread,
Oct 3, 2018, 3:15:24 AM10/3/18
to Goran Banjac, OSQP
If the sparsity pattern of P or A changes, can I still warm start?

--
You received this message because you are subscribed to the Google Groups "OSQP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to osqp+uns...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/osqp/2c645abb-f98a-4e2b-820f-066d493550e7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
Sincerely yours,
Liangliang Zhang

Goran Banjac

unread,
Oct 3, 2018, 3:37:22 AM10/3/18
to OSQP
If the sparsity pattern of P or A changes, than you need to call the setup function again.

However, you can still warm start the solver in the sense of providing the initial guess for primal and dual solutions. See here for more details.

Best,
Goran

Paul Goulart

unread,
Oct 3, 2018, 4:02:51 AM10/3/18
to OSQP
I think the answer is no, it is not strictly necessary to call the setup function again provided you do the initial setup in the correct way.

The purpose of the setup function is to make a symbolic factorisation of the KKT matrix (which has P and A as submatrices) and to allocate memory for its factors.   In order to do this we perform a symbolic factorisation during setup based on the location of all *potential* non-zeros in the data matrices.

You can therefore initialise your problem with A and P having non-zero values in *every position* in which a non-zero could conceivably appear in your problem.   If you do the setup in OSQP using these matrices, then it will not matter if later on you change some of these values to be numerically zero or nonzero.

The reason this works is that what counts as ’nonzero’ in the P and A matrices is determined only by the rowidx and colptr data (i.e. the ’symbolic sparsity’) during the symbolic factorisation.   Whether the numerical value of some of those entries is actually zero or not is not important during setup.

I would strongly advise doing the above only in the case that a very limited set of entries might change from zero to nonzero (or back).   If the sparsity of P or A changes drastically, then it is almost certainly preferable to run setup again with the new data.   The reason is that the symbolic sparsity pattern of the KKT factors is dictated by the symbolic sparsity of P and A.  If you create these matrices with many points that are “maybe zeros” then your KKT factors will have a lot of fill-in (i.e. low sparsity), making the solve times slower than they would be otherwise.    I do not think it is possible to make a general statement about how many entries counts as a “limited set of entries” because it will be strongly problem specific.

Goran’s statement below about providing initial primal and dual solutions works in either case.




Reply all
Reply to author
Forward
0 new messages