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 with_units_base feature #1232

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Add with_units_base feature #1232

wants to merge 2 commits into from

Conversation

GabrielKS
Copy link
Collaborator

Closes #1229 by adding a new exported function with_units_base that serves as a "context manager" to execute a block of code as if the system's units base were set to a particular value.

src/base.jl Outdated Show resolved Hide resolved
@GabrielKS GabrielKS self-assigned this Dec 23, 2024
Copy link

codecov bot commented Dec 23, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 84.31%. Comparing base (91bc0ab) to head (2708e09).
Report is 5 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1232      +/-   ##
==========================================
- Coverage   84.35%   84.31%   -0.04%     
==========================================
  Files         181      181              
  Lines        8375     8399      +24     
==========================================
+ Hits         7065     7082      +17     
- Misses       1310     1317       +7     
Flag Coverage Δ
unittests 84.31% <100.00%> (-0.04%) ⬇️

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/base.jl 88.98% <100.00%> (+0.10%) ⬆️

... and 2 files with indirect coverage changes

Copy link
Contributor

@daniel-thom daniel-thom left a comment

Choose a reason for hiding this comment

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

LGTM

@GabrielKS GabrielKS requested a review from jd-lara December 23, 2024 18:06
Copy link
Contributor

@kdayday kdayday left a comment

Choose a reason for hiding this comment

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

Could you add an example at the end of this tutorial section showing with_units_base? https://nrel-sienna.github.io/PowerSystems.jl/stable/tutorials/creating_system/#Changing-System-Per-Unit-Settings
and mention in https://nrel-sienna.github.io/PowerSystems.jl/stable/explanation/per_unit/ with the other functions (halfway down). Thanks!

end

"""
`with_units_base(function, system, units::Union{UnitSystem, String})`
Copy link
Contributor

Choose a reason for hiding this comment

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

Delete -- already taken care of with DocStringExtensions

Screenshot 2024-12-23 at 1 31 17 PM

"""
`with_units_base(function, system, units::Union{UnitSystem, String})`

A "context manager" similar to `Logging.with_logger` that sets the system's units base to
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
A "context manager" similar to `Logging.with_logger` that sets the system's units base to
A "context manager" that sets the [`System`](@ref)'s [units base](@ref per_unit) to

"""
`set_units_base_system!(system::System, units::Union{UnitSystem, String})`
Copy link
Contributor

Choose a reason for hiding this comment

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

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.

Move with_units here from PowerFlows.jl
3 participants