I have some progress trying to debug the code: specifically I have narrowed it to this section of code:
using Integrals
using ForwardDiff
function dNdr(r, p)
Mass, zmin, zmax = p[1], p[2], p[3]
α = 0.133
β = -1.995
γ = 0.263
η = 0.0993
A = 0.0104
r̄ = 0.00972
zfac = ((1+zmax)^(η+1) - (1+zmin)^(η+1))/(1+η)
Nm = A * (Mass*1e-12)^α * r^β * exp((r/r̄)^γ) * zfac
return Nm
end
function intdNdr(Mass, zmin, zmax, rmin, rmax)
prob = IntegralProblem(dNdr,convert(eltype(Mass),rmin),convert(eltype(Mass),rmax), [Mass, convert(eltype(Mass),zmin), convert(eltype(Mass),zmax)])
sol = solve(prob, QuadGKJL(), reltol=1e-4)
return sol
end
This section is usually called by a different function which is then used in my Turing model, however, this function in isolation still yields the same error.
For example, if you try running the above code with:
Mass = 1e10 zmin=0.1 zmax=0.2 rmin=1e-8 rmax=1
ForwardDiff.derivative(Mass->intdNdr(Mass, zmin, zmax, rmin, rmax), Mass)
You get the same error message as you get from running my entire code, so I’m quite convinced that the error is somewhere in this function. I’m not clear that the Turing model is actually trying to differentiate w.r.t. Mass, but at least this looks like a starting point.