Skip to content

Resolve symbolic idxs in the integrator interpolant - #126

Merged
ChrisRackauckas merged 2 commits into
SciML:masterfrom
ChrisRackauckas-Claude:integrator-symbolic-idxs
Sep 7, 2026
Merged

ChrisRackauckas merged 2 commits into
SciML:masterfrom
ChrisRackauckas-Claude:integrator-symbolic-idxs

Conversation

@ChrisRackauckas-Claude

@ChrisRackauckas-Claude ChrisRackauckas-Claude commented Sep 7, 2026 •

Copy link
Copy Markdown
Member

What changed and why

integrator(t; idxs = sym) passed idxs straight through to sol[idxs], so any symbolic
index threw ArgumentError: invalid index and an observed equation could never be retrieved
from an integrator. sol(t; idxs = sym) has resolved both for a long time; this closes the
same gap that SciML/OrdinaryDiffEq.jl#4469 and
SciML/Sundials.jl#565 close for their integrators. It came up in
SciML/ModelingToolkit.jl#5006.

(integrator::ODEInterfaceIntegrator)(t; idxs) now checks SciMLBase.has_symbolic_idxs and
routes to SciMLBase.symbolic_interpolation. The nothing comparison also changes from
== to ===: once idxs can hold a symbolic value, idxs == nothing no longer reliably
returns a Bool.

Depends on SciMLBase.symbolic_interpolation and SciMLBase.has_symbolic_idxs, added in
SciML/SciMLBase.jl#1585. symbolic_interpolation shipped in
SciMLBase 3.52.0, but has_symbolic_idxs did not make that merge, so the compat floor here
is 3.53 and CI fails with UndefVarError: has_symbolic_idxs not defined until #1585 is
registered.

Verification

New test file test/symbolic_interpolation_tests.jl, picked up automatically as a top-level
Core file. The ODEInterface integrator only exists inside a callback, so the symbolic
indexing is probed from an affect!. It uses a SymbolCache, whose Expr indexes are
observed quantities, so it covers the observed path without adding ModelingToolkit to the
test target.

Before, with only the test applied and src/ reverted:

Symbolic idxs inside a callback: Error During Test
  ArgumentError: invalid index: :x of type Symbol
Symbolic idxs inside a callback: Error During Test
  ArgumentError: invalid index: :y of type Symbol
Symbolic idxs inside a callback: Error During Test
  ArgumentError: invalid index: :(x + y) of type Expr

After:

Symbolic idxs inside a callback |   19     19  8.2s

Both runs used SciMLBase Pkg.developed to the branch in #1581, since the compat bound
above requires a version that is not yet registered (#1585). Runic --check and typos are clean
on the files touched.

Things a reviewer should push back on

  • The test needs a ContinuousCallback rather than a DiscreteCallback: that is what puts
    the solver into OUTPUTFCN_DENSE mode, and without it integrator(t) itself raises "The
    evaluation of the numerical solution is not possible", independent of idxs. There is a
    comment in the test saying so.
  • A symbolic index evaluates the whole state and then projects, while an integer index reads
    that component out of the raw output. The two agree to rounding rather than bitwise, so
    the tests compare those paths with ≈.
  • has_symbolic_idxs treats Symbol and Expr as symbolic, since that is what
    SymbolicIndexingInterface.symbolic_type reports. integrator(t; idxs = :x) previously
    threw and now resolves through the symbol cache — the intended widening, but a behavior
    change for anyone relying on the error.

Not verified

The rest of the ODEInterfaceDiffEq test suite, and Julia LTS. CI covers those once #1585 is
registered.


This PR should be ignored until reviewed by @ChrisRackauckas.

🤖 Generated with Claude Code

https://claude.ai/code/session_019wKpyZHy9u4QhR4ePiVmam

`integrator(t; idxs = sym)` passed `idxs` straight through to `sol[idxs]`, so any
symbolic index threw `ArgumentError: invalid index` and an observed equation
could never be retrieved. `sol(t; idxs = sym)` has resolved both for a long time.

Symbolic `idxs` now route to `SciMLBase.symbolic_interpolation`. The `nothing`
comparison also becomes `===`, which is what it has to be once `idxs` can be a
symbolic value that does not return a `Bool` from `==`.

Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com>
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019wKpyZHy9u4QhR4ePiVmam
Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com>
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019wKpyZHy9u4QhR4ePiVmam
@ChrisRackauckas
ChrisRackauckas marked this pull request as ready for review September 7, 2026 09:02
@ChrisRackauckas
ChrisRackauckas merged commit 3e576c2 into SciML:master Sep 7, 2026
13 of 18 checks passed
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