Skip to content

Consider replacing astropy's progress bar machinery with tqdm #4738

Open

Description

@eteq

tqdm is a package that implements easy/pretty progress bars in python. While we have something like this in astropy.utils.console, it might be wise to switch to tqdm in the interest of better code sharing/reuse.

One concern is how hard it will be to adapt our machinery to using this. If the interface is too different it's probably not worth it.

Another concern that needs checking is whether or not the notebook progress bar in tqdm is up-to-snuff (because the astropy one works quite well).

Originally suggested by @adrn

Activity

  1. pllim commented on Mar 28, 2016

    @pllim
    Member

    I would like to offer a different viewpoint -- "If it ain't broken, don't fix it." Is it worth adding yet another dependency just for a prettier progress bar?

  2. adrn commented on Mar 28, 2016

    @adrn
    Member

    The reason is not that it's prettier, but rather that it doesn't really make sense for astropy to maintain a progress bar utility. For the sake of the open-source community and the modularity of astropy, I think it would make sense to switch. Of course, this should be weighed with the practicality of switching...

  3. astrofrog commented on Apr 19, 2016

    @astrofrog
    Member

    Just to be clear, would we bundle it or have it as a dependency?

  4. adrn commented on Jul 2, 2016

    @adrn
    Member

    @astrofrog I would say dependency. If tqdm is not installed, I think the user could live without a progress bar? The Astropy ProgressBar class is only used in astropy/utils/data.py and astropy/utils/data.py

  5. pllim commented on Jul 5, 2016

    @pllim
    Member

    To say it is "only used" is misleading. Whenever remote data is downloaded, you will see that progress bar. I still think it's a bit excessive to require an extra dependency for a low-level util like this, but that's just me.

  6. mhvk commented on Jul 5, 2016

    @mhvk
    Contributor

    I think it is a good idea to swap, since really we should not maintain that kind of code, but on the other hand I do think the default should be to have a progress bar without having to depend on the user installing it. Sincetqdm is not exactly large, (indeed, it seems fairly similar to our current console.py), could we not just bundle it?

  7. cdeil commented on Jul 26, 2017

    @cdeil
    Member

    I wanted to use the Astropy progress update utils today for the first time.
    The use case is to report to users progress of HiPS tile fetching from the internet and tile drawing to make sky images: hipspy/hips#80

    So I looked at the examples here:

    Some observations / feedback as a naive first-time user:

    • None of the examples given is complete that I can just copy & paste them and try them out.
    • The spinner example calls next on a generator, which doesn't work on Python 3 where it's __next__, this needs to be fixed.
    • Why is it bar.update() and s.next()? This difference is unnecessary and hard to remember, no?
    • By default in the Jupyter notebook there's no output at all from the progress bar. Wouldn't it be possible / better default behaviour to show text output like on the terminal? I'm not sure how to use the progress bar from my hips package so that it shows nice progress for users both from the console and Jupyter (and some progress even in cases where they don't have the Jupyter widgets enabled like I have at the moment).

    This is the full example that I used in the end to try it, we could put that in the docstring:

    In [3]: %paste
    from astropy.utils.console import ProgressBar
    import time
    
    items = range(10)
    for item in ProgressBar(items):
        # Do some computation with `item` here
        time.sleep(0.2)
    
    ## -- End pasted text --
    |================================================================================================================|  10 / 10  (100.00%)         2s
    

    The discussion here has stalled over a year ago. I can see how this is a tough decision. Is there a way to resolve the discussion here and make a decision what to do?

    Some of the comments above lean towards switching out the implementation and (if I understand correctly), change the implementation of the existing classes to be wrappers around tqdm and provide backward compatibility for users of the astropy.utils. Is it possible? Is it desirable given the point I made about the spinner and progress bar API above or would complete deprecation of this part of astropy.utils be better (I mean via the docs, i.e. just say that external packages like hips should consider using something like tqdm directly)?

    If I get some feedback here, I could make a PR fixing / improving the docstrings of Spinner and ProgressBar a bit, but I don't have time to e.g. try switching to tqdm (and I'm not familiar with the implementations at all).

  8. Cadair commented on Jul 26, 2017

    @Cadair
    Member

    I think in general this is a good idea. I mean the "simplest" solution is to change all internal uses of progress bar to tqdm and then just deprecate the existing implementation?

  9. MridulS commented on Feb 20, 2024

    @MridulS
    Contributor

    Just wanted to bring this up again after 8 years :)
    tqdm is pretty much used everywhere now, and I am not sure how actively is the ProgressBar inside astropy is maintained. I tried switching to tqdm in astroquery and it shouldn't be that big of difference for downstream users (IMO).

    With astropy's progressbar:
    Screenshot 2024-02-20 at 10 36 54 PM

    With tqdm:
    Screenshot 2024-02-20 at 10 38 41 PM

    Let me know if there is interest in pursuing it :)

  10. pllim commented on Feb 20, 2024

    @pllim
    Member

    The more controversial discussion is adding it as a required dependency. We can't even agree on Scipy...

    And even older but broader discussions:

  11. tactipus commented on Feb 20, 2024

    @tactipus

    we should make it a dependency. we should it duke it out to see which side prevails :3

  12. WilliamJamieson commented on Feb 20, 2024

    @WilliamJamieson
    Contributor

    The main opposition to scipy surrounds how "big" its install is and how complicated it can be to build from source. tqdm appears to be ~78kB and entirely Python code with no serious dependencies itself. So I think this is an entirely reasonable thing to do. Especially if @MridulS is correct in it being a fairly simple change.

  13. 24 remaining items

  14. MridulS commented on Feb 23, 2024

    @MridulS
    Contributor

    Hmm... Where exactly?

    astropy/astropy/utils/data.py

    Lines 1749 to 1759 in 884bcac

    combined_paths = ProgressBar.map(
    _do_download_files_in_parallel,
    [
    dict(
    remote_url=u,
    cache=cache,
    show_progress=False,
    timeout=timeout,
    sources=sources.get(u, None),
    pkgname=pkgname,
    temp_cache=astropy.config.paths.set_temp_cache._temp_path,

    ProgressBar.map(download, args, multiprocess=multiprocess)

  15. mhvk commented on Feb 23, 2024

    @mhvk
    Contributor

    It sounds like this may be more work than is worth it for something that isn't broken...

  16. pllim commented on Feb 23, 2024

    @pllim
    Member

    Right, the validator. Yeah, I remember now. It was designed to download multiple sources at once for validation. If PyVO eventually takes it over, maybe it is not such a big deal for astropy.

    https://astroconda.org/aux/vo_databases/daily_html/

    But the one in download_files_in_parallel would be tough to replace, since astropy.utils.data stuff is widely used downstream.

    Does tqdm not support multiprocessing at all? That is a shame.

    Should we just close this as won't fix then?

  17. MridulS commented on Feb 24, 2024

    @MridulS
    Contributor

    Does tqdm not support multiprocessing at all? That is a shame.

    It does but it is just a progress bar, you would still need to write the actual code to do the multiprocessing bits. Astropy's porgressbar isn't really named properly, it's doing a lot more than just a progress bar 😅

    Should we just close this as won't fix then?

    Yeah I think we can just close this issue, let's keep it #4738 (comment) till it starts annoying us.

  18. astrofrog commented on Feb 24, 2024

    @astrofrog
    Member

    It does but it is just a progress bar, you would still need to write the actual code to do the multiprocessing bits. Astropy's porgressbar isn't really named properly, it's doing a lot more than just a progress bar 😅

    I've used tqdm with multiprocessing - and for simple use cases it's been as easy as just setting up a multiprocessing.Pool so it might not be too much work.

  19. pllim commented on Feb 26, 2024

    @pllim
    Member

    @astrofrog , what are you suggesting here in terms of actionable item?

  20. saimn commented on Mar 6, 2024

    @saimn
    Contributor

    Since both cases are dealing with parallel download, it would probably be better to use a thread pool (e,g, concurrent.futures) instead of a process one. (Or some package dedicated to parallel download, e.g. https://github.com/Cadair/parfive but maybe overkill for just those 2 cases)

  21. pllim commented on Mar 6, 2024

    @pllim
    Member

    I would be more comfortable if parfive isn't in Stuart's personal account and has recent releases...

    If we are serious about parfive, we are talking about requiring also tqdm and aiohttp.

    https://github.com/Cadair/parfive/blob/3b049c55f5cd35a607aafdfecfbccabf7bc71e29/setup.cfg#L19-L21

  22. tactipus commented on Mar 6, 2024

    @tactipus

    I'm down to code whatever needs to be done.

  23. saimn commented on Mar 6, 2024

    @saimn
    Contributor

    @pllim - not really serious, for 2 simple cases using directly a thread pool would be simpler.

  24. nstarman commented on Apr 15, 2024

    @nstarman
    Member

    I agree we should deprecate our ProgressBar and also that it's not as trivial a job as we'd like. I would suggest:

    1. rewriting the internals of ProgressBar to use tqdm. Users see no change from this except if they don't have tqdm installed, in which case we should raise a warning.
    2. Deprecating the ProgressBar, splitting out any functionality we need to keep , e.g. for download_files_in_parallel, as private functions.

    It's true that the code still works, but it's also true that this isn't the type of thing we want to maintain. Rather than waiting for it to eventually break, as everything does eventually, it would be much better if we actively switched to the de facto standard in Python.

    I also agree with @mhvk that it would be great if astropy[recommended] could be the default. I hope Python implements that soon.

    @tactipus. PRs welcome!!

  25. pllim commented on Apr 15, 2024

    @pllim
    Member

    I still don't see much point in introducing tqdm if we cannot get rid of anything in the end. Progress bar tech isn't going to change much and it is currently working.

  26. astrofrog commented on Apr 15, 2024

    @astrofrog
    Member

    At the very least we could always consider just recommending to users in the docs to consider using tqdm instead.

  27. Cadair commented on Apr 16, 2024

    @Cadair
    Member

    I would be more comfortable if parfive isn't in Stuart's personal account and has recent releases...

    ouch 😛

    It got a bit of love recently, it's actually reasonably active for such a project which does what it intends to.

    If we are serious about parfive, we are talking about requiring also tqdm and aiohttp.

    I am considering ditching aiohttp in favour of httpx as it's a little lighter weight (aiohttp is also a full http server library). If that's enough to make a difference then I would bump it up the list .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions