CVX on Octave: Discussion

Finding that the lineup CVX-3.0, Octave-4.0.0, Cygwin, windoze was a bit flaky (for some strange reason, opening my ~large csv output file in excel, then saving it under a different name “unblocked” octave in this config - any suggestions? weird, I was fflushing all the way…) I decided to brave a linux variant in a VM, and started again.

I picked a 32-bit Debian Jessie, and had to build Octave-4.0 and CVX again, and SeDuMi, SDPT3… Similar issues, this time I had to build openBLAS locally as well, because debian packages lag many revisions behind, and the debian package installer just never seemed to be able to pull in openBLAS to CVX’s satisfaction. But mostly it was the basic job of tracking down missing dependencies, using git, apt-get, wget, etc to pull stuff in, running make…

Long story short, it came up and was more stable (and faster!) under linux on a VM than in cygwin.

On Michael’s advice, I sought out the ECOS solver, and just now got it to compile and run ~clean as a CVX solver. A couple of issues here as well, not sure if it is ECOS/CVX, or CVX/Octave, or whatever, but posting here:

  • make sure CVX finds the right ECOS shim, the one that ships with CVX 3.0. The shim structure has changed, and there is an old 2.x style shim in the ECOS directories that can confuse CVX 3.0 if it picks it because of path search precedence.

  • there is also a library dependency (on the libut.so library) include directive in make_mex.m ("-lut" option) that I could’t resolve - these must be Matlab libs. I crossed my fingers, commented out the only reference I found, in “ctrlc.c” in ECOS/src, but of course it barfed when actually run from CVX (though ECOS seemed to run OK on native Octave). There seems to be lots of discussion about ctrl-c script interrupt when using the new Octave GUI. I chose to unblock some simple testing using ECOS by pulling the “#ifdef UNIX” code up to the Matlab section in ctrlc.c, tweaked it a bit to align with the Matlab vars, re-compiled ECOS, reran make_mex.m and cvx_setup, and got CVX to use ECOS ok, except that when I actually hit ctrl-c to the octave (GUI) command window, I hung the GUI.

Anyone out there know how to solve that last issue - to get decent ctrl-c handling for ECOS+CVX3.0 on Octave 4.0 using the new GUI?

cheers,
ben

This is great stuff. The funny thing is I’m the one that implemented CTRL-C support in the ECOS Mex file :slight_smile:

Doh! And ah, yes I see now in the header, thanks!

Hack workaround right now for me is to edit the ecos makemex and change -DCTRLC=1 to 0.

That way I can still interrupt my iterations of cvx/ecos’ iterations…

I’m just too dumb (lazy?) to know how to grab the ctrl-c interrupt from the GUI window handler (I suppose…) and then clean up afterwards… :cry:

I have just tried to install CVX3.0 beta. I encountered an “unexpected error” when I tried “cvx_setup” The following is the printout:

CVX: Software for Disciplined Convex Programming ©2014 CVX Research
Version 3.0beta, Build 1175 (1326ef2) Mon Nov 23 14:29:34 2015

Installation info:
Path: /home/pyue/octave/cvx
GNU Octave 4.0.0 on x86_64-unknown-linux-gnu
Verfying CVX directory contents:
WARNING: The following extra files/directories were found:
/home/pyue/octave/cvx/lib/cvx_bcompress_mex.mex
/home/pyue/octave/cvx/lib/cvx_bcompress_mex.o
/home/pyue/octave/cvx/lib/cvx_classify_mex.mex
/home/pyue/octave/cvx/lib/cvx_classify_mex.o
/home/pyue/octave/cvx/lib/cvx_eliminate_mex.mex
/home/pyue/octave/cvx/lib/cvx_eliminate_mex.o
/home/pyue/octave/cvx/sedumi/cholsplit.mex
/home/pyue/octave/cvx/sedumi/cholsplit.o
/home/pyue/octave/cvx/sedumi/choltmpsiz.mex
/home/pyue/octave/cvx/sedumi/choltmpsiz.o
(and 6 more files)
These files may alter the behavior of CVX in unsupported ways.
Loading preferences:
Global: /home/pyue/octave/cvx/cvx_prefs.mat … not found.
Local: /home/pyue/.cvx_prefs.mat … to be created.

Setting CVX paths…done.
Saving update path…done.
Searching for solvers…5 shims found.
3 solvers initialized (* = default):
GLPK unknown /usr/local/share/octave/4.0.0/m/optimization

  • SDPT3 4.0 {cvx}/sdpt3
    SeDuMi 1.34 {cvx}/sedumi
    2 solvers not found:
    ECOS https://github.com/ifa-ethz/ecos
    SCS https://github.com/cvxgrp/scs
    Saving updated preferences…done.
    Testing with a simple model…

    UNEXPECTED ERROR: ----------------------------------------------
    ‘mexnnz’ undefined near line 97 column 13
    Line 97: /home/pyue/octave/cvx/sdpt3/Solver/checkdepconstr.m

Please report this error to support, and include entire output of
CVX_SETUP in your support request.

Looks like you haven’t built the mex files for the solvers.

Thanks. I successfully installed SDPT3 without trouble. However, for SeDuMi, it needs some modifications. The following applies to Linux Mint (probably Ubuntu and Debian). First of all, there is no “f77blas.h”. Apparently, the current BLAS uses c-interface instead of Fortran. The header file, /usr/include/cblas.h, contains the prototypes. Hence, in order to use BLAS, cvx/sedumi/blkdsp.h needs to be modified:

#if !defined(BLKSDP)
#define BLKSDP
#include “mex.h”
#ifdef OCTAVE

if defined(__linux)

#include “cblas.h” // Newly added
#define FORT(x) cblas_ ## x // Newly added
typedef int blasint; // Newly added

else

#include “f77blas.h”
#define FORT(x) BLASFUNC(x)

endif

#else
#include “blas.h”
#define FORT(x) FORTRAN_WRAPPER(x)
typedef ptrdiff_t blasint;
#endif

Also, the parameter list of some BLAS functions have changed. These functions are: ddot(), dcopy(), dscal(), daxpy(), idamax(), which are used by blkchol2.c, sdmauxRdot.c, and sdmauxScalarmul.c. Basically, the passing arguments should not be preceded by an ampersand sign, e.g.,
FORT(dscal)(&n,&alpha,x,&one);
should be
FORT(dscal)(n,alpha,x,one);

Having modified the aforementioned files, I am able to install sedumi solver with:
install_sedumi -rebuild

Correction to my previous post. In my last post, I mentioned that I needed to modified blkchol2.c, sdmauxRdot.c, and sdmauxScalarmul.c. For Debian based distros such as Ubuntu, Mint, it is NOT needed if one apt-gets the libblas-dev package. Besides providing /usr/include/cblas.h, the package also provides /usr/include/cblas_f77.h. Hence, one keeps all the files intact in cvx/sedumi and only modifies one file, cvx/sedumi/blkdsp.h:

Instead of
#include “f77blas.h”
#define FORT(x) BLASFUNC(x)
one changes to or adds extra compile option:
#include “cblas_f77.h”
#define FORT(x) F77_ ## x
typedef int blasint;

That is all it needs to install_sedumi -rebuild

Hi
I just had some success with installing cvx on octave.
versions:
windows 10
octave 4.2.1
cvx 3.0b (from here: http://web.cvxr.com/cvx/beta/cvx-w64.zip )

workarounds i had to use:

  1. change line 53 of “cvx_version.m” to

case {‘i686-w64-mingw32’,‘x86_64-w64-mingw32’}, msub = ‘o_win’; izpc = true;

  1. compile mex files:

cd CVX_PATH
cvx_compile
cd CVX_PATH\sedumi
install_sedumi -nopath
cd CVX_PATH\sdpt3
install_sdpt3 -nopath
cd CVX_PATH
cvx_setup

where CVX_PATH is where i extracted the cvx installation files.

to test that everything seems to work i ran

CVX_PATH\examples\quickstart

i hope someone finds this useful. (and maybe fixes things to work more flawlessly).

That’s really great to hear. Thank you! Please continue to share your experiences as you use it in practice.

another bug and a workaround:
the code
get(0,'FormatSpacing')

doesn’t work in octave.
so i had to modify the “display.m” function of cvx to look like:
try long = ~isequal(get(0,'FormatSpacing'),'compact'); catch long = eval('! __compactformat__ ()'); end_try_catch

@Avi_SHMRI,

I actually get(0,'FormatSpacing') is also deprecated in MATLAB (Though still working).

@mcg,
Is CVX still under development at all?

Thank You.

Hi Michael,
Got following error after running cvx_setup:-

ᛔSetting CVX paths…

done.
Saving update path…done.
Searching for solvers…5 shims found.
3 solvers initialized (* = default):
GLPK unknown C:\Octave4.0.0\share\octave\4.0.0-qcom-2015-05-06\m\optimization

  • SDPT3 4.0 {cvx}\sdpt3
    SeDuMi 1.34 {cvx}\sedumi
    2 solvers not found:
    ECOS https://github.com/ifa-ethz/ecos
    SCS https://github.com/cvxgrp/scs
    Saving updated preferences…done.
    Testing with a simple model…

    UNEXPECTED ERROR: -----------------------------------------------------------
    ‘mexnnz’ undefined near line 97 column 13
    Line 97:
    C:\Users\navneetk\Downloads\cvx-w64\cvx\sdpt3\Solver\checkdepconstr.m

Please report this error to support, and include entire output of
CVX_SETUP in your support request.

Hi,
I got following error in cvx_compile.m.

error: temp(0): subscripts must be either integers 1 to (2^31)-1 or logicals
error: called from
cvx_version at line 81 column 11
cvx_compile at line 6 column 8

@mcg,

Does the current CVX uses the latest SDPT3?

It seems they made a very recent compatibility fix.

Hi there,

I was able to compile CVX in Octave 4.2.1 on Ubuntu Linux 16.04.

This is what I did:

  1. I downloaded cvx-a64.tar.gz (CVX 3.0 beta from this page http://cvxr.com/cvx/beta)
  2. I installed the package libopenblas-dev
  3. I replaced #include “f77blas.h” with #include <openblas/f77blas.h> in the file cvx/sedumi/blksdp.h, otherwise CVX won’t compile
  4. In Octave I launched the following commands (the same as in a previous message):

cd CVX_PATH
cvx_compile
cd CVX_PATH\sedumi
install_sedumi -nopath
cd CVX_PATH\sdpt3
install_sdpt3 -nopath
cd CVX_PATH
cvx_setup

  1. At this point, everything was OK.

  2. Then I was able to use CVX and it worked the same as in MATLAB on some problems, except for the following problem with the complex variable x:

     cvx_begin quiet
     cvx_precision best
         variable x(K) complex
         minimize (x' * R * x)
         subject to
             d'*x == c
             x' * S * x <=  b
     cvx_end             
    

with b, c real scalars, R a K x K complex hermitian matrix and d a complex K x 1 vector.

In Octave the following error was issued:

error: Disciplined convex programming error:
Invalid quadratic form: not real.
error: called from
cvx_throw at line 29 column 1
mtimes at line 155 column 13

I wasn’t able to solve this issue. Any idea?
Thanks,
RB

That’s good work! The good news is that your roadblock is not Octave dependent. The problem is that x' * R * x is not a perfectly real quantity due to roundoff errors. Just use real(x' * R * x) instead.

Oh, and do the same with x' * S * x.

Thanks for the fast answer.
I changed the block to:

    cvx_begin quiet
    cvx_precision best
        variable x(K) complex
        minimize real(x' * R * x)
        subject to
            d'*x == c
            real(x' * S * x) <=  b
    cvx_end             

and now the error message is shorter, but nearly the same:

error: Disciplined convex programming error:
Invalid quadratic form: not real.

(I forgot to mention that S is a KxK hermitian matrix, with R = inv(S)).

Oh, I see, actually, I don’t think the real() really helped you at all. I think the problem is that quad_form isn’t properly rejecting what, I assume, is the relatively small imaginary portion of the quadratic form. The only think I can think of is to replace it with the real equivalent; e.g.,

xq = [ real(x) ; imag(x) ];
Rq = [ real(R), imag(R)' ; imag(R),  real(R) ];
minimize (xq' * Rq * xq)

OK, I’ll try that monday.
However, there is no problem with this code in Matlab.
And I just saw you wrote on the CVX on Octave page: 'Complex variables will not work due to a known bug in Octave 4.0.'
Perhaps it’s the cause? I use Octave 4.2.1.
Thanks!