# How can we represent a CNOT gate using a cascade of rotation gates?

I have been working using qiskit to implement the CNOT decomposition into a cascade of rotation gates from this source. After computing the unitary matrix, the resultant matrix is not the same as the matrix for a regular CNOT.

$$CNOT=\begin{bmatrix} 1 & 0 & 0& 0\\ 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 1\\0 & 0 & 1 & 0 \end{bmatrix}$$

$$\text{qiskit output}=\begin{bmatrix} 0.71+0.71j& 0 & 0 & 0 \\ 0 & 0 & 0 & 0.71+0.71j \\ 0 & 0 & 0.71+0.71j & 0\\0 & 0.71+0.71j & 0 & 0 \end{bmatrix}$$

This is the code for reproduction.

from qiskit import Aer, QuantumCircuit, execute
import numpy as np

if __name__ == '__main__':
# create a qiskit circuit that implements a cnot gate using rotation gates
n = 2
alpha = 1
circuit = QuantumCircuit(n)

circuit.ry(alpha*np.pi/2, 0)
circuit.rxx(alpha*np.pi/2, 0, 1)
circuit.ry(-alpha*np.pi/2, 0)
circuit.rx(-np.pi/2, 1)
circuit.rz(-np.pi/2, 0)

circuit.ry(np.pi/2, 0)
circuit.ry(np.pi/2, 1)

backend = Aer.get_backend('unitary_simulator')
job = execute(circuit, backend, shots=8192)
result = job.result()

print(result.get_unitary(circuit, 2))
• If I run this code today I get a strange matrix. Apr 12 at 22:37

The matrix you get is actually correct. In ordet to see it, you have to recall two things:

1. Qiskit uses little-endian ordering.
2. Global phases are irrelevant.

Concerning the first one, you can find it in the Qiskit documentation. By using Qiskit and considering the first wire as the one which will give the first bit once measured, you'll end up getting things in reverse.

In Qiskit, the first wire is associated to the last bit. Thus, performing a CNOT controlled on the first wire actually performs the following transformations: \begin{align}|00\rangle\to|00\rangle\\|01\rangle\to|11\rangle\\|10\rangle\to|10\rangle\\|11\rangle\to|01\rangle\end{align} which corresponds to the following matrix: $$\begin{pmatrix}1&0&0&0\\0&0&0&1\\0&0&1&0\\0&1&0&0\end{pmatrix}$$

Concerning the second points, note that the matrix you get is exactly the matrix you seek up to a factor $$0.71+0.71\mathrm{i}\approx\frac{1+\mathrm{i}}{\sqrt{2}}=\mathrm{e}^{\mathrm{i}\frac\pi4}$$. This factor is a global phase and is irrelevant in implementing a quantum gate, as long as you don't build a controlled-gate out of it. Thus, you can definitely use the gate you've created as a CNOT gate :)

• What are the implications of using such gate in a quantum algorithm, say Bernstein-Vazirani's algorithm or Grover? Will that global phase have an effect on the results? Oct 5, 2022 at 23:39
• @FrostGriffin If you only use it as a CNOT gate, no. There is no physical experiment that can distinguish between a CNOT gate and the gate you've created. However, you must not use a controlled version of this gate: in order to build a Toffoli gate, you can't simply control the operation in your decomposition by a second qubit, you have to do the whole process for the Toffoli gate. Once you have the Toffoli, the CNOT and single qubit rotations, you should be able to program whatever algorithm you want Oct 5, 2022 at 23:59