Skip to content

Replace SystemUnitsSettings with a plain Float64 units anchor#596

Open
luke-kiernan wants to merge 3 commits into
IS4from
units-refactor-is4
Open

Replace SystemUnitsSettings with a plain Float64 units anchor#596
luke-kiernan wants to merge 3 commits into
IS4from
units-refactor-is4

Conversation

@luke-kiernan

Copy link
Copy Markdown
Contributor

Remove the final pieces of the stateful units system. In InfrastructureSystemsInternal, the shared reference units_info:: SystemUnitsSetting is now replaced by base_value::Union{Nothing, Float64}: the system's base power for an attached component, nothing for an unattached component. get_base_value/set_base_value! have a generic default which forwards to the internal field, so components get their "system base" anchor for free.

@m-bossart Your TransformerCircuit can now carry its own base_value::Union{Nothing, Float64} and override IS. {get, set}_base_value{!}. The units plumbing will work appropriately. The code to keep that base_value field up-to-date still lands in PSY, though, which seems mildly clunky. This is the best I can come up with, though.

The unit_system field on SystemUnitsSettings was a leftover from the
stateful-units era: it made the struct mutable and shared by reference
across every attached component so a system-wide unit change would
propagate instantly, but that whole mechanism is being retired (see
matching PowerSystems.jl change). The only thing components genuinely
need is the system's base power, a plain number that never changes
after construction.

InfrastructureSystemsInternal.units_info is now Union{Nothing, Float64}.
get_units_info/set_units_info! are renamed get_base_value/set_base_value!
and gain a generic default (get_base_value(x) = get_base_value(get_internal(x)))
so any type implementing get_internal picks it up for free, and a type
that stores its own anchor directly (no InfrastructureSystemsInternal)
can add one small concrete method instead of a parallel mechanism.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@codecov

codecov Bot commented Jul 17, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 87.50000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 84.14%. Comparing base (0289b71) to head (112422e).
⚠️ Report is 1 commits behind head on IS4.

Files with missing lines Patch % Lines
src/time_series_metadata_store.jl 66.66% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##              IS4     #596      +/-   ##
==========================================
+ Coverage   83.99%   84.14%   +0.15%     
==========================================
  Files          73       73              
  Lines        6334     6327       -7     
==========================================
+ Hits         5320     5324       +4     
+ Misses       1014     1003      -11     
Flag Coverage Δ
unittests 84.14% <87.50%> (+0.15%) ⬆️

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

Files with missing lines Coverage Δ
src/internal.jl 92.06% <100.00%> (+7.68%) ⬆️
src/utils/print.jl 70.37% <ø> (+2.99%) ⬆️
src/time_series_metadata_store.jl 92.72% <66.66%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.

Comment thread src/internal.jl Outdated
Comment thread test/test_units.jl
Comment thread docs/src/docs_best_practices/how-to/write_a_tutorial.md Outdated
- Constrain get_base_value/set_base_value! generic fallback to
  InfrastructureSystemsType, matching the get_uuid convention, so it
  doesn't dispatch on unrelated types that happen to define
  get_internal.
- Add test coverage for the generic get_internal-forwarding path via a
  minimal mock type, not just the InfrastructureSystemsInternal-direct
  methods.
- Fix an @extref reference in write_a_tutorial.md that got mangled
  into invalid :doc: role syntax during the units_info->base_value
  rename commit; restore the working label-based reference.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
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