Skip to content

fix(scip): skip dual values for MILPs and support PySCIPOpt < 5 - #1004

Open
eantonini wants to merge 1 commit into
PyPSA:masterfrom
eantonini:fix/scip-milp-duals
Open

eantonini wants to merge 1 commit into
PyPSA:masterfrom
eantonini:fix/scip-milp-duals

Conversation

@eantonini

Copy link
Copy Markdown

Changes proposed in this Pull Request

We run SCIP through linopy's file interface in the solver benchmark. Two problems came up there.

On MILPs, linopy still asks SCIP for dual values. MILPs don't have any, so SCIP fills the log with cannot get reduced costs errors, hundreds of them on some of our instances, and the duals linopy returns don't mean anything. We tracked this down in open-energy-transition/solver-benchmark#148.

Separately, our older benchmark years use SCIP 8, which only works with PySCIPOpt 4.x. There, every solve fails because getConss(False) doesn't exist yet.

This PR reads the original constraints and checks whether the problem is a MILP before solving, so it works with any PySCIPOpt version, and it skips the duals for MILPs as the other solvers do. LP duals are unchanged.

Note

The following content was generated by AI.

When solving a problem file, the SCIP interface (SCIP._run_file):

  • asked for dual values on every constraint, also for MILPs, which have none. With SCIP 9.2, SCIP printed errors such as cannot get reduced costs, because node LP is not processed (479 lines for the instance below), and the returned duals were meaningless;
  • read the original constraints after solving with getConss(False), which PySCIPOpt < 5 doesn't accept, so every solve raised TypeError: Model.getConss() takes no arguments (1 given).

This reads the original constraints and the problem type before solving, with getConss() and getNIntVars()/getNBinVars(), which every PySCIPOpt version has. It leaves the duals empty for MILPs, with the same warning as the other solvers. LP duals are unchanged.

Testing
  • New tests test_scip_lp_returns_duals and test_scipmaster, the MILP test fails (a dual of 0 instead ofnone), and with PySCIPOpt 4.3.0 both fail with the TypeError.
  • pytest test/test_solvers.py test/test_optimization.pCIP 8.0.3 + PySCIPOpt 4.3.0, SCIP 9.2.4 + PySCIPOpt5.7.1, and SCIP 10.0.0 + PySCIPOpt 6.0.0. ruffandmypy linopy/solvers.py` pass.
  • TulipaEnergyModel_1_EU_investment_simple_24h (a MILodeling-benchmarks) with SCIP 9.2.4: 479 SCIP errorlines on master, none with this change, same objective.
  • test/test_solvers.py is skipped entirely when MOSEKits module-level pytest.importorskip("mosek").

Context: open-energy-transition/solver-benchmark#148

Checklist

  • AI-generated content is marked (see [AGENTS.md]
  • Code changes are sufficiently documented; i.e. new functions contain docstrings and further explanations may be given in doc.
  • Unit tests for new features were added (if applic
  • A note for the release notes doc/release_notes.rst of the upcoming release is included.
  • I consent to the release of this PR's code under

When solving from a file, the SCIP interface asked for dual values of
every constraint, also for MILPs, which have none. SCIP printed errors
such as "cannot get reduced costs, because node LP is not processed" and
the returned duals were meaningless. They are now left empty for MILPs,
as with the other solvers.

The original constraints and the problem type are now read before
solving, with getConss() and getNIntVars()/getNBinVars(). Reading the
constraints afterwards needs getConss(transformed=False), which
PySCIPOpt < 5 doesn't have, so every solve raised a TypeError there.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codspeed

codspeed Bot commented Oct 5, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 181 untouched benchmarks
⏩ 181 skipped benchmarks1


Comparing eantonini:fix/scip-milp-duals (c7bcde1) with master (f665a26)

Open in CodSpeed

Footnotes

  1. 181 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant