Interpolations.jl isn’t setup with the Symbolics.jl tooling yet. If you want to integrate an interpolation, you’ll need to use DataInterpolations.jl. That only does 1-dimensional interpolations though. If you need higher dimension interpolations then you’ll want GitHub - SciML/DataInterpolationsND.jl: Interpolation of arbitrarily high dimensional array data , though this integration is not complete yet:
main ← ChrisRackauckas-Claude:add-symbolics-support
opened 01:34AM - 05 Sep 25 UTC
## Summary
This PR implements Symbolics.jl support for DataInterpolationsND.jl … to enable ModelingToolkit (MTK) compatibility as requested in issue #6.
The implementation follows the same pattern established in DataInterpolations.jl but is adapted for the N-dimensional case with support for partial derivatives.
## Changes
- **New Extension**: Created `DataInterpolationsNDSymbolicsExt` in `ext/` directory
- **Symbolic Registration**: Register `NDInterpolation` objects as symbolic functions
- **Partial Derivatives**: Implement symbolic differentiation for ∂f/∂x₁, ∂f/∂x₂, etc.
- **Higher-Order Derivatives**: Support for mixed partial derivatives
- **Test Suite**: Comprehensive tests for symbolic functionality
- **Project Configuration**: Proper extension setup with weakdeps
## Features
### Symbolic Evaluation
```julia
using DataInterpolationsND, Symbolics
@variables x y
itp = NDInterpolation(u, (LinearInterpolationDimension(t1), LinearInterpolationDimension(t2)))
result = itp(x, y) # Returns symbolic expression
```
### Symbolic Differentiation
```julia
∂f_∂x = Symbolics.derivative(result, x) # Partial derivative w.r.t. x
∂f_∂y = Symbolics.derivative(result, y) # Partial derivative w.r.t. y
```
### Value Substitution
```julia
numerical_value = Symbolics.substitute(result, Dict(x => 1.5, y => 0.5))
```
## Technical Details
The extension uses:
- `@register_symbolic` to register interpolation functions
- Custom `PartialDerivative` and `MixedPartialDerivative` types for symbolic differentiation
- Integration with DataInterpolationsND's existing `derivative_orders` parameter system
- Weak dependency pattern to avoid forcing Symbolics as a hard dependency
## Testing
The implementation has been thoroughly tested to verify:
- ✅ Symbolic expressions are created correctly
- ✅ Partial derivatives work for all dimensions
- ✅ Mixed derivatives are supported
- ✅ Substitution produces correct numerical values matching direct evaluation
- ✅ Integration with existing DataInterpolationsND functionality
## Test Plan
To test this PR:
1. **Basic functionality**:
```julia
using DataInterpolationsND, Symbolics
t1, t2 = [1.0, 2.0, 3.0], [0.0, 1.0, 2.0]
u = [i + j for i in t1, j in t2]
itp = NDInterpolation(u, (LinearInterpolationDimension(t1), LinearInterpolationDimension(t2)))
@variables x y
result = itp(x, y)
@assert result isa Symbolics.Num
```
2. **Differentiation**:
```julia
∂f_∂x = Symbolics.derivative(result, x)
@assert ∂f_∂x isa Symbolics.Num
```
3. **Numerical consistency**:
```julia
substituted = Symbolics.substitute(result, Dict(x => 1.5, y => 0.5))
numerical = itp(1.5, 0.5)
@assert substituted ≈ numerical
```
Resolves #6
🤖 Generated with [Claude Code](https://claude.ai/code)
When that PR is merged this story for ND will be complete.