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

Checking ipywidgets is installed for ensure tqdm working #2417

Merged

Conversation

olineumann
Copy link
Contributor

@olineumann olineumann commented Jun 29, 2020

What does this PR do?

Some users having problems with the progress bar in combination with jupyter notebook/lab. Sometimes it crashes because of missing dependencies, sometimes the progress bar isn't displayed correctly. Normally tqdm should select the correct package via tqdm.auto which is used in the code, but as some users reporting (not only in pytorch_lightning) it seems not working correctly.

Since pytorch_lightning doesn't want to add ipywidgets (which often is the problem) to the dependencies it would be better to check if this package is installed before importing tqdm.auto and import only tqdm of not.

As an example run this in jupyter without ipywidgets installed:

import time

# this will fail
from tqdm.auto import tqdm

# this not
#try:
#    import ipywidgets
#    from tqdm.auto import tqdm
#except ImportError as e:
#    from tqdm import tqdm

for i in tqdm(range(1000)):
    time.sleep(0.01)

Fixes #1687

Before submitting

  • Was this discussed/approved via a Github issue? (no need for typos and docs improvements)
  • Did you read the contributor guideline, Pull Request section?
  • Did you make sure your PR does only one thing, instead of bundling different changes together? Otherwise, we ask you to create a separate PR for every change.
  • Did you make sure to update the documentation with your changes?
  • Did you write any new necessary tests?
    Not needed I think?
  • Did you verify new and existing tests pass locally with your changes?
    Tests passed locally.
  • If you made a notable change (that affects users), did you update the CHANGELOG?
    Not necessary.

PR review

Anyone in the community is free to review the PR once the tests have passed.
If we didn't discuss your PR in Github issues there's a high chance it will not be merged.

Did you have fun?

Make sure you had fun coding 🙃

@mergify mergify bot requested a review from a team June 29, 2020 12:08
@olineumann
Copy link
Contributor Author

Just searched for tqdm.auto imports and replaced it. I think in progress.py it is correct in lr_finder.py I'm not sure and I'm wondering why lr_finder doesn't use ProgressBar?

@Borda Borda added the bug Something isn't working label Jun 29, 2020
@Borda Borda added this to the 0.8.x milestone Jun 29, 2020
Copy link
Contributor

@awaelchli awaelchli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

Comment on lines 14 to 15
from tqdm.auto import tqdm
except ImportError as e:
Copy link
Contributor

@awaelchli awaelchli Jun 29, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could we use

import importlib 
if importlib.util.find_spec("ipywidgets") is not None:
    import ipywidgets
    from tqdm.auto import tqdm
else:
    from tqdm import tqdm

? (brain compiled, may have typos)
ImportError is not suitable here in general.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should probably also add "pragma no cover " not to decrease coverage

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, sure. Thanks!

@mergify mergify bot requested a review from a team June 29, 2020 12:26
@codecov
Copy link

codecov bot commented Jun 29, 2020

Codecov Report

Merging #2417 into master will decrease coverage by 0%.
The diff coverage is 78%.

@@          Coverage Diff           @@
##           master   #2417   +/-   ##
======================================
- Coverage      89%     89%   -0%     
======================================
  Files          69      69           
  Lines        5476    5482    +6     
======================================
+ Hits         4856    4860    +4     
- Misses        620     622    +2     

@mergify
Copy link
Contributor

mergify bot commented Jun 29, 2020

This pull request is now in conflict... :(

@williamFalcon
Copy link
Contributor

@olineumann love the PR! this is a great addition

@williamFalcon williamFalcon merged commit 1a54ed6 into Lightning-AI:master Jun 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

name 'IProgress' is not defined
4 participants