Closed fsaad closed 3 months ago
Related #506
Thanks for catching this!
So I'm trying to understand why the line of code you identified was introduced in the first place, and it looks like @alex-lew added it in this old commit: c8ce0d735a775749052c12db657e92cba761219c
Apparently it was introduced to address cases where things were being discarded, but shouldn't be. So maybe we can check if the fix you suggested @fsaad also passes the original test case that @alex-lew added?
This is the test case:
This issue also seems highly related, but @alex-lew identified a different line of code in add_unvisited_to_discard!
as the likely culprit, so maybe it's a different issue?
@yifr and I just ran into this same issue. We tried out @fsaad 's solution and it works.
We initially also thought it was the code @alex-lew points to, but actually that branch doesn't get run in @fsaad 's (and our own) examples because key in visited
is only true when the hierarchical address comes from a GenerativeFunction
call and not when you just define one like {:value => i} ~ ...
.
@fsaad 's reasoning for it being wrong is right – the original code has
add_unvisited_to_discard!(
isempty(subdiscard) ? choicemap() : subdiscard,
subvisited, submap)
But since add_unvisited_to_discard!
actually works by mutating its first argument, it doesn't make sense to pass in a fresh choicemap without first keeping a reference to it as they do in their fix
I'll make a quick PR with the fix!
Consider the following simple programs
Do we expect that
Gen.update
operates differently in these two cases. Formodel_ok
, if we callupdate
in such a way that reducesk
then the discard address{i}
are correctly placed in thediscard
, but inmodel_bad
, the address{:value => i}
are not in the discard. See following example:Discard for
model_ok
Discard for
model_bad
Possible Reason
The following lines seem to be the culprit: the recursive call to
add_unvisited_to_discard!
use an anonymous choicemap whensubdiscard
is empty, so the call toset_submap!
fills out asubdiscard
that we never access again.https://github.com/probcomp/Gen.jl/blob/7955b07e6df273633da6e72d434884b73fbdffe6/src/dynamic/update.jl#L177-L181
Changing these lines to
seems to fix the issue.