Skip to content

Commit 3123dbd

Browse files
committed
Improve documentation in multiple parts
This includes a new admonition for `microgrid.battery_pool()` that higher values mean higher priorities. Signed-off-by: Sahas Subramanian <[email protected]>
1 parent 1e7f54b commit 3123dbd

File tree

4 files changed

+27
-7
lines changed

4 files changed

+27
-7
lines changed

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,21 @@
11
# License: MIT
22
# Copyright © 2023 Frequenz Energy-as-a-Service GmbH
33

4-
"""A power manager implementation that uses the matryoshka algorithm."""
4+
"""A power manager implementation that uses the matryoshka algorithm.
5+
6+
When there are multiple proposals from different actors for the same set of batteries,
7+
the matryoshka algorithm will consider the priority of the actors, the bounds they set
8+
and their preferred power to determine the target power for the batteries.
9+
10+
The preferred power of lower priority actors will take precedence as long as they
11+
respect the bounds set by higher priority actors. If lower priority actors request
12+
power values outside the bounds set by higher priority actors, the target power will
13+
be the closest value to the preferred power that is within the bounds.
14+
15+
When there is only a single proposal for a set of batteries, its preferred power would
16+
be the target power, as long as it falls within the system power bounds for the
17+
batteries.
18+
"""
519

620
from __future__ import annotations
721

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ def __init__( # pylint: disable=too-many-arguments
5050
channel_registry: The channel registry.
5151
algorithm: The power management algorithm to use.
5252
53-
5453
Raises:
5554
NotImplementedError: When an unknown algorithm is given.
5655
"""
@@ -128,8 +127,6 @@ def _add_bounds_tracker(self, battery_ids: frozenset[int]) -> None:
128127
bounds_receiver = battery_pool._system_power_bounds.new_receiver()
129128
# pylint: enable=protected-access
130129

131-
# Fetch the latest system bounds once, before starting the bounds tracker task,
132-
# so that when this function returns, there's already some bounds available.
133130
self._system_bounds[battery_ids] = PowerMetrics(
134131
timestamp=datetime.now(tz=timezone.utc),
135132
inclusion_bounds=None,

src/frequenz/sdk/microgrid/_data_pipeline.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,13 @@ def battery_pool(
433433
If a BatteryPool instance for the given ids doesn't exist, a new one is created and
434434
returned.
435435
436+
The priority value is used to resolve conflicts when multiple actors are trying to
437+
propose different power values for the same set of batteries.
438+
439+
!!! note
440+
When specifying priority, bigger values indicate higher priority. The default
441+
priority is the lowest possible value.
442+
436443
The BatteryPool is wrapped in a new `BatteryPoolWrapper` instance each time.
437444
438445
Args:

src/frequenz/sdk/timeseries/battery_pool/_battery_pool_wrapper.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ def __init__(self, battery_pool: BatteryPool, name: str | None, priority: int):
4949
5050
Args:
5151
battery_pool: The battery pool to wrap.
52-
name: The source ID to use for the requests made by this wrapper.
52+
name: An optional name used to identify this instance of the pool or a
53+
corresponding actor in the logs.
5354
priority: The priority of the actor using this wrapper.
5455
"""
5556
self._battery_pool = battery_pool
@@ -77,15 +78,16 @@ async def propose_power(
7778
The preferred power of lower priority actors will take precedence as long as
7879
they respect the bounds set by higher priority actors. If lower priority actors
7980
request power values outside of the bounds set by higher priority actors, the
80-
target power will be closest value to the preferred power that is within the
81+
target power will be the closest value to the preferred power that is within the
8182
bounds.
8283
8384
When there are no other actors trying to use the same batteries, the actor's
8485
preferred power would be set as the target power, as long as it falls within the
8586
system power bounds for the batteries.
8687
8788
The result of the request can be accessed using the receiver returned from the
88-
`power_distribution_results` method.
89+
`power_status` method, which also streams the bounds that an actor should
90+
comply with, based on its priority.
8991
9092
Args:
9193
power: The power to propose for the batteries in the pool. If None, the

0 commit comments

Comments
 (0)