ERROR: using Cholesky decomposition when using Turing.jl Bayesien inference

Hi everyone, i’am sharing my code snippet where i try to do some bayesien inference like here

@model IPPModel() = begin

#assign priors for the SPDE layer
μ₁ ~ L₁priors.μprior
l₁ ~ L₁priors.lprior
σ₁ ~ L₁priors.σprior
w₁ ~ wprior
μ = μ₁ .* exp.(spatialSPDE(smoothclamp(l₁, lmin, lmax), σ₁, w₁))
μi = μ
println(integrate_on_mesh(μ, mesh.point, mesh.cell))
Turing.@addlogprob! logsum(μi) - integrate_on_mesh(μ, mesh.point, mesh.cell)
return μ
end

function (m::spatialSPDE)(κ::Real, σ::Real, w::AbstractVector)
L = Symmetric(κ * C_inv * κ) # for alpha=2.0
F = cholesky(L).PtL’
return F \ (σ * w) # solve SPDE
end

the problem when using the cholesky decomposition i get this error:
ERROR: LoadError: TaskFailedException

nested task error: TaskFailedException

    nested task error: TypeError: in Sparse, in Tv, expected Tv<:Union{Float64, ComplexF64}, got Type{ForwardDiff.Dual{ForwardDiff.Tag{DynamicPPL.DynamicPPLTag, Float64}, Float64, 3}}
    Stacktrace:
      [1] SparseArrays.CHOLMOD.Sparse(A::SparseMatrixCSC{ForwardDiff.Dual{ForwardDiff.Tag{DynamicPPL.DynamicPPLTag, Float64}, Float64, 3}, Int64}, stype::Int64)
        @ SparseArrays.CHOLMOD C:\Users\asus\AppData\Local\Programs\Julia-1.10.2\share\julia\stdlib\v1.10\SparseArrays\src\solvers\cholmod.jl:917
      [2] SparseArrays.CHOLMOD.Sparse(A::Symmetric{ForwardDiff.Dual{ForwardDiff.Tag{DynamicPPL.DynamicPPLTag, Float64}, Float64, 3}, SparseMatrixCSC{ForwardDiff.Dual{ForwardDiff.Tag{DynamicPPL.DynamicPPLTag, Float64}, Float64, 3}, Int64}})
        @ SparseArrays.CHOLMOD C:\Users\asus\AppData\Local\Programs\Julia-1.10.2\share\julia\stdlib\v1.10\SparseArrays\src\solvers\cholmod.jl:931
      [3] cholesky(A::Symmetric{ForwardDiff.Dual{ForwardDiff.Tag{DynamicPPL.DynamicPPLTag, Float64}, Float64, 3}, SparseMatrixCSC{ForwardDiff.Dual{ForwardDiff.Tag{DynamicPPL.DynamicPPLTag, Float64}, Float64, 3}, Int64}}; kws::@Kwargs{})
        @ SparseArrays.CHOLMOD C:\Users\asus\AppData\Local\Programs\Julia-1.10.2\share\julia\stdlib\v1.10\SparseArrays\src\solvers\cholmod.jl:1437
      [4] cholesky(A::Symmetric{ForwardDiff.Dual{ForwardDiff.Tag{DynamicPPL.DynamicPPLTag, Float64}, Float64, 3}, SparseMatrixCSC{ForwardDiff.Dual{ForwardDiff.Tag{DynamicPPL.DynamicPPLTag, Float64}, Float64, 3}, Int64}})
        @ SparseArrays.CHOLMOD C:\Users\asus\AppData\Local\Programs\Julia-1.10.2\share\julia\stdlib\v1.10\SparseArrays\src\solvers\cholmod.jl:1437
      [5] safe_cholesky(L::Symmetric{ForwardDiff.Dual{ForwardDiff.Tag{DynamicPPL.DynamicPPLTag, Float64}, Float64, 3}, SparseMatrixCSC{ForwardDiff.Dual{ForwardDiff.Tag{DynamicPPL.DynamicPPLTag, Float64}, Float64, 3}, Int64}})
        @ Main d:\Statistical_tools\test_delaunay_triangulation_refined\src\spatialSPDE.j

what can i do to make it without deleting the cholesky decomposition since it’s needed here

Hello!

This code you’ve provided isn’t runnable, because we don’t have access to the variables and types you’re using. For example – what is L₁priors?

Could you please provide an example that can be run as a single script? If you need specific packages to be installed, please list those too.

Thank you :slight_smile: