Skip to content

Add public Solver.from_file API for existing LP/MPS files - #996

Open
danielelerede-oet wants to merge 2 commits into
PyPSA:masterfrom
open-energy-transition:feat/solver-from-file
Open

danielelerede-oet wants to merge 2 commits into
PyPSA:masterfrom
open-energy-transition:feat/solver-from-file

Conversation

@danielelerede-oet

@danielelerede-oet danielelerede-oet commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

Related to open-energy-transition/solver-benchmark#604 (cc @eantonini).

Note

The following technical summary and validation report were generated with AI assistance.

Changes proposed in this Pull Request

Adds Solver.from_file(name, problem_fn, options=...) as a public, non-deprecated entry point for solving existing LP/MPS files without constructing a linopy Model.

The constructor validates the solver's file-reading capability and input path, copies solver options, and prepares the existing file-based solve path. The backend reads the input during solve().

This PR also:

  • Updates deprecation warnings to point file-based callers to the new API.
  • Adds API documentation, an example and a release note.
  • Tests LP/MPS inputs, string and Path arguments, input preservation, solver options and invalid inputs.
  • Compares results with the deprecated API, including variable and constraint names not generated by linopy.

Existing backend restrictions and result semantics remain unchanged. Without a linopy Model, label-indexed primal and dual arrays may be empty; this limitation is documented.

Validation

  • Automated tests with HiGHS: 24 passed.
  • Gurobi 13.0.3 smoke tests through Solver.from_file: LP and MPS passed, including objective, native variable values and input preservation.
  • Combined solver tests with --forked: 212 passed, 20 skipped, 4 failed. The remaining failures occur in existing tests that open a second Gurobi environment while the first remains active, which the single-use license rejects.
  • mypy linopy/solvers.py: passed.

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 applicable).
  • 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 the MIT license.

@codspeed

codspeed Bot commented Sep 30, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 181 untouched benchmarks
⏩ 181 skipped benchmarks1


Comparing open-energy-transition:feat/solver-from-file (df2e7f6) with master (1b2ea76)

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. ↩

@danielelerede-oet
danielelerede-oet marked this pull request as ready for review September 30, 2026 10:59

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