How to use autodiff with Quadrature.jl

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)

Double post. Hasn’t been added yet. Someone would just need to extend https://github.com/SciML/Quadrature.jl/blob/master/src/Quadrature.jl#L583 which wouldn’t be too hard.

1 Like

Any updates on this?
this issue has gotten some activity recently: Differentiation for a limit of an integral · Issue #56 · SciML/Integrals.jl · GitHub,
but https://github.com/SciML/Quadrature.jl/blob/master/src/Quadrature.jl#L583 leads to a page that says ‘404-page not found’ on github.
does Quadrature.jl still exist? if so, where would one extend the corresponding line?

Any news on this? Would be greatly appreciated. I would also be glad to contribute to speed this up, but might need some guidance.

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.