Skip to content

Commit

Permalink
Towards a more modular state init by adding more options
Browse files Browse the repository at this point in the history
This commit adss back a ForwardDiff.jl-based state initialization that was used
in a much earlier version of this package. And in almost all cases, this is not
very performant! But the initialization should ideally be more modular, the
choice being "exact" vs "inexact", and the actual autodiff implementation in the
exact case should also be easy to swap, e.g. when we'll use TaylorDiff.jl.
Therefore we try to refactor this a bit.
  • Loading branch information
nathanaelbosch committed Nov 1, 2023
1 parent 6113ede commit 5047864
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/initialization/taylormode.jl
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,30 @@ function taylormode_get_derivatives(u, f::SciMLBase.AbstractODEFunction{true}, p
duT = zero(uT)
uauxT = similar(uT)
TaylorIntegration.jetcoeffs!(f, tT, uT, duT, uauxT, p)
# return hcat([evaluate.(differentiate.(uT, i)) for i in 0:q]...)'
return [evaluate.(differentiate.(uT, i)) for i in 0:q]
end



function forwarddiff_get_derivatives!(out, u, f::SciMLBase.AbstractODEFunction{true}, p, t, q)
_f(du, u) = f(du, u, p, t)
d = length(u0)
f_n = _f
out[1:d] .= u0
@views _f(out[d+1:2d], u0)
for o in 2:ndiffs
f_n = forwarddiff_vectorfield_derivative_iteration(f_n, _f)
@views f_n(out[o*d+1:(o+1)*d], u0)

Check warning on line 76 in src/initialization/taylormode.jl

View check run for this annotation

Codecov / codecov/patch

src/initialization/taylormode.jl#L68-L76

Added lines #L68 - L76 were not covered by tests
end
return out

Check warning on line 78 in src/initialization/taylormode.jl

View check run for this annotation

Codecov / codecov/patch

src/initialization/taylormode.jl#L78

Added line #L78 was not covered by tests
end

function forwarddiff_vectorfield_derivative_iteration(f_n, f_0)
function df(du, u)
J = ForwardDiff.jacobian(f_n, du, u)
f_0(du, u)
_matmul!(du, J, du)

Check warning on line 85 in src/initialization/taylormode.jl

View check run for this annotation

Codecov / codecov/patch

src/initialization/taylormode.jl#L81-L85

Added lines #L81 - L85 were not covered by tests
end
return df

Check warning on line 87 in src/initialization/taylormode.jl

View check run for this annotation

Codecov / codecov/patch

src/initialization/taylormode.jl#L87

Added line #L87 was not covered by tests
end

0 comments on commit 5047864

Please sign in to comment.