I’m trying to use autodiff on a function that uses Quadrature.jl numerical integration. I’m getting an error and not sure why. Any suggestions? Thanks.
The function f(y) is \int_0^y x dx - y (computed numerically using Quadrature.jl) which is just 0.5y^2 - y. I want to take the derivative of that using autodiff. This is just meant to be a minimal example which will be made more complicated and eventually used in JuMP.
using Quadrature
function f(y)
g(x,p) = x
prob = QuadratureProblem(g, 0.0, y)
sol = solve(prob,HCubatureJL(),reltol=1e-3,abstol=1e-3)
return sol[1] - y
end
f(1) # = -0.5
using ForwardDiff
g = x -> ForwardDiff.derivative(f, x)
g(2)
# MethodError: no method matching kronrod(::Type{ForwardDiff.Dual{ForwardDiff.Tag{typeof(f), Int64}, Float64, 1}}, ::Int64)
Nobody is working on this actively, but we would have to implement the Leibniz Integral Rule, and if any pr is opened for Integrals.jl I would be able to help.
In the long term this might end up in SciMLSensitivity.jl, would have to be implemented for both forward and reverse mode, be compatible with in-place and batched integral functions, and ideally give the user a choice about whether to differentiate-and-discretize or discretize-and-differentiate.