Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
1e4b7b3
fixed issue 4391 by updating idle_wires() in dagcircuit and skipping …
sar49 May 20, 2020
fb99bc6
fixed issue 4179 by updating matplotlib scaler
sar49 May 24, 2020
8de9408
fixed issue 4179 by updating matplotlib drawer and matplotlib testcase
sar49 May 25, 2020
02cabde
fixed issue 4179 by updating matplotlib drawer and updating matplotli…
sar49 May 25, 2020
64df6d3
Update dagcircuit.py
sar49 May 25, 2020
7ad4695
Update dagcircuit.py
sar49 May 25, 2020
001b938
Update dagcircuit.py
sar49 May 25, 2020
e9e4879
Update dagcircuit.py
sar49 May 25, 2020
fd6bed1
Update matplotlib.py
sar49 May 25, 2020
e482de7
Update text.py
sar49 May 25, 2020
e8027a5
Update text.py
sar49 May 25, 2020
69d87c3
Update matplotlib.py
sar49 May 25, 2020
5342609
Update test_circuit_matplotlib_drawer.py
sar49 May 26, 2020
792d5bc
Update test_circuit_matplotlib_drawer.py
sar49 May 26, 2020
a98d39e
Update test_circuit_matplotlib_drawer.py
sar49 May 26, 2020
51d401f
Update test_circuit_matplotlib_drawer.py
sar49 May 26, 2020
8655ef8
Update test_circuit_matplotlib_drawer.py
sar49 May 26, 2020
3cdf437
fixed issue 4563 by updating matplotlib drawer
sar49 Jun 11, 2020
6a788e6
Fixes issie 4179
sar49 Jun 13, 2020
a64410f
Update matplotlib.py
sar49 Jun 13, 2020
c5661a1
Update test_circuit_matplotlib_drawer.py
sar49 Jun 13, 2020
d7822ed
Delete matplotlib_barriers_ref2.png
sar49 Jun 13, 2020
c06809b
Add files via upload
sar49 Jun 13, 2020
c1130e4
Update matplotlib.py
sar49 Jun 13, 2020
f682769
Update matplotlib.py
sar49 Jun 13, 2020
3273aab
Update visualization.py
sar49 Jun 13, 2020
817bccc
Merge branch 'master' into fixissue4179
sar49 Jun 23, 2020
e418565
Merge branch 'master' into fixissue4179
sar49 Jun 24, 2020
8b88f1c
move test_conditional
1ucian0 Jun 25, 2020
762e9cc
plot_barriers
1ucian0 Jun 25, 2020
02ea692
test/ipynb/mpl/references/plot_barriers.png no needed
1ucian0 Jun 25, 2020
841ec95
Update test_circuit_matplotlib_drawer.py
sar49 Jun 25, 2020
81c5d16
Merge branch 'master' into fixissue4179
sar49 Jun 25, 2020
8bb3a0d
Merge branch 'master' into fixissue4179
sar49 Jun 25, 2020
63df24c
Update test_circuit_matplotlib_drawer.py
sar49 Jun 25, 2020
6cf7351
Merge branch 'master' into fixissue4179
sar49 Jun 26, 2020
1b33cd8
Merge branch 'master' into fixissue4179
1ucian0 Jun 26, 2020
8e635ba
merge
1ucian0 Jul 1, 2020
d700885
duplicated test
1ucian0 Jul 1, 2020
47e0bf1
test_scale
1ucian0 Jul 1, 2020
5eb85e6
new refs
1ucian0 Jul 1, 2020
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
33 changes: 16 additions & 17 deletions qiskit/visualization/matplotlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@

WID = 0.65
HIG = 0.65
DEFAULT_SCALE = 4.3
PORDER_GATE = 5
PORDER_LINE = 3
PORDER_REGLINE = 2
Expand Down Expand Up @@ -111,7 +110,7 @@ def __init__(self, qregs, cregs, ops,
'To install, run "pip install matplotlib".')

self._ast = None
self._scale = DEFAULT_SCALE * scale
self._scale = scale
self._creg = []
self._qreg = []
self._registers(cregs, qregs)
Expand Down Expand Up @@ -220,26 +219,26 @@ def _custom_multiqubit_gate(self, xy, cxy=None, fc=None, wide=True, text=None,
# Annotate inputs
for bit, y in enumerate([x[1] for x in xy]):
self.ax.text(xpos - 0.45 * wid, y, str(bit), ha='left', va='center',
fontsize=self._style.fs, color=self._style.gt,
fontsize=self._scale * self._style.fs, color=self._style.gt,
clip_on=True, zorder=PORDER_TEXT)

if text:

disp_text = text
if subtext:
self.ax.text(xpos, ypos + 0.5 * height, disp_text, ha='center',
va='center', fontsize=self._style.fs,
va='center', fontsize=self._scale * self._style.fs,
color=self._style.gt, clip_on=True,
zorder=PORDER_TEXT)
self.ax.text(xpos, ypos + 0.3 * height, subtext, ha='center',
va='center', fontsize=self._style.sfs,
va='center', fontsize=self._scale * self._style.sfs,
color=self._style.sc, clip_on=True,
zorder=PORDER_TEXT)
else:
self.ax.text(xpos, ypos + .5 * (qubit_span - 1), disp_text,
ha='center',
va='center',
fontsize=self._style.fs,
fontsize=self._scale * self._style.fs,
color=self._style.gt,
clip_on=True,
zorder=PORDER_TEXT,
Expand Down Expand Up @@ -297,16 +296,16 @@ def _gate(self, xy, fc=None, wide=False, text=None, subtext=None):
disp_text = text
if subtext:
self.ax.text(xpos, ypos + 0.15 * HIG, disp_text, ha='center',
va='center', fontsize=font_size,
va='center', fontsize=self._scale * font_size,
color=disp_color, clip_on=True,
zorder=PORDER_TEXT)
self.ax.text(xpos, ypos - 0.3 * HIG, subtext, ha='center',
va='center', fontsize=sub_font_size,
va='center', fontsize=self._scale * sub_font_size,
color=sub_color, clip_on=True,
zorder=PORDER_TEXT)
else:
self.ax.text(xpos, ypos, disp_text, ha='center', va='center',
fontsize=font_size,
fontsize=self._scale * font_size,
color=disp_color,
clip_on=True,
zorder=PORDER_TEXT)
Expand All @@ -315,7 +314,7 @@ def _subtext(self, xy, text):
xpos, ypos = xy

self.ax.text(xpos, ypos - 0.3 * HIG, text, ha='center', va='top',
fontsize=self._style.sfs,
fontsize=self._scale * self._style.sfs,
color=self._style.tc,
clip_on=True,
zorder=PORDER_TEXT)
Expand All @@ -327,7 +326,7 @@ def _sidetext(self, xy, text):
# another 0.0375 over
xp = xpos + 0.15 + (0.0375 * len(text))
self.ax.text(xp, ypos + HIG, text, ha='center', va='top',
fontsize=self._style.sfs,
fontsize=self._scale * self._style.sfs,
color=self._style.tc,
clip_on=True,
zorder=PORDER_TEXT)
Expand Down Expand Up @@ -392,7 +391,7 @@ def _measure(self, qxy, cxy, cid):
# target
if self._style.bundle:
self.ax.text(cx + .25, cy + .1, str(cid), ha='left', va='bottom',
fontsize=0.8 * self._style.fs,
fontsize=self._scale * 0.8 * self._style.fs,
color=self._style.tc,
clip_on=True,
zorder=PORDER_TEXT)
Expand Down Expand Up @@ -520,7 +519,7 @@ def draw(self, filename=None, verbose=False):
fig_w = _xr - _xl
fig_h = _yt - _yb
if self._style.figwidth < 0.0:
self._style.figwidth = fig_w * self._scale * self._style.fs / 72 / WID
self._style.figwidth = fig_w * 4.3 * self._scale * self._style.fs / 72 / WID
self.figure.set_size_inches(self._style.figwidth, self._style.figwidth * fig_h / fig_w)
if filename:
self.figure.savefig(filename, dpi=self._style.dpi,
Expand Down Expand Up @@ -615,7 +614,7 @@ def _draw_regs_sub(self, n_fold, feedline_l=False, feedline_r=False):
label = qreg['label']
y = qreg['y'] - n_fold * (self._cond['n_lines'] + 1)
self.ax.text(self.x_offset - 0.2, y, label, ha='right', va='center',
fontsize=1.25 * self._style.fs,
fontsize=self._scale * 1.25 * self._style.fs,
color=self._style.tc,
clip_on=True,
zorder=PORDER_TEXT)
Expand All @@ -641,12 +640,12 @@ def _draw_regs_sub(self, n_fold, feedline_l=False, feedline_r=False):
zorder=PORDER_LINE)
self.ax.text(self.x_offset + 1.0, y + .1, str(this_creg['val']), ha='left',
va='bottom',
fontsize=0.8 * self._style.fs,
fontsize=self._scale * 0.8 * self._style.fs,
color=self._style.tc,
clip_on=True,
zorder=PORDER_TEXT)
self.ax.text(self.x_offset - 0.2, y, this_creg['label'], ha='right', va='center',
fontsize=1.5 * self._style.fs,
fontsize=self._scale * 1.5 * self._style.fs,
color=self._style.tc,
clip_on=True,
zorder=PORDER_TEXT)
Expand Down Expand Up @@ -1093,7 +1092,7 @@ def _draw_ops(self, verbose=False):
x_coord = ii + 1
y_coord = 0.7
self.ax.text(x_coord, y_coord, str(ii + 1), ha='center',
va='center', fontsize=self._style.sfs,
va='center', fontsize=self._scale * self._style.sfs,
color=self._style.tc, clip_on=True,
zorder=PORDER_TEXT)

Expand Down
Binary file modified test/ipynb/mpl/references/conditional.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/ipynb/mpl/references/long_name.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/ipynb/mpl/references/no_barriers.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/ipynb/mpl/references/plot_barriers_false.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/ipynb/mpl/references/plot_barriers_true.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 added test/ipynb/mpl/references/scale_default.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 added test/ipynb/mpl/references/scale_double.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 added test/ipynb/mpl/references/scale_half.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 12 additions & 1 deletion test/ipynb/mpl/test_circuit_matplotlib_drawer.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from qiskit.test import QiskitTestCase
from qiskit import QuantumCircuit, QuantumRegister, ClassicalRegister
from qiskit.visualization.circuit_visualization import _matplotlib_circuit_drawer

from qiskit.quantum_info.random import random_unitary

RESULTDIR = os.path.dirname(os.path.abspath(__file__))

Expand Down Expand Up @@ -138,6 +138,17 @@ def test_no_barriers_false(self):

self.circuit_drawer(circuit, filename='no_barriers.png', plot_barriers=False)

def test_scale(self):
"""Tests scale
See: https://github.com/Qiskit/qiskit-terra/issues/4179"""
circuit = QuantumCircuit(5)
circuit.unitary(random_unitary(2 ** 5), circuit.qubits)
circuit.draw('mpl')

self.circuit_drawer(circuit, filename='scale_default.png')
self.circuit_drawer(circuit, filename='scale_half.png', scale=0.5)
self.circuit_drawer(circuit, filename='scale_double.png', scale=2)


if __name__ == '__main__':
unittest.main(verbosity=1)
4 changes: 2 additions & 2 deletions test/python/visualization/visualization.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ def assertImagesAreEqual(self, current, expected, diff_tolerance=0.001):
similarity_ratio = black_pixels / total_pixels
self.assertTrue(
1 - similarity_ratio < diff_tolerance,
'The images are different by more than a {}%'
.format(diff_tolerance * 100))
'The images are different by {}%'.format((1 - similarity_ratio) * 100) +
' which is more than the allowed {}%'.format(diff_tolerance * 100))


def _get_black_pixels(image):
Expand Down