-
-
Notifications
You must be signed in to change notification settings - Fork 38
✨ add error correction module with Shor and Steane logical circuit transpilers #930
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?
Changes from all commits
4200ef1
5a700a0
38aa1f8
df2affd
e3295e6
6e08c7e
ac7b9ea
b0e5c8c
3e211cb
1fa57c3
5cf108d
e9cc159
fba7a1f
0dec02a
b6978c4
8e189f1
e041878
0410fed
574db9a
d80afea
569bc68
ba98eaf
bd58ad5
f3fbac1
73317f7
997d7d1
1e3b44c
4a26c64
8bf47d6
3832fe8
49bd55a
a65972d
6f765f0
739084b
69e98a7
a470a35
1ace3c5
02d1ac2
86d2c36
b0c175e
9c71e3a
735cebb
45a1721
135d7b1
db68e10
b57e5cc
bcb06ad
2265c5a
624ed2a
d3517db
6d79032
9700a88
6c4b74b
4866c88
78a8d6b
ba31cba
5bfd6c2
2b19794
9432119
2ef22f2
2fa6380
31216cc
5f29699
21c9fd7
956006e
d98c80a
7853e8d
b3e2c8b
22f71bf
5553b37
f5ba739
221eb86
bb53875
137fb83
ceb55da
08463e3
33b24ce
80f347f
1d0e8de
9576b21
5823f63
75df4d6
bc6c18b
fe66b60
b1fc4c1
af74ee5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -301,3 +301,6 @@ pyrightconfig.json | |
|
|
||
| # setuptools_scm | ||
| src/**/_version.py | ||
| .idea/ | ||
| # Test Output | ||
| tests/circuit_drawings/* | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -22,6 +22,9 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||
| from qiskit.transpiler import Layout, Target | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| from typing_extensions import assert_never | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| from .error_correction.shor_transpiler import ShorTranspiler | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| from .error_correction.steane_transpiler import SteaneTranspiler | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| if sys.version_info >= (3, 11): | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| from typing import Unpack | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| else: | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -198,6 +201,7 @@ def get_benchmark_alg( | |||||||||||||||||||||||||||||||||||||||||||||||||||
| def get_benchmark_alg( | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| benchmark: str | QuantumCircuit, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| circuit_size: int | None = None, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| encoding: str = "", | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| *, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| generate_mirror_circuit: bool = False, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| random_parameters: bool = True, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -208,6 +212,7 @@ def get_benchmark_alg( | |||||||||||||||||||||||||||||||||||||||||||||||||||
| Arguments: | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| benchmark: QuantumCircuit or name of the benchmark to be generated | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| circuit_size: Input for the benchmark creation, in most cases this is equal to the qubit number | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| encoding: Error correction code to be used (currently unused). | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Docstrings incorrectly state Both
📍 Affects 1 file
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||
| generate_mirror_circuit: If True, generates the mirror version (U @ U.inverse()) of the benchmark. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| random_parameters: If True, assigns random parameters to the circuit's parameters if they exist. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| kwargs: Additional keyword arguments passed to the circuit creation. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -216,8 +221,19 @@ def get_benchmark_alg( | |||||||||||||||||||||||||||||||||||||||||||||||||||
| Qiskit::QuantumCircuit representing the raw benchmark circuit without any hardware-specific compilation or mapping. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| qc = _get_circuit(benchmark, circuit_size, random_parameters, **kwargs) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Todo: Make it combined with error code | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| if generate_mirror_circuit: | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| return _create_mirror_circuit(qc, inplace=True) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| if encoding == "shor": | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| transpiler = ShorTranspiler(qc, add_syndromes=True) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| transpiler.transpile() | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| return transpiler.transpiled_qc | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| if encoding == "steane": | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| transpiler = SteaneTranspiler(qc, add_syndromes=True) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| transpiler.transpile() | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| return transpiler.transpiled_qc | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| return qc | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+228
to
237
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick | 🔵 Trivial | ⚡ Quick win Invalid If a user passes an invalid encoding like Proposed validation+ valid_encodings = {"", "shor", "steane"}
+ if encoding not in valid_encodings:
+ msg = f"Invalid `encoding` '{encoding}'. Must be one of {valid_encodings}."
+ raise ValueError(msg)
+
if encoding == "shor":
transpiler = ShorTranspiler(qc, add_syndromes=True)
transpiler.transpile()
return transpiler.transpiled_qc
if encoding == "steane":
transpiler = SteaneTranspiler(qc, add_syndromes=True)
transpiler.transpile()
return transpiler.transpiled_qc
return qc📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -478,6 +494,7 @@ def get_benchmark( | |||||||||||||||||||||||||||||||||||||||||||||||||||
| circuit_size: int, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| target: Target | None = None, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| opt_level: int = 2, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| encoding: str = "", | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| *, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| generate_mirror_circuit: bool = False, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| random_parameters: bool = True, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -492,6 +509,7 @@ def get_benchmark( | |||||||||||||||||||||||||||||||||||||||||||||||||||
| circuit_size: None, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| target: Target | None = None, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| opt_level: int = 2, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| encoding: str = "", | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| *, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| generate_mirror_circuit: bool = False, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| random_parameters: bool = True, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -506,6 +524,7 @@ def get_benchmark( | |||||||||||||||||||||||||||||||||||||||||||||||||||
| circuit_size: int | None = None, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| target: Target | None = None, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| opt_level: int = 2, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| encoding: str = "", | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| *, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| generate_mirror_circuit: bool = False, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| random_parameters: bool = True, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -519,6 +538,7 @@ def get_benchmark( | |||||||||||||||||||||||||||||||||||||||||||||||||||
| circuit_size: int | None = None, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| target: Target | None = None, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| opt_level: int = 2, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| encoding: str = "", | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| *, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| generate_mirror_circuit: bool = False, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| random_parameters: bool = True, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -533,6 +553,7 @@ def get_benchmark( | |||||||||||||||||||||||||||||||||||||||||||||||||||
| target: `~qiskit.transpiler.target.Target` for the benchmark generation | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| (only used for "nativegates" and "mapped" level) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| opt_level: Optimization level to be used by the transpiler. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| encoding: Error correction code to be used (currently unused). | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| generate_mirror_circuit: If True, generates the mirror version (U @ U.inverse()) of the benchmark. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| random_parameters: If True, assigns random parameters to the circuit's parameters if they exist. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| kwargs: Additional keyword arguments passed to the circuit creation. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -546,6 +567,7 @@ def get_benchmark( | |||||||||||||||||||||||||||||||||||||||||||||||||||
| circuit_size=circuit_size, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| generate_mirror_circuit=generate_mirror_circuit, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| random_parameters=random_parameters, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| encoding=encoding, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| **kwargs, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.