Skip to content

fix(io): raise when writing indicator constraints to MPS - #1187

Draft
FabianHofmann wants to merge 1 commit into
masterfrom
claude/exciting-turing-b608cv
Draft

FabianHofmann wants to merge 1 commit into
masterfrom
claude/exciting-turing-b608cv

Conversation

@FabianHofmann

Copy link
Copy Markdown
Collaborator

Closes #1186.

Changes proposed in this Pull Request

Note

The following content was generated by AI.

linopy writes MPS through HiGHS, which has no indicator constraints. They were dropped silently, so io_api="mps" returned a wrong optimum (x = 10 instead of 5 in the #1186 example, Gurobi and CPLEX).

  • matrices_to_file raises NotImplementedError when the matrices hold indicator rows, and points to io_api="lp" or "direct". This covers Model.to_file("*.mps") and solve(io_api="mps").
  • Tests: to_file to MPS raises; solve(io_api="mps") raises for every licensed solver with indicator support.
  • Release note under I/O.
Validation and reviewer notes
  • New tests fail on master (3/3) and pass here.
  • pytest on test_indicator_constraints, test_io, test_restrict_matrix, test_matrices, test_sos_constraints, test_windowing_integration: 336 passed, 5 skipped. Verified with Gurobi and CPLEX.
  • ruff check/ruff format clean. mypy reports the same 28 Xpress errors in linopy/solvers.py as master.
  • Behaviour change: code that wrote indicator models to MPS now raises where it got a wrong file before.
  • Possible follow-up: write an MPS INDICATORS section (Gurobi and CPLEX read it) instead of raising.
  • The empty-body indicator case (b = 1 -> 0 * x >= 5) is fixed for direct by fix: a constraint row without a nonzero term reaches the solver #1183; this PR does not touch it.

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.md of the upcoming release is included.
  • I consent to the release of this PR's code under the MIT license.

Generated by Claude Code

linopy writes MPS through HiGHS, which has no indicator constraints, so
they were dropped without warning and the solve returned a wrong optimum.

Closes #1186.

Copy link
Copy Markdown
Collaborator Author

Note

The following content was generated by AI.

"Check types" fails with 6 mypy errors in test/test_spec_api.py, which this PR does not touch. Master (ac3eaf7, from #1179) fails with the same errors. #1185 changes that file and passes the check, so it likely carries the fix.


Generated by Claude Code

@codspeed

codspeed Bot commented Nov 18, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 181 untouched benchmarks
⏩ 181 skipped benchmarks1


Comparing claude/exciting-turing-b608cv (b0ccb82) with master (ac3eaf7)

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.

MPS export silently drops all indicator constraints

2 participants