Skip to content

Commit

Permalink
only log significant progress
Browse files Browse the repository at this point in the history
  • Loading branch information
Pepijn de Vos committed Oct 5, 2023
1 parent f6672aa commit af6d724
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/ensemble/basic_ensemble_solve.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@ $(TYPEDEF)
"""
struct EnsembleSerial <: BasicEnsembleAlgorithm end

struct AggregateLogger{T<:AbstractLogger} <: AbstractLogger
mutable struct AggregateLogger{T<:AbstractLogger} <: AbstractLogger
progress::Dict{Symbol, Float64}
total::Float64
lock::ReentrantLock
logger::T
end
AggregateLogger(logger::AbstractLogger) = AggregateLogger(Dict{Symbol, Float64}(), ReentrantLock(), logger)
AggregateLogger(logger::AbstractLogger) = AggregateLogger(Dict{Symbol, Float64}(), 0.0, ReentrantLock(), logger)

function Logging.handle_message(l::AggregateLogger, level, message, _module, group, id, file, line; kwargs...)
if convert(LogLevel, level) == LogLevel(-1) && haskey(kwargs, :progress)
Expand All @@ -42,6 +43,8 @@ function Logging.handle_message(l::AggregateLogger, level, message, _module, gro
l.progress[id] = 1.0
end
tot = sum(values(l.progress))/length(l.progress)
tot < 1.0 && isapprox(tot, l.total; atol=0.001) && return # less than 0.1% change
l.total = tot
if tot>=1.0
tot="done"
empty!(l.progress)
Expand Down

0 comments on commit af6d724

Please sign in to comment.