-
Notifications
You must be signed in to change notification settings - Fork 38
Closed
Description
Our current use of show for VarInfo is quite inconsistent. In:
module MWE
using DynamicPPL, Distributions, LinearAlgebra
function print(vi, name)
println("\n\n============================ $name ============================\n")
println("# DISPLAY")
display(vi)
println("\n# SHOW")
show(vi)
end
@model function f()
x ~ Normal()
y ~ MvNormal(Diagonal(fill(abs(x), 2)))
end
print(DynamicPPL.untyped_varinfo(f()), "UNTYPED")
print(DynamicPPL.typed_varinfo(f()), "TYPED")
print(DynamicPPL.SimpleVarInfo(f()), "SIMPLE")
print(DynamicPPL.ThreadSafeVarInfo(DynamicPPL.untyped_varinfo(f())), "THREADSAFE UNTYPED")
endOut:
============================ UNTYPED ============================
# DISPLAY
/=======================================================================
| VarInfo
|-----------------------------------------------------------------------
| Varnames : AbstractPPL.VarName[x, y]
| Range : UnitRange{Int64}[1:1, 2:3]
| Vals : Real[0.6393339904991309, -2.1020960714862715, 0.21204297326010874]
| Orders : [0, 0]
| Logp : -6.004814519363116
| #produce : 0
| flags : Dict{String, BitVector}("del" => [0, 0], "trans" => [0, 0])
\=======================================================================
# SHOW
VarInfo (2 variables (y, x), dimension 3; logp: -6.005)
============================ TYPED ============================
# DISPLAY
DynamicPPL.TypedVarInfo{@NamedTuple{x::DynamicPPL.Metadata{Dict{AbstractPPL.VarName{:x, typeof(identity)}, Int64}, Vector{Distributions.Normal{Float64}}, Vector{AbstractPPL.VarName{:x, typeof(identity)}}, Vector{Float64}}, y::DynamicPPL.Metadata{Dict{AbstractPPL.VarName{:y, typeof(identity)}, Int64}, Vector{Distributions.ZeroMeanDiagNormal{Tuple{Base.OneTo{Int64}}}}, Vector{AbstractPPL.VarName{:y, typeof(identity)}}, Vector{Float64}}}, Float64}((x = DynamicPPL.Metadata{Dict{AbstractPPL.VarName{:x, typeof(identity)}, Int64}, Vector{Distributions.Normal{Float64}}, Vector{AbstractPPL.VarName{:x, typeof(identity)}}, Vector{Float64}}(Dict(x => 1), [x], UnitRange{Int64}[1:1], [-1.250616290583678], Distributions.Normal{Float64}[Distributions.Normal{Float64}(μ=0.0, σ=1.0)], [0], Dict{String, BitVector}("del" => [0], "trans" => [0])), y = DynamicPPL.Metadata{Dict{AbstractPPL.VarName{:y, typeof(identity)}, Int64}, Vector{Distributions.ZeroMeanDiagNormal{Tuple{Base.OneTo{Int64}}}}, Vector{AbstractPPL.VarName{:y, typeof(identity)}}, Vector{Float64}}(Dict(y => 1), [y], UnitRange{Int64}[1:2], [0.7503094371292123, 0.3255295112123813], Distributions.ZeroMeanDiagNormal{Tuple{Base.OneTo{Int64}}}[ZeroMeanDiagNormal(
dim: 2
μ: Zeros(2)
Σ: [1.250616290583678 0.0; 0.0 1.250616290583678]
)
], [0], Dict{String, BitVector}("del" => [0], "trans" => [0]))), Base.RefValue{Float64}(-4.029914243271634), Base.RefValue{Int64}(0))
# SHOW
DynamicPPL.TypedVarInfo{@NamedTuple{x::DynamicPPL.Metadata{Dict{AbstractPPL.VarName{:x, typeof(identity)}, Int64}, Vector{Distributions.Normal{Float64}}, Vector{AbstractPPL.VarName{:x, typeof(identity)}}, Vector{Float64}}, y::DynamicPPL.Metadata{Dict{AbstractPPL.VarName{:y, typeof(identity)}, Int64}, Vector{Distributions.ZeroMeanDiagNormal{Tuple{Base.OneTo{Int64}}}}, Vector{AbstractPPL.VarName{:y, typeof(identity)}}, Vector{Float64}}}, Float64}((x = DynamicPPL.Metadata{Dict{AbstractPPL.VarName{:x, typeof(identity)}, Int64}, Vector{Distributions.Normal{Float64}}, Vector{AbstractPPL.VarName{:x, typeof(identity)}}, Vector{Float64}}(Dict(x => 1), [x], UnitRange{Int64}[1:1], [-1.250616290583678], Distributions.Normal{Float64}[Distributions.Normal{Float64}(μ=0.0, σ=1.0)], [0], Dict{String, BitVector}("del" => [0], "trans" => [0])), y = DynamicPPL.Metadata{Dict{AbstractPPL.VarName{:y, typeof(identity)}, Int64}, Vector{Distributions.ZeroMeanDiagNormal{Tuple{Base.OneTo{Int64}}}}, Vector{AbstractPPL.VarName{:y, typeof(identity)}}, Vector{Float64}}(Dict(y => 1), [y], UnitRange{Int64}[1:2], [0.7503094371292123, 0.3255295112123813], Distributions.ZeroMeanDiagNormal{Tuple{Base.OneTo{Int64}}}[ZeroMeanDiagNormal(
dim: 2
μ: Zeros(2)
Σ: [1.250616290583678 0.0; 0.0 1.250616290583678]
)
], [0], Dict{String, BitVector}("del" => [0], "trans" => [0]))), Base.RefValue{Float64}(-4.029914243271634), Base.RefValue{Int64}(0))
============================ SIMPLE ============================
# DISPLAY
SimpleVarInfo((x = 0.15360503384997595, y = [-0.023559980538471543, 0.19884647851374856]), -1.0257554501131314)
# SHOW
DynamicPPL.SimpleVarInfo{@NamedTuple{x::Float64, y::Vector{Float64}}, Float64, DynamicPPL.NoTransformation}((x = 0.15360503384997595, y = [-0.023559980538471543, 0.19884647851374856]), -1.0257554501131314, DynamicPPL.NoTransformation())
============================ THREADSAFE UNTYPED ============================
# DISPLAY
DynamicPPL.ThreadSafeVarInfo{DynamicPPL.UntypedVarInfo{DynamicPPL.Metadata{Dict{AbstractPPL.VarName, Int64}, Vector{Distributions.Distribution}, Vector{AbstractPPL.VarName}, Vector{Real}}, Float64}, Vector{Base.RefValue{Float64}}}(VarInfo (2 variables (y, x), dimension 3; logp: -3.004), Base.RefValue{Float64}[Base.RefValue{Float64}(0.0)])
# SHOW
DynamicPPL.ThreadSafeVarInfo{DynamicPPL.UntypedVarInfo{DynamicPPL.Metadata{Dict{AbstractPPL.VarName, Int64}, Vector{Distributions.Distribution}, Vector{AbstractPPL.VarName}, Vector{Real}}, Float64}, Vector{Base.RefValue{Float64}}}(VarInfo (2 variables (y, x), dimension 3; logp: -3.004), Base.RefValue{Float64}[Base.RefValue{Float64}(0.0)])Main.MWENote that display results in a call to show(io, ::MIME"text/plain", vi), which is meant to produce a nice, human-readable output. show on the other hand goes to show(io, vi), which should produce something that includes full details about the object, enough to reconstruct it, preferably as valid Julia code.
Two things should be fixed:
- We are violating the second rule at least with
UntypedVarInfo, i.e.show(vi)is not a dump ofvias valid code. - We are inconsistent in what we produce with
displayfor the pretty print.TypedVarInfoandThreadSafeVarInfojust fall back toshow(vi)which is not very readable.SimpleVarInfoandUntypedVarInfoboth do have nice print outs, though they are quite different.
This issue supersedes #243.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels