Does the √SWAP gate have a ready-to-use function on the Qiskit circuit library?
If not, how to implement it?
Quantum Computing Stack Exchange is a question and answer site for engineers, scientists, programmers, and computing professionals interested in quantum computing. It only takes a minute to sign up.
Sign up to join this communityDoes the √SWAP gate have a ready-to-use function on the Qiskit circuit library?
If not, how to implement it?
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:
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])