Skip to content

Instantly share code, notes, and snippets.

@TOTON95
Last active May 18, 2021 18:36
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save TOTON95/e246babce1aea2df809509b4f5568956 to your computer and use it in GitHub Desktop.
Save TOTON95/e246babce1aea2df809509b4f5568956 to your computer and use it in GitHub Desktop.
Guide to install CVX into Octave / Ubuntu (16.10 & 18.04)

Guide to install CVX into Octave / Ubuntu (16.10 & 18.04)

This guide was made using different solutions shared at the CVX forums and experimentation, to successfuly install the CVX tools into Octave running in Ubuntu 16.10 and 18.04.


Dependencies:

OpenBLAS

$ sudo apt-get install libopenblas-dev

Terminal

1. Create a directory for the Octave tools and move into it

$ mkdir ~/your/path/to/Octave_dir/ && cd ~/your/path/to/Octave_dir/

2. Clone the CVX tools (rework branch)

$ git clone -b rework https://github.com/cvxr/CVX.git/

3. Move into the CVX directory

$ cd CVX

4. The "git clone..." command will not copy the content in directories sedumi and sdpt3, since they are a link, they should be deleted

$ rmdir sedumi sdpt3

5. Place the solvers into the Tool's directory

$ git clone https://github.com/sqlp/sdpt3.git

$ git clone https://github.com/sqlp/sedumi.git

OCTAVE

Using the Octave's Command Window:

1. Move to the CVX directory in Octave

 cd ~/your/path/to/Octave_dir/CVX

1.5 (After Octave 5.0)

Change the function octave_config_info by _octave_config_info_ at cvx_version (line 50). Octave Ref

2. Run the CVX compiler

 cvx_compile

NOTE: If there are problems with the compilation just add the parameter '-rebuild'

3. Move to the sdpt3 directory in Octave and install the solver

 cd ~/your/path/to/Octave_dir/CVX/sdpt3
 install_sdpt3 -nopath

NOTE: If there are problems with the compilation just add the parameter '-rebuild'

4. Move to the sedumi directory in Octave and install the solver

 cd ~/your/path/to/Octave_dir/CVX/sedumi
 install_sedumi -nopath

NOTE: It may be posible that this solver will be unable to compile due to the f77blas.h file, jump to ALTERNATIVE METHODS section and rebuild (add parameter '-rebuild')

 install_sedumi -nopath -rebuild

5. Move to the CVX directory and run cvx_setup

 cd ~/your/path/to/Octave_dir/CVX
 cvx_setup

The CVX is installed!


Alternative Methods

If you are having problems with the f77blas.h file try the following:

(A) Open the file blksdp.h at ~/your/path/to/Octave_dir/CVX/sedumi and replace the line:

#include <f77blas.h>

For

#include <openblas/f77blas.h>

Rebuild and continue with step 5.

 install_sedumi -nopath -rebuild

(B) Open the file blksdp.h at ~/your/path/to/Octave_dir/CVX/sedumi and replace the line:

#include <f77blas.h>

For

#include "cblas.h"

Also

#define FORT(x) BLASFUNC(x)

For

#define FORT(x) cblas_ ## x

Finally add this line next to the line mentioned above

typedef int blasint;

You may need to modify other files like sdmauxScalarmul.c at the same directory, pay attention to the compiler's messages.

Remove ampersand from functions like:

FORT(dscal)(&n,&alpha,x,&one);

to become

FORT(dscal)(n,alpha,x,one);

Rebuild and continue with step 5.

 install_sedumi -nopath -rebuild

These are the solutions by the moment. Feel free to ask anything about this procedure to the forum or to me. Best wishes and good luck!

References:

[1] http://ask.cvxr.com/t/cvx-on-octave-discussion/975/34

[2] http://ask.cvxr.com/t/cvx-on-octave-discussion/975/16

@AndrijaPFC
Copy link

Hi,

After following your guide and seemingly installing everything correctly, when I try to run CVX (whether my own code which works perfectly under Matlab, or the built-in CVX examples), I get

Successive approximation method to be employed.
SDPT3 will be called several times to refine the solution.
Original size: 140 variables, 72 equality constraints
32 exponentials add 224 variables, 128 equality constraints

Cones | Errors |
Mov/Act | Centering Exp cone Poly cone | Status
--------+---------------------------------+---------
21/ 21 | 8.000e+00 1.500e+01 0.000e+00 | Solved
20/ 20 | 8.000e+00 1.727e+00 0.000e+00 | Solved
15/ 16 | 8.000e+00 3.928e-02 0.000e+00 | Solved
1/ 1 | 1.627e+00 9.941e-08 0.000e+00 | Solved
0/ 0 | 1.359e+00 0.000e+00 0.000e+00 | Solved

Status: Solved
Optimal value (cvx_optval): +0.367178

error: cellfun: all values must be scalars when UniformOutput = true

So it calls the solver once, and then hits this cellfun error. This error is not in my own code, it is somewhere inside CVX. When I try to run CVX again (the same script, or some other), I get just:

error: cellfun: all values must be scalars when UniformOutput = true

I am running Octave 4.2.2 on Pop!_OS 18.04 LTS 4.18.0-18-generic.
Any idea what is going on? Thanks!

@TOTON95
Copy link
Author

TOTON95 commented Aug 13, 2019

Sorry for the delay I've been busy through the semester, some people reported that different results were shown using Octave 5. So, I would suggest you move into this version, as I will see how to update this gist to solve it.

@matiasiescobar
Copy link

Hi, in the step 1.5 (octave) shoud said __octave_config_info__ (two _ at the beginning and end).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment