Skip to content

Feat/offtick soc normalization#2194

Open
BelhsanHmida wants to merge 11 commits into
mohamed/dev/floor-event-startfrom
feat/offtick-soc-normalization
Open

Feat/offtick soc normalization#2194
BelhsanHmida wants to merge 11 commits into
mohamed/dev/floor-event-startfrom
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 scheduler grid using charge/discharge capacity, instead of blindly flooring timed soc-targets, soc-minima, and soc-maxima.
  • 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.

Look & Feel

N/A

How to test

.venv/bin/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
PATH="$PWD/.venv/bin:$PATH" .venv/bin/pre-commit run --all-files

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 grid as an adjusted previous-tick bound and a next-tick target.
  • Verify off-tick SoC constraints enable relax-soc-constraints.

Further Improvements

  • Extend coverage for more complex off-tick combinations, such as time-varying charge/discharge capacities and mixed soc-minima / soc-maxima / soc-targets.

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.

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>
@BelhsanHmida BelhsanHmida self-assigned this May 22, 2026
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
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>
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.

2 participants