ERROR: TaskFailedException

I have a differential equation based model for which i’m doing inference using Turing. For solver I use alg = Rodas5P(linsolve = QRFactorization()). I was wondering if QRFactorization has anything to do with current error? But if I doesn’t use that I get Singularity Error.

Can someone explain this error and what could be possible cause?

ERROR: TaskFailedException

    nested task error: TaskFailedException
    
        nested task error: TypeError: in setfield!, expected LinearAlgebra.QRCompactWY{ForwardDiff.Dual{ForwardDiff.Tag{Turing.TuringTag, Float64}, Float64, 12}, Matrix{ForwardDiff.Dual{ForwardDiff.Tag{Turing.TuringTag, Float64}, Float64, 12}}, Matrix{ForwardDiff.Dual{ForwardDiff.Tag{Turing.TuringTag, Float64}, Float64, 12}}}, got a value of type QR{ForwardDiff.Dual{ForwardDiff.Tag{Turing.TuringTag, Float64}, Float64, 12}, Matrix{ForwardDiff.Dual{ForwardDiff.Tag{Turing.TuringTag, Float64}, Float64, 12}}, Vector{ForwardDiff.Dual{ForwardDiff.Tag{Turing.TuringTag, Float64}, Float64, 12}}}
        Stacktrace:
          [1] setproperty!(cache::LinearSolve.LinearCache{…}, name::Symbol, x::QR{…})
            @ LinearSolve ~/.julia/packages/LinearSolve/Dqpre/src/common.jl:95
          [2] macro expansion
            @ ~/.julia/packages/LinearSolve/Dqpre/src/LinearSolve.jl:135 [inlined]
          [3] solve!(cache::LinearSolve.LinearCache{…}, alg::QRFactorization{…}; kwargs::@Kwargs{…})
            @ LinearSolve ~/.julia/packages/LinearSolve/Dqpre/src/LinearSolve.jl:130
          [4] solve!(::LinearSolve.LinearCache{…}; kwargs::@Kwargs{…})
            @ LinearSolve ~/.julia/packages/LinearSolve/Dqpre/src/common.jl:189
          [5] dolinsolve(integrator::OrdinaryDiffEq.ODEIntegrator{…}, linsolve::LinearSolve.LinearCache{…}; A::Matrix{…}, linu::Nothing, b::Vector{…}, du::Vector{…}, u::Vector{…}, p::Vector{…}, t::Float64, weight::Vector{…}, solverdata::@NamedTuple{…}, reltol::Float64)
            @ OrdinaryDiffEq ~/.julia/packages/OrdinaryDiffEq/pWCEq/src/misc_utils.jl:107
          [6] perform_step!(integrator::OrdinaryDiffEq.ODEIntegrator{…}, cache::OrdinaryDiffEq.Rosenbrock5Cache{…}, repeat_step::Bool)
            @ OrdinaryDiffEq ~/.julia/packages/OrdinaryDiffEq/pWCEq/src/perform_step/rosenbrock_perform_step.jl:2428
          [7] perform_step!(integrator::OrdinaryDiffEq.ODEIntegrator{…}, cache::OrdinaryDiffEq.Rosenbrock5Cache{…})
            @ OrdinaryDiffEq ~/.julia/packages/OrdinaryDiffEq/pWCEq/src/perform_step/rosenbrock_perform_step.jl:2368
          [8] solve!(integrator::OrdinaryDiffEq.ODEIntegrator{…})
            @ OrdinaryDiffEq ~/.julia/packages/OrdinaryDiffEq/pWCEq/src/solve.jl:538
          [9] #__solve#749
            @ ~/.julia/packages/OrdinaryDiffEq/pWCEq/src/solve.jl:6 [inlined]
         [10] __solve
            @ ~/.julia/packages/OrdinaryDiffEq/pWCEq/src/solve.jl:1 [inlined]
         [11] solve_call(_prob::ODEProblem{…}, args::Rodas5P{…}; merge_callbacks::Bool, kwargshandle::Nothing, kwargs::@Kwargs{…})
            @ DiffEqBase ~/.julia/packages/DiffEqBase/eLhx9/src/solve.jl:609
         [12] solve_call
            @ DiffEqBase ~/.julia/packages/DiffEqBase/eLhx9/src/solve.jl:567 [inlined]
         [13] #solve_up#42
            @ DiffEqBase ~/.julia/packages/DiffEqBase/eLhx9/src/solve.jl:1058 [inlined]
         [14] solve_up
            @ DiffEqBase ~/.julia/packages/DiffEqBase/eLhx9/src/solve.jl:1044 [inlined]
         [15] #solve#40
            @ DiffEqBase ~/.julia/packages/DiffEqBase/eLhx9/src/solve.jl:981 [inlined]
         [16] fit_CTL(__model__::DynamicPPL.Model{…}, __varinfo__::DynamicPPL.ThreadSafeVarInfo{…}, __context__::DynamicPPL.SamplingContext{…}, data::Vector{…}, prob::ODEProblem{…})
            @ Main ~/julia_programs/CTL/code/CTL_MUT_EXP.jl:321
         [17] _evaluate!!(model::DynamicPPL.Model{…}, varinfo::DynamicPPL.ThreadSafeVarInfo{…}, context::DynamicPPL.SamplingContext{…})
            @ DynamicPPL ~/.julia/packages/DynamicPPL/U5lel/src/model.jl:963
         [18] evaluate_threadsafe!!(model::Any, varinfo::Any, context::Any)
            @ DynamicPPL ~/.julia/packages/DynamicPPL/U5lel/src/model.jl:952 [inlined]
         [19] evaluate!!(model::DynamicPPL.Model{…}, varinfo::DynamicPPL.TypedVarInfo{…}, context::DynamicPPL.SamplingContext{…})
            @ DynamicPPL ~/.julia/packages/DynamicPPL/U5lel/src/model.jl:887
         [20] logdensity
            @ ~/.julia/packages/DynamicPPL/U5lel/src/logdensityfunction.jl:94 [inlined]
         [21] Fix1
            @ ./operators.jl:1118 [inlined]
         [22] vector_mode_dual_eval!
            @ ~/.julia/packages/ForwardDiff/PcZ48/src/apiutils.jl:24 [inlined]
         [23] vector_mode_gradient!(result::DiffResults.MutableDiffResult{…}, f::Base.Fix1{…}, x::Vector{…}, cfg::ForwardDiff.GradientConfig{…})
            @ ForwardDiff ~/.julia/packages/ForwardDiff/PcZ48/src/gradient.jl:96
         [24] gradient!
            @ ~/.julia/packages/ForwardDiff/PcZ48/src/gradient.jl:37 [inlined]
         [25] gradient!
            @ ~/.julia/packages/ForwardDiff/PcZ48/src/gradient.jl:35 [inlined]
         [26] logdensity_and_gradient
            @ ~/.julia/packages/LogDensityProblemsAD/OQ0BL/ext/LogDensityProblemsADForwardDiffExt.jl:118 [inlined]
         [27] ∂logπ∂θ
            @ ~/.julia/packages/Turing/Gqh3H/src/mcmc/hmc.jl:159 [inlined]
         [28] ∂H∂θ
            @ ~/.julia/packages/AdvancedHMC/AlvV4/src/hamiltonian.jl:38 [inlined]
         [29] phasepoint(h::AdvancedHMC.Hamiltonian{…}, θ::Vector{…}, r::Vector{…})
            @ AdvancedHMC ~/.julia/packages/AdvancedHMC/AlvV4/src/hamiltonian.jl:74
         [30] phasepoint(rng::TaskLocalRNG, θ::Vector{…}, h::AdvancedHMC.Hamiltonian{…})
            @ AdvancedHMC ~/.julia/packages/AdvancedHMC/AlvV4/src/hamiltonian.jl:155
         [31] initialstep(rng::TaskLocalRNG, model::DynamicPPL.Model{…}, spl::DynamicPPL.Sampler{…}, vi::DynamicPPL.TypedVarInfo{…}; initial_params::Nothing, nadapts::Int64, kwargs::@Kwargs{})
            @ Turing.Inference ~/.julia/packages/Turing/Gqh3H/src/mcmc/hmc.jl:163
         [32] step(rng::TaskLocalRNG, model::DynamicPPL.Model{…}, spl::DynamicPPL.Sampler{…}; initial_params::Nothing, kwargs::@Kwargs{…})
            @ DynamicPPL ~/.julia/packages/DynamicPPL/U5lel/src/sampler.jl:116
         [33] step
            @ ~/.julia/packages/DynamicPPL/U5lel/src/sampler.jl:99 [inlined]
         [34] macro expansion
            @ ~/.julia/packages/AbstractMCMC/Es490/src/sample.jl:127 [inlined]
         [35] macro expansion
            @ ~/.julia/packages/AbstractMCMC/Es490/src/logging.jl:16 [inlined]
         [36] mcmcsample(rng::TaskLocalRNG, model::DynamicPPL.Model{…}, sampler::DynamicPPL.Sampler{…}, N::Int64; progress::Bool, progressname::String, callback::Nothing, discard_initial::Int64, thinning::Int64, chain_type::Type, initial_state::Nothing, kwargs::@Kwargs{…})
            @ AbstractMCMC ~/.julia/packages/AbstractMCMC/Es490/src/sample.jl:117
         [37] mcmcsample
            @ ~/.julia/packages/AbstractMCMC/Es490/src/sample.jl:95 [inlined]
         [38] #sample#30
            @ ~/.julia/packages/Turing/Gqh3H/src/mcmc/hmc.jl:117 [inlined]
         [39] sample
            @ ~/.julia/packages/Turing/Gqh3H/src/mcmc/hmc.jl:86 [inlined]
         [40] (::AbstractMCMC.var"#32#45"{…})()
            @ AbstractMCMC ~/.julia/packages/AbstractMCMC/Es490/src/sample.jl:387
    
    ...and 1 more exception.
    
    Stacktrace:
     [1] sync_end(c::Channel{Any})
       @ Base ./task.jl:448
     [2] macro expansion
       @ ./task.jl:480 [inlined]
     [3] (::AbstractMCMC.var"#31#44"{…})()
       @ AbstractMCMC ~/.julia/packages/AbstractMCMC/Es490/src/sample.jl:361
Stacktrace:
  [1] sync_end(c::Channel{Any})
    @ Base ./task.jl:448
  [2] macro expansion
    @ ./task.jl:480 [inlined]
  [3] macro expansion
    @ ~/.julia/packages/AbstractMCMC/Es490/src/sample.jl:339 [inlined]
  [4] macro expansion
    @ ~/.julia/packages/ProgressLogging/6KXlp/src/ProgressLogging.jl:328 [inlined]
  [5] macro expansion
    @ ~/.julia/packages/AbstractMCMC/Es490/src/logging.jl:9 [inlined]
  [6] mcmcsample(rng::TaskLocalRNG, model::DynamicPPL.Model{…}, sampler::DynamicPPL.Sampler{…}, ::MCMCThreads, N::Int64, nchains::Int64; progress::Bool, progressname::String, initial_params::Nothing, initial_state::Nothing, kwargs::@Kwargs{…})
    @ AbstractMCMC ~/.julia/packages/AbstractMCMC/Es490/src/sample.jl:333
  [7] sample(rng::TaskLocalRNG, model::DynamicPPL.Model{…}, sampler::DynamicPPL.Sampler{…}, ensemble::MCMCThreads, N::Int64, n_chains::Int64; chain_type::Type, progress::Bool, kwargs::@Kwargs{})
    @ Turing.Inference ~/.julia/packages/Turing/Gqh3H/src/mcmc/Inference.jl:229
  [8] sample
    @ Turing.Inference ~/.julia/packages/Turing/Gqh3H/src/mcmc/Inference.jl:218 [inlined]
  [9] #sample#4
    @ Turing.Inference ~/.julia/packages/Turing/Gqh3H/src/mcmc/Inference.jl:214 [inlined]
 [10] sample
    @ Turing.Inference ~/.julia/packages/Turing/Gqh3H/src/mcmc/Inference.jl:205 [inlined]
 [11] #sample#3
    @ Turing.Inference ~/.julia/packages/Turing/Gqh3H/src/mcmc/Inference.jl:201 [inlined]
 [12] sample(model::DynamicPPL.Model{…}, alg::NUTS{…}, ensemble::MCMCThreads, N::Int64, n_chains::Int64)
    @ Turing.Inference ~/.julia/packages/Turing/Gqh3H/src/mcmc/Inference.jl:193
 [13] top-level scope
    @ ~/julia_programs/CTL/code/CTL_MUT_EXP.jl:402
Some type information was truncated. Use `show(err)` to see complete types.

Share a reproducer.