Start Here › Student guides · Printable PDF of all guides
Guide 1 — Your first project, step by step
About 30 minutesSimulator only
This guide walks through Q01 — Quantum Coin from an empty folder to a finished experiment. Every later project follows the same routine, so learning it once here saves time on all of them.
Step 1 — Read first
Read Chapter 1. You need one idea from it: a qubit prepared with a Hadamard gate, H|0⟩, has probability ½ of giving 0 and ½ of giving 1 when measured.
Step 2 — Write your prediction before any code
Open a text file and answer these three questions. This is the part students skip, and it is the part that makes the work scientific.
- State. H|0⟩ = (|0⟩ + |1⟩)/√2.
- Prediction. P(0) will be close to 0.5, and it will get closer as the number of shots grows.
- Metric. The distance from the ideal value, |P(0) − 0.5|, for 10, 100, 1,000, and 10,000 shots.
Step 3 — Create your project folder
Use your own GitHub username in the folder name.
projects/q01-yourgithubname/ README.md notebook.ipynb results/raw/ results/figures/ environment/requirements.txt REPORT.md
Step 4 — Set up the software
You need Python 3. In a terminal, or in the first cell of a notebook with ! in front, run:
pip install qiskit qiskit-aer matplotlib
Step 5 — Run the baseline
Put this in notebook.ipynb and run it. It builds the circuit, runs it for each shot count, saves the raw counts, and draws one figure.
import json, os
from qiskit import QuantumCircuit
from qiskit_aer import AerSimulator
import matplotlib.pyplot as plt
# 1. Build the circuit: H on |0>, then measure
qc = QuantumCircuit(1, 1)
qc.h(0)
qc.measure(0, 0)
# 2. Run the baseline for each shot count
sim = AerSimulator(seed_simulator=7)
results = []
for shots in [10, 100, 1000, 10000]:
counts = sim.run(qc, shots=shots).result().get_counts()
p0 = counts.get("0", 0) / shots
p1 = counts.get("1", 0) / shots
results.append({"shots": shots, "counts": counts,
"P0": p0, "P1": p1, "abs_error": abs(p0 - 0.5)})
print(shots, counts, round(p0, 4), round(abs(p0 - 0.5), 4))
# 3. Save the raw data (never only a screenshot)
os.makedirs("results/raw", exist_ok=True)
os.makedirs("results/figures", exist_ok=True)
with open("results/raw/q01_counts.json", "w") as f:
json.dump(results, f, indent=2)
# 4. One labeled figure
plt.plot([r["shots"] for r in results], [r["abs_error"] for r in results], "o-")
plt.xscale("log")
plt.xlabel("Number of shots")
plt.ylabel("|P(0) - 0.5|")
plt.title("Q01: sampling error vs. shots")
plt.savefig("results/figures/q01_error_vs_shots.png", dpi=150, bbox_inches="tight")
Step 6 — Check what you got
You should see four lines, one per shot count. Your numbers will differ from these because measurement is random, but the pattern should be the same: the error gets smaller as shots increase.
| Shots | Example counts | P(0) | |P(0) − 0.5| |
|---|---|---|---|
| 10 | 0: 4, 1: 6 | 0.40 | 0.10 |
| 100 | 0: 54, 1: 46 | 0.54 | 0.04 |
| 1,000 | 0: 514, 1: 486 | 0.514 | 0.014 |
| 10,000 | 0: 5012, 1: 4988 | 0.5012 | 0.0012 |
Two files should now exist: results/raw/q01_counts.json and results/figures/q01_error_vs_shots.png. If they do, your baseline is done.
Step 7 — Add one controlled extension
Change exactly one thing and keep everything else fixed. Write a prediction first. Two ideas that fit Q01:
- Repeat the experiment. Run each shot count 20 times and look at how much P(0) varies between runs. Prediction to test: the spread shrinks as shots grow.
- Change the state. Replace
qc.h(0)withqc.x(0)and predict the counts before you run it.
Step 8 — Record your environment
So that someone else can reproduce your result, save the exact package versions:
pip freeze > environment/requirements.txt
Step 9 — Write it up
Fill in README.md and REPORT.md. Guide 2 gives you templates for both.
Before you move on, check
- The prediction was written before the code was run.
- Raw counts are saved as a file, not only shown on screen.
- The metric is a number.
- The figure has axis labels and a title.
- No passwords, tokens, or API keys are anywhere in the folder.