Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor scheduler interface - API and inner logic #537

Merged
merged 44 commits into from Dec 29, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
274ca78
Add flex_model & flex_context in API endpoint; refactor design for Sc…
nhoening Nov 23, 2022
814ad4a
add new schema modules
nhoening Nov 23, 2022
59419e2
Merge branch 'main' into refactor-scheduler-interface
nhoening Nov 23, 2022
0cb4928
include two other flex context params in solver test
nhoening Nov 23, 2022
610ab2a
Merge branch 'main' into refactor-scheduler-interface
nhoening Dec 10, 2022
2f77285
also support deprecated flex_context parameters, and align spelling o…
nhoening Dec 10, 2022
6042cd5
correctly handle flex-model validation errors when they come up in th…
nhoening Dec 10, 2022
d3911a1
merge
nhoening Dec 10, 2022
c0cc2ce
changelog: add deprecation warnings and mentions this PR
nhoening Dec 12, 2022
7d6abb7
fix internal link
nhoening Dec 12, 2022
140e5be
move flex-model and flex-context docs to notation module; small fixes…
nhoening Dec 12, 2022
af00092
deprecate soc-sensor-id field, store soc states on the asset attribut…
nhoening Dec 13, 2022
b87de99
check (and potentially fill in defaults for) soc_min and soc_max befo…
nhoening Dec 13, 2022
6ac5a76
make add schedule command work with our refactored scheduling code, s…
nhoening Dec 13, 2022
f3cf7a2
rename the CLI command as it only represents storage right now (and w…
nhoening Dec 13, 2022
8bb30f9
More thorough checks for passed soc-values in StorageScheduler, leads…
nhoening Dec 14, 2022
11633f8
doc improvements from review
nhoening Dec 14, 2022
b784c56
Change parameter names for flex model and context which come through …
nhoening Dec 16, 2022
7321019
Make `flexmeasures add schedule` a subgroup (#557)
Flix6x Dec 16, 2022
4bf8e55
add one missing documentation improvement from review
nhoening Dec 16, 2022
7231c18
make sure hyphens are used in flex-model to the outside world (API, CLI)
nhoening Dec 21, 2022
f667106
smaller review items, mostly documentation
nhoening Dec 21, 2022
e06e235
remove soc checks which added interpretation (should be part of anoth…
nhoening Dec 25, 2022
403660c
fixes to notation docs
nhoening Dec 25, 2022
0da3b30
make sure scheduling tests work on empty queues, with new fixture
nhoening Dec 25, 2022
20de523
remove two tests for previously removed util function
nhoening Dec 25, 2022
c9bc738
batch of small review comments
nhoening Dec 25, 2022
4965575
make get_data_source_info a class method of Scheduler
nhoening Dec 25, 2022
fcbfad9
small simplification of get_data_source_for_job
nhoening Dec 25, 2022
d562bf1
Merge branch 'main' into refactor-scheduler-interface
nhoening Dec 25, 2022
1b8ded8
specify min/max inclusiveness of roundtrip-efficiency parameter
nhoening Dec 25, 2022
f1bc3cb
Merge branch 'refactor-scheduler-interface' of github.com:FlexMeasure…
nhoening Dec 25, 2022
a32b819
create_scheduling_jobs accepts both object and ID
nhoening Dec 27, 2022
07a21a3
fix type hinting
nhoening Dec 27, 2022
0ef19fa
API changelog & flex config introduction
nhoening Dec 27, 2022
480fac9
two missing fixes
nhoening Dec 27, 2022
658f8b5
remove line about previously undocumented & now depreacated line
nhoening Dec 27, 2022
b053994
Deprecation headers for old fields that moved to flex-model and flex-…
Flix6x Dec 27, 2022
c2b7ffa
refactor where the code lives that builds device equality constraints…
nhoening Dec 28, 2022
39b82d7
change a sentence in notation
nhoening Dec 28, 2022
6b26a32
Rename inspection to deserialization
Flix6x Dec 29, 2022
c8bd10a
Fix DummyScheduler in documentation
Flix6x Dec 29, 2022
9ad7c3d
Simplify imports for plugin developers (also facilitates renaming the…
Flix6x Dec 29, 2022
37b56f0
Resolve circular import
Flix6x Dec 29, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 18 additions & 0 deletions documentation/api/change_log.rst
Expand Up @@ -5,6 +5,24 @@ API change log

.. note:: The FlexMeasures API follows its own versioning scheme. This is also reflected in the URL, allowing developers to upgrade at their own pace.

v3.0-5 | 2022-12-30
"""""""""""""""""""

- Introduced ``flex-model`` and ``flex-context`` fields to `/sensors/<id>/schedules/trigger` (POST). They are dictionaries and group pre-existing fields:

- ``soc-at-start`` -> send in ``flex-model`` instead
- ``soc-min`` -> send in ``flex-model`` instead
- ``soc-max`` -> send in ``flex-model`` instead
- ``soc-unit`` -> send in ``flex-model`` instead
- ``roundtrip-efficiency`` -> send in ``flex-model`` instead
- ``prefer-charging-sooner`` -> send in ``flex-model`` instead
- ``consumption-price-sensor`` -> send in ``flex-context`` instead
- ``production-price-sensor`` -> send in ``flex-context`` instead
- ``inflexible-device-sensors`` -> send in ``flex-context`` instead

- The field ``doc-sensor-id`` in `/sensors/<id>/schedules/trigger` (POST) has been deprecated.
nhoening marked this conversation as resolved.
Show resolved Hide resolved


v3.0-4 | 2022-12-08
"""""""""""""""""""

Expand Down
9 changes: 6 additions & 3 deletions documentation/api/notation.rst
Expand Up @@ -163,9 +163,12 @@ Describing flexibility
FlexMeasures computes schedules for energy systems that consist of multiple devices that consume and/or produce electricity.
We model a device as an asset with a power sensor, and compute schedules only for flexible devices, while taking into account inflexible devices.

To compute a schedule, FlexMeasures first needs to assess the flexibility available to the system.
For this it needs information about the state and possible actions of each device, as well as context information about the system as a whole, in order to assess the value of activating flexibility.
This information goes beyond the usual time series recorded by an asset's sensors.
To compute a schedule, FlexMeasures first needs to assess under what configuration flexibility can be made available to the system.
This is described by the `flex model` (information about the state and possible actions of the flexible device) and the `flex-context`
(information about the system as a whole, in order to assess the value of activating flexibility).

This information goes beyond the usual time series recorded by an asset's sensors. It's being sent through the API when triggering schedule computation.
Some parts of it can be persisted on the asset & sensor model as attributes (that's design work in progress).

We distinguish the information with two groups:

Expand Down
6 changes: 3 additions & 3 deletions flexmeasures/data/models/planning/storage.py
@@ -1,7 +1,7 @@
from __future__ import annotations

from datetime import datetime, timedelta
from typing import List, Union, Dict
from typing import List, Dict

import pandas as pd
import numpy as np
Expand All @@ -28,7 +28,7 @@ class StorageScheduler(Scheduler):

def compute_schedule(
self,
) -> Union[pd.Series, None]:
) -> pd.Series | None:
"""Schedule a battery or Charge Point based directly on the latest beliefs regarding market prices within the specified time window.
For the resulting consumption schedule, consumption is defined as positive values.
"""
Expand Down Expand Up @@ -259,7 +259,7 @@ def inspect_flex_config(self):

def get_min_max_targets(
self, deserialized_names: bool = True
) -> tuple[float | None]:
) -> tuple[float | None, float | None]:
min_target = None
max_target = None
soc_targets_label = "soc_targets" if deserialized_names else "soc-targets"
Expand Down
15 changes: 8 additions & 7 deletions flexmeasures/data/services/scheduling.py
@@ -1,5 +1,6 @@
from __future__ import annotations

from datetime import datetime, timedelta
from typing import Optional
import os
import sys
import importlib.util
Expand Down Expand Up @@ -29,8 +30,8 @@


def create_scheduling_job(
sensor: [int | Sensor],
job_id: Optional[str] = None,
sensor: int | Sensor,
job_id: str | None = None,
enqueue: bool = True,
**scheduler_kwargs,
) -> Job:
Expand Down Expand Up @@ -72,9 +73,9 @@ def make_schedule(
start: datetime,
end: datetime,
resolution: timedelta,
belief_time: Optional[datetime] = None,
flex_model: Optional[dict] = None,
flex_context: Optional[dict] = None,
belief_time: datetime | None = None,
flex_model: dict | None = None,
flex_context: dict | None = None,
) -> bool:
"""
This function is meant to be queued as a job. It returns True if it ran successfully.
Expand Down Expand Up @@ -238,7 +239,7 @@ def handle_scheduling_exception(job, exc_type, exc_value, traceback):
job.save_meta()


def get_data_source_for_job(job: Optional[Job]) -> Optional[DataSource]:
def get_data_source_for_job(job: Job | None) -> DataSource | None:
"""
Try to find the data source linked by this scheduling job.

Expand Down