Skip to content

Lk/units domain agnostic#574

Draft
luke-kiernan wants to merge 11 commits intoIS4from
lk/units-domain-agnostic
Draft

Lk/units domain agnostic#574
luke-kiernan wants to merge 11 commits intoIS4from
lk/units-domain-agnostic

Conversation

@luke-kiernan
Copy link
Copy Markdown
Contributor

Backend for explicit units in getters and setters.

luke-kiernan and others added 9 commits April 15, 2026 16:21
- Add units.jl with Unitful integration, RelativeQuantity type for DU/SU
- Define custom Mvar and MVA units for reactive/apparent power
- Update generate_structs.jl template to generate two-method accessors:
  - Default accessor returns natural units (MW, Mvar, etc.)
  - Optional second argument accepts explicit unit (DU, SU, MW, etc.)
- Add get_natural_unit() to map conversion types to appropriate units
  (reactive power fields → Mvar, other power fields → MW)
- Export unit types and Unitful re-exports from main module
- Register custom Unitful units in __init__()

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
The type parameter in repr() may or may not be module-qualified
depending on what names are in scope, which differs between local
and CI environments. Use occursin checks instead of exact string
matching.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
When exclude_getter is true, generates an internal _get_ prefixed accessor
instead of the public get_ accessor. Suppresses the public getter export
while keeping setter exports (since exclude_setter means hand-written, not
nonexistent).

Used by PSY to make get_base_power return unitful values while keeping
_get_base_power as raw Float64 for internal conversion machinery.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The 1-arg getter now uses DEFAULT_UNITS (a constant) instead of the
stateful _get_system_units, eliminating type instability and enabling
full compiler optimization of the getter path.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Replace inline units.jl with using/re-exporting from PowerSystemsUnits.
Keep time_period_conversion in units.jl (unrelated to unit types).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Purge power-domain knowledge from generate_structs template
  (NATURAL_UNIT_MAP / get_natural_unit removed); template emits
  untyped `units` parameter for downstream packages to specialize.
- Declare bare `get_value` / `set_value` interface; methods are
  now provided by domain packages (e.g. PowerSystems).
- Drop PowerSystemsUnits and Unitful deps so IS has no knowledge
  of power-system-specific unit types.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 17, 2026

Codecov Report

❌ Patch coverage is 64.28571% with 20 lines in your changes missing coverage. Please review.
✅ Project coverage is 81.81%. Comparing base (94161b0) to head (0a29de7).
⚠️ Report is 28 commits behind head on IS4.

Files with missing lines Patch % Lines
src/cost_aliases.jl 40.00% 6 Missing ⚠️
src/relative_units.jl 84.61% 4 Missing ⚠️
src/utils/print_pt_v2.jl 0.00% 4 Missing ⚠️
src/utils/print_pt_v3.jl 0.00% 4 Missing ⚠️
src/utils/generate_structs.jl 75.00% 2 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##              IS4     #574      +/-   ##
==========================================
- Coverage   82.04%   81.81%   -0.23%     
==========================================
  Files          74       75       +1     
  Lines        6238     6336      +98     
==========================================
+ Hits         5118     5184      +66     
- Misses       1120     1152      +32     
Flag Coverage Δ
unittests 81.81% <64.28%> (-0.23%) ⬇️

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

Files with missing lines Coverage Δ
src/InfrastructureSystems.jl 44.44% <ø> (ø)
src/time_series_interface.jl 96.24% <100.00%> (ø)
src/utils/test.jl 71.87% <100.00%> (-1.46%) ⬇️
src/value_curve.jl 94.84% <100.00%> (+0.96%) ⬆️
src/utils/generate_structs.jl 86.99% <75.00%> (-1.05%) ⬇️
src/relative_units.jl 84.61% <84.61%> (ø)
src/utils/print_pt_v2.jl 0.00% <0.00%> (ø)
src/utils/print_pt_v3.jl 88.65% <0.00%> (-1.93%) ⬇️
src/cost_aliases.jl 53.33% <40.00%> (-4.64%) ⬇️

... and 3 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

- New relative_units.jl vendors AbstractRelativeUnit, DU/SU/NU, and
  RelativeQuantity; power-specific types stay in PSY.
- Template drops the 1-arg getter emission — callers must specify units.
  Emits a `display_units_arg(f, ::Type{T})` trait so consumers can dispatch
  on whether a (getter, struct) pair takes units.
- `_make_time_array` now calls `multiplier(owner, SU)` so
  `scaling_factor_multiplier = get_max_active_power` keeps working.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@jd-lara
Copy link
Copy Markdown
Member

jd-lara commented Apr 17, 2026

One comment I see is that we need The five TimeSeries*Curve aliases to full parametric type. Please add overrides for symmetry and better printing.

Comment thread src/utils/generate_structs.jl Outdated
Mirror the existing exclude_setter behavior so the public name is registered
for export even when the generator emits a _-prefixed internal accessor.

Co-Authored-By: Claude Opus 4.7 (1M context) <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