Skip to content

Commit 1c597f1

Browse files
committed
Add bench script
1 parent bf87624 commit 1c597f1

File tree

3 files changed

+54
-2
lines changed

3 files changed

+54
-2
lines changed

bench/Project.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[deps]
2+
DiffEqDevTools = "f3b72e0c-5b89-59e1-b016-84e28bfd966d"
3+
OrdinaryDiffEq = "1dea7af3-3e70-54e6-95c3-0bf5283fa5ed"
4+
OrdinaryDiffEqTaylorSeries = "9c7f1690-dd92-42a3-8318-297ee24d8d39"
5+
ParameterizedFunctions = "65888b18-ceab-5e60-b2b9-181511a3b968"
6+
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
7+
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
8+
TaylorIntegration = "92b13dbe-c966-51a2-8445-caca9f8a7d42"

bench/adaptive_order.jl

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
using OrdinaryDiffEq, ParameterizedFunctions, DiffEqDevTools, StaticArrays,
2+
OrdinaryDiffEqTaylorSeries
3+
using Plots, BenchmarkTools
4+
gr();
5+
6+
abstols = 1.0 ./ 10.0 .^ (6:15)
7+
reltols = 1.0 ./ 10.0 .^ (3:12);
8+
9+
function lotka(du, u, p, t)
10+
x = u[1]
11+
y = u[2]
12+
du[1] = p[1] * x - p[2] * x * y
13+
du[2] = -p[3] * y + p[4] * x * y
14+
end
15+
prob = ODEProblem{true, SciMLBase.FullSpecialize}(
16+
lotka, [1.0, 1.0], (0.0, 10.0), [1.5, 1.0, 3.0, 1.0])
17+
sol = solve(prob, Vern7(), abstol = 1 / 10^14, reltol = 1 / 10^14)
18+
19+
# Profile
20+
cache1 = init(prob, ExplicitTaylorAdaptiveOrder(min_order = Val(6), max_order = Val(12)))
21+
OrdinaryDiffEqTaylorSeries.perform_step!(cache1, cache1.cache, false)
22+
@profview for _ in 1:10000000
23+
OrdinaryDiffEqTaylorSeries.perform_step!(cache1, cache1.cache, false)
24+
end
25+
@btime OrdinaryDiffEqTaylorSeries.perform_step!(cache1, cache1.cache, false)
26+
27+
# Make work-precision plot
28+
setups = [Dict(:alg => DP5())
29+
Dict(:alg => Tsit5())
30+
Dict(:alg => Vern6())
31+
Dict(:alg => Vern8())
32+
Dict(:alg => ExplicitTaylorAdaptiveOrder(min_order = Val(8), max_order = Val(12)))];
33+
names = ["DP5", "Tsit5", "Vern6", "Vern8", "Taylor"]
34+
for order in 6:2:12
35+
push!(names, "Taylor $(order)")
36+
push!(setups, Dict(:alg => ExplicitTaylor(order = Val(order + 1))))
37+
end
38+
wp = WorkPrecisionSet([prob], abstols, reltols, setups; names = names, appxsol = [sol],
39+
save_everystep = false, numruns = 100, maxiters = 10000)
40+
plot(wp)

lib/OrdinaryDiffEqTaylorSeries/src/TaylorSeries_perform_step.jl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ end
110110

111111
min_order_value = get_value(min_order)
112112
max_order_value = get_value(max_order)
113+
# println("current order: ", current_order[])
113114
jet_index = current_order[] - min_order_value + 1
114115
# compute one additional order for adaptive order
115116
jet = jets[jet_index + 1]
@@ -122,10 +123,12 @@ end
122123
min_work = Inf
123124
start_order = max(min_order_value, current_order[] - 1)
124125
end_order = min(max_order_value - 1, current_order[] + 1)
126+
dtn = dt^start_order
125127
for i in start_order:end_order
126128
A = i * i
127-
@.. broadcast=false thread=thread utilde=TaylorDiff.get_coefficient(
128-
utaylor, i) * dt^i
129+
for ix in eachindex(utaylor)
130+
utilde[ix] = TaylorDiff.partials(utaylor[ix])[i] * dtn
131+
end
129132
calculate_residuals!(atmp, utilde, uprev, u, integrator.opts.abstol,
130133
integrator.opts.reltol, integrator.opts.internalnorm, t)
131134
EEst = integrator.opts.internalnorm(atmp, t)
@@ -147,6 +150,7 @@ end
147150
min_work = work
148151
integrator.EEst = EEst
149152
end
153+
dtn *= dt
150154
end
151155
end
152156
return nothing

0 commit comments

Comments
 (0)