Skip to content

Chains shouldn't (really) be indexed by Symbols #470

@penelopeysm

Description

@penelopeysm

I know this is a contrived example, but I don't think that this should be a problem if somebody wanted to do it:

julia> using Turing

julia> @model function f()
          var"x.a" ~ Normal()
          x = (a = 1.0,)
          x.a ~ Normal()
       end
f (generic function with 2 methods)

julia> sample(f(), MH(), 100)
Sampling 100%|███████████████████████████████████████████████████████████████████| Time: 0:00:02
Chains MCMC chain (100×3×1 Array{Float64, 3}):

Iterations        = 1:1:100
Number of chains  = 1
Samples per chain = 100
Wall duration     = 3.61 seconds
Compute duration  = 3.61 seconds
parameters        = x.a
internals         = lp
Error showing value of type Chains{Float64, AxisArrays.AxisArray{Float64, 3, Array{Float64, 3}, Tuple{AxisArrays.Axis{:iter, StepRange{Int64, Int64}}, AxisArrays.Axis{:var, Vector{Symbol}}, AxisArrays.Axis{:chain, UnitRange{Int64}}}}, Missing, @NamedTuple{parameters::Vector{Symbol}, internals::Vector{Symbol}}, @NamedTuple{varname_to_symbol::OrderedDict{AbstractPPL.VarName, Symbol}, start_time::Float64, stop_time::Float64}}:
ERROR: ArgumentError: index Symbol[] not found
[...]

IMO the use of Symbols in chains should be reserved for printing / indexing convenience. The underlying data type should, IMO, be a type parameter (in our case, VarName) that is convertable to a Symbol.

This would also eliminate the need for the varname to symbol dict that we stick inside our chains (to be precise, it would make it an inherent part of the Chains object, rather than it being manually tacked on as an extra).

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