# Issues with porting Turing.jl to RxInfer.jl

**URL:** <https://discourse.julialang.org/t/issues-with-porting-turing-jl-to-rxinfer-jl/115696>\
**Category:** Modelling & Simulations\
**Tags:** rxinfer\
**Created:** [June 15, 2024, 6:40pm UTC](https://discourse.julialang.org/t/issues-with-porting-turing-jl-to-rxinfer-jl/115696 "2024-06-15T18:40:48Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![sdwfrost](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sdwfrost/32/2831_2.png) [@sdwfrost](https://discourse.julialang.org/u/sdwfrost)\
**Post date:** [June 15, 2024, 6:40pm UTC](https://discourse.julialang.org/t/issues-with-porting-turing-jl-to-rxinfer-jl/115696/1 "2024-06-15T18:40:48Z")

</div>

Hi everyone, I’m trying to port a Turing.jl example to RxInfer.jl. However, the following throws an error; any tips on how to reformat?

```Julia
using OrdinaryDiffEq
using SciMLSensitivity
using RxInfer

Y = [7, 6, 10, 8, 13, 17, 18, 19, 29, 27,
     39, 28, 45, 55, 41, 39, 41, 44, 28, 39,
     28, 34, 22, 12, 12, 11, 15, 16, 15, 12,
     7, 3, 1, 3, 4, 2, 2, 2, 0, 0];

function sir_ode!(du,u,p,t)
    (S,I,R,C) = u
    (β,c,γ) = p
    N = S+I+R
    infection = β*c*I/N*S
    recovery = γ*I
    @inbounds begin
        du[1] = -infection
        du[2] = infection - recovery
        du[3] = recovery
        du[4] = infection
    end
    nothing
end;

@model function bayes_sir(y)
    l = length(y)
    i₀ ~ Uniform(0.0,1.0)
    β ~ Uniform(0.0,1.0)
    I = i₀*1000.0
    u0=[1000.0-I,I,0.0,0.0]
    p=[β,10.0,0.25]
    tspan = (0.0,float(l))
    prob = ODEProblem(sir_ode!,
            u0,
            tspan,
            p)
    sol = solve(prob,
                Tsit5(),
                saveat = 1.0)
    sol_C = Array(sol)[4,:] # Cumulative cases
    sol_X = sol_C[2:end] - sol_C[1:(end-1)]
    for i in 1:l
      y[i] ~ Poisson(abs(sol_X[i]))
    end
end;

result = infer(
    model = bayes_sir(),
    data = (y = Y, )
)

```

Error:

```Julia
ERROR: MethodError: no method matching *(::GraphPPL.VariableRef{…}, ::Float64)

```

The line it is complaining about (and there are similar ones) is:

```Julia
I = i₀*1000.0

```

Why can’t I transform in the model file?

---

<div class="post-metadata">

**Author:** ![sdwfrost](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sdwfrost/32/2831_2.png) [@sdwfrost](https://discourse.julialang.org/u/sdwfrost)\
**Post date:** [June 15, 2024, 6:50pm UTC](https://discourse.julialang.org/t/issues-with-porting-turing-jl-to-rxinfer-jl/115696/2 "2024-06-15T18:50:17Z")

</div>

PS. I’m not sure that RxInfer.jl can handle the ODE within the model loop, but I can write a discrete time model that it should be able to handle…

---

<div class="post-metadata">

**Author:** ![albertpod](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/albertpod/32/31336_2.png) [@albertpod](https://discourse.julialang.org/u/albertpod)\
**Post date:** [June 26, 2024, 12:08pm UTC](https://discourse.julialang.org/t/issues-with-porting-turing-jl-to-rxinfer-jl/115696/3 "2024-06-26T12:08:30Z")

</div>

Hi @sdwfrost! Thanks for trying out RxInfer.jl!

Can you please duplicate this question on [ReactiveBayes · Discussions · GitHub](https://github.com/orgs/ReactiveBayes/discussions)?

---

<div class="post-metadata">

**Author:** ![sdwfrost](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sdwfrost/32/2831_2.png) [@sdwfrost](https://discourse.julialang.org/u/sdwfrost)\
**Post date:** [June 28, 2024, 9:49pm UTC](https://discourse.julialang.org/t/issues-with-porting-turing-jl-to-rxinfer-jl/115696/4 "2024-06-28T21:49:51Z")

</div>

Dear @albertpod

I seemed to be able to fix this using `~`, but now I run into the problem of extracting Float64 from my random variable to pass to the differential equation solver. I’ve posted this as a follow-up to the ask for a DifferentialEquations example in the [RxInfer discussion](https://github.com/orgs/ReactiveBayes/discussions/56).
