Skip to content

Commit b3a4bfd

Browse files
authored
fix (solvers): Add compatibility shim for xpress.Namespaces (#521)
* fix (solvers): Add compatibility shim for xpress.Namespaces xpress.Namespaces was added in version 9.6. * Update release_notes.rst * fix: explicitly ignore mypy's redef error
1 parent 12474e7 commit b3a4bfd

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

doc/release_notes.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ Release Notes
33

44
.. Upcoming Version
55
6+
* Fix compatibility for xpress versions below 9.6 (regression)
67

78
Version 0.5.8
89
--------------

linopy/solvers.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,17 @@
108108

109109
available_solvers.append("xpress")
110110

111+
# xpress.Namespaces was added in xpress 9.6
112+
try:
113+
from xpress import Namespaces as xpress_Namespaces
114+
except ImportError:
115+
116+
class xpress_Namespaces: # type: ignore[no-redef]
117+
ROW = 1
118+
COLUMN = 2
119+
SET = 3
120+
121+
111122
with contextlib.suppress(ModuleNotFoundError):
112123
import mosek
113124

@@ -1605,13 +1616,13 @@ def solve_problem_from_file(
16051616
def get_solver_solution() -> Solution:
16061617
objective = m.getObjVal()
16071618

1608-
var = m.getnamelist(xpress.Namespaces.COLUMN, 0, m.attributes.cols - 1)
1619+
var = m.getnamelist(xpress_Namespaces.COLUMN, 0, m.attributes.cols - 1)
16091620
sol = pd.Series(m.getSolution(), index=var, dtype=float)
16101621

16111622
try:
16121623
_dual = m.getDual()
16131624
constraints = m.getnamelist(
1614-
xpress.Namespaces.ROW, 0, m.attributes.rows - 1
1625+
xpress_Namespaces.ROW, 0, m.attributes.rows - 1
16151626
)
16161627
dual = pd.Series(_dual, index=constraints, dtype=float)
16171628
except (xpress.SolverError, xpress.ModelError, SystemError):

0 commit comments

Comments
 (0)