# Modeling Toolkit crash

**URL:** <https://discourse.julialang.org/t/modeling-toolkit-crash/58056>\
**Category:** Modelling & Simulations\
**Tags:** economics\
**Created:** [March 27, 2021, 12:03am UTC](https://discourse.julialang.org/t/modeling-toolkit-crash/58056 "2021-03-27T00:03:21Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Albert\_Zevelev](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/albert_zevelev/32/11844_2.png) [@Albert\_Zevelev](https://discourse.julialang.org/u/Albert_Zevelev)\
**Post date:** [March 27, 2021, 12:03am UTC](https://discourse.julialang.org/t/modeling-toolkit-crash/58056/1 "2021-03-27T00:03:21Z")

</div>

The following causes a crash in Julia v 1.6

```julia
using ModelingToolkit, NonlinearSolve, Plots

@variables c, ℓ, L, K, Y, Π, v, r, w  
@parameters αK, αL, γ, EH, EK  

F(K,L,αK, αL) = (K^αK)*(L^αL)
FK(K,L,αK,αL) = αK*(K^(αK-1.0))*(L^αL)
FL(K,L,αK,αL) = αL*(K^αK)*(L^(αL-1.0))

U(c,ℓ,γ) = γ*log(c) + (1.0 -γ)*log(ℓ)
Uc(c,ℓ,γ) = γ/c 
Uℓ(c,ℓ,γ) = (1.0 -γ)/ℓ

eqs = [
      0.0 ~ r - FK(K,L,αK,αL), # r = F_K
      0.0 ~ w - FL(K,L,αK,αL), # w = F_L
      0.0 ~ Y - F(K,L,αK, αL), # Y = F(K,L)
      0.0 ~ Π - (Y- r*K - w*L), # Π = Y -rK -wL
      #
      0.0 ~ Uc(c,ℓ,γ)/Uℓ(c,ℓ,γ) - 1/w, # Uc/Uℓ = 1/w MRS = price ratio
      0.0 ~ c + w*ℓ - (w*EH + r*K + Π), # BC
      0.0 ~ EH - L - ℓ, # ℓ = EH - L
      0.0 ~ EK - K,
      0.0 ~ v - U(c,ℓ,γ), # value function 
      #
      0.0 ~ c - Y, # c = Y 
]
ns = NonlinearSystem(eqs, [c, ℓ, L, K, Y, Π, v, r, w,], [αK, αL, γ, EH, EK,])
guess = [c => 1.0, ℓ => 1.0, L => 1.0, K => 1.0, Y => 1.0, Π => 1.0, v =>1.0, r => 1.0, w => 1.0]
ps = [αK => 0.45; αL => 0.5; γ => 0.5; EH => 24.0; EK => 10.0;]
prob = NonlinearProblem(ns,guess,ps)
sol = solve(prob,NewtonRaphson())
#c, ℓ, L, K, Y, Π, v, r, w = tuple(sol...)

```

Crash occurs at `solve()`

Crash message:  
The terminal process  
“C:\Users\azevelev\AppData\Local\Programs\Julia-1.6.0\bin\julia.exe ‘-i’, ‘–banner=no’, ‘–project=C:\Users\azevelev.julia\environments\v1.6’, ‘c:\Users\azevelev.vscode\extensions\julialang.language-julia-1.1.37\scripts\terminalserver\terminalserver.jl’, ‘\.\pipe\vsc-jl-repl-95aefdc3-19e2-4af6-b729-7a88dcfed920’, ‘\.\pipe\vsc-jl-cr-0dc6ed39-f5cb-40b5-bbb6-83e0abb7fcb3’, ‘USE\_REVISE=true’, ‘USE\_PLOTPANE=true’, ‘USE\_PROGRESS=true’, ‘DEBUG\_MODE=undefined’”  
terminated with exit code: 1.

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [March 27, 2021, 1:30am UTC](https://discourse.julialang.org/t/modeling-toolkit-crash/58056/2 "2021-03-27T01:30:43Z")

</div>

Open an issue.

---

<div class="post-metadata">

**Author:** ![Albert\_Zevelev](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/albert_zevelev/32/11844_2.png) [@Albert\_Zevelev](https://discourse.julialang.org/u/Albert_Zevelev)\
**Post date:** [March 27, 2021, 2:03am UTC](https://discourse.julialang.org/t/modeling-toolkit-crash/58056/3 "2021-03-27T02:03:53Z")

</div>

Thanks I’ll open an issue.  
I think I got to the bottom of it: it crashes whenever I post a redundant equation

Basically, I have 3 market clearing equations, and only need two (any two) of the three to pin down the r the price of capital, and w the price of labor. It’s a shame that over-constraining a non-linear system w/ redundant equations causes a crash. I’m sure it’s a fixable bug…

For whoever wants to see, the following code works if you comment out any one (and only one) of the three market clearing equations:

```julia
using ModelingToolkit, NonlinearSolve, Plots

if 1==1
      @variables LD, KD, Y, Π, c, ℓ, LS, KS, v, r, w
      @parameters αK, αL, γ, EH, EK     

      F(K,L,αK, αL) = (K^αK)*(L^αL)
      FK(K,L,αK,αL) = αK*(K^αK)*(L^αL)/K
      FL(K,L,αK,αL) = αL*(K^αK)*(L^αL)/L

      U(c,ℓ,γ) = γ*log(c) + (1.0 -γ)*log(ℓ)
      Uc(c,ℓ,γ) = γ/c 
      Uℓ(c,ℓ,γ) = (1.0 -γ)/ℓ

      eqs = [
            0.0 ~ r - FK(KD,LD,αK,αL), # r = F_K
            0.0 ~ w - FL(KD,LD,αK,αL), # w = F_L
            0.0 ~ Y - F(KD,LD,αK, αL), # Y = F(K,L)
            0.0 ~ Π - (Y- r*KD - w*LD), # Π = Y -rK -wL
            #
            0.0 ~ Uc(c,ℓ,γ)/Uℓ(c,ℓ,γ) - 1.0/w, # Uc/Uℓ = 1/w MRS = price ratio
            0.0 ~ c + w*ℓ - (w*EH + r*KS + Π), # BC
            0.0 ~ EH - LS - ℓ, # ℓ = EH - L
            0.0 ~ EK - KS, # K ≤ EK  
            0.0 ~ v - U(c,ℓ,γ), # value function 
            #
            #0.0 ~ KD - KS, # Capital Market Clearing 
            0.0 ~ LD - LS, # Labor Market Clearing 
            0.0 ~ c - Y, # Goods Market Clearing 
      ]
      ns = NonlinearSystem(eqs, 
            [LD, KD, Y, Π, c, ℓ, LS, KS, v, r, w,], 
            [αK, αL, γ, EH, EK,]
            )
      guess = [LD=>1.0, KD=>1.0, Y=>1.0, Π=>1.0,
            c=>1.0, ℓ=>1.0, LS=>1.0, KS=>1.0, v=>1.0,
            r=>1.0, w=>1.0]
      ps = [αK=>0.45; αL=>0.51; γ=>0.5; EH=>24.0; EK=>10.0;]
      #ps = [αK=>0.5; αL=>0.5; γ=>0.5; EH=>24.0; EK=>10.0;]
      prob = NonlinearProblem(ns,guess,ps)
      sol = solve(prob,NewtonRaphson())
      tuple(sol...)
end 

```

---

<div class="post-metadata">

**Author:** ![Albert\_Zevelev](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/albert_zevelev/32/11844_2.png) [@Albert\_Zevelev](https://discourse.julialang.org/u/Albert_Zevelev)\
**Post date:** [March 27, 2021, 2:24am UTC](https://discourse.julialang.org/t/modeling-toolkit-crash/58056/4 "2021-03-27T02:24:00Z")

</div>

@ChrisRackauckas is there a good rule of thumb for when I should open an issue in the repo vs when I should post my question on Discourse?

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [March 27, 2021, 10:19am UTC](https://discourse.julialang.org/t/modeling-toolkit-crash/58056/5 "2021-03-27T10:19:17Z")

</div>

When is a bug report and not a discussion. Sometimes it can be hard to tell if your not a dev so don’t worry too much
