Skip to content

Commit

Permalink
fix(tracker): ordering of the promotion
Browse files Browse the repository at this point in the history
  • Loading branch information
avik-pal committed Aug 16, 2024
1 parent ab55e3c commit 57b5aec
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
10 changes: 8 additions & 2 deletions ext/DiffEqBaseTrackerExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,15 @@ Tracker.@grad function DiffEqBase.solve_up(prob,
},
u0, p, args...;
kwargs...)
out = DiffEqBase._solve_adjoint(prob, sensealg, Tracker.data(u0), Tracker.data(p),
sol, pb_f = DiffEqBase._solve_adjoint(
prob, sensealg, Tracker.data(u0), Tracker.data(p),
SciMLBase.TrackerOriginator(), args...; kwargs...)
Array(out[1]), out[2]

if sol isa AbstractArray
!hasfield(typeof(sol), :u) && return sol, pb_f # being safe here
return sol.u, pb_f # AbstractNoTimeSolution isa AbstractArray
end
return convert(AbstractArray, sol), pb_f
end

end
12 changes: 6 additions & 6 deletions src/solve.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1130,23 +1130,23 @@ function get_concrete_problem(prob::AbstractJumpProblem, isadapt; kwargs...)
end

function get_concrete_problem(prob::SteadyStateProblem, isadapt; kwargs...)
u0 = get_concrete_u0(prob, isadapt, Inf, kwargs)
u0 = promote_u0(u0, prob.p, nothing)
p = get_concrete_p(prob, kwargs)
u0 = get_concrete_u0(prob, isadapt, Inf, kwargs)
u0 = promote_u0(u0, p, nothing)
remake(prob; u0 = u0, p = p)
end

function get_concrete_problem(prob::NonlinearProblem, isadapt; kwargs...)
u0 = get_concrete_u0(prob, isadapt, nothing, kwargs)
u0 = promote_u0(u0, prob.p, nothing)
p = get_concrete_p(prob, kwargs)
u0 = get_concrete_u0(prob, isadapt, nothing, kwargs)
u0 = promote_u0(u0, p, nothing)
remake(prob; u0 = u0, p = p)
end

function get_concrete_problem(prob::NonlinearLeastSquaresProblem, isadapt; kwargs...)
u0 = get_concrete_u0(prob, isadapt, nothing, kwargs)
u0 = promote_u0(u0, prob.p, nothing)
p = get_concrete_p(prob, kwargs)
u0 = get_concrete_u0(prob, isadapt, nothing, kwargs)
u0 = promote_u0(u0, p, nothing)
remake(prob; u0 = u0, p = p)
end

Expand Down

0 comments on commit 57b5aec

Please sign in to comment.