How to implement and modify MimiRICE2010 on Julia?

Hello,

I would like to ask you if some supplementary instructions are necessary in Julia to start running MimiRICE2010 beyond those indicated in github i.e. :

pkg> registry add https://github.com/mimiframework/MimiRegistry.git
pkg> add MimiRICE2010
pkg> add Mimi
julia> using MimiRICE2010
julia> m = MimiRICE2010.get_model()
julia> run(m)

When I write the instruction “julia> using MimiRICE2010”, an error message appears advising me to “re-run Pkg.build(“Special Functions”)”. And further down, other error messages say that StatsFuns, Distributions, Mimi and MimiRICE2010 failed to precompile. Do you have any idea of which instructions I could write to resolve these problems and implement successfully the model?

Last of all, as my goal is to compile my own version of RICE (with other regionalization and endogenous demography), I need to change the code, and especially the file parameters.jl. So I downloaded the entire zip code via the “clone or download” bottom in the git. But when I open it via Julia, it directly closes after writing errors in the Julia console. Do you think there would be an easier way to open and modify parameters.jl ?

Best regards,

Marvin Dupuis

I think something went wrong on your system when some other packages were installed. Can you try to run pkg> build in the pkg REPL and see whether that fixes it?

Thanks for your questions @MarvinDupuis, I’m sure we can get you set up in no time. As David suggests, the first problem looks related to package installation on your system and will need to be solved before you can proceed, Let us know if the build step above works. As you have probably noted from the Julia documentation, there are two ways to access the Pkg functions. The first is through

using Pkg
Pkg.build()

however the cleaner way is to access the Pkg REPL by typing ], and simply typing build to rebuild your installed packages. This is what we mean by the pkg> syntax.

Your second question refers to modifying MimiRICE2010 itself. There are two primary ways to modify an existing model. I’m more than happy to help work through modifications for either of these methods, whichever works best for your purposes. We are aiming to build out tutorials and documentation to make these processes easier for users, so we very much appreciate the communication as it helps us improve the user experience.

Method 1

The first, and most simple method, is to pull down the model with the

using MimiRICE2010
m = MimiRICE2010.get_model()

script and then modify this model using our modification functions as described in Tutorial 2 here such as update_param!, replace_comp!, and add_comp! etc. This method is most useful if you are for the most part maintaining structure but updating parameters, adding an individual component, or modifying an existing one.

We generally recommend trying this method first, since it allow more abstraction away from the inner workings of the original model and thus hopefully less burden on the user.

Another hands-on example of this comes from material from our recent workshop at the AERE conference linked here, specifically in these two notebooks: https://github.com/davidanthoff/teaching-2019-aere-workshop/blob/master/src/6_HandsOnSession_BuildModel.ipynb and https://github.com/davidanthoff/teaching-2019-aere-workshop/blob/master/src/3_HandsOnSession_ModifyingParameters.ipynb.

Method 2

If you are performing more significant changes, you may wish to do as you said and download the model using git clone [url] to view and change the internals of the model. This allows for deeper structural changes etc. and can also be informed by our examples and tutorials.

Hey @Lisa,

I’ve chatted with Marvin a bit about this. I think one issue for him will be updating the RICE regions without having to mess with the source code.

So if we want to keep the RICE structure/equations the same, but allow for different regions with different parameters, is there a straight forward way to do this? In other words, I want to load RICE, swap in a new region index (for example dividing RICE up into 20+ regions) while keeping all component connections and model equations the same, and then resetting any parameters I needed to (damage function coefficients, population, etc.). Ideally the bulk of the work here would just be maybe writing a new script to load all of the new parameters. Thanks!

Ah ok that makes sense and I think that should be doable. Let me play with that a little bit and get back to you both tomorrow with the easiest flow of code to do just that.

@FrankErrickson I’ve looked at this a bit more and if you are just working with the currently exported functions, I don’t think it’s possible to do this without downloading the source code, but do think it could be relatively straightforward in terms of the additional functions. The issue is that the signature for MimiRICE2010.get_model is:

function get_model(;datafile=joinpath(@__DIR__, "..", "data", "RICE_2010_base_000.xlsm"))
    params = getrice2010parameters(datafile)
    m = constructrice(params)
    return m
end #function

… and both of the functions called by get_model include explicit information about the regions since
constructrice contains

set_dimension!(m, :regions, ["US", "EU", "Japan", "Russia", "Eurasia", "China", "India", "MidEast", "Africa", "LatAm", "OHI", "OthAsia"])

and getrice2010parameters contains

regions = ["US", "EU", "Japan", "Russia", "Eurasia", "China", "India", "MidEast", "Africa", "LatAm", "OHI", "OthAsia"]

That said, I think all you would have to do is make new versions of those two functions and change those two lines, and then make a new RICE_2010_base_000.xlsm type file.

More concretely, I think basically you’d do the following. Let me know if that’s satisfactory. Note that these changes are so minimal that you could certainly alter the get_model function held by MimiRICE2010 to have more optionality for regions. That wouldn’t be too difficult at all … it just depends on whether you want to go that route and how often you’re doing this type of adjustment. We hadn’t previously thought of needing to make dimensions flexible.

  1. Copy constructrice into a new function like constructrice_20regions and change the set_dimension!(m, :regions, ...) line
  2. Copy getrice2010parameters into a new function like getrice2010parameters_20regions and change the regions = ... line
  3. Create a new RICE_2010_base_000.xlsm file altered as needed to be RICE_2010_base_000_20regions.xlsxm
  4. Copy the get_model function into a new function like get_model_20regions which would be:
function get_model_20regions(;datafile=joinpath(@__DIR__, "..", "data", "RICE_2010_base_000_20regions.xlsm"))
    params = getrice2010parameters_20regions(datafile)
    m = constructrice_20regions(params)
    return m
end #function

Hi and thank very mich for your detailed answers.

  1. Concerning first the implementation of the original RICE 2010 model, running “build” at the beginning helped me and I have no more error when I add https://github.com/mimiframework/MimiRegistry.git, but when I add MimiRICE2010 a big error message appears under the step “Resolbing package versions”:

“ERROR: Unsatisfiable requirements detected for package VersionParsing [81def892] : VersionParsing [81def892] log: VersionParsing [81def892] has no known versions! Found to have no compatible versions left with PyCall [438e738f] : PyCall [438e738f] log: possible versions are [0.0.1, 0.1.0, …, 1.91.2] or uninstalled. Restricted by julia compatibility requirements to versions [1.18.0, …, 1.91.2] or uninstalled. Restricted by compatibility requirements with ExcelReaders [c04bee98] to versions [1.17.1, …, 1.91.2] leaving only versions [1.18.0, …, 1.91.2]. ExcelReaders [c04bee98] log: possible versions are [0.1.0, …, 0.11.0] or uninstalled. Restricted by compatibility requirements with MimiRICE2010 [54b9761e] to versions [0.1.0, …, 0.11.0]. MimiRICE2010 [54n9761e] log: possible versions are 2.0.0-2.0.3 or uninstalled. Restricted to versions * by an explicit requirement leaving only versions 2.0.0-2.0.3. Restricted by julia compatibility requirements to versions [0.10.0, …, 0.11.0] or uninstalled, leaving only versions [0.10.0, …, 0.11.0].”

Have you ever met this type of error ?

  1. Concerning the modifications to the original model,n thank you very much for the tuto and these details instructions, I’ll try them as soon as the original model works. The biggest part of the modifications I had to bring was in Nordhaus’ excel. I created 21 regions sheets ans now I have to modify the code parameters.jl to call this new Excel file and modify the list of the regions and the references of the excel boxes called into this code. All other codes, among which the components codes, remain unchanged.

I’ll be able to give you my feedback about this modification when my compiling problem are resolved :slight_smile:

Marvin

----- Mail d’origine -----

Hi,

No problem, I also recognize that answer about how to make those adjustments was directed more to a user familiar with programming in Mimi (or programming in general) like @FrankErrickson so I can break it down for you if it was too much information at once!

I’m sorry it’s taking a bit to get your system up and running! Sometimes if there is an error along the way with the internet connection or during a specific installation step things can get a little messed up but I’m sure we can clear it up in no time and this should be a. one time issue!

Per your ERROR I have seen that kind of thing before, it’s probably a relic of where your system was when it ran into the build problem. Can you try

pkg> up

to update all of your packages? See how that goes, and then for good measure can you let me know what the output of the following call to the status function is?

pkg> st

This will tell us all of the packages in your environment and their status.

@davidanthoff also maybe a good project to think about workflow?

Hi,

So when I run

“pkg > up”

after running

“pkg > build”

and

“pkg > registry add h t t p s : / / g i t h u b . c o m /mimiframework/MimiRegistry.git”

I get

"Updating registry at ‘C:\Users\marvin`.julia\registries\General’

Updating registry at 'C:\Users\marvin`.julia\registries\MimiRegistry

Updating git - repo ’ h t t p s : / / g i t h u b . c o m / mimiframework/MimiRegistry.git’

Warning : Some registries fail to update :

  • ‘C:\Users\marvin`.julia\registries\General’ - registry dirty

@ Pkg. Types C:\cygwin\home\Administrator\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.1\Pkg\src\Types.jl:1269

Resolving package versions…"

Then when I run

“pkg > st”

Status ‘C\Users\marvin.julia\environments\v1.1\Project.toml’

(empty environment)

And then when I run again

“pkg > add MimiRICE2010”

I get the same error message than before :

"Resolving package versions…

ERROR : Unsatisfiable requirements…"

So I’m a bit lost, and error messages are never very clear.

When I close Julia and re open it, I get the same messages.

Marvin

----- Mail d’origine -----

@davidanthoff advice here?

That sounds like your local copy of the general registry got corrupted. Not clear to me how that can happen. One option is always to just delete the whole ~/.julia folder and start over. Obviously only do that if there is nothing in that folder that you modified! But if you haven’t worked on packages, this could be a very clean option.