Wrapping Fortran libraries for Python with PRIK. Suggestions?

Hi everyone,

I’m the author of PRIK. I have recently wrapped two large Fortran projects with PRIK.

PRIMA (Zaikun Zhang’s modern Fortran implementation of Powell’s derivative-free solvers). All five solvers (COBYLA, UOBYQA, NEWUOA, BOBYQA, LINCOA) are generated directly from the Fortran sources.The tests check each solver against a known minimum and compare COBYLA with SciPy’s.
Guide: PRIMA Wrapper - PRIK — Bring Native Code to Python

Open MPI. PRIK generates a Python extension from Open MPI’s Fortran mpi_f08 sources. With an edited .pyi contract and a short Python module on top, an mpi4py-style program (send/recv, broadcast, reduce, allreduce) runs unchanged apart from its import and produces the same output. In our measurements, small Allreduce calls were on average about 16 % faster than mpi4py (28 % when calling the generated API directly). It covers one datatype for now.
Tutorial: Wrap Open MPI mpi_f08 - PRIK — Bring Native Code to Python

Besides the two I just described (PRIMA and Open MPI), PRIK already has maintained, numerically validated wrappers for:

Fortran: BLAS, LAPACK, FFTPACK, MINPACK, BSPLINE-FORTRAN, PRIMA, and Open MPI mpi_f08

C: libm and TA-Lib

Do you have any suggestions for other important Fortran libraries that would be worth wrapping for Python?

Documentation: PRIK — Bring Native Code to Python
GitHub: GitHub - PyNumLab/prik: Bring Native Code to Python with editable .pyi contracts · GitHub

2 Likes

I have used ChatGPT to translate 566 R packages to Fortran packages. Eventually I want to have Python, Octave/Matlab, and R interfaces for all the translations. You could try PRIK on them. I use Windows on which PRIK does not yet run.

2 Likes

Do you have a top 10 list of those packages? I’ll focus on those first, and then maybe, with the help of AI, we could try to wrap all of them.

ChatGPT says the 50 most popular of the translated packages, based on downloads of the originals, are as follows. You could start with them, although the first 3 are specific to R programming (part of the tidyverse), so providing Python interfaces to Fortran translations of them may not be useful.

Rank R package
1 dplyr
2 purrr
3 stringr
4 igraph
5 Matrix
6 lme4
7 survival
8 mgcv
9 MASS
10 abind
11 numDeriv
12 glmnet
13 cluster
14 boot
15 rpart
16 nnet
17 car
18 e1071
19 psych
20 forecast
21 Hmisc
22 mice
23 sandwich
24 multcomp
25 lavaan
26 ranger
27 lmtest
28 mclust
29 ape
30 quantreg
31 survey
32 fields
33 fitdistrplus
34 geepack
35 robustbase
36 deSolve
37 classInt
38 spdep
39 coda
40 tseries
41 FNN
42 dbscan
43 fastcluster
44 truncnorm
45 copula
46 urca
47 pracma
48 cubature
49 DEoptim
50 expm
1 Like

quadpack would be a great one, adaptive quadrature is something people reach for constantly and the fortran implementation is still the gold standard. odepack too, lsoda especially, having a solid stiff/non-stiff solver via python would get a lot of use. arpack for large sparse eigenvalue problems would round it out nicely.

1 Like