-
Notifications
You must be signed in to change notification settings - Fork 57
Commitments can be scoped to specific sensors, binding their aggregate flow #2295
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Flix6x
wants to merge
4
commits into
main
Choose a base branch
from
feat/sensor-scoped-commitments
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
69f7f56
feat: commitments can be scoped to specific sensors, binding their ag…
Flix6x 80174b8
Merge branch 'main' into feat/sensor-scoped-commitments
Flix6x a696cd4
docs: changelog entry for sensor-scoped commitments (#2295)
Flix6x 6b4ec90
Merge branch 'main' into feat/sensor-scoped-commitments
Flix6x File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2046,3 +2046,83 @@ def test_commitment_commodity_does_not_bind_other_commodity_devices(): | |
| # the electricity device (index 0), not the gas device (index 1). | ||
| assert (electricity_commitment.device == 0).all() | ||
| assert set(electricity_commitment.device_group.unique()) == {"electricity"} | ||
|
|
||
|
|
||
| def test_sensor_scoped_commitment_binds_aggregate_of_selected_devices(app, db): | ||
| """A commitment scoped to specific sensors (here: two e-heaters) binds their | ||
| aggregate flow as one commitment: a baseline of 10 MW with a steep penalty on | ||
| downward deviation keeps their combined consumption at 10 MW even though a | ||
| cheaper allocation (0 MW) exists, while an unscoped battery stays unaffected. | ||
| """ | ||
| heater_type = get_or_create_model(GenericAssetType, name="e-heater") | ||
| site = GenericAsset( | ||
| name="Band site (scoped commitment test)", generic_asset_type=heater_type | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Explain the term "band" in the docstring. |
||
| ) | ||
| db.session.add(site) | ||
| db.session.flush() | ||
|
|
||
| resolution = pd.Timedelta("1h") | ||
| start = pd.Timestamp("2026-02-01T00:00:00+01:00") | ||
| end = pd.Timestamp("2026-02-01T04:00:00+01:00") | ||
|
|
||
| def sensor(name): | ||
| s = Sensor( | ||
| name=name, unit="MW", event_resolution=resolution, generic_asset=site | ||
| ) | ||
| db.session.add(s) | ||
| return s | ||
|
|
||
| heater_1 = sensor("band heater 1") | ||
| heater_2 = sensor("band heater 2") | ||
| db.session.flush() | ||
|
|
||
| flex_model = [ | ||
| { | ||
| # Heaters burn money at the consumption price; without the band | ||
| # commitment the optimum is to stay off. | ||
| "sensor": heater_1.id, | ||
| "power-capacity": "8 MW", | ||
| "consumption-capacity": "8 MW", | ||
| "production-capacity": "0 kW", | ||
| }, | ||
| { | ||
| "sensor": heater_2.id, | ||
| "power-capacity": "8 MW", | ||
| "consumption-capacity": "8 MW", | ||
| "production-capacity": "0 kW", | ||
| }, | ||
| ] | ||
| flex_context = { | ||
| "consumption-price": "50 EUR/MWh", | ||
| "production-price": "50 EUR/MWh", | ||
| "site-power-capacity": "1 GW", | ||
| "commitments": [ | ||
| { | ||
| "name": "reserved band", | ||
| "sensors": [heater_1.id, heater_2.id], | ||
| "baseline": "10 MW", | ||
| # Steep penalty for consuming less than the band (negative price | ||
| # penalizes downward deviation); consuming more is free. | ||
| "down-price": "-10000 EUR/MWh", | ||
| } | ||
| ], | ||
| } | ||
|
|
||
| scheduler = StorageScheduler( | ||
| asset_or_sensor=site, | ||
| start=start, | ||
| end=end, | ||
| resolution=resolution, | ||
| belief_time=start, | ||
| flex_model=flex_model, | ||
| flex_context=flex_context, | ||
| return_multiple=True, | ||
| ) | ||
| results = scheduler.compute(skip_validation=True) | ||
| schedules = { | ||
| r["sensor"]: r["data"] for r in results if r.get("name") == "storage_schedule" | ||
| } | ||
| combined = schedules[heater_1] + schedules[heater_2] | ||
| # The band keeps the aggregate at 10 MW (cheapest way to avoid the penalty), | ||
| # even though each heater alone (8 MW max) could not carry it. | ||
| np.testing.assert_allclose(combined.iloc[:-1], 10.0, rtol=1e-4) | ||
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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the regular commitment not aggregating over all devices (of one grid-connected commodity), rather than applied to each device individually?