Skip to content

Commit 5b087ab

Browse files
committed
Make battery power manager algorithm configurable
With this, `SHIFTING_MATRYOSHKA` remains the default algorithm for batteries, but can now be changed to the original `MATRYOSHKA` algorithm when calling `microgrid.initialize()`. Signed-off-by: Sahas Subramanian <[email protected]>
1 parent 3ea8c42 commit 5b087ab

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

src/frequenz/sdk/microgrid/__init__.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,13 +383,16 @@
383383
producer,
384384
voltage_per_phase,
385385
)
386+
from ._power_managing import PowerManagerAlgorithm
386387

387388

388389
async def initialize(
389390
server_url: str,
390391
resampler_config: ResamplerConfig,
391392
*,
392393
api_power_request_timeout: timedelta = timedelta(seconds=5.0),
394+
# pylint: disable-next: line-too-long
395+
battery_power_manager_algorithm: PowerManagerAlgorithm = PowerManagerAlgorithm.SHIFTING_MATRYOSHKA, # noqa: E501
393396
) -> None:
394397
"""Initialize the microgrid connection manager and the data pipeline.
395398
@@ -404,15 +407,19 @@ async def initialize(
404407
the microgrid API. When requests to components timeout, they will
405408
be marked as blocked for a short duration, during which time they
406409
will be unavailable from the corresponding component pools.
410+
battery_power_manager_algorithm: The power manager algorithm to use for
411+
batteries.
407412
"""
408413
await connection_manager.initialize(server_url)
409414
await _data_pipeline.initialize(
410415
resampler_config,
411416
api_power_request_timeout=api_power_request_timeout,
417+
battery_power_manager_algorithm=battery_power_manager_algorithm,
412418
)
413419

414420

415421
__all__ = [
422+
"PowerManagerAlgorithm",
416423
"initialize",
417424
"consumer",
418425
"grid",

src/frequenz/sdk/microgrid/_data_pipeline.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,16 @@ def __init__(
8383
self,
8484
resampler_config: ResamplerConfig,
8585
api_power_request_timeout: timedelta = timedelta(seconds=5.0),
86+
battery_power_manager_algorithm: PowerManagerAlgorithm = PowerManagerAlgorithm.SHIFTING_MATRYOSHKA, # noqa: E501
8687
) -> None:
8788
"""Create a `DataPipeline` instance.
8889
8990
Args:
9091
resampler_config: Config to pass on to the resampler.
9192
api_power_request_timeout: Timeout to use when making power requests to
9293
the microgrid API.
94+
battery_power_manager_algorithm: The power manager algorithm to use for
95+
batteries.
9396
"""
9497
self._resampler_config: ResamplerConfig = resampler_config
9598

@@ -103,7 +106,7 @@ def __init__(
103106
self._battery_power_wrapper = PowerWrapper(
104107
self._channel_registry,
105108
api_power_request_timeout=api_power_request_timeout,
106-
power_manager_algorithm=PowerManagerAlgorithm.SHIFTING_MATRYOSHKA,
109+
power_manager_algorithm=battery_power_manager_algorithm,
107110
default_power=DefaultPower.ZERO,
108111
component_class=Battery,
109112
)
@@ -514,6 +517,7 @@ async def _stop(self) -> None:
514517
async def initialize(
515518
resampler_config: ResamplerConfig,
516519
api_power_request_timeout: timedelta = timedelta(seconds=5.0),
520+
battery_power_manager_algorithm: PowerManagerAlgorithm = PowerManagerAlgorithm.SHIFTING_MATRYOSHKA, # noqa: E501
517521
) -> None:
518522
"""Initialize a `DataPipeline` instance.
519523
@@ -523,6 +527,8 @@ async def initialize(
523527
the microgrid API. When requests to components timeout, they will
524528
be marked as blocked for a short duration, during which time they
525529
will be unavailable from the corresponding component pools.
530+
battery_power_manager_algorithm: The power manager algorithm to use for
531+
batteries.
526532
527533
Raises:
528534
RuntimeError: if the DataPipeline is already initialized.
@@ -531,7 +537,9 @@ async def initialize(
531537

532538
if _DATA_PIPELINE is not None:
533539
raise RuntimeError("DataPipeline is already initialized.")
534-
_DATA_PIPELINE = _DataPipeline(resampler_config, api_power_request_timeout)
540+
_DATA_PIPELINE = _DataPipeline(
541+
resampler_config, api_power_request_timeout, battery_power_manager_algorithm
542+
)
535543

536544

537545
def frequency() -> GridFrequency:

0 commit comments

Comments
 (0)