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 power requests from shifting actors in the PowerManager #957

Merged
merged 10 commits into from
Jun 7, 2024

Conversation

shsms
Copy link
Contributor

@shsms shsms commented May 31, 2024

There are cases where the target power needs to be shifted by a certain amount, for example, to make adjustments to the operating point. This PR enables this by designating some actors to be part of the shifting_group.

Closes #905

@shsms shsms self-assigned this May 31, 2024
@shsms shsms requested a review from a team as a code owner May 31, 2024 08:32
@shsms shsms requested a review from llucax May 31, 2024 08:32
@github-actions github-actions bot added part:docs Affects the documentation part:tests Affects the unit, integration and performance (benchmarks) tests part:data-pipeline Affects the data pipeline part:actor Affects an actor ot the actors utilities (decorator, etc.) part:microgrid Affects the interactions with the microgrid labels May 31, 2024
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.

I gave this a quick look, I still have to look at the commit doing the actual implementation in more detail, but I have a couple of comments:

  1. It is still no 100% clear what incremental means here. It might be nice to add some better description to the PR and maybe even the docs, like one example with a few actors some using incremental and some not, and seeing what difference does it make in terms of what is the resulting power.

  2. It looks like you have at least subscriptions and pools grouped in incremental and not incremental. It might be worth adding some class (not sure what it is exactly? Power requests? Algorithms?) that have 2 members, pool and subscriptions, and I don't know, maybe there is some more common code to manipulate both that can go there too. Maybe it doesn't make sense, not sure, as I said I only gave a quick look but it is something that popped out when looking at the commits.

@shsms shsms marked this pull request as draft June 4, 2024 09:51
@shsms
Copy link
Contributor Author

shsms commented Jun 4, 2024

Draft until I finish the renaming to shifting_group.

@llucax
Copy link
Contributor

llucax commented Jun 4, 2024

No in_? 😆

@shsms
Copy link
Contributor Author

shsms commented Jun 4, 2024

in_ in the argument names and class fields.

@shsms shsms changed the title Support power requests from incremental actors in the PowerManager Support power requests from shifting actors in the PowerManager Jun 5, 2024
shsms added 8 commits June 5, 2024 14:43
Signed-off-by: Sahas Subramanian <sahas.subramanian@proton.me>
The older name was a bit ambiguous, because there are also bounds
calculated by the power manager for use by actors.

This change clears this ambiguity.

Signed-off-by: Sahas Subramanian <sahas.subramanian@proton.me>
This would return the most recently calculated target power for a
given set of components.

Signed-off-by: Sahas Subramanian <sahas.subramanian@proton.me>
And propagate it all the way to the power manager.

Signed-off-by: Sahas Subramanian <sahas.subramanian@proton.me>
This is done by having an additional `Matryoshka` instance for
resolving requests from shifting actors.  And the target power thus
obtained is added to the target power from the regular actors, which
in effect, shifts the target power of the regular actors by the target
power of the shifting actors.

Signed-off-by: Sahas Subramanian <sahas.subramanian@proton.me>
Signed-off-by: Sahas Subramanian <sahas.subramanian@proton.me>
Signed-off-by: Sahas Subramanian <sahas.subramanian@proton.me>
Signed-off-by: Sahas Subramanian <sahas.subramanian@proton.me>
@shsms shsms marked this pull request as ready for review June 5, 2024 13:46
llucax
llucax previously approved these changes Jun 6, 2024
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.

I really like how this turned up! And the new documentation is great, it makes things so much clearer!

I made several comments but they are all part of the same thing, a proposal to have a specific class for managing pool groups, as I mentioned in my first review.

I really think it could simplify the code quite a bit and remove some duplication. If you agree, I think this refactoring should be done in a separate PR since I don't have any other comments other than that, I think it would be a good idea to merge this PR as is to keep things moving. So approving.

src/frequenz/sdk/microgrid/__init__.py Outdated Show resolved Hide resolved
src/frequenz/sdk/microgrid/__init__.py Outdated Show resolved Hide resolved
@@ -211,6 +212,8 @@ def ev_charger_pool(
EVChargerPool.
name: An optional name used to identify this instance of the pool or a
corresponding actor in the logs.
in_shifting_group: Whether the power requests get sent to the shifting group
in the PowerManager or not.
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be nice to include a link to the shifting group docs in here (and in every place that receives a in_shifting_group). I will be quite verbose, but we can greatly simplify it by creating a [macro like we did for linking to the glossary][https://github.com/frequenz-floss/frequenz-sdk-python/blob/8e5d65e383442c3fa85060e985e225d5e6412a9e/docs/_scripts/macros.py#L79-L97].

Comment on lines -87 to +99
self._subscriptions: dict[frozenset[int], dict[int, Sender[_Report]]] = {}
self._non_shifting_subscriptions: dict[
frozenset[int], dict[int, Sender[_Report]]
] = {}
self._shifting_subscriptions: dict[
frozenset[int], dict[int, Sender[_Report]]
] = {}
self._distribution_results: dict[frozenset[int], power_distributing.Result] = {}

self._algorithm: BaseAlgorithm = Matryoshka(
self._non_shifting_group: BaseAlgorithm = Matryoshka(
max_proposal_age=timedelta(seconds=60.0)
)
self._shifting_group: BaseAlgorithm = Matryoshka(
Copy link
Contributor

Choose a reason for hiding this comment

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

Not going to insist a lot on this because I don't want to keep focusing on bikeshedding, but I though it out there just in case you agree it could bring some extra clarity. Back to my previous suggestion of grouping the groups, what about having something like:

class PoolGroup:
    algorithm: BaseAlgorithm
    subscriptions: dict[...]
    # Again, I'm not sure if there are common operations with
    # these algorithm and subscriptions that could be moved here too.

class PowerManagingActor(Actor):
    def __init__(self, ...):
        self._default_group = PoolGroup(...)
        self._shifting_group = PoolGroup(...)

?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If we end up adding more than two groups, I think it makes sense to refactor at that time. For now, I'm not sure it is worth the effort, the code is not really that complicated the way it is.

Copy link
Contributor

Choose a reason for hiding this comment

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

I created an issue just so it doesn't get lost, but I agree is OK as it is for now:

@llucax
Copy link
Contributor

llucax commented Jun 6, 2024

Oh, right, there is also the cross referencing of in_shifting_group to the high-level docs of what a shifting group is, but that's also optional and I don't mind if that's also done in a separate PR.

@llucax
Copy link
Contributor

llucax commented Jun 6, 2024

It looks like DCO is still not working

Co-authored-by: Leandro Lucarella <luca@llucax.com>
Signed-off-by: Sahas Subramanian <sahas.subramanian@proton.me>
Also update the function's docstring.

Signed-off-by: Sahas Subramanian <sahas.subramanian@proton.me>
@shsms shsms requested a review from llucax June 7, 2024 08:36
@shsms shsms added this pull request to the merge queue Jun 7, 2024
Merged via the queue into frequenz-floss:v1.x.x with commit d5d74a3 Jun 7, 2024
18 checks passed
@shsms shsms deleted the incremental-power branch June 7, 2024 14:05
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:data-pipeline Affects the data pipeline part:docs Affects the documentation part:microgrid Affects the interactions with the microgrid part:tests Affects the unit, integration and performance (benchmarks) tests
Projects
Development

Successfully merging this pull request may close these issues.

Support multiple Matryoshka pools in the Power Manager that can be aggregated
2 participants