Skip to content

Commit

Permalink
several fixes to support upstream changes (#253)
Browse files Browse the repository at this point in the history
* several fixes to support upstream changes

* push CI changes as well

* no cplex for 3.11

* add release notes

* bump sympy

* update RNs
  • Loading branch information
cdiener authored May 26, 2023
1 parent c4208ae commit 685e26a
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 12 additions & 2 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -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
-----
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion src/optlang/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions src/optlang/scipy_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,15 +243,15 @@ 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":
c *= -1

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:
Expand Down
15 changes: 3 additions & 12 deletions src/optlang/symbolics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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__()
Expand Down
1 change: 0 additions & 1 deletion src/optlang/tests/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
}

variable_schema = {
"$schema": "variable",
"type": "object",
"properties": {
"name": {
Expand Down
4 changes: 2 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -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 =
Expand Down

0 comments on commit 685e26a

Please sign in to comment.