CVXMOD – code generation (utterly preliminary)

Alert!

CVXMOD is discontinued!

Unfortunately CVXMOD has not been developed since 2008. It is incomplete, somewhat buggy and not supported. Please instead try the replacement package CVXPY. Or, try CVXOPT if you are prepared to work at a lower level, CVX if you are ok with Matlab, or CVXGEN if you want small (but super high speed) QP solvers.

Sparse parameters (preliminary)

To take advantage of a sparse parameter A, set A.ss to some alternative storage scheme. A storage scheme is a dictionary where A[i,j] = k means that in the generated C code, the (i, j) entry of A is located at params->A[k]. Leaving (i, j) pairs out of A.ss means they are assumed to be always zero.

To automatically generate a packed column-major storage scheme from a sparse matrix Aval, use A.ss = storagescheme(Aval).

Pre/post conversions

It is often useful to generate some auxiliary code for converting data to and from the model's format. To do this, add a dictionary to the preconvert or postconvert attributes of a problem. For example, in an MPC problem

prob.preconvert['setupvars'] = []
for t in range(1, T+1):
    prob.preconvert['setupvars'].append((z[t+1], A*z[t] + B*v[t]))

will generate code for a function with signature void setupvars(Workspace work, Params params, Vars vars) that performs the assignments z[t+1] := A*z[t] + B*v[t] for t = 1, …, T+1. This function will appear in testsolver.c and will (by default) be called before solving each problem.

Algorithm parameter tuning

In initsolver.c, you'll find the following parameters. These can be tuned either at compile time or runtime. They are called, by default, as part of the initwork function.

work->maxiters = 50;
work->verbose = 1;
work->alpha = 0.05;
work->beta = 0.5;
work->eps = 0.01;
work->kappainit = @pyval{5/(2.0*n)}@;
work->gapfactor = 0.1;
work->Mbound = 1000;
work->normrp0 = square(1e-6);
work->rpscale = 1;
  • Set maxiters to a hard Newton step limit.

  • Adjust verbose to watch the solver output (or not).

  • Both alpha and beta are probably best left alone. They're unlikely to change much.

  • Adjust eps to set the required guaranteed maximum suboptimality.

  • Lowering gapfactor makes the algorithm lower kappa faster.

  • Ensure that Mbound is larger than the potential absolute value of all variables (including intermediate variables).

  • The parameter normrp0 is used to determine when primal feasibility has been achieved.

  • It's probably best to leave rpscale at 1. Lowering it will adjust kappa at every step, whether it's justified or not.