Qiskit Fundamentals

Lesson 8 of 8

Final Project: Build and Verify an Entangled Circuit

Every piece from this course now exists on its own: building circuits, superposition, gates, entanglement, shot-based measurement, and a quantum random number generator. This final project assembles several of them into one small, verifiable quantum program.

Requirements

Your finished quantum_project.py should satisfy every one of these:

  1. Build a 2-qubit Bell state circuit (h then cx).
  2. Inspect it with Statevector and print its exact probabilities, confirming |01>/|10> are (numerically) zero.
  3. Run the same circuit on AerSimulator with at least 1000 shots, and print the resulting counts.
  4. Write a Python function verify_entanglement(counts) that checks every observed bitstring in counts is either '00' or '11' (allow a small tolerance if you experiment with real hardware in the stretch goals), and prints whether entanglement was verified.
  5. Reuse (or rewrite) the quantum_random_bits(n_bits) function from the RNG lesson, and use it to generate and print 5 random numbers between 0 and 255.
from qiskit import QuantumCircuit
from qiskit.quantum_info import Statevector
from qiskit_aer import AerSimulator

def build_bell_circuit():
    qc = QuantumCircuit(2, 2)
    qc.h(0)
    qc.cx(0, 1)
    return qc

def verify_entanglement(counts):
    valid = all(bitstring in ('00', '11') for bitstring in counts)
    print('Entanglement verified!' if valid else 'Unexpected outcome, entanglement broken or noisy hardware.')
    return valid

# 1-2: build and inspect
qc = build_bell_circuit()
state = Statevector(qc)
print('Probabilities:', state.probabilities())

# 3-4: run and verify
qc.measure([0, 1], [0, 1])
simulator = AerSimulator()
counts = simulator.run(qc, shots=1000).result().get_counts()
print('Counts:', counts)
verify_entanglement(counts)

Stretch goals

  • Run your circuit on real IBM Quantum hardware (free tier) and compare the counts to the ideal simulator, is entanglement still verified within a reasonable tolerance?
  • Build a 3-qubit GHZ state (h(0), then cx(0, 1), then cx(1, 2)) and extend verify_entanglement to check that only '000'/'111' appear.
  • Add a simple quantum coin flip game: use quantum_random_bits(1) to decide a winner, and explain in a comment why this is fundamentally fairer than random.randint(0, 1).
  • Plot the counts histogram with matplotlib instead of just printing the dictionary.

Submit a link to your finished project (a repo or gist) below, an instructor will review it before you can mark this lesson complete.

This lesson ends in a project. Build it on your own machine, there's nowhere to submit it here, but the brief above is everything you need.