|ψ⟩ register A |φ⟩ register B ancilla qubit

Quantum Swap Test: State Overlap Estimator (2D)

Quantum machine learning algorithms need a way to measure "how similar" two data points are once they've been encoded as quantum states — that's exactly what the swap test provides. This 2D simulator builds the real joint statevector of three qubits — two data registers, A and B, each set from its own Bloch-circle angles, plus an ancilla qubit — and pushes it through an explicit Hadamard–controlled-SWAP–Hadamard circuit, amplitude by amplitude. Firing a batch of shots then samples real Born-rule outcomes from that simulated ancilla marginal, and the running measured statistics visibly converge toward the exact overlap as more shots accumulate — the same statistical process that underlies quantum k-means, quantum kNN and quantum kernel classifiers.