Fix nested ForwardDiff tag mismatch in UJacobianWrapper for Rosenbrock solvers#1319
Fix nested ForwardDiff tag mismatch in UJacobianWrapper for Rosenbrock solvers#1319AdityaPandeyCN wants to merge 3 commits intoSciML:masterfrom
Conversation
Signed-off-by: AdityaPandeyCN <adityapand3y666@gmail.com>
…compat Signed-off-by: AdityaPandeyCN <adityapand3y666@gmail.com>
| DualU = eltype(u) | ||
| DualP = eltype(p) | ||
| if !(DualP <: DualU) | ||
| return DualU.(p) |
There was a problem hiding this comment.
I overlooked that you already have a PR for this(SciML/OrdinaryDiffEq.jl#3389). Should I close this?
There was a problem hiding this comment.
it's fine if you get to something good for it first 😅 it's just it should convert p once instead of each f call.
Signed-off-by: AdityaPandeyCN <adityapand3y666@gmail.com>
| eltype(p) <: DualU && return p | ||
| cached = ff._promoted_p | ||
| cached isa AbstractArray{DualU} && return cached | ||
| ff._promoted_p = DualU.(p) |
There was a problem hiding this comment.
This converts p once on the first f! call and caches it in _promoted_p all subsequent calls hit cached isa AbstractArray{DualU} && return cached.
Am I missing something?
There was a problem hiding this comment.
this isn't the right place to do it. DiffEqBase solve has a promotion path, why not do it there?
There was a problem hiding this comment.
Opened one SciML/OrdinaryDiffEq.jl#3406 here but have made the changes in the ForwardDiff extension file.
Checklist
contributor guidelines, in particular the SciML Style Guide and
COLPRAC.
Additional context
Fix for SciML/OrdinaryDiffEq.jl#3381
When NonlinearSolve computes a Jacobian over an ODE solve,
penters as Dual{NLTag}and Rosenbrock's internal ForwardDiff seedsuasDual{OrdEqTag, Dual{NLTag}, CS}. UJacobianWrapper passes these mismatched types to the user function. p[1]*u[1] producesDual{NLTag}outer due to tag precedence, but du expectsDual{OrdEqTag}outer, so the assignment crashes.This promote p to match
eltype(u)in UJacobianWrapper before calling f