Skip to content

Commit 7da41bf

Browse files
committed
Expose only outer usable bounds
With this change, the SDK will just expose one set of outer bounds, even if it has exclusion zones within. The representation of bounds data in the SDK is no longer exposed. When users need additional control over what power values they propose, they can use the `adjust_to_bounds` methods. Signed-off-by: Sahas Subramanian <[email protected]>
1 parent b518af5 commit 7da41bf

File tree

5 files changed

+39
-20
lines changed

5 files changed

+39
-20
lines changed

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

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,14 @@ class Report:
5050
target_power: Power | None
5151
"""The currently set power for the batteries."""
5252

53-
inclusion_bounds: timeseries.Bounds[Power] | None
53+
_inclusion_bounds: timeseries.Bounds[Power] | None
5454
"""The available inclusion bounds for the batteries, for the actor's priority.
5555
5656
These bounds are adjusted to any restrictions placed by actors with higher
5757
priorities.
5858
"""
5959

60-
exclusion_bounds: timeseries.Bounds[Power] | None
60+
_exclusion_bounds: timeseries.Bounds[Power] | None
6161
"""The exclusion bounds for the batteries.
6262
6363
The power manager doesn't manage exclusion bounds, so these are aggregations of
@@ -73,6 +73,20 @@ class Report:
7373
This is `None` if no power distribution has been performed yet.
7474
"""
7575

76+
@property
77+
def bounds(self) -> timeseries.Bounds[Power] | None:
78+
"""The bounds for the batteries.
79+
80+
These bounds are adjusted to any restrictions placed by actors with higher
81+
priorities.
82+
83+
There might be exclusion zones within these bounds. If necessary, the
84+
[`adjust_to_bounds`][frequenz.sdk.timeseries.battery_pool.Report.adjust_to_bounds]
85+
method may be used to check if a desired power value fits the bounds, or to get
86+
the closest possible power values that do fit the bounds.
87+
"""
88+
return self._inclusion_bounds
89+
7690
def adjust_to_bounds(self, power: Power) -> tuple[Power | None, Power | None]:
7791
"""Adjust a power value to the bounds.
7892
@@ -123,14 +137,14 @@ def adjust_to_bounds(self, power: Power) -> tuple[Power | None, Power | None]:
123137
A tuple of the closest power values to the desired power that fall within
124138
the available bounds for the actor.
125139
"""
126-
if self.inclusion_bounds is None:
140+
if self._inclusion_bounds is None:
127141
return None, None
128142

129143
return _clamp_to_bounds(
130144
power,
131-
self.inclusion_bounds.lower,
132-
self.inclusion_bounds.upper,
133-
self.exclusion_bounds,
145+
self._inclusion_bounds.lower,
146+
self._inclusion_bounds.upper,
147+
self._exclusion_bounds,
134148
)
135149

136150

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -228,8 +228,8 @@ def get_status(
228228
if system_bounds.inclusion_bounds is None:
229229
return Report(
230230
target_power=target_power,
231-
inclusion_bounds=None,
232-
exclusion_bounds=system_bounds.exclusion_bounds,
231+
_inclusion_bounds=None,
232+
_exclusion_bounds=system_bounds.exclusion_bounds,
233233
distribution_result=distribution_result,
234234
)
235235

@@ -263,9 +263,9 @@ def get_status(
263263
break
264264
return Report(
265265
target_power=target_power,
266-
inclusion_bounds=timeseries.Bounds[Power](
266+
_inclusion_bounds=timeseries.Bounds[Power](
267267
lower=lower_bound, upper=upper_bound
268268
),
269-
exclusion_bounds=system_bounds.exclusion_bounds,
269+
_exclusion_bounds=system_bounds.exclusion_bounds,
270270
distribution_result=distribution_result,
271271
)

tests/actor/_power_managing/test_matryoshka.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,11 @@ def bounds(
6969
else:
7070
assert report.target_power is not None
7171
assert report.target_power.as_watts() == expected_power
72-
assert report.inclusion_bounds is not None
73-
assert report.inclusion_bounds.lower.as_watts() == expected_bounds[0]
74-
assert report.inclusion_bounds.upper.as_watts() == expected_bounds[1]
72+
# pylint: disable=protected-access
73+
assert report._inclusion_bounds is not None
74+
assert report._inclusion_bounds.lower.as_watts() == expected_bounds[0]
75+
assert report._inclusion_bounds.upper.as_watts() == expected_bounds[1]
76+
# pylint: enable=protected-access
7577

7678

7779
async def test_matryoshka_no_excl() -> None: # pylint: disable=too-many-statements

tests/actor/_power_managing/test_report.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ def __init__(
1818
"""Initialize the tester."""
1919
self._report = Report(
2020
target_power=None,
21-
inclusion_bounds=Bounds(
21+
_inclusion_bounds=Bounds( # pylint: disable=protected-access
2222
Power.from_watts(inclusion_bounds[0]),
2323
Power.from_watts(inclusion_bounds[1]),
2424
)
2525
if inclusion_bounds is not None
2626
else None,
27-
exclusion_bounds=Bounds(
27+
_exclusion_bounds=Bounds( # pylint: disable=protected-access
2828
Power.from_watts(exclusion_bounds[0]),
2929
Power.from_watts(exclusion_bounds[1]),
3030
)

tests/timeseries/_battery_pool/test_battery_pool_control_methods.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -149,13 +149,16 @@ def _assert_report(
149149
assert report.target_power == (
150150
Power.from_watts(power) if power is not None else None
151151
)
152+
# pylint: disable=protected-access
152153
assert (
153-
report.inclusion_bounds is not None and report.exclusion_bounds is not None
154+
report._inclusion_bounds is not None
155+
and report._exclusion_bounds is not None
154156
)
155-
assert report.inclusion_bounds.lower == Power.from_watts(lower)
156-
assert report.inclusion_bounds.upper == Power.from_watts(upper)
157-
assert report.exclusion_bounds.lower == Power.from_watts(0.0)
158-
assert report.exclusion_bounds.upper == Power.from_watts(0.0)
157+
assert report._inclusion_bounds.lower == Power.from_watts(lower)
158+
assert report._inclusion_bounds.upper == Power.from_watts(upper)
159+
assert report._exclusion_bounds.lower == Power.from_watts(0.0)
160+
assert report._exclusion_bounds.upper == Power.from_watts(0.0)
161+
# pylint: enable=protected-access
159162
if expected_result_pred is not None:
160163
assert report.distribution_result is not None
161164
assert expected_result_pred(report.distribution_result)

0 commit comments

Comments
 (0)