Circuits

Swap Test Circuit

class SwaptestCircuit(qc_state_1, qc_state_2, name=None)[source]

Bases: qiskit.circuit.quantumcircuit.QuantumCircuit

Constructs a swap test circuit employing a controlled swap: .. parsed-literal:

         ┌───┐       ┌───┐┌─┐
q_0: ────┤ H ├─────■─┤ H ├┤M├
     ┌───┴───┴───┐ │ └───┘└╥┘
q_1: ┤ circuit-0 ├─X───────╫─
     ├───────────┤ │       ║
q_2: ┤ circuit-1 ├─X───────╫─
     └───────────┘         ║
c: 1/══════════════════════╩═
                           0

A swap test circuit allows to measure the fidelity between two quantum states, which can be interpreted as a distance measure of some sort. In other words, given two quanutm states \(|\alpha\rangle, \ |\beta\rangle\), it measures how symmetric the state \(|\alpha\rangle \otimes |\beta\rangle\) is