Skip to content

Commit 3227b97

Browse files
committed
remove compat layer for benchmarking
1 parent f0bd1e2 commit 3227b97

File tree

4 files changed

+13
-243
lines changed

4 files changed

+13
-243
lines changed

benchmark/benchmark_compat.jl

Lines changed: 3 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,12 @@
11
#=
2-
Helper functions to create compatible states between NetworkDynamics.jl and NetworkDynamics.jl v0.8
2+
Helper functions to create compatible states between newer and older versions of NetworkDynamics.jl
3+
for cross version benchmarking.
34
=#
45

5-
if pkgversion(NetworkDynamics) < v"0.9.0"
6-
@info "Define compatibility functions"
7-
struct Network end
8-
struct SequentialExecution{P} end
9-
struct KAExecution{P} end
10-
struct PolyesterExecution{P} end
11-
struct ThreadedExecution{P} end
12-
struct KAAggregator; f; end
13-
struct SequentialAggregator; f; end
14-
struct PolyesterAggregator; f; end
15-
struct ThreadedAggregator; f; end
16-
function Network(g, v, e; execution = SequentialExecution{true}(), aggregator=SequentialAggregator(+))
17-
if execution isa PolyesterExecution{true} && aggregator isa PolyesterAggregator
18-
network_dynamics(v, e, g; parallel=true)
19-
elseif execution isa SequentialExecution{true} && aggregator isa SequentialAggregator
20-
network_dynamics(v, e, g; parallel=false)
21-
else
22-
error("execution type not supported")
23-
end
24-
end
25-
elseif pkgversion(NetworkDynamics) < v"0.9.1"
26-
isdynamic = NetworkDynamics.isdynamic
27-
else
28-
isdynamic(_) = true
29-
end
30-
31-
function _syms_old_order(nd::Network)
32-
syms = []
33-
for (i,cf) in enumerate(nd.im.vertexm)
34-
isdynamic(cf) || continue
35-
append!(syms, collect(VIndex(i, 1:dim(cf))))
36-
end
37-
for (i,cf) in enumerate(nd.im.edgem)
38-
isdynamic(cf) || continue
39-
append!(syms, collect(EIndex(i, 1:dim(cf))))
40-
end
41-
syms
42-
end
43-
function _psyms_old_order(nd::Network)
44-
syms = []
45-
for (i,cf) in enumerate(nd.im.vertexm)
46-
append!(syms, collect(VPIndex(i, 1:pdim(cf))))
47-
end
48-
for (i,cf) in enumerate(nd.im.edgem)
49-
append!(syms, collect(EPIndex(i, 1:pdim(cf))))
50-
end
51-
syms
52-
end
536
function randx0(nd::Network)
547
rng = StableRNG(1)
55-
_x0 = rand(rng, dim(nd))
56-
57-
s = NWState(nd; utype=typeof(_x0))
58-
for (i,sym) in enumerate(_syms_old_order(nd::Network))
59-
s[sym] = _x0[i]
60-
end
61-
s[:]
8+
rand(rng, dim(nd))
629
end
63-
randx0(nd::ODEFunction) = rand(StableRNG(1), length(nd.syms))
64-
function legacy_order(nd::Network, _dx)
65-
s = NWState(nd, _dx)
66-
dx = similar(_dx)
67-
for (i,sym) in enumerate(_syms_old_order(nd::Network))
68-
dx[i] = s[sym]
69-
end
70-
dx
71-
end
72-
legacy_order(nd::ODEFunction, dx) = dx
7310

7411
function randp(nd::Network)
7512
rng = StableRNG(1)
@@ -80,9 +17,3 @@ function randp(nd::Network)
8017
end
8118
p[:]
8219
end
83-
function randp(nd::ODEFunction)
84-
rng = StableRNG(1)
85-
g = nd.f.graph
86-
_p = rand(rng, nv(g) + ne(g))
87-
p = (_p[1:nv(g)], _p[nv(g)+1:end])
88-
end

benchmark/benchmark_models_v0.8.jl

Lines changed: 0 additions & 46 deletions
This file was deleted.

benchmark/benchmark_models_v0.9.jl

Lines changed: 0 additions & 109 deletions
This file was deleted.

benchmark/benchmarks.jl

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,7 @@ using CUDA: adapt
1818
using ThreadPinning
1919
pinthreads(:cores)
2020

21-
if pkgversion(NetworkDynamics) < v"0.9.0"
22-
(isinteractive() ? includet : include)("benchmark_models_v0.8.jl")
23-
elseif pkgversion(NetworkDynamics) < v"0.9.1"
24-
(isinteractive() ? includet : include)("benchmark_models_v0.9.jl")
25-
else
26-
(isinteractive() ? includet : include)("benchmark_models.jl")
27-
end
21+
(isinteractive() ? includet : include)("benchmark_models.jl")
2822

2923
@info "Benchmark with $(Threads.nthreads()) threads"
3024

@@ -116,7 +110,7 @@ for k in keys(edges)
116110
@test dx _dx
117111

118112
b = @be $nd($dx, $_x0, nothing, 0.0) seconds=SECONDS
119-
br = BenchmarkResult(b, legacy_order(nd, dx))
113+
br = BenchmarkResult(b, dx)
120114
bd["diffusion_"*k, exname, aggname, N] = br
121115

122116
if CUDA.functional() && iscudacompatible(execution) && iscudacompatible(nd.layer.aggregator)
@@ -134,7 +128,7 @@ for k in keys(edges)
134128
b = @be $nd_d($dx_d, $x0_d, nothing, 0.0) seconds=SECONDS
135129
# we store the original _dx in the benchmarks results because we know
136130
# our dx_d does not have the precision
137-
br = BenchmarkResult(b, legacy_order(nd, _dx))
131+
br = BenchmarkResult(b, _dx)
138132
bd["diffusion_"*k, exname*"_cuda32", aggname*"_cuda32", N] = br
139133

140134
to = CuArray{Float64}
@@ -146,7 +140,7 @@ for k in keys(edges)
146140
@test Vector(dx_d) _dx
147141

148142
b = @be $nd_d($dx_d, $x0_d, nothing, 0.0) seconds=SECONDS
149-
br = BenchmarkResult(b, legacy_order(nd, Vector(dx_d)))
143+
br = BenchmarkResult(b, Vector(dx_d))
150144
bd["diffusion_"*k, exname*"_cuda64", aggname*"_cuda64", N] = br
151145
end
152146
end
@@ -213,7 +207,7 @@ for f in [homogeneous, heterogeneous]
213207
@test dx _dx
214208

215209
b = @be $nd($dx, $_x0, $p, 0.0) seconds=SECONDS
216-
br = BenchmarkResult(b, legacy_order(nd, dx))
210+
br = BenchmarkResult(b, dx)
217211
bd["kuramoto_"*name, exname, aggname, N] = br
218212

219213
if CUDA.functional() && iscudacompatible(execution) && iscudacompatible(nd.layer.aggregator)
@@ -232,7 +226,7 @@ for f in [homogeneous, heterogeneous]
232226
b = @be $nd_d($dx_d, $x0_d, $p_d, 0.0) seconds=SECONDS
233227
# we store the original _dx in the benchmarks results because we know
234228
# our dx_d does not have the precision
235-
br = BenchmarkResult(b, legacy_order(nd, _dx))
229+
br = BenchmarkResult(b, _dx)
236230
bd["kuramoto_"*name, exname*"_cuda32", aggname*"_cuda32", N] = br
237231

238232
to = CuArray{Float64}
@@ -245,7 +239,7 @@ for f in [homogeneous, heterogeneous]
245239
@test Vector(dx_d) _dx
246240

247241
b = @be $nd_d($dx_d, $x0_d, $p_d, 0.0) seconds=SECONDS
248-
br = BenchmarkResult(b, legacy_order(nd, Vector(dx_d)))
242+
br = BenchmarkResult(b, Vector(dx_d))
249243
bd["kuramoto_"*name, exname*"_cuda64", aggname*"_cuda64", N] = br
250244
end
251245
end
@@ -305,7 +299,7 @@ for N in Ns
305299
@test dx _dx
306300

307301
b = @be $nd($dx, $_x0, $p, 0.0) seconds=SECONDS
308-
br = BenchmarkResult(b, legacy_order(nd, dx))
302+
br = BenchmarkResult(b, dx)
309303
bd["powergrid", exname, aggname, N] = br
310304

311305
if CUDA.functional() && iscudacompatible(execution) && iscudacompatible(nd.layer.aggregator)
@@ -324,7 +318,7 @@ for N in Ns
324318
b = @be $nd_d($dx_d, $x0_d, $p_d, 0.0) seconds=SECONDS
325319
# we store the original _dx in the benchmarks results because we know
326320
# our dx_d does not have the precision
327-
br = BenchmarkResult(b, legacy_order(nd, _dx))
321+
br = BenchmarkResult(b, _dx)
328322
bd["powergrid", exname*"_cuda32", aggname*"_cuda32", N] = br
329323

330324
to = CuArray{Float64}
@@ -337,7 +331,7 @@ for N in Ns
337331
@test Vector(dx_d) _dx
338332

339333
b = @be $nd_d($dx_d, $x0_d, $p_d, 0.0) seconds=SECONDS
340-
br = BenchmarkResult(b, legacy_order(nd, Vector(dx_d)))
334+
br = BenchmarkResult(b, Vector(dx_d))
341335
bd["powergrid", exname*"_cuda64", aggname*"_cuda64", N] = br
342336
end
343337
end

0 commit comments

Comments
 (0)