-
Notifications
You must be signed in to change notification settings - Fork 17
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
Fallback components in generated formulas #1037
Fallback components in generated formulas #1037
Conversation
39526b0
to
54cb9c8
Compare
src/frequenz/sdk/timeseries/formula_engine/_formula_generators/_formula_generator.py
Outdated
Show resolved
Hide resolved
54cb9c8
to
d86115a
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 just gave this a quick look. Will leave it for people more familiar with the formula engine.
src/frequenz/sdk/timeseries/formula_engine/_formula_generators/_formula_generator.py
Outdated
Show resolved
Hide resolved
src/frequenz/sdk/timeseries/formula_engine/_formula_generators/_formula_generator.py
Outdated
Show resolved
Hide resolved
src/frequenz/sdk/timeseries/formula_engine/_formula_generators/_formula_generator.py
Outdated
Show resolved
Hide resolved
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.
The logic looks good to me.
Would be nice if you put the docstrings and comments through a grammar checker like https://languagetool.org/ or https://www.grammarly.com/grammar-check.
src/frequenz/sdk/timeseries/formula_engine/_formula_generators/_formula_generator.py
Outdated
Show resolved
Hide resolved
d86115a
to
9af5416
Compare
def start(self) -> None: | ||
"""Initialize formula engine and start fetching samples.""" | ||
self._formula_engine = self._formula_generator.generate() # type: ignore[assignment] | ||
assert isinstance(self._formula_engine, FormulaEngine) | ||
self._receiver = self._formula_engine.new_receiver() |
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.
Mmm, interesting, but with this implementation stop()
and cancel()
will not work. I guess cancel()
could still be a NOP, but you should probably override stop()
.
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.
stop()
should work because it has :
if not self._tasks:
return
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.
OK, I guess I reviewed this too quickly and didn't realized the missing stop()
in the comment was this stop. I also missed that even when it had a run()
method it didn't actually have any task running. I think I saw a run()
and stop()
and immediately assumed it had some task running.
I think this class is actually a good match for the new abstract Service
interface, and a good case for splitting the ServiceBase
with a basic implementation using tasks, as it doesn't really help in this case but it is nice to still have the common Service
interface with start/stop/is_running/etc. for consistency.
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.
Ok, I will do that later today (or on Monday).
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.
frequenz-core-python has no release, yet.
Should I add dependency to the v1.x.x?
Maybe I could do that in separate PR (this one is pretty big now)?
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.
No, sorry, I didn't mean to do it now, but I actually got thinking about this, and I wonder why isn't this just a Receiver
with a couple of extra methods and we are already using stop()
for some receivers (like in Merger
.
Part of the reasons of splitting this to core
is so we can use core
in channels
too, and maybe make these Receiver
s a Service
too.
So my suggestion would be to make it a Receiver
(so fetch_next()
would just be receive()
) and follow the interface of Service
so in the future when this can inherit from Service
it is not a breaking change.
OR, you can leave things are they are and we take care of it when we introduce the dependency to core
, which will probably need adapting many other classes :)
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.
This can't be Receiver, because stopping Receiver won't stop formula.
Here i would like to start/stop formula when needed. This means: subscribe/unsubscribe from all formula components, too.
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 still don't get this.
So there is no stop()
for now (or there is one inherited from BackgroundService
that doesn't do anything).
I guess in the future you want to add a stop()
. You are saying this stop()
should not stop the self._formula_engine
? Or the self._receiver
? Or both? In any case, if you make FallbackMetricFetcher
a Receiver
, why can't you just make stop()
do whatever it should do? If it is a semantic issue, maybe you could call it pause()
instead of stop()
to better convey that it is not entirely stopped but just not producing values anymore temporarily?
I think it was also mentioned before, I find it confusing that we have this extra inheritance FallbackFormulaMetricFetcher
-> FallbackMetricFetcher
. Can't we get rid of FallbackMetricFetcher
? What is it for? We already have some unnecessary inheritance in the SDK from the past, I would prefer not to introduce more unless it is really necessary.
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.
Done, I made it Receiver.
b5bfa34
to
db41689
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.
Still looking into it, but got a couple of items.
src/frequenz/sdk/timeseries/formula_engine/_formula_generators/_formula_generator.py
Outdated
Show resolved
Hide resolved
first commit: |
...equenz/sdk/timeseries/formula_engine/_formula_generators/_fallback_formula_metric_fetcher.py
Outdated
Show resolved
Hide resolved
...equenz/sdk/timeseries/formula_engine/_formula_generators/_fallback_formula_metric_fetcher.py
Outdated
Show resolved
Hide resolved
FallbackMericFetcher stores fallback formula but generates and subscribes for it on demand. Signed-off-by: Elzbieta Kotulska <[email protected]>
Change PVPowerFormula to get primary and fallback of the given components. For the fallback comonents sub formulas are created This makes sure that both main and fallback formulas have the same behaviour and less complexity. Signed-off-by: Elzbieta Kotulska <[email protected]>
Signed-off-by: Elzbieta Kotulska <[email protected]>
This receiver is only to forward messages to subscribers. It doesn't need more then 1 last message. No tests are broken after this. Signed-off-by: Elzbieta Kotulska <[email protected]>
Signed-off-by: Elzbieta Kotulska <[email protected]>
Signed-off-by: Elzbieta Kotulska <[email protected]>
Previously if no_meter was True, meter was created but didn't send values. Now no meter is created. No tests are failing after this change Signed-off-by: Elzbieta Kotulska <[email protected]>
Signed-off-by: Elzbieta Kotulska <[email protected]>
Signed-off-by: Elzbieta Kotulska <[email protected]>
Signed-off-by: Elzbieta Kotulska <[email protected]>
And fix graph in test_batter_pool_power_two_batteries_per_inverter, Previously meters were connected to the grid and had no successors, inverters were connected to grid and had no meter. Now meters are connected to the inverters. Signed-off-by: Elzbieta Kotulska <[email protected]>
Fix mockMicrogrid: create senders always in the same order. Previous solution was working because we had simple graphs. Signed-off-by: Elzbieta Kotulska <[email protected]>
Signed-off-by: Elzbieta Kotulska <[email protected]>
Signed-off-by: Elzbieta Kotulska <[email protected]>
This should simplify code Signed-off-by: Elzbieta Kotulska <[email protected]>
I see 😢 |
ff0c626
to
1731ad4
Compare
The switch to I'd like to see two more changes, can be in this PR or can be turned into an issue:
NB: if you're doing it in this PR, please put in a new commit, so it is easier to read the changes. |
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.
This is great, one more really cool SDK feature!
Approving from my side, but please wait for @llucax's approval also.
Because that's where it is used. Signed-off-by: Elzbieta Kotulska <[email protected]>
Done (last commit)
In separate PR: #1056 |
I don't use that account anymore, so I won't be notified if you use it. The latest commit looks good as well. |
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.
This is great, one more really cool SDK feature!
➕ 1
Thanks for taking care of it!
Fallback components are used in generated formulas. If primary components is unavailable, formula will generate metric from fallback components. Fallback formulas are implemented for:
All necessary formulas are implemented in this PR