SWAP overlap circuit
An ancilla-controlled exchange circuit whose measurement estimates the overlap of two quantum states.
Also called SWAP test
On this page
Definition and significance
The SWAP overlap circuit, conventionally called the SWAP test, compares two prepared states through interference. It is a scientific protocol, not a visitor test. For pure inputs it estimates their squared inner-product magnitude; it does not reveal the relative global phase between independently prepared states.
Mechanism and mathematical treatment
Prepare an ancilla |+>, apply a controlled-SWAP to inputs |psi> and |phi>, then measure ancilla X. Its expectation is |<psi|phi>|^2, so ancilla outcome 0 after a final H has probability [1+|<psi|phi>|^2]/2. For mixed states the overlap becomes Tr(rho sigma), which is not generally the Uhlmann fidelity.
Fully worked reference example
Take |psi>=|0> and |phi>=(3/5)|0>+(4/5)|1>. The squared overlap is 9/25, so P(ancilla 0)=17/25 and P(1)=8/25. Orthogonal inputs give equal ancilla probabilities; identical pure inputs give outcome 0 with certainty.
Limitations and common misconceptions
Both input states must be prepared for each relevant trial, and controlled-SWAP may be costly. A single outcome 0 does not prove equality. For mixed states, even rho=sigma can yield Tr(rho^2)<1.
Scientific relationships
The former estimates a state overlap through exchange; the latter estimates a unitary overlap through coherent control.
Two mixed states with different overlap and fidelity
Take rho=(I+0.6Z)/2 and sigma=(I+0.8X)/2. Their Bloch vectors are perpendicular, so Tr(rho sigma)=(1+0)/2=1/2. An overlap circuit using independently prepared copies therefore gives the ancilla-zero probability 3/4. This outcome does not mean that the states are halfway identical under every quantum distance measure; it is one particular bilinear statistic.
For qubits, the squared Uhlmann fidelity is [1+r dot s+sqrt((1-|r| squared)(1-|s| squared))]/2. Substitution gives [1+sqrt(0.64 times 0.36)]/2=0.74. Thus the same pair has Hilbert-Schmidt overlap 0.5 and squared Uhlmann fidelity 0.74. The distinction comes from the extra determinant contribution in the mixed-state fidelity, which an ordinary SWAP expectation does not contain.
The purities are Tr(rho squared)=0.68 and Tr(sigma squared)=0.82. Combining three independently estimated overlaps gives the squared Hilbert-Schmidt distance Tr[(rho-sigma) squared]=0.68+0.82-2(0.5)=0.5. If rho is compared with another independent copy of itself, the ancilla-zero probability is (1+0.68)/2=0.84, despite the preparations being identical. The missing 0.16 probability reflects mixedness, not a mismatch between those two density operators.
A destructive Bell-measurement alternative
For a single pair of qubits, SWAP=(II+XX+YY+ZZ)/2. Its eigenvalue is +1 on the three symmetric Bell states and -1 on the antisymmetric singlet. A Bell-basis measurement can therefore measure SWAP without a coherent control ancilla. After CNOT from the first qubit to the second and H on the first, computational measurement identifies the Bell label; only the singlet label contributes -1.
For rho tensor sigma in the example, every Bell outcome has probability 1/4. Their signed average is consequently 3/4-1/4=1/2, reproducing the overlap. The outcome distribution contains more information than the single SWAP eigenvalue, but the input copies are consumed by the Bell measurement. This implementation is suitable when the comparison protocol requires only the statistic and does not need the original states afterward.
For n-qubit inputs, the full register exchange is the product of the n pairwise exchange operators. Local Bell measurements on corresponding qubit pairs therefore supply the global SWAP eigenvalue as the product of the pairwise signs. Entanglement within each n-qubit input does not invalidate that operator identity. The two complete input registers must still be independent preparations if the expectation is to equal Tr(rho sigma).
Why correlations between the inputs matter
Suppose instead that the two input qubits jointly occupy |Phi+>. Each separate marginal is I/2, and independent copies of those marginals would have overlap 1/2. The actual correlated joint state is symmetric under exchange, however, so its SWAP expectation is one. The overlap circuit then produces ancilla zero with certainty. It has correctly measured the joint exchange observable, but the interpretation as a product-state overlap would be incorrect.
A singlet supplies an even sharper boundary case: its SWAP expectation is -1, although an overlap Tr(rho sigma) between two positive density operators cannot be negative. The negative result is not an impossible measurement; it signals that the joint input cannot be treated as the required independent product. Shared preparation errors or unwanted interactions can introduce such correlations without changing every local diagnostic.
On independent inputs, each signed SWAP sample has variance 1-t squared for t=Tr(rho sigma). Here the variance of the sample mean is 3/(4N). The ancilla formulation gives the same expression because its estimator is twice the observed zero frequency minus one. Estimating three terms for a Hilbert-Schmidt distance adds their measurement variances with the squared coefficient of each term, including a factor of four for the cross overlap. Separate statistical budgets are therefore needed for a derived distance.
Resource and interpretation ledger
A comparison consumes two state preparations per trial. A controlled-exchange construction also requires controls over each corresponding pair; an apparent parallel arrangement can be limited by the shared control qubit. The destructive alternative uses pairwise entangling gates and local measurements, with connectivity and label interpretation still explicit. Classical statevector inner products are preferable when both states are already available as manageable classical arrays. Neither circuit returns all amplitudes or preserves an unknown state for unlimited repeated comparison.
In the independent-input example, the perpendicular Bloch vectors yield swap-test overlap 0.5. The squared Uhlmann fidelity for the same pair is 0.74. Four equally likely Bell outcomes and the distinct correlated inputs |Φ⁺⟩ and the singlet illustrate why an input model must be specified. These values are mathematical predictions.
Sources
Verification scope
Selected source text checked ·
Source anchors gate-decomposition conventions. New worked instances are independent mathematical constructions, not reported experiments.