Home▸Articles▸Quantum Computing

Quantum Swap Test: State Overlap Estimator

A fundamental quantum algorithm for estimating state overlap, essential for various quantum machine learning tasks.

mysimulator teamUpdated June 2026≈ 4 min read▶ Open the simulation

What is the Quantum Swap Test?

The quantum swap test, also known as the Grover–Lovett algorithm, is a quantum circuit designed to estimate the overlap or fidelity (f) between two arbitrary quantum states |ψ⟩ and |φ⟩. This overlap is crucial in many quantum algorithms, including quantum machine learning techniques like quantum k-means clustering and kernel-based methods.

The test involves preparing an ancilla qubit in the state |+⟩ = (|0⟩ + |1⟩)/√2 and applying a controlled-swap operation between this ancilla and each of the two states. The final measurement on the ancilla reveals information about the overlap, which can be statistically estimated from multiple runs.

How Does It Work?

The quantum swap test circuit consists of three qubits: one ancilla and two target states |ψ⟩ and |φ⟩. The ancilla is first prepared in the state |+⟩, then a controlled-swap operation (CSWAP) is applied between the ancilla and each of the target states. This operation effectively swaps the ancilla's state with the target state if they are identical; otherwise, it leaves the ancilla unchanged.

After these operations, a measurement on the ancilla qubit yields either |0⟩ or |1⟩. The probability distribution of these outcomes is directly related to the overlap between the two states: f = (1 + 2Re⟨ψ|φ⟩)/4.

live demo · related simulation● LIVE

Why Is It Important?

The quantum swap test is significant because it allows for the estimation of state fidelity without directly measuring the target states, which can be a complex and noisy process. This non-destructive measurement capability makes it particularly useful in scenarios where preserving the integrity of the quantum states is crucial.

Moreover, this algorithm forms the basis for more advanced quantum machine learning techniques that rely on estimating similarities between data points represented as quantum states.

Real-World Applications

The quantum swap test has applications in various fields of quantum computing and machine learning. For example, it can be used to compare the similarity of different datasets or to optimize parameters in quantum neural networks.

In practical terms, this algorithm helps in reducing the number of measurements required for state comparison, thereby improving efficiency and accuracy in quantum computations.

Frequently asked questions

How does the swap test differ from direct measurement?

The swap test avoids directly measuring the target states, which can be destructive. Instead, it uses a controlled-swap operation to infer the overlap between two states through ancilla measurements.

What is the significance of the fidelity in quantum computing?

Fidelity measures how close two quantum states are. It's crucial for tasks like state preparation, error correction, and comparing different quantum algorithms or datasets.

Can the swap test be used with any pair of quantum states?

Yes, the swap test can be applied to any pair of quantum states, regardless of their complexity. It provides a general method for estimating state overlap without direct measurement.

How does the swap test relate to quantum machine learning?

The swap test is foundational in quantum machine learning as it allows for efficient estimation of kernel functions and similarities between data points, which are essential for algorithms like k-means clustering and support vector machines.

Try it live

Everything above runs in your browser — open Quantum Swap Test: State Overlap Estimator and change the parameters while it is running. Nothing is installed, nothing is uploaded, the whole model lives in one tab.

▶ Open Quantum Swap Test: State Overlap Estimator simulation

What did you find?

Add reproduction steps (optional)