Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fix: Use non-gui matplotlib backend for tests to avoid hanging on ipywidgets interact #2098

Merged
merged 7 commits into from
Jan 20, 2023

Conversation

matthewfeickert
Copy link
Member

@matthewfeickert matthewfeickert commented Jan 20, 2023

Description

  • To avoid having the notebook tests hang on the ipywidgets interact sections of InterpolationCodes.ipynb set the matplotlib backend to the non-gui Agg which disallows the creation of the gui elements that are causing the problem. This also speeds up runtime as no gui-elements are created for the notebook tests now.
  • Remove '%pylab inline' from InterpolationCodes.ipynb as pylab is very deprecated.
  • Add --verobse flag to notebook tests to make it easier to track the progress of the notebooks in the CI logs.

Checklist Before Requesting Reviewer

  • Tests are passing
  • "WIP" removed from the title of the pull request
  • Selected an Assignee for the PR to be responsible for the log summary

Before Merging

For the PR Assignees:

  • Summarize commit messages into a comprehensive review of the PR
* Avoid the notebook tests hanging on the ipywidgets interact sections of `InterpolationCodes.ipynb`
  by setting the matplotlib backend to the non-gui Agg which disallows the creation of the gui elements
  that are causing the problem.
* Remove '%pylab inline' from InterpolationCodes.ipynb as pylab is very deprecated.
* Add --verobse flag to notebook tests to make it easier to track the progress of the notebooks in the
  CI logs.

@matthewfeickert matthewfeickert added the tests pytest label Jan 20, 2023
@matthewfeickert matthewfeickert self-assigned this Jan 20, 2023
@review-notebook-app
Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@matthewfeickert matthewfeickert added the docs Documentation related label Jan 20, 2023
@codecov
Copy link

codecov bot commented Jan 20, 2023

Codecov Report

Base: 98.30% // Head: 98.30% // No change to project coverage 👍

Coverage data is based on head (14127ae) compared to base (14127ae).
Patch has no changes to coverable lines.

❗ Current head 14127ae differs from pull request most recent head 03106eb. Consider uploading reports for the commit 03106eb to get more accurate results

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2098   +/-   ##
=======================================
  Coverage   98.30%   98.30%           
=======================================
  Files          69       69           
  Lines        4531     4531           
  Branches      645      645           
=======================================
  Hits         4454     4454           
  Misses         45       45           
  Partials       32       32           
Flag Coverage Δ
contrib 97.88% <0.00%> (ø)
doctest 61.15% <0.00%> (ø)
unittests-3.10 96.31% <0.00%> (ø)
unittests-3.8 96.33% <0.00%> (ø)
unittests-3.9 96.35% <0.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@matthewfeickert
Copy link
Member Author

matthewfeickert commented Jan 20, 2023

Bug reproducible with

$ jupyter execute docs/examples/notebooks/learn/InterpolationCodes.ipynb
[NbClientApp] Executing docs/examples/notebooks/learn/InterpolationCodes.ipynb
[NbClientApp] Executing notebook with kernel: python3

which then hangs.

@matthewfeickert
Copy link
Member Author

matthewfeickert commented Jan 20, 2023

Freezing on the interact call of

from ipywidgets import interact

...

x = interact(
    lambda alpha: plot_interpolated_histogram(alpha, down_hist, nom_hist, up_hist),
    alpha=(-1, 1, 0.1),
)

of https://github.com/scikit-hep/pyhf/blob/3eef1fff2e6d4ccf474bbe51e2211cf690752b82/docs/examples/notebooks/learn/InterpolationCodes.ipynb for ipywidgets v8.0.2.

@matthewfeickert
Copy link
Member Author

Seems to be a general problem with interact https://ipywidgets.readthedocs.io/en/8.0.2/examples/Using%20Interact.html

as

$ curl -sL https://raw.githubusercontent.com/jupyter-widgets/ipywidgets/8.0.2/docs/source/examples/Using%20Interact.ipynb -o /tmp/Using-Interact.ipynb
$ jupyter execute /tmp/Using-Interact.ipynb                                                                                                           
[NbClientApp] Executing /tmp/Using-Interact.ipynb
[NbClientApp] Executing notebook with kernel: python3  # ...hangs

@matthewfeickert
Copy link
Member Author

matthewfeickert commented Jan 20, 2023

Temporary workaround locally:

$ jupytext --to py:percent docs/examples/notebooks/learn/InterpolationCodes.ipynb
[jupytext] Reading docs/examples/notebooks/learn/InterpolationCodes.ipynb in format ipynb
[jupytext] Updating the timestamp of docs/examples/notebooks/learn/InterpolationCodes.py
$ MPLBACKEND=agg python docs/examples/notebooks/learn/InterpolationCodes.py
interactive(children=(FloatSlider(value=0.0, description='alpha', max=1.0, min=-1.0), Output()), _dom_classes=('widget-interact',))
[[ 8.   8.2  8.4  8.6  8.8  9.   9.2  9.4  9.6  9.8 10. ]]
[[10.  10.3 10.6 10.9 11.2 11.5 11.8 12.1 12.4 12.7 13. ]]
[[15.  15.5 16.  16.5 17.  17.5 18.  18.5 19.  19.5 20. ]]
/home/feickert/Code/GitHub/pyhf/docs/examples/notebooks/learn/InterpolationCodes.py:221: UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure.
  plt.show()
interactive(children=(FloatSlider(value=0.0, description='alpha', max=1.0, min=-1.0), Output()), _dom_classes=('widget-interact',))

also just

$ MPLBACKEND=agg jupyter execute docs/examples/notebooks/learn/InterpolationCodes.ipynb
[NbClientApp] Executing docs/examples/notebooks/learn/InterpolationCodes.ipynb
[NbClientApp] Executing notebook with kernel: python3

@matthewfeickert matthewfeickert changed the title fix: Remove deprecated pylab module magic fix: Use non-gui matplotlib backend for tests to avoid hanging on ipywidges interact Jan 20, 2023
@matthewfeickert matthewfeickert changed the title fix: Use non-gui matplotlib backend for tests to avoid hanging on ipywidges interact fix: Use non-gui matplotlib backend for tests to avoid hanging on ipywidgets interact Jan 20, 2023
@matthewfeickert matthewfeickert marked this pull request as ready for review January 20, 2023 17:04
@matthewfeickert matthewfeickert force-pushed the fix/remove-deprecated-pylab branch from 21fd150 to 03106eb Compare January 20, 2023 17:29
@matthewfeickert matthewfeickert merged commit e942d85 into main Jan 20, 2023
@matthewfeickert matthewfeickert deleted the fix/remove-deprecated-pylab branch January 20, 2023 17:49
matthewfeickert added a commit that referenced this pull request May 16, 2023
* Backport components of:
   - PR #2046
   - PR #2098
   - PR #2113
   - PR #2115
   - PR #2145
   - PR #2198
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
docs Documentation related tests pytest
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants