Hi @jrising, good question Iāve struggled with this as well. I think the primary issue here is the rigidity of the @defsim
macro, which cannot parse as wide of an array of expressions as Iād like. Itās something Iād like to work on and can add to the Issues list.
In the meantime, what Iāve done in models like GIVE
that really need more flexilbility is use the underlying helper functions that @defsim
actually uses to build up my mcs
. You can even use the macro for the simpler cases and then add to it as needed. The GIVE code could be an example. That is here: MimiGIVE.jl/src/main_mcs.jl at main Ā· rffscghg/MimiGIVE.jl Ā· GitHub
First we construct a small mcs
function, which could be empty but some of our random variables are pretty simple so we start with that.
# define the Monte Carlo Simulation and add some simple random variables
mcs = @defsim begin
dice2016R2_damage.a2 = Normal(0.00236, 0.00236/2) # Nordhaus (2017, PNAS) DICE2016 RV
end
and then use small functions to add random variables to it with more flexibility.
The agriculture would be a good example for you I think, where we have one RV per region per coefficient:
for coef in [1,2,3] # three coefficients defined with an anonymous dimension
for (i, region) in enumerate(["USA","CAN","WEU","JPK","ANZ","EEU","FSU","MDE","CAM","LAM","SAS","SEA","CHI","MAF","SSA","SIS"]) # fund regions for ag
rv_name = Symbol("rv_gtap_coef$(coef)_$region")
add_RV!(mcs, rv_name, ag_sample_stores[i, coef])
add_transform!(mcs, :Agriculture, :gtap_df, :(=), rv_name, [region, coef])
end
end
So in your case I think youād have something along the lines of:
for (i, country) in enumerate(get_countryinfo().ISO3)
rv_name = rv_name = Symbol("rv_uniform_$country")
add_RV!(mcd, rv_name, Uniform(0,1))
add_transform!(mcs, :MyComponent, :MyParameter, :(=), rv_name, [country])
end
Where the first line makes a local variable for the random variable, the second lines adds a random variable with that name to the Monte Carlo simulation definition, and the third line attaches your parameter to that random variable, sets it equal (:(=)
there are other options but they are rarely used), and then connects to the country
dimension of your model. You can change that if you call it something else?
Let me know if that helps and be in touch with any follow up!
I always appreciate your questions, and Iām looking to carve out some time to make some feature additions to Mimi 