2 min read

Quantum Gate Implementations on Qiskit

Quantum Gate Implementations on Qiskit

Single Input Gates

There are six different single-input gates whose are: X, Y, Z, S, T and Hadamard gates. X, Y and Z gate rotates Bloch sphere on their named axis by $\pi$ radians. Therefore, they may be called as a bit flip gate for X gate, and phase flip gate for Z gate.

X Gate (NOT Gate for classical states)

Input: $|0\rangle$

from qiskit import QuantumRegister, QuantumCircuit
from numpy import pi

qreg_q = QuantumRegister(1, 'q')
circuit = QuantumCircuit(qreg_q)

circuit.reset(qreg_q[0])
circuit.x(qreg_q[0])

Input: $|-\rangle$

from qiskit import QuantumRegister, QuantumCircuit
from numpy import pi

qreg_q = QuantumRegister(1, 'q')
circuit = QuantumCircuit(qreg_q)

circuit.reset(qreg_q[0])
circuit.x(qreg_q[0])
circuit.h(qreg_q[0])
circuit.x(qreg_q[0])

Multiple Input Gates

There may be many multiple input gates out there, however, what we'll cover in this post is CNOT gate, Bell's states, Toffoli gate and Swap gate.

Bell's States

Bell introduces a standard way to represent quantum entanglement.

Input: $|00\rangle$

from qiskit import QuantumRegister, QuantumCircuit
from numpy import pi

qreg_q = QuantumRegister(2, 'q')
circuit = QuantumCircuit(qreg_q)

circuit.reset(qreg_q[0])
circuit.reset(qreg_q[1])
circuit.barrier(qreg_q[0], qreg_q[1])
circuit.h(qreg_q[0])
circuit.barrier(qreg_q[0], qreg_q[1])
circuit.cx(qreg_q[0], qreg_q[1])

Input: $|01\rangle$

from qiskit import QuantumRegister, QuantumCircuit
from numpy import pi

qreg_q = QuantumRegister(2, 'q')
circuit = QuantumCircuit(qreg_q)

circuit.reset(qreg_q[0])
circuit.reset(qreg_q[1])
circuit.x(qreg_q[1])
circuit.barrier(qreg_q[0], qreg_q[1])
circuit.h(qreg_q[0])
circuit.barrier(qreg_q[0], qreg_q[1])
circuit.cx(qreg_q[0], qreg_q[1])

Input: $|10\rangle$

from qiskit import QuantumRegister, QuantumCircuit
from numpy import pi

qreg_q = QuantumRegister(2, 'q')
circuit = QuantumCircuit(qreg_q)

circuit.reset(qreg_q[0])
circuit.reset(qreg_q[1])
circuit.x(qreg_q[0])
circuit.barrier(qreg_q[0], qreg_q[1])
circuit.h(qreg_q[0])
circuit.barrier(qreg_q[0], qreg_q[1])
circuit.cx(qreg_q[0], qreg_q[1])

Input: $|11\rangle$

from qiskit import QuantumRegister, QuantumCircuit
from numpy import pi

qreg_q = QuantumRegister(2, 'q')
circuit = QuantumCircuit(qreg_q)

circuit.reset(qreg_q[0])
circuit.reset(qreg_q[1])
circuit.x(qreg_q[0])
circuit.x(qreg_q[1])
circuit.barrier(qreg_q[0], qreg_q[1])
circuit.h(qreg_q[0])
circuit.barrier(qreg_q[0], qreg_q[1])
circuit.cx(qreg_q[0], qreg_q[1])