0

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

If not, how to implement it?

Bekaso
  • 285
  • 2
  • 5

1 Answers1

2

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) array_to_latex(op)

And to use it as a gate:

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

qc = QuantumCircuit(2) qc.append(sr_swap, [0, 1])

Egretta.Thula
  • 9,972
  • 1
  • 11
  • 30
  • Thanks for this comprehensive answer. Is there a command that prints out the truth table for this circuit? – Bekaso Oct 29 '21 at 11:43