# Qiskit Controlled S and Controlled T Gates

I was implementing controlled S and T gates in qiskit and was wondering if there is any difference between using the cu1 and crz gates for this purpose. Qiskit doesn't seem to include explicit versions of these two gates.

circuit = qiskit.QuantumCircuit(2)
# a)
circuit.crz(theta=math.pi/2, control_qubit=0, target_qubit=1)
# b)
circuit.cu1(theta=math.pi/2, control_qubit=0, target_qubit=1)


In terms of the unitary the cu1 gate seems closer to what one would want, I would assume. Are there any other consequences I should be aware of?

• cu1 will be deprecated in favor of cp, but the answer still holds. Using cp will be more concise, but luciano's answer using Gate().control renders more nicely in diagrams (as controlled S not as controlled P (pi/2)) Jan 2, 2021 at 15:49

In Qiskit you can get the controlled version of any gate with the method control. For S and T, here is the example:

from qiskit.circuit.library.standard_gates import SGate, TGate

csgate = SGate().control(1) # the parameter is the amount of control points you want
ctgate = TGate().control(1)

circuit = QuantumCircuit(2)
circuit.append(csgate, [0, 1])
circuit.append(ctgate, [0, 1])
print(circuit)

q_0: ──■────■──
┌─┴─┐┌─┴─┐
q_1: ┤ S ├┤ T ├
└───┘└───┘


If you want to compare these gates with cu1 or crz, you can use the Operator class:

from qiskit.circuit.library.standard_gates import CRZGate, CU1Gate
from math import pi

from qiskit.quantum_info import Operator
print(Operator(CU1Gate(pi/2)) == Operator(csgate))
print(Operator(CRZGate(pi/4)) == Operator(ctgate))

True
False

• edited to include that comment. Jan 2, 2021 at 20:20

cu1 and crz are different gates and the difference is explained in this answer. One can express $$cS$$ and $$cT$$ gates with cu1 gate, but it is impossible to express them with crz gate.

$$cS = \begin{pmatrix} 1&0&0&0 \\ 0&1&0&0 \\ 0&0&1&0 \\ 0&0&0&i \\ \end{pmatrix} = cu1(\pi/2) \qquad cT = \begin{pmatrix} 1&0&0&0 \\ 0&1&0&0 \\ 0&0&1&0 \\ 0&0&0&e^{i \pi/4} \\ \end{pmatrix} = cu1(\pi/4)$$

while

$$cRz(\alpha) = \begin{pmatrix} 1&0&0&0 \\ 0&1&0&0 \\ 0&0&e^{-i \alpha/2}&0 \\ 0&0&0&e^{i \alpha/2} \\ \end{pmatrix}$$

and there is no way to choose such $$\alpha$$ for $$cRz(\alpha)$$ to be equal to $$cS$$ or $$cT$$.

• Thanks for pointing this out. I hastily assumed that I could get rid of the rotation on |0> as a global phase. Jan 2, 2021 at 8:22
• @midor, you are welcome :) Jan 2, 2021 at 8:35