Fix nested ForwardDiff tag mismatch in UJacobianWrapper for Rosenbrock solvers#1319
Open
AdityaPandeyCN wants to merge 3 commits intoSciML:masterfrom
Open
Fix nested ForwardDiff tag mismatch in UJacobianWrapper for Rosenbrock solvers#1319AdityaPandeyCN wants to merge 3 commits intoSciML:masterfrom
AdityaPandeyCN wants to merge 3 commits intoSciML:masterfrom
Conversation
Signed-off-by: AdityaPandeyCN <adityapand3y666@gmail.com>
…compat Signed-off-by: AdityaPandeyCN <adityapand3y666@gmail.com>
ext/SciMLBaseForwardDiffExt.jl
Outdated
| DualU = eltype(u) | ||
| DualP = eltype(p) | ||
| if !(DualP <: DualU) | ||
| return DualU.(p) |
Contributor
Author
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?
Member
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) |
Contributor
Author
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?
Member
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?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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