Basic Quantum Computing Gates using IBM Qiskit

Tanvesh Takawale
Qubit Factory
Published in
5 min readJun 1, 2020

--

Introduction

Quantum Gate is a quantum circuit applying various operations on qubits. In analogous to classical computers we have the gates like XOR, NOT, AND, etc which perform operations on the classical bits and changes their values according to the gate.

Contents

1. Prerequisites

2. Quantum Logic Gates

Prerequisites

Representation of Qubit

A Qubit is represented in terms of the probabilistic amplitudes of various states it can be in.

Example: A single qubit is represented in this particular form:

|ψ⟩ = α|0⟩+β|1⟩

where,

  • |α|² + |β|² = 1
  • α and β: They are the possibility amplitudes of state |0⟩ and |1⟩ respectively.
  • In simple words, |α|² is the possibility of qubit being in state|0⟩ and |β|² is the possibility of qubit being in state |1⟩.

Bloch Sphere

Bloch sphere is a geometric representation of a qubit in its state space. In simple words after applying some quantum gates to the qubit or any qubit which is present in a superposition then the possible number of states and their phase can be visualized using a Bloch Sphere.

Bloch Sphere

In the above image, we can see that the state |0⟩ at the top of the sphere and state|1⟩ appears at the bottom.

Now, let us move onto the main topic for this article.

Quantum Logic Gates

For understanding all these gates we will be using a 1-Qubit Quantum Circuit. So the following code will be the initialization of the Quantum Circuit.

#Imports
from qiskit import QuantumCircuit, execute, Aer, IBMQ
from qiskit.compiler import transpile, assemble
from qiskit.tools.jupyter import *
from qiskit.visualization import *

Quantum Circuit Initializations

#backend is where you simulate the cirucit
backend = Aer.get_backend('statevector_simulator')
qc = QuantumCircuit(1)
qc.draw()
job = execute(qc, backend).result()
plot_state_qsphere(job.get_statevector(qc))
One Qubit Circuit Created
State After Initialization

Note:

  • Qubits are indexed from 0 so the first qubit is addressed as qubit ‘0’.
  • QuantumCircuit.{GATE}(parameter), the parameter means the qubits list or qubit number.

Pauli-X Gate

This gate performs a similar operation to the state of the qubit like a NOT gate does in terms of classical computing. In other terms, the probabilities of the state |0⟩ and |1⟩ are switched by using this gate.

qc.x(0) #X gate applied on qubit 0
After Applying X get the Circuit

In mathematical terms,

Pauli X Matrix

The above matrix is multiplied with the state vector matrix of the qubit and then the following “bit-flip” is achieved.

After Applying the X Gate

Hadamard Gate

This gate is used to give equal probabilities to different possible states that a qubit can represent. So basically a qubit goes into superposition after applying this gate.

qc.h(0) #H gate applied on qubit 0
H gate applied to qubit 0.

In mathematical terms,

Hadamard Matrix

By multiplying with the above matrix the qubit goes into superposition. Considering a single qubit with initial state 0 it will have 0.5 probability for state |0⟩ and 0.5 probability for state |1⟩.

qsphere after H gate

Pauli-Y Gate

It is a gate which performs the bit flip as the X gate does and also changes the phase of the qubit by π radians.

qc.y(0) #Y Gate applied on qubit 0
Circuit After applying Y gate

In mathematical terms,

Pauli Y Matrix

The above matrix is multiplied with the state vector matrix to achieve bit flip + phase change. To achieve the phase change the matrix should be in superposition. The rotation of the angle is with respect to the Y-axis of the Bloch sphere.

After Applying H and Y Gate

Pauli-Z Gate

It is a gate which is used to change the phase of the qubit. It changes it by π radians but along the Z-axis. It is also called as the phase shift gate.

qc.z(0) #Z Gate applied to qubit 0
After Applying Z Gate

In mathematical terms,

Pauli Z Matrix

The above matrix multiplied with the state vector of the qubit gives us the phase shift.

After Applying H and Z Gate

Difference Between Z and Y Gates:

  • Y represents a bit+phase flip gate whereas a Z gate is just a phase shift gate.
  • The phase change is applied to different axes, for Y it’s Y-axis and for Z it’s Z-axis.

References

  1. https://en.wikipedia.org/wiki/Quantum_logic_gate
  2. https://quantum-computing.ibm.com/
  3. https://qiskit.org/

--

--