From 6abd8116921ffb9b54262986a49375a53a86758a Mon Sep 17 00:00:00 2001 From: Werner Van Geit Date: Mon, 29 Jul 2024 10:58:59 +0200 Subject: [PATCH 1/6] Patch pyarray --- Makefile | 9 ++-- pyproject.toml | 4 +- .../dakota-src.patch | 0 src_patches/numpy_pyarray.patch | 49 +++++++++++++++++++ .../replace_old_macros_numpy.sed | 0 5 files changed, 56 insertions(+), 6 deletions(-) rename dakota-src.patch => src_patches/dakota-src.patch (100%) create mode 100644 src_patches/numpy_pyarray.patch rename replace_old_macros_numpy.sed => src_patches/replace_old_macros_numpy.sed (100%) diff --git a/Makefile b/Makefile index fb73270..17d0de8 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ all: wheel: cache-clean clean - CIBW_BUILD=cp38*x86_64 cibuildwheel --platform linux + CIBW_BUILD=cp311*x86_64 cibuildwheel --platform linux install: pip install -v . @@ -15,11 +15,12 @@ cache-clean: get-dakota-src: rm -rf dakota - git clone -j4 --branch v6.19.0 --depth 1 https://github.com/snl-dakota/dakota.git + git clone -j4 --branch v6.20.0 --depth 1 https://github.com/snl-dakota/dakota.git cd dakota && \ git submodule update --init packages/external && \ git submodule update --init packages/pecos && \ git submodule update --init packages/surfpack && \ - git apply ../dakota-src.patch && \ + git apply ../src_patches/dakota-src.patch && \ + git apply --whitespace=nowarn ../src_patches/numpy_pyarray.patch && \ find . \( -name \*.cpp -o -name \*.hpp -o -name \*.c -o -name \*.h \) -exec \ - sed -i -f ../replace_old_macros_numpy.sed {} + ; + sed -i -f ../src_patches/replace_old_macros_numpy.sed {} + diff --git a/pyproject.toml b/pyproject.toml index 82bfe66..977a282 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ dynamic = ["version"] description = "Dakota wheel built by the IT'IS Foundation, Zurich, Switzerland" license = { file = "LICENSE.txt" } readme = {file = "README.md", content-type = "text/markdown"} -dependencies = ["numpy"] +dependencies = ["numpy<2.0.0"] requires-python = ">=3.8" [project.urls] @@ -13,7 +13,7 @@ repository = "https://github.com/ITISFoundation/itis-dakota.git" issues = "https://github.com/ITISFoundation/itis-dakota/issues" [build-system] -requires = ["py-build-cmake", "numpy", "versioneer[toml]", "h5py", "auditwheel", "flit", "flit-core"] +requires = ["py-build-cmake", "numpy<2.0.0", "versioneer[toml]", "h5py", "auditwheel", "flit", "flit-core"] build-backend = "py_build_cmake.build" [tool.versioneer] diff --git a/dakota-src.patch b/src_patches/dakota-src.patch similarity index 100% rename from dakota-src.patch rename to src_patches/dakota-src.patch diff --git a/src_patches/numpy_pyarray.patch b/src_patches/numpy_pyarray.patch new file mode 100644 index 0000000..8c917d5 --- /dev/null +++ b/src_patches/numpy_pyarray.patch @@ -0,0 +1,49 @@ +diff --git a/src/PythonInterface.cpp b/src/PythonInterface.cpp +index 075d769..e094d41 100644 +--- a/src/PythonInterface.cpp ++++ b/src/PythonInterface.cpp +@@ -475,7 +475,7 @@ python_convert(PyObject *pyv, RealVector& rv, const int& dim) + #ifdef DAKOTA_PYTHON_NUMPY + // could automatically detect return type instead of throwing error + if (userNumpyFlag) { +- if (!PyArray_Check(pyv) || PyArray_NDIM(pyv) != 1 || ++ if (!PyArray_Check(pyv) || PyArray_Converter(pyv, &pyv) || PyArray_NDIM(pyv) != 1 || + PyArray_DIM(pyv,0) != dim) { + Cerr << "Python numpy array not 1D of size " << dim << "." << std::endl; + return(false); +@@ -517,7 +517,7 @@ python_convert(PyObject *pyv, double *rv, const int& dim) + #ifdef DAKOTA_PYTHON_NUMPY + // could automatically detect return type instead of throwing error + if (userNumpyFlag) { +- if (!PyArray_Check(pyv) || PyArray_NDIM(pyv) != 1 || ++ if (!PyArray_Check(pyv) || PyArray_Converter(pyv, &pyv) || PyArray_NDIM(pyv) != 1 || + PyArray_DIM(pyv,0) != dim) { + Cerr << "Python numpy array not 1D of size " << dim << "." << std::endl; + return(false); +@@ -556,7 +556,7 @@ bool PythonInterface::python_convert(PyObject *pym, RealMatrix &rm) + { + #ifdef DAKOTA_PYTHON_NUMPY + if (userNumpyFlag) { +- if (!PyArray_Check(pym) || PyArray_NDIM(pym) != 2 || ++ if (!PyArray_Check(pym) || PyArray_Converter(pym, &pym) || PyArray_NDIM(pym) != 2 || + PyArray_DIM(pym,0) != numFns || PyArray_DIM(pym,1) != numDerivVars) { + Cerr << "Python numpy array not 2D of size " << numFns << "x" + << numDerivVars << "." << std::endl; +@@ -603,7 +603,7 @@ bool PythonInterface::python_convert(PyObject *pym, + // Hessian array convert) + #ifdef DAKOTA_PYTHON_NUMPY + if (userNumpyFlag) { +- if (!PyArray_Check(pym) || PyArray_NDIM(pym) != 2 || ++ if (!PyArray_Check(pym) || PyArray_Converter(pym, &pym) || PyArray_NDIM(pym) != 2 || + PyArray_DIM(pym,0) != numDerivVars || + PyArray_DIM(pym,1) != numDerivVars) { + Cerr << "Python numpy array not 2D of size " << numDerivVars << "x" +@@ -660,7 +660,7 @@ python_convert(PyObject *pyma, RealSymMatrixArray &rma) + if (userNumpyFlag) { + // cannot recurse in this case as we now have a symmetric matrix + // (clearer this way anyway) +- if (!PyArray_Check(pyma) || PyArray_NDIM(pyma) != 3 || ++ if (!PyArray_Check(pyma) || PyArray_Converter(pyma, &pyma) || PyArray_NDIM(pyma) != 3 || + PyArray_DIM(pyma,0) != numFns || PyArray_DIM(pyma,1) != numDerivVars || + PyArray_DIM(pyma,2) != numDerivVars ) { + Cerr << "Python numpy array not 3D of size " << numFns << "x" diff --git a/replace_old_macros_numpy.sed b/src_patches/replace_old_macros_numpy.sed similarity index 100% rename from replace_old_macros_numpy.sed rename to src_patches/replace_old_macros_numpy.sed From e72073d40c3e095133642dee4a6bc36559afaa5d Mon Sep 17 00:00:00 2001 From: Werner Van Geit Date: Mon, 29 Jul 2024 11:00:36 +0200 Subject: [PATCH 2/6] Remove numpy downgrade --- pyproject.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 977a282..82bfe66 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ dynamic = ["version"] description = "Dakota wheel built by the IT'IS Foundation, Zurich, Switzerland" license = { file = "LICENSE.txt" } readme = {file = "README.md", content-type = "text/markdown"} -dependencies = ["numpy<2.0.0"] +dependencies = ["numpy"] requires-python = ">=3.8" [project.urls] @@ -13,7 +13,7 @@ repository = "https://github.com/ITISFoundation/itis-dakota.git" issues = "https://github.com/ITISFoundation/itis-dakota/issues" [build-system] -requires = ["py-build-cmake", "numpy<2.0.0", "versioneer[toml]", "h5py", "auditwheel", "flit", "flit-core"] +requires = ["py-build-cmake", "numpy", "versioneer[toml]", "h5py", "auditwheel", "flit", "flit-core"] build-backend = "py_build_cmake.build" [tool.versioneer] From 4379559aa794cedcfd3a1bfe2bd92187d837f6f2 Mon Sep 17 00:00:00 2001 From: Werner Van Geit Date: Mon, 29 Jul 2024 13:30:55 +0200 Subject: [PATCH 3/6] Use sed command to fix numpy --- Makefile | 3 +-- src_patches/replace_old_macros_numpy.sed | 1 + 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 17d0de8..f71a95d 100644 --- a/Makefile +++ b/Makefile @@ -21,6 +21,5 @@ get-dakota-src: git submodule update --init packages/pecos && \ git submodule update --init packages/surfpack && \ git apply ../src_patches/dakota-src.patch && \ - git apply --whitespace=nowarn ../src_patches/numpy_pyarray.patch && \ find . \( -name \*.cpp -o -name \*.hpp -o -name \*.c -o -name \*.h \) -exec \ - sed -i -f ../src_patches/replace_old_macros_numpy.sed {} + + sed -i -E -f ../src_patches/replace_old_macros_numpy.sed {} + diff --git a/src_patches/replace_old_macros_numpy.sed b/src_patches/replace_old_macros_numpy.sed index e1402a9..f8a4794 100644 --- a/src_patches/replace_old_macros_numpy.sed +++ b/src_patches/replace_old_macros_numpy.sed @@ -149,3 +149,4 @@ s/\bPyArray_MAX_ELSIZE\b/NPY_MAX_ELSIZE/g s/\bPyArray_USE_PYMEM\b/NPY_USE_PYMEM/g s/\bPyArray_RemoveLargest\b/PyArray_RemoveSmallest/g s/\bPyArray_UCS4\b/npy_ucs4/g +s/PyArray_(DIM|NDIM)\(([[:alpha:]]*)([^)]*)\)/PyArray_\1(reinterpret_cast(\2)\3)/g From a0dfd071102ddde66d706e28fea4bc6ad0fb5a27 Mon Sep 17 00:00:00 2001 From: Werner Van Geit Date: Mon, 29 Jul 2024 13:32:07 +0200 Subject: [PATCH 4/6] Remove numpy patch file --- src_patches/numpy_pyarray.patch | 49 --------------------------------- 1 file changed, 49 deletions(-) delete mode 100644 src_patches/numpy_pyarray.patch diff --git a/src_patches/numpy_pyarray.patch b/src_patches/numpy_pyarray.patch deleted file mode 100644 index 8c917d5..0000000 --- a/src_patches/numpy_pyarray.patch +++ /dev/null @@ -1,49 +0,0 @@ -diff --git a/src/PythonInterface.cpp b/src/PythonInterface.cpp -index 075d769..e094d41 100644 ---- a/src/PythonInterface.cpp -+++ b/src/PythonInterface.cpp -@@ -475,7 +475,7 @@ python_convert(PyObject *pyv, RealVector& rv, const int& dim) - #ifdef DAKOTA_PYTHON_NUMPY - // could automatically detect return type instead of throwing error - if (userNumpyFlag) { -- if (!PyArray_Check(pyv) || PyArray_NDIM(pyv) != 1 || -+ if (!PyArray_Check(pyv) || PyArray_Converter(pyv, &pyv) || PyArray_NDIM(pyv) != 1 || - PyArray_DIM(pyv,0) != dim) { - Cerr << "Python numpy array not 1D of size " << dim << "." << std::endl; - return(false); -@@ -517,7 +517,7 @@ python_convert(PyObject *pyv, double *rv, const int& dim) - #ifdef DAKOTA_PYTHON_NUMPY - // could automatically detect return type instead of throwing error - if (userNumpyFlag) { -- if (!PyArray_Check(pyv) || PyArray_NDIM(pyv) != 1 || -+ if (!PyArray_Check(pyv) || PyArray_Converter(pyv, &pyv) || PyArray_NDIM(pyv) != 1 || - PyArray_DIM(pyv,0) != dim) { - Cerr << "Python numpy array not 1D of size " << dim << "." << std::endl; - return(false); -@@ -556,7 +556,7 @@ bool PythonInterface::python_convert(PyObject *pym, RealMatrix &rm) - { - #ifdef DAKOTA_PYTHON_NUMPY - if (userNumpyFlag) { -- if (!PyArray_Check(pym) || PyArray_NDIM(pym) != 2 || -+ if (!PyArray_Check(pym) || PyArray_Converter(pym, &pym) || PyArray_NDIM(pym) != 2 || - PyArray_DIM(pym,0) != numFns || PyArray_DIM(pym,1) != numDerivVars) { - Cerr << "Python numpy array not 2D of size " << numFns << "x" - << numDerivVars << "." << std::endl; -@@ -603,7 +603,7 @@ bool PythonInterface::python_convert(PyObject *pym, - // Hessian array convert) - #ifdef DAKOTA_PYTHON_NUMPY - if (userNumpyFlag) { -- if (!PyArray_Check(pym) || PyArray_NDIM(pym) != 2 || -+ if (!PyArray_Check(pym) || PyArray_Converter(pym, &pym) || PyArray_NDIM(pym) != 2 || - PyArray_DIM(pym,0) != numDerivVars || - PyArray_DIM(pym,1) != numDerivVars) { - Cerr << "Python numpy array not 2D of size " << numDerivVars << "x" -@@ -660,7 +660,7 @@ python_convert(PyObject *pyma, RealSymMatrixArray &rma) - if (userNumpyFlag) { - // cannot recurse in this case as we now have a symmetric matrix - // (clearer this way anyway) -- if (!PyArray_Check(pyma) || PyArray_NDIM(pyma) != 3 || -+ if (!PyArray_Check(pyma) || PyArray_Converter(pyma, &pyma) || PyArray_NDIM(pyma) != 3 || - PyArray_DIM(pyma,0) != numFns || PyArray_DIM(pyma,1) != numDerivVars || - PyArray_DIM(pyma,2) != numDerivVars ) { - Cerr << "Python numpy array not 3D of size " << numFns << "x" From ca32d1926f752fc3c9aa0e639909e30b84b8f9f2 Mon Sep 17 00:00:00 2001 From: Werner Van Geit Date: Mon, 29 Jul 2024 13:35:11 +0200 Subject: [PATCH 5/6] Enable python 3.12 ci --- .github/workflows/build-wheels.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-wheels.yml b/.github/workflows/build-wheels.yml index 400b18b..4dfc19d 100644 --- a/.github/workflows/build-wheels.yml +++ b/.github/workflows/build-wheels.yml @@ -11,7 +11,7 @@ jobs: fail-fast: true matrix: os: [ubuntu-20.04] - python: [cp38,cp39,cp310,cp311] + python: [cp38,cp39,cp310,cp311,cp312] arch: [x86_64] env: SCCACHE_GHA_ENABLED: "true" From 54540b390098245e263a4d3a5da5953844ea8e37 Mon Sep 17 00:00:00 2001 From: Werner Van Geit Date: Mon, 29 Jul 2024 13:57:42 +0200 Subject: [PATCH 6/6] Upgrade some external github action versions --- .github/workflows/build-wheels.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build-wheels.yml b/.github/workflows/build-wheels.yml index 4dfc19d..7a20c1d 100644 --- a/.github/workflows/build-wheels.yml +++ b/.github/workflows/build-wheels.yml @@ -20,9 +20,9 @@ jobs: with: fetch-depth: 0 - name: Set up sccache - uses: mozilla-actions/sccache-action@v0.0.3 + uses: mozilla-actions/sccache-action@v0.0.5 - name: Set up Python - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: python-version: 3.9 - name: Get dakota src