ProgressMeter.jl icon indicating copy to clipboard operation
ProgressMeter.jl copied to clipboard

Implemented SimpleProgress suitable for output to file

Open jagot opened this issue 4 years ago • 3 comments

When running on e.g. a cluster, the output is usually redirected to a file, where the escape characters turn into a jumbled mess (see #151). This PR implements a simple swap-in for Progress that instead prints a new line after each progress update:

N = 100
p = SimpleProgress(N)
for i = 1:N
    sleep(0.01)
    ProgressMeter.next!(p)
end

which gives output like this:

Progress:   8%  ETA: 0:00:01
Progress:  17%  ETA: 0:00:01
Progress:  26%  ETA: 0:00:01
Progress:  35%  ETA: 0:00:01
Progress:  44%  ETA: 0:00:01
Progress:  53%  ETA: 0:00:01
Progress:  62%  ETA: 0:00:00
Progress:  71%  ETA: 0:00:00
Progress:  80%  ETA: 0:00:00
Progress:  89%  ETA: 0:00:00
Progress:  98%  ETA: 0:00:00
Progress: 100% Time: 0:00:01

showvalues & showspeed is also supported:

N = 100
p = SimpleProgress(N, showspeed=true)
for i = 1:N
    sleep(0.01)
    ProgressMeter.next!(p, showvalues=[(:i,i),(:x,sin(i))])
end
Progress:   8%  ETA: 0:00:01 (13.12 ms/it)
  i:  8
  x:  0.9893582466233818
Progress:  17%  ETA: 0:00:01 (12.19 ms/it)
  i:  17
  x:  -0.9613974918795568
Progress:  26%  ETA: 0:00:01 (11.97 ms/it)
  i:  26
  x:  0.7625584504796027
Progress:  35%  ETA: 0:00:01 (11.84 ms/it)
  i:  35
  x:  -0.428182669496151
Progress:  44%  ETA: 0:00:01 (11.82 ms/it)
  i:  44
  x:  0.017701925105413577
Progress:  53%  ETA: 0:00:01 (11.74 ms/it)
  i:  53
  x:  0.39592515018183416
Progress:  62%  ETA: 0:00:00 (11.71 ms/it)
  i:  62
  x:  -0.7391806966492228
Progress:  71%  ETA: 0:00:00 (11.68 ms/it)
  i:  71
  x:  0.9510546532543747
Progress:  80%  ETA: 0:00:00 (11.67 ms/it)
  i:  80
  x:  -0.9938886539233752
Progress:  89%  ETA: 0:00:00 (11.66 ms/it)
  i:  89
  x:  0.8600694058124532
Progress:  98%  ETA: 0:00:00 (11.64 ms/it)
  i:  98
  x:  -0.5733818719904229
Progress: 100% Time: 0:00:01 (11.63 ms/it)
  i:  100
  x:  -0.5063656411097588

This PR does not implement finish! or cancel.

Is this interesting? Are the tests adequate?

jagot avatar Nov 09 '21 08:11 jagot

Could this be done by adding an option in the constructor of the Progressbars or in next!/update! instead of a new type of Progress ?

MarcMush avatar Nov 09 '21 11:11 MarcMush

I guess, but updateProgress!(p::Progress) would need even more conditional statements, to ensure that no escape characters are printed, i.e. there would be more and more complicated logic. Having a separate type to dispatch on simplifies this in my opinion.

jagot avatar Nov 09 '21 12:11 jagot

I believe it's more versatile to add this as an option (what if someone wants this but with colors, or with a ProgressUnknown/ProgressThresh)

I made a draft of what it could look like (#223)

MarcMush avatar Nov 09 '21 14:11 MarcMush