From 96a152c22a8ba7539c53384a23c281bb2a45f85e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olav=20M=C3=B8yner?= Date: Wed, 11 Dec 2024 20:42:54 +0100 Subject: [PATCH] Add option to successful_reports --- src/timesteps.jl | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/timesteps.jl b/src/timesteps.jl index cd2b2b3c..1dc43fde 100644 --- a/src/timesteps.jl +++ b/src/timesteps.jl @@ -152,9 +152,10 @@ end successful_reports(old_reports, current_reports, step_index, n = 1) Get the `n` last successful solve reports from all previous reports -(old_reports) and the current ministep set. +(old_reports) and the current ministep set. You can optionally provide a +function that replaces the default definition of `success=r->r[:success]`. """ -function successful_reports(old_reports, current_reports, step_index, n = 1) +function successful_reports(old_reports, current_reports, step_index, n = 1; success = r -> r[:success]) out = similar(current_reports, 0) if isfinite(n) sizehint!(out, n) @@ -169,7 +170,7 @@ function successful_reports(old_reports, current_reports, step_index, n = 1) end for r in Iterators.reverse(reports) - if !ismissing(r) && r[:success] + if !ismissing(r) && success(r) push!(out, r) if length(out) >= n return out @@ -187,12 +188,12 @@ Get last n successful reports starting at the end of `step` and reversing backwards until `n` values have been found. `n` can be set to `Inf` to produce all successful reports. """ -function successful_reports(reports, current_reports = missing; step = length(reports)+1, n = 1) +function successful_reports(reports, current_reports = missing; step = length(reports)+1, n = 1, kwarg...) if ismissing(current_reports) step = clamp(step, 1, length(reports)) current_reports = reports[step][:ministeps] end - return successful_reports(reports, current_reports, step, n) + return successful_reports(reports, current_reports, step, n; kwarg...) end """