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

Turn off DI strictness #643

merged 3 commits into from
Jul 20, 2025

Conversation

ChrisRackauckas
Copy link
Member

The issue is that DI strictness does not allow views, even though most of the AD engines are fine with views.

@@ -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)))

@@ -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))

@@ -352,14 +352,14 @@
@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))

@@ -375,7 +375,7 @@

@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))

@ChrisRackauckas ChrisRackauckas merged commit 6c893d2 into master Jul 20, 2025
80 of 98 checks passed
@ChrisRackauckas ChrisRackauckas deleted the ChrisRackauckas-patch-1 branch July 20, 2025 04:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant