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 toODEProblemconstructor, 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.jlwith inactive rule for VJP choice typestest/enzyme_vjp_inactive.jlincluding the original failing case from Enzyme gradient fails whensensealgis defined in theODEProblemrather than in thesolvefunction #1225Architecture
This PR handles VJP choice types defined in SciMLSensitivity, while the
AbstractSensitivityAlgorithminactive rule is properly handled in SciMLBase to avoid type piracy.Complete solution requires both:
AbstractSensitivityAlgorithminactive ruleVJPChoiceinactive rule (this PR)Testing
EnzymeVJP,ZygoteVJP,ReverseDiffVJP,TrackerVJP)sensealgis defined in theODEProblemrather than in thesolvefunction #1225 withsensealginODEProblemconstructorBefore/After
Before:
After:
Both cases work correctly with Enzyme differentiation.
🤖 Generated with Claude Code