Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/adjoint_common.jl
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,9 @@ function adjointdiffcache(g::G, sensealg, discrete, sol, dgdu::DG1, dgdp::DG2, f
pf = nothing
elseif autojacvec isa EnzymeVJP
paramjac_config = get_paramjac_config(autojacvec, p, f, y, _p, _t; numindvar, alg)
if isscimlstructure(p)
unwrappedf = repack_ode_function(unwrappedf, repack)
end
pf = get_pf(autojacvec; _f = unwrappedf, isinplace = isinplace, isRODE = isRODE)
paramjac_config = (paramjac_config..., Enzyme.make_zero(pf))
elseif autojacvec isa MooncakeVJP
Expand Down
22 changes: 12 additions & 10 deletions src/derivative_wrappers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -664,6 +664,13 @@ function _vecjacobian(y, λ, p, t, S::TS, isautojacvec::ZygoteVJP, dgrad, dy,
return dy, dλ, dgrad
end

function repack_ode_function(f, repack)
f_repacked = function (du, u, p, t)
f(du, u, repack(p), t)
end
return f_repacked
end

function _vecjacobian!(dλ, y, λ, p, t, S::TS, isautojacvec::EnzymeVJP, dgrad, dy,
W) where {TS <: SensitivityFunction}
(; sensealg) = S
Expand Down Expand Up @@ -700,23 +707,18 @@ function _vecjacobian!(dλ, y, λ, p, t, S::TS, isautojacvec::EnzymeVJP, dgrad,
Enzyme.remake_zero!(tmp1) # should be removed for dλ
vec(ytmp) .= vec(y)

#if dgrad !== nothing
# tmp2 = dgrad
#else
dup = if !(tmp2 isa SciMLBase.NullParameters)
# tmp2 .= 0
Enzyme.remake_zero!(tmp2)
Enzyme.Duplicated(p, repack(tmp2))
Enzyme.Duplicated(tunables, tmp2)
else
Enzyme.Const(p)
end
#end

#if dy !== nothing
# tmp3 = dy
#else
if isscimlstructure(p)
f = repack_ode_function(f, repack)
end

Enzyme.remake_zero!(tmp3)
#end

vec(tmp4) .= vec(λ)
isautojacvec = get_jacvec(sensealg)
Expand Down
Loading