Choosing an Algorithm
CuBIE ships several integration algorithm families. This page helps you
pick the right one. Pass the algorithm name as method= to
solve_ivp() or algorithm= to Solver;
names are case-insensitive.
Decision Guide
Problem type |
Recommended family |
Notes |
|---|---|---|
Non-stiff |
ERK |
Fast per step. |
Mildly stiff |
DIRK or Rosenbrock-W |
DIRK is robust but slower to compile and run; Rosenbrock-W methods are fast. |
Very stiff |
FIRK |
Use FIRK algorithms like |
The bare family names erk, dirk, firk, and rosenbrock
are also accepted and select each family’s default tableau
(tsit5, l_stable_dirk_3, firk_gauss_legendre_2,
and ros3p respectively).
Adaptive or fixed?
“Adaptive: Yes” in the tables below means that cubie can estimate the
error of each step of the method, so you can use it with an adaptive
step-size controller. An order of p(q) means the method is of
order p and cubie estimates its error with an order q method.
Cubie always runs a method without an error estimate at a fixed step:
if you pair one with an adaptive controller, cubie warns with a
UserWarning and uses the fixed-step controller instead.
Available Algorithms
Explicit Runge–Kutta (ERK)
Name |
Order |
Adaptive |
Notes |
|---|---|---|---|
|
2 |
No |
Heun’s method. |
|
3 |
No |
Ralston’s third-order method. |
|
3(2) |
Yes |
Low-order, cheap. |
|
4 |
No |
The classical Runge–Kutta method. |
|
5(4) |
Yes |
Fehlberg’s method. |
|
5(4) |
Yes |
Cash–Karp coefficients; defaults to Gustafsson control. |
|
5(4) |
Yes |
Industry standard. |
|
5(4) |
Yes |
Tsitouras 5(4); often slightly more efficient than Dormand–Prince. The default algorithm and the ERK family default. |
|
7(6) |
Yes |
Verner’s high-order method; defaults to Gustafsson control. |
|
8(5,3) |
Yes |
High order for smooth problems; defaults to Gustafsson control. |
Diagonally Implicit Runge–Kutta (DIRK)
Name |
Order |
Adaptive |
Notes |
|---|---|---|---|
|
2 |
No |
Symmetric, energy-preserving. |
|
2 |
No |
Trapezoidal rule. |
|
2 |
No |
L-stable SDIRK; has no embedded error estimate. |
|
3 |
No |
Default DIRK tableau; L-stable, stiffly accurate, 3 stages. |
|
3(2) |
Yes |
A-L stable ESDIRK, 4 stages. |
|
5(4) |
Yes |
A-L stable ESDIRK, 7 stages; defaults to exact Newton. |
|
4(3) |
Yes |
L-stable, 5 stages; defaults to exact Newton. |
|
2(3) |
Yes |
ELDIRK: implicit Euler and two explicit stages. |
|
2(3) |
Yes |
ELDIRK: trapezoidal rule and one explicit stage. |
|
2(3) |
Yes |
ELDIRK: |
Fully Implicit Runge–Kutta (FIRK)
Name |
Order |
Adaptive |
Notes |
|---|---|---|---|
|
4 |
No |
2-stage Gauss–Legendre; default FIRK. |
|
8(2) |
Yes |
4-stage Gauss–Legendre. Cubie controls the step conservatively, because it estimates the error with a second-order method. |
|
3(1) |
Yes |
2-stage Radau IIA; the cheapest of the family. |
|
5(3) |
Yes |
3-stage Radau IIA; excellent for stiff problems. Cubie smooths
its error estimate by default, which makes the estimate third
order; with |
|
9(5) |
Yes |
5-stage Radau IIA; for tight tolerances, five coupled stages
per step. Defaults to BiCGSTAB with exact Newton. Cubie smooths
its error estimate by default, which makes the estimate fifth
order; with |
Rosenbrock-W
Name |
Order |
Adaptive |
Notes |
|---|---|---|---|
|
3(2) |
Yes |
Lang and Verwer (2001), 3 stages. The default Rosenbrock-W tableau. |
|
3(2) |
Yes |
Steinebach (2024), 5 stages. |
|
2(3) |
Yes |
Shampine and Reichelt (1997), 3 stages; the method of MATLAB’s |
|
3(2) |
Yes |
Shampine and Reichelt (1997), 3 stages. |
|
2(1) |
Yes |
Verwer et al. (1999), 2 stages. |
|
2(1) |
Yes |
Rang (2014), 3 stages. |
|
2(1) |
Yes |
Rang (2014), 3 stages. |
|
3(2) |
Yes |
Hairer and Wanner (1996), 3 stages. |
|
3(2) |
Yes |
Rang (2014), 3 stages. |
|
3(2) |
Yes |
Rang (2014), 3 stages. |
|
3(2) |
Yes |
Rang and Angermann (2005), 4 stages. |
|
3(2) |
Yes |
Rang and Angermann (2005), 4 stages. |
|
3(2) |
Yes |
Rang and Angermann (2005), 4 stages. |
|
4(3) |
Yes |
Rang and Angermann (2005), 4 stages. |
|
3(2) |
Yes |
Rang (2015), 4 stages. |
|
3(2) |
Yes |
Rang (2014), 4 stages. |
|
3(2) |
Yes |
Rang (2014), 4 stages. |
|
4(3) |
Yes |
Tranquilli and Sandu (2014), 4 stages. |
|
4(3) |
Yes |
Shampine (1982), 4 stages. |
|
4(3) |
Yes |
van Veldhuizen (1984), 4 stages. |
|
4(3) |
Yes |
van Veldhuizen (1984), 4 stages. |
|
4(3) |
Yes |
Kaps and Rentrop (1979), 4 stages. |
|
4(3) |
Yes |
Kaps and Rentrop (1979), 4 stages. |
|
4(3) |
Yes |
Hairer and Wanner (1996), 4 stages. |
|
4 |
No |
6 stages. |
|
3(2) |
Yes |
Sandu et al. (1997), 4 stages. |
|
3(2) |
Yes |
Yu et al. (2024), 4 stages. |
|
2(3) |
Yes |
Steinebach (2024), 5 stages. |
|
4(3) |
Yes |
Hairer and Wanner (1996), 6 stages. |
|
4(3) |
Yes |
Hairer and Wanner (1996), 6 stages. |
|
4(3) |
Yes |
Steinebach (1995), 6 stages. |
|
4(3) |
Yes |
Steinebach (2020), 6 stages. |
|
4(3) |
Yes |
Steinebach, 9 stages. |
|
5(4) |
Yes |
Di Marzo (1993), 8 stages. |
|
5(4) |
Yes |
Steinebach (2023), 8 stages. |
|
5(4) |
Yes |
Steinebach (2024), 8 stages. |
|
6(5) |
Yes |
Steinebach (2025), 16 stages. |
Simple methods
Name |
Order |
Adaptive |
Notes |
|---|---|---|---|
|
1 |
No |
Forward Euler; explicit. |
|
1 |
No |
Backward Euler; implicit, L-stable. |
|
1 |
No |
Predictor-corrector backward Euler. |
|
2 |
Yes |
Implicit trapezoidal rule; a second backward-Euler solve provides the embedded error estimate. |
Choosing a Controller
Adaptive algorithms use an error controller to adjust the step size.
Select one by name with the step_controller keyword argument:
"fixed", "i", "pi", "pid", or "gustafsson".
- fixed
Constant step size; no error control. Used automatically for methods without an error estimate.
- i, pi, pid
The
i,pi, andpidcontrollers are all the same PID controller, but theiandpidevice functions compile to more efficient code when you don’t need the additional gain terms. After every step they compare the estimated error with the tolerance (atol + rtol * max(|this_state|, |last_state|)) and propose a next-step size to bring the ratio of error/tolerance to 1. Each gain term acts on the current error and a subset of previous errors:integral_gainmultiplies by the error/tolerance ratio of the current step. It sets how much this error adds to the running correction.proportional_gainmultiplies by how much the ratio changed since the previous step. It sets how much the running correction is adjusted by the change in error.derivative_gainmultiplies by how much the change in the ratio changed over two steps. It acts against large changes in the rate of change of error, damping the controller.
Passing gains without any
step_controllerselected will select the fastest of thei,pi,pidcontrollers that can provide your gains, or you can provide a string to select a common literature controller using thefilter_coefficientsargument.- gustafsson
Predictive controller that accounts for the previous step’s error ratio. Widely used with implicit methods; useful when step rejections are frequent.
Each algorithm family picks a default controller (i for ERK,
pi for DIRK, gustafsson for FIRK and Rosenbrock, fixed
without an error estimate); some tableaus override it. To choose a
different controller, pass its name:
solver = qb.Solver(
LV,
algorithm="dormand-prince-54",
step_controller="gustafsson",
)
Automatic calibration
The fastest algorithm order, linear solver type, preconditioner, and Newton variant depend on the system. Given a representative batch, the solver can measure them directly:
solver = qb.Solver(LV, algorithm="ros3p", atol=1e-6, rtol=1e-6)
report = solver.calibrate(
{"x": x0_values},
{"alpha": alpha_values},
duration=10.0,
)
print(report.summary())
Solver.calibrate
races different solver configurations on your problem: it compares a
few orders of each algorithm family and, for the implicit families,
the preconditioner, linear-solver, Newton-variant, smoothed-error,
and dense-predictor settings. Every candidate is timed on a few
full-length solves and reported with its solve times and failed-run
count. Cubie resizes the batch it times so that a solve takes about
20 ms where it can; pass auto_size=False to time your exact batch
instead. Cubie ranks candidates whose trajectories succeed (runs that
don’t end in a step-size or convergence error) at a rate at least 95%
of the best candidate’s rate by time. Candidates below that threshold
are ranked afterward, also by time, with their failure rates shown.
By default cubie applies the winning configuration to the solver in
place; pass apply=False to get the results of the race without
modifying the solver.
calibrate compiles a large number of kernels, so allow half an
hour for a bigger system.
With the algorithm settled, Solver.optimize tries a few different
configurations of where buffers sit in memory, which loops get
unrolled, and how many threads run at once on the GPU to find the
fastest configuration for your system:
report = solver.optimize(
{"x": x0_values},
{"alpha": alpha_values},
duration=10.0,
)
print(report.summary())
Settings you gave explicitly, or ones that were set by an earlier
optimize, stay fixed unless force=True. Like calibrate(),
the fastest configuration is applied in place unless apply=False,
and batches are autosized for a 20ms runtime unless auto_size=False.