[WIP] MATLAB interface
Hi Charlie,
I've just written a first draft of the MATLAB interface. It has also some minor changes in the C/C++ interface. For now it's only a draft, may be unstable at the moment.
Track list:
- [x] Create low-level matlab mex functions
result = uno_optimize(model[, options, callbacks])andoptions = uno_options([preset]) - [x] Create readme for matlab interface
- [x] Create HS015 problem example
- [x] Use explicit sparsity pattern in matlab low-level interface
- [x] Add argument validation functions in
interfaces\Matlab\Uno_mex_utilities.hpp - [x] Add argument validation in
uno_optimizemex function - [x] Add high-level (fmicon-like) interface
- [x] Add github action (Windows)
- [ ] Add github action (MacOS)
Really cool Stefano! Do we need a self-hosted runner with a Matlab license to test the interface in a Github Action or can we do that on the Github runners?
Hi @cvanaret
As far I know, it's possible to use Matlab on the Github runners for public repos, so no need for self-hosted runners (see here). So far, I was able to build a Matlab mex (via cmake) even for a private repo without a Matlab license, as this step only requires the Matlab installation and doesn’t actually call MATLAB itself. I’ll try running a test on GitHub runners to confirm that this works as well.
Tested Matlab mex in Github runner: matlab-action-test No Matlab license needed
For Mac-os a workaround seems to be needed when building the mex using CMake: add the (typical) location(s) of libMatlabEngine.dylib to the mex rpath:
if(APPLE)
# This adds $matlabdir/extern/bin/maci64 (intel arch) and $matlabdir/extern/bin/maca64 (arm arch) to @rpath
# @executable_path is the location of the executable, i.e. matlab, typically $matlabdir/bin or $matlabdir/bin/<arch>
# This is also to solve bug in MATLAB R2023b, see
# https://it.mathworks.com/matlabcentral/answers/2044762-why-do-i-receive-a-library-not-loaded-rpath-libmatlabengine-dylib-error-when-running-a-mex-funct
set(MEX_RPATH "@executable_path/../extern/bin/maci64;@executable_path/../extern/bin/maca64;@executable_path/../../extern/bin/maci64;@executable_path/../../extern/bin/maca64")
set_target_properties(mex-target PROPERTIES
BUILD_RPATH "${CMAKE_BUILD_RPATH};${MEX_RPATH}"
INSTALL_RPATH "${CMAKE_INSTALL_RPATH};${MEX_RPATH}"
)
endif()
The Github action runs, well done :partying_face:
@stefphd sorry for the many changes we're merging into main :sweat_smile: Let me know if you need anything.