3
$\begingroup$

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?

$\endgroup$
1
  • $\begingroup$ 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)) $\endgroup$
    – midor
    Commented Jan 2, 2021 at 15:49

2 Answers 2

4
$\begingroup$

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
$\endgroup$
1
  • $\begingroup$ edited to include that comment. $\endgroup$
    – luciano
    Commented Jan 2, 2021 at 20:20
0
$\begingroup$

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$.

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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