Add Enzyme inactive rules for VJP choice types #1272
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.
Summary
Adds Enzyme extension to make VJP choice types inactive during differentiation, complementing the AbstractSensitivityAlgorithm rule in SciMLBase.
Problem
When
sensealg=BacksolveAdjoint(autojacvec=EnzymeVJP())
is passed toODEProblem
constructor, Enzyme fails with:This occurs because Enzyme tries to differentiate through VJP choice objects (like
EnzymeVJP()
,ZygoteVJP()
, etc.) that are stored within the sensitivity algorithm.See issue: #1225
Solution
This PR adds:
ext/SciMLSensitivityEnzymeExt.jl
with inactive rule for VJP choice typestest/enzyme_vjp_inactive.jl
including the original failing case from Enzyme gradient fails whensensealg
is defined in theODEProblem
rather than in thesolve
function #1225Architecture
This PR handles VJP choice types defined in SciMLSensitivity, while the
AbstractSensitivityAlgorithm
inactive rule is properly handled in SciMLBase to avoid type piracy.Complete solution requires both:
AbstractSensitivityAlgorithm
inactive ruleVJPChoice
inactive rule (this PR)Testing
EnzymeVJP
,ZygoteVJP
,ReverseDiffVJP
,TrackerVJP
)sensealg
is defined in theODEProblem
rather than in thesolve
function #1225 withsensealg
inODEProblem
constructorBefore/After
Before:
After:
Both cases work correctly with Enzyme differentiation.
🤖 Generated with Claude Code