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

Read export metadata file for round trip with PowerFlows.jl's PSS/E exporter #1273

Merged
merged 9 commits into from
Jan 31, 2025

Conversation

GabrielKS
Copy link
Collaborator

@GabrielKS GabrielKS commented Jan 31, 2025

Here, I implement logic such that when System("my_filename.raw") is called, PowerSystems will check for a my_filename_export_metadata.json file written by the PowerFlows.jl PSS/E exporter in the same directory and, if it is found, use its contents to undo the system alterations PowerFlows had to make to write to the PSS/E format. The goal is for systems loaded this way to look as similar to the original system that was serialized as possible. The user can opt out of this feature by passing try_reimport = false. There is also interface to manually pass a metadata dictionary to perform this same remapping.

In the process of implementation, I also added a area_name_formatter System constructor kwarg along the same lines as #1160.

No unit tests are currently included. Up until now, this functionality was implemented in PowerFlows.jl, and there are fairly detailed but not perfectly comprehensive tests of this functionality due to the testing of the round trip fidelity over there. Looking for reviewer input on whether that is sufficient to merge this now or whether dedicated unit tests in PowerSystems are required first.

Exporter is implemented in NREL-Sienna/PowerFlows.jl#53 and that PR now depends on this one.

@daniel-thom don't feel obligated to fully review, just tagging you in case you have opinions on how I'm messing with the System constructor.

Copy link

codecov bot commented Jan 31, 2025

Codecov Report

Attention: Patch coverage is 17.10526% with 63 lines in your changes missing coverage. Please review.

Project coverage is 83.74%. Comparing base (718f842) to head (e90f6d9).
Report is 13 commits behind head on main.

Files with missing lines Patch % Lines
src/parsers/psse_metadata_reimport.jl 0.00% 61 Missing ⚠️
src/base.jl 83.33% 2 Missing ⚠️

❌ Your patch status has failed because the patch coverage (17.10%) is below the target coverage (70.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1273      +/-   ##
==========================================
- Coverage   84.35%   83.74%   -0.62%     
==========================================
  Files         183      184       +1     
  Lines        8451     8519      +68     
==========================================
+ Hits         7129     7134       +5     
- Misses       1322     1385      +63     
Flag Coverage Δ
unittests 83.74% <17.10%> (-0.62%) ⬇️

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

Files with missing lines Coverage Δ
src/PowerSystems.jl 0.00% <ø> (ø)
src/parsers/power_models_data.jl 90.14% <100.00%> (+0.05%) ⬆️
src/base.jl 89.36% <83.33%> (-0.18%) ⬇️
src/parsers/psse_metadata_reimport.jl 0.00% <0.00%> (ø)

function remap_bus_numbers!(sys::System, bus_number_mapping)
for bus in collect(get_components(Bus, sys))
set_number!(bus, parse(Int, bus_number_mapping[get_number(bus)]))
end
Copy link
Contributor

@daniel-thom daniel-thom Jan 31, 2025

Choose a reason for hiding this comment

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

sys.bus_numbers is now out-of-date. You also need to guarantee unique numbers.

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 bus_number_mapping is a reversed dictionary so that guarantees uniqueness. I can modify sys.bus_numbers, but isn't it a bug for public interface to be able to put the system into an inconsistent state?

Copy link
Contributor

Choose a reason for hiding this comment

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

We could set exclude_setter = true in power_system_structs.json and then add a function for set_bus!(::System, ::Bus), similar to set_name!.

Copy link
Member

Choose a reason for hiding this comment

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

I think this solution is ok for now and we can revise the bus renumbering in PSY 6. I think that when we re-design the capability to read/write to the DB this will come back

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'll fix it as a one-off here for now, principled solution tracked at #1274

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done

end

function remap_bus_numbers!(sys::System, bus_number_mapping)
for bus in collect(get_components(Bus, sys))
Copy link
Member

Choose a reason for hiding this comment

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

why are we calling collect here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

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.

The PR looks fine to me but we need to add an issue to increase test coverage.

@GabrielKS
Copy link
Collaborator Author

The PR looks fine to me but we need to add an issue to increase test coverage.

-> #1275

@jd-lara jd-lara merged commit 3b39831 into main Jan 31, 2025
10 of 11 checks passed
@jd-lara jd-lara deleted the gks/reimport_psse_metadata branch February 1, 2025 01:06
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.

3 participants