Skip to content

Add adjoint for ODEProblem constructor w/ iip, specialization #1039

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

Conversation

jClugstor
Copy link
Member

Checklist

  • Appropriate tests were added
  • Any code changes were done in a way that does not break public API
  • All documentation related to code changes were updated
  • The new code follows the
    contributor guidelines, in particular the SciML Style Guide and
    COLPRAC.
  • Any new documentation only uses public API

Additional context

This fixes SciML/SciMLSensitivity.jl#1181

@@ -64,6 +64,15 @@ function ChainRulesCore.rrule(::Type{ODEProblem}, args...; kwargs...)
ODEProblem(args...; kwargs...), ODEProblemAdjoint
end

function ChainRulesCore.rrule(::Type{
<:ODEProblem{iip, T}}, args...; kwargs...) where {iip, T}
Copy link
Member

Choose a reason for hiding this comment

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

usually only IIP is set, is this hit there?

Copy link
Member Author

Choose a reason for hiding this comment

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

If only IIP is set it actually goes through the existing rrule, e.g.

y, back = Zygote._pullback(p -> ODEProblem{true}(dudt!, u0, (0.0, 20.0), p), [1.0])

back(1.0)

ends up going through

function ChainRulesCore.rrule(::Type{ODEProblem}, args...; kwargs...)
function ODEProblemAdjoint(ȳ)
(NoTangent(), ȳ.f, ȳ.u0, ȳ.tspan, ȳ.p, ȳ.kwargs, ȳ.problem_type)
end
ODEProblem(args...; kwargs...), ODEProblemAdjoint
end

@ChrisRackauckas ChrisRackauckas merged commit fed63df into SciML:master May 28, 2025
49 of 60 checks passed
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.

Wrong gradient when using AutoSpecialize and embedding the ODEProblem in a NamedTuple
2 participants