Repository navigation
Check each commitment for a convex cost curve, rather than their pooled prices - #2631
Conversation
…ed prices A commitment carries its own pair of deviation variables, priced by its own pair of prices, so a convex cost curve is a property of one commitment at a time. Summing every commitment's prices per time step let one commitment's prices mask another's non-convexity, which left out the commitment-sign variables that keep such a commitment bounded. The solver then returned the problem as infeasible or unbounded, with nothing to point at. The check now reads a commitment's price through the same helper that the Pyomo and the HiGHS path use to price their deviation variables, so that the check and the model cannot disagree about a commitment's price. Fixes #2534 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015He1XE7G7HN1svS7Nxgth4 Signed-off-by: F.N. Claessen <claessen@seita.nl>
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015He1XE7G7HN1svS7Nxgth4 Signed-off-by: F.N. Claessen <claessen@seita.nl>
Documentation build overview
10 files changed ·
|
There was a problem hiding this comment.
Copilot review overview
🔵 Needs a closer look
It changes core scheduler convexity detection that toggles LP-vs-MILP behaviour across both solver backends, and the interaction with split multi-slot ("any"-type) sub-commitments is subtle enough to warrant human verification.
Review effort: Balanced
Findings: None
What changed in this PR
This PR fixes issue #2534, where the scheduler's convex-cost-curve check pooled every commitment's deviation prices per time step before deciding whether the commitment-sign binary variables (and their Big-M safeguards) were needed. Because each commitment carries its own pair of deviation variables, one commitment's expensive upwards price could mask another commitment's non-convexity in the pooled sum, leaving out the binaries and returning the whole problem as infeasible/unbounded. The fix evaluates convexity per commitment and extracts a shared deviation_price helper so the convexity check and both solver backends price deviations identically.
Changes:
- Added a shared
deviation_pricehelper inscheduling_problem.pyand switched the convex-cost-curve check from a pooled per-time-step sum to anall(...)over each commitment individually. - Reused
deviation_pricein the Pyomo (linear_optimization.py) and highspy (highspy_optimization.py) backends, replacing their duplicated local price accessors. - Added three regression tests in
test_sign_binaries.py(including the masking case from #2534) and a Bugfixes changelog entry.
| File | Description |
|---|---|
flexmeasures/data/models/planning/scheduling_problem.py |
Adds deviation_price, replaces the pooled convexity check with a per-commitment check, and updates the related dataclass comment. |
flexmeasures/data/models/planning/linear_optimization.py |
Imports and uses deviation_price in price_down_select/price_up_select, removing duplicated logic. |
flexmeasures/data/models/planning/highspy_optimization.py |
Imports and uses deviation_price, removing the local _price_of helper. |
flexmeasures/data/models/planning/tests/test_sign_binaries.py |
Adds tests covering non-convex detection, the masking regression, and the each-convex no-binaries case. |
documentation/changelog.rst |
Adds a Bugfixes entry describing the fix with the PR link. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Copilot asked for the interaction with split multi-slot commitments to be verified, so this holds it. An "any"-type commitment groups every time slot together, and such a group is split into an upwards and a downwards half, each keeping one price column. The test passes both before and after the per-commitment check, which is the point: this change leaves the split path alone. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015He1XE7G7HN1svS7Nxgth4 Signed-off-by: F.N. Claessen <claessen@seita.nl>
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015He1XE7G7HN1svS7Nxgth4 Signed-off-by: F.N. Claessen <claessen@seita.nl>
#2631 was squash-merged, so main holds its content as one commit while this branch carries the originals. Resolved with -X ours, which is lossless here because main was merged into #2631's branch before the squash, so this branch already holds everything main does on these files -- see .github/instructions/feature-branch-sync.instructions.md. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015He1XE7G7HN1svS7Nxgth4 Signed-off-by: F.N. Claessen <claessen@seita.nl>
* Tidy up the v1.1.0 section of the main changelog Group the entries under New features, Infrastructure / Support and Bugfixes by topic, using bold paragraph headings, so the section's table of contents stays as it was. Merge entries describing one change from several PRs, split entries combining unrelated changes, and cut verbosity, keeping every upgrade instruction. Correct two PR links whose text and target disagreed or that pointed at the wrong PR (#2585 to #2583, #2631 to #2634), and move the README entry out of "Automations, in detail". Set the release month to November, leaving the day as a placeholder. Part of #2772 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UBBvKZkzbfEPKctwTN8SDf Signed-off-by: F.N. Claessen <claessen@seita.nl> * Tidy up the v1.1.0 section of the CLI changelog Order the entries by the same topics as the main changelog, additions before changes within each topic. Merge the two entries on flexmeasures jobs run-automations, split the entry on saving report outputs from the one on saving plugin forecasts, and give flexmeasures show account an entry of its own. Set the release month to November, leaving the day as a placeholder. Part of #2772 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UBBvKZkzbfEPKctwTN8SDf Signed-off-by: F.N. Claessen <claessen@seita.nl> * Merge the duplicate entry on reusing a data source for an automation in API v3.0-40 Part of #2772 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UBBvKZkzbfEPKctwTN8SDf Signed-off-by: F.N. Claessen <claessen@seita.nl> * Merge the unreleased API versions into v3.0-40, released with v1.1.0 v3.0-33 to v3.0-40, except the resolution change already released with v1.0.1, become the one API version v3.0-40, dated like the v1.1.0 release and grouped by the same topics as the main changelog. Changes between versions that never shipped are folded into the end state, such as the automation cursor moving from UTC to the automation's own timezone. The resolution change keeps the number it was released under, v3.0-33, as in the v1.0.1 release. Part of #2772 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UBBvKZkzbfEPKctwTN8SDf Signed-off-by: F.N. Claessen <claessen@seita.nl> * State the CDN fallback in the changelog entry on serving the UI's libraries Until a library's files are fetched, browsers load them from its CDN, checked against their hashes. Part of #2772 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UBBvKZkzbfEPKctwTN8SDf Signed-off-by: F.N. Claessen <claessen@seita.nl> * Number the v1.1.0 API version v3.0-34, right after the released v3.0-33 Part of #2772 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UBBvKZkzbfEPKctwTN8SDf Signed-off-by: F.N. Claessen <claessen@seita.nl> * Address the review of the v1.1.0 changelog tidy-up Splits the device-group aggregate entry, moves #2699 to "Automations, in detail", adds upgrade warnings on the new roles and the per-organisation rate limits, links the add-report warning, and clarifies or trims several entries. Part of #2772 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UBBvKZkzbfEPKctwTN8SDf Signed-off-by: F.N. Claessen <claessen@seita.nl> * Address the second part of the review of the v1.1.0 changelog tidy-up Leads the plugin-forecaster fix with returning results, explains day-ahead prices as realized beliefs about the future, names the kinds of regressors, and stops implying that an input's belief_time keeps its name on purpose. Part of #2772 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UBBvKZkzbfEPKctwTN8SDf Signed-off-by: F.N. Claessen <claessen@seita.nl> * Address the third part of the review of the v1.1.0 changelog tidy-up Tells hosts, not organisations, to check rate limits before upgrading, and says who calls set_attribute. Part of #2772 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UBBvKZkzbfEPKctwTN8SDf Signed-off-by: F.N. Claessen <claessen@seita.nl> --------- Signed-off-by: F.N. Claessen <claessen@seita.nl> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
…ent merge from the split's constant columns Since this branch last merged main, main added the per-commitment convexity check (#2631) and the merge of interchangeable sub-commitments (#2635). Both read their prices, shapes and quantities back off every one-row sub-commitment frame. They now read them from the constant columns and row arrays this branch gathers while splitting, so the HiGHS path still never builds those frames. A sub-commitment that carries a merged group is built with its summed prices only when the Pyomo path asks for it. merge_interchangeable_subcommitments and interchangeable_subcommitments still accept plain frames. main's timely-beliefs>=4.4.1 requirement supersedes this branch's >=4.3.0. Signed-off-by: Ahmad-Wahid <ahmedwahid16101@gmail.com>
Fixes #2534.
The defect
A commitment's cost curve is convex when deviating upwards costs at least what deviating downwards pays. Where it is not, the solver needs the commitment-sign binaries: without them it can inflate the upwards and the downwards deviation together, leaving the position unchanged, and bank the difference between the two prices without bound.
The check decided this from the prices of all commitments pooled per time step:
But each commitment carries its own pair of deviation variables, priced by its own pair of prices, so convexity is a property of one commitment at a time. Pooling let a commitment with an expensive upwards price hide a second commitment that pays for deviating downwards. The binaries were then left out, and the solver returned the whole problem as infeasible or unbounded, with nothing to point at.
The fix
Check each commitment on its own, reading its price through a new shared
deviation_pricehelper — the same helper the Pyomo path and the HiGHS path now use to price their deviation variables, so that the check and the model cannot disagree about what a commitment's price is. The helper ishighspy_optimization's former local_price_of, whose docstring already said it "Mirrors price_down_select / price_up_select"; now it does so by construction rather than by repetition.What this changes for existing schedules
Nothing, except that a problem which used to fail now solves. Summation preserves the inequality: if every commitment is convex, the pooled sums are convex too. So the pooled check flagged non-convexity only when some commitment really was non-convex, and the per-commitment check detects a strict superset of what it detected. No problem loses its binaries, and no problem that solved before is solved differently — a masked commitment made the problem unbounded every time, because its deviation variables are bounded on one side only, so there was no silently wrong answer to preserve.
The cost is that a masked commitment now makes the problem a MILP, which is the price of solving it at all.
Proof it fails without the fix
test_another_commitments_prices_do_not_mask_a_non_convex_commitmentbuilds two commitments — one priced to reward deviating downwards, one with an expensive upwards price that hides it in the sum — and reverting the one-line check turns it red withTerminationCondition.infeasibleOrUnbounded, HiGHS reportingPrimal infeasible or unbounded. It passes with the fix.It comes with two controls, which pass either way and pin the boundaries:
The planning suite is green (366 passed, 3 xfailed).
Affected versions
The pooled check dates back to "only use extra binary variable if cost curve is not convex" and is in v1.0.1, so this is a fix to released behaviour rather than to something unreleased.
🤖 Generated with Claude Code
https://claude.ai/code/session_015He1XE7G7HN1svS7Nxgth4