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..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 @@ -120,6 +121,18 @@ 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: + solver_options: dict[str, Any] = {"display/verblevel": 0} + status, condition = simple_model.solve("scip", **solver_options) + assert (status, condition) == ("ok", "optimal") + assert capfd.readouterr() == ("", "") + + @pytest.mark.skipif( "highs" not in set(solvers.licensed_solvers), reason="HiGHS is not installed" )