Feature: flex-context per commodity as list#2235
Merged
Flix6x merged 48 commits intoJul 1, 2026
Merged
Conversation
…mmodity) Signed-off-by: F.N. Claessen <claessen@seita.nl>
Signed-off-by: F.N. Claessen <claessen@seita.nl>
Signed-off-by: F.N. Claessen <claessen@seita.nl>
…odity Signed-off-by: F.N. Claessen <claessen@seita.nl>
Signed-off-by: F.N. Claessen <claessen@seita.nl>
…ty' into dev/flex-context-as-list Signed-off-by: F.N. Claessen <claessen@seita.nl> # Conflicts: # flexmeasures/ui/static/openapi-specs.json
Signed-off-by: F.N. Claessen <claessen@seita.nl>
Copilot AI
added a commit
that referenced
this pull request
Jun 12, 2026
- Add SensorReferenceSchema import - Override relax_constraints default to True in CommodityFlexContextSchema - Remove duplicate breach price and relax fields from FlexContextSchema - Remove duplicate set_default_breach_prices method from FlexContextSchema Co-authored-by: Flix6x <30658763+Flix6x@users.noreply.github.com>
- Add SensorReferenceSchema import - Override relax_constraints default to True in CommodityFlexContextSchema - Remove duplicate breach price and relax fields from FlexContextSchema - Remove duplicate set_default_breach_prices method from FlexContextSchema Co-authored-by: Flix6x <30658763+Flix6x@users.noreply.github.com> Signed-off-by: F.N. Claessen <claessen@seita.nl>
- Test aggregate-consumption and aggregate-production fields - Test SharedSchema fields accessible in FlexContextSchema - Test CommodityFlexContextSchema relax_constraints defaults to True - Test shared currency logic for flex-context listings - Test breach prices in both schemas - Add noqa comment for existing unused variable Co-authored-by: Flix6x <30658763+Flix6x@users.noreply.github.com>
- Add validator to check prices share same currency across all commodity contexts - Fix test data to use actual fixture sensor names - All new tests now passing Co-authored-by: Flix6x <30658763+Flix6x@users.noreply.github.com>
- Add aggregate-consumption and aggregate-production to scheduling.rst - Exclude COMMODITY_FLEX_CONTEXT and COMMODITY_FLEX_MODEL from doc test (already documented as "commodity") - Exclude aggregate fields from UI test (not yet supported in UI) Co-authored-by: Flix6x <30658763+Flix6x@users.noreply.github.com>
Signed-off-by: F.N. Claessen <claessen@seita.nl>
Signed-off-by: F.N. Claessen <claessen@seita.nl>
…g validators in place to forbid that, we actually stop having those fields in the schemas of those fields Signed-off-by: F.N. Claessen <claessen@seita.nl>
Signed-off-by: F.N. Claessen <claessen@seita.nl>
Signed-off-by: F.N. Claessen <claessen@seita.nl>
Signed-off-by: F.N. Claessen <claessen@seita.nl>
Flix6x
commented
Jun 12, 2026
…s possible that the entire flex-config is described in the db instead of the trigger message (this cherry-pick was adapted, because the flex-context moved from being documented as a dict to a list) Signed-off-by: F.N. Claessen <claessen@seita.nl>
Signed-off-by: F.N. Claessen <claessen@seita.nl>
Signed-off-by: F.N. Claessen <claessen@seita.nl>
sensor for aggregate-consumption sensor and/or aggregate-production Signed-off-by: F.N. Claessen <claessen@seita.nl>
…ty is defined in the html in 3 places Signed-off-by: F.N. Claessen <claessen@seita.nl>
…gate-production Signed-off-by: F.N. Claessen <claessen@seita.nl>
Signed-off-by: F.N. Claessen <claessen@seita.nl>
Co-authored-by: Felix Claessen <30658763+Flix6x@users.noreply.github.com> Signed-off-by: Ahmad Wahid <59763365+Ahmad-Wahid@users.noreply.github.com>
Co-authored-by: Felix Claessen <30658763+Flix6x@users.noreply.github.com> Signed-off-by: Ahmad Wahid <59763365+Ahmad-Wahid@users.noreply.github.com>
Signed-off-by: F.N. Claessen <claessen@seita.nl>
…ev/flex-context-as-list
Copilot AI
added a commit
that referenced
this pull request
Jun 16, 2026
Context: - PR #2235 tests were weak and under-specified - Need to verify aggregate sensors get filled with data - Need to verify correct sign conventions - Need to verify per-commodity logic and backwards compatibility Change: - New file test_scheduling_aggregate_sensors_fresh_db.py (465 lines) - 5 integration tests verifying aggregate sensor functionality: * Data filling and sign convention (3 parametrized cases) * Per-commodity aggregation (skipped - multi-device complexity) * Backwards compatibility (no commodity_contexts) * Data source type verification - Tests use fresh_db fixture for database modifications - All tests passing (5 passed, 1 skipped) Co-authored-by: Flix6x <30658763+Flix6x@users.noreply.github.com>
Copilot AI
added a commit
that referenced
this pull request
Jun 16, 2026
Context: - PR #2235 feedback: aggregate sensors not being filled with data - Missing per-commodity logic in StorageScheduler - Need backwards compatibility (no commodity_contexts = all electric) Change: - New method _compute_commodity_aggregate_schedules (lines 2082-2202) - Reconstructs commodity-to-devices mapping from device models - Computes per-commodity aggregates by summing ems_schedule - Supports aggregate-consumption and aggregate-production sensors - Applies split logic based on which sensors are defined - Maintains backwards compatibility with old format Co-authored-by: Flix6x <30658763+Flix6x@users.noreply.github.com>
Copilot AI
added a commit
that referenced
this pull request
Jun 16, 2026
Context: - PR #2235 tests were weak and under-specified - Test comments didn't accurately describe behavior - Need better schema validation coverage Change: - Renamed test_commodity_flex_context_defaults to test_commodity_flex_context_schema_validation - Enhanced docstring to clarify schema validation only - Added 3 new test cases for individual aggregate sensors - Added assertions to verify parsed sensor references - 6 parametrized test cases, all passing Co-authored-by: Flix6x <30658763+Flix6x@users.noreply.github.com>
Copilot AI
added a commit
that referenced
this pull request
Jun 16, 2026
Context: - PR #2235 required testing aggregate sensor data filling - Integration tests verify scheduler populates aggregate sensors - Schema validation tests are separate from integration tests Change: - Document integration test pattern for aggregate sensors - Add fresh_db requirement for scheduler integration tests - Document scheduler result format (list[dict] with sensor/data/unit/name) - Add lesson about sign convention verification pattern - Document backwards compatibility testing approach Co-authored-by: Flix6x <30658763+Flix6x@users.noreply.github.com>
Copilot AI
added a commit
that referenced
this pull request
Jun 16, 2026
Context: - PR #2235 added _compute_commodity_aggregate_schedules method - Implemented per-commodity aggregate power flow computation - Split logic for consumption vs production sensors Change: - Document aggregate schedule computation pattern - Add commodity_to_devices mapping to scheduler knowledge - Document sign convention handling for aggregate fields - Document integration point in scheduler flow - Add backwards compatibility handling pattern Co-authored-by: Flix6x <30658763+Flix6x@users.noreply.github.com>
Signed-off-by: Ahmad-Wahid <ahmedwahid16101@gmail.com>
Signed-off-by: Ahmad-Wahid <ahmedwahid16101@gmail.com>
Signed-off-by: Ahmad-Wahid <ahmedwahid16101@gmail.com>
Flix6x
commented
Jun 17, 2026
Co-authored-by: Felix Claessen <30658763+Flix6x@users.noreply.github.com> Signed-off-by: Ahmad Wahid <59763365+Ahmad-Wahid@users.noreply.github.com>
Signed-off-by: Ahmad-Wahid <ahmedwahid16101@gmail.com>
Flix6x
commented
Jun 30, 2026
Co-authored-by: Felix Claessen <30658763+Flix6x@users.noreply.github.com> Signed-off-by: Felix Claessen <30658763+Flix6x@users.noreply.github.com>
Signed-off-by: F.N. Claessen <claessen@seita.nl>
… flex-context fields - Add test_asset_trigger_and_get_aggregate_schedule to verify aggregate sensors get populated (currently xfail as StorageScheduler doesn't yet populate them) - Add test_asset_trigger_with_multi_commodity_flex_context to verify aggregate sensors work with multi-commodity flex-context format (list of commodity dicts) - Document that aggregate sensor population is missing logic in StorageScheduler - Both tests verify the infrastructure and schema support works correctly
…ption and aggregate-production sensors Signed-off-by: F.N. Claessen <claessen@seita.nl>
_compute_commodity_aggregate_schedules only added the top-level inflexible devices to the electricity commodity, so a commodity's own inflexible demand (e.g. a heat load) was excluded from its aggregate-consumption schedule. The aggregate then reflected only that commodity's flexible devices. Mirror the device enumeration used in _prepare so each commodity context's inflexible-device-sensors are appended to that commodity at the matching ems_schedule indices.
- Remove xfail markers from both tests now that StorageScheduler populates aggregate sensors - Update test docstrings to reflect actual functionality - Tests now verify that aggregate-consumption and aggregate-production sensors receive data - First test covers single aggregate pair with dual devices - Second test covers aggregates with multiple devices scheduling together
…flex-context Signed-off-by: F.N. Claessen <claessen@seita.nl>
Signed-off-by: F.N. Claessen <claessen@seita.nl>
Signed-off-by: F.N. Claessen <claessen@seita.nl>
Signed-off-by: F.N. Claessen <claessen@seita.nl>
When a multi-commodity flex_context includes a commodity (e.g., heat) but no devices exist for that commodity, the sum() of an empty list returns integer 0 instead of a pandas Series. This caused AttributeError when calling .round() on the result later in compute(). Fixed by checking if any devices contribute to the commodity before attempting to aggregate. If no devices exist for a commodity, skip creating an aggregate schedule for it. Signed-off-by: F.N. Claessen <claessen@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
aggregate-consumptionandaggregate-productionare the per-commodity replacements ofaggregate-powerdocumentation/changelog.rstLook & Feel
...
How to test
Further Improvements
Internally, list-like flex-contexts remain nested under the
commoditiesfield in the regular dict-like flex-context. I tried for some time to deal with list-like flex-contexts throughout the codebase, but there were numerous complications, including but not limit to dealing with sequential scheduling, in which a sequence of dependent scheduling jobs are set up, where the inflexible-device-sensors (in the flex-context) of the next job includes the power sensors of the previous jobs.Related Items
Merges into #2172.