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

BatteryPool should be more explicit about using all components or a given set of component ids #949

Open
Marenz opened this issue May 15, 2024 · 10 comments
Labels
part:microgrid Affects the interactions with the microgrid priority:❓ We need to figure out how soon this should be addressed scope:breaking-change Breaking change, users will need to update their code type:enhancement New feature or enhancement visitble to users
Milestone

Comments

@Marenz
Copy link
Contributor

Marenz commented May 15, 2024

What's needed?

Working a bit with the scenario of possibly changing component ids in the FCR actor, I found it cumbersome that
the empty set had the special meaning of "use all components".

Proposed solution

I propose we:

  • Add an explicit parameter use_all_components: bool
  • Also add a new getter using_all_components: bool to explicitly know if it is using all components or a a specific set

Use cases

No response

Alternatives and workarounds

No response

Additional context

No response

@Marenz Marenz added part:❓ We need to figure out which part is affected priority:❓ We need to figure out how soon this should be addressed type:enhancement New feature or enhancement visitble to users labels May 15, 2024
@llucax
Copy link
Contributor

llucax commented May 16, 2024

So calling without either some component_ids or use_all_components will be an error? I don't like that it makes the interface more complicated and that you can end up with some exception if you call it with the wrong combination of arguments.

Also, why it is important to know if it was created with all available components or not? It would be good to explain the user case a little bit.

@llucax llucax added this to the Untriaged milestone May 16, 2024
@Marenz
Copy link
Contributor Author

Marenz commented May 16, 2024

It's fundamentally different if you use the pool with "use everything you can, even new things" and "use this fixed set of ids" and right now it's non-trivial to find out which of those two cases it is, once the pool is created.

and because it is so fundamentally different, I feel it should be setup differently, too.

So calling without either some component_ids or use_all_components will be an error?

No I think it' still fine to have use_all as default, it just shouldn't be use_all if you pass an empty set or None, imo, that mixes the two different cases too much.

Also, why it is important to know if it was created with all available components or not? It would be good to explain the user case a little bit.

Probably becoming less relevant once the SDK does pool caching or so, but it would help to then decide if you want to recreate the pool because you need a different set of ids (or all)

@llucax
Copy link
Contributor

llucax commented May 17, 2024

OK, I see your point now, but I if the issue is the interface being confusing and error prone, then I think your suggestion introduces other set of issues, as we have an overlapping set of options.

What about creating a sentinel value USE_ALL and make the signature: new_pool(batteries: USE_ALL | Set[int] = USE_ALL)? Then we can make passing an empty set an error and I think the interface should be pretty clear and explicit.

Then we can expose the requested batteries as a property (which might be different to the "currently used batteries", we should expose this as a separate property), which will have the info if you requested all or a fixed set.

@llucax llucax added part:microgrid Affects the interactions with the microgrid and removed part:❓ We need to figure out which part is affected labels May 17, 2024
@llucax
Copy link
Contributor

llucax commented May 17, 2024

@jh2007github this might be a good issue for you to pick up.

@shsms
Copy link
Contributor

shsms commented Jun 26, 2024

It's fundamentally different if you use the pool with "use everything you can, even new things" and "use this fixed set of ids" and right now it's non-trivial to find out which of those two cases it is, once the pool is created.

Sorry, a bit late, but this is not entirely accurate. When nothing is specified, it uses the available components at start. It doesn't pick up new or dropped components dynamically:

self._batteries: frozenset[int]
if batteries_id:
self._batteries = frozenset(batteries_id)
else:
self._batteries = self._get_all_batteries()

It just checks the component graph one time, so even components that are not connected, but present in the component graph are added. So there's no real difference between how they behave, and using battery_pool.component_ids would be stable irrespective of how it was created.

Also, using newly added components is not really possible without a restart. The component graph doesn't get updated once setup. We were discussing in the early days about having a trigger to automatically update the component graph when there are changes and rebuild the formulas, and reconfigure the power distributor, etc. But that's all a lot of work, and hasn't been prioritized because it happens so rarely and we've just been restarting the apps.

All that said, I'm still ok with the proposal from Luca of having USE_ALL rather than an empty set as code to automatically fetch the components.

@llucax
Copy link
Contributor

llucax commented Jun 26, 2024

Third option is to take only a set, without any special meaning, and having a simple function to get all components of a particular category. Then it is new_battery_pool(get_all_batteries()). Super explicit also and we get an extra convenience feature of being able to retrieve all components of a category, but it requires extra work and it is considerably more verbose.

@Marenz
Copy link
Contributor Author

Marenz commented Jun 26, 2024

Then it is new_battery_pool(get_all_batteries()).

While I do like that idea, I think we should try to make the most common case the most convenient one, too.
Maybe this + factory function?

@llucax
Copy link
Contributor

llucax commented Jun 27, 2024

Yeah, even when I like explicitness a lot, I also have my doubts if it is just too long for the most common case. What do you mean by "this + factory function"?

@Marenz
Copy link
Contributor Author

Marenz commented Jun 27, 2024

your suggestion as is, additionally a convenience function to do exactly what your suggestion says

@llucax
Copy link
Contributor

llucax commented Jun 27, 2024

Also taking some distance from the topic and just reading pool = microgrid.new_battery_pool() for me there is not much other option than getting a pool with all the available batteries. So not sure if we really need a change here. I guess the original issue was it was confusing to have pool = microgrid.new_battery_pool(set()) get all the batteries, and this is true, so back to new_pool(batteries: USE_ALL | set[int] = USE_ALL), this sounds reasonable (it is still new_battery_pool() the default to get all) and we can make receiving an empty set an error.

@llucax llucax modified the milestones: Untriaged, v1.0.0 Jul 29, 2024
@llucax llucax added the scope:breaking-change Breaking change, users will need to update their code label Jul 29, 2024
@llucax llucax modified the milestones: v1.0.0, v1.0.0-rc800 Aug 2, 2024
@shsms shsms modified the milestones: v1.0.0-rc800, v1.0.0-rc900 Aug 22, 2024
@llucax llucax modified the milestones: v1.0.0-rc900, 1.0.0-rc1000 Sep 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
part:microgrid Affects the interactions with the microgrid priority:❓ We need to figure out how soon this should be addressed scope:breaking-change Breaking change, users will need to update their code type:enhancement New feature or enhancement visitble to users
Projects
Status: To do
Development

No branches or pull requests

3 participants