Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
lrennels opened this issue Mar 2, 2023 · 5 comments

Comments

@lrennels
Copy link
Collaborator

lrennels commented Mar 2, 2023

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
Copy link
Collaborator Author

lrennels commented Mar 2, 2023

rffscghg/MimiRFFSPs.jl#31 for an example of where this could be useful

@lrennels
Copy link
Collaborator Author

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

@jrising
@djsmithumn

@lrennels
Copy link
Collaborator Author

lrennels commented Aug 23, 2024

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]

@lrennels
Copy link
Collaborator Author

lrennels commented Sep 3, 2024

Another option is to fill in the keys for the component dimension upon build! of the component instance, or wherever the above initialization happens, so that the Component Instance knows it's own keys and then pass these to a built-in function like get_dim_keys ...

@lrennels
Copy link
Collaborator Author

lrennels commented Sep 3, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant