WIP Add Dimension Key Access to run_timestep
function
#1017
+46
−6
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Handling part of #948 (also mentions access to
t
ininit
but save that for a second PR)The goal of this PR is to add access to the dimension keys from within components. Currently for a
run_timestep(p,v,d,t)
function,d.dim_name
will return a vector of theType
needed to index into Arrays for the dimension, namelyInt
s for all dimensions excepttime
for which it is our customTimestep
type.While this is useful for a loop like
there are times a user would like to check the actual keys, I think the core example being something like
Note the line above fails because
d
is an Integer (eg. in GIVE we know it is 174, the index of the key "USA" in the countries dimension vector).One way to pass information to
run_timestep
without breaking compatibility is to have keyword args we set during initialization, and then are in scope for the function, that the user never needs to see or manipulate. We have access to the entireModelInstance
at the time of runningrun_timestep
.Some decisions/TODOs
get_dim_keys(dim_name::Symbol)
function, but we could really pass any structure that is useful. Instead of a function we could have an object calledd_keys
that is exactly the same asd
but returns the keys?init
as well (?)