Skip to content

Testing MPL with a notebook in binder#4544

Merged
1ucian0 merged 22 commits intoQiskit:masterfrom
1ucian0:binder
Jun 22, 2020
Merged

Testing MPL with a notebook in binder#4544
1ucian0 merged 22 commits intoQiskit:masterfrom
1ucian0:binder

Conversation

@1ucian0
Copy link
Member

@1ucian0 1ucian0 commented Jun 4, 2020

Fixes #4533
Fixes #2968

Summary

In the effort to improve the MPL drawer testing, this PR offers a way to do "visual" test. Here is the workflow:

  1. Somebody makes a PR that affects qiskit/visualization/matplotlib.py
  2. A bot adds a comment like this one:

Screen Shot 2020-06-04 at 1 45 03 PM

3. The link to the binder, triggers an online notebook that needs to be executed:

Screen Shot 2020-06-04 at 1 53 54 PM

4. Each image is compared with a reference manually.

Details of the PR

  • test/ipynb/mpl_tester.ipynb The notebook that is going to be run in Binder. It was cleaned up with nb-clean
  • test/ipynb/mpl/test_circuit_matplotlib_drawer.py The notebook runs this tests. They have no assert as their goal is to create the images. And check that there are no exceptions.
  • .gitignore The images from the previous point are stored in test/ipynb/mpl/*.png, so they are ignored.
  • test/ipynb/mpl/references/ Where the reference images are stored.
  • test/ipynb/results.py It is run in the second cell of the notebook for showing the results.
  • .github/workflows/binder_mpl.yml It's the action to add the comment when
    qiskit/visualization/matplotlib.py is modified.
  • postBuild Binder runs this file after the build, since matplotlib is not installed automatically

Further work

  • The rest of the MPL tests need to be moved to this format
  • (?) Do something similar with latex
  • Improve the result presentation (for example, with big images)
  • Does not show the results when there are no changes
  • Have a easy way to see image differences (something like substraction)

The binder to this PR can be found here https://mybinder.org/v2/gh/1ucian0/qiskit-terra/binder?filepath=test/ipynb/mpl_tester.ipynb

@1ucian0 1ucian0 requested a review from a team as a code owner June 4, 2020 18:55
@1ucian0
Copy link
Member Author

1ucian0 commented Jun 7, 2020

In fcd2830 I added a reference to the test generating the image file:

Screen Shot 2020-06-07 at 9 21 25 AM

@1ucian0
Copy link
Member Author

1ucian0 commented Jun 8, 2020

In f47b0f3 I added a "diff".

Screen Shot 2020-06-08 at 1 55 03 PM

@1ucian0
Copy link
Member Author

1ucian0 commented Jun 10, 2020

In a3a994f I added folding results.

When passing (default is folded):
Screen Shot 2020-06-10 at 1 59 17 PM

When failing (default is showing):
Screen Shot 2020-06-10 at 2 03 53 PM

When the reference is not found:
Screen Shot 2020-06-10 at 2 17 04 PM

@ajavadia
Copy link
Member

ajavadia commented Jun 10, 2020 via email

@1ucian0
Copy link
Member Author

1ucian0 commented Jun 10, 2020

This is awesome. Do you know if the diff occurs pixel by pixel? For example if I slightly shift an image to the right it’s still the same image but all the pixels are different compared to reference.

It's a pixel by pixel comparison. Unmatching pixels are going to be highlighted in the diff. If there is a shift, the reference image should be refreshed.

@1ucian0
Copy link
Member Author

1ucian0 commented Jun 10, 2020

I added autoexecution. The result can be seen here:
https://mybinder.org/v2/gh/1ucian0/qiskit-terra/binder?urlpath=apps/test/ipynb/mpl_tester.ipynb

@1ucian0 1ucian0 merged commit 970496a into Qiskit:master Jun 22, 2020
mtreinish added a commit to mtreinish/qiskit-core that referenced this pull request Jul 9, 2020
In Qiskit#4544 a github action workflow was added to attempt to automate
leaving a comment on PRs that made changes to the matplotlib with a link
to a jupyter environment running in binder that will show a visual diff
of the changes being made. But this workflow can't work for PRs opened
from forks (which is most of them) because the permissions for the
github actions workflow only allows reading from the github api [1]
and will not be able to leave comments. This is done for obvious
security reasons because a job triggered by an external fork can run
arbitrary code so you don't want to give any elevated permissions until
the code has been verified. Since this approach will never be viable
using github actions (or a similar ci platform) this commit removes the
job.
1ucian0 pushed a commit that referenced this pull request Jul 9, 2020
In #4544 a github action workflow was added to attempt to automate
leaving a comment on PRs that made changes to the matplotlib with a link
to a jupyter environment running in binder that will show a visual diff
of the changes being made. But this workflow can't work for PRs opened
from forks (which is most of them) because the permissions for the
github actions workflow only allows reading from the github api [1]
and will not be able to leave comments. This is done for obvious
security reasons because a job triggered by an external fork can run
arbitrary code so you don't want to give any elevated permissions until
the code has been verified. Since this approach will never be viable
using github actions (or a similar ci platform) this commit removes the
job.
faisaldebouni pushed a commit to faisaldebouni/qiskit-terra that referenced this pull request Aug 5, 2020
faisaldebouni pushed a commit to faisaldebouni/qiskit-terra that referenced this pull request Aug 5, 2020
In Qiskit#4544 a github action workflow was added to attempt to automate
leaving a comment on PRs that made changes to the matplotlib with a link
to a jupyter environment running in binder that will show a visual diff
of the changes being made. But this workflow can't work for PRs opened
from forks (which is most of them) because the permissions for the
github actions workflow only allows reading from the github api [1]
and will not be able to leave comments. This is done for obvious
security reasons because a job triggered by an external fork can run
arbitrary code so you don't want to give any elevated permissions until
the code has been verified. Since this approach will never be viable
using github actions (or a similar ci platform) this commit removes the
job.
@galeinston galeinston mentioned this pull request Sep 15, 2020
@omarcostahamido
Copy link
Contributor

wow, this so cool. I always wondered if github would be able to one day report diffs on images in a more human readable way... you just did it 👏

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

reference circuit to check matplotlib changes How to test visualization?

4 participants