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

Update plot_gate_map() family to leverage graphviz for visualization #10208

Merged
merged 119 commits into from
Sep 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
119 commits
Select commit Hold shift + click to select a range
6a46be1
Update gate_map.py
maxwell04-wq Jun 6, 2023
c27c921
Removed has_rustworkx instances
maxwell04-wq Jun 6, 2023
5d32cd1
Added release notes
maxwell04-wq Jun 6, 2023
e4add11
Update test_gate_map.py
maxwell04-wq Jun 6, 2023
e52b792
Merge branch 'main' into main
maxwell04-wq Jun 6, 2023
da5da55
Formatted gate_map.py
maxwell04-wq Jun 6, 2023
f38f963
Format test_gate_map.py
maxwell04-wq Jun 6, 2023
6d46d23
Merge branch 'main' into main
maxwell04-wq Jun 7, 2023
7145ca6
Merge branch 'main' into main
maxwell04-wq Jun 7, 2023
f470013
Added release notes for the fix of #9031
maxwell04-wq Jun 8, 2023
f4f7546
Merge branch 'main' into main
maxwell04-wq Jun 10, 2023
ebc8c57
Update gate_map.py
maxwell04-wq Jun 11, 2023
a39a8ce
Update test_gate_map.py
maxwell04-wq Jun 11, 2023
a021e07
Update test_gate_map.py
maxwell04-wq Jun 11, 2023
ebd4045
Update gate_map.py for rerunning tests.
maxwell04-wq Jun 11, 2023
1a0af9a
Update test_clifford.py
maxwell04-wq Jun 12, 2023
d729985
Merge branch 'Qiskit:main' into main
maxwell04-wq Jun 13, 2023
814634b
Update gate_map.py to reuse rx.draw_graphiz
maxwell04-wq Jun 13, 2023
6205df9
Update test_gate_map.py to omit qubit_visualization
maxwell04-wq Jun 13, 2023
9ea26d3
Update test_gate_map.py to fix formatting changes
maxwell04-wq Jun 13, 2023
8d92e36
Update gate_map.py
maxwell04-wq Jun 13, 2023
33e6560
Update gate_map.py
maxwell04-wq Jun 13, 2023
530a8b1
Update gate_map.py
maxwell04-wq Jun 13, 2023
e3f7211
Update test_gate_map.py
maxwell04-wq Jun 13, 2023
22e7f57
Merge branch 'main' into main
maxwell04-wq Jun 13, 2023
a230239
Update test_gate_map.py
maxwell04-wq Jun 14, 2023
ffd1eb8
Update gate_map.py
maxwell04-wq Jun 14, 2023
1097ecd
Update gate_map.py
maxwell04-wq Jun 14, 2023
4214a6a
Update gate_map.py
maxwell04-wq Jun 14, 2023
b666322
Update gate_map.py
maxwell04-wq Jun 14, 2023
1277012
Update gate_map.py
maxwell04-wq Jun 14, 2023
53bc305
Update gate_map.py
maxwell04-wq Jun 14, 2023
e51c821
Update gate_map.py
maxwell04-wq Jun 14, 2023
d2d60d3
Merge branch 'main' into main
maxwell04-wq Jun 14, 2023
5329ad4
Update test_gate_map.py
maxwell04-wq Jun 14, 2023
7974bd4
Update test_gate_map.py to add rx import
maxwell04-wq Jun 14, 2023
893e82c
Update test_gate_map.py
maxwell04-wq Jun 14, 2023
521862c
Update test_gate_map.py
maxwell04-wq Jun 14, 2023
4c643bd
Update test_gate_map.py to fix imports
maxwell04-wq Jun 14, 2023
8a1a3b6
Update test_gate_map.py to add HAS_GRAPHVIZ to all tests
maxwell04-wq Jun 14, 2023
31f3799
Update test_graph_matplotlib_drawer.py to have HAS_GRAPHVIZ
maxwell04-wq Jun 14, 2023
c30bf25
Update test_graph_matplotlib_drawer.py to add HAS_GRAPHVIZ import to …
maxwell04-wq Jun 14, 2023
ea10b35
Update test_graph_matplotlib_drawer.py to add GRAPHVIZ check to the c…
maxwell04-wq Jun 14, 2023
4baa0fe
Update test_graph_matplotlib_drawer.py to add HAS_GRAPHVIZ to both ga…
maxwell04-wq Jun 14, 2023
f76f09e
Update test_graph_matplotlib_drawer.py
maxwell04-wq Jun 14, 2023
155e08b
Update test_graph_matplotlib_drawer.py
maxwell04-wq Jun 14, 2023
64a9532
Update test_graph_matplotlib_drawer.py
maxwell04-wq Jun 14, 2023
cf4fad3
Merge branch 'main' into main
maxwell04-wq Jun 15, 2023
4bad579
Fixed the `font_color` parameter in `gate_map.py/plot_gate_map()`
maxwell04-wq Jun 15, 2023
50ccb03
Modify color_edge function to increase speed
maxwell04-wq Jun 15, 2023
7e5db1d
Update gate_map.py to fix formatting
maxwell04-wq Jun 15, 2023
41abed9
Merge branch 'main' into main
maxwell04-wq Jun 16, 2023
4e3a810
Update gate_map.py to shift seaborn import to `plot_error_map`
maxwell04-wq Jun 16, 2023
6c6f39b
Add HAS_SEABORN to test_plot_error_map
maxwell04-wq Jun 16, 2023
f2879ec
Reformat gate_map.py
maxwell04-wq Jun 16, 2023
907d69b
Merge branch 'main' into main
maxwell04-wq Jun 16, 2023
688bad4
Fixed node autoscaling in `gate_map.py` graphs
maxwell04-wq Jun 16, 2023
0e006ef
Add return type to `test_from_gate_with_cyclic_definition ` in `test_…
maxwell04-wq Jun 16, 2023
5845412
Merge branch 'main' into main
maxwell04-wq Jun 17, 2023
4134d2a
Update update-gate_map-visualizations-6ea907a0502fdc1a.yaml
maxwell04-wq Jun 17, 2023
eaecc7a
Rename update-gate_map-visualizations-6ea907a0502fdc1a.yaml to update…
maxwell04-wq Jun 17, 2023
e7ceff4
Update update-gate-map-visualizations-6ea907a0502fdc1a.yaml
maxwell04-wq Jun 17, 2023
ddf8613
Update update-gate-map-visualizations-6ea907a0502fdc1a.yaml
maxwell04-wq Jun 18, 2023
6427079
Update pauli_op.py to use np.prod
maxwell04-wq Jun 18, 2023
6d734d7
Update operator.py to use np.prod
maxwell04-wq Jun 18, 2023
88420e9
Update pauli_sum_op.py to use np.prod
maxwell04-wq Jun 18, 2023
f7d6446
Update random.py to use np.product
maxwell04-wq Jun 18, 2023
f55c0a1
Update chi.py to use np.prod
maxwell04-wq Jun 18, 2023
d33f3d1
Replace np.product with np.prod
maxwell04-wq Jun 18, 2023
de5f8cc
Update ptm.py to use np.prod
maxwell04-wq Jun 18, 2023
24d86c0
Update stinespring.py to use np.prod
maxwell04-wq Jun 18, 2023
3369fc9
Update superop.py to use np.prod
maxwell04-wq Jun 18, 2023
e5f383b
Update transformations.py to use np.prod
maxwell04-wq Jun 18, 2023
8c19478
Update densitymatrix.py to use np.prod
maxwell04-wq Jun 18, 2023
9ae6fa9
Update random.py to use np.prod
maxwell04-wq Jun 18, 2023
4f48719
Update statevector.py to use np.prod
maxwell04-wq Jun 18, 2023
0291cbd
Update local_readout_mitigator.py to use np.prod
maxwell04-wq Jun 18, 2023
0f73838
Update unitary_synthesis.py to use np.prod
maxwell04-wq Jun 18, 2023
ea9da64
Update test_random.py to use np.prod
maxwell04-wq Jun 18, 2023
271d333
Update test_scalar_op.py to use np.prod
maxwell04-wq Jun 18, 2023
e4b85c4
Update test_random.py to use np.prod
maxwell04-wq Jun 18, 2023
bf1fd3d
Merge branch 'main' into main
maxwell04-wq Jun 19, 2023
febe483
Merge branch 'main' into main
maxwell04-wq Jun 19, 2023
7dbabf7
Merge branch 'main' into main
maxwell04-wq Jun 21, 2023
7b703ab
Update test_clifford.py to remove debugging code
maxwell04-wq Jun 21, 2023
bf8040e
Merge branch 'main' into main
maxwell04-wq Jun 23, 2023
065776b
Merge branch 'main' into main
maxwell04-wq Jun 26, 2023
cf21c9e
Merge branch 'main' into main
maxwell04-wq Jun 30, 2023
e1225af
Merge branch 'main' into main
mtreinish Jul 10, 2023
d27df30
Merge remote-tracking branch 'origin/main'
mtreinish Jul 11, 2023
d719620
Move matplotlib imports to occur at run time
mtreinish Jul 11, 2023
2b88152
Apply suggestions from code review
mtreinish Jul 11, 2023
a72eaa3
Move matplotlib_close_if_inline to runtime import too
mtreinish Jul 11, 2023
884f8a9
Merge branch 'main' into main
maxwell04-wq Jul 13, 2023
847f532
Flatten parallel edges
maxwell04-wq Jul 13, 2023
26b2c8d
Merge branch 'main' into main
maxwell04-wq Jul 14, 2023
7bca09e
Merge branch 'main' into main
maxwell04-wq Jul 14, 2023
31bdaba
Merge branch 'main' into main
mtreinish Jul 19, 2023
e34c4c5
Fix 1 qubit backend handling
mtreinish Jul 19, 2023
bbe5a7a
Merge branch 'main' into main
maxwell04-wq Jul 19, 2023
fe815c2
Merge branch 'main' into main
maxwell04-wq Jul 20, 2023
ebd288d
Fix qubit label and font sizes
maxwell04-wq Jul 20, 2023
ee6f960
Merge branch 'main' into main
maxwell04-wq Jul 20, 2023
3ff3635
Merge branch 'main' into main
maxwell04-wq Jul 20, 2023
671f005
Merge branch 'main' into main
maxwell04-wq Jul 20, 2023
8bdfcbd
Merge branch 'main' into main
maxwell04-wq Jul 20, 2023
e4c8057
Merge branch 'main' into main
maxwell04-wq Jul 27, 2023
571cd8a
Merge branch 'main' into main
maxwell04-wq Jul 27, 2023
31940df
Merge branch 'main' into main
1ucian0 Aug 30, 2023
894d143
new reference images
1ucian0 Sep 1, 2023
7324be5
Merge branch 'main' into main
1ucian0 Sep 1, 2023
81c049b
Merge branch 'main' into main
maxwell04-wq Sep 4, 2023
4c5bf89
Merge branch 'main' into main
mtreinish Sep 21, 2023
2e2f3b0
Adjust font scaling
mtreinish Sep 21, 2023
641d9e3
Update reference images
mtreinish Sep 22, 2023
cef10fa
Remove unrelated reference file update
mtreinish Sep 22, 2023
2e459fd
Improve formatting
mtreinish Sep 22, 2023
b45b991
Adjust pixel scaling factor
mtreinish Sep 22, 2023
7ad96fb
Update reference images with formatting changes
mtreinish Sep 22, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
267 changes: 105 additions & 162 deletions qiskit/visualization/gate_map.py

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
features:
- |
The visualizations from the :func:`~.plot_gate_map`, :func:`~.plot_coupling_map`.
:func:`~.plot_error_map`, and :func:`~.plot_circuit_layout` functions have been significantly
improved for rendering layouts of backends with large numbers of qubits. This was accomplished
by leveraging `graphviz <https://graphviz.org/>`__ through rustworkx's ``graphviz_draw()`` function
to perform a more sophisticated algorithmic graph layout that scales for large numbers of
qubits.

upgrade:
- |
The visualization functions: :func:`~.plot_gate_map`, :func:`~.plot_coupling_map`.
:func:`~.plot_error_map`, and :func:`~.plot_circuit_layout` now depend on
`graphviz <https://graphviz.org/>`__ being installed to function. This change was
necessary to enable visualizing backends with larger numbers of qubits. This
additional external requirement is in addition to the existing optional dependencies
these functions previously required. You find details on how to install
graphviz here: https://graphviz.org/download/
20 changes: 19 additions & 1 deletion test/python/visualization/test_gate_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ class TestGateMap(QiskitVisualizationTestCase):
)

@data(*backends)
@unittest.skipIf(not optionals.HAS_MATPLOTLIB, "matplotlib not available.")
@unittest.skipUnless(optionals.HAS_GRAPHVIZ, "Graphviz not installed")
def test_plot_gate_map(self, backend):
"""tests plotting of gate map of a device (20 qubit, 16 qubit, 14 qubit and 5 qubit)"""
n = backend.configuration().n_qubits
Expand All @@ -67,6 +69,8 @@ def test_plot_gate_map(self, backend):
plt.close(fig)

@data(*backends)
@unittest.skipIf(not optionals.HAS_MATPLOTLIB, "matplotlib not available.")
@unittest.skipUnless(optionals.HAS_GRAPHVIZ, "Graphviz not installed")
def test_plot_circuit_layout(self, backend):
"""tests plot_circuit_layout for each device"""
layout_length = int(backend._configuration.n_qubits / 2)
Expand All @@ -83,9 +87,11 @@ def test_plot_circuit_layout(self, backend):
with BytesIO() as img_buffer:
fig.savefig(img_buffer, format="png")
img_buffer.seek(0)
self.assertImagesAreEqual(Image.open(img_buffer), img_ref, 0.1)
self.assertImagesAreEqual(Image.open(img_buffer), img_ref, 0.2)
plt.close(fig)

@unittest.skipIf(not optionals.HAS_MATPLOTLIB, "matplotlib not available.")
@unittest.skipUnless(optionals.HAS_GRAPHVIZ, "Graphviz not installed")
def test_plot_gate_map_no_backend(self):
"""tests plotting of gate map without a device"""
n_qubits = 8
Expand All @@ -101,6 +107,9 @@ def test_plot_gate_map_no_backend(self):
self.assertImagesAreEqual(Image.open(img_buffer), img_ref, 0.2)
plt.close(fig)

@unittest.skipIf(not optionals.HAS_MATPLOTLIB, "matplotlib not available.")
@unittest.skipUnless(optionals.HAS_GRAPHVIZ, "Graphviz not installed")
@unittest.skipUnless(optionals.HAS_SEABORN, "Seaborn not installed")
def test_plot_error_map_backend_v1(self):
"""Test plotting error map with fake backend v1."""
backend = FakeKolkata()
Expand All @@ -112,6 +121,9 @@ def test_plot_error_map_backend_v1(self):
self.assertImagesAreEqual(Image.open(img_buffer), img_ref, 0.2)
plt.close(fig)

@unittest.skipIf(not optionals.HAS_MATPLOTLIB, "matplotlib not available.")
@unittest.skipUnless(optionals.HAS_GRAPHVIZ, "Graphviz not installed")
@unittest.skipUnless(optionals.HAS_SEABORN, "Seaborn not installed")
def test_plot_error_map_backend_v2(self):
"""Test plotting error map with fake backend v2."""
backend = FakeKolkataV2()
Expand All @@ -123,6 +135,9 @@ def test_plot_error_map_backend_v2(self):
self.assertImagesAreEqual(Image.open(img_buffer), img_ref, 0.2)
plt.close(fig)

@unittest.skipIf(not optionals.HAS_MATPLOTLIB, "matplotlib not available.")
@unittest.skipUnless(optionals.HAS_GRAPHVIZ, "Graphviz not installed")
@unittest.skipUnless(optionals.HAS_SEABORN, "Seaborn not installed")
def test_plot_error_map_over_100_qubit(self):
"""Test plotting error map with large fake backend."""
backend = FakeWashington()
Expand All @@ -134,6 +149,9 @@ def test_plot_error_map_over_100_qubit(self):
self.assertImagesAreEqual(Image.open(img_buffer), img_ref, 0.2)
plt.close(fig)

@unittest.skipIf(not optionals.HAS_MATPLOTLIB, "matplotlib not available.")
@unittest.skipUnless(optionals.HAS_GRAPHVIZ, "Graphviz not installed")
@unittest.skipUnless(optionals.HAS_SEABORN, "Seaborn not installed")
def test_plot_error_map_over_100_qubit_backend_v2(self):
"""Test plotting error map with large fake backendv2."""
backend = FakeWashingtonV2()
Expand Down
Binary file modified test/visual/mpl/graph/references/16_qubit_gate_map.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/visual/mpl/graph/references/1_qubit_gate_map.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/visual/mpl/graph/references/27_qubit_gate_map.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/visual/mpl/graph/references/5_qubit_gate_map.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/visual/mpl/graph/references/65_qubit_gate_map.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/visual/mpl/graph/references/7_qubit_gate_map.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/visual/mpl/graph/references/coupling_map.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/visual/mpl/graph/references/figsize.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/visual/mpl/graph/references/font_color.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/visual/mpl/graph/references/line_color.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/visual/mpl/graph/references/qubit_color.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/visual/mpl/graph/references/qubit_labels.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/visual/mpl/graph/references/qubit_size.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.