Connecting parameters of two replaced components

Hi there,

I am trying to modify MimiDICE2016R2 using the Mimi API. I successfully defined new components and replaced the existing co2cycle, climatedynamics, damages components with the following code.

# Load newly defined compoments
include("../input/FAIRco2cycle_component.jl")
include("../input/UPDATEDclimatedynamics_component.jl")
include("../input/UPDATEDdamages_component.jl")

# Replace DICE2016R2 components with newly defined components
replace!(m, :co2cycle => Main.FAIRco2cycle, reconnect = false)
replace!(m, :climatedynamics => Main.UPDATEDclimatedynamics, reconnect = false)
replace!(m, :damages => Main.UPDATEDdamages, reconnect = false)

Thereafter, I provided values for the unshared parameters in the new replaced components with update_param!() which worked fine as well. I can also connect the replaced co2cycle with the original emissions components:

connect_param!(m, :co2cycle, :E, :emissions, :E)

What I find strange here, is that the original component name “co2cycle” is maintained and not replaced by the new component name “FAIRco2cycle”. However, that is not my problem.

My problem arises when I try to connect the parameter TAT in component co2cycle with variable TAT in component climatedynamics with the following command:

connect_param!(m, :co2cylce, :TAT, :climatedynamcis, :TAT)

This throws me the error “MethodError: no method matching disconnect_param!(::Mimi.ModelDef, ::Nothing, ::Symbol)”.

Similarly but differently, if I try to connect the parameter TAT_IPCC in damages component with the variable TAT_IPCC in the climatedynamics component

connect_param!(m, :damages, :TAT_IPCC, :climatedynamcis, :TAT_IPCC)

it throws me the error “no method matching first_and_last(::Nothing)”.

I feel this is somehow related to the naming of the components after I replaced them, but I cannot find a solution. I would be very glad, if you could help me on that. A search in the forum did not produce question with a similar problem.

Hi there,

I solved my problem by using delete!() and add_comp!() instead of replace!(). However, the above described behaviour still seems odd to me.

Best,
Michael

Hi @michaelsureth thank you for your questions and I apologize for the delay in response. I am glad you’ve found a way to solve your problem, but also would be happy to engage with your questions and take a look into whether these warrant any bug fixes or open issues to the Mimi platform itself!

What I find strange here, is that the original component name “co2cycle” is maintained and not replaced by the new component name “FAIRco2cycle”.

I can see how this would be confusing! The replace! function maintains the same name as the previous component (in this case co2cycle) instead of updating or changing the name. This was a design choice made to try to retain the idea of a clean, under-the-hood replacement with minimal changes to the model and its user-facing structure (for example references to :co2cycle would not be broken this way), though I can see arguments both ways

For the two MethodErrors I do see typos in your code copied in, but I assume that is simply in this forum not in your code itself (no problem of course). If it is not that, then this does seem like a bug with the initialization of your replacement components.

I can open an Issue on Mimi to look into this this week, but would suggest that it might help me to have a bit more information on one or more of your replacement components to expedite that process of replicating and then fixing the error. I can understand if you don’t want to make your work public, or even send me code, in which case I can certainly try to replicate the errors on my own, but if you’d like to send me a private message with whatever you are comfortable sharing that might streamline the process.

Hi @lrennels, thanks a lot for your extensive replies and taking the time to look into my issue!

I see that this makes sense, but I got confused by the fact that calling the model m gave me the following output with the component ID including the name of the newly defined components. A hint that the replace! function retains the original name in the Reference Guides of the Mimi API would have helped me there.

julia> m
Mimi.Model
  Module: Mimi
  Components:
    ComponentId(MimiDICE2016R2.totalfactorproductivity)
    ComponentId(MimiDICE2016R2.grosseconomy)
    ComponentId(MimiDICE2016R2.emissions)
    ComponentId(Main.FAIRco2cycle)
    ComponentId(Main.UPDATEDradiativeforcing)
    ComponentId(Main.UPDATEDclimatedynamics)
    ComponentId(Main.UPDATEDdamages)
    ComponentId(MimiDICE2016R2.neteconomy)
    ComponentId(MimiDICE2016R2.welfare)```

Thank you for pointing me towards the typos. Indeed, this seems to have been the problem and replacing the replace! function with delete!and add_comp! just forced me to retype the component names, eliminating those typos. Quite embarrassing but it took me another five minutes to find the misspelled letters after you pointed them out…

Anyway, thank you very much for taking the time and sorry for bothering you unnecessarily. You do a great job with Mimi and your extensive replies and helps in this forum. I am very happy to be able to use the framework for my research!

Best,
Michael

Hi @michaelsureth thats great news! No apologies needed we’ve all been there and I’m happy to hear that it’s an easy fix that’s the best kind! Thanks for the note about replace! I’ll add that to our documentation.