Open adigitoleo opened 1 month ago
Relevant:
Maybe better than f2py:
f2py
)Lfortran is working on their own thing as well
Distributing any of this with the PyPI wheel is a non-goal, too many hoops to jump through. Only needs to work on Linux (gfortran, probably).
Starting work on the Fortran routines in add-fortran-routines
(branch). Aiming for Fortran 2003 compatibility which provides proper inf
values and real64
, among other things. gfortran -fsyntax-only
is a good way to lint, as well as fortls which I added to the dev dependencies.
To call the functions/subroutines from Python, fmodpy
looks the most appealing of the above options, but I have yet to test it properly (passing in numpy arrays, GC, parallel? or we only test serial performance?). f2py
probably only supports up to Fortran 95, and going through a C layer is the more modern approach. fmodpy
also doesn't require any special annotations in the Fortran source.
Maybe the best way to do it is using
numpy.f2py
to generate some Fortran extensions. This way, we can pass data from Python (much nicer for I/O and setup) and even run the Fortran stuff in CI as part of the test suite if desired. Manuele Faccenda has a refactored version of DRex with a more generic interface compared to the original. It seems like the newest Fortran DRex variant and is actively used, which makes it the best candidate for comparisons. I think I'll use that code as the basis for our Fortran extensions.It seems like the preferred way of writing Fortran extensions that gives the most control over the data transfer involves adding f2py directives in the Fortran source (just as writing C extensions actually involves writing "Cython").
We want drop-in replacements for the following PyDRex methods:
minerals.update_all
, which requiresminerals.update_orientations
, which requirescore.derivatives
We also might want the statistical methods:
minerals.voigt_averages
stats.resample_orientations
(was this ever included in the Fortran?)And it could be nice to have:
diagnostics.elasticity_components
(but check the new routine from Tape & Tape 2024 first)diagnostics.finite_strain