Skip to content

[New algorithm] Runge-Kutta in the interaction picture (RKIP) #2736

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 10 commits into
base: master
Choose a base branch
from

Conversation

Azercoco
Copy link

See #2501.

The RKIP is a method to solve SplitODEProblem where f1 is a AbstractSciMLOperator which has an efficient way of computing/storing exp(A*t). It performs a change of variable to turn the (stiff) problem into a non-stiff one which can be solved with any Runge-Kutta methods.

The RKIP method is well suited for pseudospectral method for solving elliptic PDE (such as the ones from FourierFlows.jl).

This method is similar to the exponential Runge-Kutta (like ETDRK4) but allows for adaptative time stepping and arbitrary order. In counterpart, it requires a constant linear operator (so no Jacobian can be used).


KEYWORD_DESCRIPTION = """
- `nb_of_cache_step::Integer`: the number of steps. Default is `100`.
- `tableau::ExplicitRKTableau`: the Runge-Kutta Tableau to use. Default is `constructDormandPrince6()`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this the default? The Dormand Prince integrators tend to not be very good.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need to recheck but from my benchmark on NLSE-like equations, it seems to perform the best. What others methods would you suggest ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I redid my benchmark on NLSE-like equation with 2048 points. Here are the results:

 --- Tableau benchmark result for reltol = 1.0e-02 ---
BogakiShampine5 : 0.44 sec | nf = 29328
Dverk : 0.519 sec | nf = 34462
DormandLockyerMcCorriganPrince6 : 0.584 sec | nf = 37395
PapakostasPapaGeorgiou5 : 0.621 sec | nf = 40968
CashKarp : 0.666 sec | nf = 44853
SharpVerner6 : 0.715 sec | nf = 48073
SharpSmart5 : 0.726 sec | nf = 48333
Verner6 : 0.761 sec | nf = 45852
TsitourasPapakostas6 : 0.833 sec | nf = 50918
RKF4 : 0.855 sec | nf = 57412
RKF5 : 0.855 sec | nf = 51392
DormandPrince6 : 0.862 sec | nf = 56120
Papakostas6 : 0.877 sec | nf = 60157
Tsitouras5 : 1.118 sec | nf = 69153
VernerEfficient6 : 1.216 sec | nf = 82045
Verner9162 : 1.307 sec | nf = 91051
VernerRobust6 : 1.384 sec | nf = 89436
ClassicVerner6 : 1.471 sec | nf = 92704
BogakiShampine3 : 1.724 sec | nf = 113520
 --- Tableau benchmark result for reltol = 1.0e-04 ---
BogakiShampine5 : 0.757 sec | nf = 49558
CashKarp : 0.799 sec | nf = 52757
Verner6 : 1.013 sec | nf = 63260
Dverk : 1.018 sec | nf = 63362
PapakostasPapaGeorgiou5 : 1.058 sec | nf = 64503
SharpVerner6 : 1.076 sec | nf = 72735
RKF5 : 1.133 sec | nf = 75195
DormandPrince6 : 1.17 sec | nf = 77064
Papakostas6 : 1.217 sec | nf = 77561
TsitourasPapakostas6 : 1.276 sec | nf = 83796
DormandLockyerMcCorriganPrince6 : 1.309 sec | nf = 88410
SharpSmart5 : 1.41 sec | nf = 83643
RKF4 : 1.515 sec | nf = 92612
VernerEfficient6 : 1.581 sec | nf = 108132
ClassicVerner6 : 1.731 sec | nf = 113597
VernerRobust6 : 1.769 sec | nf = 121261
Verner9162 : 1.916 sec | nf = 124833
Tsitouras5 : 2.059 sec | nf = 132078
BogakiShampine3 : 2.699 sec | nf = 177924
 --- Tableau benchmark result for reltol = 1.0e-06 ---
Dverk : 0.852 sec | nf = 53451
CashKarp : 0.932 sec | nf = 57216
DormandLockyerMcCorriganPrince6 : 0.967 sec | nf = 59264
RKF5 : 1.001 sec | nf = 66355
Verner6 : 1.04 sec | nf = 69278
SharpVerner6 : 1.042 sec | nf = 65439
BogakiShampine5 : 1.055 sec | nf = 66031
PapakostasPapaGeorgiou5 : 1.201 sec | nf = 79173
TsitourasPapakostas6 : 1.308 sec | nf = 88556
Papakostas6 : 1.312 sec | nf = 84040
DormandPrince6 : 1.34 sec | nf = 84017
Tsitouras5 : 1.344 sec | nf = 90348
SharpSmart5 : 1.396 sec | nf = 90768
RKF4 : 1.646 sec | nf = 110575
VernerEfficient6 : 1.725 sec | nf = 115599
VernerRobust6 : 1.768 sec | nf = 124605
ClassicVerner6 : 1.781 sec | nf = 119632
Verner9162 : 1.852 sec | nf = 128101
BogakiShampine3 : 4.5 sec | nf = 283458
 --- Tableau benchmark result for reltol = 1.0e-08 ---
Dverk : 0.842 sec | nf = 54250
CashKarp : 0.883 sec | nf = 57606
DormandLockyerMcCorriganPrince6 : 0.954 sec | nf = 60385
Verner6 : 1.045 sec | nf = 70162
BogakiShampine5 : 1.06 sec | nf = 65742
SharpVerner6 : 1.082 sec | nf = 66161
RKF5 : 1.089 sec | nf = 68227
PapakostasPapaGeorgiou5 : 1.216 sec | nf = 81378
Papakostas6 : 1.271 sec | nf = 84477
TsitourasPapakostas6 : 1.314 sec | nf = 88981
Tsitouras5 : 1.343 sec | nf = 91473
DormandPrince6 : 1.367 sec | nf = 84289
SharpSmart5 : 1.4 sec | nf = 92538
RKF4 : 1.707 sec | nf = 114755
VernerEfficient6 : 1.742 sec | nf = 115960
ClassicVerner6 : 1.774 sec | nf = 119938
VernerRobust6 : 1.786 sec | nf = 124662
Verner9162 : 1.86 sec | nf = 128272
BogakiShampine3 : 5.204 sec | nf = 331950

From this, I think the default tableau should be either Dverk, CashKarp or BogakiShampine5 . What do you think ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the tableau methods do not have the same performance and that isn't showing accuracy, just tolerance.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

Comparison with lower order method. The slopes seem all correct. The last plot has possibly a too long integration time compared to Lyapunov time. The only thing strange is that the order 4 and 5 method seems to be have the same slope. But from this, I would suggest having either CashKarp (for medium accuracy) or Verner7 (for high accuracy) as the default tableau.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's very odd for Cash Karp to be good, I wonder if it has some odd super convergence on this problem 😅

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's entirely possible that it is a specific of this problem. Also, the error control is made on the transformed equation so the change of coordinate can increase (or decrease) the error. So you would suggest to set Verner6 as default ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that would be a generally good choice.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verner6 is now the default tableau.

Comment on lines +72 to +86
# fails as calling a MatrixOperator on a StaticVector change its type to Vector, causing a type instability

# @testset "Out-of-place Diagonal 1x1 Operator SVector Adaptative" begin
# test((μ) -> DiagonalOperator([μ]), u0 -> SVector(u0), false)
# end

# @testset "Out-of-place Matrix 1x1 Operator SVector Adaptative" begin
# test((μ) -> MatrixOperator([μ;;]), u0 -> SVector(u0), false)
# end

# # Fails for a strange reason as calling ldiv!(a, B, c) on a MatrixOperator dispatch toward an inexisting method

# @testset "In-Place MatrixOperator Vector Float Adaptative Ldiv" begin
# test(μ -> MatrixOperator([μ;;]), u0 -> [u0], true; use_ldiv=true)
# end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Set as @test_broken

@safetestset "Type Safety Tests" include("type_test.jl")
@safetestset "Cache Test" include("cache_recycling_test.jl")
@safetestset "Fourier Semilinear PDE Tests" include("semilinear_pde_test_cpu.jl")
@safetestset "CUDA Test" include("semilinear_pde_test_cuda.jl")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to move to the CUDA queue

Copy link
Author

@Azercoco Azercoco Jun 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This mean moving the test to OrdinaryDiffEq/test/gpu ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes

Comment on lines +49 to +54
solve(ode_prob_1, rkip, t1)
solve(ode_prob_2, rkip, t2)
````

will reuse the precomputed exponential cached during the first `solve` call.
This can be useful for solving several times successively problems with a common `A`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

t1 and t2 aren't defined here. And this is interface breaking: it should just use init and reinit! / solve! and it'll do this without the extra work anyways.

Comment on lines +24 to +27
This solver is only implemented for semilinear problem: `SplitODEProblem` when the first function `f1` is a `AbstractSciMLOperator` A implementing:

```julia
LinearAlgebra.exp(A, t) # = exp(A*t)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should instead be using ExponentialUtilities.jl algorithm choice for exponential!

Copy link
Author

@Azercoco Azercoco Jun 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As the implementation of the exponential is very operator dependent, are you sure that is should not use the AbstractSciMLOperator interface instead ?

cf : https://github.com/SciML/SciMLOperators.jl/blob/7ba386430a229776b41f481ff352eacd7c9f09d4/src/interface.jl#L382C1-L382C60

I checked the code of ExponetialUtilities and it seems to be useful when the exponential matrix output is dense. But in that case, caching the matrix as made here does not make a lot of sense and one would be better to used an ETD method with Krylov based expmv.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As the implementation of the exponential is very operator dependent, are you sure that is should not use the AbstractSciMLOperator interface instead ?

ExponentialUtilities.jl will specialize on claimed properties like symmetric.

I checked the code of ExponetialUtilities and it seems to be useful when the exponential matrix output is dense. But in that case, caching the matrix as made here does not make a lot of sense and one would be better to used an ETD method with Krylov based expmv.

You mean sparse? expv is for the sparse case. But exponential! is for the dense case, and it will be faster for standard dense matrices.

Azercoco and others added 2 commits June 18, 2025 11:14
Co-authored-by: Christopher Rackauckas <[email protected]>
Co-authored-by: Christopher Rackauckas <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants