Retrieving parameter values

Suppose that I have an un-run model, which has its external parameters filled in. How can I get the values of these parameters?

Previously, I could say m.external_parameters[:paramname].values. I can’t figure out how to do this in the new version, except to run the model, and then I can say: get_param_value(m.mi.components[:ComponentName], :paramname).data

Is that the intended approach? (I couldn’t figure out a reasonable way to use the components function to help with this.)

Hi James, so am I right in saying that what you would ideally like to do here is access the values of the external parameters that have been filled in without running the model?

In this case, once the model is run, it seems the intended way to get the value is model[:ComponentName, :ParamName]. Per your question about an unrun model, that wouldn’t work since there’s no model instance of an unrun model, and this function requires a model instance. I can probably add an error message and we could also discuss possibilities for an unrun model if that’s useful. The parameters are held in, but we haven’t written API functions to make it easy to access those and deal with their types, so would probably want to think on that.

I can work with that! It’s worth flagging that I’ll be going outside of the API, but I understand that the general solution is likely to be somewhat involved: it would be nice to be able to run any function that does not require the model to have been run without running it.

Yes that makes sense, the arrays are of special type TimestepArray so that may be a little tricky, I’m happy to look into it with you though.

I second @jrising’s suggestion. I find myself in a situation where it would be helpful to run functions that don’t require a solved model.

To ask a slightly related follow up question, is it possible to get information about the number of timesteps a created (but un-run) Mimi model has? For instance I want to pre-allocate an array with the proper size to store some results, but haven’t run the model yet.

So you want to know the length of your tilmestep dimension, that you set with something like set_dimension!(mymodel, :time, 2015:5:2110)? Sure there are a few functions you can use.

The easiest way is probably to use the exported dim_keys function, which will return an Array of the dimension keys for the :time dimension can give you the dimension keys as follows

using Mimi, MimiDICE2010
m = MimiDICE2010.get_model()
time_dim_keys = dim_keys(m, :time)
len = length(time_dim_keys)
1 Like