TuringLang / DynamicPPL.jl

Implementation of domain-specific language (DSL) for dynamic probabilistic programming
https://turinglang.org/DynamicPPL.jl/
MIT License
164 stars 29 forks source link

`SimpleVarInfo` sometimes returns a `SimpleVarInfo` with `Int`-type `logp` and creates down-stream errors #569

Closed sunxd3 closed 9 months ago

sunxd3 commented 10 months ago

MWE

using DynamicPPL # version 0.24.4

julia> si = SimpleVarInfo(Dict(:x => [1, 2 ,3])) # looks good
SimpleVarInfo(Dict(:x => [1, 2, 3]), 0.0)

julia> si = SimpleVarInfo(Dict(:x => 1)) # looks good
SimpleVarInfo(Dict(:x => 1), 0.0)

julia> si = SimpleVarInfo(Dict(:x => [1, 2 ,3], :a => 1)) # bit strange
SimpleVarInfo(Dict{Symbol, Any}(:a => 1, :x => [1, 2, 3]), 0)

julia> acclogp!!(DynamicPPL.ThreadSafeVarInfo(si), -7.899)
ERROR: InexactError: Int64(-7.899)
Stacktrace:
 [1] Int64
   @ Base ./float.jl:909 [inlined]
 [2] convert
   @ Base ./number.jl:7 [inlined]
 [3] setindex!
   @ Base ./array.jl:1021 [inlined]
 [4] acclogp!!(vi::DynamicPPL.ThreadSafeVarInfo{SimpleVarInfo{…}, Vector{…}}, logp::Float64)
   @ DynamicPPL ~/.julia/packages/DynamicPPL/YWihz/src/threadsafe.jl:25
 [5] top-level scope
   @ REPL[24]:1
Some type information was truncated. Use `show(err)` to see complete types.
torfjelde commented 9 months ago

It's not Int, it's Real:

julia> d = Dict(:x => [1, 2 ,3], :a => 1)
Dict{Symbol, Any} with 2 entries:
  :a => 1
  :x => [1, 2, 3]

julia> typeof(DynamicPPL.SimpleVarInfo(d))
SimpleVarInfo{Dict{Symbol, Any}, Real, DynamicPPL.NoTransformation}