mirror of
https://github.com/saymrwulf/QuantumLearning.git
synced 2026-05-14 20:58:00 +00:00
747 lines
32 KiB
Text
747 lines
32 KiB
Text
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"<!-- QL_BADGE -->\n",
|
|
"<div style=\"padding:0.55rem 0.8rem; border-left:6px solid #2563eb; background:#dbeafe; color:#1e3a8a; border-radius:0.35rem; font-family:Helvetica, Arial, sans-serif; margin:0.15rem 0 0.85rem 0;\">\n",
|
|
"<strong>META READING</strong> · Difficulty 1/10 · Notebook-level rule, objective, or usage guidance.\n",
|
|
"</div>\n",
|
|
"\n",
|
|
"# Gates and Measurement Lab\n",
|
|
"\n",
|
|
"This lab turns protocol language into concrete manipulation. The main question is not whether the circuit executes. The main question is whether you can change preparation, basis, or reporting one at a time and still keep the explanation stable.\n"
|
|
],
|
|
"id": "d301b31d"
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"<!-- QL_BADGE -->\n",
|
|
"<div style=\"padding:0.55rem 0.8rem; border-left:6px solid #2563eb; background:#dbeafe; color:#1e3a8a; border-radius:0.35rem; font-family:Helvetica, Arial, sans-serif; margin:0.15rem 0 0.85rem 0;\">\n",
|
|
"<strong>META READING</strong> · Difficulty 1/10 · Official walkthrough guardrail.\n",
|
|
"</div>\n",
|
|
"\n",
|
|
"<!-- COURSE_NAV_TOP -->\n",
|
|
"## Mainline Navigation\n",
|
|
"\n",
|
|
"Step 12 of 59. Follow the official walkthrough in order.\n",
|
|
"\n",
|
|
"Previous notebook: [Gates and Measurement Lecture](lecture.ipynb)\n",
|
|
"\n",
|
|
"Next notebook: [Gates and Measurement Problems](problems.ipynb)\n",
|
|
"\n",
|
|
"Rule: complete the mandatory cells in this notebook before you open the next one.\n"
|
|
],
|
|
"id": "c3c741de"
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"<!-- QL_BADGE -->\n",
|
|
"<div style=\"padding:0.55rem 0.8rem; border-left:6px solid #2563eb; background:#dbeafe; color:#1e3a8a; border-radius:0.35rem; font-family:Helvetica, Arial, sans-serif; margin:0.15rem 0 0.85rem 0;\">\n",
|
|
"<strong>META READING</strong> · Difficulty 1/10 · Notebook-level rule, objective, or usage guidance.\n",
|
|
"</div>\n",
|
|
"\n",
|
|
"## Lab Protocol\n",
|
|
"\n",
|
|
"Use the same lab cycle as before: predict, edit one thing, render, inspect, and revise. The only difference here is that you should now classify the edit even more explicitly. Did you change the prepared state, the measurement basis, or the classical reporting layer? If you cannot answer that, the edit was not conceptually controlled enough.\n"
|
|
],
|
|
"id": "a4f30dbd"
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"ql_injected": "badge",
|
|
"ql_track": "mandatory",
|
|
"ql_role": "setup"
|
|
},
|
|
"source": [
|
|
"<!-- QL_BADGE -->\n",
|
|
"<div style=\"padding:0.55rem 0.8rem; border-left:6px solid #6b7280; background:#e5e7eb; color:#111827; border-radius:0.35rem; font-family:Helvetica, Arial, sans-serif; margin:0.15rem 0 0.85rem 0;\">\n",
|
|
"<strong>MANDATORY SETUP</strong> · Difficulty 1/10 · Environment, import, or helper cell required by the notebook.\n",
|
|
"</div>\n"
|
|
],
|
|
"id": "36a43fbf"
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"from pathlib import Path\n",
|
|
"import sys\n",
|
|
"\n",
|
|
"project_root = Path.cwd().resolve()\n",
|
|
"while not (project_root / \"pyproject.toml\").exists():\n",
|
|
" if project_root.parent == project_root:\n",
|
|
" raise RuntimeError(\"Could not locate the project root from this notebook.\")\n",
|
|
" project_root = project_root.parent\n",
|
|
"\n",
|
|
"src_path = project_root / \"src\"\n",
|
|
"if str(src_path) not in sys.path:\n",
|
|
" sys.path.insert(0, str(src_path))\n"
|
|
],
|
|
"id": "50c7b992"
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"ql_injected": "badge",
|
|
"ql_track": "mandatory",
|
|
"ql_role": "exercise"
|
|
},
|
|
"source": [
|
|
"<!-- QL_BADGE -->\n",
|
|
"<div style=\"padding:0.55rem 0.8rem; border-left:6px solid #15803d; background:#dcfce7; color:#14532d; border-radius:0.35rem; font-family:Helvetica, Arial, sans-serif; margin:0.15rem 0 0.85rem 0;\">\n",
|
|
"<strong>MANDATORY EXERCISE</strong> · Difficulty 2/10 · Official walkthrough runnable or written exercise.\n",
|
|
"</div>\n"
|
|
],
|
|
"id": "ae935a8a"
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"from quantum_learning import (\n",
|
|
" counts_to_probabilities,\n",
|
|
" editable_circuit_lab,\n",
|
|
" plot_counts,\n",
|
|
" plot_probabilities,\n",
|
|
" quiz_block,\n",
|
|
" reflection_box,\n",
|
|
" simulate_counts,\n",
|
|
" statevector_probabilities,\n",
|
|
" step_reference_table,\n",
|
|
")\n",
|
|
"from qiskit import QuantumCircuit\n",
|
|
"from qiskit.quantum_info import Statevector\n"
|
|
],
|
|
"id": "6b4fdd33"
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"<!-- QL_BADGE -->\n",
|
|
"<div style=\"padding:0.55rem 0.8rem; border-left:6px solid #2563eb; background:#dbeafe; color:#1e3a8a; border-radius:0.35rem; font-family:Helvetica, Arial, sans-serif; margin:0.15rem 0 0.85rem 0;\">\n",
|
|
"<strong>META READING</strong> · Difficulty 1/10 · Notebook-level rule, objective, or usage guidance.\n",
|
|
"</div>\n",
|
|
"\n",
|
|
"## Lab 1: Small Gate Compositions\n",
|
|
"\n",
|
|
"Start with a one-qubit circuit. Move `X`, `H`, and `Z` around and explain why the final counts change or fail to change. The purpose is to stop treating gate names as slogans and start treating them as transformations in sequence.\n"
|
|
],
|
|
"id": "a9cc8dcb"
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"ql_injected": "badge",
|
|
"ql_track": "mandatory",
|
|
"ql_role": "exercise"
|
|
},
|
|
"source": [
|
|
"<!-- QL_BADGE -->\n",
|
|
"<div style=\"padding:0.55rem 0.8rem; border-left:6px solid #15803d; background:#dcfce7; color:#14532d; border-radius:0.35rem; font-family:Helvetica, Arial, sans-serif; margin:0.15rem 0 0.85rem 0;\">\n",
|
|
"<strong>MANDATORY EXERCISE</strong> · Difficulty 2/10 · Official walkthrough runnable or written exercise.\n",
|
|
"</div>\n"
|
|
],
|
|
"id": "0e915c09"
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {
|
|
"jupyter": {
|
|
"source_hidden": true
|
|
},
|
|
"tags": [
|
|
"hide-input"
|
|
]
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"editable_code = '\\ncircuit = QuantumCircuit(1, 1)\\n# [1] Try changing the preparation gate sequence.\\ncircuit.x(0)\\ncircuit.h(0)\\n# [2] Optionally add Z or another H before measurement.\\n# circuit.z(0)\\n# circuit.h(0)\\n# [3] Measure the result.\\ncircuit.measure(0, 0)\\n'\n",
|
|
"editable_circuit_lab(\n",
|
|
" initial_code=editable_code,\n",
|
|
" context={\"QuantumCircuit\": QuantumCircuit, \"simulate_counts\": simulate_counts},\n",
|
|
" title='Lab 1: Small Gate Composition',\n",
|
|
" instructions='Reorder or add one gate at a time and explain whether the change altered preparation, phase, or the measurement question.',\n",
|
|
" shots=256,\n",
|
|
")\n"
|
|
],
|
|
"id": "a500daf8"
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"ql_injected": "badge",
|
|
"ql_track": "mandatory",
|
|
"ql_role": "exercise"
|
|
},
|
|
"source": [
|
|
"<!-- QL_BADGE -->\n",
|
|
"<div style=\"padding:0.55rem 0.8rem; border-left:6px solid #15803d; background:#dcfce7; color:#14532d; border-radius:0.35rem; font-family:Helvetica, Arial, sans-serif; margin:0.15rem 0 0.85rem 0;\">\n",
|
|
"<strong>MANDATORY EXERCISE</strong> · Difficulty 2/10 · Official walkthrough runnable or written exercise.\n",
|
|
"</div>\n"
|
|
],
|
|
"id": "0d53ff18"
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"low_shot = QuantumCircuit(1, 1)\n",
|
|
"low_shot.h(0)\n",
|
|
"low_shot.measure(0, 0)\n",
|
|
"\n",
|
|
"counts_64 = simulate_counts(low_shot, shots=64)\n",
|
|
"counts_4096 = simulate_counts(low_shot, shots=4096)\n",
|
|
"{\n",
|
|
" \"64_shots\": counts_64,\n",
|
|
" \"4096_shots\": counts_4096,\n",
|
|
"}\n"
|
|
],
|
|
"id": "eb9d580c"
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"<!-- QL_BADGE -->\n",
|
|
"<div style=\"padding:0.55rem 0.8rem; border-left:6px solid #2563eb; background:#dbeafe; color:#1e3a8a; border-radius:0.35rem; font-family:Helvetica, Arial, sans-serif; margin:0.15rem 0 0.85rem 0;\">\n",
|
|
"<strong>META READING</strong> · Difficulty 1/10 · Notebook-level rule, objective, or usage guidance.\n",
|
|
"</div>\n",
|
|
"\n",
|
|
"The first lab makes a simple but essential point: the meaning of a gate sequence is not the sum of independent gate slogans. Order matters. Context matters. A `Z` in the middle of a sequence can be invisible in one immediate view and decisive in a later one.\n"
|
|
],
|
|
"id": "d27a47c6"
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"ql_injected": "badge",
|
|
"ql_track": "mandatory",
|
|
"ql_role": "test"
|
|
},
|
|
"source": [
|
|
"<!-- QL_BADGE -->\n",
|
|
"<div style=\"padding:0.55rem 0.8rem; border-left:6px solid #15803d; background:#dcfce7; color:#14532d; border-radius:0.35rem; font-family:Helvetica, Arial, sans-serif; margin:0.15rem 0 0.85rem 0;\">\n",
|
|
"<strong>MANDATORY TEST</strong> · Difficulty 2/10 · Official walkthrough multiple-choice test.\n",
|
|
"</div>\n"
|
|
],
|
|
"id": "6f933c21"
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {
|
|
"jupyter": {
|
|
"source_hidden": true
|
|
},
|
|
"tags": [
|
|
"hide-input"
|
|
]
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"quiz_block([{'prompt': 'What is the best reason to compare counts across different shot budgets?', 'options': ['To separate stable probability claims from normal sampling fluctuation', 'To reduce circuit depth', 'To change the prepared state'], 'correct_index': 0, 'explanation': 'Shot scaling teaches you how much statistical noise to expect from the same circuit.'}, {'prompt': 'What does swapping classical bit targets test?', 'options': ['Whether your explanation tracks the reporting layer instead of only the quantum layer', 'Whether CNOT still works', 'Whether the backend supports measurement'], 'correct_index': 0, 'explanation': 'Good reasoning follows the evidence all the way into the bitstring labels.'}], heading='Measurement Lab Checkpoint A')\n"
|
|
],
|
|
"id": "2a172956"
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"ql_injected": "badge",
|
|
"ql_track": "mandatory",
|
|
"ql_role": "exercise"
|
|
},
|
|
"source": [
|
|
"<!-- QL_BADGE -->\n",
|
|
"<div style=\"padding:0.55rem 0.8rem; border-left:6px solid #15803d; background:#dcfce7; color:#14532d; border-radius:0.35rem; font-family:Helvetica, Arial, sans-serif; margin:0.15rem 0 0.85rem 0;\">\n",
|
|
"<strong>MANDATORY EXERCISE</strong> · Difficulty 2/10 · Official walkthrough runnable or written exercise.\n",
|
|
"</div>\n"
|
|
],
|
|
"id": "fb5b68bb"
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {
|
|
"jupyter": {
|
|
"source_hidden": true
|
|
},
|
|
"tags": [
|
|
"hide-input"
|
|
]
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"reflection_box('Which one-qubit edit best exposed the difference between changing preparation and changing the final question?')\n"
|
|
],
|
|
"id": "bffb8648"
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"<!-- QL_BADGE -->\n",
|
|
"<div style=\"padding:0.55rem 0.8rem; border-left:6px solid #15803d; background:#dcfce7; color:#14532d; border-radius:0.35rem; font-family:Helvetica, Arial, sans-serif; margin:0.15rem 0 0.85rem 0;\">\n",
|
|
"<strong>MANDATORY READING</strong> · Difficulty 2/10 · Official walkthrough reading cell.\n",
|
|
"</div>\n",
|
|
"\n",
|
|
"## Lab 2: Basis Rotation On A Two-Qubit Circuit\n",
|
|
"\n",
|
|
"Return to the Bell-style preparation and vary the final Hadamard placement. Ask the stronger question every time: what did this edit change in the protocol, and what evidence would support that claim?\n"
|
|
],
|
|
"id": "28c96683"
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"ql_injected": "badge",
|
|
"ql_track": "mandatory",
|
|
"ql_role": "exercise"
|
|
},
|
|
"source": [
|
|
"<!-- QL_BADGE -->\n",
|
|
"<div style=\"padding:0.55rem 0.8rem; border-left:6px solid #15803d; background:#dcfce7; color:#14532d; border-radius:0.35rem; font-family:Helvetica, Arial, sans-serif; margin:0.15rem 0 0.85rem 0;\">\n",
|
|
"<strong>MANDATORY EXERCISE</strong> · Difficulty 2/10 · Official walkthrough runnable or written exercise.\n",
|
|
"</div>\n"
|
|
],
|
|
"id": "fe1d9b73"
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {
|
|
"jupyter": {
|
|
"source_hidden": true
|
|
},
|
|
"tags": [
|
|
"hide-input"
|
|
]
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"step_reference_table([{'marker': '[1]', 'code_focus': 'Prepare a Bell-style correlated state with `H` and `CX`.', 'diagram_effect': 'The first two operations create a structured two-wire object rather than two independent qubits.', 'why_it_matters': 'Measurement interpretation depends on what was prepared before the final question is asked.'}, {'marker': '[2]', 'code_focus': 'Rotate one qubit with `H` immediately before measurement.', 'diagram_effect': 'The final question changes on that wire without erasing the rest of the preparation story.', 'why_it_matters': 'Basis changes are part of the experiment design, not cosmetic extras.'}, {'marker': '[3]', 'code_focus': 'Measure into explicitly chosen classical bits.', 'diagram_effect': 'The circuit commits to a specific readout question and a specific reporting layout.', 'why_it_matters': 'Classical wiring is part of the evidence trail and can itself become a source of confusion.'}])\n"
|
|
],
|
|
"id": "055b2fba"
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"ql_injected": "badge",
|
|
"ql_track": "mandatory",
|
|
"ql_role": "exercise"
|
|
},
|
|
"source": [
|
|
"<!-- QL_BADGE -->\n",
|
|
"<div style=\"padding:0.55rem 0.8rem; border-left:6px solid #15803d; background:#dcfce7; color:#14532d; border-radius:0.35rem; font-family:Helvetica, Arial, sans-serif; margin:0.15rem 0 0.85rem 0;\">\n",
|
|
"<strong>MANDATORY EXERCISE</strong> · Difficulty 2/10 · Official walkthrough runnable or written exercise.\n",
|
|
"</div>\n"
|
|
],
|
|
"id": "b8c10e42"
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {
|
|
"jupyter": {
|
|
"source_hidden": true
|
|
},
|
|
"tags": [
|
|
"hide-input"
|
|
]
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"editable_code = '\\ncircuit = QuantumCircuit(2, 2)\\n# [1] Prepare the correlated state.\\ncircuit.h(0)\\ncircuit.cx(0, 1)\\n# [2] Change the basis of the first measurement question.\\ncircuit.h(0)\\n# [3] Measure both qubits into the matching classical bits.\\ncircuit.measure([0, 1], [0, 1])\\n'\n",
|
|
"editable_circuit_lab(\n",
|
|
" initial_code=editable_code,\n",
|
|
" context={\"QuantumCircuit\": QuantumCircuit, \"simulate_counts\": simulate_counts},\n",
|
|
" title='Lab 2: Bell Basis Rotation',\n",
|
|
" instructions='Move or delete the final Hadamard and explain whether your edit changed preparation or only the final measurement question.',\n",
|
|
" shots=256,\n",
|
|
")\n"
|
|
],
|
|
"id": "78b42854"
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"ql_injected": "badge",
|
|
"ql_track": "mandatory",
|
|
"ql_role": "exercise"
|
|
},
|
|
"source": [
|
|
"<!-- QL_BADGE -->\n",
|
|
"<div style=\"padding:0.55rem 0.8rem; border-left:6px solid #15803d; background:#dcfce7; color:#14532d; border-radius:0.35rem; font-family:Helvetica, Arial, sans-serif; margin:0.15rem 0 0.85rem 0;\">\n",
|
|
"<strong>MANDATORY EXERCISE</strong> · Difficulty 2/10 · Official walkthrough runnable or written exercise.\n",
|
|
"</div>\n"
|
|
],
|
|
"id": "2814ef64"
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"bell_z = QuantumCircuit(2, 2)\n",
|
|
"bell_z.h(0)\n",
|
|
"bell_z.cx(0, 1)\n",
|
|
"bell_z.measure([0, 1], [0, 1])\n",
|
|
"\n",
|
|
"bell_x_probe = QuantumCircuit(2, 2)\n",
|
|
"bell_x_probe.h(0)\n",
|
|
"bell_x_probe.cx(0, 1)\n",
|
|
"bell_x_probe.h(0)\n",
|
|
"bell_x_probe.measure([0, 1], [0, 1])\n",
|
|
"\n",
|
|
"{\n",
|
|
" \"z_basis_counts\": simulate_counts(bell_z, shots=512),\n",
|
|
" \"probe_counts\": simulate_counts(bell_x_probe, shots=512),\n",
|
|
"}\n"
|
|
],
|
|
"id": "09726191"
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"<!-- QL_BADGE -->\n",
|
|
"<div style=\"padding:0.55rem 0.8rem; border-left:6px solid #15803d; background:#dcfce7; color:#14532d; border-radius:0.35rem; font-family:Helvetica, Arial, sans-serif; margin:0.15rem 0 0.85rem 0;\">\n",
|
|
"<strong>MANDATORY READING</strong> · Difficulty 2/10 · Official walkthrough reading cell.\n",
|
|
"</div>\n",
|
|
"\n",
|
|
"## Lab 3: Reporting Layer Sanity Check\n",
|
|
"\n",
|
|
"The last lab isolates classical wiring. Swapping the target classical bits should not be explained as a change in quantum preparation. It is a reporting change. That sounds obvious when written plainly, but many learners still misread the resulting bitstrings unless the notebook forces the distinction.\n"
|
|
],
|
|
"id": "4053dc1a"
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"ql_injected": "badge",
|
|
"ql_track": "mandatory",
|
|
"ql_role": "exercise"
|
|
},
|
|
"source": [
|
|
"<!-- QL_BADGE -->\n",
|
|
"<div style=\"padding:0.55rem 0.8rem; border-left:6px solid #15803d; background:#dcfce7; color:#14532d; border-radius:0.35rem; font-family:Helvetica, Arial, sans-serif; margin:0.15rem 0 0.85rem 0;\">\n",
|
|
"<strong>MANDATORY EXERCISE</strong> · Difficulty 2/10 · Official walkthrough runnable or written exercise.\n",
|
|
"</div>\n"
|
|
],
|
|
"id": "0293d25f"
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {
|
|
"jupyter": {
|
|
"source_hidden": true
|
|
},
|
|
"tags": [
|
|
"hide-input"
|
|
]
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"editable_code = '\\ncircuit = QuantumCircuit(2, 2)\\n# [1] Prepare a Bell-style state.\\ncircuit.h(0)\\ncircuit.cx(0, 1)\\n# [2] Try swapping the classical wiring.\\ncircuit.measure([0, 1], [1, 0])\\n'\n",
|
|
"editable_circuit_lab(\n",
|
|
" initial_code=editable_code,\n",
|
|
" context={\"QuantumCircuit\": QuantumCircuit, \"simulate_counts\": simulate_counts},\n",
|
|
" title='Lab 3: Classical Wiring Check',\n",
|
|
" instructions='Switch between direct and swapped classical mappings and explain how the evidence labels change even if the quantum preparation story does not.',\n",
|
|
" shots=256,\n",
|
|
")\n"
|
|
],
|
|
"id": "36cb4fba"
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"<!-- QL_BADGE -->\n",
|
|
"<div style=\"padding:0.55rem 0.8rem; border-left:6px solid #15803d; background:#dcfce7; color:#14532d; border-radius:0.35rem; font-family:Helvetica, Arial, sans-serif; margin:0.15rem 0 0.85rem 0;\">\n",
|
|
"<strong>MANDATORY READING</strong> · Difficulty 2/10 · Official walkthrough reading cell.\n",
|
|
"</div>\n",
|
|
"\n",
|
|
"This exercise is professionally important because many debugging mistakes come from the reporting layer, not from the state preparation layer. A world-class lecture series should train that suspicion early rather than treating it as an advanced nuisance.\n"
|
|
],
|
|
"id": "a39bc676"
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"<!-- QL_BADGE -->\n",
|
|
"<div style=\"padding:0.55rem 0.8rem; border-left:6px solid #15803d; background:#dcfce7; color:#14532d; border-radius:0.35rem; font-family:Helvetica, Arial, sans-serif; margin:0.15rem 0 0.85rem 0;\">\n",
|
|
"<strong>MANDATORY READING</strong> · Difficulty 2/10 · Official walkthrough reading cell.\n",
|
|
"</div>\n",
|
|
"\n",
|
|
"## Lab Debrief\n",
|
|
"\n",
|
|
"These three labs together teach a simple review pattern. First ask whether the preparation changed. If not, ask whether the measurement basis changed. If not, ask whether only the reporting layer changed. That sequence is powerful because it narrows explanation quickly. It also stops you from inventing dramatic quantum stories for what may only be a bookkeeping issue.\n",
|
|
"\n",
|
|
"The debrief is worth reading carefully because many learners still default to a single undifferentiated sentence such as “the circuit output changed.” That sentence contains almost no engineering value. A stronger sentence might be: “The prepared Bell-style state stayed the same, but the added Hadamard changed the first qubit's measurement basis, so the empirical correlation pattern now answers a different question.” That is the level of explanation this lab is trying to normalize.\n"
|
|
],
|
|
"id": "26d37984"
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"ql_injected": "badge",
|
|
"ql_track": "mandatory",
|
|
"ql_role": "test"
|
|
},
|
|
"source": [
|
|
"<!-- QL_BADGE -->\n",
|
|
"<div style=\"padding:0.55rem 0.8rem; border-left:6px solid #15803d; background:#dcfce7; color:#14532d; border-radius:0.35rem; font-family:Helvetica, Arial, sans-serif; margin:0.15rem 0 0.85rem 0;\">\n",
|
|
"<strong>MANDATORY TEST</strong> · Difficulty 2/10 · Official walkthrough multiple-choice test.\n",
|
|
"</div>\n"
|
|
],
|
|
"id": "9b519db1"
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {
|
|
"jupyter": {
|
|
"source_hidden": true
|
|
},
|
|
"tags": [
|
|
"hide-input"
|
|
]
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"quiz_block([{'prompt': 'If a final Hadamard changes the counts drastically, what is the first serious question to ask?', 'options': ['Did I change the measurement basis rather than merely add decoration?', 'Did the notebook theme corrupt the circuit?', 'Did the number of qubits change automatically?'], 'correct_index': 0, 'explanation': 'The basis question is the right first interpretation, not panic.'}, {'prompt': 'Why keep counts and probabilities conceptually separate in the same notebook?', 'options': ['Because one is sampled evidence and the other is an idealized expectation derived from the model', 'Because they should never be compared', 'Because counts are only for advanced users'], 'correct_index': 0, 'explanation': 'Serious measurement reasoning compares the ideal story with sampled evidence carefully.'}], heading='Measurement Lab Checkpoint B')\n"
|
|
],
|
|
"id": "023cf0cd"
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"ql_injected": "badge",
|
|
"ql_track": "mandatory",
|
|
"ql_role": "exercise"
|
|
},
|
|
"source": [
|
|
"<!-- QL_BADGE -->\n",
|
|
"<div style=\"padding:0.55rem 0.8rem; border-left:6px solid #15803d; background:#dcfce7; color:#14532d; border-radius:0.35rem; font-family:Helvetica, Arial, sans-serif; margin:0.15rem 0 0.85rem 0;\">\n",
|
|
"<strong>MANDATORY EXERCISE</strong> · Difficulty 2/10 · Official walkthrough runnable or written exercise.\n",
|
|
"</div>\n"
|
|
],
|
|
"id": "67335971"
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {
|
|
"jupyter": {
|
|
"source_hidden": true
|
|
},
|
|
"tags": [
|
|
"hide-input"
|
|
]
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"reflection_box('Write a short explanation of how you would distinguish a basis mistake from a classical-wiring mistake in a notebook review.')\n"
|
|
],
|
|
"id": "ad411438"
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"ql_injected": "badge",
|
|
"ql_track": "mandatory",
|
|
"ql_role": "exercise"
|
|
},
|
|
"source": [
|
|
"<!-- QL_BADGE -->\n",
|
|
"<div style=\"padding:0.55rem 0.8rem; border-left:6px solid #15803d; background:#dcfce7; color:#14532d; border-radius:0.35rem; font-family:Helvetica, Arial, sans-serif; margin:0.15rem 0 0.85rem 0;\">\n",
|
|
"<strong>MANDATORY EXERCISE</strong> · Difficulty 2/10 · Official walkthrough runnable or written exercise.\n",
|
|
"</div>\n"
|
|
],
|
|
"id": "2d1d11fd"
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {
|
|
"jupyter": {
|
|
"source_hidden": true
|
|
},
|
|
"tags": [
|
|
"hide-input"
|
|
]
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"reflection_box('What does shot noise change in your interpretation, and what does it not change?')\n"
|
|
],
|
|
"id": "38ae3dd6"
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"<!-- QL_BADGE -->\n",
|
|
"<div style=\"padding:0.55rem 0.8rem; border-left:6px solid #2563eb; background:#dbeafe; color:#1e3a8a; border-radius:0.35rem; font-family:Helvetica, Arial, sans-serif; margin:0.15rem 0 0.85rem 0;\">\n",
|
|
"<strong>META READING</strong> · Difficulty 1/10 · Official walkthrough guardrail.\n",
|
|
"</div>\n",
|
|
"\n",
|
|
"<!-- COURSE_NAV_BOTTOM -->\n",
|
|
"## What To Open Next\n",
|
|
"\n",
|
|
"Next notebook: [Gates and Measurement Problems](problems.ipynb)\n",
|
|
"\n",
|
|
"Official walkthrough rule: once every mandatory cell above is complete, open the next notebook. Anything below this cell is facultative.\n"
|
|
],
|
|
"id": "416446a5"
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"ql_injected": "facultative_zone",
|
|
"ql_track": "meta",
|
|
"ql_role": "reading",
|
|
"ql_difficulty": 1,
|
|
"ql_note": "Optional-zone boundary. The official walkthrough is already complete above."
|
|
},
|
|
"source": [
|
|
"<!-- QL_BADGE -->\n",
|
|
"<div style=\"padding:0.55rem 0.8rem; border-left:6px solid #2563eb; background:#dbeafe; color:#1e3a8a; border-radius:0.35rem; font-family:Helvetica, Arial, sans-serif; margin:0.15rem 0 0.85rem 0;\">\n",
|
|
"<strong>META READING</strong> · Difficulty 1/10 · Optional-zone boundary. The official walkthrough is already complete above.\n",
|
|
"</div>\n",
|
|
"\n",
|
|
"<!-- QL_OPTIONAL_ZONE -->\n",
|
|
"## Facultative Extension Zone\n",
|
|
"\n",
|
|
"You have already completed the mandatory walkthrough for **Gates and Measurement Lab**. Everything below is optional. Use it only if you want deeper consolidation or extra transfer work.\n"
|
|
],
|
|
"id": "f4216c48"
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"ql_injected": "facultative",
|
|
"ql_track": "facultative",
|
|
"ql_role": "reading",
|
|
"ql_difficulty": 4,
|
|
"ql_note": "Optional extension reading."
|
|
},
|
|
"source": [
|
|
"<!-- QL_BADGE -->\n",
|
|
"<div style=\"padding:0.55rem 0.8rem; border-left:6px solid #ea580c; background:#ffedd5; color:#9a3412; border-radius:0.35rem; font-family:Helvetica, Arial, sans-serif; margin:0.15rem 0 0.85rem 0;\">\n",
|
|
"<strong>FACULTATIVE READING</strong> · Difficulty 4/10 · Optional extension reading.\n",
|
|
"</div>\n",
|
|
"\n",
|
|
"## Facultative Extension Reading\n",
|
|
"\n",
|
|
"In **Gates and Measurement Lab**, the mandatory labs already gave you the official practice loop. This optional cell is for deeper experimentation discipline: decide one variable you would perturb next, one quantity you would track, and one false conclusion you want to avoid.\n"
|
|
],
|
|
"id": "5207fcd0"
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"ql_injected": "badge",
|
|
"ql_track": "facultative",
|
|
"ql_role": "test"
|
|
},
|
|
"source": [
|
|
"<!-- QL_BADGE -->\n",
|
|
"<div style=\"padding:0.55rem 0.8rem; border-left:6px solid #ea580c; background:#ffedd5; color:#9a3412; border-radius:0.35rem; font-family:Helvetica, Arial, sans-serif; margin:0.15rem 0 0.85rem 0;\">\n",
|
|
"<strong>FACULTATIVE TEST</strong> · Difficulty 5/10 · Optional multiple-choice extension.\n",
|
|
"</div>\n"
|
|
],
|
|
"id": "cae43829"
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {
|
|
"ql_injected": "facultative",
|
|
"ql_track": "facultative",
|
|
"ql_role": "test",
|
|
"ql_difficulty": 5,
|
|
"ql_note": "Optional multiple-choice extension.",
|
|
"jupyter": {
|
|
"source_hidden": true
|
|
},
|
|
"tags": [
|
|
"hide-input"
|
|
]
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"quiz_block([{'prompt': 'In an optional lab variant, what should you change first?', 'options': ['One design variable you can explain', 'As many gates as possible to make the result surprising', 'The notebook order itself'], 'correct_index': 0, 'explanation': 'Optional exploration is still strongest when the perturbation is controlled.'}, {'prompt': 'What makes an optional lab note useful?', 'options': ['It records what changed, what stayed fixed, and what evidence moved', 'It only reports that the circuit still ran', 'It avoids writing predictions to save time'], 'correct_index': 0, 'explanation': 'The extension is about deeper evidence discipline.'}], heading='Facultative Extension Test')\n"
|
|
],
|
|
"id": "6c709e2a"
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"ql_injected": "badge",
|
|
"ql_track": "facultative",
|
|
"ql_role": "exercise"
|
|
},
|
|
"source": [
|
|
"<!-- QL_BADGE -->\n",
|
|
"<div style=\"padding:0.55rem 0.8rem; border-left:6px solid #ea580c; background:#ffedd5; color:#9a3412; border-radius:0.35rem; font-family:Helvetica, Arial, sans-serif; margin:0.15rem 0 0.85rem 0;\">\n",
|
|
"<strong>FACULTATIVE EXERCISE</strong> · Difficulty 6/10 · Optional written exercise.\n",
|
|
"</div>\n"
|
|
],
|
|
"id": "d1d8b3cd"
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {
|
|
"ql_injected": "facultative",
|
|
"ql_track": "facultative",
|
|
"ql_role": "exercise",
|
|
"ql_difficulty": 6,
|
|
"ql_note": "Optional written exercise.",
|
|
"jupyter": {
|
|
"source_hidden": true
|
|
},
|
|
"tags": [
|
|
"hide-input"
|
|
]
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"reflection_box('Describe one optional circuit variation you would run after Gates and Measurement Lab, what you would predict before running it, and what evidence would make you abandon the prediction.')\n"
|
|
],
|
|
"id": "1f53c24c"
|
|
}
|
|
],
|
|
"metadata": {
|
|
"kernelspec": {
|
|
"display_name": "QuantumLearning (.venv)",
|
|
"language": "python",
|
|
"name": "quantum-learning"
|
|
},
|
|
"language_info": {
|
|
"name": "python",
|
|
"version": "3.12"
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 5
|
|
}
|