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 fast_deepcopy_system function, fix bug 1233, fix compare_values bug #1234

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 2 additions & 1 deletion src/PowerSystems.jl
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,8 @@ import InfrastructureSystems:
get_y_coords,
get_raw_data_type,
supports_time_series,
supports_supplemental_attributes
supports_supplemental_attributes,
fast_deepcopy_system
import InfrastructureSystems:
ValueCurve,
InputOutputCurve,
Expand Down
38 changes: 37 additions & 1 deletion src/base.jl
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ struct System <: IS.InfrastructureSystemsType
"unit_system kwarg ignored. The value in SystemUnitsSetting takes precedence"
)
end
bus_numbers = Set{Int}()
bus_numbers = Set(get_number.(IS.get_components(ACBus, data)))
return new(
data,
frequency,
Expand Down Expand Up @@ -2662,3 +2662,39 @@ function check_time_series_consistency(sys::System, ::Type{T}) where {T <: TimeS
end

stores_time_series_in_memory(sys::System) = IS.stores_time_series_in_memory(sys.data)

"""
Make a `deepcopy` of a [`System`](@ref) more quickly by skipping the copying of time
series and/or supplemental attributes.

# Arguments

- `data::System`: the `System` to copy
- `skip_time_series::Bool = true`: whether to skip copying time series
- `skip_supplemental_attributes::Bool = true`: whether to skip copying supplemental
attributes

Note that setting both `skip_time_series` and `skip_supplemental_attributes` to `false`
results in the same behavior as `deepcopy` with no performance improvement.
"""
function fast_deepcopy_system(
sys::System;
skip_time_series::Bool = true,
skip_supplemental_attributes::Bool = true,
)
new_data = IS.fast_deepcopy_system(
sys.data;
skip_time_series = skip_time_series,
skip_supplemental_attributes = skip_supplemental_attributes,
)
new_sys = System(
new_data,
deepcopy(sys.units_settings),
deepcopy(sys.internal);
runchecks = deepcopy(sys.runchecks[]),
frequency = deepcopy(sys.frequency),
time_series_directory = deepcopy(sys.time_series_directory),
name = deepcopy(sys.metadata.name),
description = deepcopy(sys.metadata.description))
return new_sys
end
25 changes: 25 additions & 0 deletions test/test_system.jl
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,31 @@ end
end
end

@testset "Test fast deepcopy of system" begin
systems = Dict(
in_memory => PSB.build_system(
PSITestSystems,
"test_RTS_GMLC_sys";
time_series_in_memory = in_memory,
force_build = true,
) for in_memory in (true, false)
)
@testset for (in_memory, skip_ts, skip_sa) in # Iterate over all permutations
Iterators.product(repeat([(true, false)], 3)...)
sys = systems[in_memory]

sys2 = IS.fast_deepcopy_system(sys;
skip_time_series = skip_ts, skip_supplemental_attributes = skip_sa)
@test IS.compare_values(
sys,
sys2;
exclude = Set(
[:time_series_manager, :supplemental_attribute_manager][[skip_ts, skip_sa]],
),
)
end
end

@testset "Test with compression enabled" begin
@test get_compression_settings(System(100.0)) == CompressionSettings(; enabled = false)

Expand Down
Loading