Skip to content

Add FLEXMEASURES_LP_SOLVER_OPTIONS to configure solver options#2283

Open
Flix6x wants to merge 2 commits into
mainfrom
feat/configurable-lp-solver-options
Open

Add FLEXMEASURES_LP_SOLVER_OPTIONS to configure solver options#2283
Flix6x wants to merge 2 commits into
mainfrom
feat/configurable-lp-solver-options

Conversation

@Flix6x

@Flix6x Flix6x commented Jul 10, 2026

Copy link
Copy Markdown
Member

What

Solver options for the scheduling solver could previously only be set in code (a hardcoded HiGHS profile inside device_scheduler). This adds a FLEXMEASURES_LP_SOLVER_OPTIONS config dict, merged over that profile so operators can tune the solver without patching FlexMeasures:

FLEXMEASURES_LP_SOLVER_OPTIONS = {"mip_rel_gap": "1e-4"}

Validation (the important part)

When the solver is HiGHS, the options are validated against the installed HiGHS build before use. An unknown option name, an invalid value, or a feature the build lacks raises a clear ValueError.

This matters because Pyomo's appsi_highs interface applies options without checking HiGHS' return status — so a mistake is otherwise silently ignored. Concretely, solver="hipo" is unavailable in the pip-installed highspy (it needs a HiGHS built against BLAS + METIS), yet appsi_highs solves on as if nothing were wrong. Anyone benchmarking such an option would get a false negative. Validation turns that silent no-op into an explicit error.

Setting threads/parallel logs a warning: HiGHS initializes its thread scheduler once per process, so in a long-lived worker only the first solve honours them and later solves fail with global scheduler has already been initialized.

Tests

test_solver_options.py covers: the shipped default profile stays acceptable, unknown names / invalid values / unavailable solvers raise, all rejected options are reported, and threads warns.

Context

Found while investigating SeitaBV/ems#172 (benchmarking whether the HiGHS hipo solver helps the HEMS scheduler — it can't even be selected from the pip wheel, and appsi_highs was hiding that).

🤖 Generated with Claude Code

https://claude.ai/code/session_01LeqGFrHfGrBHAJyjdAyr3y

Flix6x and others added 2 commits July 10, 2026 21:33
Solver options for the scheduling solver could previously only be set in
code (a hardcoded HiGHS profile in device_scheduler). This adds a
FLEXMEASURES_LP_SOLVER_OPTIONS config dict, merged over that profile so
operators can tune the solver (e.g. {"mip_rel_gap": "1e-4"}) without
patching FlexMeasures.

When the solver is HiGHS, the options are validated against the installed
HiGHS build: an unknown option name, an invalid value, or a feature the
build lacks raises a clear ValueError. This matters because Pyomo's
appsi_highs interface applies options without checking HiGHS' return
status, so a mistake would otherwise be silently ignored (e.g.
solver="hipo" is unavailable in the pip-installed highspy, yet appsi_highs
solves on as if nothing were wrong). Setting threads/parallel logs a
warning about HiGHS' process-global thread scheduler.

Found while investigating SeitaBV/ems#172.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LeqGFrHfGrBHAJyjdAyr3y
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LeqGFrHfGrBHAJyjdAyr3y
@read-the-docs-community

read-the-docs-community Bot commented Jul 10, 2026

Copy link
Copy Markdown

Documentation build overview

📚 flexmeasures | 🛠️ Build #33536583 | 📁 Comparing 32d3f10 against latest (922ecf6)

  🔍 Preview build  

5 files changed · ± 5 modified

± Modified

# Apply operator-configured options last, so they override the defaults above.
configured_options = current_app.config.get("FLEXMEASURES_LP_SOLVER_OPTIONS") or {}
if configured_options and "highs" in solver_name.lower():
validate_highs_options(configured_options)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

It would be better to do this once on startup rather than for each scheduling job.

Comment on lines +20 to +25
"mip_rel_gap": "0",
"mip_abs_gap": "0",
"primal_feasibility_tolerance": "1e-9",
"dual_feasibility_tolerance": "1e-9",
"mip_feasibility_tolerance": "1e-9",
"output_flag": "false",

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The settings tested here should be gotten from the operational codebase. Maybe via a shared import.

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