Details and Options
ResourceFunction["MonitorProgress"] will estimate the remaining time based on the number of remaining steps and the time taken so far.
ResourceFunction["MonitorProgress"] can automatically monitor the progress of a wide variety of functions:
map-type functions | Map,ParallelMap,AssociationMap,MapIndexed,MapAt,
BlockMap,Scan,Apply |
queries | Query |
table-type functions | Table,ParallelTable,Do,ParallelDo,Array,ParallelArray |
recursion functions | Nest,NestList,Fold,FoldList,FoldPair,FoldPairList |
filtering/counting functions | Select,SelectFirst,LengthWhile,TakeWhile |
*By-type functions | CountDistinctBy,CountsBy,DeleteDuplicatesBy,GatherBy,
GroupBy,KeySortBy,MaximalBy,MinimalBy,OrderingBy,
ReverseSortBy,SortBy,SplitBy,TakeLargestBy,TakeSmallestBy |
procedural programming functions | For,While |
operator forms | Map,AssociationMap,MapIndexed,MapAt,Apply,Query,
Fold,FoldList,Select,SelectFirst,CountDistinctBy,CountsBy,
DeleteDuplicatesBy,GroupBy,KeySortBy,MaximalBy,
MinimalBy,ReverseSortBy,SortBy,TakeLargestBy,TakeSmallestBy,
Function |
For the *By-type function, ResourceFunction["MonitorProgress"] will monitor only the progress of applying the function to the individual items. Anything else, e.g. the actual sorting, is not included.
For the functions listed in "operator forms", ResourceFunction["MonitorProgress"] will return an operator if the expression was an operator form.
For some types of expressions, ResourceFunction["MonitorProgress"] cannot determine the number of expected steps. In these cases, an "endless" progress bar is used.
ResourceFunction["MonitorProgress"] accepts the following options:
"Resolution" | Automatic | resolution with which to update the progress bar |
"Timing" | True | whether to include timing information |
"Label" | None | label for the progress indicator |
"CurrentDisplayFunction" | Full | how to display the current item of the computation |
Parallelization | Automatic | how to handle parallelization of the evaluation |
The option "Resolution" can be set to the following:
steps | update the progress bar after the specified number of steps |
Scaled[frac] | update after a fraction of the total number of steps |
Automatic | use an automatically determined setting |
The setting
"Resolution"→Automatic is equivalent to
Scaled[1/20] when the number of steps is known, and 5 otherwise.
The option "Timing" can be set to the following:
True | include timing information |
False | do not include timing information |
Automatic | only include timing information if the total number of steps is known |
The timing information provided includes time elapsed, time per step, estimated time remaining and estimated total time. The latter two are missing if the number of steps is unknown.
The option "CurrentDisplayFunction" can be set to the following:
Full | show a short version of the current item, with a tooltip of the full item |
Automatic | do not include a tooltip |
None | do not display the current item |
func | apply func before generating the tooltipped short version of the current item |
{func} | same as func, but do not include a tooltip |
{func,toolfunc} | apply toolfunc to generate the content of the tooltip |
{func,Full} | show the full current item in the tooltip |
The function specified by "CurrentDisplayFunction" is effectively applied to the value set by ResourceFunction["MonitorProgress"]["SetCurrent"]/ResourceFunction["MonitorProgress"]["SetCurrentBy"].
ResourceFunction["MonitorProgress"] supports parallelized evaluation, with the progress being properly synchronized between kernels. The exact behavior can be specified using the
Parallelization option:
Automatic | only use parallelization if the argument is explicitly parallelized |
False | disable parallelization support |
{opts} | attempt parallelization using Parallelize with the specified options |
Full | attempt parallelization using Parallelize; equivalent to {} |
If ResourceFunction["MonitorProgress"] cannot automatically determine how to inject tracking into the evaluated expression, the necessary information can be provided manually. Apart from supplying the number of steps expected, it is also necessary to indicate when each step of the computation is finished. It is also possible to set a label for the currently processed item/step. The following functions can be used for this purpose:
ResourceFunction["MonitorProgress"]["Step"][args] | indicates that one step is done; returns args |
ResourceFunction["MonitorProgress"]["SetCurrent"][label] | set the label of the current step to label; returns label |
ResourceFunction["MonitorProgress"]["SetCurrentBy"][func][expr] | set the label of the current step to func[expr];
returns expr |
All three functions for manual monitoring return their arguments to allow for simple chaining.
If the number of steps is unknown,
Indeterminate can be specified for
steps instead. This causes an "endless" progress bar to be used.
ResourceFunction["MonitorProgress"] supports advanced evaluation control and will work nicely with
Unevaluated arguments and functions with
HoldAll and related attributes.
ResourceFunction["MonitorProgress"] will accurately predict the number of steps needed for mapping operations on
SparseArray expressions.
Even though ResourceFunction["MonitorProgress"] is designed to incur minimal overhead, the performance impact might not be negligible if the individual steps are very fast. Furthermore, ResourceFunction["MonitorProgress"] might prevent automatic compilation performed by some functions.