Swap Test
   HOME

TheInfoList



OR:

The swap test is a procedure in
quantum computation A quantum computer is a computer that exploits quantum mechanical phenomena. On small scales, physical matter exhibits properties of both particles and waves, and quantum computing takes advantage of this behavior using specialized hardware. C ...
that is used to check how much two
quantum states In quantum physics, a quantum state is a mathematical entity that embodies the knowledge of a quantum system. Quantum mechanics specifies the construction, evolution, and measurement of a quantum state. The result is a prediction for the system re ...
differ, appearing first in the work of Barenco et al. and later rediscovered by Harry Buhrman, Richard Cleve, John Watrous, and
Ronald de Wolf Ronald Michiel de Wolf (born 1973) is a Dutch Computer Scientist, currently a Senior Researcher at Centrum Wiskunde & Informatica (CWI) and a professor at the Institute for Logic, Language and Computation (ILLC) of the University of Amsterdam ( ...
. It appears commonly in quantum machine learning, and is a circuit used for proofs-of-concept in implementations of quantum computers. Formally, the swap test takes two input states , \phi\rangle and , \psi\rangle and outputs a
Bernoulli random variable In probability theory and statistics, the Bernoulli distribution, named after Swiss mathematician Jacob Bernoulli, is the discrete probability distribution of a random variable which takes the value 1 with probability p and the value 0 with pro ...
that is 1 with probability \textstyle\frac - \frac ^2 (where the expressions here use
bra–ket notation Bra–ket notation, also called Dirac notation, is a notation for linear algebra and linear operators on complex vector spaces together with their dual space both in the finite-dimensional and infinite-dimensional case. It is specifically de ...
). This allows one to, for example, estimate the squared inner product between the two states, ^2, to \varepsilon additive error by taking the average over O(\textstyle\frac) runs of the swap test. This requires O(\textstyle\frac) copies of the input states. The squared inner product roughly measures "overlap" between the two states, and can be used in linear-algebraic applications, including clustering quantum states.


Explanation of the circuit

Consider two states: , \phi\rangle and , \psi\rangle. The state of the system at the beginning of the protocol is , 0, \phi, \psi\rangle. After the
Hadamard gate The Hadamard transform (also known as the Walsh–Hadamard transform, Hadamard–Rademacher–Walsh transform, Walsh transform, or Walsh–Fourier transform) is an example of a generalized class of Fourier transforms. It performs an orthogonal ...
, the state of the system is \frac(, 0, \phi, \psi\rangle + , 1, \phi, \psi\rangle). The controlled SWAP gate transforms the state into \frac(, 0, \phi, \psi\rangle + , 1, \psi, \phi\rangle). The second Hadamard gate results in \frac(, 0, \phi, \psi\rangle + , 1, \phi, \psi\rangle + , 0, \psi, \phi\rangle - , 1, \psi, \phi\rangle) = \frac, 0\rangle(, \phi, \psi\rangle + , \psi, \phi\rangle) + \frac, 1\rangle(, \phi, \psi\rangle - , \psi, \phi\rangle) The measurement gate on the first qubit ensures that it's 0 with a probability of P(\text = 0) = \frac \Big( \langle \phi , \langle \psi , + \langle \psi , \langle \phi , \Big) \frac \Big( , \phi \rangle , \psi \rangle + , \psi \rangle , \phi \rangle \Big) = \frac + \frac ^2 when measured. If \psi and \phi are
orthogonal In mathematics, orthogonality (mathematics), orthogonality is the generalization of the geometric notion of ''perpendicularity''. Although many authors use the two terms ''perpendicular'' and ''orthogonal'' interchangeably, the term ''perpendic ...
(^2 = 0), then the probability that 0 is measured is \frac. If the states are equal (^2 = 1), then the probability that 0 is measured is 1. In general, for P trials of the swap test using P copies of , \phi\rangle and P copies of , \psi\rangle, the fraction of measurements that are zero is 1 - \textstyle\frac \textstyle\sum_^ M_i, so by taking P \rightarrow \infty, one can get arbitrary precision of this value. Below is the pseudocode for estimating the value of , \langle \psi , \phi \rangle , ^2 using ''P'' copies of , \psi\rangle and , \phi\rangle: Inputs ''P'' copies each of the ''n'' qubits quantum states , \psi\rangle and , \phi\rangle Output An estimate of , \langle \psi , \phi \rangle , ^2 for ''j'' ranging from 1 to ''P'': initialize an ancilla qubit ''A'' in state , 0\rangle apply a Hadamard gate to the ancilla qubit ''A'' for ''i'' ranging from 1 to ''n'': apply CSWAP to \psi_i and \phi_i (the ''i''th qubit of the ''j''th copy of , \psi\rangle and , \phi\rangle), with ''A'' as the control qubit apply a Hadamard gate to the ancilla qubit ''A'' measure ''A'' in the Z basis and record the measurement ''Mj'' as either a 0 or 1 compute s = 1 - \textstyle\frac \textstyle\sum_^ M_i. return s as our estimate of , \langle \psi , \phi \rangle , ^2


References

{{Quantum computing Quantum algorithms