Hi! I was playing a bit with the Magnus solvers included in the examples for linear ODEs in the docs: Non-autonomous Linear ODE / Lie Group ODE Solvers.
I was particularly interesting in benchmarking the solver I am currently using for a state independent solver and I noticed that the gold standard Tsitouras solver still performs better in these cases, even when Magnus solvers should be in principle better for ODEs of the form u' = A(t) u.
Here is a simple MWE with the example included in the documentation:
using OrdinaryDiffEqCore, OrdinaryDiffEqTsit5
using OrdinaryDiffEqLinear
using BenchmarkTools
function update_func(A, u, p, t)
A[1, 1] = cos(t)
A[2, 1] = sin(t)
A[1, 2] = -sin(t)
A[2, 2] = cos(t)
end
A = DiffEqArrayOperator(ones(2, 2), update_func = update_func)
prob = ODEProblem(A, ones(2), (1.0, 6.0))
@btime solve(prob, Tsit5(), dt=0.1, abstol=1e-6, reltol=1e-6);
# 26.245 μs (280 allocations: 24.20 KiB)
@btime solve(prob, MagnusGL6(), dt=0.1, abstol=1e-6, reltol=1e-6);
# 208.365 μs (3481 allocations: 335.88 KiB)
@btime solve(prob, MagnusGL4(), dt=0.1, abstol=1e-6, reltol=1e-6);
# 93.735 μs (981 allocations: 94.47 KiB)
@btime solve(prob, MagnusLeapfrog(), dt=0.1, abstol=1e-6, reltol=1e-6);
# 67.176 μs (532 allocations: 45.33 KiB)
Also, the Magnus solvers don’t allow don’t passing dt
, reason why the comparison is with fixed timestep.
Does this result makes sense? I was expecting the Magnus solvers to be the best solution for my problem u' = A(t)u, but it looks like Tsitouras also is better here!
Any feedback is more than welcome, I am trying to understand if I am missing something here.