-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Adds support to PassManager drawer to display stages #9128
Conversation
Thank you for opening a new pull request. Before your PR can be merged it will first need to pass continuous integration tests and be reviewed. Sometimes the review process can be slow, so please be patient. While you're waiting, please feel free to review other open PRs. While only a subset of people are authorized to approve pull requests for merging, everyone is encouraged to review open pull requests. Doing reviews helps reduce the burden on the core team and helps make the project's code better for everyone. One or more of the the following people are requested to review this:
|
a52f261
to
4b36fd1
Compare
Pull Request Test Coverage Report for Build 4059859471
💛 - Coveralls |
cc @mtreinish |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @psschwei thanks for your work on this! @mtreinish is away on vacation so it might be a little while before he reviews it. In the meantime could you add some screenshots to this PR of how the drawer renders the result with your changes?
releasenotes/notes/staged-pass-manager-drawer-f1da0308895a30d9.yaml
Outdated
Show resolved
Hide resolved
Here's a very short example (that I borrowed from somewhere in the Qiskit docs, but didn't bookmark exactly where): from qiskit.providers.fake_provider import FakeLagosV2
from qiskit.transpiler.preset_passmanagers import generate_preset_pass_manager
backend=FakeLagosV2()
pass_manager = generate_preset_pass_manager(3, backend)
pass_manager.draw() Here's what it looked like before these changes: and here's the result with the changes from this PR: |
4b36fd1
to
9091d39
Compare
@mtreinish @1ucian0 gentle ping |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the delay in review, I took some time off at the end of 2022 and this fell through the cracks before I took off.
Overall this LGTM this is basically what I had in mind and it'll be great to have this visualization improved to properly show stages. I had a couple inline comments. But the biggest thing I think is the code duplication. Right now the inner subgraph being built is essentially copying what pass_manager_drawer()
is doing. I feel like it would be best to just have a private function that is given a Cluster
and PassManager
(which each stage is) and then adds the subgraphs, nodes, and edges to it. Then most of the code will be shared between the two functions.
@@ -179,17 +279,3 @@ def pass_manager_drawer(pass_manager, filename=None, style=None, raw=False): | |||
if filename: | |||
image.save(filename, "PNG") | |||
return image | |||
|
|||
|
|||
def _get_node_color(pss, style): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note: this is still there on line 101 or thereabouts, git diff just makes it look like a deletion / readdition
seems there's an issue where the image won't load for a staged draw... looking into that now edit: looks to be something with edit2: problem seems to be with this line, as the image renders properly if I comment out the line: https://github.com/Qiskit/qiskit-terra/blob/b4e10d5bb2750cc42e8787c17544d97d07158587/qiskit/visualization/utils.py#L25 digging a little more, looks like the issue is with the offset... existing value of whereas updating the offset to that said, I don't know the codebase well enough to be able to say if changing the offset is a good idea. for now, I've just removed the trim call in the drawer output, but am open to something else if you think that makes more sense |
@@ -174,22 +274,7 @@ def pass_manager_drawer(pass_manager, filename=None, style=None, raw=False): | |||
graph.write_png(tmppath) # pylint: disable=no-member | |||
|
|||
image = Image.open(tmppath) | |||
image = utils._trim(image) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
opted for removing the trim versus messing with the offset (as per #9128 (comment))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This makes sense to me. The trim here isn't super necessary, IIRC (and I probably don't since it's been a while since I dove down these code paths) this was added primarily for the latex circuit visualization which ends up with a pillow image object for an entire pdf page and the image is trimmed to avoid excess whitespace. For these image files generated by graphviz we don't have this concern, so the trim call was mostly superfluous.
Signed-off-by: Paul S. Schweigert <paul@paulschweigert.com>
Signed-off-by: Paul S. Schweigert <paul@paulschweigert.com>
Signed-off-by: Paul S. Schweigert <paul@paulschweigert.com>
Signed-off-by: Paul S. Schweigert <paul@paulschweigert.com>
Signed-off-by: Paul S. Schweigert <paul@paulschweigert.com>
Signed-off-by: Paul S. Schweigert <paul@paulschweigert.com>
@mtreinish this should be ready for another review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This LGTM now, thanks for working on this and updating based on my earlier comments. Again, sorry for the slow reviews on this it kept falling off my radar because of vacation and then the rush in the lead up to the 0.23.0 release last week. I just left a quick inline suggestion on some docstring formatting fixes which I'll apply before tagging this for merge.
A quick follow up PR, if you're interested would be to make the same doc typo fixes in pass_manager_drawer
but no pressure.
@@ -174,22 +274,7 @@ def pass_manager_drawer(pass_manager, filename=None, style=None, raw=False): | |||
graph.write_png(tmppath) # pylint: disable=no-member | |||
|
|||
image = Image.open(tmppath) | |||
image = utils._trim(image) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This makes sense to me. The trim here isn't super necessary, IIRC (and I probably don't since it's been a while since I dove down these code paths) this was added primarily for the latex circuit visualization which ends up with a pillow image object for an entire pdf page and the image is trimmed to avoid excess whitespace. For these image files generated by graphviz we don't have this concern, so the trim call was mostly superfluous.
This commit fixes some copy paste issues around the sphinx syntax for hyperlinks in the docstring for the new staged_pass_manager_drawer() function.
Yeah, I can do that. |
* adds support to PassManager drawer to display stages Signed-off-by: Paul S. Schweigert <paul@paulschweigert.com> * reviewer comments Signed-off-by: Paul S. Schweigert <paul@paulschweigert.com> * label, DRY code Signed-off-by: Paul S. Schweigert <paul@paulschweigert.com> * DRY output Signed-off-by: Paul S. Schweigert <paul@paulschweigert.com> * remove trim from passmanger draw output Signed-off-by: Paul S. Schweigert <paul@paulschweigert.com> * linting Signed-off-by: Paul S. Schweigert <paul@paulschweigert.com> * unused import Signed-off-by: Paul S. Schweigert <paul@paulschweigert.com> * Fix sphinx syntax for hyperlinks This commit fixes some copy paste issues around the sphinx syntax for hyperlinks in the docstring for the new staged_pass_manager_drawer() function. --------- Signed-off-by: Paul S. Schweigert <paul@paulschweigert.com> Co-authored-by: Matthew Treinish <mtreinish@kortar.org> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Signed-off-by: Paul S. Schweigert paul@paulschweigert.com
Fixes #8934
Summary
Adds support to PassManager drawer to display stages
Details and comments
The ask was to add an outer box around the passes for each stage. This meant implementing a new
draw()
method forStagedPassManager
that: