Skip to content

In-place solution evaluation does not work with ModelingToolkit #2562

@hersle

Description

@hersle

The documentation mentions an inplace function for evaluating a solution, but this does not work with ModelingToolkit:

using OrdinaryDiffEq, ModelingToolkit, Test
using ModelingToolkit: t_nounits as t, D_nounits as D
@variables x(t) y(t)
@named sys = ODESystem([
    D(x) ~ 0 # unknown
    y ~ 2*x # observed
], t)
sys = structural_simplify(sys)
prob = ODEProblem(sys, [x => 1.0], (0.0, 1.0), [])
sol = solve(prob, Tsit5())

ts = range(0.0, 1.0, length=5)
out = zeros(size(ts))
@test sol(out, ts; idxs=1) == sol(ts; idxs=1) # passes
@test sol(out, ts; idxs=sys.x) == sol(ts; idxs=sys.x) # RHS works, LHS fails
@test sol(out, ts; idxs=sys.y) == sol(ts; idxs=sys.y) # RHS works, LHS fails

The last two in-place evaluations fail with

ERROR: ArgumentError: invalid index: x(t) of type SymbolicUtils.BasicSymbolic{Real}
ERROR: ArgumentError: invalid index: y(t) of type SymbolicUtils.BasicSymbolic{Real}

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions