From 685e26a12a4437f37c7d0e1205e7f7f2ee4ff966 Mon Sep 17 00:00:00 2001 From: Christian Diener Date: Fri, 26 May 2023 08:08:45 -0700 Subject: [PATCH] several fixes to support upstream changes (#253) * several fixes to support upstream changes * push CI changes as well * no cplex for 3.11 * add release notes * bump sympy * update RNs --- .github/workflows/main.yml | 2 +- CHANGELOG.rst | 14 ++++++++++++-- setup.cfg | 2 +- src/optlang/interface.py | 1 - src/optlang/scipy_interface.py | 4 ++-- src/optlang/symbolics.py | 15 +++------------ src/optlang/tests/test_io.py | 1 - tox.ini | 4 ++-- 8 files changed, 21 insertions(+), 22 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index aff2ca24..a8d9d907 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -20,7 +20,7 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest, macos-latest, windows-latest] - python-version: ["3.7", "3.8", "3.9", "3.10"] + python-version: ["3.8", "3.9", "3.10"] steps: - uses: actions/checkout@v2 diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 87998da9..e387d873 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,10 +1,20 @@ ======= Next Release ------------- -* remove deprecated numpy type casts +----- +1.7.0 +----- +* remove deprecated numpy type casts * The symbolics module now has consistent exports +* When sympy is used the internal Symbol class now derives from sympy.core.Dummy. This + circumvents the hack in place to make Symbols unique and makes optlang work with + sympy>=1.12 again. +* Updated the scipy and the jsonschema tests to work with newer versions of those packages. +* Package version dependencies are now more specific. +* Tests are run for sympy and symengine now. +* Updated support Python versions to >=3.8. + 1.6.1 ----- diff --git a/setup.cfg b/setup.cfg index 23bf0c4f..08c52540 100644 --- a/setup.cfg +++ b/setup.cfg @@ -36,7 +36,7 @@ zip_safe = True install_requires = six >=1.9 swiglpk >=5.0.8 - sympy >=1.0 + sympy >=1.12.0 python_requires = >=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.* tests_require = tox diff --git a/src/optlang/interface.py b/src/optlang/interface.py index 935becdf..5f2440dc 100644 --- a/src/optlang/interface.py +++ b/src/optlang/interface.py @@ -407,7 +407,6 @@ def _substitute_variables(cls, expression, model=None, **kwargs): variable_substitutions = dict() for variable in expression.variables: if model is not None and variable.name in model.variables: - # print(variable.name, id(variable.problem)) variable_substitutions[variable] = model.variables[variable.name] else: variable_substitutions[variable] = interface.Variable.clone(variable) diff --git a/src/optlang/scipy_interface.py b/src/optlang/scipy_interface.py index fa397746..35712602 100644 --- a/src/optlang/scipy_interface.py +++ b/src/optlang/scipy_interface.py @@ -243,7 +243,7 @@ def get_constraint_slack(self, name): index = self._get_constraint_index(name) return self._slacks[index] - def optimize(self, method="simplex", verbosity=False, tolerance=1e-9, **kwargs): + def optimize(self, method="highs", verbosity=False, tolerance=1e-9, **kwargs): """Run the linprog function on the problem. Returns None.""" c = np.array([self.objective.get(name, 0) for name in self._variables]) if self.direction == "max": @@ -251,7 +251,7 @@ def optimize(self, method="simplex", verbosity=False, tolerance=1e-9, **kwargs): bounds = list(six.itervalues(self.bounds)) solution = linprog(c, self.A, self.upper_bounds, bounds=bounds, method=method, - options={"maxiter": 10000, "disp": verbosity, "tol": tolerance}, **kwargs) + options={"maxiter": 10000, "disp": verbosity}, **kwargs) self._solution = solution self._status = solution.status if SCIPY_STATUS[self._status] == interface.OPTIMAL: diff --git a/src/optlang/symbolics.py b/src/optlang/symbolics.py index bd6a37fe..0b218527 100644 --- a/src/optlang/symbolics.py +++ b/src/optlang/symbolics.py @@ -101,8 +101,6 @@ def mul(*args): else: # Use sympy import sympy - from sympy.core.assumptions import _assume_rules - from sympy.core.facts import FactKB optlang._USING_SYMENGINE = False @@ -120,21 +118,14 @@ def mul(*args): Mul = sympy.Mul Pow = sympy.Pow - class Symbol(sympy.Symbol): + class Symbol(sympy.core.Dummy): """A generic symbol used in expressions.""" - def __new__(cls, name, **kwargs): + def __new__(cls, name, *args, **kwargs): if not isinstance(name, six.string_types): raise TypeError("name should be a string, not %s" % repr(type(name))) - obj = sympy.Symbol.__new__(cls, str(uuid.uuid1())) - - obj.name = name - obj._assumptions = FactKB(_assume_rules) - obj._assumptions._tell("commutative", True) - obj._assumptions._tell("uuid", uuid.uuid1()) - - return obj + return sympy.core.Dummy.__new__(cls, name) def __init__(self, *args, **kwargs): super(Symbol, self).__init__() diff --git a/src/optlang/tests/test_io.py b/src/optlang/tests/test_io.py index 44bb55f0..d50b35c8 100644 --- a/src/optlang/tests/test_io.py +++ b/src/optlang/tests/test_io.py @@ -17,7 +17,6 @@ } variable_schema = { - "$schema": "variable", "type": "object", "properties": { "name": { diff --git a/tox.ini b/tox.ini index 030fe309..fee43a4d 100644 --- a/tox.ini +++ b/tox.ini @@ -1,12 +1,12 @@ [tox] -envlist = isort, black, flake8, safety, docs, py3{7,8,9,10}-symengine +envlist = isort, black, flake8, safety, docs, py3{8,9,10}, py3{8,9,10}-symengine [gh-actions] python = - 3.7: safety, py37, py37-symengine 3.8: safety, py38, py38-symengine 3.9: safety, py39, py39-symengine 3.10: safety, py310, py310-symengine + 3.11: safety, py311, py311-symengine ;[testenv] ;deps =