-
Notifications
You must be signed in to change notification settings - Fork 0
02_Progress
Progress bars are derived from rich progress bars. These custom progress bars are derived from pytorch-lightning's default rich progress bars with some tweaks. Colors, layout and columns are fixed. See Customization for more details.
The code samples all assume previous declarations as well as:
from time import sleep
from nob import progressWrap around an Iterator
for _ in progress.track(range(100)):
sleep(0.01)The number of total items will be automatically detected (if the iterator has a __len__ method). Otherwise, you can specify it with the total argument. Pass None for iterators with no length and -1 to use the automatic detection (which is the default).
Get more control - don't only track iterators. Do not forget to:
- create a bar,
- create a task,
- enter the bar scope,
- and to advance your task(s).
bar = progress.progress() # 1
task = bar.add_task("Working...", total=100) # 2
with bar: # 3
for _ in range(100):
sleep(0.01)
bar.advance(task) # 4The number of total items is not automatically detected here, since we don't interact with the iterator. Each bar you create has a known_total attribute that is True by default, and is used to determine whether the total number of items will be known when the progress bar starts. Each task is created with total=100 by default, so you should almost always specify it yourself.
You can create as many bars as you want, and as many tasks per bar as you like. Each task within the same bar will auto-align their descriptions unless the bar context is exited and re-entered.
The progress bars have a very restricted set of customization options. The layout is fixed to:
{task.description} {progress.bar} {task.completed}/{task.total} {task.elapsed} • {task.remaining} {task.speed:.2f}it/smeaning the examples above will render as:
Working... ━━━━━━━━━━━━━━━━━━━━ 100/100 0:00:01 • 0:00:00 95.49/swith colors and styles that match the rest of the library. The only customization options are:
-
show_percentage: Whether to show the percentage of completion instead of the "completed/total" format. Particularly useful for tasks with a large total number of iterations. -
hide_time: If you don't want to show the elapsed and remaining time, set this toTrue. The remaining time is hidden if the total number of iterations is unknown. -
hide_processing_speed: Hides the processing speed if set toTrue. -
human_format: IfTrue, the "completed/total" and throughput will be shown in a human-readable format (e.g., "1.5k/10k" instead of "1500/10000" and "1.5k/s" instead of "1500/s"). This isTrueby default. -
unit: A string so that "completed/total" and throughput will show the unit (e.g., "1.5kB/10kB" instead of "1.5k/10k" and "1.5kB/s" instead of "1.5k/s" forunit="B"). This is an empty string by default.
Powered by caffeine and uv.
MIT license.