libprima / prima

PRIMA is a package for solving general nonlinear optimization problems without using derivatives. It provides the reference implementation for Powell's derivative-free optimization methods, i.e., COBYLA, UOBYQA, NEWUOA, BOBYQA, and LINCOA. PRIMA means Reference Implementation for Powell's methods with Modernization and Amelioration, P for Powell.
http://libprima.net
BSD 3-Clause "New" or "Revised" License
293 stars 37 forks source link

Consider leveraging the new MATLAB build tool. #20

Open acampbel opened 1 year ago

acampbel commented 1 year ago

R2022b shipped a new MATLAB build tool. R2023a added incremental build features. Much more development is ongoing.

The setup.m file in this repository looks like it is doing activities a build tool might be leveraged for. Would definitely be interested in feedback you may have on the new build tool and where it can use improvement for your workflow:

More info: https://www.mathworks.com/help/matlab/build-automation.html

zaikunzhang commented 1 year ago

Hello @acampbel ! Thank you for your comments!

Currently, the PRIMA project implements several optimization solvers in modern Fortran, and provides a MATLAB interface to use the solvers under MATLAB. This interface calls the mexified version of the Fortran code. setup.m basically does the mexification and sets the paths.

I have two questions.

  1. Is there a way to package my project so that users can use the mexified solvers out of the box after downloading the package, without any need to mexify the Fortran code locally? If yes, how? I would like the package to be usable under Linux, macOS, and Windows.

  2. Does the build tool you mentioned help me to build the package towards the above-mentioned objective? If yes, how?

As an example, we may consider the distribution of Python packages that wrap Fortran/C code: we build (compile) the wheels, and make the package available on pypi; then users can get the package by a simple pip install, which will obtain the compiled and ready-to-use version of the package without any need for local compilation. Is there a way to distribute MATLAB packages in a similar way?

Thank you very much!

Best regards, Zaikun

acampbel commented 1 year ago

Yes, this will likely take some work to get going on your project, but you can create a toolbox package from the code that includes all the Mex files you have created on the 3 platforms you listed. The build tool can help you organize your build pipeline and create those toolbox packages both within your local matlab and the ci build. You will likely need at least 4 jobs to run, one for each platform and one to gather all of the derived artifacts (the Mex files, etc) and package them into a toolbox package (*mltbx) Once you do that you can upload these packages to some location like GitHub releases or to the file exchange. If they are on the file exchange users can install them using add-ons apis.

Does that help?

zaikunzhang commented 1 year ago

Thank you @acampbel for the information.

  1. Is it ensured that the MEX files compiled on one Linux machine can run on another one with the same system, but the versions of the system and MATLAB might be different? For example, the MEX files are compiled on Ubuntu 22.04 with MATLAB R2022a, the compiler being gfortran 12. Will the MEX files work on Ubuntu 20.04 with MATLAB R2023a without gfortran installed? I have the same question for macOS and Windows, respectively.

  2. Is it legal to distribute the compiled MEX files? Does it violate the copyright / EULA of MATLAB? (On Windows, I the compiler will be Intel oneAPI, and I am not sure whether Intel has some restriction on the compiled binaries produced by its compilers).

Many thanks and best regards, Zaikun

acampbel commented 1 year ago

Hi @zaikunzhang,

  1. I believe that this is the case, but I am not the expert on MEX and it various compatibilities. I do indeed believe however that it is a very stable API that works across versions, compilers, etc. Really to get a definitive answer though it would be best to ask support@mathworks.com who is better equipped to answer that question or find the best person in the organization to do so.
  2. It is definitely appropriate to distribute the compiled mex files as far as we are concerned. I dont know any details about the oneAPI compiler and any restrictions it may have. For that aspect you may need to check in with the folks who support the oneAPI compiler.

Thanks! Andy

acampbel commented 1 year ago

Hello @acampbel ! Thank you for your comments!

Currently, the PRIMA project implements several optimization solvers in modern Fortran, and provides a MATLAB interface to use the solvers under MATLAB. This interface calls the mexified version of the Fortran code. setup.m basically does the mexification and sets the paths.

I have two questions.

  1. Is there a way to package my project so that users can use the mexified solvers out of the box after downloading the package, without any need to mexify the Fortran code locally? If yes, how? I would like the package to be usable under Linux, macOS, and Windows.
  2. Does the build tool you mentioned help me to build the package towards the above-mentioned objective? If yes, how?

As an example, we may consider the distribution of Python packages that wrap Fortran/C code: we build (compile) the wheels, and make the package available on pypi; then users can get the package by a simple pip install, which will obtain the compiled and ready-to-use version of the package without any need for local compilation. Is there a way to distribute MATLAB packages in a similar way?

Thank you very much!

Best regards, Zaikun

Here is an example of a repo that is doing something similar to what you describe:

https://github.com/cafarm/matlab-glfw