From 4da32d07879a5445c8297cb680a735fb8572cd47 Mon Sep 17 00:00:00 2001 From: Talley Lambert Date: Fri, 3 Nov 2023 21:15:59 -0400 Subject: [PATCH] build: update for cython 3 (#40) --- ilpy/impl/solvers/GurobiBackend.cpp | 4 ---- ilpy/impl/solvers/ScipBackend.cpp | 10 ++++------ ilpy/wrapper.pyx | 4 ++-- pyproject.toml | 2 +- setup.py | 10 +++++++++- 5 files changed, 16 insertions(+), 14 deletions(-) diff --git a/ilpy/impl/solvers/GurobiBackend.cpp b/ilpy/impl/solvers/GurobiBackend.cpp index e8f63c8..6c48b20 100644 --- a/ilpy/impl/solvers/GurobiBackend.cpp +++ b/ilpy/impl/solvers/GurobiBackend.cpp @@ -147,12 +147,8 @@ GurobiBackend::setConstraints(const Constraints& constraints) { } _numConstraints = constraints.size(); - unsigned int j = 0; for (const Constraint& constraint : constraints) { - addConstraint(constraint); - - j++; } GRB_CHECK(GRBupdatemodel(_model)); diff --git a/ilpy/impl/solvers/ScipBackend.cpp b/ilpy/impl/solvers/ScipBackend.cpp index bb336ec..82fafe6 100644 --- a/ilpy/impl/solvers/ScipBackend.cpp +++ b/ilpy/impl/solvers/ScipBackend.cpp @@ -3,6 +3,7 @@ #ifdef HAVE_SCIP #include +#include // for std::runtime_error #include #include @@ -131,12 +132,8 @@ ScipBackend::setConstraints(const Constraints& constraints) { // allocate memory for new constraints _constraints.reserve(constraints.size()); - unsigned int j = 0; for (const Constraint& constraint : constraints) { - addConstraint(constraint); - - j++; } } @@ -172,7 +169,7 @@ ScipBackend::addConstraint(const Constraint& constraint) { if (constraint.getRelation() == GreaterEqual) rhs = SCIPinfinity(_scip); - SCIP_CALL_ABORT(SCIPcreateConsBasicQuadratic( + SCIP_CALL_ABORT(SCIPcreateConsBasicQuadraticNonlinear( _scip, &c, name.c_str(), @@ -323,7 +320,8 @@ ScipBackend::scipVarType(VariableType type, double& lb, double& ub) { return SCIP_VARTYPE_CONTINUOUS; } - assert(false); + // Handle the unexpected value of 'type' + throw std::runtime_error("Unhandled VariableType passed to ScipBackend::scipVarType"); } #endif // HAVE_SCIP diff --git a/ilpy/wrapper.pyx b/ilpy/wrapper.pyx index 0b7fb31..e13d356 100644 --- a/ilpy/wrapper.pyx +++ b/ilpy/wrapper.pyx @@ -6,7 +6,7 @@ from libcpp.memory cimport shared_ptr from libcpp.map cimport map as cppmap from libcpp.string cimport string from cython.operator cimport dereference as deref -cimport decl +from . cimport decl from typing import Iterable, Mapping, Sequence if TYPE_CHECKING: @@ -47,7 +47,7 @@ cdef class Solution: def __cinit__(self, size): self.p = new decl.Solution(size) - self._status = "" + self._status = b"" def __dealloc__(self): del self.p diff --git a/pyproject.toml b/pyproject.toml index 357ce2c..a98fa66 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ # https://peps.python.org/pep-0517 [build-system] -requires = ["setuptools", "Cython<3"] +requires = ["setuptools", "Cython"] build-backend = "setuptools.build_meta" # https://peps.python.org/pep-0621/ diff --git a/setup.py b/setup.py index 9ca635d..306cdd3 100644 --- a/setup.py +++ b/setup.py @@ -44,4 +44,12 @@ define_macros=[("CYTHON_TRACE", CYTHON_TRACE)], ) -setup(ext_modules=cythonize([wrapper], compiler_directives={"linetrace": CYTHON_TRACE})) +setup( + ext_modules=cythonize( + [wrapper], + compiler_directives={ + "linetrace": CYTHON_TRACE, + "language_level": "3", + }, + ) +)