Skip to content

Commit 2ab7616

Browse files
committed
Integrate new ShiftingMatryoshka algorithm into the PowerManager
Signed-off-by: Sahas Subramanian <[email protected]>
1 parent a2898eb commit 2ab7616

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

src/frequenz/sdk/microgrid/_power_managing/_power_managing_actor.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import logging
1010
import sys
1111
from datetime import datetime, timedelta, timezone
12+
from typing import assert_never
1213

1314
from frequenz.channels import Receiver, Sender, select, selected_from
1415
from frequenz.channels.timer import SkipMissedAndDrift, Timer
@@ -22,6 +23,7 @@
2223
from .. import _data_pipeline, _power_distributing
2324
from ._base_classes import Algorithm, BaseAlgorithm, Proposal, ReportRequest, _Report
2425
from ._matryoshka import Matryoshka
26+
from ._shifting_matryoshka import ShiftingMatryoshka
2527

2628
_logger = logging.getLogger(__name__)
2729

@@ -63,15 +65,7 @@ def __init__( # pylint: disable=too-many-arguments
6365
`None` when the component category is enough to uniquely identify the
6466
component.
6567
algorithm: The power management algorithm to use.
66-
67-
Raises:
68-
NotImplementedError: When an unknown algorithm is given.
6968
"""
70-
if algorithm is not Algorithm.MATRYOSHKA:
71-
raise NotImplementedError(
72-
f"PowerManagingActor: Unknown algorithm: {algorithm}"
73-
)
74-
7569
self._component_category = component_category
7670
self._component_type = component_type
7771
self._bounds_subscription_receiver = bounds_subscription_receiver
@@ -84,9 +78,17 @@ def __init__( # pylint: disable=too-many-arguments
8478
self._bound_tracker_tasks: dict[frozenset[int], asyncio.Task[None]] = {}
8579
self._subscriptions: dict[frozenset[int], dict[int, Sender[_Report]]] = {}
8680

87-
self._algorithm: BaseAlgorithm = Matryoshka(
88-
max_proposal_age=timedelta(seconds=60.0)
89-
)
81+
match algorithm:
82+
case Algorithm.MATRYOSHKA:
83+
self._algorithm: BaseAlgorithm = Matryoshka(
84+
max_proposal_age=timedelta(seconds=60.0)
85+
)
86+
case Algorithm.SHIFTING_MATRYOSHKA:
87+
self._algorithm = ShiftingMatryoshka(
88+
max_proposal_age=timedelta(seconds=60.0)
89+
)
90+
case _:
91+
assert_never(algorithm)
9092

9193
super().__init__()
9294

0 commit comments

Comments
 (0)