Skip to content

Commit ff00d27

Browse files
committed
Ignore unknown battery bucket in the absence of system bounds
If a proposal arrives for a previously unknown battery bucket, and there are no system bounds available for the bucket, then ignore the proposal. This commit also improves the code comments for the case where a previous target power already exists for a given battery bucket, because in that case, we bring the target power down to zero. Signed-off-by: Sahas Subramanian <[email protected]>
1 parent b6137dd commit ff00d27

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

src/frequenz/sdk/actor/_power_managing/_matryoshka.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
from __future__ import annotations
77

8+
import logging
89
import typing
910

1011
from typing_extensions import override
@@ -16,6 +17,8 @@
1617
if typing.TYPE_CHECKING:
1718
from ...timeseries.battery_pool import PowerMetrics
1819

20+
_logger = logging.getLogger(__name__)
21+
1922

2023
class Matryoshka(BaseAlgorithm):
2124
"""The matryoshka algorithm."""
@@ -49,6 +52,21 @@ def get_target_power(
4952
already part of another bucket.
5053
"""
5154
if battery_ids not in self._battery_buckets:
55+
# if there are no previous proposals and there are no system bounds, then
56+
# don't calculate a target power and just return `None`.
57+
if (
58+
system_bounds.inclusion_bounds is None
59+
and system_bounds.exclusion_bounds is None
60+
):
61+
if proposal is not None:
62+
_logger.warning(
63+
"PowerManagingActor: No system bounds available for battery "
64+
"IDs %s, but a proposal was given. The proposal will be "
65+
"ignored.",
66+
battery_ids,
67+
)
68+
return None
69+
5270
for bucket in self._battery_buckets:
5371
if any(battery_id in bucket for battery_id in battery_ids):
5472
raise NotImplementedError(
@@ -68,7 +86,10 @@ def get_target_power(
6886
lower_bound = (
6987
system_bounds.inclusion_bounds.lower
7088
if system_bounds.inclusion_bounds
71-
else Power.zero() # in the absence of system bounds, block all requests.
89+
# if a target power exists from a previous proposal, and the system bounds
90+
# have become unavailable, force the target power to be zero, by narrowing
91+
# the bounds to zero.
92+
else Power.zero()
7293
)
7394
upper_bound = (
7495
system_bounds.inclusion_bounds.upper

0 commit comments

Comments
 (0)