NREL-Sienna / InfrastructureSystems.jl

Utility package for Sienna's simulation infrastructure
https://nrel-sienna.github.io/InfrastructureSystems.jl/
BSD 3-Clause "New" or "Revised" License
38 stars 20 forks source link

MethodError: no method matching keys(::InfrastructureSystems.FlattenIteratorWrapper{Bus}) #280

Closed kdheepak closed 1 year ago

kdheepak commented 2 years ago

Currently keys is not defined for InfrastructureSystems.FlattenIteratorWrapper.

julia> create_graph(sys)
ERROR: MethodError: no method matching keys(::InfrastructureSystems.FlattenIteratorWrapper{Bus})
Closest candidates are:
  keys(::Union{Tables.AbstractColumns, Tables.AbstractRow}) at ~/.julia/packages/Tables/M26tI/src/Tables.jl:184
  keys(::Union{HDF5.File, HDF5.Group}) at ~/.julia/packages/HDF5/pIJra/src/HDF5.jl:943
  ...

This prevents users from using functions like findall(x -> x.name === get_from(get_arc(branch)).name, buses) where buses is a InfrastructureSystems.FlattenIteratorWrapper.

Workaround is to use findall(x -> x.name === get_from(get_arc(branch)).name, collect(buses)) at the moment.

jd-lara commented 2 years ago

Why would you expect for the FlattenIteratorWrapper have a methods keys if it isn't a dictionary? We have a method

get_components(Branch system, x -> get_name(get_from(get_arch(x))) == name) 

or if you have the bus:

get_components(Branch system, x -> get_from(get_arch(x)) == bus) 
claytonpbarrows commented 2 years ago

What about this:

julia> branch = first(get_components(Branch, sys))
B15 (TapTransformer):
   name: B15
   available: true
   active_power_flow: 0.0
   reactive_power_flow: 0.0
   arc: Balzac -> Barkla (Arc)
   r: 0.002
   x: 0.084
   primary_shunt: 0.0
   tap: 1.03
   rate: 4.0
   services: 0-element Vector{Service}
   ext: Dict{String, Any}()
   time_series_container: InfrastructureSystems.TimeSeriesContainer: 0
   InfrastructureSystems.SystemUnitsSettings:
      base_value: 100.0
      unit_system: UnitSystem.SYSTEM_BASE = 0

julia> buses = get_components(Bus, sys)
Bus Counts: 
Bus: 73

julia> findall(x -> x === get_name(get_from(get_arc(branch))), get_name.(buses))
1-element Vector{Int64}:
 45