Skip to content
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

Support exclusion bounds in power distributor #562

Merged
merged 12 commits into from
Aug 9, 2023

Conversation

shsms
Copy link
Contributor

@shsms shsms commented Aug 3, 2023

To be merged after #537

Closes #152

@shsms shsms added this to the v0.24.0 milestone Aug 3, 2023
@shsms shsms requested a review from a team as a code owner August 3, 2023 17:08
@shsms shsms marked this pull request as draft August 3, 2023 17:08
@github-actions github-actions bot added part:docs Affects the documentation part:tests Affects the unit, integration and performance (benchmarks) tests part:tooling Affects the development tooling (CI, deployment, dependency management, etc.) part:data-pipeline Affects the data pipeline part:power-management Affects the management of battery power and distribution part:actor Affects an actor ot the actors utilities (decorator, etc.) part:microgrid Affects the interactions with the microgrid labels Aug 3, 2023
@shsms
Copy link
Contributor Author

shsms commented Aug 3, 2023

Still need to add tests.

@shsms shsms force-pushed the power-dist-excl-bounds branch 2 times, most recently from 8df671c to 2200e1b Compare August 4, 2023 17:24
@github-actions github-actions bot removed the part:tooling Affects the development tooling (CI, deployment, dependency management, etc.) label Aug 4, 2023
This method will replace the `_get_{upper,lower}_bound` methods in
subsequent commits.

Signed-off-by: Sahas Subramanian <[email protected]>
This just updates the tests to use data structures that support
exclusion bounds, so that once support is implemented in the actor,
it would be easy to add incremental tests.

Signed-off-by: Sahas Subramanian <[email protected]>
This allows us to not pack all tests in the same class, but group them
separately in smaller units.

Signed-off-by: Sahas Subramanian <[email protected]>
@github-actions github-actions bot removed part:docs Affects the documentation part:data-pipeline Affects the data pipeline part:microgrid Affects the interactions with the microgrid labels Aug 8, 2023
@shsms shsms marked this pull request as ready for review August 8, 2023 10:23
Signed-off-by: Sahas Subramanian <[email protected]>
@github-actions github-actions bot added the part:docs Affects the documentation label Aug 8, 2023
@llucax llucax removed this from the v0.24.0 milestone Aug 8, 2023
Copy link
Contributor

@llucax llucax left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Except for the abs_tol for deficit (which I'm not sure it is an issue or not), nothing major from my side. I didn't dig very deep into the distribution algorithm itself. The rest can be easily applied by accepting the suggestions.

tests/actor/test_power_distributing.py Show resolved Hide resolved
src/frequenz/sdk/power/_distribution_algorithm.py Outdated Show resolved Hide resolved
src/frequenz/sdk/power/_distribution_algorithm.py Outdated Show resolved Hide resolved
src/frequenz/sdk/power/_distribution_algorithm.py Outdated Show resolved Hide resolved
if math.isclose(take_from[1], 0.0, abs_tol=1e-6) or take_from[1] < 0.0:
break
if take_from[1] >= -deficit or math.isclose(
take_from[1], -deficit, abs_tol=1e-6
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I deficit supposed to be close to zero? abs_tol seems to be mainly useful for comparing to near-zero values AFAIK, not sure if it is generally OK to use it for other values or not. Maybe @matthias-wende-frequenz can speak his mathematician mind...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a >=. But the = part is not exact, value is sometimes slightly on the other side. hence the isclose.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, what I'm asking if it is OK is specifically the abs_tol argument.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand the full algorithm but the check is fine. It's just about having a higher certainty the the deficit is close the excess_reserved under consideration (the take_from[1]).

Copy link
Contributor

@daniel-zullo-frequenz daniel-zullo-frequenz Aug 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should use the relative tolerance instead as take_from[1] and deficit are already compared to zero above where the absolute tolerance makes more sense

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The relative tolerance is defined by default (rel_tol=1e-09), this is why I asked only about removing tol_abs.

if left_over > -deficit:
distributed_power += deficit
deficit = 0.0
deficits[inverter_id] = 0.0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think deficits does not need to be updated in this for-loop

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

true, only the distributed_power needs to be updated. I guess I added the other two just to be able to properly reason about what was going on as I was developing, but they don't have to be there.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add a comment about it in the refactor PR if it would make reasoning about it easier.

elif left_over > 0.0:
deficit += left_over
distributed_power += left_over
deficits[inverter_id] = deficit
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updating deficits might be redundant here as it will no longer be used after the for-loop

distribution[inverter_id] += excess
distributed_power += excess

for inverter_id, deficit in deficits.items():
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This duplicated for-loop is not needed as its content could be added in the first loop for deficits, right after the end of the while-loop

llucax and others added 3 commits August 9, 2023 10:07
Signed-off-by: Leandro Lucarella <[email protected]>
We already have an utility function to check if a `float` is close
to zero, so we can use that instead.

Signed-off-by: Leandro Lucarella <[email protected]>
Co-authored-by: daniel-zullo-frequenz <[email protected]>
Signed-off-by: Leandro Lucarella <[email protected]>
@llucax llucax added this pull request to the merge queue Aug 9, 2023
Merged via the queue into frequenz-floss:v0.x.x with commit 6258c76 Aug 9, 2023
9 checks passed
@llucax
Copy link
Contributor

llucax commented Aug 9, 2023

@shsms shsms deleted the power-dist-excl-bounds branch August 9, 2023 13:20
github-merge-queue bot pushed a commit that referenced this pull request Aug 10, 2023
- [x] Remove absolute tolerance in floating-point comparison: see
#562 (comment)
for more details
- [x] Remove redundant deficits updates: see
#562 (comment)
for more details
- [x] Consolidate deficits for-loops: see
#562 (comment)
for more details

This is an internal refactoring for the power distribution algorithm
maintaining its functionality, so release notes don't need to be
updated.

Fixes #572
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
part:actor Affects an actor ot the actors utilities (decorator, etc.) part:docs Affects the documentation part:power-management Affects the management of battery power and distribution part:tests Affects the unit, integration and performance (benchmarks) tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

PowerDistributingActor should use min SoP (inclusion/exclusion bounds)
4 participants