Skip to content

Commit fde596e

Browse files
committed
250403.145021.CST [skip ci] add About in pyprima README
1 parent 07922f9 commit fde596e

1 file changed

Lines changed: 33 additions & 4 deletions

File tree

pyprima/README.md

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,39 @@
1+
## About
2+
3+
This is a Python translation of the [modern-Fortran reference implementation](https://github.com/libprima/prima/tree/main/fortran)
4+
for Powell's derivative-free optimization solvers, which is available at `fortran/` under the root directory.
5+
It is supposed to be a faithful translation, [producing bit-for-bit identical results as the Fortran
6+
reference implementation](https://github.com/scipy/scipy/pull/22350#issue-2795978526).
7+
If you notice a difference, [raise an issue](https://github.com/libprima/prima/issues/new).
8+
9+
Due to [bug-fixes](https://github.com/libprima/prima#bug-fixes) and [improvements](https://github.com/libprima/prima#improvements),
10+
the modern-Fortran reference implementation by [Zaikun Zhang](https://www.zhangzk.net)
11+
behaves differently from the original Fortran 77 implementation by [M.J.D. Powell](https://www.zhangzk.net/powell.html),
12+
even though the algorithms are essentially the same. Therefore, it is important to point out that you are using
13+
PRIMA rather than the original solvers if you want your results to be reproducible.
14+
15+
Compared to Powell's Fortran 77 implementation, the modern-Fortran implementation and hence this Python
16+
translation [produce better results with less function evaluations](https://github.com/libprima/prima#improvements)
17+
on average, making them preferable for [applications with expensive function evaluations](https://github.com/orgs/libprima/discussions/145).
18+
However, if function evaluations are not the dominant cost in your application, the Fortran 77
19+
implementation are likely to be faster, as it is more efficient in terms of memory usage and flops
20+
thanks to the careful and unique (but unmaintained) implementation by Powell.
21+
22+
As of April 2025, only the COBYLA solver is available in this Python translation, and SciPy 1.16.0
23+
integrates it to replace the original Fortran 77 implementation of [COBYLA underlying the
24+
`scipy.optimize.minimize` function](https://docs.scipy.org/doc/scipy/reference/optimize.minimize-cobyla.html).
25+
The other solvers will be translated from the Fortran reference implementation in the future.
26+
If you are interested in doing so, contact [Zaikun Zhang](https://www.zhangzk.net).
27+
28+
## Development notes
29+
130
To develop, `cd` into the `src` directory and run
231

332
```pip install --editable .```
433

534
This will install prima locally in an editable fashion. From there you can run the examples/cobyla/cobyla_example.py (from any directory) and go from there.
635

7-
## Style notes
36+
### Style notes
837

938
- Most of the comments are copied from Fortran verbatim, except in cases where they need to modified due to specifics of the Python language. In these cases a note will be made of the difference between Fortran and Python
1039
- Rationale:
@@ -13,7 +42,7 @@ This will install prima locally in an editable fashion. From there you can run t
1342
- Rationale:
1443
- Fortran uses `SIZE` so this helps us to be as consistent with the Fortran code as possible.
1544

16-
## A note on Fortran's `maxval`, `maximum`, and `maxval` and their Python equivalents
45+
### A note on Fortran's `maxval`, `maximum`, and `maxval` and their Python equivalents
1746

1847
| Fortran | Python | Return value |
1948
|-----------|--------------|--------------|
@@ -31,7 +60,7 @@ returns an elementwise maximum of the scalar and each element of the array.
3160
This note applies to `minval`, `minimum`, and `min` as well.
3261

3362

34-
## A note on indices
63+
### A note on indices
3564

3665
Consider the following Fortran code
3766

@@ -63,4 +92,4 @@ for i in range(1, 6):
6392
print(some_array[i-1])
6493
```
6594

66-
This leads to awkward Python code, since the more pythonic code would range from 0 to 5, and the indexing would be `some_array[i]`. In order to make the Python code more usable, we will attempt to write more "pythonic" code, even though that makes the translation a little bit more difficult.
95+
This leads to awkward Python code, since the more pythonic code would range from 0 to 5, and the indexing would be `some_array[i]`. In order to make the Python code more usable, we will attempt to write more "pythonic" code, even though that makes the translation a little bit more difficult.

0 commit comments

Comments
 (0)