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