Handle AD-valued interpolation knots#557
Draft
ChrisRackauckas-Claude wants to merge 1 commit into
Draft
Conversation
Contributor
Author
|
Commit Local evidence for this commit:
The branch is based on current upstream |
Contributor
Author
|
Post-timer CI check: all 18 reported checks are green, including Core on Julia lts/1/pre, Methods on Julia lts/1/pre, Extensions on Julia lts/1, Misc on Julia lts/1/pre, QA, Downgrade, documentation, Runic, and spelling. |
9faed1f to
90b22a0
Compare
Reconstructing an interpolation inside ForwardDiff promotes both the values and the knot vector to `ForwardDiff.Dual`. On FindFirstFunctions < 3.2 the `SearchProperties` linearity probe attempted an invalid `Float64(::Dual)` conversion, breaking `LinearInterpolation` (and the other constructors) for 11+ knots — the v9.0.0 regression. FindFirstFunctions 3.2 fixes the probe upstream (SciML/FindFirstFunctions.jl#100), so no local opt-out shim is needed: bump the compat lower bound to `3.2` and keep using `something(search_properties, FindFirstFunctions.SearchProperties(t))` directly. Adds a regression test differentiating through both values and knots across 15 knots. Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com> Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FvBXVKGujjeaCB3iLwsDeG
90b22a0 to
13dff09
Compare
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.
Please ignore this PR until reviewed by @ChrisRackauckas.
Summary
FindFirstFunctions.SearchPropertieswith AD-valued knot vectorsSearchProperties()sentinel for number wrappers, selecting the correct binary-search fallbackRoot cause
Reconstructing an interpolation inside ForwardDiff can promote both the interpolation values and knot vector to
ForwardDiff.Dual. For vectors with at least 11 knots,SearchProperties(t)runs the sampled linear-fit probe.FindFirstFunctions._sampled_linear_errthen attempts aFloat64(::ForwardDiff.Dual)conversion and throws before interpolation evaluation.The existing four-knot ForwardDiff coverage from #510 / #513 does not enter that sampled probe.
The constructor pattern
also evaluates the default probe eagerly even when callers supply search properties. The private dispatch helper in this PR avoids that eager evaluation.
Primitive
IntegerandAbstractFloatknots still receive populated properties and retain the fast path. Other number wrappers receive the documented zero-information sentinel and use binary search. This uses only public FindFirstFunctions APIs and introduces no new public DataInterpolations API.Regression boundary
I reproduced the same 15-knot combined value/knot gradient at adjacent DataInterpolations commits:
9ad45d3426c19c38c6a0da93eedb971b04087fbc(Migrate to FindFirstFunctions 2.0 strategy API): passese22f5d6a6fa8d72079b33209b910b9504c4cadde(Cache SearchProperties per interpolation to skip per-call Auto probes): fails withFloat64(::ForwardDiff.Dual)There is exactly one commit between those endpoints, so
e22f5d6is the first bad commit. It first shipped in DataInterpolations v9.0.0; v8.10.0 does not contain it.Related history: #229 / #230 added ForwardDiff support, while #510 / #513 added differentiation-through-knots coverage with only four knots.
Downstream classification
ModelingToolkitStandardLibrary currently supports DataInterpolations 8.x, not 9.x. The exact combined 15-knot MRE passes under its supported versions:
An unmodified current-main MTKStandardLibrary
test/sources.jlrun was independently blocked before its interpolation assertions byfntype_X_Y(::Type{Real}). That clean-main callable-symtype defect is fixed and tracked separately in ModelingToolkitStandardLibrary.jl#480.With #480's commit applied while retaining the supported DataInterpolations 8.10.0 environment:
Therefore this PR fixes the DataInterpolations 9 regression; it does not alter MTKStandardLibrary compatibility or code.
Local verification
Julia 1.12.6:
GROUP=Core julia +1.12 --project -e 'using Pkg; Pkg.test()'Testing DataInterpolations tests passedGROUP=Methods julia +1.12 --project -e 'using Pkg; Pkg.test()'Testing DataInterpolations tests passed3.50.0[3 => 0.5, 4 => 0.5, 18 => -0.5, 19 => -0.5]Runic.main(["--check", "."])exited 0git diff --checkpassedInvestigation and implementation record
9ad45d3ande22f5d6