6

The regular Matrix representation of a CNOT gate as found in literature is:

CNOT =

      \begin{bmatrix}
      
      1 & 0 &  0 & 0\\
      0 & 1 &  0 & 0\\
      0 & 0 &  0 & 1\\
      0 & 0 &  1 & 0
      
      \end{bmatrix} 
      

However in Qiskit, the matrix is represented as CNOT =

      \begin{bmatrix}

      1  & 0 &  0 &  0\\
      0  & 0 &  0 &  1\\
      0  & 0 &  1 &  0\\
      0  & 1 &  0 &  0

      \end{bmatrix}

Is this something related to the Big-endian/Little-endian issue? Is there a way to represent my matrix the same way it is recovered in literature?

  • I think this should be asked on [Quantum Computing Stack Exchange](https://quantumcomputing.stackexchange.com/), because I just [realized](https://meta.stackexchange.com/a/60020) that SO does not supports LaTeX. – Rajesh Swarnkar Aug 04 '22 at 06:45

1 Answers1

7

Yes, as you mentioned this has to do with the little endian bit-order in Qiskit. Most textbooks (and the first matrix you showed) are in big endian order.

If you want to know more you could check out these posts/documentation:

If you want to convert your Qiskit circuit to big endian you can just use the reverse_bits method:

from qiskit import QuantumCircuit
from qiskit.quantum_info import Operator

circuit = QuantumCircuit(2)
circuit.cx(0, 1)

print('Little endian:')
print(Operator(circuit))

print('Big endian:')
print(Operator(circuit.reverse_bits()))

gives:

Little endian:
Operator([[1.+0.j, 0.+0.j, 0.+0.j, 0.+0.j],
          [0.+0.j, 0.+0.j, 0.+0.j, 1.+0.j],
          [0.+0.j, 0.+0.j, 1.+0.j, 0.+0.j],
          [0.+0.j, 1.+0.j, 0.+0.j, 0.+0.j]],
         input_dims=(2, 2), output_dims=(2, 2))
Big endian:
Operator([[1.+0.j, 0.+0.j, 0.+0.j, 0.+0.j],
          [0.+0.j, 1.+0.j, 0.+0.j, 0.+0.j],
          [0.+0.j, 0.+0.j, 0.+0.j, 1.+0.j],
          [0.+0.j, 0.+0.j, 1.+0.j, 0.+0.j]],
         input_dims=(2, 2), output_dims=(2, 2))
Cryoris
  • 416
  • 1
  • 4
  • 12