PRIMA: CMake building system and C interface available

PRIMA is a package for solving general nonlinear optimization problems without using derivatives. It provides the reference implementation for the late Professor Powell’s renowned 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.

After almost three years of intensive coding, the modern Fortran version of PRIMA has been finished by December 2022.

Thanks to the great contribution of Julien Schueller, PRIMA now has a CMake building system and a C interface.

Fortran

To compile the Fortran library, do the following.

git clone --depth 1 https://github.com/libprima/prima.git
cd prima
cmake -S . -B build -DCMAKE_INSTALL_PREFIX=install -DBUILD_SHARED_LIBS=OFF
cmake --build build --target install

This should create the primaf library for Fortran usage, located in the install/lib directory
to be used with the module files in install/include/prima/mod.

Examples of how to use the library from an external code are available in fortran/examples.
Below is an illustration with COBYLA.

cd fortran/examples/cobyla
cmake -S . -B build -DCMAKE_INSTALL_PREFIX=install -DPRIMA_DIR=$PWD/../../../install/lib/cmake/prima/
cmake --build build --target install
./install/bin/cobyla_example

C

The compilation of the Fortran library also produces the primac library for C usage, located in install/lib to be used with the prima.h header in install/include/prima.

Examples on how to use the library from an external code are available in c/examples.
Below is an illustration with COBYLA.

cd c/examples/cobyla
cmake -S . -B build -DCMAKE_INSTALL_PREFIX=install -DPRIMA_DIR=$PWD/../../../install/lib/cmake/prima/
cmake --build build --target install
./install/bin/cobyla_example

Who was Powell?

Michael James David Powell FRS was “a British numerical analyst who was among the pioneers of computational mathematics”. He was the inventor/early contributor of quasi-Newton method, trust region method, augmented Lagrangian method, and SQP method. Each of them is a pillar of modern numerical optimization. He also made significant contributions to approximation theory and methods.

Among numerous honors, Powell was one of the first two recipients of the Dantzig Prize from the Mathematical Programming Society (MOS) and Society for Industrial and Applied Mathematics (SIAM). This is considered the highest award in optimization.

9 Likes

The next low-hanging apple would be to make PRIMA available under fpm.

2 Likes

Excellent work. The organization and code/documentation quality is remarkable. I just built the library in WSL. CMake had difficulty finding the Fortran compiler with -- The Fortran compiler identification is unknown, despite having 5 Fortran compilers in the OS bin directory. I could readily solve it by specifying -DCMAKE_Fortran_COMPILER=/usr/bin/gfortran-13. This may be an exception, but it might be worth having a brief troubleshooting discussion in the installation guidelines just in case people unfamiliar with Fortran or CMake face the same problem. I have used Powell methods in the past and look forward to using the modernized version in the coming months.

1 Like

Thank you @shahmoradi for the encouraging words.

The organization and code/documentation quality is remarkable.

PRIMA still has a long way to go regarding documentation.
Currently, the README is more like a presentation of the project rather than a user-oriented documentation, although I wrote it in that way on purpose. I hope the abundant comments in the Fortran code could help those who are interested in the methods, but we really need to generate better documentation using tools like FORD.

CMake had difficulty finding the Fortran compiler with -- The Fortran compiler identification is unknown , despite having 5 Fortran compilers in the OS bin directory. I could readily solve it by specifying -DCMAKE_Fortran_COMPILER=/usr/bin/gfortran-13 . This may be an exception, but it might be worth having a brief troubleshooting discussion in the installation guidelines just in case people unfamiliar with Fortran or CMake face the same problem.

I have opened a GitHub issue about the problem you mentioned. Probably Julien will fix it.

I have used Powell methods in the past and look forward to using the modernized version in the coming months

Great! I look forward to more feedback from you.

Thank you.

1 Like

Response on GitHub from Julien Schueller:

cmake will only find compilers in the PATH with default names, I think it will be fine if there was a gfortran symlink

Does this explain the problem you encountered? You are invited to give comments under the GitHub issue.

Anyway, since you have five compilers installed, I guess at least one of them is in the PATH with default names, right?

Forcing CMake to recognize all possible variants of Fortran compiler names is likely a long shot. Adding a troubleshooting section in the README files to discuss this potential pitfall and how to fix it if it happens should be more than enough.

What I do to bypass CMake inadequacies is to add a wrapper script around CMake, which attempts to identify the Fortran compiler first following CMake’s approach and, if failed, through an aggressive search in the system bin directory. Then, I define the macro CMake_Fortran_COMPILER with one of the identified compilers on the CMake command line. If there is no compiler, I ask the user’s permission to install a Fortran compiler. This can never be foolproof. But I confess setting up such a pipeline has been a project for me.

1 Like

Thank you for the suggestion @shahmoradi . What about something like “In case CMake fails to find your Fortran compiler, you can indicate it by specifying -DCMAKE_Fortran_COMPILER=/path/to/your/Fortran/compiler” in the README?

1 Like

That’s what I originally meant to suggest.

Done. See CMake had difficulty finding the Fortran compiler · Issue #53 · libprima/prima · GitHub
Thank you for your suggestion @shahmoradi .

1 Like

Excellent, thank you. Again as an end user, I am very much impressed by the within-code documentation quality and code clarity.

1 Like