Does the √SWAP gate have a ready-to-use function on the Qiskit circuit library?

If not, how to implement it?


1 Answer 1


I don't think √SWAP gate has a ready-to-use function in Qiskit. But it is easy to implement.

√SWAP unitary is: $$\sqrt{swap} = \left( {\begin{array}{*{20}{c}} 1&0&0&0 \\ 0&\frac{1}{2}(1 + i)&\frac{1}{2}(1 - i)&0 \\ 0&\frac{1}{2}(1 - i)&\frac{1}{2}(1 + i)&0 \\ 0&0&0&1 \end{array}} \right)$$

It is equivalent to:

enter image description here

So, it can be implemented as follows:

from qiskit import QuantumCircuit

circ = QuantumCircuit(2)
circ.cx(0, 1)
circ.csx(1, 0)
circ.cx(0, 1)

To verify:

from qiskit.quantum_info.operators import Operator
from qiskit.visualization import array_to_latex

op = Operator(circ)

And to use it as a gate:

sr_swap = circ.to_gate(label = '√SWAP')

qc = QuantumCircuit(2)
qc.append(sr_swap, [0, 1])
  • $\begingroup$ Thanks for this comprehensive answer. Is there a command that prints out the truth table for this circuit? $\endgroup$
    – Bekaso
    Commented Oct 29, 2021 at 11:43

Not the answer you're looking for? Browse other questions tagged or ask your own question.