This 2D version runs the exact same swap-test circuit as the 3D edition, but instead of just plugging angles into the closed-form formula, it builds the real 3-qubit joint statevector (ancilla ⊗ register A ⊗ register B, 8 complex amplitudes) and applies each gate to it directly — Hadamard on the ancilla, a genuine controlled-SWAP of the A/B amplitudes, then Hadamard again — before reading off the ancilla's marginal probability.
Circuit: |0⟩ ancilla — H — •SWAP• — H — measure
|ψ⟩ ——————×—————————
|φ⟩ ——————×—————————
P(ancilla = 0) = 1/2 + 1/2·|⟨ψ|φ⟩|² (derived here from the simulated amplitudes, not assumed)
Each "shot" draws one Bernoulli sample from that simulated marginal probability, exactly like a real quantum device repeating the circuit from scratch every run. No single shot reveals the overlap — only the accumulated statistics converge on the true fidelity, which the convergence chart plots live against the shot count.
- θ, φ sliders — set each register's state on its Bloch circle: |ψ⟩ = cos(θ/2)|0⟩ + eiφsin(θ/2)|1⟩.
- B = A — snaps register B onto register A (fidelity 1, ancilla always |0⟩).
- B ⟂ A — snaps B to the antipodal point (fidelity 0, a true orthogonal state).
- Amplitude bars — the 8 basis-state probabilities |⟨anc,a,b|Ψ⟩|² of the actual post-circuit statevector, grouped by ancilla outcome.
- Run 100 / 1000 shots — fires that many independent circuit repetitions, sampled from the simulated Born-rule probability computed above.
Why it matters for QML: the swap test lets an algorithm compare two data points encoded as quantum states — the core operation behind quantum distance-based classifiers, quantum kernels and quantum k-means — without ever performing full state tomography, which would need exponentially many measurements.