-
Notifications
You must be signed in to change notification settings - Fork 35
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
WIP Add Dimension Key Access to run_timestep
function
#1017
base: master
Are you sure you want to change the base?
Conversation
@jrising @djsmithumn @bryanparthum think you've all mentioned this to me -- open to ideas here as I consider options -- will talk to @davidanthoff as well. @jrising now that I see this implementation I admit we could pretty easily embed a function like |
run_timestep
functionrun_timestep
function
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #1017 +/- ##
==========================================
- Coverage 84.84% 84.83% -0.01%
==========================================
Files 40 40
Lines 4070 4069 -1
==========================================
- Hits 3453 3452 -1
Misses 617 617
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
Current implementation (not totally happy with it though ...) would let you do ... for d in d.countries
if get_dim_keys(:countries)[d] == "USA"
# do something
else
# do something else
end
end we could also have something like for d in d.countries
if d_keys.countries[d] == "USA"
# do something
else
# do something else
end
end or maybe something fancier ... |
The |
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 (?)