Skip to content

Leaf nodes and submaps are not sorted when pretty-printing choicemaps. #525

Open
@ztangent

Description

@ztangent

Currently, pretty-printing for choicemaps does not attempt to sort the addresses of leaf-nodes or submaps before printing them:

Gen.jl/src/choice_map.jl

Lines 126 to 137 in 18c06fd

for (key, value) in key_and_values
# For strings, `print` is what we want; `Base.show` includes quote marks.
# https://docs.julialang.org/en/v1/base/io-network/#Base.print
print(io, indent_vert_str)
print(io, (cur == n ? indent_last_str : indent_str) * "$(repr(key)) : $value\n")
cur += 1
end
for (key, submap) in key_and_submaps
print(io, indent_vert_str)
print(io, (cur == n ? indent_last_str : indent_str) * "$(repr(key))\n")
_show_pretty(io, submap, pre + 4, cur == n ? (vert_bars...,) : (vert_bars..., pre+1))
cur += 1

This leads to confusing output for choicemaps produced by the dynamic modeling language, especially those that involve for loops -- the addresses are not sorted by timesteps, and so it's not as easy to parse what's in the choicemap.

Fixing won't be hard -- we just need to sort the keys before printing, taking care to handle addresses which don't have ordering functions (Base.:<) defined for them.

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