-
Notifications
You must be signed in to change notification settings - Fork 26
Huge detriment in computational performance #72
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
Comments
Hi @oxinabox, thanks for your quick reply! I will revert to version 0.9.2 while you work it out. I will probably ask you about this issue in a while if that's okay. Thanks for your help! |
stats on my computer. v0.9.5
v0.9.2
#65 only
|
I think this never hits me in general because I create one global constant |
I migrated my MWE based in your comment about the using Parameters
using FiniteDifferences
using Dierckx: Spline1D
using DifferentialEquations
params = @with_kw((
LY = Spline1D(
[0.08, 0.1666667, 0.25, 0.5, 1.0, 2.0, 3.0, 5.0, 7.0, 10.0, 20.0, 30.0],
[
0.0242,
0.0243,
0.0243,
0.0245,
0.0236,
0.0226,
0.0223,
0.0226,
0.0237,
0.0247,
0.027,
0.0289,
],
k = 1,
bc = "nearest",
),
P1 = t -> 1 / (1 + LY(t) * t),
P2 = t -> 1 / ((1 + LY(t))^t),
P = t -> ifelse(t < 1.0, P1(t), P2(t)),
_fdm = forward_fdm(5, 1),
f = t -> _fdm(s -> -log(P(s)), t),
f′ = t -> _fdm(s -> f(s), t),
ϰ = 0.4363,
σ = 0.1491,
ϑ = t -> 1 / ϰ * f′(t) + f(t) + (σ / ϰ)^2 / 2 * (1 - exp(-2 * ϰ * t)),
))
function riccati(du, u, p, t)
@unpack (LY ,P1, P2, P, f, f′, ϰ, σ, ϑ, _fdm) = p
cattle = u[1]
snake = u[2]
locust = f(t)
lion = 1
mouse = ϰ
loris = ϑ(t)
aardvark = σ
deer = 1
coati = 0
snail = _fdm(f, t)
crocodile = 0
du[1] = (((mouse * loris - mouse * locust) - snail) * snake) / lion - ((deer + coati * locust) / 2) * ((aardvark * snake) / lion) ^ 2
du[2] = ((mouse + crocodile / lion) * snake + (coati / (2lion)) * (aardvark * snake) ^ 2) - lion
return nothing
end
let
p = params()
tspan = (0.0, 1.0)
Δt = (tspan[2] - tspan[1])
dt = 1.0 / 252.0
nodes = Int(ceil(Δt / dt) + 1)
# time meshes
t = T = [tspan[1] + (i - 1) * dt for i = 1:nodes]
prob = ODEProblem(riccati, zeros(2), (0.0, 1.0), p)
prob_func = (prob, i, repeat) -> begin
ODEProblem(prob.f, prob.u0, (T[i + 1], t[1]), prob.p)
end
odes = EnsembleProblem(prob, prob_func = prob_func)
@time sol = DifferentialEquations.solve(
odes,
Tsit5(),
trajectories = nodes - 1,
saveat = -dt
)
end with the following time results for version v0.9.5: 22.494440 seconds (27.82 M allocations: 1.664 GiB, 2.84% gc time)
17.850900 seconds (20.12 M allocations: 1.294 GiB, 2.64% gc time)
18.231992 seconds (20.12 M allocations: 1.294 GiB, 3.24% gc time)
18.729749 seconds (20.12 M allocations: 1.294 GiB, 2.74% gc time) As you suggest, it is better but it doesn't seem to solve the issue. Unless there is something I am missing. Thanks! |
Interesting, I thought it would help more than that. |
Thank you very much Lyndon!! |
Hi all!
First of all, I would like to thank you for your package, it's really nice and very helpful. Now let me explain the issue I am facing.
I am seeing a huge decrement in performance once I moved from version
v0.9.2
tov0.9.3
, and it still persists in the current versionv0.9.5
.I prepared a minimal working example for the testing, which seems not so minimal but it is 😄:
The important thing is that I have to evaluate both
f
andf′
many times in this calculation, which means that I have to callFiniteDifferences.forward_fdm
many times as well. I also tested with different algorithms, such ascentral_fdm
orbackward_fdm
and noted the same detriment in performance.Let me show you my
@time
results for each version (multiple runs for each case, the first one considers the overhead regarding compilation):v0.9.2:
v0.9.3:
v0.9.5 (current):
As you see, this reduces performance by a factor of ≈ 20. It is important to remark that all versions lead to the correct answer.
Could you please help me find a way around this issue?
Thank you very much!
Regards,
Ramiro.
The text was updated successfully, but these errors were encountered: