# Influence of declaration order

**URL:** <https://forum.mimiframework.org/t/influence-of-declaration-order/310>\
**Category:** Uncategorized\
**Created:** [September 7, 2024, 3:39am UTC](https://forum.mimiframework.org/t/influence-of-declaration-order/310 "2024-09-07T03:39:21Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![emilywen2001](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.mimiframework.org/emilywen2001/32/116_2.png) [@emilywen2001](https://forum.mimiframework.org/u/emilywen2001)\
**Post date:** [September 7, 2024, 3:39am UTC](https://forum.mimiframework.org/t/influence-of-declaration-order/310/1 "2024-09-07T03:39:21Z")

</div>

Hi there

I changed neteconomy and emissions components.  
Firstly, I use `replace!(m, :neteconomy=>neteconomy, reconnect=true)` to replace the neteconomy component.  
Secondly, I use `connect_param!(m, :neteconomy, :E, :emissions, :E)` to connect parameter `E` in neteconomy component and variable `E` in emissions component.  
However, I changed equations of variable `E` in emissions component and I may repalce it after that.

Here is my question, will the declaration order influence the result? The parameter `E` will follow the old or new equation in emissions component?

---

<div class="post-metadata">

**Author:** ![emilywen2001](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.mimiframework.org/emilywen2001/32/116_2.png) [@emilywen2001](https://forum.mimiframework.org/u/emilywen2001)\
**Post date:** [September 7, 2024, 3:50am UTC](https://forum.mimiframework.org/t/influence-of-declaration-order/310/2 "2024-09-07T03:50:00Z")

</div>

BTW, can I view the values of the parameter without running the model? I want to know whether I match all the new parameters successfully and I think it may be of great help for my debugging afterwards.

---

<div class="post-metadata">

**Author:** ![emilywen2001](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.mimiframework.org/emilywen2001/32/116_2.png) [@emilywen2001](https://forum.mimiframework.org/u/emilywen2001)\
**Post date:** [September 7, 2024, 8:39am UTC](https://forum.mimiframework.org/t/influence-of-declaration-order/310/3 "2024-09-07T08:39:21Z")

</div>

I also face a Missing data error looks like this:

> ERROR: MissingException: Cannot get index; data is missing. You may have tried to access a value in timestep 1 that has not yet been computed.

I’ve already found the missing index. However, I have given the value by using `connect!param` to connect with a variable in the other component (which I didn’t change).

I don’t actually know why this happens.

---

<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:** [September 8, 2024, 5:59am UTC](https://forum.mimiframework.org/t/influence-of-declaration-order/310/4 "2024-09-08T05:59:39Z")

</div>

> [@emilywen2001](#):
>
> Here is my question, will the declaration order influence the result? The parameter `E` will follow the old or new equation in emissions component?

If I’m understanding the question correctly, no, the declaration order will not influence the result. The parameter `E` in `neteconomy` will take the outputs from the variable `E` in the `emissions` component, whatever that is. So if you replace `emissions`, then it will connect to that new component.

---

<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:** [September 8, 2024, 6:02am UTC](https://forum.mimiframework.org/t/influence-of-declaration-order/310/5 "2024-09-08T06:02:20Z")

</div>

> [@emilywen2001](#):
>
> BTW, can I view the values of the parameter without running the model? I want to know whether I match all the new parameters successfully and I think it may be of great help for my debugging afterwards.

For a Parameter like the one you list above, the `E` Parameter of the `neteconomy ` component which is pulling values from the `E` Variable of the `emissions` component, you cannot access the values because they are not computed until the model is run.

---

<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:** [September 8, 2024, 6:12am UTC](https://forum.mimiframework.org/t/influence-of-declaration-order/310/6 "2024-09-08T06:12:17Z")

</div>

> [@emilywen2001](#):
>
> I also face a Missing data error looks like this:
> 
> > ERROR: MissingException: Cannot get index; data is missing. You may have tried to access a value in timestep 1 that has not yet been computed.
> 
> I’ve already found the missing index. However, I have given the value by using `connect!param` to connect with a variable in the other component (which I didn’t change).
> 
> I don’t actually know why this happens.

This is a bit difficult to diagnose without any code, but some ideas are

- make sure that if you’ve added any components you’ve added them in the appropriate order, you can use `before` and `after` keyword arguments in `add_comp!` to specify this
- `println` statements can help figure out where missing data is, for example if you suspect it is paramteter `my_param` you can try to print out `println(p.my_param[t]` and see if it comes out as `missing` – though It sounds like you already think you’ve found the culprit
- Incrementally remove some modifications until you isolate what’s going on
- There sometimes have to be caveats for the first tilmestep, if the connected component does not compute a value in the first year. For example, using your components from above if you look at the original `neteconomy` component there are a few places that look like:

```auto
for r in d.regions
            if is_first(t)
                v.YNET[t,r] = p.YGROSS[t,r]/(1+p.DAMFRAC[t,r])
            else
                v.YNET[t,r] = p.YGROSS[t,r] - p.DAMAGES[t,r]
            end
end

```

which _could_ indicate that `p.DAMFRAC[t,r]` is `missing` in the first tilmestep, though I’d need to take a closer look at the MimiRICE model.

These `missing` errors can be frustrating, and generally have to do with the flow of data through the model and where you might not have computed data before passing it through. Some more code might allow me to be more helpful here.

---

<div class="post-metadata">

**Author:** ![emilywen2001](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.mimiframework.org/emilywen2001/32/116_2.png) [@emilywen2001](https://forum.mimiframework.org/u/emilywen2001)\
**Post date:** [September 8, 2024, 10:26am UTC](https://forum.mimiframework.org/t/influence-of-declaration-order/310/7 "2024-09-08T10:26:49Z")

</div>

Got that. But for the parameter I newly update or create, can I check the value before I run the model?

---

<div class="post-metadata">

**Author:** ![emilywen2001](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.mimiframework.org/emilywen2001/32/116_2.png) [@emilywen2001](https://forum.mimiframework.org/u/emilywen2001)\
**Post date:** [September 8, 2024, 10:31am UTC](https://forum.mimiframework.org/t/influence-of-declaration-order/310/8 "2024-09-08T10:31:47Z")

</div>

Hi @lrennels, I checked my code and found that the order of components causes this problem. Thanks for your advice! It helps me a lot!

---

<div class="post-metadata">

**Author:** ![emilywen2001](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.mimiframework.org/emilywen2001/32/116_2.png) [@emilywen2001](https://forum.mimiframework.org/u/emilywen2001)\
**Post date:** [September 8, 2024, 10:35am UTC](https://forum.mimiframework.org/t/influence-of-declaration-order/310/9 "2024-09-08T10:35:32Z")

</div>

Got it. Thanks for your help. I think have a deeper understanding of Mimi structure after solving these problems!

---

<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:** [September 9, 2024, 5:38pm UTC](https://forum.mimiframework.org/t/influence-of-declaration-order/310/10 "2024-09-09T17:38:10Z")

</div>

Hi @emilywen2001 great I’m so glad the `missing` error was solved quickly, those can be frustrating, it often helps me to talk through it with someone because data flow can be confusing so I’m glad the component order solved it – that’s the easiest one to fix!

I know it’s a lot to learn, I’m still learning myself, but yes understanding the structure definitely helps debug problems.

In terms of new `Parameter`s, is the question that you want to basically update a parameter with something like

```auto
update_param!(m, :ComponentName, :ParameterName, values)

```

and then double check that the `values` are correctly entered into the model? It is a little bit tricky to access `Parameter` values before the model is run due to the order of how it is built and filled out, but It think it is possible with some under-the-hood functions if that’s what you’re hoping to do?
