Jump to content

Swap test

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Fawly (talk | contribs) at 22:01, 9 November 2021 (citation). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
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 a paper of Harry Buhrman, Richard Cleve, John Watrous, and Ronald de Wolf.[1] It appears commonly in quantum machine learning, and is a circuit used for proofs-of-concept in implementations of quantum computers.[2][3]

Formally, the swap test takes two input states and and outputs a Bernoulli random variable that is 1 with probability . This allows one to, for example, estimate the squared inner product between the two states, , to additive error using copies of the state simply by taking the average over many runs of the swap test.[4] This squared inner product roughly measures "overlap" between the two states, and can be used in linear-algebraic applications, including clustering quantum states.[5]

Explanation of the circuit

Consider two states: and . The state of the system at the beginning of the protocol is . After the Hadamard gate, the state of the system is . The controlled SWAP gate transforms the state into . The second Hadamard gate results in

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

when measured. If and are orthogonal , then the probability that 0 is measured is . If the states are equal , then the probability that 0 is measured is 1.[1]

Pseudocode

Below is the pseudocode for implementing the Swap test:

Algorithm Swap Test
Inputs Two quantum states and , stored in two separate qubit registers, each containing qubits (We denote the -th qubit in the two registers, respectively, by and )

                  An ancilla qubit, initialized as (We denote the ancilla qubit by )

                  Some , representing the number of times the algorithm will be executed

Output Compute
  1. For ranging from to :
    1. Apply a Hadamard gate to the ancilla qubit
    2. For ranging from to (iterating over each pair of qubits in the two registers):
      1. Apply ( is the control qubit, while and are the targets)
    3. Apply a Hadamard gate to the ancilla qubit
    4. Measure the ancilla qubit in the basis and record the result of the measurement (we assume that measurements yield either or , and we denote the outcome of the measurement by )
  2. Compute .
Return (Note that , with equality occurring as , as in this limit, , so the result follows from above.)


  • "←" denotes assignment. For instance, "largestitem" means that the value of largest changes to the value of item.
  • "return" terminates the algorithm and outputs the following value.

References

  1. ^ a b Harry Buhrman, Richard Cleve, John Watrous, Ronald de Wolf (2001). "Quantum Fingerprinting". Physical Review Letters. 87 (16). arXiv:quant-ph/0102001. doi:10.1103/PhysRevLett.87.167902.{{cite journal}}: CS1 maint: multiple names: authors list (link)
  2. ^ Schuld, Maria; Sinayskiy, Ilya; Petruccione, Francesco (2015-04-03). "An introduction to quantum machine learning". Contemporary Physics. 56 (2): 172–185. doi:10.1080/00107514.2014.964942. ISSN 0010-7514.
  3. ^ Kang Min-Sung, Heo Jino, Choi Seong-Gon, Moon Sung, Han Sang-Wook (2019). "Implementation of SWAP test for two unknown states in photons via cross-Kerr nonlinearities under decoherence effect". Scientific Reports. 9 (1). doi:10.1038/s41598-019-42662-4.{{cite journal}}: CS1 maint: multiple names: authors list (link)
  4. ^ de Wolf, Ronald (2021-01-20). "Quantum Computing: Lecture Notes". arXiv:1907.09415 [quant-ph]: 117–119, 122.
  5. ^ Wiebe, Nathan; Kapoor, Anish; Svore, Krysta M. (1 March 2015). "Quantum Algorithms for Nearest-Neighbor Methods for Supervised and Unsupervised Learning". Quantum Information and Computation. 15 (3–4). Rinton Press, Incorporated: 316–356.