I'm writing a program in Qiskit involving the generation of Haar-random unitaries. Is there a way to label each unitary such that the label appears instead of 'unitary' when I draw the circuit?

qc = qiskit.QuantumCircuit(2,1)
randUnitary = qiskit.quantum_info.random_unitary(4)

Circuit output


1 Answer 1


Yeah, you can assign a label to a Gate or an Instruction object for this. For example, something like:

from qiskit import QuantumCircuit
from qiskit.extensions import UnitaryGate
from qiskit.quantum_info import random_unitary

qc = QuantumCircuit(2,1)
randUnitary = UnitaryGate(random_unitary(4), label='My Special Unitary')
qc.append(randUnitary, [0,1])

which yields

Unitary with label


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.