In Julia Turing: getting AssertionError: model isa Model

Hi All,
I am executing below code mentioned in the Turing.jl Guide. This code can be used to calculate likelihood for the Turing model. However I am getting below mentioned error. Please let me know what I may be doing wrong. Thanks for all the help!

Code for model:

using Turing
@model function gdemo(x, y)
s² ~ InverseGamma(2, 3)
m ~ Normal(0, sqrt(s²))
x ~ Normal(m, sqrt(s²))
y ~ Normal(m, sqrt(s²))
end

Code to get likelihood

prob"x = 1.0, y = 1.0 | model = gdemo, s = 1.0, m = 1.0"

Error that I am getting:

AssertionError: model isa Model

Stacktrace:
[1] probtype(ntl::NamedTuple{(:x, :y), Tuple{Float64, Float64}}, ntr::NamedTuple{(:model, :s, :m), Tuple{typeof(gdemo), Float64, Float64}})
@ DynamicPPL C:\Users.….julia\packages\DynamicPPL\hglyy\src\prob_macro.jl:66
[2] logprob(ex1::NamedTuple{(:x, :y), Tuple{Float64, Float64}}, ex2::NamedTuple{(:model, :s, :m), Tuple{typeof(gdemo), Float64, Float64}})
@ DynamicPPL C:\Users.….julia\packages\DynamicPPL\hglyy\src\prob_macro.jl:25
[3] top-level scope
@ In[117]:7
[4] eval
@ .\boot.jl:373 [inlined]
[5] include_string(mapexpr::typeof(REPL.softscope), mod::Module, code::String, filename::String)
@ Base .\loading.jl:1196

See https://github.com/TuringLang/DynamicPPL.jl/issues/182

Though I am not sure how one should provide the observations — as part of the model or in the string macro? So the following works for me:

using Turing
@model function gdemo(x, y)
	s² ~ InverseGamma(2, 3)
	m ~ Normal(0, sqrt(s²))
	x ~ Normal(m, sqrt(s²))
	y ~ Normal(m, sqrt(s²))
end

model = gdemo(missing, missing)
prob"x = 3.0, y = 3.0 | model = model, s = 1.0, m = 1.0"
1 Like

This worked for me too. Thanks for the help!