Skip to content

Turn off DI strictness #643

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

Merged
merged 3 commits into from
Jul 20, 2025
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
4 changes: 2 additions & 2 deletions lib/NonlinearSolveBase/src/jacobian.jl
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ function construct_jacobian_cache(
end
autodiff = construct_concrete_adtype(f, autodiff)
di_extras = if SciMLBase.isinplace(f)
DI.prepare_jacobian(f, fu_cache, autodiff, u, Constant(p))
DI.prepare_jacobian(f, fu_cache, autodiff, u, Constant(p), strict = Val(false))
else
DI.prepare_jacobian(f, autodiff, u, Constant(p))
DI.prepare_jacobian(f, autodiff, u, Constant(p), strict = Val(false))
end
else
di_extras = nothing
Expand Down
10 changes: 5 additions & 5 deletions lib/SciMLJacobianOperators/src/SciMLJacobianOperators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -307,14 +307,14 @@ function prepare_vjp(::Val{false}, prob::AbstractNonlinearProblem,
@assert DI.check_inplace(autodiff) "Backend: $(autodiff) doesn't support in-place \
problems."
fu_cache = copy(fu)
di_extras = DI.prepare_pullback(f, fu_cache, autodiff, u, (fu,), Constant(prob.p))
di_extras = DI.prepare_pullback(f, fu_cache, autodiff, u, (fu,), Constant(prob.p), strict=Val(false))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
di_extras = DI.prepare_pullback(f, fu_cache, autodiff, u, (fu,), Constant(prob.p), strict=Val(false))
di_extras = DI.prepare_pullback(
f, fu_cache, autodiff, u, (fu,), Constant(prob.p), strict = Val(false))

return @closure (vJ, v, u, p) -> begin
DI.pullback!(f, fu_cache, (reshape(vJ, size(u)),), di_extras, autodiff,
u, (reshape(v, size(fu_cache)),), Constant(p))
return
end
else
di_extras = DI.prepare_pullback(f, autodiff, u, (fu,), Constant(prob.p))
di_extras = DI.prepare_pullback(f, autodiff, u, (fu,), Constant(prob.p), strict=Val(false))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
di_extras = DI.prepare_pullback(f, autodiff, u, (fu,), Constant(prob.p), strict=Val(false))
di_extras = DI.prepare_pullback(
f, autodiff, u, (fu,), Constant(prob.p), strict = Val(false))

return @closure (v, u, p) -> begin
return only(DI.pullback(
f, di_extras, autodiff, u, (reshape(v, size(fu)),), Constant(p)))
Expand Down Expand Up @@ -352,14 +352,14 @@ function prepare_jvp(::Val{false}, prob::AbstractNonlinearProblem,
@assert DI.check_inplace(autodiff) "Backend: $(autodiff) doesn't support in-place \
problems."
fu_cache = copy(fu)
di_extras = DI.prepare_pushforward(f, fu_cache, autodiff, u, (u,), Constant(prob.p))
di_extras = DI.prepare_pushforward(f, fu_cache, autodiff, u, (u,), Constant(prob.p), strict=Val(false))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
di_extras = DI.prepare_pushforward(f, fu_cache, autodiff, u, (u,), Constant(prob.p), strict=Val(false))
di_extras = DI.prepare_pushforward(
f, fu_cache, autodiff, u, (u,), Constant(prob.p), strict = Val(false))

return @closure (Jv, v, u, p) -> begin
DI.pushforward!(f, fu_cache, (reshape(Jv, size(fu_cache)),), di_extras,
autodiff, u, (reshape(v, size(u)),), Constant(p))
return
end
else
di_extras = DI.prepare_pushforward(f, autodiff, u, (u,), Constant(prob.p))
di_extras = DI.prepare_pushforward(f, autodiff, u, (u,), Constant(prob.p), strict=Val(false))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
di_extras = DI.prepare_pushforward(f, autodiff, u, (u,), Constant(prob.p), strict=Val(false))
di_extras = DI.prepare_pushforward(
f, autodiff, u, (u,), Constant(prob.p), strict = Val(false))

return @closure (v, u, p) -> begin
return only(DI.pushforward(
f, di_extras, autodiff, u, (reshape(v, size(u)),), Constant(p)))
Expand All @@ -375,7 +375,7 @@ function prepare_scalar_op(::Val{false}, prob::AbstractNonlinearProblem,

@assert autodiff!==nothing "`autodiff` must be provided if `f` doesn't have \
analytic `vjp` or `jvp` or `jac`."
di_extras = DI.prepare_derivative(f, autodiff, u, Constant(prob.p))
di_extras = DI.prepare_derivative(f, autodiff, u, Constant(prob.p), strict=Val(false))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
di_extras = DI.prepare_derivative(f, autodiff, u, Constant(prob.p), strict=Val(false))
di_extras = DI.prepare_derivative(f, autodiff, u, Constant(prob.p), strict = Val(false))

return @closure (v, u, p) -> DI.derivative(f, di_extras, autodiff, u, Constant(p)) * v
end

Expand Down
4 changes: 2 additions & 2 deletions lib/SimpleNonlinearSolve/src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,10 @@ end
function prepare_jacobian(prob, autodiff, fx, x)
SciMLBase.has_jac(prob.f) && return AnalyticJacobian()
if SciMLBase.isinplace(prob.f)
return DIExtras(DI.prepare_jacobian(prob.f, fx, autodiff, x, Constant(prob.p)))
return DIExtras(DI.prepare_jacobian(prob.f, fx, autodiff, x, Constant(prob.p), strict = Val(false)))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
return DIExtras(DI.prepare_jacobian(prob.f, fx, autodiff, x, Constant(prob.p), strict = Val(false)))
return DIExtras(DI.prepare_jacobian(
prob.f, fx, autodiff, x, Constant(prob.p), strict = Val(false)))

else
x isa SArray && return DINoPreparation()
return DIExtras(DI.prepare_jacobian(prob.f, autodiff, x, Constant(prob.p)))
return DIExtras(DI.prepare_jacobian(prob.f, autodiff, x, Constant(prob.p), strict = Val(false)))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
return DIExtras(DI.prepare_jacobian(prob.f, autodiff, x, Constant(prob.p), strict = Val(false)))
return DIExtras(DI.prepare_jacobian(
prob.f, autodiff, x, Constant(prob.p), strict = Val(false)))

end
end

Expand Down
Loading