Port Symbolics extension to the Symbolics v7 APIs#72
Merged
ChrisRackauckas merged 2 commits intoJun 10, 2026
Conversation
This was referenced Jun 10, 2026
Contributor
Author
|
CI status note: all 9
🤖 Generated with Claude Code |
The extension was written against the Symbolics v6 extension APIs and was
never functional on Symbolics v7, which is the only version allowed by
compat:
- `Symbolics.array_term` does not exist in v7, so symbolically calling
any array-output interpolation threw an UndefVarError.
- Scalar-output terms were built without shape information, getting
`Unknown` shape, which `expand_derivatives` rejects with
"Differentiation with array expressions is not yet supported".
- The `Symbolics.derivative(op, args, ::Val{I})` overload API was
removed in v7 in favor of `@register_derivative`/`derivative_rule`,
so the registered derivatives were dead code and derivatives of
interpolation calls were left as unexpanded `Differential` operators.
This went unnoticed because the Extensions test group is declared in
test/runtests.jl but was missing from test/test_groups.toml, so the
extension tests never ran on CI.
Changes:
- Build terms with `SymbolicUtils.term` passing explicit `type` and
`shape`, and define `SymbolicUtils.promote_shape` alongside
`promote_symtype` for both interpolation callable types.
- Register derivatives via `@register_derivative`, keeping the
`DifferentiatedNDInterpolation` representation for partial
derivatives of arbitrary order.
- Add the Extensions group to test_groups.toml so the tests run on CI.
- Extend the tests to cover scalar-output (N_out == 0) interpolations,
full `expand_derivatives` chain rules, and second derivatives
(SciML#69), and fix a
`BasicSymbolic{Vector{Real}}` assertion that is invalid under
SymbolicUtils v4's type parameterization.
Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com>
The extension is pure Julia with no platform-specific behavior, so the os matrix adds CI cost without coverage. Windows grouped jobs currently do not even run their declared group (SciML/.github#81). Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com>
a2464a1 to
a915b42
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.
Important
This PR should be ignored until reviewed by @ChrisRackauckas.
Investigation of #69 revealed the Symbolics extension has been entirely non-functional on Symbolics v7 — which is the only version the compat allows — because it still uses the v6 extension APIs:
Symbolics.array_termdoes not exist in any Symbolics v7 release. Symbolically calling an array-output (N_out >= 1) interpolation throwsUndefVarError: array_term not defined.Unknownshape.SymbolicUtils.term(interp, t...; type = Real)leavesshape = Unknown(-1), whichexpand_derivativesrejects withDifferentiation with array expressions is not yet supported. SymbolicUtils v4 needspromote_shape(or an explicitshape) for non-builtin callables.Symbolics.derivative(op, args, ::Val{I})overload API was removed in Symbolics v7 in favor of@register_derivative/derivative_rule(the same migration DataInterpolations.jl did in its Symbolics ext behind apkgversion(Symbolics) >= v"7"check). Defining methods on the old function does nothing, so derivatives of interpolation terms were left as unexpandedDifferentialoperators.Why CI never caught this:
test/runtests.jlhas anExtensionsgroup containingtest_symbolics_ext.jl, buttest/test_groups.tomlonly declaresCoreandQA, so the extension tests never ran on CI. (Locally, on current main with Symbolics v7.26,test_symbolics_ext.jlerrors immediately atinterp(x, y).)Changes
SymbolicUtils.termwith explicittypeandshape, and defineSymbolicUtils.promote_shapealongsidepromote_symtypefor bothNDInterpolationandDifferentiatedNDInterpolation.@register_derivative; partial derivatives are still represented byDifferentiatedNDInterpolationso arbitrary mixed orders compose.Extensionsgroup totest_groups.tomlso these tests actually run on CI.N_out == 0) interpolations (the Differentiating through DataInterpolationsND functions throws error #69 use case — previously untested), fullexpand_derivativeschain rule through both arguments, second/mixed derivatives, and numeric evaluation of every generated expression. Also fixed anex isa BasicSymbolic{Vector{Real}}assertion that is invalid under SymbolicUtils v4 (the type parameter is now the variant, not the symtype).All APIs used (
@register_derivative,Symbolics.SymbolicT,SymbolicUtils.ShapeVecT) exist since Symbolics v7.0.0, so no compat change is needed.What this does and does not fix for #69
With this PR, directly embedding
NDInterpolationobjects in MTK equations works end-to-end: the #69 MWE rewritten with direct embedding compiles viamtkcompile(9-equation fully determined system) and solves successfully withRodas5P(verified locally).The original MWE uses MTK callable parameters (
(itp::NDInterpolation)(..)), and that form still fails: in the symbolic expression the operation is the symbolic stand-in for the parameter (symtypeFnType{Tuple, Real, NDInterpolation}), not anNDInterpolationinstance, so no instance-dispatched derivative rule can ever fire andexpand_derivativesleavesDifferential(p(t))(itp(p(t), T(t)))behind, whichvalidate_operatorthen rejects. That gap is upstream (Symbolics needs a hook to dispatch derivative rules on the FnType's callable type) and affects DataInterpolations.jl 1-D the same way whenever a callable parameter is called with an unknown rather thant(itsODEProblemconstruction fails at the initialization system even thoughmtkcompilehappens to pass). I am filing that separately upstream.Local test output
Runic.jl run on the changed files.
🤖 Generated with Claude Code