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
f(1) # = -0.5

using ForwardDiff
g = x -> ForwardDiff.derivative(f, x)
# 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 Quadrature.jl/Quadrature.jl at master · SciML/Quadrature.jl · GitHub which wouldn’t be too hard.

1 Like