Skip to content

Commit 53b5ba1

Browse files
committed
Add plots
1 parent b3a1b3e commit 53b5ba1

File tree

1 file changed

+51
-7
lines changed

1 file changed

+51
-7
lines changed

examples/integration.jl

Lines changed: 51 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,20 @@ function jetcoeffs(f::ODEFunction{iip}, u0, p, t0, ::Val{P}) where {P, iip}
2929
u
3030
end
3131

32+
function jetcoeffs_inplace!(u, fu, f::ODEFunction{true}, u0, p, t0, ::Val{P}) where {P}
33+
t = TaylorScalar{P}(t0, one(t0))
34+
for index in 1:P
35+
if iip
36+
f(fu, u, p, t)
37+
else
38+
fu = f(u, p, t)
39+
end
40+
d = get_coefficient(fu, index - 1) / index
41+
u = set_coefficient(u, index, d)
42+
end
43+
u
44+
end
45+
3246
function scalar_test()
3347
P = 6
3448
prob = prob_ode_linear
@@ -116,17 +130,47 @@ function simplify_array_test()
116130
@btime $fast_oop($prob.u0, $t0)
117131
end
118132

119-
P = 6
120-
prob = prob_ode_lotkavolterra
121-
t0 = prob.tspan[1]
122-
@btime jetcoeffs($prob.f, $prob.u0, $prob.p, $t0, Val($P))
123-
fast_oop, fast_iip = build_jetcoeffs(prob.f, prob.p, Val(10), length(prob.u0));
124-
@btime $fast_oop($prob.u0, $t0)
125-
126133
@generated function evaluate_polynomial(t::TaylorScalar{T, P}, z) where {T, P}
127134
ex = :(v[$(P + 1)])
128135
for i in P:-1:1
129136
ex = :(v[$i] + z * $ex)
130137
end
131138
return :($(Expr(:meta, :inline)); v = flatten(t); $ex)
132139
end
140+
141+
prob = prob_ode_lotkavolterra
142+
t0 = prob.tspan[1]
143+
raw = Float64[]
144+
optimized = Float64[]
145+
orders = [2, 4, 6, 8, 10, 12]
146+
for P in orders
147+
raw_time = @belapsed jetcoeffs($prob.f, $prob.u0, $prob.p, $t0, Val($P))
148+
fast_oop, fast_iip = build_jetcoeffs(prob.f, prob.p, Val(P), length(prob.u0))
149+
optimized_time = @belapsed $fast_oop($prob.u0, $t0)
150+
push!(raw, raw_time)
151+
push!(optimized, optimized_time)
152+
end
153+
154+
using CairoMakie
155+
156+
colors = Makie.wong_colors()
157+
f = begin
158+
f = Figure(resolution = (700, 400))
159+
ax = Axis(f[1, 1],
160+
xlabel = "Order",
161+
ylabel = "Time for computing truncated Taylor series (s)",
162+
title = "Effect of Symbolic Simplification on Computing Truncated Taylor Series",
163+
xticks = orders,
164+
yscale = log10
165+
)
166+
167+
group = [fill(1, length(orders));
168+
fill(2, length(orders))]
169+
barplot!(ax, [orders; orders], [raw; optimized],
170+
dodge = group,
171+
color = colors[group])
172+
elements = [PolyElement(polycolor = colors[i]) for i in 1:2]
173+
Legend(f[1, 2], elements, ["Raw", "Optimized"], "Groups")
174+
f
175+
end
176+
f

0 commit comments

Comments
 (0)