Skip to content

Feat/offtick soc projection#2194

Open
BelhsanHmida wants to merge 58 commits into
mainfrom
feat/offtick-soc-normalization
Open

Feat/offtick soc projection#2194
BelhsanHmida wants to merge 58 commits into
mainfrom
feat/offtick-soc-normalization

Conversation

@BelhsanHmida
Copy link
Copy Markdown
Contributor

@BelhsanHmida BelhsanHmida commented May 22, 2026

Description

  • Project off-tick storage SoC constraints onto the scheduling ticks using charge/discharge capacity, instead of blindly flooring timed soc-targets, soc-minima, and soc-maxima.
  • [x]Preserve original SoC event times during storage flex-model schema deserialization so scheduler logic can interpret the user’s intent.
  • Automatically enable relax-soc-constraints when off-tick SoC constraints are submitted, so generated/adjusted constraints can be softened safely.
  • Added tests for off-tick SoC target projection and automatic SoC constraint relaxation.
  • add changelog entry.

How to test

pytest flexmeasures/api/v3_0/tests/test_sensor_schedules.py flexmeasures/data/schemas/tests/test_scheduling.py flexmeasures/data/models/planning/tests/test_storage.py -q

Manual test:

  • Trigger a storage schedule with a 15-minute resolution and an off-tick soc-target, e.g. 17:12.
  • Use 0.04 MW charging capacity and target 1 MWh.
  • Verify the scheduler does not floor the target to 17:00, but projects it onto the scheduling ticks as an adjusted previous-tick bound and a next-tick target.
  • Verify off-tick SoC constraints enable relax-soc-constraints.

Projection policy

The scheduler can enforce SoC constraints only on its scheduling ticks. For point-like off-tick SoC events:

  • soc-targets are projected to an exact target on the next scheduling tick, with capacity-adjusted lower and upper bounds on the previous tick.
  • soc-minima are projected as lower bounds on the surrounding ticks, adjusted by reachable charge/discharge capacity.
  • soc-maxima are projected as upper bounds on the surrounding ticks, adjusted by reachable charge/discharge capacity.
  • If multiple projected lower bounds land on the same tick, the stricter lower bound is kept.
  • If multiple projected upper bounds land on the same tick, the stricter upper bound is kept.

Related Items

Follow-up to PR #2146 review discussion around off-tick storage SoC constraints.

Sign-off

  • I agree to license my contributions under the project’s license.
  • I signed off my commits.

Flix6x and others added 30 commits November 21, 2025 15:41
…ataFrames

Signed-off-by: F.N. Claessen <felix@seita.nl>
Signed-off-by: F.N. Claessen <felix@seita.nl>
Signed-off-by: F.N. Claessen <felix@seita.nl>
Signed-off-by: F.N. Claessen <felix@seita.nl>
Signed-off-by: F.N. Claessen <felix@seita.nl>
Signed-off-by: F.N. Claessen <felix@seita.nl>
# Conflicts:
#	flexmeasures/api/common/schemas/sensor_data.py
Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
…nt-start

Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>

# Conflicts:
#	flexmeasures/api/v3_0/tests/test_sensor_schedules.py
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Mohamed Belhsan Hmida <149331360+BelhsanHmida@users.noreply.github.com>
Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Signed-off-by: F.N. Claessen <claessen@seita.nl>
…dule_floors_flex_model_datetimes

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: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Signed-off-by: Mohamed Belhsan Hmida <149331360+BelhsanHmida@users.noreply.github.com>
…nt-start

Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>

# Conflicts:
#	flexmeasures/api/common/schemas/sensor_data.py
#	flexmeasures/api/v3_0/tests/test_sensor_data.py
#	flexmeasures/data/schemas/sensors.py
Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates storage scheduling to preserve user-provided (off-tick) SoC constraint timings during flex-model deserialization, and then projects those constraints onto the scheduler’s time grid using charge/discharge capacity so they remain enforceable. It also auto-enables SoC constraint relaxation when off-tick constraints are present, and adds tests for off-tick target projection + auto-relax behavior.

Changes:

  • Stop flooring SoC event datetimes during storage flex-model schema deserialization (preserve original event times).
  • Normalize/project off-tick SoC constraints onto the scheduling grid inside the storage scheduler using capacity-derived bounds.
  • Auto-enable relax-soc-constraints when off-tick SoC constraints are detected; add regression tests for target projection and auto-relax.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
flexmeasures/data/schemas/scheduling/storage.py Removes schema-level datetime flooring for soc-targets/soc-minima/soc-maxima so original timings are preserved.
flexmeasures/data/models/planning/storage.py Adds detection of off-tick SoC constraints, enables relaxation automatically, and normalizes/project off-tick constraints onto the scheduling grid during _prepare.
flexmeasures/data/models/planning/tests/test_storage.py Adds tests for off-tick SoC target projection and automatic enabling of SoC constraint relaxation.
Comments suppressed due to low confidence (1)

flexmeasures/data/models/planning/storage.py:1125

  • For multi-device scheduling (self.flex_model is a list), off-tick SoC events are checked against self.resolution only. When resolution is omitted, _prepare later derives it (or falls back) based on the sensors’ event resolutions, but this early check returns False with resolution=None, so relax-soc-constraints won’t be auto-enabled even though off-tick events will be projected later. Consider deriving a resolution here in the same way _prepare does (minimum non-zero sensor resolution, with default fallback) before calling flex_model_has_off_tick_soc_constraints.
        if isinstance(self.flex_model, list):
            return any(
                flex_model_has_off_tick_soc_constraints(
                    flex_model, resolution=self.resolution
                )
                for flex_model in self.flex_model
            )

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread flexmeasures/data/models/planning/storage.py Outdated
Comment thread flexmeasures/data/models/planning/tests/test_storage.py Outdated
BelhsanHmida and others added 10 commits May 22, 2026 13:51
Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Co-authored-by: Felix Claessen <30658763+Flix6x@users.noreply.github.com>
Signed-off-by: Mohamed Belhsan Hmida <149331360+BelhsanHmida@users.noreply.github.com>
Co-authored-by: Felix Claessen <30658763+Flix6x@users.noreply.github.com>
Signed-off-by: Mohamed Belhsan Hmida <149331360+BelhsanHmida@users.noreply.github.com>
…nto feat/offtick-soc-normalization

Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>

# Conflicts:
#	flexmeasures/data/schemas/scheduling/storage.py
@BelhsanHmida BelhsanHmida requested a review from Flix6x May 29, 2026 00:38
Base automatically changed from mohamed/dev/floor-event-start to main June 1, 2026 18:01
…alization

Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>

# Conflicts:
#	flexmeasures/data/schemas/tests/test_scheduling.py
#	flexmeasures/data/schemas/tests/test_sensor.py
Copy link
Copy Markdown
Member

@Flix6x Flix6x left a comment

Choose a reason for hiding this comment

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

Thanks for this. I still need to check the tests and the actual projection policy, but I'd like to hold that off until it's more documented.

Comment thread documentation/changelog.rst Outdated
Comment thread flexmeasures/data/models/planning/tests/test_storage.py Outdated
Comment thread flexmeasures/data/models/planning/tests/test_storage.py Outdated
Comment thread flexmeasures/data/models/planning/storage.py Outdated
Comment thread flexmeasures/data/models/planning/storage.py Outdated
Comment thread flexmeasures/data/models/planning/storage.py Outdated
Comment thread flexmeasures/data/models/planning/storage.py Outdated
Comment thread flexmeasures/data/models/planning/storage.py Outdated
Comment thread flexmeasures/data/models/planning/tests/test_storage.py Outdated
Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
@BelhsanHmida BelhsanHmida changed the title Feat/offtick soc normalization Feat/offtick soc projection Jun 5, 2026
BelhsanHmida and others added 7 commits June 5, 2026 04:15
Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Co-authored-by: Felix Claessen <30658763+Flix6x@users.noreply.github.com>
Signed-off-by: Mohamed Belhsan Hmida <149331360+BelhsanHmida@users.noreply.github.com>
Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
@BelhsanHmida BelhsanHmida requested a review from Flix6x June 5, 2026 13:36
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.

4 participants