![]() |
SuperSCS
1.3.2
|
Read this section if you intend to use SuperSCS in C.
Most users are interested in use SuperSCS via its MATLAB and Python interface and via CVX/CVXPy.
To you SuperSCS in C you first need to build the source code as explained above.
This will generate the following four files in the out/
folder:
out/libscsdir.a
: static SuperSCS library with the direct methodout/libscsindir.a
: static SuperSCS library with the indirect method (more suitable for large-scale problems).out/libscsdir.so
: shared library (direct)out/libscsindir.so
: shared library (indirect)Let us give a brief example of how to use SuperSCS in C by compiling your source code (read more here)...
Let us now compile and link to the static library out/libscsdir.a
On Linux, append -lrt
, that is
In particular:
SuperSCS can be compiled to run on multiple cores using OpenMP.
In order to compile SuperSCS with OpenMP enabled, set USE_OPENMP=1
in scs.mk
.
You may find a comprehensive example here.
SuperSCS can be called directly, to solve conic problems, in MATLAB.
Two functions, namely scs_direct
and scs_indirect
, solve the problem with the direct and indirect methods respectively.
Here is an example:
The user needs to provide three structures:
data
: with the problem data, i.e., the triplet \((A,b,c)\)cones
: the specifications of the cone \(\mathcal{K}\)solver_options
: (optional) options for the solverTo use SuperSCS provide the option solver_options.do_super_scs=1
.
A list of all solver options and their default parameters can be found here.
Note that the method with which SuperSCS computes the direction (e.g., the restarted Broyden method, Anderson's acceleration etc) is specified using solver_options.direction
. Admissible values are numeric (not strings) and are as follows:
direction=100
: Restarted Broyden methoddirection=150
: Anderson's accelerationdirection=200
: Fixed point residualdirection=300
: Full Broyden methodFunctions scs_direct
and scs_indirect
return the primal and dual solution of the problem, \((x,s,y)\) and a structure with information about the solution such as the solver time, number of iterations, relative duality gap and more).
By default, SuperSCS does not record the progress of the algorithm. To do so, you need to set the option do_record_progress=1
in the solver options.
SuperSCS can be used with CVX in MATLAB by simply using
and setting the solver option do_super_scs=1
as shown below
Several examples are given here.
Solver info can be stored using the property dumpfile
as explained here.
In order to use SuperSCS in Python, you first need to install the superscs
module.
Then, it is straightforward to import superscs
, define the problem data (matrix A
as a scipy.sparse
matrix and vectors b
and c
), the cone and call superscs.solve
:
The last invocation takes as input arguments:
data
which is the triplet \((A,b,c)\); the problem data,cone
which, here, is a linear cone of dimension 4,The call returns sol
; an object which return the solver status, the solution and additional information.
Here is what we see if we print out sol
from the example above:
We see that sol.status
is Solved
and the status code is sol.statusVal: 1
, meaning that the problem has been solved.
The triplet (x,y,s)
is the solution of the problem and sol.pobj
and sol.dobj
are the values of the primal and dual objectives.
We may also inspect the relative duality gap, primal and dual residuals, the residuals associated with the infeasibility and unboundedness of the solution and the number of iterations required to solve the problem.
First, let us load some necessary libraries
In order to verify that SuperSCS is properly installed and CVXPy can use it, run
This will return a list of solvers and SUPERSCS
should be among them.
Then, we define the problem data
Finally, we define the optimization problem (we specify the cost function and the constraints) and we invoke the solver