open-standards/wai/wai-quantum/course/lessons/phase-estimation/exercise.json
Transaction Science fb230d8a62 wai-quantum: the circuits course as data, each exercise checked by the engine, and wai-quantum learn in English and Chinese
engine::course reads the course from wai-quantum/course/: 21 lessons from a
first circuit through superposition, entanglement, interference, the standard
algorithms, noise and mitigation, error correction and fault tolerance to
resource estimates, each a Markdown text in English and Simplified Chinese and
an exercise.json with a schema. A check runs each case of an exercise (a
generator's inputs) with its intent and the verdict, measures its constraints
(the gates allowed, counts, the T count, the critique's smells, the resource
estimate's counts), and says what went wrong from the diagnostics, the verdict
and the critique, never from the solution. The tests hold every solution to
pass by proof, every known wrong answer to fail for its stated reason, and
every locale to every text and message.

wai-quantum learn shows, starts, checks, hints and explains a lesson, keeps
progress only on this machine, and speaks the language --lang or LANG names;
the command summaries and docs topics have Chinese translations held to the
English they came from. The verdict gains of_diagnostic for a generator's
refusal. llms.txt names the course.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-28 08:42:54 -04:00

72 lines
3.1 KiB
JSON
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

{
"schema": "wai.quantum.exercise/1",
"id": "phase-estimation",
"translations": { "zh-CN": "machine-assisted: to be reviewed by a fluent reader before it is advertised" },
"title": { "en": "Phase estimation", "zh-CN": "相位估计" },
"task": {
"en": "The T gate multiplies |1⟩ by e^{2πi/8}: its phase is 1/8. Three counting qubits have picked up that phase, written as Σₓ e^{2πi·x/8}|x⟩, with q[2] the highest bit. Finish with the inverse quantum Fourier transform so that the counting register reads 001, that is 8 × 1/8, every time.",
"zh-CN": "T 门把 |1⟩ 乘以 e^{2πi/8}:它的相位是 1/8。三个计数量子比特已经获得了这个相位,写作 Σₓ e^{2πi·x/8}|x⟩,其中 q[2] 是最高位。最后加上逆量子傅里叶变换,使计数寄存器每次都读出 001,即 8 × 1/8。"
},
"starter": [
"OPENQASM 3.0;",
"include \"stdgates.inc\";",
"qubit[4] q;",
"bit[3] c;",
"// the eigenstate |1⟩ of the T gate, on q[3]",
"x q[3];",
"// the counting register",
"h q[0];",
"h q[1];",
"h q[2];",
"// controlled T to the powers 1, 2 and 4",
"cp(pi/4) q[0], q[3];",
"cp(pi/2) q[1], q[3];",
"cp(pi) q[2], q[3];",
"// the inverse quantum Fourier transform: your gates here",
"c[0] = measure q[0];",
"c[1] = measure q[1];",
"c[2] = measure q[2];"
],
"intent": { "distribution": { "001": 1.0 } },
"constraints": { "allow": ["h", "x", "cp", "swap"], "counts": { "x": { "max": 1 }, "cp": { "min": 6, "max": 6 }, "h": { "min": 6, "max": 6 } } },
"hints": {
"en": [
"The previous lesson's inverse transform is close, but it was written for q[0] as the highest bit. Here q[2] is.",
"Undo the order first: a swap of the outer qubits, then a Hadamard on each qubit from q[0] up, each preceded by cp(−π/2ᵏ) from the qubits already done."
],
"zh-CN": [
"上一课的逆变换已经很接近了,但它是以 q[0] 为最高位写的。这里最高位是 q[2]。",
"先把顺序倒回来:交换最外侧的两个量子比特;然后从 q[0] 开始依次对每个量子比特作用 Hadamard 门,在每个 Hadamard 之前,从已经处理过的量子比特作用 cp(−π/2ᵏ)。"
]
},
"reference": [
"OPENQASM 3.0;",
"include \"stdgates.inc\";",
"qubit[4] q;",
"bit[3] c;",
"x q[3];",
"h q[0];",
"h q[1];",
"h q[2];",
"cp(pi/4) q[0], q[3];",
"cp(pi/2) q[1], q[3];",
"cp(pi) q[2], q[3];",
"swap q[0], q[2];",
"h q[0];",
"cp(-pi/2) q[1], q[0];",
"h q[1];",
"cp(-pi/4) q[2], q[0];",
"cp(-pi/2) q[2], q[1];",
"h q[2];",
"c[0] = measure q[0];",
"c[1] = measure q[1];",
"c[2] = measure q[2];"
],
"wrong": [
{
"fails": "intent",
"note": "Hadamards alone do not read a phase of 1/8",
"qasm": ["OPENQASM 3.0;", "include \"stdgates.inc\";", "qubit[4] q;", "bit[3] c;", "x q[3];", "h q[0];", "h q[1];", "h q[2];", "cp(pi/4) q[0], q[3];", "cp(pi/2) q[1], q[3];", "cp(pi) q[2], q[3];", "h q[0];", "h q[1];", "h q[2];", "c[0] = measure q[0];", "c[1] = measure q[1];", "c[2] = measure q[2];"]
}
]
}