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]>
63 lines
2.9 KiB
JSON
63 lines
2.9 KiB
JSON
{
|
||
"schema": "wai.quantum.exercise/1",
|
||
"id": "toffoli",
|
||
"translations": { "zh-CN": "machine-assisted: to be reviewed by a fluent reader before it is advertised" },
|
||
"title": { "en": "A Toffoli from Clifford+T", "zh-CN": "用 Clifford+T 搭建 Toffoli 门" },
|
||
"task": {
|
||
"en": "Write the Toffoli gate, ccx q[0], q[1], q[2], using only h, t, tdg and cx. The check proves your program the same circuit as the Toffoli, up to a global phase.",
|
||
"zh-CN": "只用 h、t、tdg 和 cx 写出 Toffoli 门 ccx q[0], q[1], q[2]。检查会证明你的程序与 Toffoli 门在相差一个全局相位的意义下是同一条线路。"
|
||
},
|
||
"starter": [
|
||
"OPENQASM 3.0;",
|
||
"include \"stdgates.inc\";",
|
||
"qubit[3] q;",
|
||
"// the Toffoli, which this exercise does not allow as one gate",
|
||
"ccx q[0], q[1], q[2];"
|
||
],
|
||
"intent": { "equivalent": "OPENQASM 3.0;\ninclude \"stdgates.inc\";\nqubit[3] q;\nccx q[0], q[1], q[2];\n" },
|
||
"constraints": { "allow": ["h", "t", "tdg", "cx"], "t_count": { "max": 7 } },
|
||
"hints": {
|
||
"en": [
|
||
"A Toffoli is a controlled-controlled-Z with a Hadamard on each side of the target.",
|
||
"The controlled-controlled-Z multiplies |111⟩ by −1. Written as phases, that is a product of e^{±iπ/4} factors on the parities x₀, x₁, x₂, x₀⊕x₁, x₀⊕x₂, x₁⊕x₂ and x₀⊕x₁⊕x₂: seven T or T† gates.",
|
||
"Each parity can be brought onto one qubit with controlled-NOTs, a T or T† applied there, and the controlled-NOTs undone."
|
||
],
|
||
"zh-CN": [
|
||
"Toffoli 门就是在目标比特两侧各加一个 Hadamard 门的受控受控 Z 门。",
|
||
"受控受控 Z 门把 |111⟩ 乘以 −1。写成相位的形式,它是作用在奇偶性 x₀、x₁、x₂、x₀⊕x₁、x₀⊕x₂、x₁⊕x₂ 和 x₀⊕x₁⊕x₂ 上的 e^{±iπ/4} 因子之积:七个 T 或 T† 门。",
|
||
"每种奇偶性都可以用受控非门汇集到一个量子比特上,在那里作用一个 T 或 T†,再把这些受控非门撤销。"
|
||
]
|
||
},
|
||
"reference": [
|
||
"OPENQASM 3.0;",
|
||
"include \"stdgates.inc\";",
|
||
"qubit[3] q;",
|
||
"h q[2];",
|
||
"cx q[1], q[2];",
|
||
"tdg q[2];",
|
||
"cx q[0], q[2];",
|
||
"t q[2];",
|
||
"cx q[1], q[2];",
|
||
"tdg q[2];",
|
||
"cx q[0], q[2];",
|
||
"t q[1];",
|
||
"t q[2];",
|
||
"h q[2];",
|
||
"cx q[0], q[1];",
|
||
"t q[0];",
|
||
"tdg q[1];",
|
||
"cx q[0], q[1];"
|
||
],
|
||
"wrong": [
|
||
{
|
||
"fails": "intent",
|
||
"note": "one T where a T† belongs leaves a relative phase",
|
||
"qasm": ["OPENQASM 3.0;", "include \"stdgates.inc\";", "qubit[3] q;", "h q[2];", "cx q[1], q[2];", "tdg q[2];", "cx q[0], q[2];", "t q[2];", "cx q[1], q[2];", "tdg q[2];", "cx q[0], q[2];", "t q[1];", "t q[2];", "h q[2];", "cx q[0], q[1];", "tdg q[0];", "tdg q[1];", "cx q[0], q[1];"]
|
||
},
|
||
{
|
||
"fails": "constraint",
|
||
"note": "the Toffoli as one gate",
|
||
"qasm": ["OPENQASM 3.0;", "include \"stdgates.inc\";", "qubit[3] q;", "ccx q[0], q[1], q[2];"]
|
||
}
|
||
]
|
||
}
|