mimiframework / Mimi.jl

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

Add access to time information in the `init` function; Add Dimensions keys to `d` #948

Open lrennels opened 1 year ago

lrennels commented 1 year ago

The init function currently only takes function init(p,v,d) but does not have the time dimension, which could provide useful information to things like the MimiRFFSPs component which needs start_year and end_year to run properly, and these are currently Parameters that will not automatically update with set_dimension! applied to a model.

In addition, make sure that the dimensions or d object includes both the keys and values (names and integers) for indices to give richer information to the component functions.

lrennels commented 1 year ago

https://github.com/rffscghg/MimiRFFSPs.jl/issues/31 for an example of where this could be useful

lrennels commented 4 days ago

bumping this -- would be useful for multiple teams -- I'll prioritize

@jrising @djsmithumn

lrennels commented 4 days ago

Getting started with this issue, we see in instances.jl

# Get the dimensions Named Tuple from the dimension dictionary which will be 
    # passed to run_timestep() and init(), so we can safely implement Base.getproperty(),
    # allowing `d.regions` etc.
    # All values in the named tuple are vectors of Ints, except the `:time` value, which is a
    # vector of AbstractTimesteps, so that `d.time` returns values that can be used for indexing
    # into timestep arrays.
    dim_val_named_tuple = NamedTuple(name => (name == :time ? timesteps(clock) : collect(values(dim))) for (name, dim) in dim_dict(mi.md))

    # recursively initializes all components
    init(mi, dim_val_named_tuple)

    while ! finished(clock)
        run_timestep(mi, clock, dim_val_named_tuple)
        advance(clock)
    end

This is where we can start passing more information to the dim_val_named_tuple, but we need to be very careful about backwards compatibility. For example Base.get_property() on dim_val_named_tuple needs to return a Vector of Ints or a Vector of time steps. One idea would be to add keys so dim.regions returns [1,2,3,4] and dim.regions_keys returns [:r1, :r2, :r3, :r4].

(1) Pass the information through so that at least it can be used for lookups in things like init functions (2) Once that works, add ability to Index into Parameters and Variables with these keys ie. p.myparam[:tau, :USA]