Migrate to nanobind, remove pybind11 - #595
Conversation
|
Cool! @BenWibking van you try to use nanobind's stub generator to replace our pybind11-stubgen? We need stubs for docs and ipython completion. |
| ${pyAMReX_SOURCE_DIR}/src/amrex/space${D}d/amrex_${D}d_pybind/__init__.pyi | ||
| PYTHON_PATH $<TARGET_FILE_DIR:pyAMReX_${D}d> | ||
| DEPENDS pyAMReX_${D}d | ||
| ) |
There was a problem hiding this comment.
@ax3l nanobind stubs are generated here using nanobind's CMake interface: https://nanobind.readthedocs.io/en/latest/typing.html#cmake-interface
|
Amazingly, all tests pass on all compilers. I'm marking it ready for review. |
|
|
||
|
|
||
| void init_TagBox (py::module& m) | ||
| void init_TagBox (nb::module_& m) |
| { | ||
| template<int dim> | ||
| void init_IntVectND(py::module &m) | ||
| void init_IntVectND(nb::module_ &m) |
|
|
||
|
|
||
| void init_RealBox(py::module &m) { | ||
| void init_RealBox(nb::module_ &m) { |
|
|
||
|
|
||
| void init_RealVect(py::module &m) { | ||
| void init_RealVect(nb::module_ &m) { |
|
|
||
|
|
||
| void init_PhysBCFunct(py::module& m) | ||
| void init_PhysBCFunct(nb::module_& m) |
| { | ||
| template<typename T> | ||
| void make_FabArray_T(py::module &m, std::string const &name) | ||
| void make_FabArray_T(nb::module_ &m, std::string const &name) |
There was a problem hiding this comment.
I don't understand this comment. @ax3l do you?
There was a problem hiding this comment.
Huh, I think that is a false positive.
| ArrayOfStructs<T_ParticleType, amrex::PinnedArenaAllocator> h_data; | ||
| h_data.resize(aos.size()); | ||
| //py::array_t<T_ParticleType> h_data(aos.size()); | ||
| //nb::array_t<T_ParticleType> h_data(aos.size()); |
ax3l
left a comment
There was a problem hiding this comment.
This looks pretty great!
I added a few inline thoughts to research.
I will push a commit to undo the .pyi changes and might isolate the setup.py binary distr update once I understand it to a separate PR.
| cmake_minimum_required(VERSION 3.24) | ||
| project(pyAMReXDownstreamNanobind LANGUAGES C CXX) | ||
|
|
||
| find_package(Python 3.8 COMPONENTS Interpreter Development.Module REQUIRED) |
There was a problem hiding this comment.
Oh, that's a neat downstream integration test.
There was a problem hiding this comment.
The AI came up with that after it broke on an earlier change. I think it's useful.
| PYTHON_PATH $<TARGET_FILE_DIR:pyAMReX_${D}d> | ||
| DEPENDS pyAMReX_${D}d | ||
| ) | ||
| add_dependencies(pyAMReX_stubs pyAMReX_${D}d_stub) |
There was a problem hiding this comment.
We might need to add a dependency pyAMReX_${D}d_stub -> pyAMReX_${D}d as well.
Maybe also env var helpers in case we do not want to rely on a pip_install (to check).
|
I was confused to whether the .pyi files should be checked in. What is the policy on that? Is it documented somewhere? |
|
Sorry for the confusion. Yes, the But, they are only checked in via an auto-commit on Thus, our PR's CIs do build them, check they are valid, but they do not commit them. yes, we should document this workflow / automation in the |
ah, okay :) That makes sense. |
|
Before we merge this in (maybe early in a release cycle), I would do a whole BLAST build test to see if mixing nanobind and pybind11 works well for the mid-term, then migrate the rest of BLAST too. (I expect no issues.) |
|
Ok, I can extract the build fixes to a separate PR. I have some uncommitted fixes to make things easier when using |
for more information, see https://pre-commit.ci
We do not want to modify the generated stub files on this branch. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Resolutions port the new features to nanobind: - dependencies.json: keep nanobind pins, take new AMReX commit - PlotFileUtil.cpp: port write_multi_level_plotfile to nb:: - ParticleHeader.cpp: port new bindings to nb:: (def_rw, nb::arg) - ParticleContainer.H, pyAMReX.cpp: nb:: for merged declarations Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
Build fixes moved to #599. |
This is a vibe-coded experiment to see if it is feasible to replace pybind11 with nanobind. Apparently, it is!
Benefits:
nb::ndarray<...>Generated using ~1 million tokens from GPT-5.6-Sol.