Integrals.jl icon indicating copy to clipboard operation
Integrals.jl copied to clipboard

Batch Single dim derivative test is broken

Open killah-t-cell opened this issue 4 years ago • 0 comments

This test is broken

https://github.com/SciML/Quadrature.jl/blob/f913f39d9766a5d15f3829c51155ab3b655269d3/test/derivative_tests.jl#L137

The problem occurs with dp2. It throws a LoadError: DimensionMismatch("variable with size(x) == (1, 15) cannot have a gradient with size(dx) == (15,)")

https://github.com/SciML/Quadrature.jl/blob/f913f39d9766a5d15f3829c51155ab3b655269d3/test/derivative_tests.jl#L133

Which causes the test to break.

For convenience, here is an MWE one can use to test.

using Quadrature, Cuba, Cubature, Zygote, FiniteDiff, ForwardDiff
using Test

### Batch Single dim
f(x,p) = x*p[1].+p[2]*p[3]

lb =1.0
ub = 3.0
p = [2.0, 3.0, 4.0]
prob = QuadratureProblem(f,lb,ub,p)

function testf3(lb,ub,p; f=f)
    prob = QuadratureProblem(f,lb,ub,p, batch = 10, nout=1)
    solve(prob, CubatureJLh(); reltol=1e-3,abstol=1e-3)[1]
end

dp1 = ForwardDiff.gradient(p->testf3(lb,ub,p),p)
dp2 = Zygote.gradient(p->testf3(lb,ub,p),p)[1] # LoadError: DimensionMismatch("variable with size(x) == (1, 15) cannot have a gradient with size(dx) == (15,)")
dp3 = FiniteDiff.finite_difference_gradient(p->testf3(lb,ub,p),p)

@test dp1 ≈ dp3 #passes
@test dp2 ≈ dp3 # THIS IS BROKEN

killah-t-cell avatar Oct 09 '21 15:10 killah-t-cell