Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/release_notes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ Upcoming Version

**Bug fixes**

* Probe the Xpress license via ``xpress.init()`` in ``Xpress._license_probe`` so unlicensed Xpress installations are accurately excluded from ``licensed_solvers`` and reported in ``check_solver_licenses``. (:issue:`994`, :pull:`1028`)
* ``Variable.get_solver_attribute`` for Gurobi now maps values by position for the direct API. It parsed labels from the solver's variable names, which returned the values of the wrong variables when names were off and a variable was masked. (`#978 <https://github.com/PyPSA/linopy/issues/978>`__)
* ``densify_terms`` no longer raises on expressions without coordinate dimensions (``expr.sum(drop_zeros=True)`` over all dimensions) and now works on ``QuadraticExpression``, where it previously indexed the ``_factor`` axis as the term axis.
* ``sum()`` over a dimension no longer raises when another dimension of the expression has size 0; it returns an expression without terms over the kept coordinates, as summing over the empty dimension itself already did. (https://github.com/PyPSA/linopy/issues/906)
Expand Down
5 changes: 5 additions & 0 deletions linopy/solvers.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@ def __getattr__(self, attr: str) -> Any:
coptpy = _LazyModule("coptpy")
cupdlpx = _LazyModule("cupdlpx")
cuopt = _LazyModule("cuopt")
xpress = _LazyModule("xpress")


def _has_module(name: str) -> bool:
Expand Down Expand Up @@ -2665,6 +2666,10 @@ class Xpress(Solver[None]):
def is_available(cls) -> bool:
return _has_module("xpress")

@classmethod
def _license_probe(cls) -> None:
xpress.init()

def _apply_var_bounds(
self, ctx: Any, indices: np.ndarray, lower: np.ndarray, upper: np.ndarray
) -> None:
Expand Down
20 changes: 20 additions & 0 deletions test/test_available_solvers.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,3 +238,23 @@ class _FakeMindoptpy:
cls._license_probe()

assert events == ["env_init", "env_dispose"]


def test_xpress_license_probe(
monkeypatch: pytest.MonkeyPatch,
) -> None:
cls = _solver_class_for("xpress")
assert cls is not None

events: list[str] = []

class _FakeXpress:
@staticmethod
def init() -> None:
events.append("init")

monkeypatch.setattr(solvers_mod, "xpress", _FakeXpress)

cls._license_probe()

assert events == ["init"]
Loading