# @ode\_def macro leads to UndefRefError: access to undefined reference

**URL:** <https://discourse.julialang.org/t/ode-def-macro-leads-to-undefreferror-access-to-undefined-reference/35330>\
**Category:** Optimization (Mathematical)\
**Tags:** error\
**Created:** [February 29, 2020, 6:59pm UTC](https://discourse.julialang.org/t/ode-def-macro-leads-to-undefreferror-access-to-undefined-reference/35330 "2020-02-29T18:59:13Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![joergbuchwald](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joergbuchwald/32/13112_2.png) [@joergbuchwald](https://discourse.julialang.org/u/joergbuchwald)\
**Post date:** [February 29, 2020, 6:59pm UTC](https://discourse.julialang.org/t/ode-def-macro-leads-to-undefreferror-access-to-undefined-reference/35330/1 "2020-02-29T18:59:13Z")

</div>

Hi,  
I tried to use the @ode\_def macro, but somehow got stuck in an UndefRefError:

```julia
julia> sir_ode = @ode_def SIRModel begin
           dS = -β*S*I
           dI = β*S*I-γ*I
           dR = γ*I
           end β γ
┌ Warning: Symbolic calculations could not initiate. Likely there's a function which is not differentiable by SymEngine.
└ @ ParameterizedFunctions ~/.julia/packages/ParameterizedFunctions/WcTrd/src/ode_def_opts.jl:244
ERROR: LoadError: UndefRefError: access to undefined reference
Stacktrace:
 [1] getindex at ./array.jl:745 [inlined]
 [2] getindex at ./multidimensional.jl:486 [inlined]
 [3] _broadcast_getindex at ./broadcast.jl:596 [inlined]
 [4] _getindex at ./broadcast.jl:627 [inlined]
 [5] _broadcast_getindex at ./broadcast.jl:612 [inlined]
 [6] getindex at ./broadcast.jl:563 [inlined]
 [7] copyto_nonleaf!(::Array{Expr,2}, ::Base.Broadcast.Broadcasted{Base.Broadcast.DefaultArrayStyle{2},Tuple{Base.OneTo{Int64},Base.OneTo{Int64}},typeof(convert),Tuple{Base.RefValue{Type{Expr}},Base.Broadcast.Extruded{Array{SymEngine.Basic,2},Tuple{Bool,Bool},Tuple{Int64,Int64}}}}, ::CartesianIndices{2,Tuple{Base.OneTo{Int64},Base.OneTo{Int64}}}, ::CartesianIndex{2}, ::Int64) at ./broadcast.jl:1003
 [8] copy at ./broadcast.jl:857 [inlined]
 [9] materialize at ./broadcast.jl:819 [inlined]
 [10] #ode_def_opts#1(::Symbol, ::typeof(ode_def_opts), ::Symbol, ::Dict{Symbol,Bool}, ::Expr, ::Symbol, ::Vararg{Symbol,N} where N) at /home/joerg/.julia/packages/ParameterizedFunctions/WcTrd/src/ode_def_opts.jl:295
 [11] ode_def_opts(::Symbol, ::Dict{Symbol,Bool}, ::Expr, ::Symbol, ::Vararg{Symbol,N} where N) at /home/joerg/.julia/packages/ParameterizedFunctions/WcTrd/src/ode_def_opts.jl:5
 [12] @ode_def(::LineNumberNode, ::Module, ::Any, ::Any, ::Vararg{Any,N} where N) at /home/joerg/.julia/packages/ParameterizedFunctions/WcTrd/src/macros.jl:11
in expression starting at REPL[5]: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 2, 2020, 2:40am UTC](https://discourse.julialang.org/t/ode-def-macro-leads-to-undefreferror-access-to-undefined-reference/35330/2 "2020-03-02T02:40:02Z")

</div>

That syntax hasn’t existed for years. Where did you find it?

---

<div class="post-metadata">

**Author:** ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)\
**Post date:** [March 2, 2020, 3:48am UTC](https://discourse.julialang.org/t/ode-def-macro-leads-to-undefreferror-access-to-undefined-reference/35330/3 "2020-03-02T03:48:56Z")

</div>

searching “ode\_def SIRModel begin” brings me:

> **[SIR model in Julia using DifferentialEquations](http://epirecip.es/epicookbook/chapters/sir/julia)**
>
> SIR model in Julia using DifferentialEquations

---

<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 2, 2020, 3:51am UTC](https://discourse.julialang.org/t/ode-def-macro-leads-to-undefreferror-access-to-undefined-reference/35330/4 "2020-03-02T03:51:15Z")

</div>

Cool. I contacted Simon and we’ll get it updated for years. In the meantime, I suggest you follow the tutorials,

[https://docs.juliadiffeq.org/latest/tutorials/ode\_example/](https://docs.juliadiffeq.org/latest/tutorials/ode_example/)

```julia
function sir_ode(du,u,p,t)
  S,I,R = u
  β,γ = p
  du[1] = -β*S*I
  du[2] = β*S*I-γ*I
  du[3] = γ*I
end

```

---

<div class="post-metadata">

**Author:** ![joergbuchwald](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joergbuchwald/32/13112_2.png) [@joergbuchwald](https://discourse.julialang.org/u/joergbuchwald)\
**Post date:** [March 2, 2020, 10:06am UTC](https://discourse.julialang.org/t/ode-def-macro-leads-to-undefreferror-access-to-undefined-reference/35330/5 "2020-03-02T10:06:00Z")

</div>

Thank you. So the entire macro is obsolete?  
Because, I really found it everywhere…

---

<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 2, 2020, 12:38pm UTC](https://discourse.julialang.org/t/ode-def-macro-leads-to-undefreferror-access-to-undefined-reference/35330/6 "2020-03-02T12:38:18Z")

</div>

> [@joergbuchwald](#):
>
> Because, I really found it everywhere…

Everywhere? Where else?

I mean, you can do `using ParameterizedFunctions` and it still exists as a separate package, but it’s quite limited so we don’t develop it anymore, and since it has binary dependencies we don’t ship it with DifferentialEquations.jl. It’s largely being replaced by ModelingToolkit and crew though.

---

<div class="post-metadata">

**Author:** ![joergbuchwald](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joergbuchwald/32/13112_2.png) [@joergbuchwald](https://discourse.julialang.org/u/joergbuchwald)\
**Post date:** [March 2, 2020, 12:53pm UTC](https://discourse.julialang.org/t/ode-def-macro-leads-to-undefreferror-access-to-undefined-reference/35330/7 "2020-03-02T12:53:34Z")

</div>

Ah ok, yeah, thats what I did, which gave me the error above.  
I guess, I saw it first in your video tutorials. I also searched for “parameter estimation ODE” and “julia” and found a reference to an old version of the documentation [https://docs.juliadiffeq.org/v1.6/analysis/parameter\_estimation.html](https://docs.juliadiffeq.org/v1.6/analysis/parameter_estimation.html) (Of course, I did’t paid attention to the doc version, when I found this site… I found it out just now, that the site has moved ;-))  
It seems to be a google problem, that ranks older sites higher…

---

<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 2, 2020, 12:55pm UTC](https://discourse.julialang.org/t/ode-def-macro-leads-to-undefreferror-access-to-undefined-reference/35330/8 "2020-03-02T12:55:39Z")

</div>

> [@joergbuchwald](#):
>
> It seems to be a google problem, that ranks older sites higher…

Oh dang, we put stuff in the header to ensure the latest stable version is given higest priority, but 🤷‍♂️I wonder if it takes a bit to kick in.
