Skip to content

Commit 044cbe6

Browse files
committed
Remove unused must_send flag from power manager algorithms
Signed-off-by: Sahas Subramanian <[email protected]>
1 parent e4ef158 commit 044cbe6

File tree

6 files changed

+15
-66
lines changed

6 files changed

+15
-66
lines changed

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,6 @@ def calculate_target_power(
215215
component_ids: frozenset[int],
216216
proposal: Proposal | None,
217217
system_bounds: SystemBounds,
218-
must_return_power: bool = False,
219218
) -> Power | None:
220219
"""Calculate and return the target power for the given components.
221220
@@ -224,12 +223,10 @@ def calculate_target_power(
224223
proposal: If given, the proposal to added to the bucket, before the target
225224
power is calculated.
226225
system_bounds: The system bounds for the components in the proposal.
227-
must_return_power: If `True`, the algorithm must return a target power,
228-
even if it hasn't changed since the last call.
229226
230227
Returns:
231228
The new target power for the components, or `None` if the target power
232-
didn't change.
229+
couldn't be calculated.
233230
"""
234231

235232
# The arguments for this method are tightly coupled to the `Matryoshka` algorithm.

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,6 @@ def calculate_target_power(
158158
component_ids: frozenset[int],
159159
proposal: Proposal | None,
160160
system_bounds: SystemBounds,
161-
must_return_power: bool = False,
162161
) -> Power | None:
163162
"""Calculate and return the target power for the given components.
164163
@@ -167,12 +166,10 @@ def calculate_target_power(
167166
proposal: If given, the proposal to added to the bucket, before the target
168167
power is calculated.
169168
system_bounds: The system bounds for the components in the proposal.
170-
must_return_power: If `True`, the algorithm must return a target power,
171-
even if it hasn't changed since the last call.
172169
173170
Returns:
174171
The new target power for the components, or `None` if the target power
175-
didn't change.
172+
couldn't be calculated.
176173
177174
Raises: # noqa: DOC502
178175
NotImplementedError: When the proposal contains component IDs that are

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -186,13 +186,11 @@ async def _send_updated_target_power(
186186
self,
187187
component_ids: frozenset[int],
188188
proposal: Proposal | None,
189-
must_send: bool = False,
190189
) -> None:
191190
target_power = self._algorithm.calculate_target_power(
192191
component_ids,
193192
proposal,
194193
self._system_bounds[component_ids],
195-
must_send,
196194
)
197195
if target_power is not None:
198196
await self._power_distributing_requests_sender.send(
@@ -228,9 +226,7 @@ async def _run(self) -> None:
228226
# This can be removed as soon as
229227
# https://github.com/frequenz-floss/frequenz-sdk-python/issues/293 is
230228
# implemented.
231-
await self._send_updated_target_power(
232-
proposal.component_ids, proposal, must_send=True
233-
)
229+
await self._send_updated_target_power(proposal.component_ids, proposal)
234230
await self._send_reports(proposal.component_ids)
235231

236232
elif selected_from(selected, self._bounds_subscription_receiver):
@@ -265,7 +261,7 @@ async def _run(self) -> None:
265261
if not last_result_partial_failure:
266262
last_result_partial_failure = True
267263
await self._send_updated_target_power(
268-
frozenset(request.component_ids), None, must_send=True
264+
frozenset(request.component_ids), None
269265
)
270266
case _power_distributing.Success():
271267
last_result_partial_failure = False

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,6 @@ def calculate_target_power(
218218
component_ids: frozenset[int],
219219
proposal: Proposal | None,
220220
system_bounds: SystemBounds,
221-
must_return_power: bool = False,
222221
) -> Power | None:
223222
"""Calculate and return the target power for the given components.
224223
@@ -227,12 +226,10 @@ def calculate_target_power(
227226
proposal: If given, the proposal to added to the bucket, before the target
228227
power is calculated.
229228
system_bounds: The system bounds for the components in the proposal.
230-
must_return_power: If `True`, the algorithm must return a target power,
231-
even if it hasn't changed since the last call.
232229
233230
Returns:
234231
The new target power for the components, or `None` if the target power
235-
didn't change.
232+
couldn't be calculated.
236233
237234
Raises: # noqa: DOC502
238235
NotImplementedError: When the proposal contains component IDs that are

tests/actor/_power_managing/test_matryoshka.py

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ def tgt_power( # pylint: disable=too-many-arguments,too-many-positional-argumen
3737
bounds: tuple[float | None, float | None],
3838
expected: float | None,
3939
creation_time: float | None = None,
40-
must_send: bool = False,
4140
batteries: frozenset[int] | None = None,
4241
) -> None:
4342
"""Test the target power calculation."""
@@ -60,7 +59,6 @@ def tgt_power( # pylint: disable=too-many-arguments,too-many-positional-argumen
6059
),
6160
),
6261
self._system_bounds,
63-
must_send,
6462
)
6563
assert tgt_power == (
6664
Power.from_watts(expected) if expected is not None else None
@@ -110,9 +108,7 @@ async def test_matryoshka_no_excl() -> None: # pylint: disable=too-many-stateme
110108
tester.bounds(priority=1, expected_power=25.0, expected_bounds=(25.0, 50.0))
111109

112110
tester.tgt_power(priority=1, power=20.0, bounds=(20.0, 50.0), expected=25.0)
113-
tester.tgt_power(
114-
priority=1, power=20.0, bounds=(20.0, 50.0), expected=25.0, must_send=True
115-
)
111+
tester.tgt_power(priority=1, power=20.0, bounds=(20.0, 50.0), expected=25.0)
116112
tester.bounds(priority=1, expected_power=25.0, expected_bounds=(25.0, 50.0))
117113

118114
tester.tgt_power(priority=3, power=10.0, bounds=(10.0, 15.0), expected=15.0)
@@ -395,13 +391,9 @@ async def test_matryoshka_drop_old_proposals() -> None:
395391
expected=25.0,
396392
)
397393

398-
tester.tgt_power(
399-
priority=1, power=20.0, bounds=(20.0, 50.0), expected=25.0, must_send=True
400-
)
394+
tester.tgt_power(priority=1, power=20.0, bounds=(20.0, 50.0), expected=25.0)
401395
tester.algorithm.drop_old_proposals(now)
402-
tester.tgt_power(
403-
priority=1, power=20.0, bounds=(20.0, 50.0), expected=22.0, must_send=True
404-
)
396+
tester.tgt_power(priority=1, power=20.0, bounds=(20.0, 50.0), expected=22.0)
405397

406398
# When overwritten by a newer proposal, that proposal is not dropped.
407399
tester.tgt_power(
@@ -417,16 +409,11 @@ async def test_matryoshka_drop_old_proposals() -> None:
417409
bounds=(25.0, 50.0),
418410
creation_time=now - 30.0,
419411
expected=25.0,
420-
must_send=True,
421412
)
422413

423-
tester.tgt_power(
424-
priority=1, power=20.0, bounds=(20.0, 50.0), expected=25.0, must_send=True
425-
)
414+
tester.tgt_power(priority=1, power=20.0, bounds=(20.0, 50.0), expected=25.0)
426415
tester.algorithm.drop_old_proposals(now)
427-
tester.tgt_power(
428-
priority=1, power=20.0, bounds=(20.0, 50.0), expected=25.0, must_send=True
429-
)
416+
tester.tgt_power(priority=1, power=20.0, bounds=(20.0, 50.0), expected=25.0)
430417

431418
# When all proposals are too old, they are dropped, and the buckets are dropped as
432419
# well. After that, sending a request for a different but overlapping bucket will
@@ -443,7 +430,6 @@ async def test_matryoshka_drop_old_proposals() -> None:
443430
power=25.0,
444431
bounds=(25.0, 50.0),
445432
expected=25.0,
446-
must_send=True,
447433
batteries=overlapping_batteries,
448434
)
449435

@@ -453,23 +439,20 @@ async def test_matryoshka_drop_old_proposals() -> None:
453439
bounds=(25.0, 50.0),
454440
creation_time=now - 70.0,
455441
expected=25.0,
456-
must_send=True,
457442
)
458443
tester.tgt_power(
459444
priority=2,
460445
power=25.0,
461446
bounds=(25.0, 50.0),
462447
creation_time=now - 70.0,
463448
expected=25.0,
464-
must_send=True,
465449
)
466450
tester.tgt_power(
467451
priority=3,
468452
power=25.0,
469453
bounds=(25.0, 50.0),
470454
creation_time=now - 70.0,
471455
expected=25.0,
472-
must_send=True,
473456
)
474457

475458
tester.algorithm.drop_old_proposals(now)
@@ -479,7 +462,6 @@ async def test_matryoshka_drop_old_proposals() -> None:
479462
power=25.0,
480463
bounds=(25.0, 50.0),
481464
expected=25.0,
482-
must_send=True,
483465
batteries=overlapping_batteries,
484466
)
485467

@@ -514,7 +496,6 @@ def ensure_overlapping_bucket_request_fails() -> None:
514496
power=None,
515497
bounds=(20.0, 50.0),
516498
expected=None,
517-
must_send=True,
518499
batteries=overlapping_batteries,
519500
)
520501

tests/actor/_power_managing/test_shifting_matryoshka.py

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ def tgt_power( # pylint: disable=too-many-arguments,too-many-positional-argumen
4141
bounds: tuple[float | None, float | None],
4242
expected: float | None,
4343
creation_time: float | None = None,
44-
must_send: bool = False,
4544
batteries: frozenset[int] | None = None,
4645
) -> None:
4746
"""Test the target power calculation."""
@@ -64,7 +63,6 @@ def tgt_power( # pylint: disable=too-many-arguments,too-many-positional-argumen
6463
),
6564
),
6665
self._system_bounds,
67-
must_send,
6866
)
6967
assert tgt_power == (
7068
Power.from_watts(expected) if expected is not None else None
@@ -114,9 +112,7 @@ async def test_matryoshka_no_excl() -> None: # pylint: disable=too-many-stateme
114112
tester.bounds(priority=1, expected_power=25.0, expected_bounds=(0.0, 25.0))
115113

116114
tester.tgt_power(priority=1, power=20.0, bounds=(20.0, 50.0), expected=45.0)
117-
tester.tgt_power(
118-
priority=1, power=20.0, bounds=(20.0, 50.0), expected=45.0, must_send=True
119-
)
115+
tester.tgt_power(priority=1, power=20.0, bounds=(20.0, 50.0), expected=45.0)
120116
tester.bounds(priority=1, expected_power=45.0, expected_bounds=(0.0, 25.0))
121117

122118
tester.tgt_power(priority=3, power=10.0, bounds=(10.0, 15.0), expected=15.0)
@@ -428,13 +424,9 @@ async def test_matryoshka_drop_old_proposals() -> None:
428424
expected=47.0,
429425
)
430426

431-
tester.tgt_power(
432-
priority=1, power=20.0, bounds=(20.0, 50.0), expected=67.0, must_send=True
433-
)
427+
tester.tgt_power(priority=1, power=20.0, bounds=(20.0, 50.0), expected=67.0)
434428
tester.algorithm.drop_old_proposals(now)
435-
tester.tgt_power(
436-
priority=1, power=20.0, bounds=(20.0, 50.0), expected=42.0, must_send=True
437-
)
429+
tester.tgt_power(priority=1, power=20.0, bounds=(20.0, 50.0), expected=42.0)
438430

439431
# When overwritten by a newer proposal, that proposal is not dropped.
440432
tester.tgt_power(
@@ -450,16 +442,11 @@ async def test_matryoshka_drop_old_proposals() -> None:
450442
bounds=(25.0, 50.0),
451443
creation_time=now - 30.0,
452444
expected=67.0,
453-
must_send=True,
454445
)
455446

456-
tester.tgt_power(
457-
priority=1, power=20.0, bounds=(20.0, 50.0), expected=67.0, must_send=True
458-
)
447+
tester.tgt_power(priority=1, power=20.0, bounds=(20.0, 50.0), expected=67.0)
459448
tester.algorithm.drop_old_proposals(now)
460-
tester.tgt_power(
461-
priority=1, power=20.0, bounds=(20.0, 50.0), expected=67.0, must_send=True
462-
)
449+
tester.tgt_power(priority=1, power=20.0, bounds=(20.0, 50.0), expected=67.0)
463450

464451
# When all proposals are too old, they are dropped, and the buckets are dropped as
465452
# well. After that, sending a request for a different but overlapping bucket will
@@ -476,7 +463,6 @@ async def test_matryoshka_drop_old_proposals() -> None:
476463
power=25.0,
477464
bounds=(25.0, 50.0),
478465
expected=25.0,
479-
must_send=True,
480466
batteries=overlapping_batteries,
481467
)
482468

@@ -486,23 +472,20 @@ async def test_matryoshka_drop_old_proposals() -> None:
486472
bounds=(25.0, 100.0),
487473
creation_time=now - 70.0,
488474
expected=72.0,
489-
must_send=True,
490475
)
491476
tester.tgt_power(
492477
priority=2,
493478
power=25.0,
494479
bounds=(25.0, 100.0),
495480
creation_time=now - 70.0,
496481
expected=72.0,
497-
must_send=True,
498482
)
499483
tester.tgt_power(
500484
priority=3,
501485
power=25.0,
502486
bounds=(25.0, 100.0),
503487
creation_time=now - 70.0,
504488
expected=75.0,
505-
must_send=True,
506489
)
507490

508491
tester.algorithm.drop_old_proposals(now)
@@ -512,7 +495,6 @@ async def test_matryoshka_drop_old_proposals() -> None:
512495
power=25.0,
513496
bounds=(25.0, 50.0),
514497
expected=25.0,
515-
must_send=True,
516498
batteries=overlapping_batteries,
517499
)
518500

@@ -547,7 +529,6 @@ def ensure_overlapping_bucket_request_fails() -> None:
547529
power=None,
548530
bounds=(20.0, 50.0),
549531
expected=None,
550-
must_send=True,
551532
batteries=overlapping_batteries,
552533
)
553534

0 commit comments

Comments
 (0)