Skip to content

Add FunctionProperties extension: look through SciMLFunction wrappers#1413

Merged
ChrisRackauckas merged 1 commit into
SciML:masterfrom
ChrisRackauckas-Claude:functionproperties-unwrap-ext
Jun 30, 2026
Merged

Add FunctionProperties extension: look through SciMLFunction wrappers#1413
ChrisRackauckas merged 1 commit into
SciML:masterfrom
ChrisRackauckas-Claude:functionproperties-unwrap-ext

Conversation

@ChrisRackauckas-Claude

@ChrisRackauckas-Claude ChrisRackauckas-Claude commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Please ignore until reviewed by @ChrisRackauckas. Draft opened by an agent. Stacked on SciML/FunctionProperties.jl#62 — needs the FunctionProperties 0.1.7 release to resolve (compat is pinned to it).

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 on unwrapped_f(prob.f) — an AbstractSciMLFunction — and analyzes whatever callable it is handed.

Handed the SciMLFunction functor, it scans dispatch plumbing instead of the user's RHS:

  • the operator-selection branch if f.f isa AbstractSciMLOperator (a compile-time-constant isa), and
  • for an MTK-compiled RHS, splat forwarding into a RuntimeGeneratedFunction.

The consequence is that even a branch-free linear RHS ẋ = x − a·x reports hasbranching = true, needlessly disabling ReverseDiff compilation; and a genuine branch (a registered relu) behind the forwarder is missed.

Change

A weakdep extension that looks through the wrapper to the wrapped RHS:

FunctionProperties.hasbranching(f::AbstractSciMLFunction, args...) =
    FunctionProperties.hasbranching(f.f, args...)

Loaded only when both packages are present — no new hard dependency on SciMLBase. Follows the existing ext/SciMLBase*Ext.jl pattern.

Tests

test/function_properties_ext.jl (registered in the core group): confirms the method is defined and that a branch-free vs. branchy ODEFunction are 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 MTKParameters indexing — refuted via constant-propagation-aware inference). With #62 in place this unwrap makes the full MTK RHS table correct through the ODEFunction with no container-specific overrides. Compat is therefore pinned to FunctionProperties = "0.1.7".

Semver

Additive weakdep extension, non-breaking: 3.30.03.30.1.

`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>
@ChrisRackauckas ChrisRackauckas marked this pull request as ready for review June 30, 2026 10:04
@ChrisRackauckas ChrisRackauckas merged commit dbda304 into SciML:master Jun 30, 2026
32 of 63 checks passed
@ChrisRackauckas-Claude ChrisRackauckas-Claude changed the title Add FunctionProperties extension: look through SciMLFunction wrappers [WIP – ignore until reviewed by @ChrisRackauckas] Add FunctionProperties extension: look through SciMLFunction wrappers Jul 2, 2026
@ChrisRackauckas-Claude ChrisRackauckas-Claude changed the title [WIP – ignore until reviewed by @ChrisRackauckas] Add FunctionProperties extension: look through SciMLFunction wrappers Add FunctionProperties extension: look through SciMLFunction wrappers Jul 3, 2026
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.

2 participants