-
-
Notifications
You must be signed in to change notification settings - Fork 28
Implement Shor's 9 Qubit Code #803
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Implement Shor's 9 Qubit Code #803
Conversation
6a4e96c to
81b22da
Compare
…ious sizes of Shor's 9 Qubit Code circuits
…est_quantumcircuit_levels
81b22da to
f8b3db8
Compare
📝 WalkthroughSummary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings. WalkthroughAdds a new Shor's 9 Qubit Code benchmark and tests, introduces a CustomSolovayKitaev transpiler pass, and wires the pass into benchmark native-gate synthesis for Clifford+T targets. Changelog updated with the new benchmark entry and PR link. Changes
Sequence Diagram(s)sequenceDiagram
actor User
participant BenchmarkGen as BenchmarkGeneration
participant PassMgr as PassManager
participant CSVK as CustomSolovayKitaev
participant Transpiler as Transpiler/DAG
User->>BenchmarkGen: request native-gate synthesis (clifford+t)
BenchmarkGen->>PassMgr: create PassManager with CustomSolovayKitaev
PassMgr->>CSVK: run pass on DAG
CSVK->>Transpiler: inspect op nodes, call internal SK to synthesize approximations
CSVK->>Transpiler: replace op nodes with approximation DAGs
PassMgr->>BenchmarkGen: return transformed DAG/circuit
BenchmarkGen->>User: return native-gate circuit
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 6
🤖 Fix all issues with AI agents
In `@src/mqt/bench/benchmarks/shors_nine_qubit_code.py`:
- Around line 260-263: Fix the typo in the encoding docstring by replacing the
incorrect ket string "|--->⟩" with the correct "|---⟩" in the Encoding section;
locate the docstring that describes "Phase-flip encoding" (the text containing
"|0⟩ → |+++⟩ and |1⟩ → |--->⟩") and edit that string to remove the extra ">" so
it reads "|0⟩ → |+++⟩ and |1⟩ → |---⟩".
- Around line 84-110: The phase-flip syndrome circuit in
_get_nine_qubit_shors_code_phase_flip_syndrome_extraction_circuit uses
ancilla-controlled CNOTs but lacks an explicit note of which X‑parity
stabilizers are being measured; update the function docstring or add a brief
inline comment near the uses of phase_flip_syndrome and logical_qubit to state
that the circuit measures X⊗X⊗X parity on each 3‑qubit block (qubits 0–2, 3–5,
6–8) using ancillas phase_flip_syndrome[0] and phase_flip_syndrome[1], and
clarify the ancilla measurement mapping (01 → block 1, 10 → block 2, 11 → block
3, 00 → no error) so the CX patterns are immediately understandable.
- Around line 113-144: Update the docstring of
_apply_nine_qubit_shors_code_bit_flip_correction to explicitly state the assumed
Qiskit little-endian bit order (ClassicalRegister index 0 = least-significant
bit) and explain how the integer syndrome patterns (e.g., 0b000001, 0b000010,
etc.) map to the three-bit syndrome values for each 3-qubit block so future
maintainers understand the mapping and conditional X corrections.
In `@src/mqt/bench/custom_solovay_kitaev.py`:
- Around line 62-63: Fix the awkward comment in
src/mqt/bench/custom_solovay_kitaev.py by rephrasing the sentence that currently
reads "as we know it comes from a Qiskit gate, as this we know it will generate"
to a single clear clause; for example, change the comment inside the
input-matrix check block to: "we do not check the input matrix because it comes
from a Qiskit gate and therefore will be a valid SU(2) matrix" so it reads
grammatically correct and unambiguous.
- Around line 52-54: The docstring in src/mqt/bench/custom_solovay_kitaev.py
incorrectly states that TranspilerError is raised when a gate lacks to_matrix,
but the implementation silently continues for such gates; update the docstring
(or remove the Raises section) to reflect the actual behavior by removing the
TranspilerError claim and explaining that gates without a to_matrix method are
skipped, referencing the to_matrix check and TranspilerError symbol so reviewers
can locate the change.
- Around line 68-72: The code directly accesses the private attribute self._sk
and calls self._sk.run(...) then uses dag.substitute_node_with_dag(...); add a
clear FIXME comment above this usage that explains why accessing self._sk is
necessary (e.g., to call the Solovay–Kitaev implementation for approximation)
and include a removal trigger note "Remove once qiskit minimum version is bumped
to 2.0.0" so future maintainers know when to refactor; keep the comment adjacent
to the lines invoking self._sk, reference self._sk, _sk.run, recursion_degree
and dag.substitute_node_with_dag in the comment, and don’t change behavior—this
is purely documentation for the fragile private-attribute dependency.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@src/mqt/bench/benchmarks/shors_nine_qubit_code.py`:
- Around line 306-313: The current validation only checks divisibility by 17 and
allows invalid values like 0 or negative multiples; update the guard around
num_qubits so it requires num_qubits to be a positive multiple of 17 (e.g.,
num_qubits >= 17 and num_qubits % 17 == 0) and raise a clear ValueError
otherwise; adjust the existing validation block that computes num_logical_qubits
and calls _create_single_logical_qubit_circuit to rely on this stricter check.
Description
Adds Shor's 9 Qubit Code as a benchmark
Fixes #790
Checklist: