From 481d9bcc9a509faa0dd9760e500a93c3fd026503 Mon Sep 17 00:00:00 2001 From: Stefan Slavkovsky Date: Sat, 26 Sep 2026 16:11:10 +0200 Subject: [PATCH 1/2] fix(scip): respect verbosity when reading problem files > [!NOTE] > This commit message was generated by AI. Apply solver options before reading the problem file so display/verblevel=0 suppresses the initial model-loading output. Add a regression test and an upcoming release note. --- doc/release_notes.rst | 1 + linopy/solvers.py | 3 ++- test/test_solvers.py | 11 +++++++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/doc/release_notes.rst b/doc/release_notes.rst index 42e8bee4..8f49aada 100644 --- a/doc/release_notes.rst +++ b/doc/release_notes.rst @@ -76,6 +76,7 @@ Upcoming Version **Bug fixes** +* SCIP now applies solver options before reading the problem file, so ``model.solve("scip", **{"display/verblevel": 0})`` also suppresses the initial model-loading output. * ``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 `__) * ``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) diff --git a/linopy/solvers.py b/linopy/solvers.py index 6e1ec74d..e38f7f9f 100644 --- a/linopy/solvers.py +++ b/linopy/solvers.py @@ -2547,7 +2547,6 @@ def _run_file( sense = read_sense_from_problem_file(problem_fn) m = scip.Model() - m.readProblem(path_to_string(problem_fn)) if self.solver_options is not None: emphasis = self.solver_options.pop("setEmphasis", None) @@ -2564,6 +2563,8 @@ def _run_file( m.setParams(self.solver_options) + m.readProblem(path_to_string(problem_fn)) + if log_fn is not None: m.setLogfile(path_to_string(log_fn)) diff --git a/test/test_solvers.py b/test/test_solvers.py index 4a90b6a0..44910d83 100644 --- a/test/test_solvers.py +++ b/test/test_solvers.py @@ -120,6 +120,17 @@ def test_from_name_applies_solver_options(simple_model: Model) -> None: assert time_limit == 123 +@pytest.mark.skipif( + "scip" not in set(solvers.licensed_solvers), reason="SCIP is not installed" +) +def test_scip_quiet_model_solve( + simple_model: Model, capfd: pytest.CaptureFixture[str] +) -> None: + status, condition = simple_model.solve("scip", **{"display/verblevel": 0}) + assert (status, condition) == ("ok", "optimal") + assert capfd.readouterr() == ("", "") + + @pytest.mark.skipif( "highs" not in set(solvers.licensed_solvers), reason="HiGHS is not installed" ) From 46ccb1fca9ba97e3847d7e10f98772f38fc109f7 Mon Sep 17 00:00:00 2001 From: Stefan Slavkovsky Date: Sat, 26 Sep 2026 18:22:31 +0200 Subject: [PATCH 2/2] fix(tests): type SCIP solver options for mypy > [!NOTE] > This commit message was generated by AI. Annotate the solver options dictionary to match the heterogeneous keyword arguments accepted by Model.solve. --- test/test_solvers.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/test_solvers.py b/test/test_solvers.py index 44910d83..a05ee600 100644 --- a/test/test_solvers.py +++ b/test/test_solvers.py @@ -6,6 +6,7 @@ """ from pathlib import Path +from typing import Any from unittest.mock import MagicMock import numpy as np @@ -126,7 +127,8 @@ def test_from_name_applies_solver_options(simple_model: Model) -> None: def test_scip_quiet_model_solve( simple_model: Model, capfd: pytest.CaptureFixture[str] ) -> None: - status, condition = simple_model.solve("scip", **{"display/verblevel": 0}) + solver_options: dict[str, Any] = {"display/verblevel": 0} + status, condition = simple_model.solve("scip", **solver_options) assert (status, condition) == ("ok", "optimal") assert capfd.readouterr() == ("", "")