Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GNU Octave support #26

Open
rdzman opened this issue Aug 31, 2020 · 6 comments
Open

GNU Octave support #26

rdzman opened this issue Aug 31, 2020 · 6 comments

Comments

@rdzman
Copy link

rdzman commented Aug 31, 2020

Has the MEX interface to OSQP been successfully built for GNU Octave? If not consider this a feature request.

I tried following the instructions for building the MATLAB interface under Octave and initially got an error about verlessThan not being supported in Octave. After manually eliminating those calls in make_osqp.m, I get ...

CMake Error at CMakeLists.txt:201 (message):
  You need Matlab libraries to build the Matlab interface



-- The C compiler identification is AppleClang 11.0.3.11030032
-- The CXX compiler identification is AppleClang 11.0.3.11030032
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- We are on a Darwin system
-- Embedded is OFF
-- Printing is ON
-- Profiling is ON
-- User interrupt is ON
-- Floats are OFF
-- Long integers (64bit) are ON
-- Code coverage is OFF
-- MKL Pardiso: ON
-- Could NOT find Matlab (missing: Matlab_INCLUDE_DIRS Matlab_MEX_LIBRARY Matlab_MEX_EXTENSION Matlab_MX_LIBRARY) (found version "NOTFOUND")
-- Configuring incomplete, errors occurred!

That was on macOS. I got essentially the same error when I tried it on Linux.

I have very little experience with Octave and MEX, but I do know that it is close enough to the MATLAB MEX interface that IPOPT's Matlab interface builds under both MATLAB and Octave.

I suspect that someone with experience could get the build scripts to work in Octave with little effort.

@goulart-paul
Copy link
Collaborator

We did have a user some time ago who managed to get it to work and intended to package it as a third-party interface. I can't recall what happened though - I guess it was not finished or was never published. Perhaps @bstellato or @imciner2 remembers.

Using the canned build script make_osqp.m is probably complicating things somewhat. If I look into the CMakeLists.txt in the main OSQP repository, the configuration for CMAKE with the Matlab option is mostly just checking for the existence of matlab and configuring mex to use the pre-2018 mxArray interfaces (specifically, right here).

It might be easier instead to first build osqp as a standalone library first outside of Octave. Then try to compile osqp_mex.c directly via the mex utility linking directly to the OSQP static library, being sure to specify -DMATLAB_MEXSRC_RELEASE=R2017b (or whatever is the equivalent on Octave). This is more or less what is happening anyway, just in a single step.

@goulart-paul
Copy link
Collaborator

I have just tried the above and confirmed that it works for me on OSX with no modification to the source. The only thing that needs to be done is to 1) compile the osqp static library outside of octave, then 2) use mex within octave to compile the mex interface file osqp_mex.cpp, linking to the static library and specifying the path to the osqp headers. No fancy options seem to be required.

I suggest that we leave this open for now though, since it would be nice to implement this directly into the main project CMAKE scripts and/or provide an Octave-compatible build script for one line compilation.

@rdzman
Copy link
Author

rdzman commented Sep 1, 2020

Wonderful! Thanks.

Could you give me an example of the mex command you used in step 2? Not sure of the syntax required to specify the paths to the library and headers.

@goulart-paul
Copy link
Collaborator

if you follow the standard C install described here, then the required headers will be installed by default someplace like /usr/local/include/qdldl and /usr/local/include/osqp. The static library will be somewhere like /usr/local/lib/libosqp.a (note : you want the static one, not the dynamic one with a .dylib extension or similar).

That's normally enough for OSQP, but in the case of the matlab interface we also use an internal header from the QDLDL linear solver which seems not to get exported on install (maybe this is a bug, which I will report in a separate issue). I had to access it directly (from the osqp-matlab repo) in ./osqp_sources/lin_sys/direct/qdldl/

You can then do this:

mex -I/usr/local/include/osqp -I/usr/local/include/qdldl -I./osqp_sources/lin_sys/direct/qdldl/ osqp_mex.cpp /usr/local/lib/libosqp.a

When doing that I got a warning about the header Matrix.h (presumably some matlab header) with a case error in the filename. It didn't prevent it from building though.

@rdzman
Copy link
Author

rdzman commented Sep 1, 2020

Exactly what I needed. Thanks! I got it working. But I agree, it would be nice to have this integrated into the main project for easy one-line compilation.

@yasirroni
Copy link

Hi, @goulart-paul ,
Any update regarding this request?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants