Skip to content

LKJCholesky model fails through LogDensityProblems when using SimpleVarInfo #652

@sunxd3

Description

@sunxd3
using DynamicPPL, Distributions, LogDensityProblems

@model demo_lkj() = x ~ LKJCholesky(2, 1.0)
model = demo_lkj()

logdensity = DynamicPPL.LogDensityFunction(model, DynamicPPL.getlogjoint, DynamicPPL.VarInfo(model));
logdensity_simple = DynamicPPL.LogDensityFunction(model, DynamicPPL.getlogjoint, DynamicPPL.SimpleVarInfo(model));
θ = rand(4);

# this is fine
LogDensityProblems.logdensity(logdensity, θ)

# errors
LogDensityProblems.logdensity(logdensity_simple, θ)


ERROR: MethodError: no method matching length(::LinearAlgebra.Cholesky{Float64, Matrix{Float64}})

Closest candidates are:
  length(::PrettyTables.RowTable)
   @ PrettyTables ~/.julia/packages/PrettyTables/f6dXb/src/tables.jl:109
  length(::Distributions.VonMisesFisherSampler)
   @ Distributions ~/.julia/packages/Distributions/nmUhn/src/samplers/vonmisesfisher.jl:20
  length(::LibGit2.GitBlob)
   @ LibGit2 ~/.julia/juliaup/julia-1.10.5+0.aarch64.apple.darwin14/share/julia/stdlib/v1.10/LibGit2/src/blob.jl:3
  ...

Stacktrace:
 [1] map
   @ ./tuple.jl:291 [inlined]
 [2] unflatten(original::Tuple{LinearAlgebra.Cholesky{Float64, Matrix{Float64}}}, x::Vector{Float64})
   @ DynamicPPL ~/DynamicPPL.jl/src/utils.jl:628
 [3] unflatten(original::@NamedTuple{x::LinearAlgebra.Cholesky{Float64, Matrix{Float64}}}, x::Vector{Float64})
   @ DynamicPPL ~/DynamicPPL.jl/src/utils.jl:639
 [4] unflatten(svi::SimpleVarInfo{@NamedTuple{…}, Float64, DynamicPPL.NoTransformation}, x::Vector{Float64})
   @ DynamicPPL ~/DynamicPPL.jl/src/simple_varinfo.jl:264
 [5] unflatten(varinfo::SimpleVarInfo{…}, context::DefaultContext, θ::Vector{…})
   @ DynamicPPL ~/DynamicPPL.jl/src/abstract_varinfo.jl:737
 [6] logdensity(f::DynamicPPL.LogDensityFunction{SimpleVarInfo{…}, Model{…}, Nothing}, θ::Vector{Float64})
   @ DynamicPPL ~/DynamicPPL.jl/src/logdensityfunction.jl:139
 [7] top-level scope
   @ REPL[14]:1
Some type information was truncated. Use `show(err)` to see complete types.

versions
Julia 1.10.5
Bijectors: 1.13.17
DynamicPPL: 0.29.0

(Still an issue on 0.37.0)

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