Quantum Circuits Library: Three-qubit gates

ToffoliGate

QuantumCircuitOpt.ToffoliGate — Function
ToffoliGate()

Three-qubit Toffoli gate, also known as the CCX (controlled-controlled-NOT) gate.

Circuit Representation

q_0: ──■──
       │
q_1: ──■──
     ┌─┴─┐
q_2: ┤ X ├
     └───┘

Matrix Representation

\[Toffoli = |0 \rangle \langle 0| \otimes I \otimes I + |1 \rangle \langle 1| \otimes CXGate = \begin{pmatrix} 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\ 0 & 1 & 0 & 0 & 0 & 0 & 0 & 0\\ 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0\\ 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0\\ 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0\\ 0 & 0 & 0 & 0 & 0 & 1 & 0 & 0\\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1\\ 0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 \end{pmatrix}\]

source

QFT3Gate

QuantumCircuitOpt.QFT3Gate — Function
QFT3Gate()

Three-qubit Quantum Fourier Transform (QFT) gate, where the QFT operation on n-qubits is given by:

\[|j\rangle \mapsto \frac{1}{2^{n/2}} \sum_{k=0}^{2^n - 1} e^{2\pi ijk / 2^n} |k\rangle\]

Circuit Representation

     ┌──────┐
q_0: ┤      ├
     │      │   
q_1: ┤ QFT3 ├ 
     │      │   
q_3: ┤      ├ 
     └──────┘ 

Matrix Representation

\[M = \frac{1}{2\sqrt{2}} \begin{pmatrix} 1 1 1 1 1 1 1 1 \\ 1 \frac{1}{\sqrt{2}} + \frac{i}{\sqrt{2}} i -\frac{1}{\sqrt{2}} + \frac{i}{\sqrt{2}} -1 -\frac{1}{\sqrt{2}} - \frac{i}{\sqrt{2}} -i \frac{1}{\sqrt{2}} - \frac{i}{\sqrt{2}} \\ 1 i -1 -i 1 i -1 -i \\ 1 -\frac{1}{\sqrt{2}} + \frac{i}{\sqrt{2}} -i \frac{1}{\sqrt{2}} + \frac{i}{\sqrt{2}} -1 \frac{1}{\sqrt{2}} - \frac{i}{\sqrt{2}} i -\frac{1}{\sqrt{2}} - \frac{i}{\sqrt{2}} \\ 1 -1 1 -1 1 -1 1 -1 \\ 1 -\frac{1}{\sqrt{2}} - \frac{i}{\sqrt{2}} i \frac{1}{\sqrt{2}} - \frac{i}{\sqrt{2}} -1 \frac{1}{\sqrt{2}} + \frac{i}{\sqrt{2}} -i -\frac{1}{\sqrt{2}} + \frac{i}{\sqrt{2}} \\ 1 -i -1 i 1 -i -1 i \\ 1 \frac{1}{\sqrt{2}} - \frac{i}{\sqrt{2}} -i -\frac{1}{\sqrt{2}} - \frac{i}{\sqrt{2}} -1 -\frac{1}{\sqrt{2}} + \frac{i}{\sqrt{2}} i \frac{1}{\sqrt{2}} + \frac{i}{\sqrt{2}} \\ \end{pmatrix}\]

source

CSwapGate

QuantumCircuitOpt.CSwapGate — Function
CSwapGate()

Three-qubit, controlled SwapGate, also known as the Fredkin gate.

Circuit Representation

q_0: ─■─
      │
q_1: ─X─
      │
q_2: ─X─

Matrix Representation

\[CSwapGate = \begin{pmatrix} 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 \\ \end{pmatrix}\]

source

CCZGate

QuantumCircuitOpt.CCZGate — Function
CCZGate()

Three-qubit controlled-controlled Z gate.

Circuit Representation

q_0: ─■─
      │
q_1: ─■─
      │
q_2: ─■─

Matrix Representation

\[CCZGate = \begin{pmatrix} 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & -1 \\ \end{pmatrix}\]

source

PeresGate

QuantumCircuitOpt.PeresGate — Function
PeresGate()

Three-qubit Peres gate. This gate is equivalent to ToffoliGate followed by the CNotGate in 3 qubits. Reference: https://doi.org/10.1103/PhysRevA.32.3266

Circuit Representation

q_0: ──■─────■──          
       │   ┌─┴─┐
q_1: ──■───┤ X ├
     ┌─┴─┐ └───┘
q_2: ┤ X ├──────
     └───┘

Matrix Representation

\[PeresGate = \begin{pmatrix} 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 \\ 0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 \\ \end{pmatrix}\]

source

RCCXGate

QuantumCircuitOpt.RCCXGate — Function
RCCXGate()

Three-qubit relative (or simplified) Toffoli gate, or the CCX gate. This gate is equivalent to ToffoliGate upto relative phases. The advantage of this gate is that it's implementation requires only three CNot (or CX) gates. Reference: https://arxiv.org/pdf/1508.03273.pdf

Matrix Representation

\[RCCXGate = \begin{pmatrix} 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & -1 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & -i \\ 0 & 0 & 0 & 0 & 0 & 0 & i & 0 \\ \end{pmatrix}\]

source

MargolusGate

QuantumCircuitOpt.MargolusGate — Function
MargolusGate()

Three-qubit Margolus gate, which is a simplified ToffoliGate and coincides with the Toffoli gate up to a single change of sign. The advantage of this gate is that its implementation requires only three CNot (or CX) gates. Reference: https://arxiv.org/pdf/quant-ph/0312225.pdf

Matrix Representation

\[MargolusGate = \begin{pmatrix} 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & -1 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 \\ 0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 \\ \end{pmatrix}\]

source

CiSwapGate

QuantumCircuitOpt.CiSwapGate — Function
CiSwapGate()

Three-qubit controlled version of the iSwapGate. Reference: https://doi.org/10.1103/PhysRevResearch.2.033097

Circuit Representation

q_0: ─────■─────
          │
      ┌───────┐
q_1: ─┤       ├─
      │ iSwap │   
q_2: ─┤       ├─ 
      └───────┘ 

Matrix Representation

\[CiSwapGate = \begin{pmatrix} 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & i & 0 \\ 0 & 0 & 0 & 0 & 0 & i & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 \\ \end{pmatrix}\]

source