JuliaStats / Klara.jl

MCMC inference in Julia
Other
167 stars 38 forks source link

error using reverse autodiff with a closure #152

Closed tpapp closed 7 years ago

tpapp commented 7 years ago

The following is a code snippet from a model. It works perfectly with autodiff=:forward, but fails with :reverse:

julia>  θ_raw = BasicContMuvParameter(:θ_raw,
                                      logtarget=θ_raw->
                                      structural_ll_raw(path_counts,
                                                        LMSimple1,
                                                        θ_raw),
                                      autodiff=:reverse)
ERROR: BoundsError: attempt to access 0-element Array{Any,1} at index [1]
 in getindex(::Array{Any,1}, ::Int64) at ./array.jl:386
 in #BasicContMuvParameter#113(::Void, ::Void, ::Void, ::Void, ::Void, ::Void, ::##
4#5, ::Void, ::Void, ::Void, ::Void, ::Void, ::Void, ::Void, ::Void, ::Void, ::Void
, ::Void, ::Void, ::Array{Klara.VariableState,1}, ::Int64, ::Bool, ::Symbol, ::Int6
4, ::Int64, ::Array{Array{Any,1},1}, ::Type{T}, ::Symbol, ::Type{Val{:high}}, ::Int
64) at /home/tamas/.julia/v0.5/Klara/src/variables/parameters/BasicContMuvParameter
.jl:543                                                                           
 in (::Core.#kw#Type)(::Array{Any,1}, ::Type{BasicContMuvParameter}, ::Symbol, ::Ty
pe{Val{:high}}, ::Int64) at ./<missing>:0                                         
 in #BasicContMuvParameter#111(::Symbol, ::Array{Any,1}, ::Type{T}, ::Symbol, ::Int
64) at /home/tamas/.julia/v0.5/Klara/src/variables/parameters/BasicContMuvParameter
.jl:296                                                                           
 in (::Core.#kw#Type)(::Array{Any,1}, ::Type{BasicContMuvParameter}, ::Symbol, ::In
t64) at ./<missing>:0 (repeats 2 times)                                           

The function structural_ll_raw simply computes the log likelihood. I am wondering I am running into something obvious, ie that it is a closure?

Though my actual code is long, if the issue is not obvious I will make a self-contained example (just let me know).

papamarkou commented 7 years ago

Thanks @tpapp, yes, I am aware of this issue, and have opened a relevant issue at ReverseDiffSource a couple of months ago, see https://github.com/JuliaDiff/ReverseDiffSource.jl/issues/49 - it used to work with the previous version of ReverseDiffSource, @fredo-dedup offered to sort this out from his end, when he finds the chance.

papamarkou commented 7 years ago

This has been sorted via DiffBase and ReverseDiff.