-
Notifications
You must be signed in to change notification settings - Fork 49
Feat: Return inflexible device schedules from StorageScheduler #1994
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
Draft
Ahmad-Wahid
wants to merge
9
commits into
main
Choose a base branch
from
feat/multi-asset-scheduling
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
f080655
fix: drop a dictionary from flexmodel that has no sensor
Ahmad-Wahid 56d9a96
feat: return inflexible device sensors data along with schedules
Ahmad-Wahid c122cc0
Merge branch 'main' into feat/multi-asset-scheduling
Ahmad-Wahid 54b79b8
fix: support a single flex model which is not in a list
Ahmad-Wahid 25a3815
fix: unpack all available returns
Ahmad-Wahid cf56642
fix: unpack all available returns for all cases
Ahmad-Wahid a8ab9ea
Merge remote-tracking branch 'origin/main' into feat/multi-asset-sche…
Ahmad-Wahid 19d287c
Merge remote-tracking branch 'origin/main' into feat/multi-asset-sche…
Ahmad-Wahid 5e92a82
Merge remote-tracking branch 'origin/main' into feat/multi-asset-sche…
Ahmad-Wahid File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -90,6 +90,12 @@ def _prepare(self, skip_validation: bool = False) -> tuple: # noqa: C901 | |
| if not self.config_deserialized: | ||
| self.deserialize_config() | ||
|
|
||
| # todo: look for the reason why flex_model has an object(dict) without a sensor, and fix the root cause if possible, instead of filtering it out here | ||
| if isinstance(self.flex_model, list): | ||
| self.flex_model = [ | ||
| model for model in self.flex_model if model["sensor"] is not None | ||
| ] | ||
|
|
||
| start = self.start | ||
| end = self.end | ||
| resolution = self.resolution | ||
|
|
@@ -934,6 +940,7 @@ def _prepare(self, skip_validation: bool = False) -> tuple: # noqa: C901 | |
| device_constraints, | ||
| ems_constraints, | ||
| commitments, | ||
| inflexible_device_sensors, | ||
| ) | ||
|
|
||
| def convert_to_commitments( | ||
|
|
@@ -1452,6 +1459,7 @@ def compute(self, skip_validation: bool = False) -> SchedulerOutputType: | |
| device_constraints, | ||
| ems_constraints, | ||
| commitments, | ||
| inflexible_device_sensors, | ||
| ) = self._prepare(skip_validation=skip_validation) | ||
|
|
||
| # Fallback policy if the problem was unsolvable | ||
|
|
@@ -1578,6 +1586,7 @@ def compute(self, skip_validation: bool = False) -> SchedulerOutputType: | |
| device_constraints, | ||
| ems_constraints, | ||
| commitments, | ||
| inflexible_device_sensors, | ||
| ) = self._prepare(skip_validation=skip_validation) | ||
|
|
||
| ems_schedule, expected_costs, scheduler_results, model = device_scheduler( | ||
|
|
@@ -1605,6 +1614,16 @@ def compute(self, skip_validation: bool = False) -> SchedulerOutputType: | |
| elif sensor is not None and sensor in storage_schedule: | ||
| storage_schedule[sensor] += ems_schedule[d] | ||
|
|
||
| # Obtain the inflexible device schedules | ||
| num_flexible_devices = len(sensors) | ||
| inflexible_schedules = dict() | ||
| for i, inflexible_sensor in enumerate(inflexible_device_sensors): | ||
| device_index = num_flexible_devices + i | ||
| if inflexible_sensor not in inflexible_schedules: | ||
| inflexible_schedules[inflexible_sensor] = ems_schedule[device_index] | ||
| else: | ||
| inflexible_schedules[inflexible_sensor] += ems_schedule[device_index] | ||
|
|
||
| # Obtain the aggregate power schedule, too, if the flex-context states the associated sensor. Fill with the sum of schedules made here. | ||
| aggregate_power_sensor = self.flex_context.get("aggregate_power", None) | ||
| if isinstance(aggregate_power_sensor, Sensor): | ||
|
|
@@ -1624,6 +1643,18 @@ def compute(self, skip_validation: bool = False) -> SchedulerOutputType: | |
| if sensor is not None | ||
| } | ||
|
|
||
| # Convert each inflexible device schedule to the unit of the device's power sensor | ||
| inflexible_schedules = { | ||
| sensor: convert_units( | ||
| inflexible_schedules[sensor], | ||
| "MW", | ||
| sensor.unit, | ||
| event_resolution=sensor.event_resolution, | ||
| ) | ||
| for sensor in inflexible_schedules.keys() | ||
| if sensor is not None | ||
| } | ||
|
|
||
| flex_model = self.flex_model.copy() | ||
|
|
||
| if not isinstance(self.flex_model, list): | ||
|
|
@@ -1643,6 +1674,13 @@ def compute(self, skip_validation: bool = False) -> SchedulerOutputType: | |
| for sensor in storage_schedule.keys() | ||
| if sensor is not None | ||
| } | ||
| inflexible_schedules = { | ||
| sensor: inflexible_schedules[sensor] | ||
| .resample(sensor.event_resolution) | ||
| .mean() | ||
| for sensor in inflexible_schedules.keys() | ||
| if sensor is not None | ||
| } | ||
|
|
||
| # Round schedule | ||
| if self.round_to_decimals: | ||
|
|
@@ -1651,6 +1689,11 @@ def compute(self, skip_validation: bool = False) -> SchedulerOutputType: | |
| for sensor in storage_schedule.keys() | ||
| if sensor is not None | ||
| } | ||
| inflexible_schedules = { | ||
| sensor: inflexible_schedules[sensor].round(self.round_to_decimals) | ||
| for sensor in inflexible_schedules.keys() | ||
| if sensor is not None | ||
| } | ||
| soc_schedule = { | ||
| sensor: soc_schedule[sensor].round(self.round_to_decimals) | ||
| for sensor in soc_schedule.keys() | ||
|
|
@@ -1667,6 +1710,16 @@ def compute(self, skip_validation: bool = False) -> SchedulerOutputType: | |
| for sensor in storage_schedule.keys() | ||
| if sensor is not None | ||
| ] | ||
| inflexible_device_schedules = [ | ||
| { | ||
| "name": "inflexible_device_schedule", | ||
| "sensor": sensor, | ||
| "data": inflexible_schedules[sensor], | ||
| "unit": sensor.unit, | ||
| } | ||
| for sensor in inflexible_schedules.keys() | ||
| if sensor is not None | ||
| ] | ||
|
Comment on lines
+1713
to
+1722
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This also means |
||
| commitment_costs = [ | ||
| { | ||
| "name": "commitment_costs", | ||
|
|
@@ -1688,7 +1741,12 @@ def compute(self, skip_validation: bool = False) -> SchedulerOutputType: | |
| } | ||
| for sensor, soc in soc_schedule.items() | ||
| ] | ||
| return storage_schedules + commitment_costs + soc_schedules | ||
| return ( | ||
| storage_schedules | ||
| + inflexible_device_schedules | ||
| + commitment_costs | ||
| + soc_schedules | ||
| ) | ||
| else: | ||
| return storage_schedule[sensors[0]] | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know why this can happen. It happens when the db flex model of an asset is picked up when its parent asset is being scheduled. That means some devices are included in the optimization with only an asset ID known, and the power sensor ID to save the results is not guaranteed to be known.
Let's discuss what that means for this PR.