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

Fix for Matplotlib barriers not plotting correctly #1718

Merged
merged 10 commits into from
Jan 29, 2019
2 changes: 2 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ The format is based on `Keep a Changelog`_.
Added
-----


- New EnlargeWithAncilla pass for adding ancilla qubits after a Layout
selection pass (#1603).
- New Unroll2Q pass for unrolling gates down to just 1q or 2q gates (#1614).
Expand Down Expand Up @@ -58,6 +59,7 @@ Fixed

- Fixed a bug with measurement sampling optimization in BasicAer
qasm_simulator (#1624).
- Fixed a bug where barriers didn't plot over all qubits when using matplotlib.
maddy-tod marked this conversation as resolved.
Show resolved Hide resolved
- Fixed a minor conda env bug in Makefile (#1691).
- Fixed a bug in BasicMapper pass operating over multiple registers (#1611).
- Fixed a bug in BarrierBeforeFinalMeasurements which incorrectly moved measurements
Expand Down
16 changes: 12 additions & 4 deletions qiskit/tools/visualization/_matplotlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,7 @@ def _draw_ops(self, verbose=False):
#
for i, (op, op_next) in enumerate(
itertools.zip_longest(self._ops, next_ops)):

# wide gate
if op['name'] in _wide_gate:
_iswide = True
Expand All @@ -501,6 +502,7 @@ def _draw_ops(self, verbose=False):
break
else:
q_idxs = []

# get creg index
if 'cargs' in op.keys():
c_idxs = []
Expand All @@ -512,6 +514,7 @@ def _draw_ops(self, verbose=False):
break
else:
c_idxs = []

# find empty space to place gate
if not _barriers['group']:
this_anc = max([q_anchors[ii].get_index() for ii in q_idxs])
Expand Down Expand Up @@ -592,10 +595,15 @@ def _draw_ops(self, verbose=False):
self._measure(q_xy[0], c_xy[0], vv)
elif op['name'] in ['barrier', 'snapshot', 'load', 'save',
'noise']:
q_group = self._qreg_dict[q_idxs[0]]['group']
if q_group not in _barriers['group']:
_barriers['group'].append(q_group)
_barriers['coord'].append(q_xy[0])

# Go over all indices to add barriers across
for index in range(len(q_idxs)):
q_group = self._qreg_dict[q_idxs[index]]['group']

if q_group not in _barriers['group']:
_barriers['group'].append(q_group)
_barriers['coord'].append(q_xy[index])

if op_next and op_next['name'] == 'barrier':
continue
else:
Expand Down