Uno icon indicating copy to clipboard operation
Uno copied to clipboard

[WIP] MATLAB interface

Open stefphd opened this issue 2 months ago • 5 comments

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]) and options = 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 inuno_optimize mex function
  • [x] Add high-level (fmicon-like) interface
  • [x] Add github action (Windows)
  • [ ] Add github action (MacOS)

stefphd avatar Oct 15 '25 15:10 stefphd

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?

cvanaret avatar Oct 16 '25 10:10 cvanaret

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.

stefphd avatar Oct 16 '25 13:10 stefphd

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()

stefphd avatar Oct 22 '25 09:10 stefphd

The Github action runs, well done :partying_face:

cvanaret avatar Oct 23 '25 19:10 cvanaret

@stefphd sorry for the many changes we're merging into main :sweat_smile: Let me know if you need anything.

cvanaret avatar Oct 24 '25 07:10 cvanaret