Skip to content
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

Gen.choicemap constructor assigns choice-map args as leaves #517

Open
sritchie opened this issue Nov 7, 2023 · 2 comments
Open

Gen.choicemap constructor assigns choice-map args as leaves #517

sritchie opened this issue Nov 7, 2023 · 2 comments

Comments

@sritchie
Copy link

sritchie commented Nov 7, 2023

In this version of the constructor: https://github.com/probcomp/Gen.jl/blob/master/src/choice_map.jl#L651-L661

This line:

choices[addr] = value

assigns the value as a leaf always, leading to this erro:

julia> cm = Gen.choicemap(:k => Gen.choicemap(:v => 2))
│
└── :k : DynamicChoiceMap(Dict{Any, Any}(:v => 2), Dict{Any, Any}())


julia> Gen.has_value(cm, :k)
true

julia> Gen.has_submap(cm, :k)
false
@fsaad
Copy link
Collaborator

fsaad commented Nov 7, 2023

This behavior is the desired one, per the documentation of Gen.set_value! and Gen.set_submap!.

For the example above, the API requires breaking down the construction into separate calls:

julia> cm = Gen.choicemap()
julia> Gen.set_submap!(cm, :k, Gen.choicemap(:v =>2))

@sritchie
Copy link
Author

sritchie commented Nov 7, 2023

I would recommend that the constructor check and guard against this case though, yeah?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants