Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't use custom tags #411

Merged
merged 1 commit into from
Apr 18, 2024
Merged
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
2 changes: 1 addition & 1 deletion ext/NonlinearSolveNLSolversExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

if autodiff_concrete === :forwarddiff
fj_scalar = @closure (Jx, x) -> begin
T = typeof(NonlinearSolve.NonlinearSolveTag())
T = typeof(ForwardDiff.Tag(prob.f, eltype(x)))

Check warning on line 37 in ext/NonlinearSolveNLSolversExt.jl

View check run for this annotation

Codecov / codecov/patch

ext/NonlinearSolveNLSolversExt.jl#L37

Added line #L37 was not covered by tests
x_dual = ForwardDiff.Dual{T}(x, one(x))
y = prob.f(x_dual, prob.p)
return ForwardDiff.value(y), ForwardDiff.extract_derivative(T, y)
Expand Down
10 changes: 1 addition & 9 deletions src/internal/helpers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,6 @@ function evaluate_f!!(f::NonlinearFunction{iip}, fu, u, p) where {iip}
end

# AutoDiff Selection Functions
struct NonlinearSolveTag end

function ForwardDiff.checktag(::Type{<:ForwardDiff.Tag{<:NonlinearSolveTag, <:T}},
f::F, x::AbstractArray{T}) where {T, F}
return true
end

function get_concrete_forward_ad(
autodiff::Union{ADTypes.AbstractForwardMode, ADTypes.AbstractFiniteDifferencesMode},
prob, sp::Val{test_sparse} = True, args...; kwargs...) where {test_sparse}
Expand All @@ -62,8 +55,7 @@ function get_concrete_forward_ad(
ad = if !ForwardDiff.can_dual(eltype(prob.u0)) # Use Finite Differencing
use_sparse_ad ? AutoSparseFiniteDiff() : AutoFiniteDiff()
else
tag = ForwardDiff.Tag(NonlinearSolveTag(), eltype(prob.u0))
(use_sparse_ad ? AutoSparseForwardDiff : AutoForwardDiff)(; tag)
(use_sparse_ad ? AutoSparseForwardDiff : AutoForwardDiff)()
end
return ad
end
Expand Down
8 changes: 4 additions & 4 deletions src/internal/operators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,10 @@ function JacobianOperator(prob::AbstractNonlinearProblem, fu, u; jvp_autodiff =
if jvp_autodiff isa AutoForwardDiff || jvp_autodiff isa AutoPolyesterForwardDiff
if iip
# FIXME: Technically we should propagate the tag but ignoring that for now
cache1 = Dual{typeof(ForwardDiff.Tag(NonlinearSolveTag(), eltype(u))),
eltype(u), 1}.(similar(u), ForwardDiff.Partials.(tuple.(u)))
cache2 = Dual{typeof(ForwardDiff.Tag(NonlinearSolveTag(), eltype(fu))),
eltype(fu), 1}.(similar(fu), ForwardDiff.Partials.(tuple.(fu)))
cache1 = Dual{typeof(ForwardDiff.Tag(uf, eltype(u))), eltype(u),
1}.(similar(u), ForwardDiff.Partials.(tuple.(u)))
cache2 = Dual{typeof(ForwardDiff.Tag(uf, eltype(fu))), eltype(fu),
1}.(similar(fu), ForwardDiff.Partials.(tuple.(fu)))
@closure (Jv, v, u, p) -> auto_jacvec!(Jv, uf, u, v, cache1, cache2)
else
@closure (v, u, p) -> auto_jacvec(uf, u, v)
Expand Down
Loading