Add Symbolics.jl extension for ModelingToolkit.jl compatibility#51
Conversation
Implements Symbolics.jl registration for all FastInterpolations interpolant types (1D and ND), enabling use in ModelingToolkit.jl symbolic contexts. 1D interpolants (AbstractInterpolant): - Symbolic calling via @register_symbolic wrapper function - Derivative chain rules via @register_derivative - Supports higher-order derivatives (d/dt → derivative(itp, t, 1), etc.) ND interpolants (AbstractInterpolantND): - Symbolic calling via SymbolicUtils.term for all concrete ND types - Partial derivative chain rules via @register_derivative - DifferentiatedInterpolantND wrapper for accumulating per-axis derivative orders - Numeric varargs bridge for build_function compiled code Also adds exported `derivative(itp, t, order)` function wrapping the `deriv=DerivOp(order)` keyword API for Symbolics chain rule compatibility. Closes ProjectTorreyPines#50 Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #51 +/- ##
=======================================
Coverage 97.68% 97.68%
=======================================
Files 72 72
Lines 5781 5781
=======================================
Hits 5647 5647
Misses 134 134 🚀 New features to boost your workflow:
|
|
@ChrisRackauckas Thanks for this PR! The Symbolics integration looks great overall. One suggestion: Since this function only serves as glue between our kwargs API and _derivative_symbolic(itp::AbstractInterpolant, t, order::Integer) = itp(t; deriv=DerivOp(order))Would you mind replacing the I'm also happy to push these changes to your branch if that's easier — just let me know! |
|
That's fine. |
Per review feedback, removes `derivative` from the core API to avoid potential name clashes with AD packages. The function now lives entirely in FastInterpolationsSymbolicsExt as `_derivative_symbolic`, which is only used as glue between the kwargs API and Symbolics' positional-args requirement. - Remove src/symbolic_derivative.jl and export derivative - Replace all derivative references in extension with _derivative_symbolic - Update tests to use itp(t; deriv=DerivOp(n)) directly Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com> Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
FastInterpolations.jl BenchmarksDetails
This comment was automatically generated by Benchmark workflow. |
Summary
FastInterpolationsSymbolicsExt) that registers all FastInterpolations interpolant types with Symbolics.jl, enabling use in ModelingToolkit.jl symbolic contextsAbstractInterpolant) and ND (AbstractInterpolantND) interpolants with symbolic calling and derivative chain rulesderivative(itp, t, order)function wrapping thederiv=DerivOp(order)keyword API1D Support
@register_symbolicwrapper function (avoids method ambiguity with concrete types)@register_derivative:d/dt itp(t) → derivative(itp, t, 1),d/dt derivative(itp, t, n) → derivative(itp, t, n+1)LinearInterpolant,CubicInterpolant,QuadraticInterpolant,ConstantInterpolantND Support
SymbolicUtils.termfor all concrete ND types@register_derivativewithDifferentiatedInterpolantNDwrapper for accumulating per-axis derivative ordersbuild_functioncompiled code compatibilityLinearInterpolantND,CubicInterpolantND,QuadraticInterpolantND,ConstantInterpolantNDDesign Decisions
_fast_interp_evalfor 1D rather than registering onAbstractInterpolantdirectly, to avoid method ambiguity with concrete types that have untypedxqparameterSymbolicUtils.termmanually for ND (not@register_symbolic) because ND interpolants are callable structs with variable arityTest plan
Numexpressions and round-trip throughbuild_functionexpand_derivatives+build_functionmatch numericderivative()for 1st and 2nd orderderivative()function: matchesitp(t; deriv=DerivOp(n))for orders 1-3Numexpressions and round-trips throughbuild_functionexpand_derivativesmatch numericitp((u,v); deriv=DerivOp(1,0))andDerivOp(0,1)Closes #50
🤖 Generated with Claude Code