Skip to content

Feat: make flex-config more explicit about production vs consumption (#2041)#2156

Draft
Copilot wants to merge 6 commits into
mainfrom
copilot/update-documentation-and-tutorials
Draft

Feat: make flex-config more explicit about production vs consumption (#2041)#2156
Copilot wants to merge 6 commits into
mainfrom
copilot/update-documentation-and-tutorials

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 8, 2026

  • Core schema changes: add inflexible-loads and inflexible-generators to FlexContextSchema (deprecate inflexible-device-sensors)
  • Core schema changes: add consumption and production to MultiSensorFlexModelSchema (deprecate sensor key)
  • Metadata entries for new fields
  • StorageScheduler: handle new inflexible-loads/generators with correct sign conventions
  • Scheduling service: handle consumption/production notation in flex-model
  • Database migration for stored flex-context and flex-model data
  • API backward compatibility: UserWarning for deprecated fields
  • API changelog entry
  • Test coverage for all new fields (schema-level and unit tests)
  • Tutorial documentation updates (toy-example-expanded.rst, toy-example-multiasset-curtailment.rst)
  • Tutorial scripts updates (run-tutorial2-in-docker.sh, run-tutorial3-in-docker.sh)
  • Scheduling feature docs update (inflexible-loads/generators in flex-context table)
  • Data-model docs expanded with sign convention example
  • Main changelog entry with correct PR Feat: make flex-config more explicit about production vs consumption (#2041) #2156
  • PR Feat: make flex-config more explicit about production vs consumption (#2041) #2156 created
  • flexmeasures-client PR (not started due to time constraints)

Copilot AI and others added 6 commits May 8, 2026 18:57
…2041)

CHANGE 1 - flex-context: inflexible-device-sensors → inflexible-loads / inflexible-generators
- Add inflexible-loads (consumption-positive) and inflexible-generators (production-positive)
  fields to FlexContextSchema
- Deprecate inflexible-device-sensors with warnings.warn on load
- Update DBFlexContextSchema validation to validate all three lists
- Add entries for new fields to UI_FLEX_CONTEXT_SCHEMA
- Add consumption_is_positive parameter to get_power_values() in utils.py
- Update MetaStorageScheduler._prepare() to build combined all_inflexible list with
  explicit sign conventions per field type

CHANGE 2 - flex-model: sensor → consumption / production
- Expand MultiSensorFlexModelSchema with consumption, production, is_consumption_sensor fields
- unwrap_envelope maps consumption/production → sensor and sets is_consumption_sensor
- Preserve is_consumption_sensor through StorageScheduler.deserialize_flex_config()
- Include is_consumption_sensor in result dicts from both StorageScheduler.schedule()
  and StorageFallbackScheduler.compute()
- Extract is_consumption_sensor in create_sequential_scheduling_jobs and pass to
  create_scheduling_job as scheduler_kwargs
- Add is_consumption_sensor param to make_schedule(); use it in sign logic with fallback
  to sensor attribute

CHANGE 3 - database migration
- Add Alembic migration 9ed0e39b0447 that upgrades existing flex_context and flex_model
  JSON columns on generic_asset:
  - inflexible-device-sensors → inflexible-loads or inflexible-generators based on
    each sensor's consumption_is_positive attribute (defaults to False → generators)
  - flex_model[].sensor → consumption or production based on same attribute
  - downgrade reverses both transforms

Co-authored-by: Flix6x <30658763+Flix6x@users.noreply.github.com>
…sumption PR

- Clarify deprecation warning: note production-positive is the FlexMeasures default
- Extract _build_is_consumption_sensor_map() helper on MetaStorageScheduler to avoid
  duplication between StorageFallbackScheduler.compute() and StorageScheduler.schedule()
- Rename confusing variable result_consumption_is_positive → consumption_is_positive
  in make_schedule() sign logic
- Add mutual-exclusion validation in unwrap_envelope: raise ValidationError when both
  'consumption' and 'production' are specified in the same flex-model entry

Co-authored-by: Flix6x <30658763+Flix6x@users.noreply.github.com>
…le in production)

DeprecationWarning is silenced by default in Python for non-__main__ code,
meaning it would be invisible to API users in production Flask deployments.

Change to UserWarning which is always visible, following the existing
pattern in api/dev/sensors.py which uses FutureWarning for the same reason.

Co-authored-by: Flix6x <30658763+Flix6x@users.noreply.github.com>
- warn on inflexible-device-sensors presence (not just non-empty),
  since the field itself is deprecated regardless of its value
- improve docstring for warn_deprecated_sensor_field to clarify
  that is_consumption_sensor is an internal marker set by @pre_load
- improve unwrap_envelope docstring to mention is_consumption_sensor

Co-authored-by: Flix6x <30658763+Flix6x@users.noreply.github.com>
…ction fields

Co-authored-by: Flix6x <30658763+Flix6x@users.noreply.github.com>
…n/consumption flex-model keys

Co-authored-by: Flix6x <30658763+Flix6x@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make flex-config more explicit about production vs consumption

2 participants