Site Tools


swap-gate-qiskit

Table of Contents

SWAP gate (Qiskit)

SWAP gate implementation using Qiskit. The example prepares $\lvert 10\rangle$ and applies SWAP to produce $\lvert 01\rangle$.

from qiskit import QuantumCircuit
from qiskit.quantum_info import Statevector
 
qc = QuantumCircuit(2)
qc.x(1)       # q0=|0>, q1=|1> => |10> in math ordering
qc.swap(0, 1) # |10> -> |01>
print(Statevector(qc))
# Statevector([0.+0.j, 1.+0.j, 0.+0.j, 0.+0.j], dims=(2, 2))
swap-gate-qiskit.txt ยท Last modified: by 127.0.0.1