From 8d5c7724d3390218aad2f8ad45b050fc034a87fa Mon Sep 17 00:00:00 2001 From: PhilipDeegan Date: Wed, 15 Oct 2025 13:18:08 +0200 Subject: [PATCH 1/2] pin pybind version and use smart_holder --- res/cmake/dep/pybind.cmake | 2 +- src/python3/cpp_etc.cpp | 5 ++--- src/python3/cpp_simulator.cpp | 10 ++++++---- src/python3/cpp_simulator.hpp | 17 ++++++++--------- 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/res/cmake/dep/pybind.cmake b/res/cmake/dep/pybind.cmake index b712eaf9a..39c5022ed 100644 --- a/res/cmake/dep/pybind.cmake +++ b/res/cmake/dep/pybind.cmake @@ -10,7 +10,7 @@ function(get_pybind) endif() if(NOT DEFINED PHARE_PYBIND11_VERSION) - SET(PHARE_PYBIND11_VERSION "master") + SET(PHARE_PYBIND11_VERSION "v3.0.1") # master broken since https://github.com/pybind/pybind11/pull/5866 endif() set(PYBIND11_SRCDIR ${CMAKE_CURRENT_SOURCE_DIR}/subprojects/pybind11) diff --git a/src/python3/cpp_etc.cpp b/src/python3/cpp_etc.cpp index 93c8fb22f..409acb097 100644 --- a/src/python3/cpp_etc.cpp +++ b/src/python3/cpp_etc.cpp @@ -41,9 +41,8 @@ PYBIND11_MODULE(cpp_etc, m) auto samrai_restart_file = [](std::string path) { return PHARE::amr::HierarchyRestarter::getRestartFileFullPath(path); }; - py::class_, std::shared_ptr>>(m, "Span"); - py::class_, std::shared_ptr>, core::Span>( - m, "PyWrapper"); + py::class_, py::smart_holder>(m, "Span"); + py::class_, py::smart_holder, core::Span>(m, "PyWrapper"); m.def("makePyArrayWrapper", makePyArrayWrapper); diff --git a/src/python3/cpp_simulator.cpp b/src/python3/cpp_simulator.cpp index a5c0a5d1c..cf20c4666 100644 --- a/src/python3/cpp_simulator.cpp +++ b/src/python3/cpp_simulator.cpp @@ -9,8 +9,13 @@ namespace py = pybind11; namespace PHARE::pydata { + PYBIND11_MODULE(PHARE_CPP_MOD_NAME, m) { + declarePatchData, 1>(m, "PatchDataVectorDouble_1D"); + declarePatchData, 2>(m, "PatchDataVectorDouble_2D"); + declarePatchData, 3>(m, "PatchDataVectorDouble_3D"); + declare_essential(m); declareDim<1>(m); @@ -18,9 +23,6 @@ PYBIND11_MODULE(PHARE_CPP_MOD_NAME, m) declareDim<3>(m); core::apply(core::possibleSimulators(), [&](auto const& simType) { declare_all(m, simType); }); - - declarePatchData, 1>(m, "PatchDataVectorDouble_1D"); - declarePatchData, 2>(m, "PatchDataVectorDouble_2D"); - declarePatchData, 3>(m, "PatchDataVectorDouble_3D"); } + } // namespace PHARE::pydata diff --git a/src/python3/cpp_simulator.hpp b/src/python3/cpp_simulator.hpp index 47a9e6166..6fd1b80d0 100644 --- a/src/python3/cpp_simulator.hpp +++ b/src/python3/cpp_simulator.hpp @@ -32,7 +32,7 @@ template void declarePatchData(py::module& m, std::string key) { using PatchDataType = PatchData; - py::class_(m, key.c_str()) + py::class_(m, key.c_str()) .def_readonly("patchID", &PatchDataType::patchID) .def_readonly("origin", &PatchDataType::origin) .def_readonly("lower", &PatchDataType::lower) @@ -46,7 +46,7 @@ void declareDim(py::module& m) { using CP = core::ContiguousParticles; std::string name = "ContiguousParticles_" + std::to_string(dim); - py::class_>(m, name.c_str()) + py::class_(m, name.c_str()) .def(py::init()) .def_readwrite("iCell", &CP::iCell) .def_readwrite("delta", &CP::delta) @@ -88,7 +88,7 @@ void declare_etc(py::module& m) using Sim = Simulator; using DW = DataWrangler; std::string name = "DataWrangler" + type_string; - py::class_>(m, name.c_str()) + py::class_(m, name.c_str()) .def(py::init const&, std::shared_ptr const&>()) .def(py::init const&, std::shared_ptr const&>()) .def("sync_merge", &DW::sync_merge) @@ -97,8 +97,7 @@ void declare_etc(py::module& m) using PL = PatchLevel; name = "PatchLevel_" + type_string; - - py::class_>(m, name.c_str()) + py::class_(m, name.c_str()) .def("getEM", &PL::getEM) .def("getE", &PL::getE) .def("getB", &PL::getB) @@ -123,7 +122,7 @@ void declare_etc(py::module& m) using _Splitter = PHARE::amr::Splitter<_dim, _interp, core::RefinedParticlesConst>; name = "Splitter" + type_string; - py::class_<_Splitter, std::shared_ptr<_Splitter>>(m, name.c_str()) + py::class_<_Splitter, py::smart_holder>(m, name.c_str()) .def(py::init<>()) .def_property_readonly_static("weight", [](py::object) { return _Splitter::weight; }) .def_property_readonly_static("delta", [](py::object) { return _Splitter::delta; }); @@ -146,7 +145,7 @@ void declare_sim(py::module& m) using Sim = Simulator; std::string name = "Simulator" + type_string; declareSimulator( - py::class_>(m, name.c_str()) + py::class_(m, name.c_str()) .def_property_readonly_static("dims", [](py::object) { return Sim::dimension; }) .def_property_readonly_static("interp_order", [](py::object) { return Sim::interp_order; }) @@ -182,11 +181,11 @@ void declare_all(py::module& m, std::tuple>(m, "SamraiLifeCycle") + py::class_(m, "SamraiLifeCycle") .def(py::init<>()) .def("reset", &SamraiLifeCycle::reset); - py::class_>(m, "AMRHierarchy"); + py::class_(m, "AMRHierarchy"); m.def("make_hierarchy", []() { return PHARE::amr::Hierarchy::make(); }); m.def("mpi_size", []() { return core::mpi::size(); }); From 0c7a120a3fc2e55aae400aeaab13b4fc4696d7cd Mon Sep 17 00:00:00 2001 From: PhilipDeegan Date: Wed, 15 Oct 2025 13:49:20 +0200 Subject: [PATCH 2/2] block non-constructible arguments due to catch-all Args... --- res/cmake/dep/pybind.cmake | 2 +- src/python3/patch_data.hpp | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/res/cmake/dep/pybind.cmake b/res/cmake/dep/pybind.cmake index 39c5022ed..b712eaf9a 100644 --- a/res/cmake/dep/pybind.cmake +++ b/res/cmake/dep/pybind.cmake @@ -10,7 +10,7 @@ function(get_pybind) endif() if(NOT DEFINED PHARE_PYBIND11_VERSION) - SET(PHARE_PYBIND11_VERSION "v3.0.1") # master broken since https://github.com/pybind/pybind11/pull/5866 + SET(PHARE_PYBIND11_VERSION "master") endif() set(PYBIND11_SRCDIR ${CMAKE_CURRENT_SOURCE_DIR}/subprojects/pybind11) diff --git a/src/python3/patch_data.hpp b/src/python3/patch_data.hpp index cb289c514..e87477e29 100644 --- a/src/python3/patch_data.hpp +++ b/src/python3/patch_data.hpp @@ -25,7 +25,8 @@ struct __attribute__((visibility("hidden"))) PatchData template PatchData(Args&&... args) - : data{std::forward(args...)} + requires std::is_constructible_v + : data{std::forward(args)...} { } };