mimiframework / Mimi.jl

Integrated Assessment Modeling Framework
https://www.mimiframework.org
Other
66 stars 34 forks source link

Proposal: Adding units to Mimi #25

Open jrising opened 8 years ago

jrising commented 8 years ago

I think units are really important in building and validating models. In the next few weeks, I propose that I will add a unit system to Mimi, which will be optional unless it's required. I see that the MetaVariable and MetaParameter types have a units field, but I don't think they're in current use and I propose some changes.

The most advanced version of this would do unit conversion, and understand how arithmetic changes units. I want to put in something simpler, with some planning to help it be replaced later without too much trouble.

Parameters and variables will take an optional argument, units, which will be of any type; the typical case is that it would be a string. The units would be stored in a field in the MetaVariable and MetaParameter types-- so I would just change these from UTF8String to Any. The Any type will allow conversion-aware units to be handled later, using the overloaded unitcheck and unitconvert functions.

If a component is connected through a parameter or variable that has units, it will be required that the other side also have units and that these units match. connectparameter would make this check.

Similarly, setparameter for united parameters would require that the value is of type UnitedObject, which is just a wrapper around both a value::Any and a units::Any, and that the units match.

To support future work, the checks between components will use a unitcheck(Any, Any) function. Eventually, I want to have a system that would automatically create a whole component in between two connected components, if that's what's necessary to connect two components.

When using setparameter, the UnitedObject would be passed to a unitconvert(UnitedObject, unit::Any) function, which returns the raw data (possibly in a converted form). In version 1, unitconvert will just call unitcheck and then return value.

davidanthoff commented 8 years ago

Yes, I agree, we should add this!

A few random points:

jrising commented 8 years ago

The Unitful package is just the sort of thing I would want to use. I'm worried though about runtime costs. Also, bizarrely, the Unitful documentation says nothing about arrays. I think we should not wed Mimi to any particular unit system.

delgadom commented 7 years ago

@jrising @davidanthoff Unitful includes support for arrays (now referenced in the docs here http://ajkeller34.github.io/Unitful.jl/stable/manipulations/). They claim to have a very small performance penalty.

lrennels commented 3 years ago

Let's bump this towards top of discussion as it would be a well-contained, but valuable, contribution. We also see interest on the forum here: https://forum.mimiframework.org/t/mimi-and-unitful/182/2