Skip to content

Commit c5a5d7c

Browse files
authored
Align tqdm progress bars (#567)
* Align tqdm progress bars * Improve alignment of the colon
1 parent 5901054 commit c5a5d7c

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

cubed/diagnostics/tqdm.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,31 @@ def __init__(self, *args, **kwargs):
1717
def on_compute_start(self, event):
1818
from tqdm.auto import tqdm
1919

20+
# find the maximum display width so we can align bars below
21+
max_op_display_name = (
22+
max(
23+
len(node["op_display_name"].replace("\n", " "))
24+
for _, node in visit_nodes(event.dag, event.resume)
25+
)
26+
+ 1 # for the colon
27+
)
28+
2029
self.pbars = {}
21-
i = 0
22-
for name, node in visit_nodes(event.dag, event.resume):
30+
for i, (name, node) in enumerate(visit_nodes(event.dag, event.resume)):
2331
num_tasks = node["primitive_op"].num_tasks
24-
op_display_name = node["op_display_name"].replace("\n", " ")
32+
op_display_name = node["op_display_name"].replace("\n", " ") + ":"
33+
# note double curlies to get literal { and } for tqdm bar format
34+
bar_format = (
35+
f"{{desc:{max_op_display_name}}} {{percentage:3.0f}}%|{{bar}}{{r_bar}}"
36+
)
2537
self.pbars[name] = tqdm(
2638
*self.args,
2739
desc=op_display_name,
2840
total=num_tasks,
2941
position=i,
42+
bar_format=bar_format,
3043
**self.kwargs,
3144
)
32-
i = i + 1
3345

3446
def on_compute_end(self, event):
3547
for pbar in self.pbars.values():

0 commit comments

Comments
 (0)