Table of Contents

GHZ state (Qiskit)

GHZ state implementation using Qiskit. The three-qubit GHZ state $(\lvert 000\rangle + \lvert 111\rangle)/\sqrt{2}$ is prepared by applying a Hadamard gate to the first qubit and then chaining CNOT gates to spread the superposition to the remaining qubits.

from qiskit import QuantumCircuit
from qiskit.quantum_info import Statevector
 
qc = QuantumCircuit(3)
qc.h(0)      # |000> -> (|000> + |100>) / sqrt(2)
qc.cx(0, 1)  # -> (|000> + |110>) / sqrt(2)
qc.cx(0, 2)  # -> (|000> + |111>) / sqrt(2)
print(Statevector(qc))
# Statevector([0.70710678+0.j, 0.+0.j, ..., 0.70710678+0.j], dims=(2, 2, 2))
# non-zero only at |000> (index 0) and |111> (index 7)