Scientific Software Interoperability
Cross-language bindings, build systems, and packaging for computational science codes
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:
- Direct
bind(c)shadowing: For C-compatible types, a C struct mirrors the Fortran type exactly. No copies, no indirection. - Opaque pointer wrapping: For arbitrary types, the Fortran side exposes
handles (
c_ptrvalues) and accessor functions. Python stores these inPyCapsuleobjects. - Python class generation: A full
PyTypeObjectfor 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
Related writing
- Bridging Fortran & Python series: derived types, ISO_C_BINDING, opaque pointers, OOP.
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.