From a73dfe8c15ff93e9a0454aa23dcb4e1180c88cd8 Mon Sep 17 00:00:00 2001 From: a-andre <13609565+a-andre@users.noreply.github.com> Date: Mon, 19 Aug 2024 09:09:21 +0200 Subject: [PATCH] Update cibuildwheel to 2.20.0 to fix issue with CentOS mirrors being EOL (#202) * Update cibuildwheel to 2.20.0 to fix issue with CentOS mirrors being EOL * CyLP isn't compatible with numpy 2.0 * Replace old PyArray names * Add hypothesis dependency * Add missing includes for PyArray_DIM * Disable Python 3.13 for now. Apparently, CyLP is not compatible yet. * Try to fix failure on Linux by specifying language level * Skip pp38-manylinux --------- Co-authored-by: Ted Ralphs --- .github/workflows/cibuildwheel.yml | 2 +- cylp/cpp/ICbcModel.cpp | 2 +- cylp/cpp/IClpSimplex.cpp | 50 ++++++++++++++++-------------- cylp/cpp/ICoinIndexedVector.cpp | 7 +++-- cylp/cpp/ICoinMpsIO.cpp | 24 +++++++------- cylp/cpp/ICoinPackedMatrix.cpp | 8 ++--- pyproject.toml | 5 +-- setup.py | 5 ++- 8 files changed, 56 insertions(+), 47 deletions(-) diff --git a/.github/workflows/cibuildwheel.yml b/.github/workflows/cibuildwheel.yml index d0d2cee3..3b70e191 100644 --- a/.github/workflows/cibuildwheel.yml +++ b/.github/workflows/cibuildwheel.yml @@ -47,7 +47,7 @@ jobs: platforms: all - name: Build wheels - uses: pypa/cibuildwheel@v2.19.1 + uses: pypa/cibuildwheel@v2.20.0 - uses: actions/upload-artifact@v4 with: diff --git a/cylp/cpp/ICbcModel.cpp b/cylp/cpp/ICbcModel.cpp index a3bab13b..15998ec8 100644 --- a/cylp/cpp/ICbcModel.cpp +++ b/cylp/cpp/ICbcModel.cpp @@ -8,7 +8,7 @@ PyObject* ICbcModel::getPrimalVariableSolution(){ _import_array(); npy_intp dims = this->solver()->getNumCols(); double* d = (double*)(this->solver()->getColSolution()); - PyObject *Arr = PyArray_SimpleNewFromData( 1, &dims, PyArray_DOUBLE, d ); + PyObject *Arr = PyArray_SimpleNewFromData( 1, &dims, NPY_DOUBLE, d ); return Arr; } diff --git a/cylp/cpp/IClpSimplex.cpp b/cylp/cpp/IClpSimplex.cpp index 512ff300..c0733440 100644 --- a/cylp/cpp/IClpSimplex.cpp +++ b/cylp/cpp/IClpSimplex.cpp @@ -7,6 +7,8 @@ #include "IClpPackedMatrix.hpp" #include "OsiClpSolverInterface.hpp" #include +#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION +#include int IClpSimplex::argWeightedMax(PyObject* arr, PyObject* arr_ind, PyObject* w, PyObject* w_ind){ //_import_array(); @@ -345,7 +347,7 @@ bool IClpSimplex::varIsFixed(int ind){ PyObject* IClpSimplex::getStatusArray(){ npy_intp dims = getNumCols() + getNumRows(); - PyObject *Arr = PyArray_SimpleNewFromData( 1, &dims, PyArray_UINT8, this->status_ ); + PyObject *Arr = PyArray_SimpleNewFromData( 1, &dims, NPY_UINT8, this->status_ ); return Arr; } @@ -354,7 +356,7 @@ PyObject* IClpSimplex::getStatusArray(){ PyObject* IClpSimplex::getReducedCosts(){ npy_intp dims = getNumCols() + getNumRows(); - PyObject *Arr = PyArray_SimpleNewFromData( 1, &dims, PyArray_DOUBLE, this->djRegion() ); + PyObject *Arr = PyArray_SimpleNewFromData( 1, &dims, NPY_DOUBLE, this->djRegion() ); return Arr; } @@ -370,7 +372,7 @@ void IClpSimplex::setReducedCosts(double* rc){ PyObject* IClpSimplex::getComplementarityList(){ npy_intp dims = getNumCols() + getNumRows(); - PyObject *Arr = PyArray_SimpleNewFromData( 1, &dims, PyArray_INT32, QP_ComplementarityList ); + PyObject *Arr = PyArray_SimpleNewFromData( 1, &dims, NPY_INT32, QP_ComplementarityList ); return Arr; } @@ -378,7 +380,7 @@ PyObject* IClpSimplex::getComplementarityList(){ PyObject* IClpSimplex::getPivotVariable(){ npy_intp dims = getNumRows(); - PyObject *Arr = PyArray_SimpleNewFromData( 1, &dims, PyArray_INT32, this->pivotVariable() ); + PyObject *Arr = PyArray_SimpleNewFromData( 1, &dims, NPY_INT32, this->pivotVariable() ); return Arr; } @@ -387,7 +389,7 @@ PyObject* IClpSimplex::getPivotVariable(){ PyObject* IClpSimplex::getPrimalRowSolution(){ npy_intp dims = getNumRows(); - PyObject *Arr = PyArray_SimpleNewFromData( 1, &dims, PyArray_DOUBLE, this->primalRowSolution() ); + PyObject *Arr = PyArray_SimpleNewFromData( 1, &dims, NPY_DOUBLE, this->primalRowSolution() ); return Arr; } @@ -395,33 +397,33 @@ PyObject* IClpSimplex::getPrimalRowSolution(){ PyObject* IClpSimplex::getPrimalColumnSolution(){ npy_intp dims = getNumCols(); - PyObject *Arr = PyArray_SimpleNewFromData(1, &dims, PyArray_DOUBLE, this->primalColumnSolution() ); + PyObject *Arr = PyArray_SimpleNewFromData(1, &dims, NPY_DOUBLE, this->primalColumnSolution() ); return Arr; } PyObject* IClpSimplex::getPrimalColumnSolutionAll(){ npy_intp dims = getNumCols() + getNumRows(); - PyObject *Arr = PyArray_SimpleNewFromData(1, &dims, PyArray_DOUBLE, this->primalColumnSolution() ); + PyObject *Arr = PyArray_SimpleNewFromData(1, &dims, NPY_DOUBLE, this->primalColumnSolution() ); return Arr; } PyObject* IClpSimplex::getSolutionRegion(){ npy_intp dims = getNumCols() + getNumRows(); - PyObject *Arr = PyArray_SimpleNewFromData(1, &dims, PyArray_DOUBLE, this->solutionRegion() ); + PyObject *Arr = PyArray_SimpleNewFromData(1, &dims, NPY_DOUBLE, this->solutionRegion() ); return Arr; } PyObject* IClpSimplex::getCostRegion(){ npy_intp dims = getNumCols() + getNumRows(); - PyObject *Arr = PyArray_SimpleNewFromData(1, &dims, PyArray_DOUBLE, this->costRegion() ); + PyObject *Arr = PyArray_SimpleNewFromData(1, &dims, NPY_DOUBLE, this->costRegion() ); return Arr; } PyObject* IClpSimplex::getDualRowSolution(){ npy_intp dims = getNumRows(); - PyObject *Arr = PyArray_SimpleNewFromData( 1, &dims, PyArray_DOUBLE, this->dualRowSolution() ); + PyObject *Arr = PyArray_SimpleNewFromData( 1, &dims, NPY_DOUBLE, this->dualRowSolution() ); return Arr; } @@ -429,7 +431,7 @@ PyObject* IClpSimplex::getDualRowSolution(){ PyObject* IClpSimplex::getDualColumnSolution(){ npy_intp dims = getNumCols(); - PyObject *Arr = PyArray_SimpleNewFromData( 1, &dims, PyArray_DOUBLE, this->dualColumnSolution() ); + PyObject *Arr = PyArray_SimpleNewFromData( 1, &dims, NPY_DOUBLE, this->dualColumnSolution() ); return Arr; } @@ -437,63 +439,63 @@ PyObject* IClpSimplex::getDualColumnSolution(){ PyObject* IClpSimplex::getObjective(){ npy_intp dims = getNumCols(); - PyObject *Arr = PyArray_SimpleNewFromData( 1, &dims, PyArray_DOUBLE, this->objective() ); + PyObject *Arr = PyArray_SimpleNewFromData( 1, &dims, NPY_DOUBLE, this->objective() ); return Arr; } PyObject* IClpSimplex::getRowLower(){ npy_intp dims = getNumRows(); - PyObject *Arr = PyArray_SimpleNewFromData( 1, &dims, PyArray_DOUBLE, this->rowLower() ); + PyObject *Arr = PyArray_SimpleNewFromData( 1, &dims, NPY_DOUBLE, this->rowLower() ); return Arr; } PyObject* IClpSimplex::getRowUpper(){ npy_intp dims = getNumRows(); - PyObject *Arr = PyArray_SimpleNewFromData( 1, &dims, PyArray_DOUBLE, this->rowUpper() ); + PyObject *Arr = PyArray_SimpleNewFromData( 1, &dims, NPY_DOUBLE, this->rowUpper() ); return Arr; } PyObject* IClpSimplex::getUpper(){ npy_intp dims = getNumRows() + getNumCols(); - PyObject *Arr = PyArray_SimpleNewFromData( 1, &dims, PyArray_DOUBLE, this->upperRegion() ); + PyObject *Arr = PyArray_SimpleNewFromData( 1, &dims, NPY_DOUBLE, this->upperRegion() ); return Arr; } PyObject* IClpSimplex::getLower(){ npy_intp dims = getNumRows() + getNumCols(); - PyObject *Arr = PyArray_SimpleNewFromData( 1, &dims, PyArray_DOUBLE, this->lowerRegion() ); + PyObject *Arr = PyArray_SimpleNewFromData( 1, &dims, NPY_DOUBLE, this->lowerRegion() ); return Arr; } PyObject* IClpSimplex::getColLower(){ npy_intp dims = getNumCols(); - PyObject *Arr = PyArray_SimpleNewFromData( 1, &dims, PyArray_DOUBLE, this->columnLower() ); + PyObject *Arr = PyArray_SimpleNewFromData( 1, &dims, NPY_DOUBLE, this->columnLower() ); return Arr; } PyObject* IClpSimplex::getColUpper(){ npy_intp dims = getNumCols(); - PyObject *Arr = PyArray_SimpleNewFromData( 1, &dims, PyArray_DOUBLE, this->columnUpper() ); + PyObject *Arr = PyArray_SimpleNewFromData( 1, &dims, NPY_DOUBLE, this->columnUpper() ); return Arr; } PyObject* IClpSimplex::getColumnScale(){ npy_intp dims = getNumCols(); - PyObject *Arr = PyArray_SimpleNewFromData( 1, &dims, PyArray_DOUBLE, columnScale_); + PyObject *Arr = PyArray_SimpleNewFromData( 1, &dims, NPY_DOUBLE, columnScale_); return Arr; } PyObject* IClpSimplex::getRowScale(){ npy_intp dims = getNumRows(); - PyObject *Arr = PyArray_SimpleNewFromData( 1, &dims, PyArray_DOUBLE, rowScale_ ); + PyObject *Arr = PyArray_SimpleNewFromData( 1, &dims, NPY_DOUBLE, rowScale_ ); return Arr; } @@ -503,9 +505,9 @@ PyObject* IClpSimplex::getIntegerInformation(){ npy_intp dims = getNumCols(); PyObject* Arr; if (this->integerInformation()) - Arr = PyArray_SimpleNewFromData(1, &dims, PyArray_INT8, this->integerInformation()); + Arr = PyArray_SimpleNewFromData(1, &dims, NPY_INT8, this->integerInformation()); else - Arr = PyArray_ZEROS(1, &dims, PyArray_INT8, 0); + Arr = PyArray_ZEROS(1, &dims, NPY_INT8, 0); return Arr; } @@ -1391,7 +1393,7 @@ PyObject* IClpSimplex::filterVars(PyObject* inds){ npy_intp inds_len = PyArray_DIM(inds, 0); if (inds_len == 0){ npy_intp dims = 0; - PyObject *Arr = PyArray_SimpleNewFromData( 1, &dims, PyArray_INT, tempIntArray ); + PyObject *Arr = PyArray_SimpleNewFromData( 1, &dims, NPY_INT, tempIntArray ); return Arr; } if (tempArrayExists == false) @@ -1417,7 +1419,7 @@ PyObject* IClpSimplex::filterVars(PyObject* inds){ } npy_intp dims = ind_count; - PyObject *Arr = PyArray_SimpleNewFromData( 1, &dims, PyArray_INT, tempIntArray ); + PyObject *Arr = PyArray_SimpleNewFromData( 1, &dims, NPY_INT, tempIntArray ); return Arr; } diff --git a/cylp/cpp/ICoinIndexedVector.cpp b/cylp/cpp/ICoinIndexedVector.cpp index 2b2c35f7..34540b9c 100644 --- a/cylp/cpp/ICoinIndexedVector.cpp +++ b/cylp/cpp/ICoinIndexedVector.cpp @@ -1,5 +1,8 @@ #include "ICoinIndexedVector.hpp" +#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION +#include + ICoinIndexedVector::ICoinIndexedVector(){ _import_array(); } @@ -9,7 +12,7 @@ PyObject* ICoinIndexedVector::getIndicesNPArray(){ npy_intp dims = this->getNumElements(); PyObject *Arr = PyArray_SimpleNewFromData(1, &dims, - PyArray_INT32, + NPY_INT32, this->getIndices()); return Arr; } @@ -18,7 +21,7 @@ PyObject* ICoinIndexedVector::getDenseVectorNPArray(){ npy_intp dims = this->capacity(); PyObject *Arr = PyArray_SimpleNewFromData(1, &dims, - PyArray_DOUBLE, + NPY_DOUBLE, this->denseVector()); return Arr; } diff --git a/cylp/cpp/ICoinMpsIO.cpp b/cylp/cpp/ICoinMpsIO.cpp index 2fdf8ce9..f74f75c8 100644 --- a/cylp/cpp/ICoinMpsIO.cpp +++ b/cylp/cpp/ICoinMpsIO.cpp @@ -88,7 +88,7 @@ double * ICoinMpsIO::IObjCoefficients() const PyObject* ICoinMpsIO::np_getColLower(){ npy_intp dims = this->getNumCols(); _import_array(); - PyObject *Arr = PyArray_SimpleNewFromData( 1, &dims, PyArray_DOUBLE, this->IColLower() ); + PyObject *Arr = PyArray_SimpleNewFromData( 1, &dims, NPY_DOUBLE, this->IColLower() ); return Arr; } @@ -96,14 +96,14 @@ PyObject* ICoinMpsIO::np_getColLower(){ PyObject* ICoinMpsIO::np_getColUpper(){ npy_intp dims = this->getNumCols(); _import_array(); - PyObject *Arr = PyArray_SimpleNewFromData( 1, &dims, PyArray_DOUBLE, this->IColUpper() ); + PyObject *Arr = PyArray_SimpleNewFromData( 1, &dims, NPY_DOUBLE, this->IColUpper() ); return Arr; } PyObject* ICoinMpsIO::np_getRowSense(){ npy_intp dims = this->getNumRows(); _import_array(); - PyObject *Arr = PyArray_SimpleNewFromData( 1, &dims, PyArray_INT8, this->IRowSense() ); + PyObject *Arr = PyArray_SimpleNewFromData( 1, &dims, NPY_INT8, this->IRowSense() ); return Arr; } @@ -111,42 +111,42 @@ PyObject* ICoinMpsIO::np_getRowSense(){ PyObject* ICoinMpsIO::np_getRightHandSide(){ npy_intp dims = this->getNumRows(); _import_array(); - PyObject *Arr = PyArray_SimpleNewFromData( 1, &dims, PyArray_DOUBLE, this->IRightHandSide() ); + PyObject *Arr = PyArray_SimpleNewFromData( 1, &dims, NPY_DOUBLE, this->IRightHandSide() ); return Arr; } PyObject* ICoinMpsIO::np_getRowRange(){ npy_intp dims = this->getNumRows(); _import_array(); - PyObject *Arr = PyArray_SimpleNewFromData( 1, &dims, PyArray_DOUBLE, this->IRowRange() ); + PyObject *Arr = PyArray_SimpleNewFromData( 1, &dims, NPY_DOUBLE, this->IRowRange() ); return Arr; } PyObject* ICoinMpsIO::np_getRowLower(){ npy_intp dims = this->getNumRows(); _import_array(); - PyObject *Arr = PyArray_SimpleNewFromData( 1, &dims, PyArray_DOUBLE, this->IRowLower() ); + PyObject *Arr = PyArray_SimpleNewFromData( 1, &dims, NPY_DOUBLE, this->IRowLower() ); return Arr; } PyObject* ICoinMpsIO::np_getRowUpper(){ npy_intp dims = this->getNumRows(); _import_array(); - PyObject *Arr = PyArray_SimpleNewFromData( 1, &dims, PyArray_DOUBLE, this->IRowUpper() ); + PyObject *Arr = PyArray_SimpleNewFromData( 1, &dims, NPY_DOUBLE, this->IRowUpper() ); return Arr; } PyObject* ICoinMpsIO::np_getObjCoefficients(){ npy_intp dims = this->getNumCols(); _import_array(); - PyObject *Arr = PyArray_SimpleNewFromData( 1, &dims, PyArray_DOUBLE, this->IObjCoefficients() ); + PyObject *Arr = PyArray_SimpleNewFromData( 1, &dims, NPY_DOUBLE, this->IObjCoefficients() ); return Arr; } PyObject* ICoinMpsIO::np_integerColumns(){ npy_intp dims = this->getNumCols(); _import_array(); - PyObject *Arr = PyArray_SimpleNewFromData( 1, &dims, PyArray_INT8, this->IintegerColumns() ); + PyObject *Arr = PyArray_SimpleNewFromData( 1, &dims, NPY_INT8, this->IintegerColumns() ); return Arr; } @@ -154,21 +154,21 @@ PyObject* ICoinMpsIO::np_integerColumns(){ PyObject* ICoinMpsIO::getQPColumnStarts(){ npy_intp dims = this->getNumCols() + 1; _import_array(); - PyObject *Arr = PyArray_SimpleNewFromData( 1, &dims, PyArray_INT32, d_colStart ); + PyObject *Arr = PyArray_SimpleNewFromData( 1, &dims, NPY_INT32, d_colStart ); return Arr; } PyObject* ICoinMpsIO::getQPColumns(){ npy_intp dims = d_colStart[this->getNumCols()]; _import_array(); - PyObject *Arr = PyArray_SimpleNewFromData( 1, &dims, PyArray_INT32, d_cols ); + PyObject *Arr = PyArray_SimpleNewFromData( 1, &dims, NPY_INT32, d_cols ); return Arr; } PyObject* ICoinMpsIO::getQPElements(){ npy_intp dims = d_colStart[this->getNumCols()]; _import_array(); - PyObject *Arr = PyArray_SimpleNewFromData( 1, &dims, PyArray_DOUBLE, d_elements ); + PyObject *Arr = PyArray_SimpleNewFromData( 1, &dims, NPY_DOUBLE, d_elements ); return Arr; } diff --git a/cylp/cpp/ICoinPackedMatrix.cpp b/cylp/cpp/ICoinPackedMatrix.cpp index a3926e98..1696dd30 100644 --- a/cylp/cpp/ICoinPackedMatrix.cpp +++ b/cylp/cpp/ICoinPackedMatrix.cpp @@ -4,7 +4,7 @@ PyObject* ICoinPackedMatrix::np_getIndices(){ npy_intp dims = this->getNumElements(); _import_array(); - PyObject *Arr = PyArray_SimpleNewFromData( 1, &dims, PyArray_INT32, this->IgetIndices() ); + PyObject *Arr = PyArray_SimpleNewFromData( 1, &dims, NPY_INT32, this->IgetIndices() ); return Arr; } @@ -12,7 +12,7 @@ PyObject* ICoinPackedMatrix::np_getElements(){ npy_intp dims = this->getNumElements(); _import_array(); - PyObject *Arr = PyArray_SimpleNewFromData( 1, &dims, PyArray_DOUBLE, this->IgetElements() ); + PyObject *Arr = PyArray_SimpleNewFromData( 1, &dims, NPY_DOUBLE, this->IgetElements() ); return Arr; } @@ -20,7 +20,7 @@ PyObject* ICoinPackedMatrix::np_getMajorIndices(){ npy_intp dims = this->getNumElements(); _import_array(); - PyObject *Arr = PyArray_SimpleNewFromData( 1, &dims, PyArray_INT32, this->getMajorIndices() ); + PyObject *Arr = PyArray_SimpleNewFromData( 1, &dims, NPY_INT32, this->getMajorIndices() ); return Arr; } @@ -28,7 +28,7 @@ PyObject* ICoinPackedMatrix::np_getMajorIndices(){ PyObject* ICoinPackedMatrix::np_getVectorStarts(){ npy_intp dims = this->getMajorDim() + 1; _import_array(); - PyObject *Arr = PyArray_SimpleNewFromData( 1, &dims, PyArray_INT32, this->IgetVectorStarts() ); + PyObject *Arr = PyArray_SimpleNewFromData( 1, &dims, NPY_INT32, this->IgetVectorStarts() ); return Arr; } diff --git a/pyproject.toml b/pyproject.toml index 69be3cb0..c509b1b2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -5,7 +5,8 @@ requires = [ # https://numpy.org/devdocs/user/depending_on_numpy.html#build-time-dependency # from https://github.com/scipy/oldest-supported-numpy/pull/78#issuecomment-1747936818: "oldest-supported-numpy; platform_python_implementation != 'PyPy'", - "numpy; platform_python_implementation=='PyPy'" + "numpy < 2.0.0; platform_python_implementation=='PyPy'", + 'hypothesis' ] build-backend = "setuptools.build_meta" @@ -25,4 +26,4 @@ before-all = """ ./coinbrew fetch Cbc@2.10.11 --no-third-party && eval ./coinbrew build Cbc --no-third-party --parallel-jobs 16 --prefix=$(pwd)/local --verbosity 4 $config_args || (cat build/Data/Sample/1.2.12/config.log; echo ignoring errors) """ environment = { PATH="$(pwd)/local/bin:$PATH", LD_LIBRARY_PATH="$(pwd)/local/lib:$LD_LIBRARY_PATH", PKG_CONFIG_PATH="$(pwd)/local/lib/pkgconfig:$PKG_CONFIG_PATH", CIBW_ARCHS="$CIBW_ARCHS" } -skip = ["pp*-macosx*", "*-musllinux*", "pp31*-*", "pp*-*i686", "pp39-manylinux*", "cp312-*i686"] +skip = ["pp*-macosx*", "*-musllinux*", "pp31*-*", "pp*-*i686", "pp38-manylinux*", "pp39-manylinux*", "cp312-*i686", "cp313-*"] diff --git a/setup.py b/setup.py index 6184cbd5..95248565 100644 --- a/setup.py +++ b/setup.py @@ -390,6 +390,9 @@ extra_compile_args=extra_compile_args, extra_link_args=extra_link_args), ] +# Add language level directive per https://stackoverflow.com/a/58116368 +for e in ext_modules: + e.cython_directives = {'language_level': "3"} #all are Python-3 s_README = open('README.rst').read() s_AUTHORS = open('AUTHORS').read() @@ -411,6 +414,6 @@ 'cylp.py.utils', 'cylp.py.mip','cylp.py.QP'], cmdclass={'build_ext': build_ext}, ext_modules=ext_modules, - install_requires=['numpy >= 1.5.0', 'scipy >= 0.10.0'], + install_requires=['numpy >= 1.5.0,<2.0.0', 'scipy >= 0.10.0', 'hypothesis'], zip_safe = False, package_data={"cylp": extra_files})