Dedicated to the late Professor M. J. D. Powell FRS (1936--2015)
- What
- Why
- How
- Current status
- Bug fixes
- Improvements
- Who was Powell?
- A "fun" fact
- Acknowledgment
- Citing PRIMA
- Charityware
- Contact
- Mirrors
- Star history
PRIMA is a package for solving general nonlinear optimization problems without using derivatives. It provides the reference implementation for Powell's renowned derivative-free optimization methods, i.e., COBYLA, UOBYQA, NEWUOA, BOBYQA, and LINCOA. The "P" in the name stands for Powell, and "RIMA" is an acronym for "Reference Implementation with Modernization and Amelioration".
PRIMA is part of a research project funded by the Hong Kong Research Grants Council and the Department of Applied Mathematics (AMA) at the Hong Kong Polytechnic University (PolyU). The current version is ready to be used in Fortran, in C, in Python, in MATLAB, and in Julia.
PRIMA was initiated by Zaikun Zhang in July 2020, based on the PDFO package by Tom M. Ragonneau and Zaikun Zhang.
See Zaikun Zhang's talk on PRIMA at The 10th International Congress on Industrial and Applied Mathematics for more information.
Professor Powell carefully implemented his derivative-free optimization methods into publicly available solvers, which are genuine masterpieces. They are widely used by engineers and scientists. For instance, see Section 1 of a recent paper on Powell's solvers as well as the Google searches of COBYLA and BOBYQA.
However, Professor Powell's implementation was done in Fortran 77. The code is nontrivial to understand or maintain, let alone extend. For many practitioners, this has become an obstacle to exploiting these solvers in their applications. Even worse, it has hindered researchers from exploring the wealth left by Professor Powell. By all means, it is necessary to make the solvers available in languages other than Fortran promptly, first wrapping Powell's code, which is the objective of PDFO, and then providing native and modernized implementations, which is the mission of PRIMA.
Before he passed, Professor Powell had asked me and Professor Nick Gould to maintain his solvers. This is an honorable mission. To make the solvers more accessible, I started PRIMA. It is a project similar to the translation, interpretation, and annotation of Euclid’s Elements. It will make Powell's solvers easily understandable to everyone, not only the experts. Few people remember who translated Elements, but it is a job that must be done.
PRIMA aims to provide the reference implementation of Powell's methods in modern languages, including modern Fortran (F2008 or newer), C/C++, Python, MATLAB, Julia, and R. It will be a faithful implementation, in the sense that the code will be mathematically equivalent to Powell’s, except for the bug fixes and improvements made intentionally.
The focus is to implement these methods in a structured and modularized way so that they are understandable, maintainable, extendable, fault-tolerant, and future-proof. The code will have no GOTO (of course) and will use matrix-vector procedures instead of loops whenever possible. In doing so, PRIMA codes the algorithms in a way that we would present them on a blackboard. Such an implementation will enable us to get a deeper understanding of Powell's methods and pave the way for new developments based on them.
There do exist "translations" of Powell's Fortran 77 code in other languages. For example, NLopt contains a C version of COBYLA, NEWUOA, and BOBYQA, but the C code in NLopt is translated from the Fortran 77 code straightforwardly, if not automatically by f2c, and hence inherits the style, structure, and probably bugs of the original Fortran 77 implementation. Note, however, that Py-BOBYQA is a true translation of BOBYQA to Python, with significant improvements.
The mission of PRIMA is nontrivial due to the delicacy of Powell's algorithms and the unique style of his code. To ensure the faithfulness of PRIMA, the modern Fortran version was started by refactoring Powell's code into the free form via a small MATLAB tool. However, such refactored code is far from what is desired, because it inherits completely the structure and style of Powell's code except for the layout. Significant modifications are needed to reorganize (indeed, to rewrite) the code. To maintain the faithfulness and quality of the reference implementation, extensive tests are conducted after each and every tiny modification, using the CUTEst problems via MatCUTEst. The tests do not only verify the faithfulness of the implementation but also check that the solvers behave properly even if they are invoked with improper inputs or encounter failures of function evaluations. Stress tests are also conducted periodically to verify that the solvers work correctly without running into errors when applied to excessively large problems.
The tests are automated by GitHub Actions. As of August 2023, more than 45,000 "workflows" have been successfully run by GitHub Actions. Normally, each workflow consists of ~ 5 (sometimes more than 200) randomized tests, each test taking from tens of minutes to several hours (the maximum is 6 hours, after which the test will be canceled automatically). In other words, PRIMA has been verified by more than 200,000 hours (or more than 20 years) of randomized tests. Code must be battle-tested before becoming software.
Since each GitHub Team account can only run at most 60 GitHub Actions workflows concurrently, I have to distribute this large amount of tests to multiple Team accounts as follows.
After almost three years of intensive coding, the modern Fortran version of PRIMA was finished by December 2022. It can be compiled using CMake as follows.
git clone --depth 1 https://github.com/libprima/prima.git
cd prima
cmake -S . -B build -DCMAKE_INSTALL_PREFIX=install
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/
.
In case CMake fails to find your Fortran compiler,
you can indicate it by specifying -DCMAKE_Fortran_COMPILER=/path/to/your/Fortran/compiler
.
Similarly, set -DCMAKE_C_COMPILER=/path/to/your/C/compiler
for your C compiler if needed.
Examples on 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
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$PWD/../../../install/lib ./install/bin/cobyla_example_1
A C binding to the Fortran library is available in the c/
folder.
In the same way as the Fortran library, it can be compiled using CMake,
which should also create the primac
library for C compilation, 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
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$PWD/../../../install/lib ./install/bin/cobyla_example
- An interface is provided for using the modern Fortran implementation in Python.
- The inclusion of PRIMA into SciPy is under discussion. It will replace the buggy and unmaintained Fortran 77 version of COBYLA underlying
scipy.optimize.minimize
, and make the other four solvers available to all SciPy users. - A native Python implementation of PRIMA is under development.
- An interface is provided for using the modern Fortran implementation in MATLAB.
- A pure MATLAB version of NEWUOA is implemented. It was generated straightforwardly (indeed, automatically) from an earlier version of the modern Fortran code (with the help of Mr. Galann Pennec). The other four solvers will be implemented in MATLAB similarly.
- A Julia interface is provided
by
PRIMA.jl
. It is registered in the General Registry of Julia asPRIMA
.
- Interfaces for using the modern Fortran implementation in other languages will be available later.
- Given the modern Fortran version, native implementations in other languages become much easier, because we now have a structured and modularized implementation as a reference. My team will implement the methods in other languages in this way. This is the main motivation for developing the modern Fortran version first — to provide a modernized reference implementation for the development in other languages.
PRIMA has fixed some serious issues in the original Fortran 77 implementation of Powell's methods. Note that all of them are problems in the Fortran 77 code rather than flaws in the algorithms.
The examples given below are bugs or requests sent to SciPy, NLopt, nloptr, OpenTURNS, etc., which are reputable packages that wrap/interface the original Fortran 77 implementation of Powell's solver. Inevitably, they suffer from the bugs in the Fortran 77 code.
-
The Fortran 77 solvers may get stuck in infinite loops.
-
The Fortran 77 solvers may crash with segmentation faults due to uninitialized variables that are used as indices.
-
Fortran 77 COBYLA may not return the best point that is evaluated; sometimes, the returned point can have a large constraint violation even though the starting point is feasible.
Thanks to the improvements introduced into the new implementation, PRIMA outperforms Powell's
original code in terms of the number of function evaluations, which is the standard performance
indicator in derivative-free optimization.
Below are the performance profiles
of the PRIMA solvers compared with Powell's implementation, the convergence tolerance being
- NEWUOA on unconstrained CUTEst problems of at most 200 variables
- BOBYQA on bound-constrained CUTEst problems of at most 200 variables
- LINCOA on linearly constrained CUTEst problems of at most 200 variables and 20000 constraints
- COBYLA on nonlinearly constrained CUTEst problems of at most 100 variables and 10000 constraints
- UOBYQA on unconstrained CUTEst problems of at most 100 variables
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 two recipients of the first Dantzig Prize from the Mathematical Programming Society (MOS) and Society for Industrial and Applied Mathematics (SIAM). This is considered the highest award in optimization.
In the past years, while working on PRIMA, I have spotted a dozen of bugs in reputable Fortran compilers and three bugs in MATLAB. Each of them represents days of bitter debugging, which finally led to the conclusion that it was not a problem in my code but a flaw in the Fortran compilers or in MATLAB. From a very unusual angle, this reflects how intensive the coding has been.
The bitterness behind this "fun" fact is exactly why I work on PRIMA: I hope that all the frustrations that I have experienced will not happen to any user of Powell's methods anymore. I hope I am the last one in the world to decode a maze of 244 GOTOs in 7939 lines of Fortran 77 code — I did this for three years and I do not want anyone else to do it again.
PRIMA is dedicated to the memory of the late Professor Powell with gratitude for his inspiration and for the wealth he left to us.
I am grateful to Professor Ya-xiang Yuan for his everlasting encouragement and support.
The development of PRIMA would have been a mission impossible without the groundwork laid by the PDFO package of Tom M. Ragonneau and Zaikun Zhang. PDFO is Chapter 3 of Ragonneau's thesis co-supervised by Zaikun Zhang and Professor Xiaojun Chen, with financial support from the Hong Kong Ph.D. Fellowship Scheme (ref. PF18-24698).
PRIMA is a long-term project, which would not have been sustainable without the continued funds from the Hong Kong Research Grants Council (ref. PolyU 253012/17P, PolyU 153054/20P, PolyU 153066/21P, and PolyU 153086/23P) and The Hong Kong Polytechnic University (PolyU), in particular the Department of Applied Mathematics (AMA).
PRIMA has taken me significant energy and time. I will be delighted if it is useful to you. All I need is a citation / acknowledgment. Note that PRIMA contains bug fixes and improvements that do not exist in Powell's original implementation of the solvers. Results produced by PRIMA may not be reproducible using the original solvers.
If you use PRIMA, please cite it as follows. The citation will be pointed to my paper on PRIMA when I finish it.
[1] Z. Zhang, PRIMA: Reference Implementation for Powell's Methods with Modernization and Amelioration, available at http://www.libprima.net, DOI: 10.5281/zenodo.8052654, 2023
@misc{Zhang_2023,
title = {{PRIMA: Reference Implementation for Powell's Methods with Modernization and Amelioration}},
author = {Zhang, Z.},
howpublished = {available at http://www.libprima.net, DOI: 10.5281/zenodo.8052654},
year = {2023}
}
In addition, Powell’s methods can be cited as follows.
[2] M. J. D. Powell, A direct search optimization method that models the objective and constraint functions by linear interpolation, In Advances in Optimization and Numerical Analysis, eds. S. Gomez and J. P. Hennart, pages 51--67, Springer Verlag, Dordrecht, Netherlands, 1994
[3] M. J. D. Powell, UOBYQA: unconstrained optimization by quadratic approximation, Math. Program., 92(B):555--582, 2002
[4] M. J. D. Powell, The NEWUOA software for unconstrained optimization without derivatives, In Large-Scale Nonlinear Optimization, eds. G. Di Pillo and M. Roma, pages 255--297, Springer, New York, US, 2006
[5] M. J. D. Powell, The BOBYQA algorithm for bound constrained optimization without derivatives, Technical Report DAMTP 2009/NA06, Department of Applied Mathematics and Theoretical Physics, Cambridge University, Cambridge, UK, 2009
[6] T. M. Ragonneau and Z. Zhang, PDFO: a cross-platform package for Powell's derivative-free optimization solvers, arXiv:2302.13246, 2023
Remarks
-
LINCOA seeks the least value of a nonlinear function subject to linear inequality constraints without using derivatives of the objective function. Powell did not publish a paper to introduce the algorithm.
-
The paper [6] introduces the PDFO package rather than PRIMA. Nevertheless, it provides a good introduction to Powell's methods.
PRIMA is charityware, distributed for free under its license. If you appreciate it, you may consider making a donation to a charity that you trust (in addition to citing & acknowledging PRIMA). This is only a suggestion, not an obligation.
The inspiration comes from Vim, with which Zaikun Zhang typed all his PRIMA code.
In case of problems, open a GitHub issue or contact Zaikun Zhang.
stardev ranking: 28 among 30,975 Fortran repos as of Jan. 2024.
Thank you for your support.