Add forward mode rules for calling a FunctionWrappersWrapper - #84
Merged
ChrisRackauckas merged 4 commits intoAug 18, 2026
Conversation
AstitvaAggarwal
marked this pull request as draft
August 10, 2026 12:19
AstitvaAggarwal
marked this pull request as ready for review
August 10, 2026 14:19
build_frule(f_orig_dual, args...) is an existing convenience method that extracts the interpreter/signature internally, same as build_rrule(sig) already does for the reverse-mode rule above. Removes the need to import ForwardMode/get_interpreter at all, cutting the Mooncake QA ignore list from 15 to 13 symbols.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Mooncake had a reverse mode rule for calling a FunctionWrappersWrapper, but no forward mode rule, so forward mode differentiation through code that calls one (for example, second derivatives) failed.
This adds a forward mode rule for calling a wrapper, plus rules for
unwrap, which reaches into a nested FunctionWrapper's internal field in a way the generic getfield rule cannot handle since FunctionWrapperTangent is a custom tangent type.Every rule here builds a fresh zero tangent for the unwrapped function rather than threading through any real tangent it might carry. That is only correct if the wrapped function itself has nothing to differentiate; if it does (for example, a struct holding a learnable matrix), it now errors clearly instead of silently returning a too-small gradient. Derived rules are cached by signature too, since the wrapped function is typically called once per ODE timestep, and rebuilding a rule from scratch on every call would be wasted work.
Needed for SciML/SciMLSensitivity.jl#1427.