# TypeError using ODEs in Turing.jl

**URL:** https://discourse.julialang.org/t/typeerror-using-odes-in-turing-jl/34857
**Category:** Probabilistic Programming
**Created:** [February 19, 2020, 4:10pm UTC](https://discourse.julialang.org/t/typeerror-using-odes-in-turing-jl/34857 "2020-02-19T16:10:13Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![virgile-baudrot](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/virgile-baudrot/32/6857_2.png) [@virgile-baudrot](https://discourse.julialang.org/u/virgile-baudrot)
#### Post date: [February 19, 2020, 4:10pm UTC](https://discourse.julialang.org/t/typeerror-using-odes-in-turing-jl/34857/1 "2020-02-19T16:10:14Z")

</div>

Hi all,

I try using ODEs within Turing model, but I have the following error:  
`TypeError: in typeassert, expected Float64, got ForwardDiff.Dual{Nothing,Float64,1}`

Here is my code:

```julia
function myODE(du,u,p,t)
    du[1] = p[1] * (0.1-u[1])
end

@model bayesODE(x, t) = begin
  # 1. SET PRIORS
  prior ~ Normal(0, 1)
  #kd = 1
  # 2. MECHANISTIC MODELS
  x0 = [0.0]
  tspan = (0.0,10.0)
  #paramODE = convert.(Float64, kd)
  prob = ODEProblem(myODE,x0,tspan,prior)
  _saveat = t === nothing ? Float64[] : t
  sol_tmp = solve(prob ; saveat = _saveat)
  for i in 1:length(x)
      x[i] ~ Normal(sol_tmp.u[i][1], 2)
  end
end
# Run sampler, collect results
chn = sample(bayesODE([10 11 12], [1 2 3]), HMC(0.1, 5), 100)

```

Thanks

---

<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: [February 19, 2020, 4:57pm UTC](https://discourse.julialang.org/t/typeerror-using-odes-in-turing-jl/34857/2 "2020-02-19T16:57:00Z")

</div>

> [@virgile-baudrot](#):
>
> prob = ODEProblem(myODE,x0,tspan,prior)

`prob = ODEProblem(myODE,eltype(prior).(x0),tspan,prior)`

[https://docs.juliadiffeq.org/latest/basics/faq/#Native-Julia-solvers-compatibility-with-autodifferentiation-1](https://docs.juliadiffeq.org/latest/basics/faq/#Native-Julia-solvers-compatibility-with-autodifferentiation-1)

---

<div class="post-metadata">

### Author: ![virgile-baudrot](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/virgile-baudrot/32/6857_2.png) [@virgile-baudrot](https://discourse.julialang.org/u/virgile-baudrot)
#### Post date: [February 19, 2020, 8:33pm UTC](https://discourse.julialang.org/t/typeerror-using-odes-in-turing-jl/34857/3 "2020-02-19T20:33:27Z")

</div>

perfect. Thank you
