Skip to content

Improve Mosek interface to select optimal solution#667

Open
mgrabovsky wants to merge 3 commits intoPyPSA:masterfrom
mgrabovsky:fix-665
Open

Improve Mosek interface to select optimal solution#667
mgrabovsky wants to merge 3 commits intoPyPSA:masterfrom
mgrabovsky:fix-665

Conversation

@mgrabovsky
Copy link
Copy Markdown

Closes #665

Changes proposed in this Pull Request

Mosek can produce two distinct solutions with separate statuses: an interior-point solution (soltype.itr) and a basic solution (soltype.bas) obtained by basis identification (crossover).

Previously, linopy's Mosek interface only read the IPM solution. If the IPM terminated with solsta.dual_infeas_cer but crossover then recovers an optimal basic solution, linopy would report infeasible_or_unbounded with Objective: nan and the actual optimal solution would be silently discarded, even though Mosek itself had it.

After this change, linopy picks the solution (between bas, itr and itg) with the best score, with the order being solsta.[integer_]optimal > any other defined status > undefined. If both bas and itr are optimal, the itr solution is chosen to preserve backward compatibility with the previous behavior.

This patch was co-authored with Claude Opus 4.7.

Checklist

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

@mgrabovsky mgrabovsky changed the title Improve Mosek interface to select optimal solution status Improve Mosek interface to select optimal solution Apr 29, 2026
mgrabovsky and others added 3 commits April 29, 2026 16:51
Mosek can produce two distinct solutions with separate statuses: an
interior-point solution (soltype.itr) and a basic solution (soltype.bas)
obtained by basis identification (crossover).

Previously, linopy's Mosek interface only read the IPM solution. If the
IPM terminated with solsta.dual_infeas_cer but crossover then recovers
an optimal basic solution, linopy would report infeasible_or_unbounded
with Objective: nan and the actual optimal solution would be silently
discarded, even though Mosek itself had it.

After this change, linopy picks the solution (between bas, itr and itg)
with the best score, with the order being solsta.[integer_]optimal >
any other defined status > undefined. If both bas and itr are optimal,
the itr solution is chosen to preserve backward compatibility with the
previous behavior.

A similar bug was present in cvxpy (see cvxpy/cvxpy#335), fixed by
@aszekMosek in cvxpy/cvxpy#347.

Patch co-authored with Claude Opus 4.7.

Fixes PyPSA#665
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.

Mosek interface ignores basic solution when IPM ends in dual_infeas_cer but crossover finds optimal basis

1 participant