Skip to content

Feature: flex-context per commodity as list#2235

Draft
Flix6x wants to merge 37 commits into
dev/split-flexcontext-by-commodityfrom
dev/flex-context-as-list
Draft

Feature: flex-context per commodity as list#2235
Flix6x wants to merge 37 commits into
dev/split-flexcontext-by-commodityfrom
dev/flex-context-as-list

Conversation

@Flix6x

@Flix6x Flix6x commented Jun 12, 2026

Copy link
Copy Markdown
Member

Description

  • The flex-context is now preferred to be defined as a list, with one entry per commodity
  • The new fields aggregate-consumption and aggregate-production are the per-commodity replacements of aggregate-power
  • Added changelog item in documentation/changelog.rst

Look & Feel

...

How to test

...

Further Improvements

...

Related Items

...

Flix6x added 6 commits June 12, 2026 14:23
…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
@Flix6x Flix6x self-assigned this Jun 12, 2026
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>
Copilot AI and others added 8 commits June 12, 2026 20:43
- 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>
@Flix6x Flix6x changed the base branch from main to dev/split-flexcontext-by-commodity June 12, 2026 20:36
Flix6x added 2 commits June 12, 2026 22:49
Signed-off-by: F.N. Claessen <claessen@seita.nl>
Signed-off-by: F.N. Claessen <claessen@seita.nl>
@pytest.mark.parametrize(
["flex_context", "fails"],
[
# Test aggregate-consumption field with sensor reference

@Flix6x Flix6x Jun 12, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These test cases are very weak still. They either under-specify or falsely claim what result/behaviour they actually test.

Also, we should verify that the aggregate-consumption/production sensors actually get filled with data, with the correct sign convention and with the expected data source type. I don't think they are, which points to missing logic in the StorageScheduler, where the aggregate power flows get computed from ems_schedule. This should be done per commodity, and ensuring backwards compatibility (in case flex-context has no commodity_contexts, all devices are electric).

Comment thread flexmeasures/data/schemas/tests/test_scheduling.py Outdated
Comment thread flexmeasures/data/schemas/tests/test_scheduling.py Outdated
Comment thread flexmeasures/data/schemas/tests/test_scheduling.py Outdated
Comment thread flexmeasures/data/schemas/tests/test_scheduling.py Outdated
Comment thread flexmeasures/data/schemas/tests/test_scheduling.py Outdated
Comment thread flexmeasures/ui/tests/test_utils.py Outdated
@Flix6x Flix6x requested a review from Ahmad-Wahid June 12, 2026 23:30
Flix6x added 7 commits June 13, 2026 11:05
…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>
Flix6x and others added 8 commits June 13, 2026 11:46
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>
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>
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>
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>
Comment thread flexmeasures/ui/static/openapi-specs.json Outdated
Ahmad-Wahid and others added 2 commits June 17, 2026 19:14
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>
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.

3 participants