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

Feature request: Access to results #860

Open
1 task done
markdall opened this issue Dec 6, 2019 · 10 comments
Open
1 task done

Feature request: Access to results #860

markdall opened this issue Dec 6, 2019 · 10 comments
Assignees
Labels
duplicate 🗐 Seen it before p4-enhancement-future 🧨 On the back burner question/docs ‽ Documentation clarification candidate
Projects

Comments

@markdall
Copy link

markdall commented Dec 6, 2019

  • [X ] I have marked all applicable categories:
    • new feature request

tqdm gives nice human readable information about iterations per second. It would be great if we could access that information in order to log it, for times when we want to check the performance of a thing over time.

From this example: https://stackoverflow.com/questions/56677267/tqdm-extract-time-passed-time-remaining

0%| | 0/200 [00:00<?, ?it/s]
4%|▎ | 7/200 [00:00<00:02, 68.64it/s]
8%|▊ | 16/200 [00:00<00:02, 72.87it/s]
12%|█▎ | 25/200 [00:00<00:02, 77.15it/s]
17%|█▋ | 34/200 [00:00<00:02, 79.79it/s]
22%|██▏ | 43/200 [00:00<00:01, 79.91it/s]
26%|██▌ | 52/200 [00:00<00:01, 80.23it/s]
30%|███ | 61/200 [00:00<00:01, 82.13it/s]
....
100%|██████████| 200/200 [00:02<00:00, 81.22it/s]

I'd like to be able to retrieve 81.22, which is the last value for iterations per second. I have another script that uses tqdm and shows me k/s for a download, and I'd love to be able to log that over time. The goal is very much to have the values match what is shown (by tqdm) exactly, vs. calculating it separately and maybe coming close.

@casperdcl casperdcl self-assigned this Dec 6, 2019
@casperdcl casperdcl added duplicate 🗐 Seen it before question/docs ‽ Documentation clarification candidate labels Dec 6, 2019
@casperdcl
Copy link
Sponsor Member

Use the tqdm object's .format_dict property

@casperdcl
Copy link
Sponsor Member

casperdcl commented Dec 6, 2019

@markdall
Copy link
Author

markdall commented Dec 6, 2019

Thanks so much! This was tough to know the right search terms for.

@casperdcl
Copy link
Sponsor Member

yes but I agree that there's quite a bit of info that format_meter calculates internally from format_dict which may be nice to expose in some way. As of now it still seems that calling str() around a tqdm object and parsing the output manually might be the best way to go which seems weird.

@casperdcl casperdcl added the p4-enhancement-future 🧨 On the back burner label Dec 6, 2019
@casperdcl casperdcl added this to To Do in Casper Dec 6, 2019
@markdall
Copy link
Author

markdall commented Dec 7, 2019

I'm just not great at it and for some reason keep ending up with a number that's different than the last displayed number. But it's much better than nothing, and I really appreciate the help. Thanks!

@graue70
Copy link

graue70 commented Aug 18, 2020

yes but I agree that there's quite a bit of info that format_meter calculates internally from format_dict which may be nice to expose in some way.

This would be very useful.

I have something like the following at the moment:

logger.info(f"Reading things from '{file}'")
with file.open("rb") as f:
    progress = tqdm(
        f, desc="Reading things", unit="lines", unit_scale=True
    )
    for line_number, line in enumerate(progress):
        # do something with line

logger.info(
    f"Read {progress.format_dict['n']} things in"
    f" {progress.format_interval(progress.format_dict['elapsed'])}"
    f" ({(progress.format_dict['n'] / progress.format_dict['elapsed']):.2f}lines/s)"
)

Besides this being unreadable code, the unit is not scaled in the logging statement.

@casperdcl
Copy link
Sponsor Member

the unit is not scaled in the logging statement.

You can use progress.format_sizeof() for numbers the same way you use progress.format_interval() for seconds.

@graue70
Copy link

graue70 commented Aug 19, 2020

You can use progress.format_sizeof() for numbers the same way you use progress.format_interval() for seconds.

Wow thanks. That's awesome. Who would have thought there is some non-documented functionality hidden away in the package? :)

In that case it's only about unreadable code or the ease of extracting the relevant information.

@casperdcl
Copy link
Sponsor Member

Wow thanks. That's awesome. Who would have thought there is some non-documented functionality hidden away in the package? :)

well there's https://tqdm.github.io/docs/tqdm/#format_sizeof

@graue70
Copy link

graue70 commented Aug 19, 2020

well there's https://tqdm.github.io/docs/tqdm/#format_sizeof

You're absolutely right, but I only ever looked at https://github.com/tqdm/tqdm#documentation where it doesn't appear. I find it confusing to have multiple sources of documentation with varying content or levels of detail.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate 🗐 Seen it before p4-enhancement-future 🧨 On the back burner question/docs ‽ Documentation clarification candidate
Projects
Casper
  
To Do
Development

No branches or pull requests

3 participants