In quantum computing and specifically the quantum circuit model of computation, a quantum logic gate (or simply quantum gate) is a basic quantum circuit operating on a small number of qubits. Quantum logic gates are the building blocks of quantum circuits, like classical logic gates are for conventional digital circuits.
Unlike many classical logic gates, quantum logic gates are reversible. It is possible to perform classical computing using only reversible gates. For example, the reversible Toffoli gate can implement all Boolean functions, often at the cost of having to use ancilla bits. The Toffoli gate has a direct quantum equivalent, showing that quantum circuits can perform all operations performed by classical circuits.
Quantum gates are unitary operators, and are described as unitary matrices relative to some orthonormal basis. Usually the computational basis is used, which unless comparing it with something, just means that for a d-level quantum system (such as a qubit, a quantum register, or qutrits and qudits) the orthonormal basis vectors are labeled or use binary notation.
The current notation for quantum gates was developed by many of the founders of quantum information science including Adriano Barenco, Charles Bennett, Richard Cleve, David P. DiVincenzo, Norman Margolus, Peter Shor, Tycho Sleator, John A. Smolin, and Harald Weinfurter,[1] building on notation introduced by Richard Feynman in 1986.[2]
Quantum logic gates are represented by unitary matrices. A gate that acts on
n
2n x 2n
2n
Even though the quantum logic gates belong to continuous symmetry groups, real hardware is inexact and thus limited in precision. The application of gates typically introduces errors, and the quantum states' fidelities decrease over time. If error correction is used, the usable gates are further restricted to a finite set. Later in this article, this is ignored as the focus is on the ideal quantum gates' properties.
Quantum states are typically represented by "kets", from a notation known as bra–ket.
The vector representation of a single qubit is
|a\rangle=v0|0\rangle+v1|1\rangle → \begin{bmatrix}v0\ v1\end{bmatrix}.
Here,
v0
v1
The value zero is represented by the ket and the value one is represented by the ket
The tensor product (or Kronecker product) is used to combine quantum states. The combined state for a qubit register is the tensor product of the constituent qubits. The tensor product is denoted by the symbol
The vector representation of two qubits is:[3]
|\psi\rangle=v00|00\rangle+v01|01\rangle+v10|10\rangle+v11|11\rangle → \begin{bmatrix}v00\ v01\ v10\ v11\end{bmatrix}.
The action of the gate on a specific quantum state is found by multiplying the vector
|\psi1\rangle
U
U|\psi1\rangle=|\psi2\rangle.
See main article: List of quantum logic gates. There exists an uncountably infinite number of gates. Some of them have been named by various authors,[1] [4] [5] [6] [7] [8] [9] and below follow some of those most often used in the literature.
The identity gate is the identity matrix, usually written as I, and is defined for a single qubit as
I=\begin{bmatrix}1&0\ 0&1\end{bmatrix},
where I is basis independent and does not modify the quantum state. The identity gate is most useful when describing mathematically the result of various gate operations or when discussing multi-qubit circuits.
The Pauli gates
(X,Y,Z)
(\sigmax,\sigmay,\sigmaz)
\pi
The Pauli-X gate is the quantum equivalent of the NOT gate for classical computers with respect to the standard basis which distinguishes the z axis on the Bloch sphere. It is sometimes called a bit-flip as it maps
|0\rangle
|1\rangle
|1\rangle
|0\rangle
|0\rangle
i|1\rangle
|1\rangle
|0\rangle
|1\rangle
These matrices are usually represented as
X=\sigmax=\operatorname{NOT}=\begin{bmatrix}0&1\ 1&0\end{bmatrix},
Y=\sigmay=\begin{bmatrix}0&-i\ i&0\end{bmatrix},
Z=\sigmaz=\begin{bmatrix}1&0\ 0&-1\end{bmatrix}.
The Pauli matrices are involutory, meaning that the square of a Pauli matrix is the identity matrix.
I2=X2=Y2=Z2=-iXYZ=I
The Pauli matrices also anti-commute, for example
ZX=iY=-XZ.
The matrix exponential of a Pauli matrix
\sigmaj
-i\sigmaj\theta/2 | |
e |
.
Controlled gates act on 2 or more qubits, where one or more qubits act as a control for some operation. For example, the controlled NOT gate (or CNOT or CX) acts on 2 qubits, and performs the NOT operation on the second qubit only when the first qubit is and otherwise leaves it unchanged. With respect to the basis it is represented by the Hermitian unitary matrix:
CNOT=\begin{bmatrix}1&0&0&0\ 0&1&0&0\ 0&0&0&1\ 0&0&1&0\end{bmatrix}.
The CNOT (or controlled Pauli-X) gate can be described as the gate that maps the basis states
|a,b\rangle\mapsto|a,a ⊕ b\rangle
⊕
The CNOT can be expressed in the Pauli basis as:
CNOT=
| |||||
e |
| |||||
=e |
.
Being a Hermitian unitary operator, CNOT has the property that
ei\theta=(\cos\theta)I+(i\sin\theta)U
U
| |||||
=e |
| |||||
=e |
More generally if U is a gate that operates on a single qubit with matrix representation
U=\begin{bmatrix}u00&u01\ u10&u11\end{bmatrix},
|00\rangle\mapsto|00\rangle
|01\rangle\mapsto|01\rangle
|10\rangle\mapsto|1\rangle ⊗ U|0\rangle=|1\rangle ⊗ (u00|0\rangle+u10|1\rangle)
|11\rangle\mapsto|1\rangle ⊗ U|1\rangle=|1\rangle ⊗ (u01|0\rangle+u11|1\rangle)
The matrix representing the controlled U is
CU=\begin{bmatrix}1&0&0&0\ 0&1&0&0\ 0&0&u00&u01\ 0&0&u10&u11\end{bmatrix}.
In general, any single qubit unitary gate can be expressed as
U=eiH
CU=
| |||||
e |
.
Control can be extended to gates with arbitrary number of qubits and functions in programming languages. Functions can be conditioned on superposition states.[10]
Gates can also be controlled by classical logic. A quantum computer is controlled by a classical computer, and behaves like a coprocessor that receives instructions from the classical computer about what gates to execute on which qubits. Classical control is simply the inclusion, or omission, of gates in the instruction sequence for the quantum computer.
The phase shift is a family of single-qubit gates that map the basis states
|0\rangle\mapsto|0\rangle
|1\rangle\mapstoei\varphi|1\rangle
|0\rangle
|1\rangle
\varphi
P(\varphi)=\begin{bmatrix}1&0\ 0&ei\end{bmatrix}
where
\varphi
\pi/8
\varphi=\pi.
The phase shift gates are related to each other as follows:
Z=\begin{bmatrix}1&0\ 0&ei\end{bmatrix}=\begin{bmatrix}1&0\ 0&-1\end{bmatrix}=P\left(\pi\right)
S=\begin{bmatrix}1&0\ 0&
| ||||||
e |
\end{bmatrix}=\begin{bmatrix}1&0\ 0&i\end{bmatrix}=P\left(
\pi | |
2 |
\right)=\sqrt{Z}
T=\begin{bmatrix}1&0\ 0&
| ||||||
e |
\end{bmatrix}=P\left(
\pi | |
4 |
\right)=\sqrt{S}=\sqrt[4]{Z}
Note that the phase gate
P(\varphi)
\varphi=n\pi,n\inZ
P\dagger(\varphi)=P(-\varphi)
S\dagger
T\dagger
The Hadamard or Walsh-Hadamard gate, named after Jacques Hadamard (pronounced as /fr/) and Joseph L. Walsh, acts on a single qubit. It maps the basis states
1\rangle |
(|0\rangle+|1\rangle)/\sqrt{2}
(|0\rangle-|1\rangle)/\sqrt{2}
|+\rangle
|-\rangle
\pi
(\hat{x}+\hat{z})/\sqrt{2}
H=
1 | |
\sqrt{2 |
If the Hermitian (so
H\dagger=H-1=H
\hat{x}
\hat{z}
HZH=X
H\sqrt{X} H=\sqrt{Z}=S.
The swap gate swaps two qubits. With respect to the basis
|00\rangle
|01\rangle
|10\rangle
|11\rangle
SWAP=\begin{bmatrix}1&0&0&0\\0&0&1&0\\0&1&0&0\\0&0&0&1\end{bmatrix}.
SWAP= | I ⊗ I+X ⊗ X+Y ⊗ Y+Z ⊗ Z |
2 |
D(\pi/2)
|0\rangle
|1\rangle
The Toffoli gate is related to the classical AND (
\land
⊕
|a,b,c\rangle\mapsto|a,b,c ⊕ (a\landb)\rangle
The Toffoli gate can be expressed using Pauli matrices as
Toff=
| |||||
e |
=
| |||||
e |
.
A set of universal quantum gates is any set of gates to which any operation possible on a quantum computer can be reduced, that is, any other unitary operation can be expressed as a finite sequence of gates from the set. Technically, this is impossible with anything less than an uncountable set of gates since the number of possible quantum gates is uncountable, whereas the number of finite sequences from a finite set is countable. To solve this problem, we only require that any quantum operation can be approximated by a sequence of gates from this finite set. Moreover, for unitaries on a constant number of qubits, the Solovay–Kitaev theorem guarantees that this can be done efficiently. Checking if a set of quantum gates is universal can be done using group theory methods[14] and/or relation to (approximate) unitary t-designs[15]
Some universal quantum gate sets include:
A single-gate set of universal quantum gates can also be formulated using the parametrized three-qubit Deutsch gate
D(\theta)
|a,b,c\rangle\mapsto\begin{cases} i\cos(\theta)|a,b,c\rangle+\sin(\theta)|a,b,1-c\rangle&for a=b=1,\\ |a,b,c\rangle&otherwise. \end{cases}
Unfortunately, a working Deutsch gate has remained out of reach, due to lack of a protocol. There are some proposals to realize a Deutsch gate with dipole–dipole interaction in neutral atoms.[16]
A universal logic gate for reversible classical computing, the Toffoli gate, is reducible to the Deutsch gate
D(\pi/2)
There also exist single two-qubit gates sufficient for universality. In 1996, Adriano Barenco showed that the Deutsch gate can be decomposed using only a single two-qubit gate (Barenco gate), but it is hard to realize experimentally. This feature is exclusive to quantum circuits, as there is no classical two-bit gate that is both reversible and universal. Universal two-qubit gates could be implemented to improve classical reversible circuits in fast low-power microprocessors.
Assume that we have two gates A and B that both act on
n
C=B ⋅ A
where
⋅
For example, putting the Pauli X gate after the Pauli Y gate, both of which act on a single qubit, can be described as a single combined gate C:
C=X ⋅ Y=\begin{bmatrix}0&1\ 1&0\end{bmatrix} ⋅ \begin{bmatrix}0&-i\ i&0\end{bmatrix}=\begin{bmatrix}i&0\ 0&-i\end{bmatrix}=iZ
The product symbol (
⋅
All real exponents of unitary matrices are also unitary matrices, and all quantum gates are unitary matrices.
Positive integer exponents are equivalent to sequences of serially wired gates (e.g. and the real exponents is a generalization of the series circuit. For example,
X\pi
\sqrt{X}=X1/2
U0=I
U
I
All gates are unitary matrices, so that
U\daggerU=UU\dagger=I
\dagger
T-1=T\dagger
H\dagger=H,
HH\dagger=I,
H2=I
H
ei\theta=(\cos\theta)I+(i\sin\theta)H
| |||||
H=e |
| |||||
=e |
.
The tensor product (or Kronecker product) of two quantum gates is the gate that is equal to the two gates in parallel.
If we, as in the picture, combine the Pauli-Y gate with the Pauli-X gate in parallel, then this can be written as:
C=Y ⊗ X=\begin{bmatrix}0&-i\ i&0\end{bmatrix} ⊗ \begin{bmatrix}0&1\ 1&0\end{bmatrix}=\begin{bmatrix}0\begin{bmatrix}0&1\ 1&0\end{bmatrix}&-i\begin{bmatrix}0&1\ 1&0\end{bmatrix}\ i\begin{bmatrix}0&1\ 1&0\end{bmatrix}&0\begin{bmatrix}0&1\ 1&0\end{bmatrix}\end{bmatrix}=\begin{bmatrix}0&0&0&-i\ 0&0&-i&0\ 0&i&0&0\ i&0&0&0\end{bmatrix}
Both the Pauli-X and the Pauli-Y gate act on a single qubit. The resulting gate
C
Sometimes the tensor product symbol is omitted, and indexes are used for the operators instead.[19]
The gate
H2=H ⊗ H
H2=H ⊗ H=
1 | |
\sqrt{2 |
This "two-qubit parallel Hadamard gate" will, when applied to, for example, the two-qubit zero-vector create a quantum state that has equal probability of being observed in any of its four possible outcomes; and We can write this operation as:
H2|00\rangle=
1 | |
2 |
\begin{bmatrix}1&1&1&1\ 1&-1&1&-1\ 1&1&-1&-1\ 1&-1&-1&1\end{bmatrix}\begin{bmatrix}1\ 0\ 0\ 0\end{bmatrix}=
1 | |
2 |
\begin{bmatrix}1\ 1\ 1\ 1\end{bmatrix}=
1 | |
2 |
|00\rangle+
1 | |
2 |
|01\rangle+
1 | |
2 |
|10\rangle+
1 | |
2 |
|11\rangle=
|00\rangle+|01\rangle+|10\rangle+|11\rangle | |
2 |
Here the amplitude for each measurable state is . The probability to observe any state is the square of the absolute value of the measurable states amplitude, which in the above example means that there is one in four that we observe any one of the individual four cases. See measurement for details.
H2
\underbrace{H ⊗ H ⊗ ... ⊗ H}ntimes=
n | |
otimes | |
1 |
H=H ⊗ =Hn
n
When applied to a register of
n
2n
n-1 | |
otimes | |
0 |
(H|0\rangle)=
1 | |
\sqrt{2n |
This state is a uniform superposition and it is generated as the first step in some search algorithms, for example in amplitude amplification and phase estimation.
Measuring this state results in a random number between
|0\rangle
1 | |
\sqrt{2n |
The Hadamard transform acts on a register
|\psi\rangle
n
n-1 | |
otimes | |
0 |
H|\psi\rangle=
n-1 | |
otimes | |
i=0 |
| |||||||
\sqrt{2 |
If two or more qubits are viewed as a single quantum state, this combined state is equal to the tensor product of the constituent qubits. Any state that can be written as a tensor product from the constituent subsystems are called separable states. On the other hand, an entangled state is any state that cannot be tensor-factorized, or in other words: An entangled state can not be written as a tensor product of its constituent qubits states. Special care must be taken when applying gates to constituent qubits that make up entangled states.
If we have a set of N qubits that are entangled and wish to apply a quantum gate on M < N qubits in the set, we will have to extend the gate to take N qubits. This application can be done by combining the gate with an identity matrix such that their tensor product becomes a gate that act on N qubits. The identity matrix is a representation of the gate that maps every state to itself (i.e., does nothing at all). In a circuit diagram the identity gate or matrix will often appear as just a bare wire.
For example, the Hadamard gate acts on a single qubit, but if we feed it the first of the two qubits that constitute the entangled Bell state we cannot write that operation easily. We need to extend the Hadamard gate
H
I
K=H ⊗ I=
1 | |
\sqrt{2 |
The gate
K
K
K
|00\rangle+|11\rangle | |
\sqrt{2 |
01\rangle + | 10\rangle - | 11\rangle |
The time complexity for multiplying two
n x n
q
2q x 2q
The state vector of a quantum register with
n
2n
n
Because all quantum logical gates are reversible, any composition of multiple gates is also reversible. All products and tensor products (i.e. series and parallel combinations) of unitary matrices are also unitary matrices. This means that it is possible to construct an inverse of all algorithms and functions, as long as they contain only gates.
Initialization, measurement, I/O and spontaneous decoherence are side effects in quantum computers. Gates however are purely functional and bijective.
If
U
U\daggerU=UU\dagger=I
\dagger
If a function
F
m
F\dagger
Because
(UV)\dagger=V\daggerU\dagger
F\dagger=
m | |
\left(\prod | |
i=1 |
\dagger | |
A | |
i\right) |
=
1 | |
\prod | |
i=m |
\dagger | |
A | |
i |
=
\dagger | |
A | |
m |
⋅ ... ⋅
\dagger | |
A | |
2 |
⋅
\dagger | |
A | |
1 |
Similarly if the function
G
A
B
G=A ⊗ B
Gates that are their own unitary inverses are called Hermitian or self-adjoint operators. Some elementary gates such as the Hadamard (H) and the Pauli gates (I, X, Y, Z) are Hermitian operators, while others like the phase shift (S, T, P, CPhase) gates generally are not.
For example, an algorithm for addition can be used for subtraction, if it is being "run in reverse", as its unitary inverse. The inverse quantum Fourier transform is the unitary inverse. Unitary inverses can also be used for uncomputation. Programming languages for quantum computers, such as Microsoft's Q#,[20] Bernhard Ömer's QCL, and IBM's Qiskit,[21] contain function inversion as programming concepts.
Measurement (sometimes called observation) is irreversible and therefore not a quantum gate, because it assigns the observed quantum state to a single value. Measurement takes a quantum state and projects it to one of the basis vectors, with a likelihood equal to the square of the vector's length (in the 2-norm) along that basis vector.[22] [23] [24] This is known as the Born rule and appears as a stochastic non-reversible operation as it probabilistically sets the quantum state equal to the basis vector that represents the measured state. At the instant of measurement, the state is said to "collapse" to the definite single value that was measured. Why and how, or even if[25] [26] the quantum state collapses at measurement, is called the measurement problem.
\phi
| ⋅ |
Measuring a single qubit, whose quantum state is represented by the vector will result in
|0\rangle
For example, measuring a qubit with the quantum state
|0\rangle-i|1\rangle | |
\sqrt{2 |
|0\rangle
A quantum state
|\Psi\rangle
2n
2n
2n
2n
The sum of all probabilities for all outcomes must always be equal to . Another way to say this is that the Pythagorean theorem generalized to
2n | |
C |
|\Psi\rangle
ax
|\Psi\rangle
2n | |
C |
l{H}
The selection of basis vectors against which to measure a quantum state will influence the outcome of the measurement.[27] See change of basis and Von Neumann entropy for details. In this article, we always use the computational basis, which means that we have labeled the
In quantum mechanics, the basis vectors constitute an orthonormal basis.
An example of usage of an alternative measurement basis is in the BB84 cipher.
If two quantum states (i.e. qubits, or registers) are entangled (meaning that their combined state cannot be expressed as a tensor product), measurement of one register affects or reveals the state of the other register by partially or entirely collapsing its state too. This effect can be used for computation, and is used in many algorithms.
The Hadamard-CNOT combination acts on the zero-state as follows:
\operatorname{CNOT}(H ⊗ I)|00\rangle =\left(\begin{bmatrix}1&0&0&0\ 0&1&0&0\ 0&0&0&1\ 0&0&1&0\end{bmatrix} \left(
1 | |
\sqrt{2 |
11\rangle |
This resulting state is the Bell state It cannot be described as a tensor product of two qubits. There is no solution for
\begin{bmatrix}x\ y\end{bmatrix} ⊗ \begin{bmatrix}w\ z\end{bmatrix}=\begin{bmatrix}xw\ xz\ yw\ yz\end{bmatrix}=
1 | |
\sqrt{2 |
because for example needs to be both non-zero and zero in the case of and .
The quantum state spans the two qubits. This is called entanglement. Measuring one of the two qubits that make up this Bell state will result in that the other qubit logically must have the same value, both must be the same: Either it will be found in the state or in the state If we measure one of the qubits to be for example then the other qubit must also be because their combined state became Measurement of one of the qubits collapses the entire quantum state, that span the two qubits.
The GHZ state is a similar entangled quantum state that spans three or more qubits.
This type of value-assignment occurs instantaneously over any distance and this has as of 2018 been experimentally verified by QUESS for distances of up to 1200 kilometers.[28] [29] [30] That the phenomena appears to happen instantaneously as opposed to the time it would take to traverse the distance separating the qubits at the speed of light is called the EPR paradox, and it is an open question in physics how to resolve this. Originally it was solved by giving up the assumption of local realism, but other interpretations have also emerged. For more information see the Bell test experiments. The no-communication theorem proves that this phenomenon cannot be used for faster-than-light communication of classical information.
Take a register A with qubits all initialized to and feed it through a parallel Hadamard gate Register A will then enter the state that have equal probability of when measured to be in any of its
2n
|0\rangle
|0\rangle
Ap
Bp
If we now measure the qubits in register A, then register B will be found to contain the same value as A. If we however instead apply a quantum logic gate on A and then measure, then where
F\dagger
Because of how unitary inverses of gates act, For example, say
F(x)=x+3\pmod{2n}
The equality will hold no matter in which order measurement is performed (on the registers A or B), assuming that has run to completion. Measurement can even be randomly and concurrently interleaved qubit by qubit, since the measurements assignment of one qubit will limit the possible value-space from the other entangled qubits.
Even though the equalities holds, the probabilities for measuring the possible outcomes may change as a result of applying, as may be the intent in a quantum search algorithm.
This effect of value-sharing via entanglement is used in Shor's algorithm, phase estimation and in quantum counting. Using the Fourier transform to amplify the probability amplitudes of the solution states for some problem is a generic method known as "Fourier fishing".[31]
Functions and routines that only use gates can themselves be described as matrices, just like the smaller gates. The matrix that represents a quantum function acting on
q
28 x 28=256 x 256
Unitary transformations that are not in the set of gates natively available at the quantum computer (the primitive gates) can be synthesised, or approximated, by combining the available primitive gates in a circuit. One way to do this is to factor the matrix that encodes the unitary transformation into a product of tensor products (i.e. series and parallel circuits) of the available primitive gates. The group U(2q) is the symmetry group for the gates that act on
q
Because of the gates unitary nature, all functions must be reversible and always be bijective mappings of input to output. There must always exist a function
F-1
Logically irreversible operations, for example addition modulo
2n
n
a+b
a
All Boolean algebraic expressions can be encoded as unitary transforms (quantum logic gates), for example by using combinations of the Pauli-X, CNOT and Toffoli gates. These gates are functionally complete in the Boolean logic domain.
There are many unitary transforms available in the libraries of Q#, QCL, Qiskit, and other quantum programming languages. It also appears in the literature.[36] [37]
For example,
inc(|x\rangle)=|x+1
xlength | |
\pmod{2 |
xlength
In QCL, decrement is done by "undoing" increment. The prefix !
is used to instead run the unitary inverse of the function. !inc(x)
is the inverse of inc(x)
and instead performs the operation The cond
keyword means that the function can be conditional.[10]
In the model of computation used in this article (the quantum circuit model), a classic computer generates the gate composition for the quantum computer, and the quantum computer behaves as a coprocessor that receives instructions from the classical computer about which primitive gates to apply to which qubits.[41] Measurement of quantum registers results in binary values that the classical computer can use in its computations. Quantum algorithms often contain both a classical and a quantum part. Unmeasured I/O (sending qubits to remote computers without collapsing their quantum states) can be used to create networks of quantum computers. Entanglement swapping can then be used to realize distributed algorithms with quantum computers that are not directly connected. Examples of distributed algorithms that only require the use of a handful of quantum logic gates are superdense coding, the quantum Byzantine agreement and the BB84 cipherkey exchange protocol.