Skip to content

Big slowdown of ODE with matrix equations #3708

Open
@hersle

Description

@hersle

This "matrix ODE" is much slower and allocates much more than it used to:

using ModelingToolkit, OrdinaryDiffEq
using ModelingToolkit: t_nounits as t, D_nounits as D

@variables x(t)[1:2,1:1]
eqs = [D(x[1,1]) ~ x[1,1], x[2,1] ~ 0.0]
@named sys = System(eqs, t)
ssys = mtkcompile(sys)
prob = ODEProblem(ssys, [x[1,1] => 1.0], (0.0, 1.0))
@time sol = solve(prob, Tsit5(); dt = 1e-5, adaptive = false, save_everystep = false)
0.031453 seconds (1.80 M allocations: 64.097 MiB, 45.73% gc time)

For comparison, here is the equivalent "scalar ODE":

@variables x11(t) x21(t)
eqs = [D(x11) ~ x11, x21 ~ 0.0]
@named sys = System(eqs, t)
ssys = mtkcompile(sys)
prob = ODEProblem(ssys, [x11 => 1.0], (0.0, 1.0))
@time sol = solve(prob, Tsit5(); dt = 1e-5, adaptive = false, save_everystep = false)
0.004658 seconds (144 allocations: 8.594 KiB)

This was for a 2x1 matrix. The problem is much worse for larger sizes.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions