-
Notifications
You must be signed in to change notification settings - Fork 160
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Incorrect Dynamic DSL update
Implementation on the Prox Base Branch
#506
Comments
@georgematheos @femtomc Tagging you here as I think you might have a better idea for the fix. |
@mugamma Can you provide a bit more context about the issue:
E.g. what exactly is the bug -- is there a stacktrace? Or is it a math semantics bug (like the above)? |
I think I can guess the issue here:
One way I fixed this in GenJAX is that I don't have a To me, "the right fix" is just to eliminate
In lieu of correcting the type/interface hierarchy, if the implementation you posted is "working" now -- I'm concerned about how Also, I don't understand these lines: if key in visited
# the recursive call to update already handled the discard
# for this entire submap
continue
else
subvisited = visited[key]
if isempty(subvisited)
# none of this submap was visited, so we discard the whole thing
@assert isempty(get_submap(discard, key))
set_submap!(discard, key, submap)
else
subdiscard = get_submap(discard, key)
add_unvisited_to_discard!(
isempty(subdiscard) ? choicemap() : subdiscard,
subvisited, submap)
set_submap!(discard, key, subdiscard)
end
end You check if |
Right, so -- for # get_values_shallow and get_nonvalue_submaps_shallow are just filters on get_submaps_shallow
"""
get_values_shallow(choices::ChoiceMap)
Returns an iterable collection of tuples `(address, value)`
for each value stored at a top-level address in `choices`.
(Works by applying a filter to `get_submaps_shallow`,
so this internally requires iterating over every submap.)
"""
function get_values_shallow(choices::ChoiceMap)
(
(addr, get_value(submap))
for (addr, submap) in get_submaps_shallow(choices)
if has_value(submap)
)
end This returns an empty iterator for Gen.jl/src/choice_map/choice_map.jl Line 152 in af6fbfc
@mugamma It seems like, for that branch (which includes the distribution as generative function changes) -- the choice map interfaces (implemented for @inline has_value(choices::ValueChoiceMap) = true
@inline get_value(choices::ValueChoiceMap) = choices.val
@inline get_submap(choices::ValueChoiceMap, addr) = EmptyChoiceMap()
@inline get_submaps_shallow(choices::ValueChoiceMap) = ()
@inline Base.:(==)(a::ValueChoiceMap, b::ValueChoiceMap) = a.val == b.val
@inline Base.:(==)(a::ValueChoiceMap, b::ChoiceMap) = false
@inline Base.:(==)(a::ChoiceMap, b::ValueChoiceMap) = false
@inline Base.isapprox(a::ValueChoiceMap, b::ValueChoiceMap) = isapprox(a.val, b.val)
@inline get_address_schema(::Type{<:ValueChoiceMap}) = AllAddressSchema() And perhaps the right fix is just to use |
@femtomc @mugamma I thought the issue didn't have to do with The issue arises when a dynamic DSL generative function does something like As a result, when we call
So, in response to @femtomc's question:
No -- if I write |
Thanks Alex for clarifying! Dumb suggestion — but can you implement this function by taking the complement of the visited selection? And then applying this complement to filter the previous choice map and merging the result with the discard created from the update visitation? |
Related #512 |
Yesterday @alex-lew and I found a bug in the implementation of
add_unvisited_to_discard!
on the20220821-prox-base
branch. The bug can be reproduced by instantiating the InverseGraphics project with Gen coming from the20220821-prox-base
branch and replacing the likelihood call with a call to a Prox version of the likelihood (e.g. the one found here). The bug occurs when running line 139 of thedemo.jl
notebook.The bug seems to come from the incorrect handling of visited submaps of type
ValueChoiceMap
. Alex and I came up with the following fix. I have not reasoned carefully about the fix so I'm not sure it is a complete fix. I also don't think it is the most elegant fix, but I'm including it for reference.The text was updated successfully, but these errors were encountered: