1
$\begingroup$

So here is what I'm trying to accomplish:

I have made a gate out of a matrix, with a control:

cG_p = Operator([[np.sqrt(p[j]), -np.sqrt(1-p[j])], [np.sqrt(1-p[j]), np.sqrt(p[j])]]).to_instruction().control(1)

I then append it to a circuit in a loop:

circ.append(cG_p, [j, j+1])

When I draw the circuit it by default labels the gate "Unitary". I want to put a custom label on the gate instead

I could put the custom label on when it wasn't a control (just a gate). That worked fine. Now that I've added the necessary control I can find no way to change the label.

$\endgroup$
0
$\begingroup$

Do you mean add a label for the gate that is controlled? If yes, you could just add it to the gate before controlling it:

>>> from qiskit.circuit import QuantumCircuit
>>> from qiskit.quantum_info import Operator
>>> gate = Operator([[1,0],[0,1]]).to_instruction()
>>> gate.label = "MyLabel"
>>> cgate = gate.control()
>>> circuit = QuantumCircuit(2)
>>> circuit.append(cgate, [0, 1])
>>> circuit.draw()

q_0: ─────■─────
     ┌────┴────┐
q_1: ┤ MyLabel ├
     └─────────┘
$\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.