Skip to content

Commit 81bb2cf

Browse files
authored
Merge pull request #534 from yifr/discard-update-fix
#512 - Fix missing addresses in discard during update
2 parents 95c797f + 92d73be commit 81bb2cf

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

src/dynamic/update.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,10 +175,11 @@ function add_unvisited_to_discard!(discard::DynamicChoiceMap,
175175
set_submap!(discard, key, submap)
176176
else
177177
subdiscard = get_submap(discard, key)
178+
subdiscard_recursive = isempty(subdiscard) ? choicemap() : subdiscard
178179
add_unvisited_to_discard!(
179-
isempty(subdiscard) ? choicemap() : subdiscard,
180+
subdiscard_recursive,
180181
subvisited, submap)
181-
set_submap!(discard, key, subdiscard)
182+
set_submap!(discard, key, subdiscard_recursive)
182183
end
183184
end
184185
end

test/dsl/dynamic_dsl.jl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,19 @@ end
181181
@test isapprox(expected_new_score, get_score(new_trace))
182182
@test isapprox(expected_weight, weight)
183183
@test retdiff === UnknownChange()
184+
185+
# Test correct discarding for hierarchical choicemap update
186+
@gen function hierarchical_update()
187+
k ~ poisson(5)
188+
for i=1:k
189+
{:value => i} ~ uniform(0,1)
190+
end
191+
end
192+
tr, = Gen.generate(hierarchical_update, (), choicemap(:k=>3));
193+
# update k, affecting the number of children
194+
(new_trace, weight, _, discard) = Gen.update(tr, Gen.choicemap(:k=>1));
195+
@test Gen.has_value(discard, :value => 2)
196+
@test Gen.has_value(discard, :value => 3)
184197
end
185198

186199
@testset "regenerate" begin

0 commit comments

Comments
 (0)