Skip to content

Commit 16d4bf2

Browse files
committed
Add multitimestep PBP benchmarks (single-threaded and multi-threaded)
1 parent ef330c5 commit 16d4bf2

2 files changed

Lines changed: 115 additions & 92 deletions

File tree

test/downstream/test-all-benchmarks.jl

Lines changed: 31 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -5,47 +5,44 @@ Pkg.instantiate()
55

66
using PlantSimEngine
77
using PlantSimEngine.Examples
8-
#using Test, Aqua
98
using DataFrames, CSV
109
using MultiScaleTreeGraph
1110
using PlantMeteo, Statistics
12-
#using Documenter # for doctests
1311

1412
# Include the example dummy processes:
1513
using PlantSimEngine.Examples
1614

1715
using BenchmarkTools
1816
using Dates
1917

20-
suite_name = "bench_"
21-
22-
if Sys.iswindows()
23-
suite_name = suite_name * "windows"
24-
elseif Sys.isapple()
25-
suite_name = suite_name * "mac"
26-
elseif Sys.islinux()
27-
suite_name = suite_name * "linux"
28-
end
29-
suite = BenchmarkGroup()
30-
suite[suite_name]=BenchmarkGroup(["PSE", "PBP"])#, "XPalm"])
31-
32-
# "PSE benchmark"
33-
include("test-PSE-benchmark.jl")
34-
suite[suite_name]["PSE"] = @benchmarkable do_benchmark_on_heavier_mtg()
35-
36-
#BenchmarkTools.save("test/downstream/output.json", median(b_PSE))
37-
38-
#activate_downstream_env()
39-
# "PBP benchmark"
40-
include("test-plantbiophysics.jl")
41-
suite[suite_name]["PBP"] = @benchmarkable benchmark_plantbiophysics()
42-
#BenchmarkTools.save("test/downstream/output.json", median(b_PBP))
43-
44-
45-
# "XPalm benchmark"
46-
#include("test-xpalm.jl")
47-
#suite[suite_name]["XPalm"] = @benchmarkable xpalm_default_param_run() seconds = 120
48-
49-
tune!(suite)
50-
results = run(suite, verbose = true)
51-
BenchmarkTools.save(dirname(@__FILE__)*"/output.json", median(results))
18+
suite_name = "bench_"
19+
20+
if Sys.iswindows()
21+
suite_name = suite_name * "windows"
22+
elseif Sys.isapple()
23+
suite_name = suite_name * "mac"
24+
elseif Sys.islinux()
25+
suite_name = suite_name * "linux"
26+
end
27+
suite = BenchmarkGroup()
28+
suite[suite_name] = BenchmarkGroup(["PSE", "PBP"])#, "XPalm"])
29+
30+
# "PSE benchmark"
31+
include("test-PSE-benchmark.jl")
32+
suite[suite_name]["PSE"] = @benchmarkable do_benchmark_on_heavier_mtg()
33+
34+
# "PBP benchmark"
35+
include("test-plantbiophysics.jl")
36+
suite[suite_name]["PBP"] = @benchmarkable benchmark_plantbiophysics()
37+
38+
leaf, meteo = setup_benchmark_plantbiophysics_multitimestep()
39+
suite[suite_name]["PBP_multiple_timesteps_MT"] = @benchmarkable benchmark_plantbiophysics_multitimestep_MT($leaf, $meteo)
40+
suite[suite_name]["PBP_multiple_timesteps_ST"] = @benchmarkable benchmark_plantbiophysics_multitimestep_ST($leaf, $meteo)
41+
42+
# "XPalm benchmark"
43+
#include("test-xpalm.jl")
44+
#suite[suite_name]["XPalm"] = @benchmarkable xpalm_default_param_run() seconds = 120
45+
46+
tune!(suite)
47+
results = run(suite, verbose=true)
48+
BenchmarkTools.save(dirname(@__FILE__) * "/output.json", median(results))

test/downstream/test-plantbiophysics.jl

Lines changed: 84 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
#TODO Cleanup
1+
# For local testing :
22
#using Pkg
33
#Pkg.develop("PlantSimEngine")
44
#using PlantSimEngine
55
using Statistics
6-
using DataFrames
7-
using CSV
6+
#using DataFrames
7+
#using CSV
88
using Random
99
using PlantBiophysics
10-
using BenchmarkTools
11-
using Test
12-
using PlantMeteo
10+
#using BenchmarkTools
11+
#using Test
12+
#using PlantMeteo
1313

1414
function benchmark_plantbiophysics()
1515

@@ -60,7 +60,7 @@ function benchmark_plantbiophysics()
6060

6161

6262
constants = Constants()
63-
time_PB = Vector{Float64}(undef, N*microbenchmark_steps)
63+
#time_PB = Vector{Float64}(undef, N*microbenchmark_steps)
6464
for i = 1:N
6565
leaf = ModelList(
6666
energy_balance=Monteith(),
@@ -92,64 +92,90 @@ function benchmark_plantbiophysics()
9292
#return time_PB
9393
end
9494

95-
#=@testset "PlantBiophysics benchmark" begin
96-
97-
time_PB = benchmark_plantbiophysics()
98-
N = length(time_PB)
99-
#statsPB = (mean(time_PB), median(time_PB), Statistics.std(time_PB), findmin(time_PB), findmax(time_PB))
100-
min__ = findmin(time_PB)[1]
101-
max__ = findmin(time_PB)[1]
102-
@test min__ > 1e-7
103-
@test max__ < 1e-5
104-
@test mean(time_PB) > 5e-7
105-
@test mean(time_PB) < 5e-6
106-
#TODO
107-
end=#
108-
109-
#=
110-
function run_plantbiophysics()
111-
112-
113-
Rs = 10.0
114-
Ta = 18.0
115-
Wind = 0.5
116-
P = 90.0
117-
Rh = 0.1
118-
Ca = 360.0
119-
skyF = 0.0
120-
d = 0.001
121-
Jmax = 200.0
122-
Vmax = 150.0
123-
Rd = 0.3
124-
TPU = 5.0
125-
g0 = 0.001
126-
g1 = 0.5
127-
vpd = e_sat(Ta) - vapor_pressure(Ta, Rh)
128-
PPFD = Rs*0.48*4.57
95+
function setup_benchmark_plantbiophysics_multitimestep()
12996

130-
constants = Constants()
97+
Random.seed!(1) # Set random seed
98+
N = 100 # Number of timesteps simulated for each microbenchmark step
13199

132-
leaf = ModelList(
100+
length_range = 10000
101+
Rs = range(10, 500, length=length_range)
102+
Ta = range(18, 40, length=length_range)
103+
Wind = range(0.5, 20, length=length_range)
104+
P = range(90, 101, length=length_range)
105+
Rh = range(0.1, 0.98, length=length_range)
106+
Ca = range(360, 900, length=length_range)
107+
skyF = range(0.0, 1.0, length=length_range)
108+
d = range(0.001, 0.5, length=length_range)
109+
Jmax = range(200.0, 300.0, length=length_range)
110+
Vmax = range(150.0, 250.0, length=length_range)
111+
Rd = range(0.3, 2.0, length=length_range)
112+
TPU = range(5.0, 20.0, length=length_range)
113+
g0 = range(0.001, 2.0, length=length_range)
114+
g1 = range(0.5, 15.0, length=length_range)
115+
vars = hcat([Ta, Wind, P, Rh, Ca, Jmax, Vmax, Rd, Rs, skyF, d, TPU, g0, g1])
116+
117+
set = [rand.(vars) for i = 1:N]
118+
set = reshape(vcat(set...), (length(set[1]), length(set)))'
119+
name = [
120+
"T",
121+
"Wind",
122+
"P",
123+
"Rh",
124+
"Ca",
125+
"JMaxRef",
126+
"VcMaxRef",
127+
"RdRef",
128+
"Rs",
129+
"sky_fraction",
130+
"d",
131+
"TPURef",
132+
"g0",
133+
"g1",
134+
]
135+
set = DataFrame(set, name)
136+
@. set[!, :vpd] = e_sat(set.T) - vapor_pressure(set.T, set.Rh)
137+
@. set[!, :PPFD] = set.Rs * 0.48 * 4.57
138+
139+
leaf = Vector{ModelList}(undef, N)
140+
for i = 1:N
141+
142+
leaf[i] = ModelList(
133143
energy_balance=Monteith(),
134144
photosynthesis=Fvcb(
135-
VcMaxRef=Vmax,
136-
JMaxRef=Jmax,
137-
RdRef=Rd,
138-
TPURef=TPU,
145+
VcMaxRef=set.VcMaxRef[i],
146+
JMaxRef=set.JMaxRef[i],
147+
RdRef=set.RdRef[i],
148+
TPURef=set.TPURef[i],
139149
),
140-
stomatal_conductance=Medlyn(g0, g1),
150+
stomatal_conductance=Medlyn(set.g0[i], set.g1[i]),
141151
status=(
142-
Rₛ=Rs,
143-
sky_fraction=skyF,
144-
PPFD=PPFD,
145-
d=d,
152+
Rₛ=set.Rs,
153+
sky_fraction=set.sky_fraction,
154+
PPFD=set.PPFD,
155+
d=set.d,
146156
),
147157
)
148-
deps = PlantSimEngine.dep(leaf)
149-
meteo = Atmosphere(T=Ta, Wind=Wind, P=P, Rh=Rh, Cₐ=Ca)
150-
st = PlantMeteo.row_struct(leaf.status[1])
151-
run!(leaf, deps, 1, st, meteo, constants, nothing)
158+
end
159+
160+
atm = Vector{Atmosphere}(undef, N)
161+
for i in 1:N
162+
atm[i]= Atmosphere(T=set.T[i], Wind=set.Wind[i], P=set.P[i], Rh=set.Rh[i], Cₐ=set.Ca[i])
163+
end
164+
meteo = Weather(atm)
165+
166+
return leaf, meteo
152167
end
153168

154-
run_plantbiophysics()
155-
=#
169+
function benchmark_plantbiophysics_multitimestep_MT(leaf, meteo)
170+
N = length(meteo)
171+
for i in 1:N
172+
run!(leaf[i], meteo, Constants(), nothing; executor = ThreadedEx())
173+
end
174+
end
175+
176+
function benchmark_plantbiophysics_multitimestep_ST(leaf, meteo)
177+
N = length(meteo)
178+
for i in 1:N
179+
run!(leaf[i], meteo, Constants(), nothing; executor = SequentialEx())
180+
end
181+
end

0 commit comments

Comments
 (0)