Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/PowerSystemCaseBuilder.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export PSISystems
export PSIDSystems
export SPISystems

export all_systems
export build_system
export list_categories
export show_categories
Expand Down
33 changes: 33 additions & 0 deletions src/system_catalog.jl
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,39 @@ function list_systems(catalog::SystemCatalog, category::Type{<:SystemCategory})
end
end

"""
Builds all [`PowerSystems.System`](@extref)s in the [`SystemCatalog`](@ref) and returns them
as a `Dict` keyed by `(category, system_name)` tuples.

Systems that require additional keyword arguments are built with their default arguments
where available. Systems that fail to build are skipped with a warning.

# Accepted Key Words
- `system_catalog::SystemCatalog`: Defaults to the `PowerSystemCaseBuilder.jl` catalog of
`System`s
- All other keyword arguments are forwarded to [`build_system`](@ref)
"""
function all_systems(;
system_catalog::SystemCatalog = SystemCatalog(),
kwargs...,
)
result = Dict{Tuple{DataType, String}, PSY.System}()
Comment thread
luke-kiernan marked this conversation as resolved.
for category in list_categories(system_catalog)
for name in list_systems(system_catalog, category)
try
result[(category, name)] = build_system(
category, name; system_catalog = system_catalog, kwargs...,
)
Comment thread
luke-kiernan marked this conversation as resolved.
catch e
e isa ErrorException || rethrow()
@warn "Skipping system $(category)/$(name)" exception =
(e, catch_backtrace())
end
end
end
return result
end

function SystemCatalog(system_catalogue::Array{SystemDescriptor} = SYSTEM_CATALOG)
data = Dict{DataType, Dict{String, SystemDescriptor}}()
unique_names = Set{String}()
Expand Down
21 changes: 21 additions & 0 deletions test/test_all_systems.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
@testset "all_systems" begin
# Test with a minimal catalog containing just one system
category = MatpowerTestSystems
name = first(list_systems(category))
sys = build_system(category, name)
@test sys isa PSY.System

# Test that all_systems returns a dict with the expected type
idx = findfirst(
d -> PSB.get_category(d) == category && PSB.get_name(d) == name,
PSB.SYSTEM_CATALOG,
)
@test idx !== nothing
small_descriptor = PSB.SYSTEM_CATALOG[something(idx)]
small_catalog = SystemCatalog([small_descriptor])
result = all_systems(; system_catalog = small_catalog)
@test result isa Dict{Tuple{DataType, String}, PSY.System}
@test length(result) == 1
@test haskey(result, (category, name))
@test result[(category, name)] isa PSY.System
end
Loading