Swap test

From testwiki
Jump to navigation Jump to search

Template:Short description

Circuit implementing the swap test between two states |ϕ and |ψ

The swap test is a procedure in quantum computation that is used to check how much two quantum states differ, appearing first in the work of Barenco et al.[1] and later rediscovered by Harry Buhrman, Richard Cleve, John Watrous, and Ronald de Wolf.[2] It appears commonly in quantum machine learning, and is a circuit used for proofs-of-concept in implementations of quantum computers.[3][4]

Formally, the swap test takes two input states |ϕ and |ψ and outputs a Bernoulli random variable that is 1 with probability 1212|ψ|ϕ|2 (where the expressions here use bra–ket notation). This allows one to, for example, estimate the squared inner product between the two states, |ψ|ϕ|2, to ε additive error by taking the average over O(1ε2) runs of the swap test.[5] This requires O(1ε2) 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.[6]

Explanation of the circuit

Consider two states: |ϕ and |ψ. The state of the system at the beginning of the protocol is |0,ϕ,ψ. After the Hadamard gate, the state of the system is 12(|0,ϕ,ψ+|1,ϕ,ψ). The controlled SWAP gate transforms the state into 12(|0,ϕ,ψ+|1,ψ,ϕ). The second Hadamard gate results in 12(|0,ϕ,ψ+|1,ϕ,ψ+|0,ψ,ϕ|1,ψ,ϕ)=12|0(|ϕ,ψ+|ψ,ϕ)+12|1(|ϕ,ψ|ψ,ϕ)

The measurement gate on the first qubit ensures that it's 0 with a probability of

P(First qubit=0)=12(ϕ|ψ|+ψ|ϕ|)12(|ϕ|ψ+|ψ|ϕ)=12+12|ψ|ϕ|2

when measured. If ψ and ϕ are orthogonal (|ψ|ϕ|2=0), then the probability that 0 is measured is 12. If the states are equal (|ψ|ϕ|2=1), then the probability that 0 is measured is 1.[2]

In general, for P trials of the swap test using P copies of |ϕ and P copies of |ψ, the fraction of measurements that are zero is 11Pi=1PMi, so by taking P, one can get arbitrary precision of this value.

Below is the pseudocode for estimating the value of |ψ|ϕ|2 using P copies of |ψ and |ϕ:

Inputs P copies each of the n qubits quantum states |ψ and |ϕ
Output An estimate of |ψ|ϕ|2

for j ranging from 1 to P:
    initialize an ancilla qubit A in state |0
    apply a Hadamard gate to the ancilla qubit A
    for i ranging from 1 to n: 
        apply CSWAP to ψi and ϕi (the ith qubit of the jth copy of |ψ and |ϕ), 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=12Pi=1PMi.
return s as our estimate of |ψ|ϕ|2

References

Template:Reflist

Template:Quantum computing