Skip to content

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

Description

@sritchie

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

Activity

  1. fsaad commented on Nov 7, 2023

    @fsaad
    Collaborator

    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))
  2. sritchie commented on Nov 7, 2023

    @sritchie
    CollaboratorAuthor

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions