1
$\begingroup$

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)
qc.append(randUnitary,[0,1])
qc.draw()

Circuit output

$\endgroup$
3
$\begingroup$

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])
qc.draw()

which yields

Unitary with label

$\endgroup$

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.