Repository navigation
Apply storage losses to a shared stock's starting stock in its stored state of charge - #2838
Merged
Merged
Conversation
A shared stock (two flex-model entries on one state-of-charge sensor) with a storage efficiency below 1 should store the same decaying state of charge as a single-device stock, and the stock the solver modelled, with and without flows. 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>
…hedule The shared-stock branch of StorageScheduler._build_soc_schedule integrated each device's contribution from zero and added the starting stock on top, so the starting stock never decayed, while the solver's group_stock_balance decays the whole stock. Integrate the starting stock along with the first device's contribution instead, and use the group's storage efficiency (that of its first device) for all contributions, as the solver does. 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>
Documentation build overview
3 files changed± changelog.html± _autosummary/flexmeasures.data.models.planning.storage.html± api/v3_0.html |
Flix6x
added a commit
that referenced
this pull request
Nov 6, 2026
…stock in its stored state of charge (#2838) (cherry picked from commit cdb57a7, leaving out its changelog entry) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DWv6v2AH6FAvKrAHvqWV3D Signed-off-by: F.N. Claessen <felix@seita.nl>
Flix6x
added a commit
that referenced
this pull request
Nov 6, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DWv6v2AH6FAvKrAHvqWV3D Signed-off-by: F.N. Claessen <felix@seita.nl>
This was referenced Nov 11, 2026
Flix6x
added a commit
that referenced
this pull request
Nov 11, 2026
The v1.1.1 patch release backports #2855, #2861, #2838, #2829, #2851, #2845, #2859, #2850 and #2860 to the 1.1.x branch. Move their changelog bullets out of the v1.2.0 section into a new v1.1.1 section, worded and ordered as on 1.1.x, so the same fixes are not listed as unreleased once 1.1.1 ships. The bullet for #2861 takes the 1.1.x wording, which adds that Python 3.10 keeps the earlier Pillow, dnspython and filelock. The API change log needs no split: v3.0-35 holds only #2859, which ships in v1.1.1. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: F.N. Claessen <felix@seita.nl>
Flix6x
added a commit
that referenced
this pull request
Nov 23, 2026
The security releases v1.1.2 and v1.0.3 ship the fixes merged here. Add their sections between v1.2.0 and v1.1.1, worded as on the 1.1.x and 1.0.x branches (v1.0.3 also lists the backport of #2838, as on 1.0.x), so the same fixes are not listed as unreleased once they ship. The API change log gets v3.0-36 for these changes, and v3.0-35 gets the date it shipped with v1.1.1. The CLI change log gets a v1.1.2 section. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: F.N. Claessen <felix@seita.nl>
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.
Description
Fixes the bookkeeping described in #2837.
For a shared stock (several flex-model entries on one
state-of-chargesensor),StorageScheduler._build_soc_scheduleintegrated each device's contribution from zero, with the storage efficiency, and then added the starting stock on top without any decay.The solver (
group_stock_balanceinlinear_optimization.py) decays the whole stock, starting stock included.So the stored state of charge drifted above the solver's stock by
s0 * (1 - prod(eta_1..eta_k))afterksteps, could exceedsoc-max, and fed that drift back into the next schedule'ssoc-at-start.initial_stock=soc_at_start[d0] if d == d0 else 0), and the separateinitial_stock +in the sum is gone.Why this matches the solver exactly
group_stock_balanceruns one recursion per stock group,stock[j] = a * stock[j-1] + b * change[j], with(a, b) = loss_coefficients(efficiency of the group's first device), starting from the group's initial stock, wherechange[j]sums the members' converted flows and stock deltas.integrate_time_seriesruns the same recursion (apply_stock_changes_and_losseswithhow="linear", whichloss_coefficientsmirrors), per device, with each device's own up/down conversion efficiencies.That recursion is linear in the initial stock and the changes, so the sum of per-device runs (one of them carrying the starting stock) equals one run over the summed changes, as long as all runs use the same storage efficiency.
Different storage efficiencies within a group: members cannot differ.
StorageSchedulerresolves one storage efficiency per shared stock and assigns it to all members (raising if several entries define one),and
prepare_scheduling_problemraises if devices in one stock group have different efficiency columns.Still, I took the efficiency from the first device for all contributions rather than from each device, so the bookkeeping reads the same value the solver reads (
m.device_efficiency[d0, j]), and stays in sync should that validation ever loosen.Per-device conversion efficiencies (charging/discharging) do differ between members, and stay per device, as in the solver's
_stock_change_at.Other consumers
soc_schedule_mwh(the MWh series per device) comes from the samesoc_mwh, so the check of unresolvedsoc-minima/soc-maxima(_compute_unresolved_targets) now uses the decayed stock, too. Previously, a shared stock could report a minimum as met with an overstated SoC.state-of-chargesensor. Single-device stocks were already correct and are unchanged.%unit conversion is downstream ofsoc_mwhand unchanged.How to test
Two regression tests in
flexmeasures/data/models/planning/tests/test_storage.py:test_shared_stock_soc_decays_like_single_device_stock: two idle devices share a stock (90% storage efficiency per 15 minutes, starting at 0.8 MWh); its stored SoC must equal0.8 * 0.9**k, the single-device path's SoC, and the solver's own stock (read from the Pyomo model'sgroup_stock).test_shared_stock_soc_with_flows_matches_solver_stock: two devices with different charging/discharging efficiencies move a shared stock (99% storage efficiency) to two SoC targets; its stored SoC must equal the solver's stock at every step and hit the targets.Both fail without the fix (the first stored a flat 0.8 MWh, the second drifted up to 0.06 MWh above the solver's stock), and pass with it.
The tests pin the Pyomo backend (
appsi_highs), because only the Pyomo model exposes the solver's stock per group; the fix itself is backend-independent.The planning test package passes locally (392 passed, 3 xfailed).
Question
This bug is in released versions (1.0.1 and 1.1.0). Should it be backported to 1.1.x?
I added the changelog entry under v1.2.0 for now.
Further Improvements
None planned.
Related Items
#2837
documentation/changelog.rst🤖 Generated with Claude Code
https://claude.ai/code/session_01UBBvKZkzbfEPKctwTN8SDf