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

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

Open
ztangent opened this issue Apr 5, 2024 · 0 comments
Open

Comments

@ztangent
Copy link
Member

ztangent commented Apr 5, 2024

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.

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

1 participant