When trying to draw a QuantumCircuit object using .draw(output='mpl'), I'm getting AttributeError: 'Instruction' object has no attribute 'label' in qiskit/visualization/matplotlib.py. The circuit draws fine using the default text drawer.
The code is adapted from the linear_systems_of_equations HHL tutorial notebook. Here's a (probably non-minimal) snippet to reproduce:
from qiskit.aqua.algorithms import HHL
from qiskit.aqua.components.eigs import EigsQPE
from qiskit.circuit.library import QFT
from qiskit.aqua.components.reciprocals import LookupRotation
from qiskit.aqua.operators import MatrixOperator
from qiskit.aqua.components.initial_states import Custom
def create_eigs(matrix, num_ancillae, negative_evals):
ne_qfts = [None, None]
if negative_evals:
num_ancillae += 1
ne_qfts = [QFT(num_ancillae - 1), QFT(num_ancillae - 1, inverse=True)]
return EigsQPE(MatrixOperator(matrix=matrix),
QFT(num_ancillae, inverse=True),
num_time_slices=50,
num_ancillae=num_ancillae,
expansion_mode='suzuki',
expansion_order=2,
evo_time=None,
negative_evals=negative_evals,
ne_qfts=ne_qfts)
matrix = [[1, 0], [0, 2]]
vector = [1, 4]
orig_size = len(vector)
matrix, vector, truncate_powerdim, truncate_hermitian = HHL.matrix_resize(matrix, vector)
# Initialize eigenvalue finding module
eigs = create_eigs(matrix, 3, False)
num_q, num_a = eigs.get_register_sizes()
# Initialize initial state module
init_state = Custom(num_q, state_vector=vector)
# Initialize reciprocal rotation module
reci = LookupRotation(negative_evals=eigs._negative_evals, evo_time=eigs._evo_time)
algo = HHL(matrix, vector, truncate_powerdim, truncate_hermitian, eigs,
init_state, reci, num_q, num_a, orig_size)
circuit = algo.construct_circuit(measurement=True)
circuit.draw(output='mpl')
No errors, and the circuit is drawn correctly using Matplotlib.
Not sure - I don't know whether this could be a Terra visualization problem or an Aqua circuit design problem (or just a problem with the code above).
There is already a fix in progress for this issue: https://github.com/Qiskit/qiskit-terra/pull/4389 It's caused by certain gates (or circuit library elements that were converted to gates or instructions) missing a label attribute which the mpl drawer incorrectly assumes is always present.
Hi, is there an ETA on a fix for this?
This should be part of the 0.15 release which is scheduled for two weeks. #4389 is fixing this 馃檪
Awesome, thanks 馃帀
Most helpful comment
There is already a fix in progress for this issue: https://github.com/Qiskit/qiskit-terra/pull/4389 It's caused by certain gates (or circuit library elements that were converted to gates or instructions) missing a label attribute which the mpl drawer incorrectly assumes is always present.