I’ve managed to install CVX with SDPT3 and Sedumi on Octave seemingly alright, but whenever I run any optimization script (whether the built-in examples, or my own which work perfectly fine in MATLAB), I get the following output:
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
Status: Solved
Optimal value (cvx_optval): +0.367178
error: cellfun: all values must be scalars when UniformOutput = true
This last line about cellfun is the one that keeps coming up all the time. I checked and this is not in my own code, i.e. the built-in examples have the same error. What is it about CVX’s usage of cellfun that Octave does not like?
I have succesfully installed cvx3.0beta under Octave 9 and also used it for serveral days (with sedumi and sdpt3 solver), getting proper results (the same as in Matlab) and a reasonable execution time.
Here is what I did: (Most suggested code changes are from other forum posts above.)
Install the latest Octave version from here: https://octave.org/download
I used Octave 9.1.0 under Windows, that is: octave-9.1.0-w64-installer.exe
Download the latest cvx beta release from here: https://cvxr.com/cvx/beta/
and uncompress it into a folder of your choice (let’s call it cvx/ for now).
I used cvx 3.0beta for 64-bit Windows, that is: cvx-w64.zip
Do a couple of smaller code changes on the cvx code:
in cvx_version.m at line 50, add surrounding underscores: comp = __octave_config_info__('canonical_host_type');
in cvx_version.m at line 53, add current host type: case 'x86_64-w64-mingw32', msub = 'o_win'; izpc = true;
in cvx_error.m at line 54, add char() to silence the “implicit conversion” warning: lines{end+1} = [ char(32*ones(1,n_indent)), chunk ];
in cvx/sedumi/install_sedumi.m at line 105, add current host type: case 'x86_64-w64-mingw32', mdir = 'o_win';
in cvx/sdpt3/install_sdpt3.m at line 47, add current host type: case 'x86_64-w64-mingw32',
in cvx/shims/cvx_glpk.m in line 95, use cvx_ namespace for quiet function: if cvx_quiet,
in the 5 m-files with the name display.m in the following 5 folders: cvx/lib/@cvx, cvx/lib/@cvxcnst, cvx/lib/@dvxdual, cvx/lib/@dvxprob, cvx/lib@cvxtuple
replace this code line: long = ~isequal(get(0,'FormatSpacing'),'compact');
by this one: long = true;
(There is probably a better fix to solve this problem…)
in the following 6 files: cvx/keywords/variable.m , cvx/builtins/@cvx/subsagn.m , cvx/keywords/dual.m , cvx/keywords/expression.m , cvx/keywords/expressions.m, cvx/keywords/variables.m
change all occurances of throw() into cvx_throw()
and also change all occurances of rethrow() into cvx_throw()
in the file cvx/lib/cvx_throw.m
change rethrow() into warning()
in the following 7 files: cvx_setup.m, cvx_startup.m, cvx_ecos.m, cvx_glpk.m, cvx_csc.m, cvx_sdpt3.m, cvx_sedumi.m
delete the “-all” part in all “which” commands
for example in line 84 of cvx_setup.m then should look like this: solver2 = which( 'cvx_solver_shim' );
(This is neccesary because Octave currently outputs very much text to the console, when calling the path() function during the “echo on” state. This Octave behavior has been filed as bug here: https://savannah.gnu.org/bugs/?65607 )
Open the file cvx/examples/sparse_heuristics/sparse_solution.m in a capable
text editor (for example notepad++) and save it again with UTF-8 encoding.
compile the three missing oct files of cvx:
on the Octave console, inside the cvx folder, call: cvx_compile
compile the missing oct files for the (in my case two) solvers by running the following code: cd sedumi, install_sedumi -nopath cd sdpt3, install_sdpt3 -nopath
set-up and test the resulting cvx installation by running the following code: cd .., cvx_setup
remark on execution time: With my optimization problems, the Sedumi solver was fastest under Octave (only competing with sdpt3), and it was most of the times (only) 3x slower than in Matlab.
Conculding remark: I have never observed the cellfun error (that was reported many times before in this forum post), neither with cvx’s built-in examples, nor with my own code. (This error might still persist with complex variables, but I could not find any example code to provoke this error.) Maybe the time is ready now to officially support cvx under Octave?
Indeed, the new open-source bundles of CVX 2.2 do include pre-compiled MEX files.
@Hardy314 can you try the latest 2.2 build, downloaded from GitHub, and share your experience? I’m willing to review pull requests from the community that go towards improvements such as this.
I have now also tested the cvx 2.2.2 release bundle from github. Here is what I have done in detail:
Used latest Octave version from here: https://octave.org/download
I used Octave 9.1.0 under Windows, that is: octave-9.1.0-w64-installer.exe
Download the latest cvx release from github: https://github.com/cvxr/CVX/releases/tag/2.2.2
and uncompress it into a folder of your choice.
I used cvx 2.2.2 , that was named: cvx.zip
Do a couple of smaller code changes on the cvx code:
in cvx_error.m at line 44, add char() to silence the “implicit conversion” warning: lines{end+1} = [ char(32*ones(1,n_indent)), chunk ];
(new): same as above in line 38 of cvx_error.m
(new): add one line, at line 40, in cvx_version.m:
msub = cvx___.msub;
(This seems like a general, non-Octave-specific, bug in cvx.2.2.2 to me.)
in the 3 m-files with the name display.m in the following 3 folders: cvx/lib/@cvxcnst, cvx/lib/@cvxdual, cvx/lib/@cvxobj
replace this code line: long = ~isequal(get(0,'FormatSpacing'),'compact');
by this one: long = true;
(There is probably a better fix to solve this problem…)
in the following 7 files: cvx_glpk.m, cvx_gurobi.m, cvx_mosek.m, cvx_sdpt3.m, cvx_sedumi.m, cvx_setup.m, cvx_startup.m
delete the “-all” part in all “which” commands
for example in line 21 of cvx_sedumi.m then should look like this: fpaths = [ fpaths ; which( fname ) ];
(This is neccesary because Octave currently outputs very much text to the console, when calling the path() function during the “echo on” state. This Octave behavior has been filed as bug here: https://savannah.gnu.org/bugs/?65607 )
Open the file cvx/examples/sparse_heuristics/sparse_solution.m in a capable
text editor (for example notepad++) and save it again with UTF-8 encoding.
(new) in cvx_version.m, line 50: izpc = true;
Because Octave under Windows also uses “backslash” in path names.
(We should probably check in more detail here, to also match Octave under linux uses a slash instead of a backslash.)
(new info) included mex files for Octave, do NOT work under Octave 9.
My personal opinion: under Octave the mex files should ALWAYS be re-compiled during cvx-installation.
Reason: mex-files from different Octave versions are usually not binary compatible. But this re-compilation is no problem because Octave is always shipped with a compiler included!
→ I now copied the m-file cvx_compile from cvx3.0beta into the cvx folder!
re-compile the three missing oct files of cvx:
on the Octave console, inside the cvx folder, call: cvx_compile -rebuild
compile the missing oct files for the (in my case two) solvers by running the following code: cd sedumi, install_sedumi -nopath -rebuild
→ see a bunch of compiler warnings (no errors) cd sdpt3, install_sdpt3 -nopath -rebuild
set-up and test the resulting cvx installation by running the following code: cd .., cvx_setup
I can still run all my own optimization scripts without any problems, getting reasonable results in reasonable time. (I cannot nail it down, but it seems to me that cvx2.2.2 is running 50% slower with sedumi under Octave than cvx3.0beta did.)
Just let me know if I can help further with an Octave-friendly cvx-release.