Providing Python Bindings For Complex and Feature-Rich C and C++ Libraries
Description
Python is increasingly becoming the language of choice for a wide range of applications within the scientific community. For performance critical and high-performance computing (HPC) related tasks, however, it is still beneficial to develop critical code paths in a statically typed language like C or C++ and to then provide bindings to Python. In this talk, we present different options (e.g. ctypes, pybind11, cppyy) to provide these bindings, using both a simple demo library and SixTrackLib, an existing real-world high-performance C/C++ library as examples.
SixTrackLib in particular features multiple computing back-ends and a complex set of dependencies and configuration options which have to remain accessible to the users of the Python bindings. We compare the ease of use, support for modularity, and resulting performance across the different binding strategies. Moreover, we consider the interaction of the binding generation process with a build-system like CMake. We devote special attention to strategies and practices ensuring the consistent application of compiler options and sketch strategies for seamlessly performing library installations.