Add FunctionProperties extension: look through SciMLFunction wrappers#1413
Merged
ChrisRackauckas merged 1 commit intoJun 30, 2026
Merged
Conversation
`hasbranching` (FunctionProperties.jl) is used by SciMLSensitivity to decide
whether a ReverseDiff tape can be compiled for an ODE right-hand side. It is
called on `unwrapped_f(prob.f)`, i.e. an `AbstractSciMLFunction`, and analyzes
whatever callable it is handed.
Handed the SciMLFunction functor, it scans dispatch plumbing rather than the
user's RHS: the operator-selection branch (`if f.f isa AbstractSciMLOperator`)
and, for an MTK-compiled RHS, splat forwarding into a generated function. The
result is that even a branch-free linear RHS reports `true`, and (without the
companion FunctionProperties changes) genuine branches behind the forwarder are
missed.
This weakdep extension defines
FunctionProperties.hasbranching(f::AbstractSciMLFunction, args...) =
FunctionProperties.hasbranching(f.f, args...)
so the analysis targets the wrapped RHS `f.f`. Loaded only when both packages
are present; no new hard dependency.
Stacked on SciML/FunctionProperties.jl#62 (the value-independent-branch
detection that the unwrapped analysis relies on); compat set to that release.
Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com>
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.
Summary
hasbranching(FunctionProperties.jl) is how SciMLSensitivity decides whether a ReverseDiff tape can be compiled for an ODE RHS (concrete_solve.jl). It is called onunwrapped_f(prob.f)— anAbstractSciMLFunction— and analyzes whatever callable it is handed.Handed the SciMLFunction functor, it scans dispatch plumbing instead of the user's RHS:
if f.f isa AbstractSciMLOperator(a compile-time-constantisa), andRuntimeGeneratedFunction.The consequence is that even a branch-free linear RHS
ẋ = x − a·xreportshasbranching = true, needlessly disabling ReverseDiff compilation; and a genuine branch (a registeredrelu) behind the forwarder is missed.Change
A weakdep extension that looks through the wrapper to the wrapped RHS:
Loaded only when both packages are present — no new hard dependency on SciMLBase. Follows the existing
ext/SciMLBase*Ext.jlpattern.Tests
test/function_properties_ext.jl(registered in thecoregroup): confirms the method is defined and that a branch-free vs. branchyODEFunctionare scored correctly through the unwrap. Verified locally (3/3) by dev'ing this branch + FunctionProperties#62 into a fresh env — the extension precompiles and dispatches. Runic clean.Stack
Companion to SciML/FunctionProperties.jl#62, which fixes the underlying analysis (compile-time-constant branches ignored, splat forwarders followed, and constant-decided branches — e.g. split-mode
MTKParametersindexing — refuted via constant-propagation-aware inference). With #62 in place this unwrap makes the full MTK RHS table correct through theODEFunctionwith no container-specific overrides. Compat is therefore pinned toFunctionProperties = "0.1.7".Semver
Additive weakdep extension, non-breaking:
3.30.0→3.30.1.