3

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?

glS
  • 27,510
  • 7
  • 37
  • 125
midor
  • 220
  • 3
  • 9

2 Answers2

4

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
luciano
  • 6,084
  • 1
  • 13
  • 34
0

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

Davit Khachatryan
  • 4,461
  • 1
  • 11
  • 22