sci-sw-interop

Scientific Software Interoperability

Scientific software interoperability banner

Cross-language bindings, build systems, and packaging for computational science codes

Fortran-Python interoperability stack

Context

Production codes in computational chemistry, physics, and climate science are written in Fortran. Analysis, visualization, and workflow tooling is written in Python. Getting data across the boundary without losing performance or type safety is a problem scientific software has been working at for 30 years.

I maintain f2py within NumPy with commit rights, mentored on LFortran through Google Summer of Code 2022 and 2023, and wrote a survey of where the Fortran ecosystem stands today (Kedward et al. 2022). The work splits three ways: derived-type interoperability, build-system modernization, and language ecosystem health.

Derived types across the language boundary

Fortran derived types had no first-class representation in f2py. My work explored three strategies, each documented in a series of blog posts:

  1. Direct bind(c) shadowing: For C-compatible types, a C struct mirrors the Fortran type exactly. No copies, no indirection.
  2. Opaque pointer wrapping: For arbitrary types, the Fortran side exposes handles (c_ptr values) and accessor functions. Python stores these in PyCapsule objects.
  3. Python class generation: A full PyTypeObject for each derived type, with type-bound procedures becoming Python methods.

Documentation and build systems

I rewrote most of the f2py documentation, covering meson-based builds, compiler configuration, fypp preprocessing, distribution with meson-python, and the three derived type strategies described above.

Distributing compiled Fortran extensions through pip and conda-forge requires working build systems. I contributed to the meson-based build for NumPy and developed packaging patterns for mixed Fortran-C-Python projects (Goswami 2022).

Code

  • f2py (NumPy) – Maintainer (commit rights), GSoC mentor
  • wailord – Creator; quantum chemistry workflow automation

See also: project-specific writing under f2py and LFortran in Software.

Open directions

  • Extending f2py to handle Fortran 2018 features (parameterized derived types, coarrays) and generating bindings for other target languages beyond Python.
  • A universal “scientific function interface” that describes a computational routine’s inputs, outputs, and side effects in a language-neutral way.

References

Goswami, Rohit. 2022. “Wailord: Parsers and Reproducibility for Quantum Chemistry.” Proceedings of the 21st Python in Science Conference, July, 193–97. https://doi.org/10.25080/majora-212e5952-021.
Kedward, Laurence, Balint Aradi, Ondrej Certik, Milan Curcic, Sebastian Ehlert, Philipp Engel, Rohit Goswami, et al. 2022. “The State of Fortran.” Computing in Science & Engineering, April. https://doi.org/10.1109/MCSE.2022.3159862.

← All research threads