Skip to content

Register the derivative of symbolic interpolations - #616

Open
pankgeorg wants to merge 1 commit into
SciML:masterfrom
pankgeorg:symbolic-callable-derivative
Open

pankgeorg wants to merge 1 commit into
SciML:masterfrom
pankgeorg:symbolic-callable-derivative

Conversation

@pankgeorg

Copy link
Copy Markdown

Adds the derivative rule for a symbolic interpolation, such as a ModelingToolkit callable parameter @parameters (itp::LinearInterpolation)(..) (JuliaSymbolics/Symbolics.jl#1890). D(itp(x)) now expands to derivative(itp, x, 1) with itp kept symbolic, so jac = true works for models using ModelingToolkitStandardLibrary.Blocks.Interpolation. Rules for interpolation objects used directly are unchanged.

Needs JuliaSymbolics/Symbolics.jl#2022. The Symbolics compat bound is bumped to the release containing it (7.42), and the version to 10.2.0.

Tested with a new testset in test/Methods/derivative_tests.jl: first and second derivatives, the chain rule, substitution, and numeric values through build_function for two interpolations of the same type.

🤖 Generated with Claude Code

`D(itp(x))` for a symbolic interpolation, e.g. a ModelingToolkit callable
parameter, expands to `derivative(itp, x, 1)` with `itp` kept symbolic.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ChrisRackauckas-Claude

Copy link
Copy Markdown
Member

🤖 Automated comment from an AI agent running as @ChrisRackauckas — not written or reviewed by Chris.

Independent review (Codex CLI 0.166.0 / gpt-6.1-sol), session 01a1983a-42ae-7a93-86ac-92cf834a3011, reviewed head 9f28583

  • Verdict: MERGE
  • Risk: medium-low (ML4: Symbolics compatibility lower-bound increase; L6: the symbolic-callable regression fails before and passes after, while existing concrete symbolic-derivative assertions remain passing).
  • Round / slot: 1 / 1
  • Blocking priorities: none

Review written by the reviewer named above in a session other than the PR author's, and copied here by the posting agent without change to its findings. The posting agent did not re-run the reviewer's commands.

Summary: Registers differentiation of interpolation-typed symbolic callables and raises the Symbolics compatibility floor to 7.42. The added regression fails on the base and passes on the reviewed head, with independent analytic checks passing and no blocking defects found.

Blast radius: Optional Symbolics extension, interpolation-typed symbolic functions, derivative expansion, generated functions, and substitution. Existing concrete numerical implementations are untouched.

Evidence: Blind assessment sealed before reading author context. Julia 1.13.2 with Symbolics 7.42.0 and SymbolicUtils 4.54.0: added regression on base 2 passed, 6 failed, 1 errored; head 9/9 passed; existing symbolic tests 6/6 passed on both; independent analytic probe 98/98 passed. No PR CI checks were reported; local runs exercised the changed extension and ForwardDiff-backed second derivatives.

Blocking findings

None.

Non-blocking findings

None.

What I ran

Read-only GitHub inspection:

gh api repos/SciML/DataInterpolations.jl/pulls/616 --jq '{number,state,draft,headRefOid:.head.sha,baseRefName:.base.ref,baseRefOid:.base.sha}'
gh pr view 616 --repo SciML/DataInterpolations.jl --json title,body,url
gh pr checks 616 --repo SciML/DataInterpolations.jl
gh api repos/SciML/DataInterpolations.jl/commits/9f28583ee7e12a10b0c3622b875b7bc448c2b9a0/check-runs --jq '{total_count,check_runs:[.check_runs[]|{name,status,conclusion,html_url}]}'
gh run list --repo SciML/DataInterpolations.jl --branch master --event push --limit 5
gh issue view 1890 --repo JuliaSymbolics/Symbolics.jl
gh pr view 2022 --repo JuliaSymbolics/Symbolics.jl --json title,body,state,mergedAt,url

The PR was open and draft, at the target head. gh pr checks exited 1 with no checks reported; the check-runs API returned total_count: 0. Other queries exited 0. Recent master Tests run 41195051063 was completed successfully; this is contextual evidence, not a substitute for head CI. No failed PR jobs existed to inspect. The linked Symbolics prerequisite was merged; its installed implementation documents and publicly exposes SymbolicCallable and its f field.

Git commands, with the checkout represented by $CHECKOUT:

git -C "$CHECKOUT" status --short
git -C "$CHECKOUT" rev-parse HEAD
git -C "$CHECKOUT" fetch origin '+refs/pull/616/head:refs/remotes/pr/616' master
git -C "$CHECKOUT" rev-parse origin/master
git -C "$CHECKOUT" merge-base origin/master HEAD
git -C "$CHECKOUT" diff --stat origin/master...HEAD
git -C "$CHECKOUT" diff origin/master...HEAD
git -C "$CHECKOUT" diff --stat b98db80406869b7664d5760ed48785f3f2d5cad6...HEAD
git -C "$CHECKOUT" log -1 --format=%B 9f28583ee7e12a10b0c3622b875b7bc448c2b9a0

These exited 0. The checkout was clean. The merge base was the reported live base SHA above. The commit contained neither Agent-Harness: nor Agent-Model: trailers. The initial risk assessment was written and SHA-256 sealed before the description, commit message, or linked issues were read.

Exactly three sequential Julia invocations ran, all on Julia 1.13.2. Absolute depot and temporary-directory prefixes are represented by environment variables to comply with the output path restriction. Each invocation used this environment and command form, with the indicated script:

JULIA_NUM_THREADS=4 OPENBLAS_NUM_THREADS=1 JULIA_NUM_PRECOMPILE_TASKS=1 JULIA_PKG_PRECOMPILE_AUTO=0 TMPDIR="$REVIEW_TMP" JULIA_DEPOT_PATH="$SHARED_DEPOT:" timeout 3600 julia +1.13.2 --startup-file=no run_head.jl
JULIA_NUM_THREADS=4 OPENBLAS_NUM_THREADS=1 JULIA_NUM_PRECOMPILE_TASKS=1 JULIA_PKG_PRECOMPILE_AUTO=0 TMPDIR="$REVIEW_TMP" JULIA_DEPOT_PATH="$SHARED_DEPOT:" timeout 3600 julia +1.13.2 --startup-file=no run_base.jl
JULIA_NUM_THREADS=4 OPENBLAS_NUM_THREADS=1 JULIA_NUM_PRECOMPILE_TASKS=1 JULIA_PKG_PRECOMPILE_AUTO=0 TMPDIR="$REVIEW_TMP" JULIA_DEPOT_PATH="$SHARED_DEPOT:" timeout 3600 julia +1.13.2 --startup-file=no run_probe.jl
  • run_head.jl, exit 1: activated an isolated environment, developed the head checkout, added Symbolics 7.42.0, FiniteDifferences, StableRNGs, and CurveFit, and attempted include("test/Methods/derivative_tests.jl") from the checkout. It stopped at the import on test/Methods/derivative_tests.jl:2: ArgumentError: Package FindFirstFunctions not found in current path. No test assertions ran in this invocation. This was a reviewer environment setup error.
  • run_base.jl, exit 1: developed an untouched archive of the merge base in a separate environment with the same resolved dependency versions. Executed verbatim the existing Symbolic derivatives testset and the head's added Symbolic derivatives of symbolic interpolations testset, extracted from test/Methods/derivative_tests.jl:473 and test/Methods/derivative_tests.jl:509. Output: existing testset 6/6 passed; added testset 2 passed, 6 failed, 1 errored. The chain-rule expression retained Differential(ω(τ), 1)(itp(ω(τ))); generated derivatives failed numeric comparisons; substitution returned an unresolved derivative equality instead of a Boolean. This confirms the added test fails before the fix.
  • run_probe.jl, exit 0: activated the head environment and executed the same two extracted testsets unchanged, followed by an independent analytic probe. Output: Symbolic derivatives | 6 / 6; Symbolic derivatives of symbolic interpolations | 9 / 9; Analytic symbolic-callable reference | 98 / 98. This confirms the added test passes after the fix.

The analytic reference used the unique quadratic through (0, 0), (0.5, 1.5), (1, 0): q(x) = 6x - 6x², with derivatives 6 - 12x and -12. It checked generated first and second derivatives, composition with x² against 12x - 24x³ and 12 - 72x², positive/negative/zero scaling, runtime interpolation substitution, endpoints, and interior knots. Independent piecewise-linear slope checks also verified the documented left derivative at the middle knot. Bounds of 1e-12 were conservative Float64 rounding allowances for these small polynomials. Expected results came from algebra, not observed implementation output; the probe exercises G1 and the relevant G2 symbolic/ForwardDiff paths. No shared-state change invokes G3.

What I did not verify

The complete derivative test file did not execute because the first invocation lacked direct test dependencies; it was not rerun. Only the two focused symbolic testsets and analytic probe completed. I did not run the package suite, downstream suites, an end-to-end ModelingToolkit model with jac = true, other Symbolics releases, Julia 1.10, or other platforms. GPU, MPI, Reactant, and other AD backends were not exercised; this PR does not change those paths. No PR CI execution was available. Source files and upstream state were not modified.

🤖 Posted by an AI agent — harness: Claude Code · model: claude-sonnet-5-5
Conversation: https://claude.ai/code/session_01379heiiB35TtywhR7uSU74

@ChrisRackauckas-Claude
ChrisRackauckas-Claude marked this pull request as ready for review November 2, 2026 02:03

This branch has not been deployed

No deployments
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