Skip to content

Add Mooncake extension marking searches inactive - #117

Merged
ChrisRackauckas merged 2 commits into
SciML:mainfrom
AstitvaAggarwal:mooncake-ext
Sep 19, 2026
Merged

ChrisRackauckas merged 2 commits into
SciML:mainfrom
AstitvaAggarwal:mooncake-ext

Conversation

@AstitvaAggarwal

@AstitvaAggarwal AstitvaAggarwal commented Sep 18, 2026 •

Copy link
Copy Markdown
Member

Mirrors the existing EnzymeCore extension: searchsorted_last, searchsorted_first, searchsortedlast!, searchsortedfirst!, searchsortedrange, findequal, findfirstequal, and findfirstsortedequal all return a discrete index with no meaningful derivative, same as EnzymeRules.inactive already marks them.

For Mooncake this also works around a limitation: KIND_SIMD_LINEAR_SCAN's kernel embeds a raw llvmcall SIMD intrinsic that Mooncake can't translate. Marking the dispatcher itself inactive stops Mooncake before it descends into that kernel at all, rather than needing a fix on Mooncake's side for this specific SIMD path.

Found this while debugging native Hessian-vector products through OrdinaryDiffEq's dense-output interpolation, which uses these functions to locate a query time in the sorted grid of saved solution times: SciML/SciMLSensitivity.jl#1648.

Adds ext/FindFirstFunctionsMooncakeExt.jl (zero-derivative rules for the plain signature and the Core.kwcall path for keyword arguments like order/strategy/queries_sorted), the Mooncake weakdep/extension entries in Project.toml, and test/Mooncake/mooncake_tests.jl (reverse mode, forward mode, native HVP, a dedicated KIND_SIMD_LINEAR_SCAN case, and the batched/equality-search functions) wired into test_groups.toml as a new CI group.

All 6 new test groups pass. Also Verified against the SciMLSensitivity HVP scenario using a Mooncake branch with chalk-lab/Mooncake.jl#1327 (solved via chalk-lab/Mooncake.jl#1329) and chalk-lab/Mooncake.jl#1331.

Mirrors the existing EnzymeCore extension: searchsorted_last,
searchsorted_first, searchsortedlast!, searchsortedfirst!,
searchsortedrange, findequal, findfirstequal, and
findfirstsortedequal all return a discrete index with no meaningful
derivative, so mark them @zero_derivative for Mooncake too.

This also works around a real Mooncake limitation: KIND_SIMD_LINEAR_SCAN's
kernel embeds a raw llvmcall SIMD intrinsic that Mooncake's
intrinsic-lifting machinery cannot translate. Marking the dispatcher
itself inactive stops Mooncake before it ever descends into that (or
any other strategy's) kernel.

Surfaced via native Hessian-vector products through OrdinaryDiffEq's
dense-output interpolation: SciML/SciMLSensitivity.jl#1648.
Runic wants spaces after commas and around <: in where clauses.

The forward-mode test passed a NoTangent() for the closure, but
inside @safetestset closures capture their free variables as real
fields (unlike a plain top-level script), so it needs the closure's
actual zero tangent instead.
@AstitvaAggarwal

AstitvaAggarwal commented Sep 18, 2026 •

Copy link
Copy Markdown
Member Author

@ChrisRackauckas this PR + chalk-lab/Mooncake.jl#1331 are only left to merge for fixing SciML/SciMLSensitivity.jl#1648. so HVP, plain reverse or forward mode all should work for that specifc issue.

@ChrisRackauckas
ChrisRackauckas merged commit f42222d into SciML:main Sep 19, 2026
25 of 26 checks passed
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