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

Implement convert_component! for StandardLoad <- PowerLoad #1022

Merged
merged 3 commits into from
Oct 25, 2023

Conversation

GabrielKS
Copy link
Collaborator

This will be used for a new system in PowerSystemCaseBuilder. Includes unit tests.

  • Define convert_component! for conversions from PowerLoad to StandardLoad
  • Add unit tests for this method along the lines of existing convert_component! unit tests
  • Refactor convert_component! unit tests to remove repetition

 - Define convert_component! for conversions from PowerLoad to
   StandardLoad
 - Add unit tests for this method along the lines of existing
   convert_component! unit tests
 - Refactor convert_component! unit tests to remove repetition
@codecov
Copy link

codecov bot commented Oct 18, 2023

Codecov Report

Merging #1022 (703762a) into main (68cceae) will increase coverage by 0.00%.
The diff coverage is 77.77%.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #1022   +/-   ##
=======================================
  Coverage   85.37%   85.37%           
=======================================
  Files         169      169           
  Lines        7639     7646    +7     
=======================================
+ Hits         6522     6528    +6     
- Misses       1117     1118    +1     
Flag Coverage Δ
unittests 85.37% <77.77%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
src/base.jl 92.25% <77.77%> (-0.18%) ⬇️

... and 2 files with indirect coverage changes

src/base.jl Outdated
Comment on lines 1998 to 2002
function convert_component!(
new_type::Type{StandardLoad},
old_load::PowerLoad,
sys::System;
kwargs...,
Copy link
Member

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.

Suggested change
function convert_component!(
new_type::Type{StandardLoad},
old_load::PowerLoad,
sys::System;
kwargs...,
function convert_component!(
sys::System,
old_load::PowerLoad
new_type::Type{StandardLoad},
;
kwargs...,

Copy link
Collaborator Author

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

function convert_component!(
linetype::Type{MonitoredLine},
line::Line,
sys::System;
kwargs...,
)
and

PowerSystems.jl/src/base.jl

Lines 1956 to 1961 in 1b7c1c0

function convert_component!(
linetype::Type{Line},
line::MonitoredLine,
sys::System;
kwargs...,
)
and I was maintaining consistency with those. Should I change those existing methods to follow the Julia convention?

Copy link
Collaborator Author

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.

@@ -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"))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use PSB here

Copy link
Collaborator Author

@GabrielKS GabrielKS Oct 23, 2023

Choose a reason for hiding this comment

The 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.

Copy link
Member

@jd-lara jd-lara left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some changes are required.

ta = TimeSeries.TimeArray(dates, data, [component_name])
time_series = SingleTimeSeries(; name = ts_name, data = ta)
add_time_series!(sys, old_component, time_series)
@test get_time_series(SingleTimeSeries, old_component, ts_name) isa SingleTimeSeries
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
@test get_time_series(SingleTimeSeries, old_component, ts_name) isa SingleTimeSeries
@test get_time_series(SingleTimeSeries, old_component, ts_name) isa
SingleTimeSeries

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 703762a

new_component = get_component(StandardLoad, 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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
@test get_time_series(SingleTimeSeries, new_component, ts_name) isa SingleTimeSeries
@test get_time_series(SingleTimeSeries, new_component, ts_name) isa
SingleTimeSeries

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 703762a

@test get_time_series(SingleTimeSeries, new_component, ts_name) isa SingleTimeSeries
# Conversion back is not implemented
end

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 703762a

 - For all non-deprecated convert_component! methods, use the argument
   order: system, old component, new component type
 - Deprecate old convert_component! methods for backwards compatibility
 - Test deprecation
 - Run formatter
Copy link
Member

@jd-lara jd-lara left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@GabrielKS you need to run the formatter

@jd-lara jd-lara self-requested a review October 25, 2023 19:17
@jd-lara jd-lara merged commit 5b08a27 into main Oct 25, 2023
10 checks passed
@jd-lara jd-lara deleted the gks/convert-load branch October 25, 2023 19:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants