@@ -394,6 +394,122 @@ function WorkPrecisionSet(prob::AbstractRODEProblem,abstols,reltols,setups,test_
394
394
WorkPrecisionSet (wps,N,abstols,reltols,prob,setups,names,error_estimate,numruns_error)
395
395
end
396
396
397
+
398
+ function WorkPrecisionSet (prob:: AbstractEnsembleProblem ,abstols,reltols,setups,test_dt= nothing ;
399
+ numruns= 5 , trajectories= 1000 ,
400
+ print_names= false ,names= nothing ,appxsol_setup= nothing ,expected_value= nothing ,
401
+ error_estimate= :weak_final ,ensemblealg= EnsembleThreads (),
402
+ kwargs... )
403
+
404
+ @assert names === nothing || length (setups) == length (names)
405
+
406
+ weak_timeseries_errors = error_estimate ∈ WEAK_TIMESERIES_ERRORS
407
+ weak_dense_errors = error_estimate ∈ WEAK_DENSE_ERRORS
408
+
409
+ N = length (setups); M = length (abstols)
410
+ times = Array {Float64} (undef,M,N)
411
+ solutions = Array {Any} (undef,M,N)
412
+ if names === nothing
413
+ names = [string (nameof (typeof (setup[:alg ]))) for setup in setups]
414
+ end
415
+ time_tmp = Vector {Float64} (undef,numruns)
416
+
417
+ # First calculate all of the errors
418
+ for k in 1 : N
419
+ for j in 1 : M
420
+ if ! haskey (setups[1 ],:dts )
421
+ sol = solve (prob,setups[k][:alg ],ensemblealg;
422
+ setups[k]. .. ,
423
+ abstol= abstols[j],
424
+ reltol= reltols[j],
425
+ timeseries_errors= false ,
426
+ dense_errors = false ,
427
+ trajectories= Int (trajectories),kwargs... )
428
+ else
429
+ sol = solve (prob,setups[k][:alg ],ensemblealg;
430
+ setups[k]. .. ,
431
+ abstol= abstols[j],
432
+ reltol= reltols[j],
433
+ dt= setups[k][:dts ][j],
434
+ timeseries_errors= false ,
435
+ dense_errors = false ,
436
+ trajectories= Int (trajectories),kwargs... )
437
+ end
438
+ solutions[j,k] = sol
439
+ end
440
+ @info " $(setups[k][:alg ]) ($k /$N )"
441
+ end
442
+
443
+ if error_estimate ∈ WEAK_ERRORS
444
+ if expected_value != nothing
445
+ errors = [[LinearAlgebra. norm (Statistics. mean (solutions[i,j]. u .- expected_value))
446
+ for i in 1 : M] for j in 1 : N]
447
+ else
448
+ sol = solve (prob,appxsol_setup[:alg ],ensemblealg;kwargs... ,appxsol_setup... ,
449
+ timeseries_errors= false ,dense_errors = false ,trajectories= Int (trajectories))
450
+ errors = [[LinearAlgebra. norm (Statistics. mean (solutions[i,j]. u .- sol. u))
451
+ for i in 1 : M] for j in 1 : N]
452
+ end
453
+ else
454
+ error (" use RODEProblem instead of EnsembleProblem for strong errors." )
455
+ end
456
+
457
+ local _sol
458
+
459
+ # Now time it
460
+ for k in 1 : N
461
+ # precompile
462
+ GC. gc ()
463
+ if ! haskey (setups[1 ],:dts )
464
+ _sol = solve (prob,setups[k][:alg ],ensemblealg;
465
+ setups[k]. .. ,
466
+ abstol= abstols[1 ],
467
+ reltol= reltols[1 ],
468
+ timeseries_errors= false ,
469
+ dense_errors = false ,
470
+ trajectories= Int (trajectories),kwargs... )
471
+ else
472
+ _sol = solve (prob,setups[k][:alg ],ensemblealg;
473
+ setups[k]. .. ,
474
+ abstol= abstols[1 ],
475
+ reltol= reltols[1 ],
476
+ dt= setups[k][:dts ][1 ],
477
+ timeseries_errors= false ,
478
+ dense_errors = false ,
479
+ trajectories= Int (trajectories),kwargs... )
480
+ end
481
+ # x = isempty(_sol.t) ? 0 : round(Int,mean(_sol.t) - sum(_sol.t)/length(_sol.t))
482
+ GC. gc ()
483
+ for j in 1 : M
484
+ for i in 1 : numruns
485
+ time_tmp[i] = @elapsed if ! haskey (setups[k],:dts )
486
+ sol = solve (prob,setups[k][:alg ],ensemblealg;
487
+ setups[k]. .. ,
488
+ abstol= abstols[j],
489
+ reltol= reltols[j],
490
+ timeseries_errors= false ,
491
+ dense_errors = false ,
492
+ trajectories= Int (trajectories),kwargs... )
493
+ else
494
+ sol = solve (prob,setups[k][:alg ],ensemblealg;
495
+ setups[k]. .. ,
496
+ abstol= abstols[j],
497
+ reltol= reltols[j],
498
+ dt= setups[k][:dts ][j],
499
+ timeseries_errors= false ,
500
+ dense_errors = false ,
501
+ trajectories= Int (trajectories),kwargs... )
502
+ end
503
+ end
504
+ times[j,k] = mean (time_tmp) # + x
505
+ GC. gc ()
506
+ end
507
+ end
508
+
509
+ wps = [WorkPrecision (prob,abstols,reltols,errors[i],times[:,i],names[i],N) for i in 1 : N]
510
+ WorkPrecisionSet (wps,N,abstols,reltols,prob,setups,names,error_estimate,Int (trajectories))
511
+ end
512
+
397
513
function get_sample_errors (prob:: AbstractRODEProblem ,setup,test_dt= nothing ;
398
514
appxsol_setup= nothing ,
399
515
numruns,error_estimate= :final ,
0 commit comments