Updated: 27/10/25
This tutorial is an excerpt from our textbook Introduction to Quantum Computing with Qiskit.
What is the Hadamard gate?
The Hadamard gate is one of the most important gates in quantum computing. Simply put it puts a qubit in to superposition of states such that if the qubit is |0〉then the state will become:
and if the state is |1〉then the state will become:
This means that when the qubit is measured it will collapse to either |0〉or |1〉with equal probability.
In terms of rotations this corresponds to a rotation of pi radians around the Z-axis followed by pi/2 (90 degrees) around the Y-axis. This means that the pure state will be on the equator of the bloch sphere.
Note that if the state is |0〉then the resulting state will be on the equator of the bloch sphere (known as |+〉) but if it is |1〉then it will be on the opposite side of the equator (known as |−〉).
In quantum computing logic gates are described using matrices. The matrix associated with the Hadamard gate is:
By multiplying the qubits state by the matrix above we can see how the logic gate affects the qubits state. For example if we initialise the qubit to |0〉and apply the Hadamard gate :
Which has mapped:
If we instead initialise the qubit to |1〉and apply a Hadamard gate:
Which has mapped:
Implementation
In Qiskit the Hadamard gate can be demonstrated easily by applying a Hadamard gate to a qubit and then measuring it.
Circuit diagram of the program
Device used
This tutorial uses the Qiskit Aer simulator in order to run the circuit. Note that results from this simulator contain no errors unlike on real quantum devices which are prone to noise.
More information on Qiskit Aer can be found here: https://qiskit.github.io/qiskit-aer/tutorials/1_aersimulator.html
In order to use to a real quantum device follow the steps here: https://quantum.cloud.ibm.com/docs/en/guides/initialize-account
Note: This program requires that you have an API token. To get one sign up to IBM Q Experience and get your token here: https://quantum-computing.ibm.com/account
Source
from qiskit import QuantumCircuit, transpile, ClassicalRegister, QuantumRegister from qiskit_aer import AerSimulator backend = AerSimulator() # Using local Aer simulator q = QuantumRegister(1,'q') # Initialise quantum register c = ClassicalRegister(1,'c') # Initialise classical register circuit = QuantumCircuit(q,c) # Initialise circuit circuit.h(q[0]) # Put Qubit 0 in to superposition using hadamard gate circuit.measure(q,c) # Measure qubit circ = transpile(circuit, backend) # Rewrites the circuit to match the backend's basis gates and coupling map shots = 1024 # Run and get counts result = backend.run(circ,shots=shots).result() counts = result.get_counts(circ) print('RESULT: ',counts) # Print result
Output
Output showing the qubit measurements when measured 1024 times
