Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented SimpleProgress suitable for output to file #222

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jagot
Copy link

@jagot jagot commented Nov 9, 2021

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?

@MarcMush
Copy link
Collaborator

MarcMush commented Nov 9, 2021

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 ?

@jagot
Copy link
Author

jagot commented Nov 9, 2021

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.

@MarcMush
Copy link
Collaborator

MarcMush commented Nov 9, 2021

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants