Skip to content
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

[solver] Proposal: add classic tableau option for dopri5 #158

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions tests/DETEST/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ def __call__(self, t, y):
def main():

sol = dict()
for method in ['dopri5', 'adams']:
for tol in [1e-3, 1e-6, 1e-9]:
for method in ['dopri5', 'classic_dopri5']:
for tol in [1e-3, 1e-4, 1e-5, 1e-6]:
print('======= {} | tol={:e} ======='.format(method, tol))
nfes = []
times = []
Expand Down
54 changes: 39 additions & 15 deletions torchdiffeq/_impl/dopri5.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,39 @@
import torch
from .rk_common import _ButcherTableau, RKAdaptiveStepsizeODESolver

alpha=torch.tensor([1 / 5, 3 / 10, 4 / 5, 8 / 9, 1., 1.], dtype=torch.float64)
beta=[
torch.tensor([1 / 5], dtype=torch.float64),
torch.tensor([3 / 40, 9 / 40], dtype=torch.float64),
torch.tensor([44 / 45, -56 / 15, 32 / 9], dtype=torch.float64),
torch.tensor([19372 / 6561, -25360 / 2187, 64448 / 6561, -212 / 729], dtype=torch.float64),
torch.tensor([9017 / 3168, -355 / 33, 46732 / 5247, 49 / 176, -5103 / 18656], dtype=torch.float64),
torch.tensor([35 / 384, 0, 500 / 1113, 125 / 192, -2187 / 6784, 11 / 84], dtype=torch.float64),
]
c_sol=torch.tensor([35 / 384, 0, 500 / 1113, 125 / 192, -2187 / 6784, 11 / 84, 0], dtype=torch.float64)


_CLASSIC_DORMAND_PRINCE_SHAMPINE_TABLEAU = _ButcherTableau(
alpha=alpha, beta=beta, c_sol=c_sol,
c_error=torch.tensor([
35 / 384 - 5179 / 57600,
0,
500 / 1113 - 7571 / 16695,
125 / 192 - 393 / 640,
-2187 / 6784 - -92097 / 339200,
11 / 84 - 187 / 2100,
-1 / 40,
], dtype=torch.float64),
)

DPS_C_MID = torch.tensor([
6025192743 / 30085553152 / 2, 0, 51252292925 / 65400821598 / 2, -2691868925 / 45128329728 / 2,
187940372067 / 1594534317056 / 2, -1776094331 / 19743644256 / 2, 11237099 / 235043384 / 2
], dtype=torch.float64)


_DORMAND_PRINCE_SHAMPINE_TABLEAU = _ButcherTableau(
alpha=torch.tensor([1 / 5, 3 / 10, 4 / 5, 8 / 9, 1., 1.], dtype=torch.float64),
beta=[
torch.tensor([1 / 5], dtype=torch.float64),
torch.tensor([3 / 40, 9 / 40], dtype=torch.float64),
torch.tensor([44 / 45, -56 / 15, 32 / 9], dtype=torch.float64),
torch.tensor([19372 / 6561, -25360 / 2187, 64448 / 6561, -212 / 729], dtype=torch.float64),
torch.tensor([9017 / 3168, -355 / 33, 46732 / 5247, 49 / 176, -5103 / 18656], dtype=torch.float64),
torch.tensor([35 / 384, 0, 500 / 1113, 125 / 192, -2187 / 6784, 11 / 84], dtype=torch.float64),
],
c_sol=torch.tensor([35 / 384, 0, 500 / 1113, 125 / 192, -2187 / 6784, 11 / 84, 0], dtype=torch.float64),
alpha=alpha, beta=beta, c_sol=c_sol,
c_error=torch.tensor([
35 / 384 - 1951 / 21600,
0,
Expand All @@ -24,13 +45,16 @@
], dtype=torch.float64),
)

DPS_C_MID = torch.tensor([
6025192743 / 30085553152 / 2, 0, 51252292925 / 65400821598 / 2, -2691868925 / 45128329728 / 2,
187940372067 / 1594534317056 / 2, -1776094331 / 19743644256 / 2, 11237099 / 235043384 / 2
], dtype=torch.float64)


class Dopri5Solver(RKAdaptiveStepsizeODESolver):
order = 5
tableau = _DORMAND_PRINCE_SHAMPINE_TABLEAU
mid = DPS_C_MID


class ClassicDopri5Solver(RKAdaptiveStepsizeODESolver):
order = 5
tableau = _CLASSIC_DORMAND_PRINCE_SHAMPINE_TABLEAU
mid = DPS_C_MID


3 changes: 2 additions & 1 deletion torchdiffeq/_impl/odeint.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import torch
from torch.autograd.functional import vjp
from .dopri5 import Dopri5Solver
from .dopri5 import ClassicDopri5Solver, Dopri5Solver
from .bosh3 import Bosh3Solver
from .adaptive_heun import AdaptiveHeunSolver
from .fehlberg2 import Fehlberg2
Expand All @@ -13,6 +13,7 @@
SOLVERS = {
'dopri8': Dopri8Solver,
'dopri5': Dopri5Solver,
'classic_dopri5': ClassicDopri5Solver,
'bosh3': Bosh3Solver,
'fehlberg2': Fehlberg2,
'adaptive_heun': AdaptiveHeunSolver,
Expand Down