Skip to content

Commit 2e9ba3e

Browse files
authored
Log power allocations per actor in the PowerManager (#1196)
2 parents 6d106d1 + 3e402b5 commit 2e9ba3e

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

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

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,20 +63,21 @@ def __init__(self, max_proposal_age: timedelta) -> None:
6363

6464
def _calc_targets(
6565
self,
66-
proposals: set[Proposal],
66+
component_ids: frozenset[int],
6767
system_bounds: SystemBounds,
6868
priority: int | None = None,
6969
) -> tuple[Power | None, Bounds[Power]]:
7070
"""Calculate the target power and bounds for the given components.
7171
7272
Args:
73-
proposals: The proposals for the given components.
73+
component_ids: The component IDs to calculate the target power for.
7474
system_bounds: The system bounds for the components in the proposal.
7575
priority: The priority of the actor for which the target power is calculated.
7676
7777
Returns:
7878
The new target power and bounds for the components.
7979
"""
80+
proposals = self._component_buckets.get(component_ids, set())
8081
lower_bound = (
8182
system_bounds.inclusion_bounds.lower
8283
if system_bounds.inclusion_bounds
@@ -98,6 +99,9 @@ def _calc_targets(
9899
top_pri_bounds: Bounds[Power] | None = None
99100

100101
target_power = Power.zero()
102+
103+
allocations: dict[str, str] = {}
104+
101105
for next_proposal in sorted(proposals, reverse=True):
102106
# if a priority is given, the bounds calculated until that priority is
103107
# reached will be the bounds available to an actor with the given priority.
@@ -152,6 +156,8 @@ def _calc_targets(
152156
# Add the proposal power to the target power (aka shift in the opposite direction).
153157
target_power += proposal_power
154158

159+
allocations[next_proposal.source_id] = str(proposal_power)
160+
155161
# The `top_pri_bounds` is to ensure that when applying the exclusion bounds to
156162
# the target power at the end, we respect the bounds that were set by the first
157163
# power-proposing actor.
@@ -166,6 +172,13 @@ def _calc_targets(
166172
system_bounds.exclusion_bounds,
167173
)
168174

175+
if allocations:
176+
_logger.info(
177+
"PowerManager allocations for component IDs: %s: %s",
178+
sorted(component_ids),
179+
allocations,
180+
)
181+
169182
return target_power, Bounds[Power](lower=lower_bound, upper=upper_bound)
170183

171184
def _validate_component_ids(
@@ -242,9 +255,7 @@ def calculate_target_power(
242255
del self._component_buckets[component_ids]
243256
_ = self._target_power.pop(component_ids, None)
244257

245-
target_power, _ = self._calc_targets(
246-
self._component_buckets.get(component_ids, set()), system_bounds
247-
)
258+
target_power, _ = self._calc_targets(component_ids, system_bounds)
248259

249260
if target_power is not None and (
250261
must_return_power
@@ -274,9 +285,7 @@ def get_status( # pylint: disable=too-many-locals
274285
the given priority.
275286
"""
276287
target_power = self._target_power.get(component_ids)
277-
_, bounds = self._calc_targets(
278-
self._component_buckets.get(component_ids, set()), system_bounds, priority
279-
)
288+
_, bounds = self._calc_targets(component_ids, system_bounds, priority)
280289
return _Report(
281290
target_power=target_power,
282291
_inclusion_bounds=timeseries.Bounds[Power](

0 commit comments

Comments
 (0)