Hi @jrising thanks for the question! When we call run_timestep(p,v,d,t)
the function has access to richer time information (from t
) than init(p,v,d)
. I have to go double check the d
object, but I think as you said that’s just going to give you the time
dimension of the model without nuances like what times that component runs for, and thus you are getting all times.
The init
function is run only once, as described in Build and Init Functions · Mimi.jl and quoted below, and is technically not meant to be used for situations where you need access to time
. That said, we’ve done it before for speed and data needs so if you’re in a similar situation we can certainly work it out (see below re. MimiRFFSPs and MimiSSPs).
The init function
The init
function can optionally be called within @defcomp
and before run_timestep
. Similarly to run_timestep
, this function is called with parameters init(p, v, d)
, where the component state (defined by the first three arguments) has fields for the Parameters, Variables, and Dimensions of the component you defined.
If defined for a specific component, this function will run before the timestep loop, and should only be used for parameters or variables without a time index e.g. to compute the values of scalar variables that only depend on scalar parameters. Note that when using init
, it may be necessary to add special handling in the run_timestep
function for the first timestep, in particular for difference equations. A skeleton @defcomp
script using both run_timestep
and init
would appear as follows:
…
So out of curiosity, what is the need to do this here in the init
function instead of run_timestep
, given that you do need the time
dimension? We ran into this with the MimiSSPs and MimiRFFSPs where we anted to fill in data in the init
function and not run it through the run_timestep
function. Is your situation similar?
If so, we can certainly talk about the best approach. Those two components show examples, likely the largest difference is that the MimiSSPs approach is far slower because it uses lots of DataFrames
filtering etc, MimiRFFPs is optimized a lot, but is a bit less flexible to different countries and time dimensions.
One little note on changing the time dimension of MimiRFFPs that I’ll tag here in case it’s relevant for us later: Updating the RFFSPs Component Time Dimension · Issue #23 · rffscghg/MimiGIVE.jl · GitHub