Open devmotion opened 2 years ago
Run it at low tolerances?
Using e.g. abstol=1e-14, reltol=1e-14
doesn't seem to help, the output is the same (naively I would also assume that the tolerance shouldn't affect the approximation of the value at 0.1 too much).
The problem seems to be ReverseDiffAdjoint
. Without it I get:
julia> sensitivity();
isapprox(J1, J2; rtol = 0.001) = true
isapprox(J1, J3; rtol = 0.001) = true
isapprox(J2, J3; rtol = 0.001) = true
J1[4, 1] = 0.011848062676608925
J2[4, 1] = 0.011848062676608925
J3[4, 1] = 0.011848057817131118
This will fallback to ForwardDiffSensitivity, which isn't exactly the same as ForwardDiff on the solver but is fairly close. So yeah it sounds like ReverseDiff is losing something somewhere, maybe due to aliasing.
The following example shows that - similar to the example in the tests - ForwardDiff and finite differencing (here FiniteDifferences, in the tests FiniteDiff) produces similar gradients and Jacobians. However, the Jacobian computed by Zygote differs quite significantly:
Output: