BlueBrain / nmodl

Code Generation Framework For NEURON MODeling Language
https://bluebrain.github.io/nmodl/
Apache License 2.0
57 stars 15 forks source link

Move from pybind11 to nanobind + raw C API #1539

Open JCGoran opened 3 weeks ago

JCGoran commented 3 weeks ago

From an internal discussion:

In NMODL we use pybind11 to achieve 2 things:

a) making a Python wrapper for (some of the) C++ API b) embedding the interpreter

For b) we actually just call our hand-made Python script for solving systems of equations using SymPy, and nothing else. Since in NEURON we are using nanobind for a), I think it would make sense to just port a) to nanobind, and use the Python C API directly for b) (since nanobind does not support embedding the interpreter). The benefits of this switch are two-fold:

  • once we integrate NMODL into NEURON, we don’t need to keep track of two libraries, but only one (nanobind is anyway smaller and more performant)
  • pybind11 does not support the Python limited C API (which has guaranteed ABI stability), which means that, until we remove pybind11, we need to build wheels for every single minor version of Python. On the other hand, nanobind supports the limited API since 3.12, so at least the Python wheels would be more or less future-proof (so we’d only need to build wheels on one Python version, i.e. the oldest one supported)