Skip to content

Commit

Permalink
Merge pull request #92 from NREL-Sienna/jd/rename_storage
Browse files Browse the repository at this point in the history
Jd/rename storage
  • Loading branch information
jd-lara authored May 16, 2024
2 parents 71cd729 + 44f3e86 commit 5ebd6ad
Show file tree
Hide file tree
Showing 9 changed files with 78 additions and 73 deletions.
47 changes: 10 additions & 37 deletions src/build_system.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,47 +25,22 @@ function build_system(
)
sys_descriptor = get_system_descriptor(category, system_catalog, name)
sys_kwargs = filter_kwargs(; kwargs...)
sys_keys = keys(sys_kwargs)

psid_kwargs = check_kwargs_psid(; kwargs...)
psid_keys = keys(psid_kwargs)

case_keys = get_supported_argument_names(sys_descriptor)

if !(isempty(intersect(sys_keys, psid_keys)))
error(
"sys_keys and psid_keys have the overlapping key(s): $(intersect(sys_keys, psid_keys))",
)
case_kwargs = filter_descriptor_kwargs(sys_descriptor; kwargs...)
if length(kwargs) > length(sys_kwargs) + length(case_kwargs)
unexpected = setdiff(keys(kwargs), union(keys(sys_kwargs), keys(case_kwargs)))
error("These keyword arguments are not supported: $unexpected")
end

if !(isempty(intersect(sys_keys, case_keys)))
error(
"sys_keys and case_keys have the overlapping key(s): $(intersect(sys_keys, psid_keys))",
)
duplicates = intersect(keys(sys_kwargs), keys(case_kwargs))
if !isempty(duplicates)
error("System kwargs and case kwargs have overlapping keys: $duplicates")
end

if !isempty(psid_kwargs)
kwarg_type = first(values(psid_kwargs))
name = "$(name)_$kwarg_type"
end

non_sys_psid_kwargs = setdiff(kwargs, merge(psid_kwargs, sys_kwargs))
non_sys_psid_args = Dict{Symbol, Any}(k => v for (k, v) in non_sys_psid_kwargs)
key_diff = setdiff(keys(non_sys_psid_args), case_keys)
if !isempty(key_diff)
throw(ArgumentError("unsupported kwargs are specified: $key_diff"))
end

case_args = Dict{Symbol, Any}(
merge(get_supported_arguments_dict(sys_descriptor), non_sys_psid_args),
)

return _build_system(
name,
sys_descriptor,
case_args,
case_kwargs,
sys_kwargs,
psid_kwargs,
print_stat;
force_build,
assign_new_uuids,
Expand All @@ -78,7 +53,6 @@ function _build_system(
sys_descriptor::SystemDescriptor,
case_args::Dict{Symbol, <:Any},
sys_args::Dict{Symbol, <:Any},
psid_args::Dict{Symbol, <:Any},
print_stat::Bool = false;
force_build::Bool = false,
assign_new_uuids::Bool = false,
Expand All @@ -98,14 +72,13 @@ function _build_system(
raw_data = sys_descriptor.raw_data,
case_args...,
sys_args...,
psid_args...,
)
construct_time = time() - start
#construct_time = time() - start
serialized_filepath = get_serialized_filepath(name, case_args)
start = time()
if !skip_serialization
PSY.to_json(sys, serialized_filepath; force = true)
serialize_time = time() - start
#serialize_time = time() - start
serialize_case_parameters(case_args)
end
# set_stats!(sys_descriptor, SystemBuildStats(construct_time, serialize_time))
Expand Down
1 change: 0 additions & 1 deletion src/definitions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ const SERIALIZED_DIR = joinpath(PACKAGE_DIR, "data", "serialized_system")
const SERIALIZE_FILE_EXTENSIONS =
[".json", "_metadata.json", "_validation_descriptors.json", "_time_series_storage.h5"]

const ACCEPTED_PSID_TEST_SYSTEMS_KWARGS = [:avr_type, :tg_type, :pss_type, :gen_type]
const AVAILABLE_PSID_PSSE_AVRS_TEST =
["AC1A", "AC1A_SAT", "EXAC1", "EXST1", "SEXS", "SEXS_noTE"]

Expand Down
2 changes: 1 addition & 1 deletion src/library/psi_library.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1381,7 +1381,7 @@ function _duplicate_system(main_sys::PSY.System, twin_sys::PSY.System, HVDC_line
PSY.add_component!(main_sys, new_ACLine)
end

for bat in get_components(GenericBattery, main_sys)
for bat in get_components(EnergyReservoirStorage, main_sys)
set_base_power!(bat, get_base_power(bat) * 10)
end

Expand Down
54 changes: 37 additions & 17 deletions src/library/psitest_library.jl
Original file line number Diff line number Diff line change
Expand Up @@ -747,18 +747,18 @@ function build_c_sys5_bat(;
PSY.add_service!(
c_sys5_bat,
reserve_bat[1],
PSY.get_components(PSY.GenericBattery, c_sys5_bat),
PSY.get_components(PSY.EnergyReservoirStorage, c_sys5_bat),
)
PSY.add_service!(
c_sys5_bat,
reserve_bat[2],
PSY.get_components(PSY.GenericBattery, c_sys5_bat),
PSY.get_components(PSY.EnergyReservoirStorage, c_sys5_bat),
)
# ORDC
PSY.add_service!(
c_sys5_bat,
reserve_bat[3],
PSY.get_components(PSY.GenericBattery, c_sys5_bat),
PSY.get_components(PSY.EnergyReservoirStorage, c_sys5_bat),
)
for (ix, serv) in enumerate(PSY.get_components(PSY.VariableReserve, c_sys5_bat))
forecast_data = SortedDict{Dates.DateTime, TimeSeries.TimeArray}()
Expand Down Expand Up @@ -2496,7 +2496,7 @@ function build_test_RTS_GMLC_sys_with_hybrid(; raw_data, add_forecasts, kwargs..
thermal_unit = first(get_components(ThermalStandard, sys))
bus = get_bus(thermal_unit)
electric_load = first(get_components(PowerLoad, sys))
storage = first(get_components(GenericBattery, sys))
storage = first(get_components(EnergyReservoirStorage, sys))
renewable_unit = first(get_components(RenewableDispatch, sys))

name = "Test H"
Expand Down Expand Up @@ -2563,7 +2563,7 @@ function build_c_sys5_bat_ems(;
Deterministic("max_active_power", forecast_data),
)
end
for (ix, r) in enumerate(get_components(PSY.BatteryEMS, c_sys5_bat))
for (ix, r) in enumerate(get_components(PSY.EnergyReservoirStorage, c_sys5_bat))
forecast_data = SortedDict{Dates.DateTime, TimeArray}()
for t in 1:2
ini_time = timestamp(storage_target_DA[t][1])[1]
Expand Down Expand Up @@ -2593,7 +2593,7 @@ function build_c_sys5_bat_ems(;
),
)
end
for (ix, b) in enumerate(PSY.get_components(PSY.BatteryEMS, c_sys5_bat))
for (ix, b) in enumerate(PSY.get_components(PSY.EnergyReservoirStorage, c_sys5_bat))
PSY.add_time_series!(
c_sys5_bat,
b,
Expand All @@ -2606,10 +2606,22 @@ function build_c_sys5_bat_ems(;
end
if add_reserves
reserve_bat = reserve5_re(get_components(RenewableDispatch, c_sys5_bat))
add_service!(c_sys5_bat, reserve_bat[1], get_components(PSY.BatteryEMS, c_sys5_bat))
add_service!(c_sys5_bat, reserve_bat[2], get_components(PSY.BatteryEMS, c_sys5_bat))
add_service!(
c_sys5_bat,
reserve_bat[1],
get_components(PSY.EnergyReservoirStorage, c_sys5_bat),
)
add_service!(
c_sys5_bat,
reserve_bat[2],
get_components(PSY.EnergyReservoirStorage, c_sys5_bat),
)
# ORDC
add_service!(c_sys5_bat, reserve_bat[3], get_components(PSY.BatteryEMS, c_sys5_bat))
add_service!(
c_sys5_bat,
reserve_bat[3],
get_components(PSY.EnergyReservoirStorage, c_sys5_bat),
)
for (ix, serv) in enumerate(get_components(VariableReserve, c_sys5_bat))
forecast_data = SortedDict{Dates.DateTime, TimeArray}()
for t in 1:2
Expand Down Expand Up @@ -2684,9 +2696,10 @@ function build_c_sys5_hybrid(; add_forecasts, raw_data, kwargs...)
thermals = thermal_generators5(nodes)
loads = loads5(nodes)
renewables = renewable_generators5(nodes)
_battery(nodes, bus, name) = PSY.BatteryEMS(;
_battery(nodes, bus, name) = PSY.EnergyReservoirStorage(;
name = name,
prime_mover_type = PrimeMovers.BA,
storage_technology_type = StorageTech.OTHER_CHEM,
available = true,
bus = nodes[bus],
initial_energy = 5.0,
Expand Down Expand Up @@ -2868,9 +2881,10 @@ function build_c_sys5_hybrid_uc(; add_forecasts, raw_data, kwargs...)
loads = loads5(nodes)
renewables = renewable_generators5(nodes)
branches = branches5(nodes)
_battery(nodes, bus, name) = PSY.BatteryEMS(;
_battery(nodes, bus, name) = PSY.EnergyReservoirStorage(;
name = name,
prime_mover_type = PrimeMovers.BA,
storage_technology_type = StorageTech.OTHER_CHEM,
available = true,
bus = nodes[bus],
initial_energy = 5.0,
Expand Down Expand Up @@ -2997,9 +3011,10 @@ function build_c_sys5_hybrid_ed(; add_forecasts, raw_data, kwargs...)
loads = loads5(nodes)
branches = branches5(nodes)
renewables = renewable_generators5(nodes)
_battery(nodes, bus, name) = PSY.BatteryEMS(;
_battery(nodes, bus, name) = PSY.EnergyReservoirStorage(;
name = name,
prime_mover_type = PrimeMovers.BA,
storage_technology_type = StorageTech.OTHER_CHEM,
available = true,
bus = nodes[bus],
initial_energy = 5.0,
Expand Down Expand Up @@ -3445,9 +3460,10 @@ function build_batt_test_case_b_sys(; raw_data, kwargs...)
100.0,
)

batt = PSY.BatteryEMS(;
batt = PSY.EnergyReservoirStorage(;
name = "Bat2",
prime_mover_type = PrimeMovers.BA,
storage_technology_type = StorageTech.OTHER_CHEM,
available = true,
bus = node,
initial_energy = 5.0,
Expand Down Expand Up @@ -3521,9 +3537,10 @@ function build_batt_test_case_c_sys(; raw_data, kwargs...)
100.0,
)

batt = PSY.BatteryEMS(;
batt = PSY.EnergyReservoirStorage(;
name = "Bat2",
prime_mover_type = PrimeMovers.BA,
storage_technology_type = StorageTech.OTHER_CHEM,
available = true,
bus = node,
initial_energy = 2.0,
Expand Down Expand Up @@ -3597,9 +3614,10 @@ function build_batt_test_case_d_sys(; raw_data, kwargs...)
100.0,
)

batt = PSY.BatteryEMS(;
batt = PSY.EnergyReservoirStorage(;
name = "Bat2",
prime_mover_type = PrimeMovers.BA,
storage_technology_type = StorageTech.OTHER_CHEM,
available = true,
bus = node,
initial_energy = 2.0,
Expand Down Expand Up @@ -3673,9 +3691,10 @@ function build_batt_test_case_e_sys(; raw_data, kwargs...)
100.0,
)

batt = PSY.BatteryEMS(;
batt = PSY.EnergyReservoirStorage(;
name = "Bat2",
prime_mover_type = PrimeMovers.BA,
storage_technology_type = StorageTech.OTHER_CHEM,
available = true,
bus = node,
initial_energy = 2.0,
Expand Down Expand Up @@ -3749,9 +3768,10 @@ function build_batt_test_case_f_sys(; raw_data, kwargs...)
100.0,
)

batt = PSY.BatteryEMS(;
batt = PSY.EnergyReservoirStorage(;
name = "Bat2",
prime_mover_type = PrimeMovers.BA,
storage_technology_type = StorageTech.OTHER_CHEM,
available = true,
bus = node,
initial_energy = 1.0,
Expand Down
3 changes: 2 additions & 1 deletion src/library/psytest_library.jl
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,10 @@ function build_dynamic_inverter_sys(; kwargs...)
),
]

battery = PSY.GenericBattery(;
battery = PSY.EnergyReservoirStorage(;
name = "Battery",
prime_mover_type = PSY.PrimeMovers.BA,
storage_technology_type = StorageTech.OTHER_CHEM,
available = true,
bus = nodes_OMIB[2],
initial_energy = 5.0,
Expand Down
28 changes: 24 additions & 4 deletions src/system_descriptor.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ end

function SystemArgument(;
name,
default,
default = nothing,
allowed_values,
)
return SystemArgument(
Expand Down Expand Up @@ -69,9 +69,14 @@ get_build_function(v::SystemDescriptor) = v.build_function
get_download_function(v::SystemDescriptor) = v.download_function
get_stats(v::SystemDescriptor) = v.stats
get_supported_arguments(v::SystemDescriptor) = v.supported_arguments
get_supported_arguments_dict(v::SystemDescriptor) =
Dict(arg.name => arg.default for arg in v.supported_arguments)
get_supported_argument_names(v::SystemDescriptor) = [x.name for x in v.supported_arguments]
get_supported_argument_names(v::SystemDescriptor) =
Set([x.name for x in v.supported_arguments])

function get_default_arguments(v::SystemDescriptor)
Dict{Symbol, Any}(
x.name => x.default for x in v.supported_arguments if !isnothing(x.default)
)
end

function get_supported_args_permutations(v::SystemDescriptor)
keys_arr = get_supported_argument_names(v)
Expand Down Expand Up @@ -110,3 +115,18 @@ set_stats!(v::SystemDescriptor, value::SystemBuildStats) = v.stats = value

update_stats!(v::SystemDescriptor, deserialize_time::Float64) =
update_stats!(v.stats, deserialize_time)

"""
Return the keyword arguments passed by the user that apply to the descriptor.
Add any default values for fields not passed by the user.
"""
function filter_descriptor_kwargs(descriptor::SystemDescriptor; kwargs...)
case_arg_names = get_supported_argument_names(descriptor)
case_kwargs = get_default_arguments(descriptor)
for (key, val) in kwargs
if key in case_arg_names
case_kwargs[key] = val
end
end
return case_kwargs
end
4 changes: 0 additions & 4 deletions src/system_descriptor_data.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1417,7 +1417,6 @@ const SYSTEM_CATALOG = [
supported_arguments = [
SystemArgument(;
name = :avr_type,
default = "AC1A",
allowed_values = Set(AVAILABLE_PSID_PSSE_AVRS_TEST),
),
],
Expand All @@ -1431,7 +1430,6 @@ const SYSTEM_CATALOG = [
supported_arguments = [
SystemArgument(;
name = :tg_type,
default = "GAST",
allowed_values = Set(AVAILABLE_PSID_PSSE_TGS_TEST),
),
],
Expand All @@ -1445,7 +1443,6 @@ const SYSTEM_CATALOG = [
supported_arguments = [
SystemArgument(;
name = :gen_type,
default = "GENCLS",
allowed_values = Set(AVAILABLE_PSID_PSSE_GENS_TEST),
),
],
Expand All @@ -1459,7 +1456,6 @@ const SYSTEM_CATALOG = [
supported_arguments = [
SystemArgument(;
name = :pss_type,
default = "STAB1",
allowed_values = Set(AVAILABLE_PSID_PSSE_PSS_TEST),
),
],
Expand Down
5 changes: 0 additions & 5 deletions src/utils/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,6 @@ function filter_kwargs(; kwargs...)
return system_kwargs
end

function check_kwargs_psid(; kwargs...)
psid_kwargs = filter(x -> in(first(x), ACCEPTED_PSID_TEST_SYSTEMS_KWARGS), kwargs)
return psid_kwargs
end

"""
Creates a JSON file informing the user about the meaning of the hash value in the file path
if it doesn't exist already
Expand Down
7 changes: 4 additions & 3 deletions test/test_psidtestsystems.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ const PSID_BUILD_TESTS =
system_catalog = SystemCatalog(SYSTEM_CATALOG)
for case_type in [PSIDTestSystems, PSIDSystems]
for (name, descriptor) in system_catalog.data[case_type]
supported_args_permutations = PSB.get_supported_args_permutations(descriptor)
# build a new system from scratch
if name in PSID_BUILD_TESTS
supported_args_permutations =
PSB.get_supported_args_permutations(descriptor)
@test !isempty(supported_args_permutations)
for supported_arg in supported_args_permutations
sys = build_system(
case_type,
Expand All @@ -17,7 +18,7 @@ const PSID_BUILD_TESTS =
)
@test isa(sys, System)
# build a new system from json
@test PSB.is_serialized("$(name)_$(first(supported_arg)[2])")
@test PSB.is_serialized(name, supported_arg)
sys2 = build_system(
case_type,
name;
Expand Down

0 comments on commit 5ebd6ad

Please sign in to comment.