exoplanet-dev / exoplanet

Fast & scalable MCMC for all your exoplanet needs!
https://docs.exoplanet.codes
MIT License
206 stars 52 forks source link

Use tqdm.auto progressbar in xo.optimize #86

Closed adrn closed 4 years ago

adrn commented 4 years ago

This allows passing in a progress bar instance, disabling the progress bar, or (by default) using tqdm.auto.tqdm (as described in #85).

dfm commented 4 years ago

Should this use if progressbar instead of if progressbar is not False so that we support things like None?

adrn commented 4 years ago

I did that because the progress bar object is an iterable, so I don't think it can be coerced into a bool: image

dfm commented 4 years ago

It's actually not quite because it's an iterable:

import tqdm

bar = tqdm.tqdm(total=10)
if bar:  # works!
    ...

bar = tqdm.tqdm(range(50))
if bar:  # works!
    ...

bar = tqdm.tqdm()
if bar:  # TypeError
    ...

How about:

has_progress_bar = (
    hasattr(bar, "set_postfix")
    and hasattr(bar, "update")
    and hasattr(bar, "close")
)

instead?

adrn commented 4 years ago

I forgot to respond: I updated with your suggestion!

dfm commented 4 years ago

Awesome! I'm re-running the Windows test. It's not your fault, it just fails sometimes... 🤷

dfm commented 4 years ago

@adrn: one (or two, related) issues with this:

  1. The tutorials in the docs are autogenerated and it looks like tqdm.auto doesn't play nice with nbconvert (see here for example). It prints the following instead of a progress bar:
HBox(children=(FloatProgress(value=1.0, bar_style='info', max=1.0), HTML(value='')))
  1. I see the same in jupyterlab and it seems like auto doesn't play nice with jupterlab in general either.

I'm inclined to roll back some of this (allow users to provide a progress_bar but don't default to auto), but I'm interested in your thoughts.

adrn commented 4 years ago

Interesting! BTW, it looks like pymc3 switched to this progress bar.

Sounds like rolling back the tqdm.auto change, but keeping the option to pass in a progress_bar is the way to go...

dfm commented 4 years ago

The fastprogressbar won't work for us because it looks like it doesn't support bars without a known number of total steps.

I fixed this on jupyterlab using:

python -m pip install ipywidgets
jupyter nbextension enable --py widgetsnbextension
jupyter labextension install @jupyter-widgets/jupyterlab-manager

and I think that nbconvert should be able to do the right thing if we have ipywidgets installed when running so I'm going to try that.