Skip to content

Use pygraphviz to render pass manager drawings (step 1 of #16544) - #16675

Open
VedantMahadik-qc wants to merge 1 commit into
Qiskit:mainfrom
VedantMahadik-qc:use-pygraphviz-instead-of-graphviz
Open

Use pygraphviz to render pass manager drawings (step 1 of #16544)#16675
VedantMahadik-qc wants to merge 1 commit into
Qiskit:mainfrom
VedantMahadik-qc:use-pygraphviz-instead-of-graphviz

Conversation

@VedantMahadik-qc

Copy link
Copy Markdown

AI/LLM disclosure

  • I didn't use LLM tooling or only used it privately.
  • I used the following tool to help write this PR description:
  • I used the following tool to generate or modify code:

Implements step 1 of the plan @1ucian0 outlined in #16544: adds 'pygraphviz' as a new optional dependency and removes the requirement for a manually installed system Graphviz when drawing pass managers.

Changes

  • New 'HAS_PYGRAPHVIZ' lazy tester in 'qiskit.utils.optionals' (with docs entry).
  • 'pass_manager_drawer' / 'staged_pass_manager_drawer' now require pygraphviz instead of system Graphviz. Graph construction still uses pydot (removing pydot is step 2, pending the rustworkx question); rendering now hands the DOT source to pygraphviz, whose 2.0+ wheels bundle the Graphviz binaries.
  • Added 'pygraphviz>=2.0' to the 'visualization' extra and 'optionals-interactive' group (2.0 is the first release with bundled binaries).
  • Updated test skip conditions and added a release note.

Windows wheel confirmation

On Windows 11 / Python 3.11 with no system Graphviz installed, 'pip install pygraphviz' fetched the prebuilt 'pygraphviz-2.0.1-cp311-win_amd64' wheel, and 'pass_manager_drawer' rendered successfully end-to-end – which is the platform confirmation step 1 is meant to provide.

Also fixes a latent Windows bug

Testing this path exposed a pre-existing issue: 'make_output' called 'os.remove' on the temporary PNG while 'PIL.Image.open's' lazy file handle was still open, raising 'PermissionError' on Windows. The image is now loaded via a context manager and copied in-memory. (This predates this PR but was unreachable in practice, since the drawer previously required a system Graphviz install that Windows users rarely had.)

'test_pass_manager_drawer.py' passes 2/2 locally on Windows — these tests were previously always skipped on this platform.

The rustworkx-based call sites ('dag_visualization.py', 'gate_map.py', etc.) still legitimately require 'HAS_GRAPHVIZ', so that tester is unchanged. If this goes beyond step 1, I'm happy to trim it back.

Part of #16544 (step 2 - moving off pydot/dot-calls to follow separately).

@VedantMahadik-qc
VedantMahadik-qc requested a review from a team as a code owner July 28, 2026 14:49
@qiskit-bot qiskit-bot added the Community PR PRs from contributors that are not 'members' of the Qiskit repo label Jul 28, 2026
@qiskit-bot

Copy link
Copy Markdown
Collaborator

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 following people are relevant to this code:

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


Vedant seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

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

Labels

Community PR PRs from contributors that are not 'members' of the Qiskit repo

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

3 participants