← Quantum Computing
Quantum Computing

Multi-Qubit Programs

Multi-qubit programs coordinate large-scale entanglement and must respect hardware connectivity constraints at scale

Source: mortalapps.com
TL;DR
  • Multi-qubit programs are essential for implementing complex quantum algorithms, error correction, and molecular simulations.
  • A GHZ state is a highly entangled multi-qubit state represented as $\frac{1}{\sqrt{2}}(\lvert 00\dots0 \rangle + \lvert 11\dots1 \rangle)$.
  • Constructing a GHZ state programmatically requires applying a Hadamard gate to a lead qubit, followed by a cascade of CNOT gates.
  • Physical hardware constraints, such as coupling maps, require the transpiler to insert SWAP gates to route entanglement across the chip.
  • Physical error rates scale exponentially with the number of entangled qubits, requiring highly optimized gate sequences.
  • Programmatic circuit generation using Python loops is the standard way to scale quantum programs to many qubits.

Why This Matters

As we move beyond simple two-qubit systems, we enter the domain of true quantum utility. Multi-qubit programs are the building blocks of complex quantum algorithms, including quantum error correction, molecular simulation, and optimization. Programming these systems requires managing large-scale entanglement, coordinating complex gate sequences, and understanding how physical hardware constraints scale with the number of qubits.

When programming multi-qubit systems, you cannot treat qubits as isolated entities. You must design your circuits to match the physical topology of the target processor, minimize the propagation of errors across entangled states, and optimize gate scheduling to prevent decoherence. This requires a deep understanding of multi-qubit gate mechanics and programmatic circuit generation.

In this topic, you will learn how to design and execute multi-qubit programs in Qiskit. You will write code to construct a Greenberger-Horne-Zeilinger (GHZ) state, a highly entangled multi-qubit state that serves as a benchmark for quantum hardware. You will explore multi-qubit gate operations, learn how to route entanglement across complex coupling maps, and analyze how physical errors scale as you add more qubits to your program.

Core Intuition

Think of programming a multi-qubit system like orchestrating a large musical ensemble. A 2-qubit program is like a duet: it is relatively easy to keep the two musicians in sync and in harmony. However, as you add more musicians to create a full symphony orchestra (a multi-qubit system), the complexity scales dramatically.

You must ensure that all musicians are perfectly synchronized (gate scheduling). If one section of the orchestra plays too fast or too slow, the harmony is ruined (decoherence). Furthermore, you must arrange the musicians on the stage so that those who need to play together are sitting near each other (routing on a coupling map). If the violinists are scattered across the stage, they cannot hear each other well, leading to mistakes (gate errors).

In quantum programming, a GHZ state is like a massive, synchronized chord played by the entire orchestra. Every single instrument must hit the exact same note at the exact same microsecond. If even one instrument is out of tune, the entire chord collapses. By learning to program these complex states, you become the conductor of a highly sophisticated quantum orchestra.

Visualization

GHZ State Entanglement Cascade
GHZ State Entanglement Cascade Shows how a sequence of CNOT gates propagates superposition to create a multi-qubit entangled state.

Technical Explanation

A Greenberger-Horne-Zeilinger (GHZ) state is a highly entangled state of $n$ qubits, represented mathematically as:

$$\lvert \text{GHZ} \rangle = \frac{1}{\sqrt{2}}(\lvert 00\dots0 \rangle + \lvert 11\dots1 \rangle)$$

For a 3-qubit system, the state is $\frac{1}{\sqrt{2}}(\lvert 000 \rangle + \lvert 111 \rangle)$. Constructing this state programmatically requires applying a Hadamard gate to a lead qubit, followed by a cascade of CNOT gates that propagate the superposition to all other qubits.

Mathematically, the state transitions for a 3-qubit system starting in $\lvert 000 \rangle$ are: 1. Apply $H$ to qubit 0: $\frac{1}{\sqrt{2}}(\lvert 000 \rangle + \lvert 001 \rangle)$ (using Qiskit's little-endian notation where qubit 0 is the rightmost bit). 2. Apply CNOT with control 0 and target 1: $\frac{1}{\sqrt{2}}(\lvert 000 \rangle + \lvert 011 \rangle)$. 3. Apply CNOT with control 1 and target 2: $\frac{1}{\sqrt{2}}(\lvert 000 \rangle + \lvert 111 \rangle)$.

Here is a complete Qiskit 1.x program that programmatically generates a GHZ state for an arbitrary number of qubits, transpiles it for a fake backend, and simulates its execution:

PYTHON
from qiskit import QuantumCircuit
from qiskit_aer import AerSimulator
from qiskit.transpiler.preset_passmanagers import generate_preset_pass_manager
from qiskit_ibm_runtime.fake_provider import FakeSherbrooke

def build_ghz_circuit(num_qubits):
    """Programmatically generates an n-qubit GHZ state circuit."""
    qc = QuantumCircuit(num_qubits)
    # Step 1: Put the lead qubit in superposition
    qc.h(0)
    # Step 2: Cascade CNOT gates to entangle all qubits
    for i in range(num_qubits - 1):
        qc.cx(i, i + 1)
    qc.measure_all()
    return qc

# Generate a 5-qubit GHZ circuit
num_qubits = 5
ghz_circuit = build_ghz_circuit(num_qubits)
print(f"--- Logical {num_qubits}-qubit GHZ Circuit ---")
print(ghz_circuit.draw('text'))

# Load fake backend and transpile
fake_backend = FakeSherbrooke()
pm = generate_preset_pass_manager(backend=fake_backend, optimization_level=1)
isa_circuit = pm.run(ghz_circuit)

# Run noisy simulation
simulator = AerSimulator.from_backend(fake_backend)
job = simulator.run(isa_circuit, shots=1024)
result = job.result()
counts = result.get_counts()

print(f"\nNoisy Simulation Results ({num_qubits}-qubit GHZ):")
# Print the top 5 most frequent outcomes
sorted_counts = sorted(counts.items(), key=lambda x: x[1], reverse=True)
for outcome, count in sorted_counts[:5]:
    print(f"State |{outcome}>: Count = {count}")

In this code, we use a Python loop to programmatically scale the circuit to any number of qubits. When transpiled for FakeSherbrooke, the transpiler maps this linear cascade of CNOTs onto the physical heavy-hex coupling map of the chip, inserting SWAP gates if necessary to route the entanglement.

Key Takeaways

Multi-qubit programs are essential for implementing complex quantum algorithms, error correction, and molecular simulations.
A GHZ state is a highly entangled multi-qubit state represented as $\frac{1}{\sqrt{2}}(\lvert 00\dots0 \rangle + \lvert 11\dots1 \rangle)$.
Constructing a GHZ state programmatically requires applying a Hadamard gate to a lead qubit, followed by a cascade of CNOT gates.
Physical hardware constraints, such as coupling maps, require the transpiler to insert SWAP gates to route entanglement across the chip.
Physical error rates scale exponentially with the number of entangled qubits, requiring highly optimized gate sequences.
Programmatic circuit generation using Python loops is the standard way to scale quantum programs to many qubits.