Closed dkarrasch closed 7 years ago
In order to differentiate through an ODE solver which has adaptive timestepping, you need to make sure that not just the dependent variables are dual numbers, but also the independent variables. This is because changes in x
changes the points which are stepped to, so these need to be duals as well. So without testing it,
function flow(g,u0,tspan)
prob = ODEProblem(g,u0,eltype(u0).(tspan))
sol = solve(prob,dt=.1).u[end]
end
should be all that's needed (so it's dual when u0
is dual, and not dual when u0
is not).
In general it may be more efficient to solve the sensitivity equations than to do this though, but that's hard to know right now.
Many thanks, Chris. It works without complaining. I'll do some testing and comparisons at some point.
I am interested in autodifferentiating the map that takes an initial value to its "final" value of an ODE solution. Taking the Lorenz example from the docs, I tried the following:
So, all functions are defined properly, ODE-solving works, vector field autodifferentiation works, but not autodifferentiation of
flow
. The error message that I get is:Is there an issue with my definition of
flow
and how I pick the solution state from the ODEsolution-structure, or is it with thesolve
-function? Or is the idea to define the equation of variations yourself, using the autoderivative of the vector field? Any help is much appreciated!