OQCL   HomeStart Here7 SessionsTextbookProjectsQUEST LabSubmitUse CasesInstructor GuideReferences

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.

About the tool. OQCL is platform-neutral and you may use any suitable simulator. The code below uses Qiskit with the Aer simulator as one working option. It was tested with Qiskit 2.6 and Qiskit Aer 0.18.

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.

  1. State. H|0⟩ = (|0⟩ + |1⟩)/√2.
  2. Prediction. P(0) will be close to 0.5, and it will get closer as the number of shots grows.
  3. 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.

ShotsExample countsP(0)|P(0) − 0.5|
100: 4, 1: 60.400.10
1000: 54, 1: 460.540.04
1,0000: 514, 1: 4860.5140.014
10,0000: 5012, 1: 49880.50120.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:

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

Next: Guide 2 — Writing the reportBack to Start Here