Skip to content

Merge commitments that constrain the solver identically - #2635

Merged
Flix6x merged 9 commits into
mainfrom
feat/2534-tie-interchangeable-commitments
Oct 1, 2026
Merged

Flix6x merged 9 commits into
mainfrom
feat/2534-tie-interchangeable-commitments

Conversation

@Flix6x

@Flix6x Flix6x commented Oct 1, 2026 •

Copy link
Copy Markdown
Member

Refs #2534. Stacked on #2631 — review that one first; this branch's own diff is its two commits.

This is the MILP-prevention step from #2631's discussion. The branch has two commits because it changed shape on the way: the first shared the deviation variables between duplicates, the second replaces that with merging them outright, which is what you asked for and is the better answer. The measurement at the bottom says why.

What it does

Two sub-commitments constrain the solver identically when they agree on

  • which deviation prices they carry — that is what sets the row's bounds, since both present makes it an equality and one present makes it one-sided,
  • what they bind: flow or stock, and for a stock, which stock,
  • the devices they are scoped to,
  • their commodity, since costs are reported per commodity off the sub-commitment that carried them,
  • their quantity at every time step they cover.

They may still differ in the level of those prices, which is the whole point: that is what distinguishes the commitments while leaving their constraints interchangeable.

Such a group is now replaced by one sub-commitment carrying their summed prices. The duplicates said nothing the first one did not, so this takes nothing away; and with one deviation to inflate rather than one each, a commitment that is not convex on its own can be carried by a partner whose prices more than compensate. Where the summed prices are convex, the group needs no sign variables and the problem stays a linear program.

A group that is already convex throughout is left alone, so every problem that does not need this keeps its model exactly as it was.

The part to review closely: cost reporting

A merged sub-commitment stands for several commitments, and commitment_mapping is one sub-commitment to one commitment, so this is where merging could go quietly wrong.

Its realised cost is shared out by each member's own prices against the deviation they share: a commitment priced up_i and down_i carries u * up_i + d * down_i of it. That is exact rather than apportioned, because the deviation is one and the same for every member — your point about disassembly holds, and this is it.

It is also not optional. report_commitment_costs_by_name zips the original commitments against commitment_costs.values(), so a member that loses its line would mis-label every line after it. Attributing the whole merged cost to one member instead turns the comparison test red on exactly that (assert [0] == [0, 1]), which I checked rather than assumed.

Both backends, or neither

Both read the same convex_cost_curve, so a backend that did not merge while still reading the verdict as true would leave such a pair unbounded. The equivalence set carries a tied_commitments scenario that compares schedules and per-commitment costs across the two paths, and it went red with infeasibleOrUnbounded when I removed the first commit's ties from either backend.

Measurement

A pair priced up 0 / down +50 beside up +100 / down 0, same scope and baseline, over 384 time steps, one two-way device:

arm sub-commitments wall clock
not merged (sign variables, MILP) 768 1.10 s
merged (this PR, LP) 384 0.62 s
the same problem written as one commitment 384 0.45 s

The robust fact is the first column: merging builds exactly the model the problem would have had if the two commitments had been written as one, 384 against 768. Wall clock varies run to run (I measured between 1.2× and 1.8× across repeats, and a tighter benchmark did not finish in reasonable time, so treat the ratio as indicative and the model size as the result).

The residual 0.62 s against 0.45 s is not model size, since those two build the same model. It is the cost of preparing two commitment frames and splitting them into 768 sub-frames before merging back to 384 — input preparation, which is where #2364 found the time goes. Recovering it would mean merging at the Commitment level, before the split, which is a larger change and a separate one.

For contrast, the first commit's approach — tying the duplicates' deviations rather than removing them — gave about 1.1× at these sizes, because the tie rows cost roughly what the binaries did. Merging is the version worth having.

Tests

In test_sign_binaries.py: the masked pair now solves as an LP with half the sub-commitments; a pair with different baselines is not interchangeable and still gets its sign variables; an already-convex pair is left unmerged; and the merged and unmerged runs are held to the same costs, in the same order, per commitment and per device. Plus the any-type split coverage from #2631. 371 planning tests pass.

🤖 Generated with Claude Code

https://claude.ai/code/session_015He1XE7G7HN1svS7Nxgth4

Flix6x and others added 5 commits October 1, 2026 12:59
…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>
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>
…ntically

Two sub-commitments impose the identical constraint when they agree on which deviation prices they carry, what they bind, the devices they are scoped to, and their quantity at every time step they cover.
They may still differ in the level of those prices, which is what distinguishes the commitments while leaving their constraints interchangeable.
Such sub-commitments pin the same deviation in any bounded solution, so their deviation variables are now tied to each other.

That leaves one slack to price rather than one per member, which is what lets a commitment that is not convex on its own be carried by one whose prices more than compensate.
Where a group's summed prices are convex the group needs no sign variables at all, so the problem stays a linear program rather than becoming a mixed-integer one.
A group that is already convex throughout has nothing to gain and is left alone, which keeps every other problem's model exactly as it was.

Each commitment keeps its own deviation variables and so its own cost line, priced on its own prices rather than on the group's, so nothing has to be taken apart again after the solve.
A test holds the tied linear program and the sign-variable program to the same answer, per commitment and per device.

Both backends have to emit the ties, since both read the same convexity verdict: a backend that skipped them would leave such a pair unbounded.
The equivalence set now carries a scenario for it, which goes red if either backend's ties are removed.

Refs #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>
@read-the-docs-community

read-the-docs-community Bot commented Oct 1, 2026 •

Copy link
Copy Markdown

Documentation build overview

📚 flexmeasures | 🛠️ Build #34880278 | 📁 Comparing 9e1ae64 against latest (d0903d0)

  🔍 Preview build  

4 files changed
± changelog.html
± genindex.html
± _autosummary/flexmeasures.data.models.planning.scheduling_problem.html
± api/v3_0.html

Tying their deviation variables left the duplicates in the model, constrained to agree.
Merging removes them: a group of interchangeable sub-commitments is replaced by one carrying their summed prices, so the model is the size it would be had the commitments been written as one.
Measured on a pair over 384 time steps, that is 768 sub-commitments against 384, which is also what the same problem written as a single commitment builds.

The price of doing it this way is that a merged sub-commitment stands for several commitments, and costs are reported per commitment, alongside the commitments themselves.
So its realised cost is shared out by each member's own prices against the deviation they share: a commitment priced `up_i` and `down_i` carries `u * up_i + d * down_i` of it.
That is exact rather than apportioned, because the deviation is one and the same for every member.
Attributing the whole cost to one member instead drops the others' lines, which would mis-label every line after them; a test holds the merged and unmerged runs to the same costs, in the same order, per commitment and per device.

Refs #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>
@Flix6x Flix6x self-assigned this Oct 1, 2026
@Flix6x Flix6x added this to the 1.1.0 milestone Oct 1, 2026
@Flix6x Flix6x changed the title Share one deviation between commitments that constrain the solver identically Merge commitments that constrain the solver identically Oct 1, 2026
@Flix6x
Flix6x added this pull request to stack #2636 October 1, 2026 15:00
Flix6x and others added 2 commits October 1, 2026 17:12
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>
…t merger

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>

# Conflicts:
#	documentation/changelog.rst
Base automatically changed from fix/2534-per-commitment-convexity to main October 1, 2026 15:39
#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>
@Flix6x
Flix6x merged commit 0fc1fef into main Oct 1, 2026
12 of 13 checks passed
@Flix6x
Flix6x deleted the feat/2534-tie-interchangeable-commitments branch October 1, 2026 15:48
Ahmad-Wahid added a commit that referenced this pull request Nov 4, 2026
…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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant