Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to nanobind #2820

Merged
merged 171 commits into from
Nov 3, 2023
Merged

Switch to nanobind #2820

merged 171 commits into from
Nov 3, 2023

Conversation

garth-wells
Copy link
Member

@garth-wells garth-wells commented Oct 18, 2023

This PR switches from pybind11 to nanobind for generating the Python wrappers. nanobind is smaller than pybind11, the wrappers build faster and it has significantly improved support for wrapping multi-dimensional arrays, which we use heavily.

The nanobind docs are easier to follow on the low-level details, which makes understanding the memory management in the wrapper layer easier.

PR depends on the nanobind development version, which includes fixes for complex-valued arrays. Fixed in nanobind 1.8.0.

@garth-wells
Copy link
Member Author

There is an issue with docstrings, and __name__ which is not being set correctly. See: wjakob/nanobind#349

This is affecting documentation.

Fixed in nanobind (wjakob/nanobind@3c2b64a).

@garth-wells garth-wells added this pull request to the merge queue Nov 3, 2023
Merged via the queue into main with commit 0edd19f Nov 3, 2023
20 checks passed
@garth-wells garth-wells deleted the nanobind branch November 3, 2023 14:51
@wjakob
Copy link

wjakob commented Nov 9, 2023

Now that this process has concluded, I was wondering if you have statistics to share? Do you observe changes in compilation time/binary size/runtime overheads for the python binding component?

@chrisrichardson
Copy link
Contributor

@wjakob - the binary size has decreased from 4052784 to 2157624 for the Python binding module, which is good. The compilation time also, subjectively feels faster - the LTO was always very slow for pybind.
I'm not sure we have timing statistics for the Python layer, as such - but we can perhaps have a look at it. We have recipes now for py-fenics-dolfinx@0.7.1 and py-fenics-dolfin@main in https://github.com/FEniCS/spack/tree/latest which makes it relatively easy to compare the two.

@wjakob
Copy link

wjakob commented Nov 10, 2023

That's pretty cool, thanks for sharing @chrisrichardson! Regarding runtime costs, I suppose that the main difference would apply to cases where you are solving small problems and bottlenecked by Python binding overheads.

@garth-wells
Copy link
Member Author

@wjakob very appealing is ndarray support in nanobind.

@chrisrichardson
Copy link
Contributor

I think we still have to think about the full potential of interoperation with other backends (not just numpy)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants