mirror of
https://github.com/saymrwulf/QuantumLearning.git
synced 2026-09-04 20:23:49 +00:00
212 lines
11 KiB
Text
212 lines
11 KiB
Text
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"# Gates and Measurement Problems\n",
|
|
"\n",
|
|
"This notebook checks whether the protocol distinctions remain stable away from the worked examples. The questions are simple on purpose. If the simple distinctions fail, larger circuits will only hide the failure behind more syntax.\n"
|
|
],
|
|
"id": "3bc80f10"
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"## Problem-Solving Standard\n",
|
|
"\n",
|
|
"Do not ask only whether an option is correct. Ask why the other options are tempting and why they fail. That is how you identify the beginner story you are outgrowing.\n"
|
|
],
|
|
"id": "9063010c"
|
|
},
|
|
{
|
|
"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": "a84bcf22"
|
|
},
|
|
{
|
|
"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": "96b9c26f"
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"## Measurement Problem Set A\n",
|
|
"\n",
|
|
"Treat each quiz as a short diagnostic review. The point is not speed. The point is clarity about which layer of the experiment you are describing.\n"
|
|
],
|
|
"id": "ad255e61"
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"quiz_block([{'prompt': 'What is a gate in the strongest sense used by this module?', 'options': ['A transformation whose role depends on the circuit context and the question being asked', 'A decorative icon', 'Only a line of code with no conceptual content'], 'correct_index': 0, 'explanation': 'This course treats gates as moves inside a structured argument.'}, {'prompt': 'Why is the sequence of gates important?', 'options': ['Because later operations act on the state produced by earlier ones', 'Because Qiskit sorts them alphabetically', 'Because measurement always happens first'], 'correct_index': 0, 'explanation': 'Circuit meaning is time ordered.'}, {'prompt': 'What is the best beginner definition of a measurement protocol?', 'options': ['The combined choice of basis, wiring, and shot-based evidence gathering', 'Only the final `measure` syntax', 'The color of the histogram bars'], 'correct_index': 0, 'explanation': 'Measurement is a designed protocol, not a final afterthought.'}], heading='Measurement Problem Set A')\n"
|
|
],
|
|
"id": "59569808"
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"## Measurement Problem Set B\n",
|
|
"\n",
|
|
"Treat each quiz as a short diagnostic review. The point is not speed. The point is clarity about which layer of the experiment you are describing.\n"
|
|
],
|
|
"id": "299f1e2f"
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"quiz_block([{'prompt': 'Why can the same prepared state yield different-looking results under different basis choices?', 'options': ['Because the measurement question changed', 'Because the qubits became classical earlier', 'Because the simulator chooses random bases on its own'], 'correct_index': 0, 'explanation': 'Basis changes alter the question, so the evidence can change legitimately.'}, {'prompt': 'What should a careful engineer write down alongside a histogram?', 'options': ['What state was prepared, what basis was measured, and how qubits were mapped to classical bits', 'Only the backend name', 'Only whether the plot looked correct'], 'correct_index': 0, 'explanation': 'Evidence without protocol is easy to misread.'}, {'prompt': 'Why are `X`, `Z`, and `H` enough for many early measurement lessons?', 'options': ['They already expose preparation changes, phase changes, and basis changes cleanly', 'Because no other gates exist', 'Because two-qubit gates are illegal in beginner modules'], 'correct_index': 0, 'explanation': 'A small gate vocabulary can already teach the important distinctions.'}], heading='Measurement Problem Set B')\n"
|
|
],
|
|
"id": "12f9d7ea"
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"## Measurement Problem Set C\n",
|
|
"\n",
|
|
"Treat each quiz as a short diagnostic review. The point is not speed. The point is clarity about which layer of the experiment you are describing.\n"
|
|
],
|
|
"id": "c5604c51"
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"quiz_block([{'prompt': 'What does a mismatch between ideal probabilities and low-shot counts usually mean first?', 'options': ['Sampling variation or a changed measurement protocol should be examined before inventing deeper explanations', 'The statevector is false', 'The qubit count changed'], 'correct_index': 0, 'explanation': 'Start with the ordinary explanations and inspect the protocol carefully.'}, {'prompt': 'Why does swapped classical wiring deserve a dedicated exercise?', 'options': ['Because reporting mistakes can mimic conceptual mistakes if the mapping is not tracked', 'Because it changes the quantum amplitudes', 'Because it improves the histogram automatically'], 'correct_index': 0, 'explanation': 'Evidence pipelines can fail at the reporting stage too.'}, {'prompt': 'What professional habit is being built by basis-comparison exercises?', 'options': ['Separating preparation claims from question claims', 'Memorizing more gate names', 'Avoiding reflection writing'], 'correct_index': 0, 'explanation': 'A professional explanation states what changed and what stayed fixed.'}], heading='Measurement Problem Set C')\n"
|
|
],
|
|
"id": "0816e258"
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"## Measurement Problem Set D\n",
|
|
"\n",
|
|
"Treat each quiz as a short diagnostic review. The point is not speed. The point is clarity about which layer of the experiment you are describing.\n"
|
|
],
|
|
"id": "5d73e150"
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"quiz_block([{'prompt': 'What should you do after a missed quiz question in this course?', 'options': ['Identify the exact distinction that failed and reinforce it in your written explanation', 'Ignore the mistake if the code ran', 'Skip the rest of the notebook'], 'correct_index': 0, 'explanation': 'Missed retrieval is a diagnostic event, not just a score event.'}, {'prompt': 'Which sentence most clearly marks measurement maturity?', 'options': ['I can describe what question this circuit asks and why the returned bitstrings count as evidence for that question', 'I can recognize the measurement symbol', 'I know that more shots are always better no matter the question'], 'correct_index': 0, 'explanation': 'The course is training explanation quality, not icon recognition.'}, {'prompt': 'What is the danger of trusting a plausible-looking Bell histogram without further thought?', 'options': ['You may miss basis mistakes, wiring mistakes, or a false story about what was actually measured', 'There is no danger once the bars look right', 'It guarantees a hardware failure later'], 'correct_index': 0, 'explanation': 'Good-looking evidence can still be incorrectly interpreted.'}], heading='Measurement Problem Set D')\n"
|
|
],
|
|
"id": "21a08e50"
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"## Mini Case: A Plausible Histogram Can Still Be Misread\n",
|
|
"\n",
|
|
"One of the central habits in this module is distrust of superficial plausibility. A Bell-like histogram can look comforting even when the explanation attached to it is wrong. Perhaps the basis changed and nobody said so. Perhaps the classical wiring was reversed. Perhaps the shot count was low enough that the learner over-interpreted noise as structure. These are exactly the kinds of mistakes the problem sets are training you to catch.\n",
|
|
"\n",
|
|
"Keep that in mind while writing the reflections below. The real achievement is not getting every quiz right. The real achievement is being able to explain how an apparently reasonable interpretation could still fail and what extra protocol information would settle the matter.\n"
|
|
],
|
|
"id": "41afd942"
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"## Written Checks\n",
|
|
"\n",
|
|
"Use the prompts below to produce complete measurement-language sentences. If you cannot explain basis, reporting, and evidence without looking back at the lecture, you are not ready to rely on the distinction later under noise or transpilation pressure.\n"
|
|
],
|
|
"id": "0b11d3c0"
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"reflection_box('Explain the difference between changing a prepared state and changing the question asked of that state.')\n"
|
|
],
|
|
"id": "43522114"
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"reflection_box('Write a short review note describing one way a correct circuit could still be misread because of classical register wiring.')\n"
|
|
],
|
|
"id": "6d82b569"
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"## Exit Condition\n",
|
|
"\n",
|
|
"Move on only when you can tell the story of a histogram without collapsing preparation, basis choice, and classical reporting into one vague sentence.\n"
|
|
],
|
|
"id": "99c17e9a"
|
|
}
|
|
],
|
|
"metadata": {
|
|
"kernelspec": {
|
|
"display_name": "QuantumLearning (.venv)",
|
|
"language": "python",
|
|
"name": "quantum-learning"
|
|
},
|
|
"language_info": {
|
|
"name": "python",
|
|
"version": "3.12"
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 5
|
|
}
|