Hi,
I have a custom package named MyPkg and it contains a function named test_fun() as follows, that copied and modified from Turing documentation.
function test_fun()
# Set the true probability of heads in a coin.
p_true = 0.5
# Iterate from having seen 0 observations to 100 observations.
Ns = 0:100;
# Draw data from a Bernoulli distribution, i.e. draw heads or tails.
Random.seed!(12)
data = rand(Bernoulli(p_true), last(Ns))
# Declare our Turing model.
@model coinflip(y, ::Type{T}=Float64) where {T} = begin
# Our prior belief about the probability of heads in a coin.
p ~ Beta(1, 1)
# The number of observations.
N = length(y)
for n in 1:N
# Heads or tails of a coin are drawn from a Bernoulli distribution.
y[n] ~ Bernoulli(p)
end
end;
# Settings of the Hamiltonian Monte Carlo (HMC) sampler.
iterations = 1000
Ο΅ = 0.05
Ο = 10
# Start sampling.
chain = sample(coinflip(data), HMC(Ο΅, Ο), iterations);
return chain
end
When I precompile this custom package the second time, as
using Revise
using MyPkg
I am getting an error as follows:
julia> β Error: evaluation error starting at C:\Users\zac\.julia\dev\MyPkg\src\MyPkg.jl:34
β mod = MyPkg
β ex =
β quote
β #= C:\Users\zac\.julia\dev\MyPkg\src\MyPkg.jl:34 =#
β function test_fun()
β #= C:\Users\zac\.julia\dev\MyPkg\src\MyPkg.jl:36 =#
β p_true = 0.5
β #= C:\Users\zac\.julia\dev\MyPkg\src\MyPkg.jl:39 =#
β Ns = 0:100
β #= C:\Users\zac\.julia\dev\MyPkg\src\MyPkg.jl:42 =#
β Random.seed!(12)
β #= C:\Users\zac\.julia\dev\MyPkg\src\MyPkg.jl:43 =#
β data = rand(Bernoulli(p_true), last(Ns))
β #= C:\Users\zac\.julia\dev\MyPkg\src\MyPkg.jl:46 =#
β #= C:\Users\zac\.julia\dev\MyPkg\src\MyPkg.jl:46 =# @model (coinflip(y, ::Type{T}=Float64) where T) = begin
β #= C:\Users\zac\.julia\dev\MyPkg\src\MyPkg.jl:46 =#
β #= C:\Users\zac\.julia\dev\MyPkg\src\MyPkg.jl:48 =#
β p ~ Beta(1, 1)
β #= C:\Users\zac\.julia\dev\MyPkg\src\MyPkg.jl:51 =#
β N = length(y)
β #= C:\Users\zac\.julia\dev\MyPkg\src\MyPkg.jl:52 =#
β for n = 1:N
β #= C:\Users\zac\.julia\dev\MyPkg\src\MyPkg.jl:54 =#
β y[n] ~ Bernoulli(p)
β end
β end
β #= C:\Users\zac\.julia\dev\MyPkg\src\MyPkg.jl:59 =#
β iterations = 1000
β #= C:\Users\zac\.julia\dev\MyPkg\src\MyPkg.jl:60 =#
β Ο΅ = 0.05
β #= C:\Users\zac\.julia\dev\MyPkg\src\MyPkg.jl:61 =#
β Ο = 10
β #= C:\Users\zac\.julia\dev\MyPkg\src\MyPkg.jl:64 =#
β chain = sample(coinflip(data), HMC(Ο΅, Ο), iterations)
β #= C:\Users\zac\.julia\dev\MyPkg\src\MyPkg.jl:65 =#
β return chain
β end
β end
β exception =
β UndefVarError: #s95 not defined
β Stacktrace:
β [1] step_expr!(::Any, ::JuliaInterpreter.Frame, ::Any, ::Bool) at C:\Users\zac\.julia\packages\JuliaInterpreter\hyz9z\src\interpret.jl:532
β @ Revise C:\Users\zac\.julia\packages\Revise\S7mrl\src\lowered.jl:105
When I modify the model definition in the function @model coinflip(y, ::Type{T}=Float64) where {T} = begin
to @model coinflip(y) = begin
, then there is no error. But in my other functions, I need to use the first type of model definition. So, how can I solve this error?
Thanks in Advance !
Manu