probcomp / Gen.jl

A general-purpose probabilistic programming system with programmable inference

Home Page:https://gen.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`generate` of Static Gen Fn using StaticAssmt yields incorrect behavior

georgematheos opened this issue · comments

Here is a MWE to illustrate the bug:

julia> using Gen
julia> @gen (static) function foo()
           {:x => :y} ~ normal(0, 1)
       end
var"##StaticGenFunction_foo#269"(Dict{Symbol, Any}(), Dict{Symbol, Any}())

julia> @load_generated_functions()

julia> tr, _ = generate(foo, (), choicemap((:x => :y, 1.0)));

julia> get_choices(tr)
│
└── :x
    │
    └── :y : 1.0


julia> tr2, _ = generate(foo, (), get_choices(tr));

julia> get_choices(tr2)
│
└── :x
    │
    └── :y : -0.4208570938873921

The choicemap of tr2 should be the same as that of tr, but it is not.

I have not investigated carefully where the bug comes in. I have not checked whether having the nested address is necessary for the bug to occur (but I suspect that it is).

Note that the use of the static-assignment choicemap is necessary. If instead the constraints are a DynamicChoiceMap, no bug occurs:

julia> tr3, _ = generate(foo, (), DynamicChoiceMap(get_choices(tr)));

julia> get_choices(tr3)
│
└── :x
    │
    └── :y : 1.0