Skip to content

Commit 6ac8f2b

Browse files
update benchmarks
1 parent ae26c3b commit 6ac8f2b

File tree

1 file changed

+134
-10
lines changed

1 file changed

+134
-10
lines changed

README.md

Lines changed: 134 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -109,31 +109,155 @@ julia> @time MATLABDiffEq.eval_string("[t,u] = $(algstr)(f,tspan,u0,options);")
109109

110110
## Benchmark
111111

112-
MATLABDiffEq.jl will be included into [DiffEqBenchmarks.jl](https://github.com/JuliaDiffEq/DiffEqBenchmarks.jl). However, the benchmarks are not encouraging to MATLAB at all. Instead, they show that the cost of evaluating functions in MATLAB are too large (note that the functions are re-defined in MATLAB, meaning that they are true MATLAB functions and not interop functions).
113-
114-
Running benchmarks at various tolerance using the same Lotka-Volterra problem from before, we get the following:
112+
The following benchmarks demonstrate a **100x performance advantage for the
113+
pure-Julia methods over the MATLAB ODE solvers** across a range of stiff and
114+
non-stiff ODEs. These were ran with Julia 1.2 and MATLAB 2019B after verifying
115+
negligible overhead on interop.
115116

116117
```julia
117-
using OrdinaryDiffEq, ODEInterfaceDiffEq, Plots, ODE
118+
using ParameterizedFunctions, MATLABDiffEq, OrdinaryDiffEq, ODEInterface,
119+
ODEInterfaceDiffEq, Plots, Sundials
118120
using DiffEqDevTools
119-
abstols = 1./10.^(6:13)
120-
reltols = 1./10.^(3:10)
121+
using LinearAlgebra
122+
123+
## Non-Stiff Problem 1: Lotka-Volterra
124+
125+
f = @ode_def_bare LotkaVolterra begin
126+
dx = a*x - b*x*y
127+
dy = -c*y + d*x*y
128+
end a b c d
129+
p = [1.5,1,3,1]
130+
tspan = (0.0,10.0)
131+
u0 = [1.0,1.0]
132+
prob = ODEProblem(f,u0,tspan,p)
133+
sol = solve(prob,Vern7(),abstol=1/10^14,reltol=1/10^14)
134+
test_sol = TestSolution(sol)
135+
136+
setups = [Dict(:alg=>DP5())
137+
Dict(:alg=>dopri5())
138+
Dict(:alg=>BS5())
139+
Dict(:alg=>Tsit5())
140+
Dict(:alg=>Vern6())
141+
Dict(:alg=>Vern7())
142+
Dict(:alg=>MATLABDiffEq.ode45())
143+
Dict(:alg=>MATLABDiffEq.ode113())
144+
Dict(:alg=>CVODE_Adams())
145+
]
146+
abstols = 1.0 ./ 10.0 .^ (6:13)
147+
reltols = 1.0 ./ 10.0 .^ (3:10)
148+
wp = WorkPrecisionSet(prob,abstols,reltols,setups;appxsol=test_sol,dense=false,save_everystep=false,numruns=100,maxiters=10000000,ttimeseries_errors=false,verbose=false)
149+
plot(wp,title="Non-stiff 1: Lotka-Volterra")
150+
savefig("benchmark1.png")
151+
```
152+
153+
![benchmark1](https://user-images.githubusercontent.com/1814174/69478405-f9dac480-0dbf-11ea-8f8e-5572b86d2a97.png)
154+
155+
```julia
156+
## Non-Stiff Problem 2: Rigid Body
157+
158+
f = @ode_def_bare RigidBodyBench begin
159+
dy1 = -2*y2*y3
160+
dy2 = 1.25*y1*y3
161+
dy3 = -0.5*y1*y2 + 0.25*sin(t)^2
162+
end
163+
prob = ODEProblem(f,[1.0;0.0;0.9],(0.0,100.0))
121164
sol = solve(prob,Vern7(),abstol=1/10^14,reltol=1/10^14)
122165
test_sol = TestSolution(sol)
123-
plotly()
166+
124167
setups = [Dict(:alg=>DP5())
125168
Dict(:alg=>dopri5())
126169
Dict(:alg=>BS5())
127170
Dict(:alg=>Tsit5())
128171
Dict(:alg=>Vern6())
129172
Dict(:alg=>Vern7())
130173
Dict(:alg=>MATLABDiffEq.ode45())
174+
Dict(:alg=>MATLABDiffEq.ode113())
175+
Dict(:alg=>CVODE_Adams())
131176
]
132-
wp = WorkPrecisionSet(prob,abstols,reltols,setups;appxsol=test_sol,dense=false,save_everystep=false,numruns=1000,maxiters=10000000,ttimeseries_errors=false,verbose=false)
133-
plot(wp)
177+
abstols = 1.0 ./ 10.0 .^ (6:13)
178+
reltols = 1.0 ./ 10.0 .^ (3:10)
179+
wp = WorkPrecisionSet(prob,abstols,reltols,setups;appxsol=test_sol,dense=false,save_everystep=false,numruns=100,maxiters=10000000,ttimeseries_errors=false,verbose=false)
180+
plot(wp,title="Non-stiff 2: Rigid-Body")
181+
savefig("benchmark2.png")
182+
```
183+
184+
![benchmark2](https://user-images.githubusercontent.com/1814174/69478406-fe9f7880-0dbf-11ea-8f15-a0a0f3e8717f.png)
185+
186+
187+
```julia
188+
## Stiff Problem 1: ROBER
189+
190+
rober = @ode_def begin
191+
dy₁ = -k₁*y₁+k₃*y₂*y₃
192+
dy₂ = k₁*y₁-k₂*y₂^2-k₃*y₂*y₃
193+
dy₃ = k₂*y₂^2
194+
end k₁ k₂ k₃
195+
prob = ODEProblem(rober,[1.0,0.0,0.0],(0.0,1e5),[0.04,3e7,1e4])
196+
sol = solve(prob,CVODE_BDF(),abstol=1/10^14,reltol=1/10^14)
197+
test_sol = TestSolution(sol)
198+
199+
abstols = 1.0 ./ 10.0 .^ (5:8)
200+
reltols = 1.0 ./ 10.0 .^ (1:4);
201+
setups = [Dict(:alg=>Rosenbrock23()),
202+
Dict(:alg=>TRBDF2()),
203+
Dict(:alg=>rodas()),
204+
Dict(:alg=>radau()),
205+
Dict(:alg=>RadauIIA5()),
206+
Dict(:alg=>MATLABDiffEq.ode23s()),
207+
Dict(:alg=>MATLABDiffEq.ode15s())
208+
]
209+
210+
wp = WorkPrecisionSet(prob,abstols,reltols,setups;
211+
save_everystep=false,appxsol=test_sol,maxiters=Int(1e5),numruns=100)
212+
plot(wp,title="Stiff 1: ROBER")
213+
savefig("benchmark3.png")
134214
```
135215

136-
![Benchmark](assets/matlab_bench.png)
216+
![benchmark3](https://user-images.githubusercontent.com/1814174/69478407-ffd0a580-0dbf-11ea-9311-909bd3938b42.png)
217+
218+
219+
```julia
220+
## Stiff Problem 2: HIRES
221+
222+
f = @ode_def Hires begin
223+
dy1 = -1.71*y1 + 0.43*y2 + 8.32*y3 + 0.0007
224+
dy2 = 1.71*y1 - 8.75*y2
225+
dy3 = -10.03*y3 + 0.43*y4 + 0.035*y5
226+
dy4 = 8.32*y2 + 1.71*y3 - 1.12*y4
227+
dy5 = -1.745*y5 + 0.43*y6 + 0.43*y7
228+
dy6 = -280.0*y6*y8 + 0.69*y4 + 1.71*y5 -
229+
0.43*y6 + 0.69*y7
230+
dy7 = 280.0*y6*y8 - 1.81*y7
231+
dy8 = -280.0*y6*y8 + 1.81*y7
232+
end
233+
234+
u0 = zeros(8)
235+
u0[1] = 1
236+
u0[8] = 0.0057
237+
prob = ODEProblem(f,u0,(0.0,321.8122))
238+
239+
sol = solve(prob,Rodas5(),abstol=1/10^14,reltol=1/10^14)
240+
test_sol = TestSolution(sol)
241+
242+
abstols = 1.0 ./ 10.0 .^ (5:8)
243+
reltols = 1.0 ./ 10.0 .^ (1:4);
244+
setups = [Dict(:alg=>Rosenbrock23()),
245+
Dict(:alg=>TRBDF2()),
246+
Dict(:alg=>rodas()),
247+
Dict(:alg=>radau()),
248+
Dict(:alg=>RadauIIA5()),
249+
Dict(:alg=>MATLABDiffEq.ode23s()),
250+
Dict(:alg=>MATLABDiffEq.ode15s())
251+
]
252+
253+
wp = WorkPrecisionSet(prob,abstols,reltols,setups;
254+
save_everystep=false,appxsol=test_sol,maxiters=Int(1e5),numruns=100)
255+
plot(wp,title="Stiff 2: Hires")
256+
savefig("benchmark4.png")
257+
```
258+
259+
![benchmark4](https://user-images.githubusercontent.com/1814174/69478409-019a6900-0dc0-11ea-9fce-c11a5e4de9a4.png)
260+
137261

138262
This shows that being able to run MATLAB ODE algorithms with MATLAB functions
139263
is cute, but does not really have a practical use due to MATLAB's lack of

0 commit comments

Comments
 (0)