Skip to content

Commit

Permalink
Merge pull request #1038 from daniel-thom/issue-1037
Browse files Browse the repository at this point in the history
Fix serialization of System.frequency
  • Loading branch information
jd-lara authored Jan 9, 2024
2 parents 073ae04 + eb2f6ea commit 4e2ff11
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/base.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1407,7 +1407,16 @@ function IS.deserialize(

# Read any field that is defined in System but optional for the constructors and not
# already handled here.
handled = ("data", "units_settings", "bus_numbers", "internal", "data_format_version")
handled = (
"data",
"units_settings",
"bus_numbers",
"internal",
"data_format_version",
"metadata",
"name",
"description",
)
parsed_kwargs = Dict{Symbol, Any}()
for field in setdiff(keys(raw), handled)
parsed_kwargs[Symbol(field)] = raw[field]
Expand All @@ -1429,7 +1438,14 @@ function IS.deserialize(
name = get(metadata, "name", nothing)
description = get(metadata, "description", nothing)
internal = IS.deserialize(InfrastructureSystemsInternal, raw["internal"])
sys = System(data, units, internal; name = name, description = description, kwargs...)
sys = System(
data,
units,
internal;
name = name,
description = description,
parsed_kwargs...,
)

if raw["data_format_version"] != DATA_FORMAT_VERSION
pre_deserialize_conversion!(raw, sys)
Expand Down
23 changes: 23 additions & 0 deletions test/test_serialization.jl
Original file line number Diff line number Diff line change
Expand Up @@ -244,3 +244,26 @@ end
),
)
end

@testset "Test serialization of System fields" begin
frequency = 50.0
name = "my_system"
description = "test"
sys = System(100; frequency = frequency, name = name, description = description)
bus = ACBus(nothing)
bus.name = "bus1"
bus.number = 1
# This prevents an error log message.
bus.bustype = ACBusTypes.REF
add_component!(sys, bus)
gen = ThermalStandard(nothing)
gen.bus = bus
gen.name = "gen1"
add_component!(sys, gen)

sys2, result = validate_serialization(sys)
@test result
@test sys2.frequency == frequency
@test sys2.metadata.name == name
@test sys2.metadata.description == description
end

0 comments on commit 4e2ff11

Please sign in to comment.