Skip to content

Conversation

@CharlieFModo
Copy link
Contributor

Closes # (if applicable).

Changes proposed in this Pull Request

  • performance improvements to Xpress._solve_problem_from_file
  • use the solver's C interface directly to extract constraint and variable names rather than list comprehension
    • casting to string the xpress objects returned by problem.getConstraints() etc. is expensive and so is accessing the names via .name.
    • this gives small performance improvement on larger models
  • improve order of operations when extracting dual
    • for MILPs, let code hit the exception on getDuals before doing the expensive constraint name extraction
  • use writebinsol for a c. 10x improvement from writesol
    • @FabianHofmann it would be nice to not write the solution at all for xpress if keep_files=False

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.

@CharlieFModo CharlieFModo changed the title perf: use xpress c interface and order of operations improvement perf(xpress): use xpress c interface and order of operations improvement Sep 8, 2025
Copy link
Collaborator

@FabianHofmann FabianHofmann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that was fast ;)

@FabianHofmann
Copy link
Collaborator

@FabianHofmann it would be nice to not write the solution at all for xpress if keep_files=False

I very much like that, and I honestly have the feeling that this is a redundant artefact from an older implementation. So I would also be happy to remove the writing of the sol file entirely if not needed by us.

@CharlieFModo
Copy link
Contributor Author

I've pushed a small change that should remove the writing of the solution file in situations where it isn't needed or requested. For now, I've left the concept in there in case people are relying on the keep_files=True solve option

@CharlieFModo CharlieFModo changed the title perf(xpress): use xpress c interface and order of operations improvement perf: use xpress c interface, xpress solution order of operations improvement, remove redundant writing of solution files Sep 8, 2025
@CharlieFModo CharlieFModo changed the title perf: use xpress c interface, xpress solution order of operations improvement, remove redundant writing of solution files perf: use xpress c interface, xpress solution order of operations improvement, remove writing of redundant solution files Sep 8, 2025
linopy/model.py Outdated
Comment on lines 1193 to 1201
if (
solver_name
in ["xpress", "gurobi", "highs", "mosek", "scip", "copt", "mindopt"]
and not keep_files
):
# these (solver, keep_files=False) combos do not need a solution file
solution_fn = None
else:
solution_fn = self.get_solution_file()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like to avoid this hard-coded list of solvers here, rather define is in the "preamble" of solvers.py and import from there or add the logic to the solver classes (would however mean to pass keep_files to them)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Have done the first option for a smaller set of changes. I originally thought about passing the keep_files parameter through to the solvers but it felt a little messy.

Copy link
Collaborator

@FabianHofmann FabianHofmann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@FabianHofmann FabianHofmann merged commit 84f6896 into PyPSA:master Sep 9, 2025
23 of 24 checks passed
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.

2 participants