@@ -14,25 +14,19 @@ Create a new logger for progress logging.
14
14
struct CreateNewProgressBar{S<: AbstractString } <: AbstractProgressKwarg
15
15
name:: S
16
16
uuid:: UUIDs.UUID
17
-
18
17
function CreateNewProgressBar (name:: AbstractString )
19
- return new {typeof{ name} } (name, UUIDs. uuid4 ())
18
+ return new {typeof( name) } (name, UUIDs. uuid4 ())
20
19
end
21
20
end
22
21
function init_progress (p:: CreateNewProgressBar )
23
- if hasprogresslevel (Logging. current_logger ())
24
- ProgressLogging. @withprogress $ (exprs... )
25
- else
26
- $ with_progresslogger ($ Base. @__MODULE__ , $ Logging. current_logger ()) do
27
- $ ProgressLogging. @withprogress $ (exprs... )
28
- end
29
- end
30
22
ProgressLogging. @logprogress p. name nothing _id = p. uuid
31
23
end
32
- function update_progress (p:: CreateNewProgressBar , progress_frac, :: Bool )
24
+ function update_progress (p:: CreateNewProgressBar , progress_frac)
33
25
ProgressLogging. @logprogress p. name progress_frac _id = p. uuid
34
26
end
35
- finish_progress (:: CreateNewProgressBar ) = ProgressLogging. @logprogress " done"
27
+ function finish_progress (p:: CreateNewProgressBar )
28
+ ProgressLogging. @logprogress p. name " done" _id = p. uuid
29
+ end
36
30
37
31
"""
38
32
NoLogging
@@ -41,7 +35,7 @@ Do not log progress at all.
41
35
"""
42
36
struct NoLogging <: AbstractProgressKwarg end
43
37
init_progress (:: NoLogging ) = nothing
44
- update_progress (:: NoLogging , :: Any , :: Bool ) = nothing
38
+ update_progress (:: NoLogging , :: Any ) = nothing
45
39
finish_progress (:: NoLogging ) = nothing
46
40
47
41
"""
@@ -57,8 +51,21 @@ struct ExistingProgressBar{S<:AbstractString} <: AbstractProgressKwarg
57
51
name:: S
58
52
uuid:: UUIDs.UUID
59
53
end
60
- init_progress (:: ExistingProgressBar ) = nothing
61
- function update_progress (p:: ExistingProgressBar , progress_frac, :: Bool )
54
+ function init_progress (p:: ExistingProgressBar )
55
+ # Hacky code to reset the start timer if called from a multi-chain sampling
56
+ # process. We need this because the progress bar is constructed in the
57
+ # multi-chain method, i.e. if we don't do this the progress bar shows the
58
+ # time elapsed since _all_ sampling began, not since the current chain
59
+ # started.
60
+ try
61
+ bartrees = Logging. current_logger (). loggers[1 ]. logger. bartrees
62
+ bar = TerminalLoggers. findbar (bartrees, p. uuid). data
63
+ bar. tfirst = time ()
64
+ catch
65
+ end
66
+ ProgressLogging. @logprogress p. name nothing _id = p. uuid
67
+ end
68
+ function update_progress (p:: ExistingProgressBar , progress_frac)
62
69
ProgressLogging. @logprogress p. name progress_frac _id = p. uuid
63
70
end
64
71
function finish_progress (p:: ExistingProgressBar )
71
78
Use a `Channel` to log progress. This is used for 'reporting' progress back
72
79
to the main thread or worker when using `progress=:overall` with MCMCThreads or
73
80
MCMCDistributed.
81
+
82
+ n_updates is the number of updates that each child thread is expected to report
83
+ back to the main thread.
74
84
"""
75
85
struct ChannelProgress{T<: Union{Channel{Bool},Distributed.RemoteChannel{Channel{Bool}}} } < :
76
86
AbstractProgressKwarg
77
87
channel:: T
88
+ n_updates:: Int
78
89
end
79
90
init_progress (:: ChannelProgress ) = nothing
80
- function update_progress (p:: ChannelProgress , :: Any , update_channel:: Bool )
81
- return update_channel && put! (p. channel, true )
82
- end
91
+ update_progress (p:: ChannelProgress , :: Any ) = put! (p. channel, true )
83
92
# Note: We don't want to `put!(p.channel, false)`, because that would stop the
84
93
# channel from being used for further updates e.g. from other chains.
85
94
finish_progress (:: ChannelProgress ) = nothing
86
95
87
- # avoid creating a progress bar with @withprogress if progress logging is disabled
88
- # and add a custom progress logger if the current logger does not seem to be able to handle
89
- # progress logs
90
- macro ifwithprogresslogger (cond, exprs... )
96
+ # Add a custom progress logger if the current logger does not seem to be able to handle
97
+ # progress logs.
98
+ macro withprogresslogger (expr)
91
99
return esc (
92
100
quote
93
- if $ cond
94
- # Create a new logger
95
- if $ hasprogresslevel ($ Logging. current_logger ())
96
- $ ProgressLogging. @withprogress $ (exprs... )
97
- else
98
- $ with_progresslogger ($ Base. @__MODULE__ , $ Logging. current_logger ()) do
99
- $ ProgressLogging. @withprogress $ (exprs... )
100
- end
101
+ if ! ($ hasprogresslevel ($ Logging. current_logger ()))
102
+ $ with_progresslogger ($ Base. @__MODULE__ , $ Logging. current_logger ()) do
103
+ $ (expr)
101
104
end
102
105
else
103
- # Don't create a new logger, either because progress logging
104
- # was disabled, or because it's otherwise being manually
105
- # managed.
106
- $ (exprs[end ])
106
+ $ (expr)
107
107
end
108
108
end ,
109
109
)
0 commit comments