Skip to content

Add EnzymeCore extension declaring the searches inactive - #116

Merged
ChrisRackauckas merged 1 commit into
SciML:mainfrom
SebastianM-C:smc/enzymecore-ext
Sep 16, 2026
Merged

ChrisRackauckas merged 1 commit into
SciML:mainfrom
SebastianM-C:smc/enzymecore-ext

Conversation

@SebastianM-C

Copy link
Copy Markdown
Member

Summary

Adds FindFirstFunctionsEnzymeCoreExt, a weak-dependency extension on EnzymeCore that declares every search entry point EnzymeRules.inactive: searchsorted_last, searchsorted_first, the batched searchsortedlast! / searchsortedfirst! / searchsortedrange, and the equality searches findequal / findfirstequal / findfirstsortedequal.

Why

The searches return or fill indices and see their arguments only through comparisons, so no derivative flows through them in either direction: the declaration is exact, not an approximation.

It also fixes a hard abort. The early-exit search loops emit gc_preserve_begin/gc_preserve_end token pairs that Enzyme's reverse pass cannot reorder yet (EnzymeAD/Enzyme.jl#3404 — LLVM ERROR: function failed verification, "Instruction does not dominate all uses!"). Today any reverse-mode differentiation through an interpolation interval lookup — e.g. DataInterpolations.LinearInterpolation driving an ODE right-hand side under SciMLSensitivity's EnzymeVJP — aborts the Julia process, even though the search itself carries no derivative. With the rule, Enzyme never enters the loop. Verified on Enzyme 0.13.184–0.13.204 with a package-free reproducer and on the real model that motivated it (the VJP then matches an uncompiled ReverseDiff tape to the same accuracy).

The rule lives here rather than in DataInterpolations because DataInterpolations does not own these functions.

Changes

  • ext/FindFirstFunctionsEnzymeCoreExt.jl: the inactive declarations.
  • Project.toml: EnzymeCore weakdep + extension, EnzymeCore = "0.8" compat, Enzyme as a test extra.
  • test/Enzyme/enzyme_tests.jl + [Enzyme] group in test/test_groups.toml: a piecewise-linear interpolant whose interval lookup goes through searchsorted_last, differentiated in reverse mode w.r.t. the knot values and the query point, in forward mode, plus the batched and equality searches under autodiff.
  • NEWS.md, version 3.2.1 → 3.3.0.

Draft while the new CI group runs; happy to trim the set of functions covered if you would rather keep the rule to the sorted searches.

Written by Claude Code on Sebastian's behalf.

🤖 Generated with Claude Code

@ChrisRackauckas

Copy link
Copy Markdown
Member

Get rid of your noise.

Every FindFirstFunctions entry point returns or fills indices and sees its
arguments only through comparisons, so no derivative flows through it.
The new `FindFirstFunctionsEnzymeCoreExt` (weak dependency on EnzymeCore)
declares `searchsorted_last`, `searchsorted_first`, the batched
`searchsortedlast!`/`searchsortedfirst!`/`searchsortedrange` and the
equality searches `findequal`/`findfirstequal`/`findfirstsortedequal` as
`EnzymeRules.inactive`. This is exact.

It also avoids a hard abort: the early-exit search loops emit
`gc_preserve_begin`/`gc_preserve_end` token pairs that Enzyme's reverse
pass cannot reorder yet (EnzymeAD/Enzyme.jl#3404, "Instruction does not
dominate all uses!"), so any reverse-mode differentiation through an
interpolation interval lookup, e.g. DataInterpolations inside an ODE
right-hand side under `EnzymeVJP`, killed the process. With the rule
Enzyme never enters the loop.

Adds an `Enzyme` test group (piecewise-linear interpolant: reverse-mode
gradients w.r.t. knot values and query point, forward mode, batched and
equality searches under autodiff) and bumps the version to 3.3.0.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@SebastianM-C

Copy link
Copy Markdown
Member Author

trimmed the comments to trigger a rebuild

huh... the docs error is quite odd

┌ Error: linkcheck 'https://raw.githubusercontent.com/SciML/FindFirstFunctions.jl/main/bench/auto_sweep.jl' status: 404.
└ @ Documenter ~/.julia/packages/Documenter/13nbQ/src/utilities/utilities.jl:47

that link works for me, it looks like a transient network issue, should I keep retrying?

@SebastianM-C
SebastianM-C marked this pull request as ready for review September 16, 2026 22:36
@ChrisRackauckas
ChrisRackauckas merged commit 74517d1 into SciML:main Sep 16, 2026
24 of 25 checks passed
@SebastianM-C
SebastianM-C deleted the smc/enzymecore-ext branch September 16, 2026 23:26
ChrisRackauckas added a commit that referenced this pull request Sep 22, 2026
Ships two new package extensions declaring the searches inactive for AD: EnzymeCore (#116) and Mooncake (#117). Minor because both add weak dependencies and new extension behaviour.

Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com>
Co-Authored-By: Claude <noreply@anthropic.com>
Agent-Harness: Claude Code 2.1.273
Agent-Model: claude-opus-5[1m]
Agent-Session: 6a01e420-3436-4518-83cc-6cd853283cfb (local transcript; this harness publishes no conversation URL)
ChrisRackauckas added a commit that referenced this pull request Sep 22, 2026
Ships two new package extensions declaring the searches inactive for AD: EnzymeCore (#116) and Mooncake (#117). Minor because both add weak dependencies and new extension behaviour.



Agent-Harness: Claude Code 2.1.273
Agent-Model: claude-opus-5[1m]
Agent-Session: 6a01e420-3436-4518-83cc-6cd853283cfb (local transcript; this harness publishes no conversation URL)

Co-authored-by: Claude <noreply@anthropic.com>
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