Skip to content

Commit 8a2654e

Browse files
committed
Work precision diagram for nonlinearproblem
1 parent 41adf1e commit 8a2654e

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

src/benchmark.jl

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,57 @@ function WorkPrecision(prob, alg, abstols, reltols, dts = nothing;
273273
return WorkPrecision(prob, abstols, reltols, errors, times, name, N)
274274
end
275275

276+
# Work precision information for a nonlinear problem.
277+
function WorkPrecision(prob::NonlinearProblem, alg, abstols, reltols, dts = nothing; name = nothing, appxsol = nothing, error_estimate = :l2, numruns = 20, seconds = 2, kwargs...)
278+
isnothing(appxsol) && error("Must provide the real value as the \"appxsol\" kwarg.")
279+
println("HERE")
280+
281+
N = length(abstols)
282+
errors = Vector{Float64}(undef, N)
283+
times = Vector{Float64}(undef, N)
284+
if name === nothing
285+
name = "WP-Alg"
286+
end
287+
288+
if haskey(kwargs, :prob_choice)
289+
_prob = prob[kwargs[:prob_choice]]
290+
elseif prob isa AbstractArray
291+
_prob = prob[1]
292+
else
293+
_prob = prob
294+
end
295+
296+
let _prob = _prob
297+
for i in 1:N
298+
sol = solve(_prob, alg; kwargs..., abstol = abstols[i], reltol = reltols[i])
299+
300+
if error_estimate == :l2
301+
errors[i] = sqrt(sum((sol .- appxsol) .^2))
302+
else
303+
error("Unsupported norm used: $(error_estimate).")
304+
end
305+
306+
benchmark_f = let dts = dts, _prob = _prob, alg = alg, sol = sol,
307+
abstols = abstols, reltols = reltols, kwargs = kwargs
308+
309+
() -> @elapsed solve(_prob, alg;
310+
abstol = abstols[i],
311+
reltol = reltols[i],
312+
kwargs...)
313+
end
314+
benchmark_f() # pre-compile
315+
316+
b_t = benchmark_f()
317+
if b_t > seconds
318+
times[i] = b_t
319+
else
320+
times[i] = mapreduce(i -> benchmark_f(), min, 2:numruns; init = b_t)
321+
end
322+
end
323+
end
324+
return WorkPrecision(prob, abstols, reltols, errors, times, name, N)
325+
end
326+
276327
function WorkPrecisionSet(prob,
277328
abstols, reltols, setups;
278329
print_names = false, names = nothing, appxsol = nothing,

0 commit comments

Comments
 (0)