NREL-Sienna / PowerSystems.jl

Data structures in Julia to enable power systems analysis. Part of the Scalable Integrated Infrastructure Planning Initiative at the National Renewable Energy Lab.
https://nrel-sienna.github.io/PowerSystems.jl/stable/
BSD 3-Clause "New" or "Revised" License
314 stars 79 forks source link

Solve the Units Issue Once and For All #1134

Open GabrielKS opened 5 months ago

GabrielKS commented 5 months ago

From time to time, issues come up relating to confusion about the various units systems PowerSystems uses — natural units (which may perhaps be subdivided into mega- vs. kilo-, etc.), device base units, and system base units; where in the latter two cases the units are defined in reference to a per-device or per-system reference quantity. Some of these issues are:

To be thorough, the units issue can be broken down into a few parts:

  1. What units are used when creating components, before the component is attached to a system?
  2. What units are used when calling setters on components?
  3. What units are used when interpreting data from getters?
  4. What units are used in the various built-in printout formats?
  5. What units are used internally (for numerical stability and such)?

In theory, most of these issues can be eliminated by forcing the user to specify units as a keyword argument all over the place, or by having sensible, well-documented defaults and allowing the user to specify units if they want something different. I think a more robust solution, which would put all the units logic in a single place and automatically provide a consistent interface wherever units appear, is something along the lines of Unitful.jl that attaches units directly to quantities themselves. In either case, a significant refactor is required. I'm hoping that for the next major release of PowerSystems, we can solve this problem holistically and give the user a simple mental model of how PowerSystems deals with units systems. Let's use this issue to track our progress.

jd-lara commented 5 months ago

one thing to consider in all of this is the fact that unitful.jl doesn't resolve the challenges of per unit modeling.

GabrielKS commented 4 months ago

Further evidence that the current approach causes anguish "in the field": https://github.com/NREL-Sienna/PowerFlows.jl/blob/a93412c6c1712071f9117278e6654a84fcb25199/src/psse_exporter/psse_exporter.jl#L182