-
Notifications
You must be signed in to change notification settings - Fork 20
Use Power instead of float in PowerDistributor's battery manager
#1214
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This pull request refactors the PowerDistributor’s battery management by replacing float‐based power values with the new Power type. Key changes include updates to test assertions involving PowerBounds, modifications in the metric calculations and distribution algorithm to use Power objects, and corresponding adjustments in the battery manager’s API interactions.
Reviewed Changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| tests/microgrid/power_distributing/test_power_distributing.py | Updated tests to construct PowerBounds using Power.from_watts for all power parameters. |
| src/frequenz/sdk/timeseries/battery_pool/_metric_calculator.py | Revised arithmetic calculations to work with Power objects rather than raw floats. |
| src/frequenz/sdk/microgrid/_power_distributing/result.py | Changed type annotations from float to Power in PowerBounds. |
| src/frequenz/sdk/microgrid/_power_distributing/_distribution_algorithm/_battery_distribution_algorithm.py | Updated distribution algorithm to use Power objects and their arithmetic methods. |
| src/frequenz/sdk/microgrid/_power_distributing/_component_managers/_battery_manager.py | Adjusted battery manager logic to operate with Power values and consistently convert to watts when interfacing with external APIs. |
Comments suppressed due to low confidence (3)
tests/microgrid/power_distributing/test_power_distributing.py:969
- Confirm that Power.from_watts(math.nan) returns the expected NaN behavior; consider adding explicit test cases to validate how NaN values are handled.
Power.from_watts(math.nan),
src/frequenz/sdk/timeseries/battery_pool/_metric_calculator.py:605
- [nitpick] Consider leveraging operator overloading in the Power type to directly perform arithmetic operations, which would reduce the need for manual conversion using Power.from_watts on aggregated float sums.
sum((bound.inclusion_lower for bound in inverter_bounds), start=Power.zero()),
src/frequenz/sdk/microgrid/_power_distributing/_component_managers/_battery_manager.py:641
- Verify that the set_power API expects watt values; using power.as_watts() here should align with the API contract and remain consistent throughout the codebase.
api.set_power(inverter_id, power.as_watts())
|
@llucax I hope this won't be too disruptive for your microgrid API upgrade work. Otherwise, we can postpone this. |
The PV manager and the EV Charger manager of the PowerDistributor are already using `Power` and not `float`. Signed-off-by: Sahas Subramanian <[email protected]>
2af4078 to
41d4543
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess it should be fine. I can maybe try to rebase/merge the PR to the current head and then to this PR to see if it is a mess or not.
I also noticed component ID are still int, I thought I already merged the change to ID types, but maybe I only merged that in the client and never did the SDK PR to update to the new client... 😱
|
BTW, for the records LGTM, not approving only for checking the status of the client update PR. |
|
Any news @llucax? |
You did make a PR, but wasn't merged because of test failures in python 3.12: #1182 |
|
Oh damn, my backlog is getting bigger and bigger... 🙈 |
The PV manager and the EV Charger manager of the PowerDistributor are
already using
Powerand notfloat.