Function Repository Resource:

DynamicMap

Source Notebook

Map functions over lists while showing dynamic progress

Contributed by: Michael Sollami

ResourceFunction["DynamicMap"][f,list]

maps function f over the given list, while showing a progress indicator.

Details and Options

ResourceFunction["DynamicMap"] displays dynamic updates on the progress of the mapping in a panel:
ResourceFunction["DynamicMap"] works on associations as well as lists.
The panel displays the following details:
Itemcurrent index being processed
Sizecurrent size of resulting object
Timeapproximation of remaining time
Kernelsnumber of parallel kernels being used
If a computation is aborted, either by pressing the Abort button in the panel or by aborting the kernel normally, ResourceFunction["DynamicMap"] will return a list containing all the of work that was already finished, along with a report of the index of the element on which ResourceFunction["DynamicMap"] was aborted.
ResourceFunction["DynamicMap"] supports the Boolean option "Parallel" (which is False by default). If set to True, it will attempt to launch parallel subkernels and proceed with the computation.

Examples

Basic Examples (3) 

DynamicMap displays a panel of mapping progress:

In[1]:=
ResourceFunction["DynamicMap"][Pause[#] &, Range@10]

Use DynamicMap to monitor a long computation and optionally abort it:

In[2]:=
a = Association[(# -> (2^# - 1)) & /@ Range[1000, 1002]];
x = ResourceFunction["DynamicMap"][FactorInteger, Range[4^5, 8^7]];

Apply DynamicMap to an Association:

In[3]:=
ResourceFunction["DynamicMap"][#^2 &, AssociationThread[Range[20] -> Range[20]], "Parallel" -> False]
Out[3]=

Scope (1) 

Partial results (1) 

Click the Abort button in the panel to stop the computation, but return partially completed work:

In[4]:=
ResourceFunction["DynamicMap"][Pause, Range[10], "Parallel" -> False]
Out[4]=

Options (3) 

Parallel (3) 

To do the work in parallel, DynamicMap will launch kernels as needed:

In[5]:=
pfunc[x_] := (Pause[2]; x^3)
res = ResourceFunction["DynamicMap"][pfunc, Range[24], "Parallel" -> True] // AbsoluteTiming
Out[6]=

If you abort the computation while using the "Parallel" option, partial results are returned as a list of rules mapping indices to values:

In[7]:=
pfunc[x_] := (Pause[1]; If[x > 7, Abort[]]; x^3)
ResourceFunction["DynamicMap"][pfunc, Range[10], "Parallel" -> True] // AbsoluteTiming
Out[7]=

When using the "Parallel" option, you can specify the minimum number of kernels used:

In[8]:=
pfunc[x_] := (Pause[2]; x^3)
ResourceFunction["DynamicMap"][pfunc, AssociationThread[Range[24] -> Range[24]], "Parallel" -> 2] // AbsoluteTiming
Out[8]=
In[9]:=
ResourceFunction["DynamicMap"][pfunc, AssociationThread[Range[24] -> Range[24]], "Parallel" -> 6] // AbsoluteTiming
Out[9]=

Possible Issues (1) 

Time estimates require a few seconds to measure and are only first-order approximations:

In[10]:=
a = Range[100, 400];
Short@ResourceFunction["DynamicMap"][FactorInteger[2^# - 1] &, a]
Out[7]=

Publisher

Michael Sollami

Version History

  • 4.0.0 – 14 February 2020
  • 3.0.0 – 06 January 2020

Related Resources

Author Notes

V1 - Initial version V2 - Added "Parallel" option

License Information