gem-suite 0.1.6__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- gem_suite-0.1.6/Cargo.toml +28 -0
- gem_suite-0.1.6/LICENSE.txt +175 -0
- gem_suite-0.1.6/MANIFEST.in +3 -0
- gem_suite-0.1.6/PKG-INFO +16 -0
- gem_suite-0.1.6/README.md +49 -0
- gem_suite-0.1.6/gem_suite/__init__.py +23 -0
- gem_suite-0.1.6/gem_suite/analysis.py +196 -0
- gem_suite-0.1.6/gem_suite/experiments.py +172 -0
- gem_suite-0.1.6/gem_suite/gem_core.pyi +73 -0
- gem_suite-0.1.6/gem_suite/plaquettes.py +169 -0
- gem_suite-0.1.6/gem_suite/plot_utils.py +146 -0
- gem_suite-0.1.6/gem_suite/sub_analysis/__init__.py +27 -0
- gem_suite-0.1.6/gem_suite/sub_analysis/magnetization.py +94 -0
- gem_suite-0.1.6/gem_suite/sub_analysis/operators.py +397 -0
- gem_suite-0.1.6/gem_suite.egg-info/PKG-INFO +16 -0
- gem_suite-0.1.6/gem_suite.egg-info/SOURCES.txt +31 -0
- gem_suite-0.1.6/gem_suite.egg-info/dependency_links.txt +1 -0
- gem_suite-0.1.6/gem_suite.egg-info/requires.txt +9 -0
- gem_suite-0.1.6/gem_suite.egg-info/top_level.txt +1 -0
- gem_suite-0.1.6/pyproject.toml +50 -0
- gem_suite-0.1.6/setup.cfg +4 -0
- gem_suite-0.1.6/setup.py +27 -0
- gem_suite-0.1.6/src/graph.rs +212 -0
- gem_suite-0.1.6/src/heavyhex/decoding.rs +421 -0
- gem_suite-0.1.6/src/heavyhex/graph_builder.rs +594 -0
- gem_suite-0.1.6/src/heavyhex/simple_cycle.rs +294 -0
- gem_suite-0.1.6/src/heavyhex/visualization.rs +86 -0
- gem_suite-0.1.6/src/heavyhex.rs +924 -0
- gem_suite-0.1.6/src/lib.rs +31 -0
- gem_suite-0.1.6/src/mock.rs +221 -0
- gem_suite-0.1.6/src/utils.rs +102 -0
- gem_suite-0.1.6/tests/test_analysis.py +135 -0
- gem_suite-0.1.6/tests/test_circuits.py +91 -0
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
[package]
|
|
2
|
+
name = "gem_core"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
edition = "2021"
|
|
5
|
+
rust-version = "1.70"
|
|
6
|
+
license = "Apache-2.0"
|
|
7
|
+
|
|
8
|
+
[lib]
|
|
9
|
+
name = "gem_core"
|
|
10
|
+
crate-type = ["cdylib"]
|
|
11
|
+
|
|
12
|
+
[dependencies]
|
|
13
|
+
bitvec = "1.0.1"
|
|
14
|
+
ahash = "0.8.6"
|
|
15
|
+
hashbrown = "0.14.3"
|
|
16
|
+
indexmap = ">=1.9, <3"
|
|
17
|
+
rayon = "1.10"
|
|
18
|
+
petgraph = "0.6.5"
|
|
19
|
+
lazy_static = "1.4"
|
|
20
|
+
itertools = "0.13.0"
|
|
21
|
+
fusion-blossom = "0.2.10"
|
|
22
|
+
|
|
23
|
+
[dev-dependencies]
|
|
24
|
+
approx = "0.5.1"
|
|
25
|
+
|
|
26
|
+
[dependencies.pyo3]
|
|
27
|
+
version = "0.22.2"
|
|
28
|
+
features = ["extension-module", "hashbrown"]
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
gem_suite-0.1.6/PKG-INFO
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: gem-suite
|
|
3
|
+
Version: 0.1.6
|
|
4
|
+
Summary: Qiskit Experiments suite for generation of entanglement using measurements.
|
|
5
|
+
Author-email: Naoki Kanazawa <knzwnao@jp.ibm.com>
|
|
6
|
+
Requires-Python: >=3.8
|
|
7
|
+
Description-Content-Type: text/markdown
|
|
8
|
+
License-File: LICENSE.txt
|
|
9
|
+
Requires-Dist: pymatching
|
|
10
|
+
Requires-Dist: qiskit>=1.0
|
|
11
|
+
Requires-Dist: qiskit-experiments>=0.7
|
|
12
|
+
Requires-Dist: qiskit-ibm-runtime
|
|
13
|
+
Provides-Extra: dev
|
|
14
|
+
Requires-Dist: black; extra == "dev"
|
|
15
|
+
Requires-Dist: qiskit-aer; extra == "dev"
|
|
16
|
+
Requires-Dist: ruff; extra == "dev"
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# GEM experiment suite
|
|
2
|
+
|
|
3
|
+
[](https://opensource.org/licenses/Apache-2.0)
|
|
4
|
+
|
|
5
|
+
The GEM (Generation of Entanglement by Measurement) protocol prepares a quantum state across many qubits using an efficient, measurement-based protocol.
|
|
6
|
+
Generally, it is technical challenge to achieve this on current generation quantum devices because most preparation protocols are vulnerable to imperfections in gates and to noise. The protocol that realizes the Nishimori transition, also understood as a fault-tolerant threshold, is a constant depth method that demonstrates how measurement-based state preparation might be used on large-scale quantum devices exceeding a few hundred qubits.
|
|
7
|
+
Through injecting coherent errors, the GEM experiment provides an estimate for how far below the error correction threshold a device is operating.
|
|
8
|
+
|
|
9
|
+
All technical details are available on arXiv: <https://arxiv.org/abs/2309.02863>
|
|
10
|
+
|
|
11
|
+
Because of the computationally intensive subroutine responsible for decoding the measurement outcomes, this library is mostly implemented in Rust programming language for performance. The core library is interfaced with [Qiskit Experiments](https://github.com/Qiskit-Extensions/qiskit-experiments) via [PyO3](https://docs.rs/pyo3/latest/pyo3/index.html) to produce experiment circuits with the Qiskit model and analyze the results. We support two minimum weight perfect matching decoders; [pymatching](https://github.com/oscarhiggott/PyMatching) and [fusion-blossom](https://github.com/yuewuo/fusion-blossom).
|
|
12
|
+
|
|
13
|
+
This library is designed to work with, but not limited only to, IBM Quantum processors.
|
|
14
|
+
|
|
15
|
+
## Installation
|
|
16
|
+
|
|
17
|
+
This package can be installed from the downloaded repository using pip as
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
cd gem-suite
|
|
21
|
+
pip install .
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Example
|
|
25
|
+
|
|
26
|
+
In the GEM protocol, an atomic unit of the experiment is a plaquette, which is a collection of multiple qubits.
|
|
27
|
+
For the case of IBM Quantum processors with heavy hexagonal lattices,
|
|
28
|
+
a single plaquette contains 12 qubits and a single IBM Eagle processor has 18 plaquettes.
|
|
29
|
+
This is an efficient compact representation of a quantum processor with a few hundred qubits. We anticipate very minor changes to this representation when scaling up to larger devices.
|
|
30
|
+
|
|
31
|
+

|
|
32
|
+
|
|
33
|
+
We can partly reproduce experiments in the publication with a few lines of code using the Qiskit Experiments framework.
|
|
34
|
+
|
|
35
|
+
```python
|
|
36
|
+
from gem_suite.experiments import GemExperiment
|
|
37
|
+
from qiskit_ibm_runtime import QiskitRuntimeService
|
|
38
|
+
|
|
39
|
+
backend = QiskitRuntimeService().backend("ibm_cusco")
|
|
40
|
+
|
|
41
|
+
gem_exp = GemExperiment(plaquettes=range(18), backend=backend)
|
|
42
|
+
exp_data = gem_exp.run().block_for_results()
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Please see [our example notebook](./examples/01_gem_benchmark.ipynb) for the complete workflow.
|
|
46
|
+
|
|
47
|
+
## License
|
|
48
|
+
|
|
49
|
+
[Apache License 2.0](LICENSE.txt)
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
2
|
+
# not use this file except in compliance with the License. You may obtain
|
|
3
|
+
# a copy of the License at
|
|
4
|
+
#
|
|
5
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
#
|
|
7
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
8
|
+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
9
|
+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
10
|
+
# License for the specific language governing permissions and limitations
|
|
11
|
+
# under the License.
|
|
12
|
+
"""GEM experiment suite."""
|
|
13
|
+
|
|
14
|
+
from .plaquettes import PlaquetteLattice
|
|
15
|
+
from .experiments import GemExperiment
|
|
16
|
+
from .analysis import GemAnalysis
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
__all__ = [
|
|
20
|
+
"PlaquetteLattice",
|
|
21
|
+
"GemExperiment",
|
|
22
|
+
"GemAnalysis",
|
|
23
|
+
]
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
2
|
+
# not use this file except in compliance with the License. You may obtain
|
|
3
|
+
# a copy of the License at
|
|
4
|
+
#
|
|
5
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
#
|
|
7
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
8
|
+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
9
|
+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
10
|
+
# License for the specific language governing permissions and limitations
|
|
11
|
+
# under the License.
|
|
12
|
+
"""Qiskit Experiments implementation of GEM outcome decoding and analysis."""
|
|
13
|
+
|
|
14
|
+
from __future__ import annotations
|
|
15
|
+
|
|
16
|
+
import pandas as pd
|
|
17
|
+
from uncertainties import ufloat
|
|
18
|
+
from qiskit_experiments.framework import (
|
|
19
|
+
BaseAnalysis,
|
|
20
|
+
ExperimentData,
|
|
21
|
+
AnalysisResultData,
|
|
22
|
+
ArtifactData,
|
|
23
|
+
FigureData,
|
|
24
|
+
Options,
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
from gem_suite.gem_core import visualize_plaquette_with_noise, PyHeavyHexLattice
|
|
28
|
+
from .sub_analysis import (
|
|
29
|
+
analyze_magnetization,
|
|
30
|
+
analyze_operators,
|
|
31
|
+
analyze_individual_bonds,
|
|
32
|
+
analyze_clifford_limit,
|
|
33
|
+
)
|
|
34
|
+
from .plaquettes import PlaquetteLattice
|
|
35
|
+
from .plot_utils import dot_to_mplfigure
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
class GemAnalysis(BaseAnalysis):
|
|
39
|
+
"""GEM analysis for 2D protocol."""
|
|
40
|
+
|
|
41
|
+
def __init__(
|
|
42
|
+
self,
|
|
43
|
+
plaquettes: PlaquetteLattice | None = None,
|
|
44
|
+
):
|
|
45
|
+
"""Create new GEM analysis instance.
|
|
46
|
+
|
|
47
|
+
Args:
|
|
48
|
+
plaquettes: PlaquetteLattice instance of target device.
|
|
49
|
+
This can be automatically instantiated from the
|
|
50
|
+
GEM Experiment metadata if not given.
|
|
51
|
+
"""
|
|
52
|
+
super().__init__()
|
|
53
|
+
self._plaquettes = plaquettes
|
|
54
|
+
|
|
55
|
+
@classmethod
|
|
56
|
+
def _default_options(cls) -> Options:
|
|
57
|
+
"""Default analysis options for GEM analysis.
|
|
58
|
+
|
|
59
|
+
Analysis Options:
|
|
60
|
+
analyze_individual_bond (bool): Perform analysis on individual
|
|
61
|
+
ZXZ operator of each bond qubits to analyze
|
|
62
|
+
local p_bond and p_site quantities.
|
|
63
|
+
This may create large amount of analysis result entries
|
|
64
|
+
when you run experiment with many plaquettes.
|
|
65
|
+
analyze_clifford_limit (bool): Perform analysis at Clifford limit,
|
|
66
|
+
i.e. theta = 0.5 pi. This data point must be included.
|
|
67
|
+
Enabling this option will add a new figure illustrating
|
|
68
|
+
the error distribution in the plaquette view along with
|
|
69
|
+
several analysis results of plaquette-wise qualities.
|
|
70
|
+
decoder (str): Minimum weight perfect matching decoder.
|
|
71
|
+
"fusion-blossom" and "pymatching" are supported.
|
|
72
|
+
"""
|
|
73
|
+
options = super()._default_options()
|
|
74
|
+
options.update_options(
|
|
75
|
+
analyze_individual_bond=False,
|
|
76
|
+
analyze_clifford_limit=False,
|
|
77
|
+
decoder="pymatching",
|
|
78
|
+
)
|
|
79
|
+
options.set_validator("decoder", ["pymatching", "fusion-blossom"])
|
|
80
|
+
return options
|
|
81
|
+
|
|
82
|
+
# pylint: disable=too-many-locals
|
|
83
|
+
def _run_analysis(
|
|
84
|
+
self,
|
|
85
|
+
experiment_data: ExperimentData,
|
|
86
|
+
) -> tuple[list[AnalysisResultData | ArtifactData], list[FigureData]]:
|
|
87
|
+
fig_data = []
|
|
88
|
+
analysis_results = []
|
|
89
|
+
|
|
90
|
+
# Check if lattice object exists.
|
|
91
|
+
# The lattice information is necessary for decoding experiment outcomes.
|
|
92
|
+
if self._plaquettes is None:
|
|
93
|
+
plaquette_qubit_map = experiment_data.metadata.get("plaquette_qubit_map", None)
|
|
94
|
+
connectivity = experiment_data.metadata.get("connectivity", None)
|
|
95
|
+
if plaquette_qubit_map is None or connectivity is None:
|
|
96
|
+
raise RuntimeError(
|
|
97
|
+
"Analysis is not initialized with PlaquetteLattice instance and "
|
|
98
|
+
"its description is not provided by the experiment metadata. "
|
|
99
|
+
"This analysis cannot be performed because of "
|
|
100
|
+
"the missing lattice information to decode bitstrings."
|
|
101
|
+
)
|
|
102
|
+
lattice = PyHeavyHexLattice.from_plaquettes(plaquette_qubit_map, connectivity)
|
|
103
|
+
self._plaquettes = PlaquetteLattice(lattice)
|
|
104
|
+
|
|
105
|
+
# Decode count dictionaries and build intermediate data collection.
|
|
106
|
+
records = []
|
|
107
|
+
for data in experiment_data.data():
|
|
108
|
+
result = self._plaquettes.decode_outcomes(
|
|
109
|
+
counts=data["counts"],
|
|
110
|
+
decoder=self.options.decoder,
|
|
111
|
+
return_counts=False,
|
|
112
|
+
)
|
|
113
|
+
records.extend(
|
|
114
|
+
[
|
|
115
|
+
{
|
|
116
|
+
"name": "f",
|
|
117
|
+
"theta": data["metadata"]["theta"],
|
|
118
|
+
"schedule": data["metadata"]["schedule_index"],
|
|
119
|
+
"value": ufloat(result.f[0], result.f[1]),
|
|
120
|
+
"component": pd.NA,
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
"name": "g",
|
|
124
|
+
"theta": data["metadata"]["theta"],
|
|
125
|
+
"schedule": data["metadata"]["schedule_index"],
|
|
126
|
+
"value": ufloat(result.g[0], result.g[1]),
|
|
127
|
+
"component": pd.NA,
|
|
128
|
+
},
|
|
129
|
+
]
|
|
130
|
+
)
|
|
131
|
+
for i, expv in enumerate(result.w_ops):
|
|
132
|
+
records.append(
|
|
133
|
+
{
|
|
134
|
+
"name": "w",
|
|
135
|
+
"theta": data["metadata"]["theta"],
|
|
136
|
+
"schedule": data["metadata"]["schedule_index"],
|
|
137
|
+
"value": expv,
|
|
138
|
+
"component": i,
|
|
139
|
+
}
|
|
140
|
+
)
|
|
141
|
+
for i, expv in enumerate(result.zxz_ops):
|
|
142
|
+
records.append(
|
|
143
|
+
{
|
|
144
|
+
"name": "zxz",
|
|
145
|
+
"theta": data["metadata"]["theta"],
|
|
146
|
+
"schedule": data["metadata"]["schedule_index"],
|
|
147
|
+
"value": expv,
|
|
148
|
+
"component": i,
|
|
149
|
+
}
|
|
150
|
+
)
|
|
151
|
+
dataframe = pd.DataFrame.from_records(records)
|
|
152
|
+
del records
|
|
153
|
+
|
|
154
|
+
# Analyze magnetizations
|
|
155
|
+
num_site = 0
|
|
156
|
+
for qubit in self._plaquettes.qubits():
|
|
157
|
+
if qubit.role == "Site":
|
|
158
|
+
num_site += 1
|
|
159
|
+
mag_figs, mag_results = analyze_magnetization(dataframe, num_site)
|
|
160
|
+
fig_data.extend(mag_figs)
|
|
161
|
+
analysis_results.extend(mag_results)
|
|
162
|
+
|
|
163
|
+
# Analyze operators
|
|
164
|
+
op_figs, op_results = analyze_operators(dataframe)
|
|
165
|
+
fig_data.extend(op_figs)
|
|
166
|
+
analysis_results.extend(op_results)
|
|
167
|
+
|
|
168
|
+
# Analyze local bond parameters (Optional)
|
|
169
|
+
if self.options.analyze_individual_bond:
|
|
170
|
+
local_params = analyze_individual_bonds(
|
|
171
|
+
data=dataframe,
|
|
172
|
+
qubits=self._plaquettes.qubits(),
|
|
173
|
+
)
|
|
174
|
+
analysis_results.extend(local_params)
|
|
175
|
+
|
|
176
|
+
# Analyze plaquette quality (Optional)
|
|
177
|
+
if self.options.analyze_clifford_limit:
|
|
178
|
+
plaquette_qualities = analyze_clifford_limit(
|
|
179
|
+
data=dataframe,
|
|
180
|
+
plaquettes=self._plaquettes.plaquettes(),
|
|
181
|
+
qubits=self._plaquettes.qubits(),
|
|
182
|
+
)
|
|
183
|
+
analysis_results.extend(plaquette_qualities)
|
|
184
|
+
if plaquette_qualities:
|
|
185
|
+
p_map = {p.index: p.qubits for p in self._plaquettes.plaquettes()}
|
|
186
|
+
noise_map = {
|
|
187
|
+
q.extra["plaquette"]: q.value.n
|
|
188
|
+
for q in plaquette_qualities
|
|
189
|
+
if q.value is not None
|
|
190
|
+
}
|
|
191
|
+
dot = visualize_plaquette_with_noise(p_map, noise_map)
|
|
192
|
+
fig_data.append(
|
|
193
|
+
FigureData(dot_to_mplfigure(dot, "neato", 300), name="plaquette_quality")
|
|
194
|
+
)
|
|
195
|
+
|
|
196
|
+
return analysis_results, fig_data
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
2
|
+
# not use this file except in compliance with the License. You may obtain
|
|
3
|
+
# a copy of the License at
|
|
4
|
+
#
|
|
5
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
#
|
|
7
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
8
|
+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
9
|
+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
10
|
+
# License for the specific language governing permissions and limitations
|
|
11
|
+
# under the License.
|
|
12
|
+
"""Qiskit Experiments implementation of GEM experiment protocol."""
|
|
13
|
+
|
|
14
|
+
from __future__ import annotations
|
|
15
|
+
|
|
16
|
+
from itertools import product
|
|
17
|
+
from typing import Any
|
|
18
|
+
|
|
19
|
+
import numpy as np
|
|
20
|
+
|
|
21
|
+
from qiskit_experiments.framework import BaseExperiment, Options
|
|
22
|
+
from qiskit.providers.backend import BackendV2
|
|
23
|
+
from qiskit.circuit import QuantumCircuit, Parameter
|
|
24
|
+
|
|
25
|
+
from .analysis import GemAnalysis
|
|
26
|
+
from .plaquettes import PlaquetteLattice
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
class GemExperiment(BaseExperiment):
|
|
30
|
+
"""GEM experiment in 2D protocol."""
|
|
31
|
+
|
|
32
|
+
parameter = Parameter("θ")
|
|
33
|
+
|
|
34
|
+
def __init__(
|
|
35
|
+
self,
|
|
36
|
+
plaquettes: PlaquetteLattice | list[int],
|
|
37
|
+
backend: BackendV2 | None,
|
|
38
|
+
):
|
|
39
|
+
"""Create new GEM experiment.
|
|
40
|
+
|
|
41
|
+
.. notes::
|
|
42
|
+
Current implementation supports only Heavy Hexagon lattice
|
|
43
|
+
and measurement-based 2D protocol.
|
|
44
|
+
|
|
45
|
+
Args:
|
|
46
|
+
plaquettes: List of plaquette indices or configuired :class:`PlaquetteLattice`
|
|
47
|
+
instance to build GEM circuits on.
|
|
48
|
+
backend: Qiskit Backend to run experiments.
|
|
49
|
+
|
|
50
|
+
Raises:
|
|
51
|
+
RuntimeError: When plaquettes are selected by index but backend is not provided.
|
|
52
|
+
"""
|
|
53
|
+
if not isinstance(plaquettes, PlaquetteLattice):
|
|
54
|
+
plaquettes = PlaquetteLattice.from_backend(backend).filter(includes=plaquettes)
|
|
55
|
+
qubits = [q.index for q in plaquettes.qubits()]
|
|
56
|
+
super().__init__(
|
|
57
|
+
physical_qubits=qubits,
|
|
58
|
+
analysis=GemAnalysis(plaquettes=plaquettes),
|
|
59
|
+
backend=backend,
|
|
60
|
+
)
|
|
61
|
+
self._plaquettes = plaquettes
|
|
62
|
+
|
|
63
|
+
@property
|
|
64
|
+
def plaquettes(self) -> PlaquetteLattice:
|
|
65
|
+
"""Plaquette lattice to run experiemnts on."""
|
|
66
|
+
return self._plaquettes
|
|
67
|
+
|
|
68
|
+
def parameters(self) -> np.ndarray:
|
|
69
|
+
"""Create numpy array of parameters scanned in this experiment.
|
|
70
|
+
|
|
71
|
+
Returns:
|
|
72
|
+
Angle of ZZ gate determining tA.
|
|
73
|
+
"""
|
|
74
|
+
if self.experiment_options.angles is None:
|
|
75
|
+
return np.linspace(
|
|
76
|
+
self.experiment_options.min_angle,
|
|
77
|
+
self.experiment_options.max_angle,
|
|
78
|
+
self.experiment_options.num_angles,
|
|
79
|
+
)
|
|
80
|
+
return np.asarray(self.experiment_options.angles, dtype=float)
|
|
81
|
+
|
|
82
|
+
@classmethod
|
|
83
|
+
def _default_transpile_options(cls) -> Options:
|
|
84
|
+
options = super()._default_transpile_options()
|
|
85
|
+
options.optimization_level = 1
|
|
86
|
+
return options
|
|
87
|
+
|
|
88
|
+
@classmethod
|
|
89
|
+
def _default_experiment_options(cls) -> Options:
|
|
90
|
+
"""Default option values for GEM experiment.
|
|
91
|
+
|
|
92
|
+
Experiment Options:
|
|
93
|
+
schedule_idx (int): Select from 0 to 11 if any. If not provided
|
|
94
|
+
the experiment builds circuits for all possible scheduling patterns
|
|
95
|
+
and performs the analysis on averaged outcomes.
|
|
96
|
+
min_angle (float): Minimum angle to scan.
|
|
97
|
+
max_angle (float): Maximum angle to scan.
|
|
98
|
+
num_angles (int): Number of angles to scan.
|
|
99
|
+
angles (Sequence[float]): The list of angles that will be scanned in
|
|
100
|
+
the experiment. If not set, then ``num_angles``
|
|
101
|
+
evenly spaced delays between ``min_angle`` and ``max_angle``
|
|
102
|
+
are used. If ``angles`` is set, these parameters are ignored.
|
|
103
|
+
"""
|
|
104
|
+
options = super()._default_experiment_options()
|
|
105
|
+
options.schedule_idx = None
|
|
106
|
+
options.sweep_type = "A"
|
|
107
|
+
|
|
108
|
+
options.min_angle = 0
|
|
109
|
+
options.max_angle = np.pi / 2
|
|
110
|
+
options.num_angles = 21
|
|
111
|
+
options.angles = None
|
|
112
|
+
|
|
113
|
+
options.set_validator("sweep_type", ["A", "B"])
|
|
114
|
+
|
|
115
|
+
return options
|
|
116
|
+
|
|
117
|
+
def parameterized_circuits(self) -> tuple[QuantumCircuit, ...]:
|
|
118
|
+
"""Return GEM circuit with unbound parameters.
|
|
119
|
+
|
|
120
|
+
Returns:
|
|
121
|
+
Parameterized circuits.
|
|
122
|
+
"""
|
|
123
|
+
bond_idxs = [
|
|
124
|
+
self.physical_qubits.index(q.index)
|
|
125
|
+
for q in self._plaquettes.qubits()
|
|
126
|
+
if q.role == "Bond"
|
|
127
|
+
]
|
|
128
|
+
|
|
129
|
+
# Create virtual circuit
|
|
130
|
+
# Virtual qubit index is based off of list index of self.physical_qubits
|
|
131
|
+
if (usr_index := self.experiment_options.schedule_idx) is not None:
|
|
132
|
+
sched_idx = [usr_index]
|
|
133
|
+
else:
|
|
134
|
+
sched_idx = list(range(12))
|
|
135
|
+
circs = []
|
|
136
|
+
for i in sched_idx:
|
|
137
|
+
sched_iter = self._plaquettes.build_gate_schedule(i)
|
|
138
|
+
circ = QuantumCircuit(self.num_qubits, self.num_qubits)
|
|
139
|
+
circ.metadata = {"schedule_index": i}
|
|
140
|
+
circ.h(range(self.num_qubits))
|
|
141
|
+
for gate_group in sched_iter:
|
|
142
|
+
circ.barrier()
|
|
143
|
+
for gate in gate_group:
|
|
144
|
+
if gate.group == self.experiment_options.sweep_type:
|
|
145
|
+
angle = self.parameter
|
|
146
|
+
else:
|
|
147
|
+
angle = np.pi / 2
|
|
148
|
+
circ.rzz(
|
|
149
|
+
angle,
|
|
150
|
+
self.physical_qubits.index(gate.index0),
|
|
151
|
+
self.physical_qubits.index(gate.index1),
|
|
152
|
+
)
|
|
153
|
+
circ.barrier()
|
|
154
|
+
circ.h(bond_idxs)
|
|
155
|
+
circ.barrier()
|
|
156
|
+
circ.measure(range(self.num_qubits), range(self.num_qubits))
|
|
157
|
+
circs.append(circ)
|
|
158
|
+
return tuple(circs)
|
|
159
|
+
|
|
160
|
+
def circuits(self) -> list[QuantumCircuit]:
|
|
161
|
+
circs_bound = []
|
|
162
|
+
for tmp_circ, param in product(self.parameterized_circuits(), self.parameters()):
|
|
163
|
+
assigned = tmp_circ.assign_parameters({self.parameter: param}, inplace=False)
|
|
164
|
+
assigned.metadata["theta"] = np.round(param / np.pi, 5)
|
|
165
|
+
circs_bound.append(assigned)
|
|
166
|
+
return circs_bound
|
|
167
|
+
|
|
168
|
+
def _metadata(self) -> dict[str, Any]:
|
|
169
|
+
metadata = super()._metadata()
|
|
170
|
+
metadata["connectivity"] = self.plaquettes.connectivity()
|
|
171
|
+
metadata["plaquette_qubit_map"] = {p.index: p.qubits for p in self.plaquettes.plaquettes()}
|
|
172
|
+
return metadata
|