mirror of
https://github.com/saymrwulf/QuantumLearning.git
synced 2026-07-29 20:14:13 +00:00
242 lines
11 KiB
Text
242 lines
11 KiB
Text
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"# Deutsch Family and Oracle Thinking Problems\n"
|
|
],
|
|
"id": "cbab3f1d"
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"These problems check whether you can keep the semantic burden of the Deutsch family in view when the wording changes. Treat each block like a miniature design review instead of a trivia quiz.\n"
|
|
],
|
|
"id": "d8fb5fa9"
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"## How To Use This Notebook\n",
|
|
"\n",
|
|
"\n",
|
|
" Move slowly enough that you can say why the wrong answers remain tempting. If a wrong answer sounds attractive because it is shorter or more mysterious, that is exactly the weakness this notebook is trying to flush out.\n"
|
|
],
|
|
"id": "4e7cd2dc"
|
|
},
|
|
{
|
|
"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": "3e7046de"
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"from math import pi\n",
|
|
"\n",
|
|
"from quantum_learning import (\n",
|
|
" counts_to_probabilities,\n",
|
|
" draw_circuit,\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": "319d85e5"
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"## Oracle Contract Check\n",
|
|
"\n",
|
|
"Treat this block as a miniature review situation. Choose the answer that would best survive an engineering conversation.\n"
|
|
],
|
|
"id": "b8de7c5e"
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"quiz_block([{'prompt': 'Which statement best describes a Deutsch oracle in this module?', 'options': ['A reversible circuit implementing one member of a promised function family', 'Any two-qubit circuit with one CNOT', 'A measurement gadget that reveals the answer directly'], 'correct_index': 0, 'explanation': 'The oracle is defined by the function family and promise, not by a single gate mnemonic.'}, {'prompt': 'Why is copying a balanced-oracle diagram into a constant case a design error?', 'options': ['Because constants require more qubits', 'Because the circuit would no longer match the promise class being claimed', 'Because Qiskit forbids constant functions'], 'correct_index': 1, 'explanation': 'The semantic burden of the oracle changes with the promise class.'}], heading='Oracle Contract Check')\n"
|
|
],
|
|
"id": "5743cfd7"
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"## Interference Reasoning\n",
|
|
"\n",
|
|
"Treat this block as a miniature review situation. Choose the answer that would best survive an engineering conversation.\n"
|
|
],
|
|
"id": "a98b823f"
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"quiz_block([{'prompt': 'What information is actually being combined by the final Hadamard in Deutsch?', 'options': ['The branch phases created by the oracle interaction', 'The counts collected during execution', 'The classical truth table of the function'], 'correct_index': 0, 'explanation': 'The last Hadamard converts branch-relative phase into basis amplitude.'}, {'prompt': \"Which explanation is strongest when a learner says 'the circuit just magically knows'?\", 'options': ['It does not know; the oracle encodes structure and interference exposes it', 'Quantum circuits know because amplitudes are hidden variables', 'The simulator precomputes the answer and returns it'], 'correct_index': 0, 'explanation': 'Mechanistic language matters if you want professional control rather than awe.'}], heading='Interference Reasoning')\n"
|
|
],
|
|
"id": "259f8681"
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"## Scaling To Deutsch-Jozsa\n",
|
|
"\n",
|
|
"Treat this block as a miniature review situation. Choose the answer that would best survive an engineering conversation.\n"
|
|
],
|
|
"id": "49cc46a0"
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"quiz_block([{'prompt': 'What survives when the circuit scales from Deutsch to Deutsch-Jozsa?', 'options': ['The oracle-contract idea, phase kickback, and final interference logic', 'Only the exact same two-qubit diagram', 'The need to measure the ancilla'], 'correct_index': 0, 'explanation': 'The pattern survives even though the specific wiring changes.'}, {'prompt': 'What is the strongest reason to inspect all-zero versus non-zero outcomes in Deutsch-Jozsa?', 'options': ['Those patterns are easier to draw', 'They encode the constant-versus-balanced promise distinction after interference', 'They avoid using classical registers'], 'correct_index': 1, 'explanation': 'The readout pattern is a claim about the promise class, not just a visual convenience.'}], heading='Scaling To Deutsch-Jozsa')\n"
|
|
],
|
|
"id": "0b17296c"
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"## Review Language\n",
|
|
"\n",
|
|
"Treat this block as a miniature review situation. Choose the answer that would best survive an engineering conversation.\n"
|
|
],
|
|
"id": "ddd0add1"
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"quiz_block([{'prompt': 'Which review comment is strongest?', 'options': ['This looks quantum enough', 'The oracle contract is unclear, so I cannot tell whether the circuit still distinguishes the promised cases', 'Please shorten the code by removing comments'], 'correct_index': 1, 'explanation': 'Professional review language targets the semantic burden of the circuit.'}, {'prompt': 'What evidence should support a claim that a Deutsch circuit is correct?', 'options': ['A clear oracle definition, a narrated interference mechanism, and counts that match the promise cases', 'Only a rendered diagram', 'Only a transpiler summary'], 'correct_index': 0, 'explanation': 'Correctness here is conceptual, structural, and empirical.'}], heading='Review Language')\n"
|
|
],
|
|
"id": "e70322b4"
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"## Mini Case\n",
|
|
"\n",
|
|
"\n",
|
|
" One of the easiest failures in early algorithm notebooks is a kind of respectable-looking vagueness. The code runs. The diagram resembles the textbook. The counts look stable. But the writer has stopped being able to say what family of functions the oracle represents, which wire carries the verdict, or which step actually turns phase into evidence. This module refuses to accept that kind of vagueness as understanding. The point of the problems notebook is to force more exact language until the explanation becomes robust enough to survive later complexity.\n"
|
|
],
|
|
"id": "a6f8b501"
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"## What These Questions Are Really Testing\n",
|
|
"\n",
|
|
"The multiple-choice format is only the surface. Underneath it, the notebook is testing whether your explanation can survive small shifts in phrasing, emphasis, and review context. If your understanding is robust, the wording can change and the same mechanism will still come into focus. If your understanding is fragile, the wording change will tempt you back into vague or prestige-based answers. That is why these problems matter.\n"
|
|
],
|
|
"id": "fde1f2a6"
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"## Common Failure Mode\n",
|
|
"\n",
|
|
"A common failure mode at this stage is to answer with something broadly true but locally weak. For example, saying that a circuit uses superposition or interference may be accurate, yet still fail to identify what role a specific block is playing in the present design. The goal of the problems notebook is to eliminate that kind of vague correctness and replace it with circuit-specific explanation.\n"
|
|
],
|
|
"id": "596b5389"
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"## Written Checks\n",
|
|
"\n",
|
|
"Use the prompts below to rehearse full-sentence engineering explanations.\n"
|
|
],
|
|
"id": "90a59084"
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"reflection_box(\"Explain why the phrase 'the circuit just knows' is pedagogically dangerous in this module.\")\n"
|
|
],
|
|
"id": "72f4c10a"
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"reflection_box('Write a short design memo defending why only the decision wire should be measured in a minimal Deutsch implementation.')\n"
|
|
],
|
|
"id": "53688d3c"
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"## Exit Condition\n",
|
|
"\n",
|
|
"\n",
|
|
" Move on when you can describe the Deutsch family as a reusable oracle-and-interference pattern rather than as two isolated diagrams.\n"
|
|
],
|
|
"id": "c9589579"
|
|
}
|
|
],
|
|
"metadata": {
|
|
"kernelspec": {
|
|
"display_name": "QuantumLearning (.venv)",
|
|
"language": "python",
|
|
"name": "quantum-learning"
|
|
},
|
|
"language_info": {
|
|
"name": "python",
|
|
"version": "3.12"
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 5
|
|
}
|