From bb851088f42e60374293619760ec802206cfb499 Mon Sep 17 00:00:00 2001 From: ChrisRackauckas-Claude Date: Sun, 6 Sep 2026 21:35:42 -0400 Subject: [PATCH 1/2] Resolve symbolic idxs in the integrator interpolant `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 Co-Authored-By: Claude Opus 5 (1M context) Claude-Session: https://claude.ai/code/session_019wKpyZHy9u4QhR4ePiVmam --- Project.toml | 4 +-- src/integrator_types.jl | 5 +++- test/symbolic_interpolation_tests.jl | 39 ++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 3 deletions(-) create mode 100644 test/symbolic_interpolation_tests.jl diff --git a/Project.toml b/Project.toml index e0961b3..288e887 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "ODEInterfaceDiffEq" uuid = "09606e27-ecf5-54fc-bb29-004bd9f985bf" authors = ["Chris Rackauckas "] -version = "5.3.0" +version = "5.4.0" [deps] Compat = "34da2185-b29b-5c13-b0c7-acf172513d20" @@ -27,7 +27,7 @@ ODEInterface = "0.5.2" PrecompileTools = "1.2" ODEProblemLibrary = "1" SafeTestsets = "0.1" -SciMLBase = "3.1" +SciMLBase = "3.52" SciMLLogging = "2" SciMLStructures = "1" SciMLTesting = "2.4" diff --git a/src/integrator_types.jl b/src/integrator_types.jl index 9b0d2e6..63c4ea1 100644 --- a/src/integrator_types.jl +++ b/src/integrator_types.jl @@ -34,6 +34,9 @@ end idxs = nothing ) where {N} @assert N == 0 "ODEInterface does not support dense derivative" + if SciMLBase.has_symbolic_idxs(idxs) + return SciMLBase.symbolic_interpolation(integrator, t, idxs, deriv) + end sol = integrator.eval_sol_fcn(t) - return idxs == nothing ? sol : sol[idxs] + return idxs === nothing ? sol : sol[idxs] end diff --git a/test/symbolic_interpolation_tests.jl b/test/symbolic_interpolation_tests.jl new file mode 100644 index 0000000..8f1cbd8 --- /dev/null +++ b/test/symbolic_interpolation_tests.jl @@ -0,0 +1,39 @@ +using ODEInterfaceDiffEq, Test +using SciMLBase: SymbolCache + +# The ODEInterface integrator only exists inside a callback, so the symbolic indexing is +# probed from an `affect!`. `SymbolCache` resolves an `Expr` as an observed quantity, so +# `:(x + y)` is not a component of the state vector. +f = ODEFunction( + (du, u, p, t) -> (du[1] = u[2]; du[2] = -u[1]); + sys = SymbolCache([:x, :y], Symbol[], :t) +) +prob = ODEProblem(f, [1.0, 0.0], (0.0, 10.0)) + +@testset "Symbolic idxs inside a callback" begin + probed = Ref(false) + affect! = function (integrator) + t = integrator.t + # A symbolic index evaluates the whole state and then projects, while an integer + # index reads that component out of the raw output, so these agree to rounding. + @test integrator(t; idxs = :x) ≈ integrator(t; idxs = 1) + @test integrator(t; idxs = :y) ≈ integrator(t; idxs = 2) + @test integrator(t; idxs = :(x + y)) ≈ sum(integrator(t)) + @test integrator(t; idxs = [:x, :y]) ≈ integrator(t) + + # Symbolic routing does not disturb the existing integer and `nothing` paths + @test integrator(t) == integrator(t; idxs = nothing) + @test integrator(t; idxs = [1, 2]) ≈ integrator(t) + probed[] = true + return nothing + end + + # A ContinuousCallback is what puts the solver in dense-output mode, which the + # interpolant this test exercises requires. + solve( + prob, dopri5(); + callback = ContinuousCallback((u, t, integrator) -> u[1], affect!), + dtmax = 0.5 + ) + @test probed[] +end From 7419fceb9fad0cc855942830f3be9032a72ba24d Mon Sep 17 00:00:00 2001 From: ChrisRackauckas-Claude Date: Sun, 6 Sep 2026 22:56:37 -0400 Subject: [PATCH 2/2] Require SciMLBase 3.53 for has_symbolic_idxs Co-Authored-By: Chris Rackauckas Co-Authored-By: Claude Opus 5 (1M context) Claude-Session: https://claude.ai/code/session_019wKpyZHy9u4QhR4ePiVmam --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index 288e887..7b2d132 100644 --- a/Project.toml +++ b/Project.toml @@ -27,7 +27,7 @@ ODEInterface = "0.5.2" PrecompileTools = "1.2" ODEProblemLibrary = "1" SafeTestsets = "0.1" -SciMLBase = "3.52" +SciMLBase = "3.53" SciMLLogging = "2" SciMLStructures = "1" SciMLTesting = "2.4"