-
Notifications
You must be signed in to change notification settings - Fork 81
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
Implement convert_component! for StandardLoad <- PowerLoad #1022
Merged
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -132,26 +132,51 @@ end | |
end | ||
|
||
@testset "Test component conversion" begin | ||
test_conversion = | ||
# Reusable resources for this testset | ||
load_test_system = () -> System(joinpath(BAD_DATA, "case5_re.m")) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use PSB here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done in 9c7ef0f, reverted the old test and now use PSB for the new one. |
||
function setup_time_series!(sys::System, component::Component, ts_name::String) | ||
dates = collect( | ||
Dates.DateTime("2020-01-01T00:00:00"):Dates.Hour(1):Dates.DateTime( | ||
"2020-01-01T23:00:00", | ||
), | ||
) | ||
data = collect(1:24) | ||
ta = TimeSeries.TimeArray(dates, data, [get_name(component)]) | ||
time_series = SingleTimeSeries(; name = ts_name, data = ta) | ||
add_time_series!(sys, component, time_series) | ||
@test get_time_series(SingleTimeSeries, component, ts_name) isa SingleTimeSeries | ||
end | ||
|
||
function test_forward_conversion( | ||
new_type::Type{<:Component}, | ||
old_component::Component, | ||
sys, | ||
component_name, | ||
ts_name, | ||
) | ||
convert_component!(new_type, old_component, sys) | ||
println(typeof(old_component)) | ||
@test isnothing(get_component(typeof(old_component), sys, component_name)) | ||
new_component = get_component(new_type, sys, component_name) | ||
@test !isnothing(new_component) | ||
@test get_name(new_component) == component_name | ||
@test get_time_series(SingleTimeSeries, new_component, ts_name) isa SingleTimeSeries | ||
return new_component | ||
end | ||
|
||
"""Tests Line <-> MonitoredLine conversion""" | ||
test_line_conversion = | ||
() -> begin | ||
sys = System(joinpath(BAD_DATA, "case5_re.m")) | ||
sys = load_test_system() | ||
l = get_component(Line, sys, "bus2-bus3-i_4") | ||
initial_time = Dates.DateTime("2020-01-01T00:00:00") | ||
dates = collect( | ||
initial_time:Dates.Hour(1):Dates.DateTime("2020-01-01T23:00:00"), | ||
) | ||
data = collect(1:24) | ||
ta = TimeSeries.TimeArray(dates, data, [get_name(l)]) | ||
name = "active_power_flow" | ||
time_series = SingleTimeSeries(; name = name, data = ta) | ||
add_time_series!(sys, l, time_series) | ||
@test get_time_series(SingleTimeSeries, l, name) isa SingleTimeSeries | ||
PSY.convert_component!(MonitoredLine, l, sys) | ||
@test isnothing(get_component(Line, sys, "bus2-bus3-i_4")) | ||
mline = get_component(MonitoredLine, sys, "bus2-bus3-i_4") | ||
@test !isnothing(mline) | ||
@test get_name(mline) == "bus2-bus3-i_4" | ||
@test get_time_series(SingleTimeSeries, mline, name) isa SingleTimeSeries | ||
ts_name = "active_power_flow" | ||
setup_time_series!(sys, l, ts_name) | ||
|
||
# Conversion to MonitoredLine | ||
mline = | ||
test_forward_conversion(MonitoredLine, l, sys, "bus2-bus3-i_4", ts_name) | ||
|
||
# Conversion back (must be forced) | ||
@test_throws ErrorException convert_component!( | ||
Line, | ||
get_component(MonitoredLine, sys, "bus2-bus3-i_4"), | ||
|
@@ -165,7 +190,23 @@ end | |
) | ||
line = get_component(Line, sys, "bus2-bus3-i_4") | ||
@test !isnothing(mline) | ||
@test get_time_series(SingleTimeSeries, line, name) isa SingleTimeSeries | ||
@test get_time_series(SingleTimeSeries, line, ts_name) isa SingleTimeSeries | ||
end | ||
@test_logs (:error,) min_level = Logging.Error match_mode = :any test_conversion() | ||
|
||
"""Tests PowerLoad --> StandardLoad conversion""" | ||
test_load_conversion = | ||
() -> begin | ||
sys = load_test_system() | ||
l = get_component(PowerLoad, sys, "bus2") | ||
ts_name = "max_active_power" | ||
setup_time_series!(sys, l, ts_name) | ||
|
||
# Conversion to StandardLoad | ||
sload = test_forward_conversion(StandardLoad, l, sys, "bus2", ts_name) | ||
|
||
# Conversion back is not implemented | ||
end | ||
|
||
@test_logs (:error,) min_level = Logging.Error match_mode = :any test_line_conversion() | ||
@test_logs (:error,) min_level = Logging.Error match_mode = :any test_load_conversion() | ||
end |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In Julia the argument after the
!
is the one being modified. In this case is the system that is being changed.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The existing
convert_component!
methods have the new type as the first argument, then the old component, then the system:PowerSystems.jl/src/base.jl
Lines 1922 to 1927 in 1b7c1c0
PowerSystems.jl/src/base.jl
Lines 1956 to 1961 in 1b7c1c0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I should. Fixed in 703762a.