Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "ODEInterfaceDiffEq"
uuid = "09606e27-ecf5-54fc-bb29-004bd9f985bf"
authors = ["Chris Rackauckas <accounts@chrisrackauckas.com>"]
version = "5.3.0"
version = "5.4.0"

[deps]
Compat = "34da2185-b29b-5c13-b0c7-acf172513d20"
Expand All @@ -27,7 +27,7 @@ ODEInterface = "0.5.2"
PrecompileTools = "1.2"
ODEProblemLibrary = "1"
SafeTestsets = "0.1"
SciMLBase = "3.1"
SciMLBase = "3.53"
SciMLLogging = "2"
SciMLStructures = "1"
SciMLTesting = "2.4"
Expand Down
5 changes: 4 additions & 1 deletion src/integrator_types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
39 changes: 39 additions & 0 deletions test/symbolic_interpolation_tests.jl
Original file line number Diff line number Diff line change
@@ -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
Loading