# Turing Guide documentation: prob"..." examples throws errors

**URL:** https://discourse.julialang.org/t/turing-guide-documentation-prob-examples-throws-errors/50319
**Category:** Probabilistic Programming
**Tags:** turing
**Created:** [November 17, 2020, 6:43pm UTC](https://discourse.julialang.org/t/turing-guide-documentation-prob-examples-throws-errors/50319 "2020-11-17T18:43:41Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Hakan\_Kjellerstrand](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hakan_kjellerstrand/32/8447_2.png) [@Hakan\_Kjellerstrand](https://discourse.julialang.org/u/Hakan_Kjellerstrand)
#### Post date: [November 17, 2020, 6:43pm UTC](https://discourse.julialang.org/t/turing-guide-documentation-prob-examples-throws-errors/50319/1 "2020-11-17T18:43:41Z")

</div>

I’m new to Turing.jl (and quite new to Julia as well) and reading the Guide documentation ( [Guide](https://turing.ml/dev/docs/using-turing/guide) ), section “Querying Probabilities from Model or Chain”. The probability query examples are of the form

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

Am I correct to assume that this code should work verbatim, or should I change/transform them in some way?

The reason I ask is that the following program throws an error:

```
@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(2,4)
chains = sample(model, HMC(0.01, 5), 10000)

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

```

The error is:  
“”"  
ERROR: LoadError: AssertionError: model isa Model  
Stacktrace:  
[1] probtype(::NamedTuple{(:x, :y),Tuple{Float64,Float64}}, ::NamedTuple{(:model, :s, :m),Tuple{typeof(gdemo),Float64,Float64}}) at /home/hakank/.julia/packages/DynamicPPL/jOFDR/src/prob\_macro.jl:63  
[2] logprob(::NamedTuple{(:x, :y),Tuple{Float64,Float64}}, ::NamedTuple{(:model, :s, :m),Tuple{typeof(gdemo),Float64,Float64}}) at /home/hakank/.julia/packages/DynamicPPL/jOFDR/src/prob\_macro.jl:25  
[3] top-level scope at /home/hakank/julia/turing/turing\_tutorial12.jl:35  
[4] include(::String) at ./client.jl:457  
[5] top-level scope at ./timing.jl:174 [inlined]  
[6] top-level scope at ./none:0  
in expression starting at /home/hakank/julia/turing/turing\_tutorial12.jl:35  
“”"

Here’s my versioninfo():  
Julia Version 1.5.2  
Commit 539f3ce943 (2020-09-23 23:17 UTC)  
Platform Info:  
OS: Linux (x86\_64-pc-linux-gnu)  
CPU: Intel(R) Core™ i9-7940X CPU @ 3.10GHz  
WORD\_SIZE: 64  
LIBM: libopenlibm  
LLVM: libLLVM-9.0.1 (ORCJIT, skylake-avx512)  
Environment:  
JULIA\_DEPOT\_PATH = /home/hakank/.julia  
JULIA\_NUM\_THREADS = 14  
JULIA\_PKG\_SERVER = [pkg.juliahub.com](http://pkg.juliahub.com)  
JULIA\_LOAD\_PATH = @:@v#.#:@stdlib

I’m running via JuliaPro\_v1.5.2-1 (via Atom) and Turing version v0.14.10. The same error is thrown using Julia version 1.5.3.

Best regards,

Hakan

---

<div class="post-metadata">

### Author: ![cpfiffer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cpfiffer/32/208747_2.png) [@cpfiffer](https://discourse.julialang.org/u/cpfiffer)
#### Post date: [November 17, 2020, 7:17pm UTC](https://discourse.julialang.org/t/turing-guide-documentation-prob-examples-throws-errors/50319/2 "2020-11-17T19:17:24Z")

</div>

In this case, you want to use the query string

```julia
prob"x=1.0, y=1.0 | model=model, s = 1.0, m = 1.0"

```

because `model` is the name of the instantiated model with the data `2` and `4`. `gdemo` isn’t actually a “model” yet, because it hasn’t been given data – `model` has both the model definition and the data.

---

<div class="post-metadata">

### Author: ![Hakan\_Kjellerstrand](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hakan_kjellerstrand/32/8447_2.png) [@Hakan\_Kjellerstrand](https://discourse.julialang.org/u/Hakan_Kjellerstrand)
#### Post date: [November 17, 2020, 7:34pm UTC](https://discourse.julialang.org/t/turing-guide-documentation-prob-examples-throws-errors/50319/3 "2020-11-17T19:34:02Z")

</div>

@cpfiffer Excellent! Thanks, it works now.

---

<div class="post-metadata">

### Author: ![Nathaniel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nathaniel/32/37854_2.png) [@Nathaniel](https://discourse.julialang.org/u/Nathaniel)
#### Post date: [April 11, 2022, 4:01am UTC](https://discourse.julialang.org/t/turing-guide-documentation-prob-examples-throws-errors/50319/4 "2022-04-11T04:01:24Z")

</div>

This really ought to be explained in the guide doc, not just here.

I’m still confused about it though. The line `model = gdemo(2,4)` seems to give values of 2 and 4 to x and y, whereas the `prob` example gives them values `1.0` and `1.0`. Which ones are used, and why do they need to be provided twice?

---

<div class="post-metadata">

### Author: ![rdiaz02](https://avatars.discourse-cdn.com/v4/letter/r/d78d45/32.png) [@rdiaz02](https://discourse.julialang.org/u/rdiaz02)
#### Post date: [April 21, 2022, 7:18pm UTC](https://discourse.julialang.org/t/turing-guide-documentation-prob-examples-throws-errors/50319/5 "2022-04-21T19:18:00Z")

</div>

I also found it confusing: I was expecting the example to run, since it is given this way in the documentation, and it was not clear to me either which x and y were used. Anyway, the ones used are the ones given in the `prob` line; the following simplified example shows this:

```julia
@model function gdemo0(x)
    s ~ InverseGamma(2, 3)
    m ~ Normal(0, sqrt(s))
    x ~ Normal(m, sqrt(s))
end

model1 = gdemo0(1)
model4 = gdemo0(4)
model10 = gdemo0(10)

prob"x = 1.0 | model = model1, s = 1.0, m = 1.0"
prob"x = 1.0 | model = model4, s = 1.0, m = 1.0"
prob"x = 1.0 | model = model10, s = 1.0, m = 1.0"

## Compare to
pdf(Normal(1.0, 1.0), 1.0)

```

I can try to submit a (my first) PR to the docs, if appropriate.
