Repository navigation
Merge commitments that constrain the solver identically - #2635
Merged
Merged
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>
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>
Documentation build overview
|
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>
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
#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>
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
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_mappingis 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_ianddown_icarriesu * up_i + d * down_iof 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_namezips the original commitments againstcommitment_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 atied_commitmentsscenario that compares schedules and per-commitment costs across the two paths, and it went red withinfeasibleOrUnboundedwhen I removed the first commit's ties from either backend.Measurement
A pair priced
up 0 / down +50besideup +100 / down 0, same scope and baseline, over 384 time steps, one two-way device: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
Commitmentlevel, 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 theany-type split coverage from #2631. 371 planning tests pass.🤖 Generated with Claude Code
https://claude.ai/code/session_015He1XE7G7HN1svS7Nxgth4