Skip to content

Commit 56e5752

Browse files
committed
Handle SCIP on windows bug in solver_capabilities.py
1 parent 4ef32c1 commit 56e5752

File tree

3 files changed

+14
-11
lines changed

3 files changed

+14
-11
lines changed

dev-scripts/SOLVER_CAPABILITIES_PLAN.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -282,9 +282,6 @@ Replace:
282282
# Before (model.py:1199)
283283
if solver_name in NO_SOLUTION_FILE_SOLVERS:
284284

285-
# Before (model.py:1211)
286-
if solver_name not in quadratic_solvers:
287-
288285
# Before (model.py:1234)
289286
if solver_name in ["glpk", "cbc"]:
290287

@@ -296,11 +293,12 @@ With:
296293
```python
297294
# After
298295
if solver_supports(solver_name, SolverFeature.SOLUTION_FILE_NOT_NEEDED):
299-
if not solver_supports(solver_name, SolverFeature.QUADRATIC_OBJECTIVE):
300296
if not solver_supports(solver_name, SolverFeature.LP_FILE_NAMES):
301297
if solver_supports(solver_name, SolverFeature.IIS_COMPUTATION):
302298
```
303299

300+
**Note**: The quadratic solver check (`solver_name not in quadratic_solvers`) is NOT migrated to use `solver_supports()`. This is because tests may modify the `quadratic_solvers` list at runtime to exclude solvers with platform-specific bugs (e.g., SCIP on Windows). The list-based approach allows this runtime modification.
301+
304302
### Step 4: Update `variables.py`
305303

306304
Replace:
@@ -330,7 +328,7 @@ Note: `io.py` doesn't need changes - the check at line 508 (`"highs" not in avai
330328
|------|---------|
331329
| `linopy/solver_capabilities.py` | **NEW** - Core registry module (~150 lines) |
332330
| `linopy/solvers.py` | Import registry, generate compat lists (~10 lines changed) |
333-
| `linopy/model.py` | Replace 4 hardcoded checks |
331+
| `linopy/model.py` | Replace 3 hardcoded checks (quadratic check kept as-is) |
334332
| `linopy/variables.py` | Replace 1 hardcoded check |
335333
| `linopy/__init__.py` | Export `SolverFeature`, `solver_supports` (optional) |
336334

linopy/solver_capabilities.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
from __future__ import annotations
99

10+
import platform
1011
from dataclasses import dataclass
1112
from enum import Enum, auto
1213
from typing import TYPE_CHECKING
@@ -112,10 +113,17 @@ def supports(self, feature: SolverFeature) -> bool:
112113
display_name="SCIP",
113114
features=frozenset(
114115
{
116+
SolverFeature.LP_FILE_NAMES,
117+
SolverFeature.SOLUTION_FILE_NOT_NEEDED,
118+
}
119+
if platform.system() == "Windows"
120+
else {
115121
SolverFeature.QUADRATIC_OBJECTIVE,
116122
SolverFeature.LP_FILE_NAMES,
117123
SolverFeature.SOLUTION_FILE_NOT_NEEDED,
118124
}
125+
# SCIP has a bug with quadratic models on Windows, see:
126+
# https://github.com/PyPSA/linopy/actions/runs/7615240686/job/20739454099?pr=78
119127
),
120128
),
121129
"mosek": SolverInfo(

test/test_optimization.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
import itertools
1111
import logging
12-
import platform
1312
from typing import Any
1413

1514
import numpy as np
@@ -47,11 +46,9 @@
4746
params.append(("mosek", "lp", True))
4847

4948

50-
feasible_quadratic_solvers: list[str] = quadratic_solvers
51-
# There seems to be a bug in scipopt with quadratic models on windows, see
52-
# https://github.com/PyPSA/linopy/actions/runs/7615240686/job/20739454099?pr=78
53-
if platform.system() == "Windows" and "scip" in feasible_quadratic_solvers:
54-
feasible_quadratic_solvers.remove("scip")
49+
# Note: Platform-specific solver bugs (e.g., SCIP quadratic on Windows) are now
50+
# handled in linopy/solver_capabilities.py by adjusting the registry at import time.
51+
feasible_quadratic_solvers: list[str] = list(quadratic_solvers)
5552

5653

5754
def test_print_solvers(capsys: Any) -> None:

0 commit comments

Comments
 (0)