Mimi Framework

Update time index

Hi all,

New user here (to both Julia and Mimi). What a great tool you all have built. So far getting started has been great, and I hope you don’t mind a few very simple questions from time to time as I begin getting deeper into the implementations.

I’ve been running into some issues with updating parameters, and I’ll start with a simple example as it will likely help to inform others that I’m facing.

Say I would like to simply update the time index of DICE2010. Currently set at (2005:10:2595). Per the Tutorial 3, it seems like the following should work:

m = MimiDICE2010.get_model()
set_dimension!(m, :time, 2000:10:2590)
run(m)

However, after changing the time index, it seems to trip on other ComponentNames within the model (e.g., InexactError: Int64(0.5) in run_timestep_MimiDICE2010_grosseconomy).

My question: Does updating the time index not update the dimensions of the other components? Is this done individually? Better understanding what is causing this simple error will help to address others. Thanks so much!

Hi @parthum! Welcome to Mimi, we’re glad you’re using the tool and welcome any and all questions. There is always room for improvement to documentation, and we want our tool to be useful so questions and potential bug-finding is great. Let me look into this and I’ll get back to you asap.

Ok @parthum I’ve got it! The solution is quick but my answer is long to give you some context as requested. Please don’t hesitate to continue this conversation if anything is unclear!

code:

using MimIDICE2010
using Mimi

m = MimiDICE2010.get_model()
set_dimension!(m, :time, 2000:10:2590)

# As an example I  just pulled our defaults that are meant for 2005:10:2095 here, they might not make sense in this context of different years!
params = MimiDICE2010.dice2010_excel_parameters() 
update_params!(m, params, update_timesteps = true)

run(m)

explanation:

At a high level, as you guessed, updating dimensions requires a bit more involved work than updating parameters because of the underlying structure of the model and the flow of allocation of space etc. (I won’t bore you with details unless you want them).

You are spot-on when you say the problem is that updating the time index does not automatically do all of the underlying changes you need, partially because it does not know if it has enough information to do this automatically in the way you want it to.

Your first lines are correct:

using MimIDICE2010
using Mimi

m = MimiDICE2010.get_model()
set_dimension!(m, :time, 2000:10:2590)

But now looking at the next step in the tutorial, you need to update any parameters with the :time dimension so that

(1) the parameter dimensions match your new dimensions (not technically needed here because 2000:10:2590 is the same length as 2005:10:2595 but that’s not always the case (ie. if you had said det_dimension!(m, :time, 2000:10:2050)

(2) explicitly tell the model you want to update underlying labels to match your new time steps

To do this we can do with the handy update_params function that takes a model m, a dictionary params, and an (optional but in this case needed) flag update_timesteps that forces the model to update its time labels.

In this case I’m just grabbing our default parameters since it’s the same length, but in practice you may have different values for these different years, or you might need to adjust the number of values etc. The function below is an internal one we use to read in our formatted Excel file of DICE parameters and produce a dictionary. If you’ve worked with DICE you may have seen that (fairly ugly) spreadsheet before.

params = MimiDICE2010.dice2010_excel_parameters() 

Now we update the parameters and run the model!

update_params!(m, params, update_timesteps = true)
run(m)

If you are curious, params in the console looks like this:

julia> params
Dict{Symbol,Any} with 56 entries:
  :aisrate => 9.93664e-5
  :S       => [0.24554, 0.231036, 0.224214, 0.22125, 0.220242, 0.220209, 0.220649, 0.221267, 0.22195, 0.222638  …  0.229543, 0.229543, 0.229543, 0.22954…
  :sigma   => [0.144519, 0.121685, 0.103662, 0.0892681, 0.0776454, 0.0681652, 0.0603594, 0.0538759, 0.0484469, 0.0438664  …  0.0109233, 0.0108438, 0.010…
  :forcoth => [0.83, 0.777, 0.724, 0.671, 0.618, 0.565, 0.512, 0.459, 0.406, 0.353  …  0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3]
  :mu0     => 1600.0
  :therm0  => 0.1
  :t2xco2  => 3.2
  :b33     => 0.99925
  :mat1    => 829.0
  :cost1   => [0.0650336, 0.053423, 0.0444285, 0.0373729, 0.0317736, 0.0272818, 0.0236418, 0.0206644, 0.0182074, 0.0161633  …  0.00265948, 0.00263037, 0…
  :gis0    => 0.0
  :elasmu  => 1.5
  :c4      => 0.05
  :b22     => 0.94796
  :c1      => 0.208
  :b12     => 0.12
  :b32     => 0.00075
  :tatm0   => 0.83
  :etree   => [1.6, 1.28, 1.024, 0.8192, 0.65536, 0.524288, 0.41943, 0.335544, 0.268435, 0.214748  …  2.2836e-5, 1.82688e-5, 1.4615e-5, 1.1692e-5, 9.353…
  :ml0     => 10010.0
  ⋮        => ⋮

@ckingdon95 does this look right to you?

1 Like

@lrennels, this is excellent, thank you! The disconnect (for me) was recognizing that even if we aren’t updating any params (as is done in Tutorial 3) that we still need to update their :time dimension when we update the index (which is intuitive). Updating the basic set of excel_parameters is a great way to illustrate this and the bridge between Mimi and the models.

Thanks so much! This explains some of the other issues I’m running into, too.

Glad to hear it, I’m making a small update to our tutorial to try to make sure this is more explicit.

1 Like