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

Handle instructions without label in mpl drawer #4389

Closed
wants to merge 12 commits into from
13 changes: 7 additions & 6 deletions qiskit/visualization/matplotlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -863,13 +863,13 @@ def _draw_ops(self, verbose=False):
elif op.name == 'initialize':
vec = '[%s]' % param
self._custom_multiqubit_gate(q_xy, wide=_iswide,
text=op.op.label or "|psi>",
text=getattr(op.op, 'label') or "|psi>",
mtreinish marked this conversation as resolved.
Show resolved Hide resolved
subtext=vec)
elif op.name == 'unitary':
# TODO(mtreinish): Look into adding the unitary to the
# subtext
self._custom_multiqubit_gate(q_xy, wide=_iswide,
text=op.op.label or "Unitary")
text=getattr(op.op, 'label') or "Unitary")
elif isinstance(op.op, ControlledGate) and op.name not in [
'ccx', 'cx', 'c3x', 'c4x', 'cy', 'cz', 'ch', 'cu1', 'cu3', 'crz',
'cswap']:
Expand Down Expand Up @@ -1007,12 +1007,12 @@ def _draw_ops(self, verbose=False):
elif op.name in ['dcx', 'iswap']:
self._custom_multiqubit_gate(q_xy, c_xy, wide=_iswide,
fc=self._style.dispcol[op.name],
text=op.op.label or op.name)
text=getattr(op.op, 'label') or op.op.name)

# Custom gate
else:
self._custom_multiqubit_gate(q_xy, c_xy, wide=_iswide,
text=op.op.label or op.name)
text=getattr(op.op, 'label') or op.op.name)
#
# draw multi-qubit gates (n=3)
#
Expand Down Expand Up @@ -1044,12 +1044,13 @@ def _draw_ops(self, verbose=False):
# custom gate
else:
self._custom_multiqubit_gate(q_xy, c_xy, wide=_iswide,
text=getattr(op.op, 'label', None) or op.name)
text=getattr(op.op,
'label') or op.op.name)

# draw custom multi-qubit gate
elif len(q_xy) > 5:
self._custom_multiqubit_gate(q_xy, c_xy, wide=_iswide,
text=op.op.label or op.name)
text=getattr(op.op, 'label') or op.op.name)
else:
logger.critical('Invalid gate %s', op)
raise exceptions.VisualizationError('invalid gate {}'.format(op))
Expand Down