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

Add ComponentSelector feature: PSY portion (take two) #1197

Open
wants to merge 40 commits into
base: main
Choose a base branch
from

Conversation

GabrielKS
Copy link
Collaborator

@GabrielKS GabrielKS commented Sep 18, 2024

Successor to #1079 and companion to/depends on NREL-Sienna/InfrastructureSystems.jl#342. Adds an immutable, lazy, system-independent representation of a grouped set of components. For more details and a demonstration, see https://github.nrel.gov/gkonars/PowerAnalytics-demos/blob/main/component_selector_pr_demo.ipynb.

GabrielKS and others added 20 commits September 25, 2024 16:37
 - Originally, all `ComponentSelector`s always filtered out components
   marked not available. This is what we want in `PowerAnalytics`, but
   not necessarily what is wanted if `ComponentSelector` is used
   elsewhere. The solution is to not automatically perform this
   filtering but add it as an option so that `PowerAnalytics` can still
   have it.
 - This commit also defines the behavior that using a
   `TopologyComponentSelector` on a system that does not have that
   topology element returns no components/subselectors.
@GabrielKS GabrielKS force-pushed the gks/td/component_selector_port branch from d2087ba to 1c65518 Compare September 25, 2024 22:37
@GabrielKS GabrielKS changed the title Move ComponentSelector from PowerAnalytics to InfrastructureSystems: PSY portion (take two) Add ComponentSelector feature: PSY portion (take two) Sep 26, 2024
@GabrielKS GabrielKS marked this pull request as ready for review September 26, 2024 00:31
@GabrielKS
Copy link
Collaborator Author

This is now ready for in-depth code review! Note the dependency on NREL-Sienna/InfrastructureSystems.jl#342. For a demonstration, see https://github.nrel.gov/gkonars/PowerAnalytics-demos/blob/main/component_selector_pr_demo.ipynb.

@GabrielKS GabrielKS self-assigned this Sep 27, 2024
Comment on lines 9 to 22
get_components(selector::ComponentSelector, sys::System; filterby = nothing) =
IS.get_components(selector, sys; filterby = filterby)

"""
get_components(filterby, selector, sys)
Get the components of the `System` that make up the `ComponentSelector`.
- `filterby`: optional filter function to apply after evaluating the `ComponentSelector`
"""
get_components(
filterby::Union{Nothing, Function},
selector::ComponentSelector,
sys::System,
) =
get_components(selector, sys; filterby = filterby)
Copy link
Contributor

@daniel-thom daniel-thom Sep 30, 2024

Choose a reason for hiding this comment

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

I think this would be slightly cleaner.

get_components(selector::ComponentSelector, sys::System) = IS.get_components(selector, sys)
get_components(filterby::Function, selector::ComponentSelector, sys::System) = IS.get_components(selector, sys; filterby = filterby)

Copy link
Contributor

Choose a reason for hiding this comment

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

filter_func instead of filterby? Even if the second is a better term, it's better to keep consistency in the docstrings.

Copy link
Contributor

Choose a reason for hiding this comment

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

Related to our offline discussion, the fact that you can create the component selector with a filter function and then pass a separate filter function here adds complexity and possibly confusion to the user interface.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Renamed this to scope_limiter to try to reduce confusion — see this thread in the IS PR.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

scope_limiter is now no longer part of the user interface (see the IS PR).

if there is none.
- `filterby`: optional filter function to apply after evaluating the `ComponentSelector`
"""
get_component(selector::SingularComponentSelector, sys::System; filterby = nothing) =
Copy link
Contributor

Choose a reason for hiding this comment

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

Similar to above, these methods could be defined without kwargs or unions.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm fine to add the method where the function is the first argument, but I'm hoping to keep the kwarg version as well — it makes more sense to me in the context where this would be used. Is that objectionable?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I was outvoted; the filterby kwarg is no more (see the IS PR)

@GabrielKS GabrielKS requested a review from daniel-thom October 4, 2024 17:44
::Type{T},
sys::System;
subsystem_name = nothing,
) where {T <: Component}
return IS.get_components(T, sys.data; subsystem_name = subsystem_name)
end

"""
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Moved to get_components_interface (though there's an argument it should appear here too)

@@ -1184,16 +1167,10 @@ function get_components_by_name(
return IS.get_components_by_name(T, sys.data, name)
end

"""
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Moved to get_components_interface (though there's an argument it should appear here too)

@GabrielKS
Copy link
Collaborator Author

GabrielKS commented Dec 12, 2024

@daniel-thom Ready for another review. Besides the changes in the IS PR, the main new change here is discussed at the top of get_components_interface.jl.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants