# How to implement and modify MimiRICE2010 on Julia?

**URL:** https://forum.mimiframework.org/t/how-to-implement-and-modify-mimirice2010-on-julia/78
**Category:** Uncategorized
**Created:** [July 22, 2019, 3:15pm UTC](https://forum.mimiframework.org/t/how-to-implement-and-modify-mimirice2010-on-julia/78 "2019-07-22T15:15:23Z")
**Posts on this page:** 14
**Page:** 1

<div class="post-metadata">

### Author: ![MarvinDupuis](https://avatars.discourse-cdn.com/v4/letter/m/dfb087/32.png) [@MarvinDupuis](https://forum.mimiframework.org/u/MarvinDupuis)
#### Post date: [July 22, 2019, 3:15pm UTC](https://forum.mimiframework.org/t/how-to-implement-and-modify-mimirice2010-on-julia/78/1 "2019-07-22T15:15:23Z")

</div>

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](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

---

<div class="post-metadata">

### Author: ![davidanthoff](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.mimiframework.org/davidanthoff/32/5_2.png) [@davidanthoff](https://forum.mimiframework.org/u/davidanthoff)
#### Post date: [July 22, 2019, 7:01pm UTC](https://forum.mimiframework.org/t/how-to-implement-and-modify-mimirice2010-on-julia/78/2 "2019-07-22T19:01:11Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![lrennels](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.mimiframework.org/lrennels/32/6_2.png) [@lrennels](https://forum.mimiframework.org/u/lrennels)
#### Post date: [July 22, 2019, 10:00pm UTC](https://forum.mimiframework.org/t/how-to-implement-and-modify-mimirice2010-on-julia/78/3 "2019-07-22T22:00:59Z")

</div>

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

```auto
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.

---

<div class="post-metadata">

### Author: ![lrennels](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.mimiframework.org/lrennels/32/6_2.png) [@lrennels](https://forum.mimiframework.org/u/lrennels)
#### Post date: [July 23, 2019, 1:11pm UTC](https://forum.mimiframework.org/t/how-to-implement-and-modify-mimirice2010-on-julia/78/4 "2019-07-23T13:11:46Z")

</div>

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

```auto
using MimiRICE2010
m = MimiRICE2010.get_model()

```

script and then modify this model using our modification functions as described in Tutorial 2 [here](https://www.mimiframework.org/Mimi.jl/stable/tutorials/tutorial_2/) 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](https://github.com/davidanthoff/teaching-2019-aere-workshop), specifically in these two notebooks: [https://github.com/davidanthoff/teaching-2019-aere-workshop/blob/master/src/6\_HandsOnSession\_BuildModel.ipynb](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](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.

---

<div class="post-metadata">

### Author: ![FrankErrickson](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.mimiframework.org/frankerrickson/32/13_2.png) [@FrankErrickson](https://forum.mimiframework.org/u/FrankErrickson)
#### Post date: [July 23, 2019, 4:04pm UTC](https://forum.mimiframework.org/t/how-to-implement-and-modify-mimirice2010-on-julia/78/5 "2019-07-23T16:04:20Z")

</div>

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!

---

<div class="post-metadata">

### Author: ![lrennels](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.mimiframework.org/lrennels/32/6_2.png) [@lrennels](https://forum.mimiframework.org/u/lrennels)
#### Post date: [July 23, 2019, 5:59pm UTC](https://forum.mimiframework.org/t/how-to-implement-and-modify-mimirice2010-on-julia/78/6 "2019-07-23T17:59:31Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![lrennels](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.mimiframework.org/lrennels/32/6_2.png) [@lrennels](https://forum.mimiframework.org/u/lrennels)
#### Post date: [July 23, 2019, 6:30pm UTC](https://forum.mimiframework.org/t/how-to-implement-and-modify-mimirice2010-on-julia/78/7 "2019-07-23T18:30:32Z")

</div>

@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:

```auto
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

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

```

and `getrice2010parameters` contains

```auto
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.

---

<div class="post-metadata">

### Author: ![lrennels](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.mimiframework.org/lrennels/32/6_2.png) [@lrennels](https://forum.mimiframework.org/u/lrennels)
#### Post date: [July 23, 2019, 6:35pm UTC](https://forum.mimiframework.org/t/how-to-implement-and-modify-mimirice2010-on-julia/78/8 "2019-07-23T18:35:44Z")

</div>

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:

```auto
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

```

---

<div class="post-metadata">

### Author: ![MarvinDupuis](https://avatars.discourse-cdn.com/v4/letter/m/dfb087/32.png) [@MarvinDupuis](https://forum.mimiframework.org/u/MarvinDupuis)
#### Post date: [July 24, 2019, 9:10am UTC](https://forum.mimiframework.org/t/how-to-implement-and-modify-mimirice2010-on-julia/78/9 "2019-07-24T09:10:11Z")

</div>

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](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 🙂

Marvin

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

---

<div class="post-metadata">

### Author: ![lrennels](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.mimiframework.org/lrennels/32/6_2.png) [@lrennels](https://forum.mimiframework.org/u/lrennels)
#### Post date: [July 24, 2019, 1:38pm UTC](https://forum.mimiframework.org/t/how-to-implement-and-modify-mimirice2010-on-julia/78/10 "2019-07-24T13:38:16Z")

</div>

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

```auto
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?

```auto
pkg> st

```

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

---

<div class="post-metadata">

### Author: ![lrennels](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.mimiframework.org/lrennels/32/6_2.png) [@lrennels](https://forum.mimiframework.org/u/lrennels)
#### Post date: [July 24, 2019, 2:42pm UTC](https://forum.mimiframework.org/t/how-to-implement-and-modify-mimirice2010-on-julia/78/11 "2019-07-24T14:42:25Z")

</div>

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

---

<div class="post-metadata">

### Author: ![MarvinDupuis](https://avatars.discourse-cdn.com/v4/letter/m/dfb087/32.png) [@MarvinDupuis](https://forum.mimiframework.org/u/MarvinDupuis)
#### Post date: [August 2, 2019, 6:47am UTC](https://forum.mimiframework.org/t/how-to-implement-and-modify-mimirice2010-on-julia/78/12 "2019-08-02T06:47:26Z")

</div>

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 -----

---

<div class="post-metadata">

### Author: ![lrennels](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.mimiframework.org/lrennels/32/6_2.png) [@lrennels](https://forum.mimiframework.org/u/lrennels)
#### Post date: [August 2, 2019, 11:47pm UTC](https://forum.mimiframework.org/t/how-to-implement-and-modify-mimirice2010-on-julia/78/13 "2019-08-02T23:47:30Z")

</div>

@davidanthoff advice here?

---

<div class="post-metadata">

### Author: ![davidanthoff](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.mimiframework.org/davidanthoff/32/5_2.png) [@davidanthoff](https://forum.mimiframework.org/u/davidanthoff)
#### Post date: [August 3, 2019, 1:25am UTC](https://forum.mimiframework.org/t/how-to-implement-and-modify-mimirice2010-on-julia/78/14 "2019-08-03T01:25:50Z")

</div>

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.
