You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
ForwardDiff.jl differentiates through integral solver in the example below.
Expected behavior
In the example below, Integrals.jl should compute the integral without reaching the QuadGKJL algorithm. Instead, it hits the algorithm at kronrod where it returns a method error. Note that this example works correctly for Zygote.
Minimal Reproducible Example 👇
using BenchmarkTools
using Distributions
using Integrals
using ForwardDiff
integrand(x::T1, p::T2) where {T1<:Real,T2<:Real} =pdf(Normal(p, x), one(promote_type(T1, T2)))
functionf(Θ)
domain = (Θ[2], Θ[3])
p = Θ[1]
prob =IntegralProblem(integrand, domain, p)
sol =solve(prob, QuadGKJL(); reltol=1e-3, abstol=1e-3)
return sol.u
end
Θ = [0.0, 0.0, 2.0]
f(Θ)
ForwardDiff.gradient(f, Θ)[1]
Right, at the moment we are missing a rule for differentiation with respect to the bounds. We want to implement the Leibniz integral rule of calculus, but there are many ways to do this, i.e. whether you discretize then differentiate or vice versa (this affects whether you do an integral over the same domain or integrals over the boundaries -- I think the former is preferable but there are also arguments for the latter). Adding a rule will be straightforward, I hope, but ultimately the user will want to have control over the differentiation algorithm, so I also marked this as a feature request.
We already have a "broken" test case for this specific issue:
Describe the bug 🐞
ForwardDiff.jl differentiates through integral solver in the example below.
Expected behavior
In the example below, Integrals.jl should compute the integral without reaching the QuadGKJL algorithm. Instead, it hits the algorithm at
kronrod
where it returns a method error. Note that this example works correctly for Zygote.Minimal Reproducible Example 👇
Error & Stacktrace⚠️
Environment (please complete the following information):
using Pkg; Pkg.status()
using Pkg; Pkg.status(; mode = PKGMODE_MANIFEST)
versioninfo()
Additional context
This error was discovered by @gdalle. Please ping him for technical details, as AD is not my expertise.
He notes that the issue might be a missing rule for integral bounds:
Integrals.jl/ext/IntegralsForwardDiffExt.jl
Line 45 in 26f0f73
The text was updated successfully, but these errors were encountered: