Qiskit: Hadamard Gate

The Hadamard Gate is one of the most important gates in Quantum Computing. Qiskit provides a method for applying Hadamard Gate on a Qubit. In this chapter of the Qiskit Tutorial, you will learn about Hadamard Gate and how to apply the Hadamard Gate on a Qubit in Qiskit.

Hadamard Gate

The Hadamard Gate or sometimes also known as H Gate acts on a single Qubit. The Hadamard Gate can be used to create a state of superposition in a Qubit. For this reason, Hadamard Gate is sometimes also known as the Gateway to Quantum realm.

Example

For a Qubit in state Ψ = 1/sqrt(3) |0> + sqrt(2/3) |1>, the application of Hadamard Gate will change the state of the Qubit to Ψ = 0.986 |0> - 0.169 |1> (approximated).

The application of Hadamard Gate usually results in a change of both, phase and probabilities.

Hadamard Gate: Bloch Sphere

The Hadamard Gate performs a rotation of 180° or π radians about the XZ-axis(the axis making a 45° angle with both X axis and Z axis) on the Bloch Sphere.

Example

In this example, we will look at how the application of Hadamard gate on the Qubit affects its representation on the Bloch Sphere. Remember how Hadamard Gate performs a rotation of 180° or π radians about the XZ-axis on the Bloch Sphere.

In the below figure, the Hadamard Gate is applied on a Qubit in the state Ψ = |0>, and the resulting state of the Qubit is Ψ = |+>.

Qiskit Hadamard Gate Effect
Applying Hadamard Gate on Qubits in state |0>

In the below figure, the Hadamard Gate is applied on a Qubit in the state Ψ = |1> and the resulting state of the Qubit is Ψ = |->.

Qiskit Hadamard Gate Effect
Applying Hadamard Gate on Qubits in state |1>

Note– Since Hadamard Gate performs rotation about the XZ-axis, it will have no effect on a vector that lies on the XZ-axis.

Hadamard Gate: Matrix

The Hadamard Gate in Quantum Computing is represented by the matrix H

Matrix of Hadamard Gate

The resulting state of a Qubit after the application of Hadamard Gate can also be calculated by multiplying the Matrix for Hadamard Gate with the vector representing the state of the Qubit.

Example

In this example, we will apply the Hadamard gate to a Qubit, and calculate the resulting state by Multiplying it with the Matrix for the Hadamard Gate.

Let the state of the Qubit be Ψ = 1/sqrt(3) |0> + sqrt(2/3) |1>

After Applying the Hadamard Gate, the resulting state of the Qubit can be calculated by-

Calculating result of Hadamard Gate applied on a Qubit

Notice the change in both, probabilities and phase on the application of Hadamard Gate.

Inverse of Hadamard Gate

The Hadamard is its own inverse. Therefore, applying Hadamard Gate to the same Qubit twice will result in the original state of the Qubit.

Example

For a Qubit in state Ψ = 1/sqrt(3) |0> + sqrt(2/3) |1>, the application of Hadamard Gate will change the state of the Qubit to Ψ = 0.986 |0> - 0.169 |1>.

After application of the Hadamard Gate again to the same Qubit, the resulting state of the Qubit will be Ψ = 1/sqrt(3) |0> + sqrt(2/3) |1>.

Since applying Hadamard Gate twice to the same Qubit results in the same state, Hadamard Gate is its own inverse.

Hadamard Gate in Qiskit

The Hadamard Gate in Qiskit can be applied to any Qubit by calling the h() method on the Quantum Circuit(an instance of QuantumCircuit class) and passing it an integer for the Qubit on which Hadamard Gate is to be applied.

Example

In this example, we will be applying Hadamard Gate on the first Qubit in the Quantum Circuit, which will contain 2 Qubits.

# Creating a Quantum Register with 1 Qubit
qr = qiskit.QuantumRegister(2)

# Creating a Quantum Circuit
circuit = QuantumCircuit(qr)

# Applying Hadamard Gate on the first Qubit
circuit.h(0)

# Drawing the Quantum Circuit
circuit.draw()

This will result in the following Quantum Circuit being drawn-

Notice that the Hadamard Gate is applied to the first Qubit. Also notice, that Qubits follow a 0 based indexing.