From 311fd681678645be26c84f78774f1de0d25c14b9 Mon Sep 17 00:00:00 2001 From: Alexander Sinn <64009254+AlexanderSinn@users.noreply.github.com> Date: Fri, 7 Nov 2025 10:23:20 +0100 Subject: [PATCH 01/10] Fix PODVector resize and reserve --- src/Base/PODVector.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/Base/PODVector.cpp b/src/Base/PODVector.cpp index 2e11d121..549da849 100644 --- a/src/Base/PODVector.cpp +++ b/src/Base/PODVector.cpp @@ -72,9 +72,12 @@ void make_PODVector(py::module &m, std::string typestr, std::string allocstr) // .def("max_size", &PODVector_type::max_size) .def("capacity", &PODVector_type::capacity) .def("empty", &PODVector_type::empty) - .def("resize", py::overload_cast(&PODVector_type::resize)) - .def("resize", py::overload_cast(&PODVector_type::resize)) - .def("reserve", &PODVector_type::reserve) + .def("resize", [](PODVector_type const & pv, std::size_t new_size){ + pv.resize(new_size); }) + .def("resize", [](PODVector_type const & pv, std::size_t new_size, const T& init_val){ + pv.resize(new_size, init_val); }) + .def("reserve", [](PODVector_type const & pv, std::size_t new_capacity){ + pv.reserve(new_capacity); }) .def("shrink_to_fit", &PODVector_type::shrink_to_fit) .def("to_host", [](PODVector_type const & pv) { PODVector> h_data(pv.size()); From 6f11a46df63a1fab4e7d3c29cd6f2e2295885a43 Mon Sep 17 00:00:00 2001 From: Alexander Sinn <64009254+AlexanderSinn@users.noreply.github.com> Date: Fri, 7 Nov 2025 10:27:56 +0100 Subject: [PATCH 02/10] remove const --- src/Base/PODVector.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Base/PODVector.cpp b/src/Base/PODVector.cpp index 549da849..8e2658c6 100644 --- a/src/Base/PODVector.cpp +++ b/src/Base/PODVector.cpp @@ -72,11 +72,11 @@ void make_PODVector(py::module &m, std::string typestr, std::string allocstr) // .def("max_size", &PODVector_type::max_size) .def("capacity", &PODVector_type::capacity) .def("empty", &PODVector_type::empty) - .def("resize", [](PODVector_type const & pv, std::size_t new_size){ + .def("resize", [](PODVector_type & pv, std::size_t new_size){ pv.resize(new_size); }) - .def("resize", [](PODVector_type const & pv, std::size_t new_size, const T& init_val){ + .def("resize", [](PODVector_type & pv, std::size_t new_size, const T& init_val){ pv.resize(new_size, init_val); }) - .def("reserve", [](PODVector_type const & pv, std::size_t new_capacity){ + .def("reserve", [](PODVector_type & pv, std::size_t new_capacity){ pv.reserve(new_capacity); }) .def("shrink_to_fit", &PODVector_type::shrink_to_fit) .def("to_host", [](PODVector_type const & pv) { From 0883df75c52bf8901c12dc0c5579b35482b0d1c3 Mon Sep 17 00:00:00 2001 From: Alexander Sinn <64009254+AlexanderSinn@users.noreply.github.com> Date: Fri, 7 Nov 2025 13:28:21 +0100 Subject: [PATCH 03/10] Update ParticleTile and SoA --- src/Particle/ParticleTile.H | 3 ++- src/Particle/StructOfArrays.H | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Particle/ParticleTile.H b/src/Particle/ParticleTile.H index 2b95193c..892f336d 100644 --- a/src/Particle/ParticleTile.H +++ b/src/Particle/ParticleTile.H @@ -101,7 +101,8 @@ void make_ParticleTile(py::module &m, std::string allocstr) .def("set_num_neighbors", &ParticleTileType::setNumNeighbors) .def("get_num_neighbors", &ParticleTileType::getNumNeighbors) - .def("resize", &ParticleTileType::resize) + .def("resize", [](ParticleTileType & pt, std::size_t new_size){ + pt.resize(new_size); }) ; if constexpr (!T_ParticleType::is_soa_particle) { diff --git a/src/Particle/StructOfArrays.H b/src/Particle/StructOfArrays.H index 36d05877..fe8472e2 100644 --- a/src/Particle/StructOfArrays.H +++ b/src/Particle/StructOfArrays.H @@ -84,7 +84,8 @@ void make_StructOfArrays(py::module &m, std::string allocstr) .def("set_num_neighbors", &SOAType::setNumNeighbors) .def("get_num_neighbors", &SOAType::getNumNeighbors) - .def("resize", &SOAType::resize) + .def("resize", [](SOAType & soa, std::size_t new_size){ + soa.resize(new_size); }) ; if (use64BitIdCpu) py_SoA.def("get_idcpu_data", py::overload_cast<>(&SOAType::GetIdCPUData), From 7ea0783bb88e8d4c0f91a3d6d0b54cb733fc0995 Mon Sep 17 00:00:00 2001 From: Axel Huebl Date: Fri, 7 Nov 2025 10:39:43 -0800 Subject: [PATCH 04/10] PODVector: New Overloads & Defaults --- src/Base/PODVector.cpp | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/src/Base/PODVector.cpp b/src/Base/PODVector.cpp index 8e2658c6..9aab31c5 100644 --- a/src/Base/PODVector.cpp +++ b/src/Base/PODVector.cpp @@ -72,12 +72,22 @@ void make_PODVector(py::module &m, std::string typestr, std::string allocstr) // .def("max_size", &PODVector_type::max_size) .def("capacity", &PODVector_type::capacity) .def("empty", &PODVector_type::empty) - .def("resize", [](PODVector_type & pv, std::size_t new_size){ - pv.resize(new_size); }) - .def("resize", [](PODVector_type & pv, std::size_t new_size, const T& init_val){ - pv.resize(new_size, init_val); }) - .def("reserve", [](PODVector_type & pv, std::size_t new_capacity){ - pv.reserve(new_capacity); }) + .def("resize", + py::overload_cast(&PODVector_type::resize), + py::arg("new_size"), + py::arg("strategy") = GrowthStrategy::Poisson + ) + .def("resize", + py::overload_cast(&PODVector_type::resize), + py::arg("new_size"), + py::arg("value"), + py::arg("strategy") = GrowthStrategy::Poisson + ) + .def("reserve", + &PODVector_type::reserve, + py::arg("capacity"), + py::arg("strategy") = GrowthStrategy::Poisson + ) .def("shrink_to_fit", &PODVector_type::shrink_to_fit) .def("to_host", [](PODVector_type const & pv) { PODVector> h_data(pv.size()); @@ -141,6 +151,12 @@ void make_PODVector(py::module &m, std::string typestr) } void init_PODVector(py::module& m) { + py::enum_(m, "GrowthStrategy") + .value("Poisson", GrowthStrategy::Poisson) + .value("Exact", GrowthStrategy::Exact) + .value("Geometric", GrowthStrategy::Geometric) + ; + make_PODVector (m, "real"); make_PODVector (m, "int"); make_PODVector (m, "uint64"); From 1121fb128bf36d08ae3bd30bb89c071a47207902 Mon Sep 17 00:00:00 2001 From: Axel Huebl Date: Fri, 7 Nov 2025 10:40:24 -0800 Subject: [PATCH 05/10] AMReX: `development` --- dependencies.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dependencies.json b/dependencies.json index 0dadbcab..516099de 100644 --- a/dependencies.json +++ b/dependencies.json @@ -2,6 +2,6 @@ "version_pyamrex": "25.11", "version_amrex": "25.11", "version_pybind11": "v3.0.1", - "commit_amrex": "25.11", + "commit_amrex": "4dad1664d7467ae00c133c1425c1a300003fa885", "commit_pybind11": "v3.0.1" } From 0cd5e54323d021b4c055b344d3aecb2d283b0255 Mon Sep 17 00:00:00 2001 From: Axel Huebl Date: Fri, 7 Nov 2025 10:56:15 -0800 Subject: [PATCH 06/10] Fix ParmParse: Enum pybind11 cannot use `overload_cast` anymore if one of the overloads has an enable_if template and the others are not templated. Express as lambdas. --- src/Base/ParmParse.cpp | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/Base/ParmParse.cpp b/src/Base/ParmParse.cpp index 97002785..6ffa7d19 100644 --- a/src/Base/ParmParse.cpp +++ b/src/Base/ParmParse.cpp @@ -35,16 +35,15 @@ void init_ParmParse(py::module &m) .def_static("addfile", &ParmParse::addfile) - .def("add", py::overload_cast(&ParmParse::add)) - .def("add", py::overload_cast(&ParmParse::add)) - .def("add", py::overload_cast(&ParmParse::add)) - .def("add", py::overload_cast(&ParmParse::add)) - .def("add", py::overload_cast(&ParmParse::add)) - .def("add", py::overload_cast(&ParmParse::add)) - .def("add", py::overload_cast(&ParmParse::add)) - .def("add", py::overload_cast(&ParmParse::add)) - .def("add", py::overload_cast(&ParmParse::add)) - + .def("add", [](ParmParse &pp, std::string_view name, bool val) { pp.add(name, val); }) + .def("add", [](ParmParse &pp, std::string_view name, int val) { pp.add(name, val); }) + .def("add", [](ParmParse &pp, std::string_view name, long val) { pp.add(name, val); }) + .def("add", [](ParmParse &pp, std::string_view name, long long val) { pp.add(name, val); }) + .def("add", [](ParmParse &pp, std::string_view name, float val) { pp.add(name, val); }) + .def("add", [](ParmParse &pp, std::string_view name, double val) { pp.add(name, val); }) + .def("add", [](ParmParse &pp, std::string_view name, std::string const &val) { pp.add(name, val); }) + .def("add", [](ParmParse &pp, std::string_view name, amrex::IntVect const &val) { pp.add(name, val); }) + .def("add", [](ParmParse &pp, std::string_view name, amrex::Box const &val) { pp.add(name, val); }) .def("addarr", py::overload_cast const &>(&ParmParse::addarr)) .def("addarr", py::overload_cast const &>(&ParmParse::addarr)) .def("addarr", py::overload_cast const &>(&ParmParse::addarr)) From 37cbe14c8c158f58fd7618dcf0ab032b071d936c Mon Sep 17 00:00:00 2001 From: Axel Huebl Date: Fri, 7 Nov 2025 11:01:20 -0800 Subject: [PATCH 07/10] Two More Resizes --- src/Particle/ParticleTile.H | 7 +++++-- src/Particle/StructOfArrays.H | 7 +++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/Particle/ParticleTile.H b/src/Particle/ParticleTile.H index 892f336d..880ae5cf 100644 --- a/src/Particle/ParticleTile.H +++ b/src/Particle/ParticleTile.H @@ -101,8 +101,11 @@ void make_ParticleTile(py::module &m, std::string allocstr) .def("set_num_neighbors", &ParticleTileType::setNumNeighbors) .def("get_num_neighbors", &ParticleTileType::getNumNeighbors) - .def("resize", [](ParticleTileType & pt, std::size_t new_size){ - pt.resize(new_size); }) + .def("resize", + &ParticleTileType::resize, + py::arg("count"), + py::arg("strategy") = GrowthStrategy::Poisson + ) ; if constexpr (!T_ParticleType::is_soa_particle) { diff --git a/src/Particle/StructOfArrays.H b/src/Particle/StructOfArrays.H index fe8472e2..4d08681e 100644 --- a/src/Particle/StructOfArrays.H +++ b/src/Particle/StructOfArrays.H @@ -84,8 +84,11 @@ void make_StructOfArrays(py::module &m, std::string allocstr) .def("set_num_neighbors", &SOAType::setNumNeighbors) .def("get_num_neighbors", &SOAType::getNumNeighbors) - .def("resize", [](SOAType & soa, std::size_t new_size){ - soa.resize(new_size); }) + .def("resize", + &SOAType::resize, + py::arg("new_size"), + py::arg("strategy") = GrowthStrategy::Poisson + ) ; if (use64BitIdCpu) py_SoA.def("get_idcpu_data", py::overload_cast<>(&SOAType::GetIdCPUData), From df29f7a9d46a6231691b7cbebd9e046880b77c65 Mon Sep 17 00:00:00 2001 From: Axel Huebl Date: Fri, 7 Nov 2025 14:05:35 -0800 Subject: [PATCH 08/10] Native_Enum pybind11-stubgen needs location hint for default arguments that are enums, even if defined early enough. --- .github/update_stub.sh | 6 +++--- src/Base/PODVector.cpp | 7 +++++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/.github/update_stub.sh b/.github/update_stub.sh index a06f3505..d660c125 100755 --- a/.github/update_stub.sh +++ b/.github/update_stub.sh @@ -13,6 +13,6 @@ set -eu -o pipefail # we are in the source directory, .github/ this_dir=$(cd $(dirname $0) && pwd) -pybind11-stubgen --exit-code -o ${this_dir}/../src/ amrex.space1d -pybind11-stubgen --exit-code -o ${this_dir}/../src/ amrex.space2d -pybind11-stubgen --exit-code -o ${this_dir}/../src/ amrex.space3d +pybind11-stubgen --exit-code --enum-class-locations="GrowthStrategy:amrex.space3d" -o ${this_dir}/../src/ amrex.space1d +pybind11-stubgen --exit-code --enum-class-locations="GrowthStrategy:amrex.space3d" -o ${this_dir}/../src/ amrex.space2d +pybind11-stubgen --exit-code --enum-class-locations="GrowthStrategy:amrex.space3d" -o ${this_dir}/../src/ amrex.space3d diff --git a/src/Base/PODVector.cpp b/src/Base/PODVector.cpp index 9aab31c5..ffa75df1 100644 --- a/src/Base/PODVector.cpp +++ b/src/Base/PODVector.cpp @@ -150,11 +150,14 @@ void make_PODVector(py::module &m, std::string typestr) #endif } -void init_PODVector(py::module& m) { - py::enum_(m, "GrowthStrategy") +void init_PODVector(py::module& m) +{ + py::native_enum(m, "GrowthStrategy", "enum.IntEnum") .value("Poisson", GrowthStrategy::Poisson) .value("Exact", GrowthStrategy::Exact) .value("Geometric", GrowthStrategy::Geometric) + .export_values() + .finalize() ; make_PODVector (m, "real"); From 2345e18db2760183113cb79c25d307f161d16c7e Mon Sep 17 00:00:00 2001 From: Axel Huebl Date: Fri, 7 Nov 2025 14:14:26 -0800 Subject: [PATCH 09/10] `enum.Enum` --- src/Base/PODVector.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Base/PODVector.cpp b/src/Base/PODVector.cpp index ffa75df1..5c6a4fa0 100644 --- a/src/Base/PODVector.cpp +++ b/src/Base/PODVector.cpp @@ -152,7 +152,7 @@ void make_PODVector(py::module &m, std::string typestr) void init_PODVector(py::module& m) { - py::native_enum(m, "GrowthStrategy", "enum.IntEnum") + py::native_enum(m, "GrowthStrategy", "enum.Enum") .value("Poisson", GrowthStrategy::Poisson) .value("Exact", GrowthStrategy::Exact) .value("Geometric", GrowthStrategy::Geometric) From e9f1a52ce612f7bcdf5a040f9b55e53cdaa7fd65 Mon Sep 17 00:00:00 2001 From: Axel Huebl Date: Fri, 7 Nov 2025 14:16:08 -0800 Subject: [PATCH 10/10] Stubs: 1d/2d/3d --- .github/update_stub.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/update_stub.sh b/.github/update_stub.sh index d660c125..5e6875ff 100755 --- a/.github/update_stub.sh +++ b/.github/update_stub.sh @@ -13,6 +13,6 @@ set -eu -o pipefail # we are in the source directory, .github/ this_dir=$(cd $(dirname $0) && pwd) -pybind11-stubgen --exit-code --enum-class-locations="GrowthStrategy:amrex.space3d" -o ${this_dir}/../src/ amrex.space1d -pybind11-stubgen --exit-code --enum-class-locations="GrowthStrategy:amrex.space3d" -o ${this_dir}/../src/ amrex.space2d +pybind11-stubgen --exit-code --enum-class-locations="GrowthStrategy:amrex.space1d" -o ${this_dir}/../src/ amrex.space1d +pybind11-stubgen --exit-code --enum-class-locations="GrowthStrategy:amrex.space2d" -o ${this_dir}/../src/ amrex.space2d pybind11-stubgen --exit-code --enum-class-locations="GrowthStrategy:amrex.space3d" -o ${this_dir}/../src/ amrex.space3d