iqm-benchmarks 1.3__py3-none-any.whl
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.
Potentially problematic release.
This version of iqm-benchmarks might be problematic. Click here for more details.
- iqm/benchmarks/__init__.py +31 -0
- iqm/benchmarks/benchmark.py +109 -0
- iqm/benchmarks/benchmark_definition.py +264 -0
- iqm/benchmarks/benchmark_experiment.py +163 -0
- iqm/benchmarks/compressive_gst/__init__.py +20 -0
- iqm/benchmarks/compressive_gst/compressive_gst.py +1029 -0
- iqm/benchmarks/entanglement/__init__.py +18 -0
- iqm/benchmarks/entanglement/ghz.py +802 -0
- iqm/benchmarks/logging_config.py +29 -0
- iqm/benchmarks/optimization/__init__.py +18 -0
- iqm/benchmarks/optimization/qscore.py +719 -0
- iqm/benchmarks/quantum_volume/__init__.py +21 -0
- iqm/benchmarks/quantum_volume/clops.py +726 -0
- iqm/benchmarks/quantum_volume/quantum_volume.py +854 -0
- iqm/benchmarks/randomized_benchmarking/__init__.py +18 -0
- iqm/benchmarks/randomized_benchmarking/clifford_1q.pkl +0 -0
- iqm/benchmarks/randomized_benchmarking/clifford_2q.pkl +0 -0
- iqm/benchmarks/randomized_benchmarking/clifford_rb/__init__.py +19 -0
- iqm/benchmarks/randomized_benchmarking/clifford_rb/clifford_rb.py +386 -0
- iqm/benchmarks/randomized_benchmarking/interleaved_rb/__init__.py +19 -0
- iqm/benchmarks/randomized_benchmarking/interleaved_rb/interleaved_rb.py +555 -0
- iqm/benchmarks/randomized_benchmarking/mirror_rb/__init__.py +19 -0
- iqm/benchmarks/randomized_benchmarking/mirror_rb/mirror_rb.py +810 -0
- iqm/benchmarks/randomized_benchmarking/multi_lmfit.py +86 -0
- iqm/benchmarks/randomized_benchmarking/randomized_benchmarking_common.py +892 -0
- iqm/benchmarks/readout_mitigation.py +290 -0
- iqm/benchmarks/utils.py +521 -0
- iqm_benchmarks-1.3.dist-info/LICENSE +205 -0
- iqm_benchmarks-1.3.dist-info/METADATA +190 -0
- iqm_benchmarks-1.3.dist-info/RECORD +42 -0
- iqm_benchmarks-1.3.dist-info/WHEEL +5 -0
- iqm_benchmarks-1.3.dist-info/top_level.txt +2 -0
- mGST/LICENSE +21 -0
- mGST/README.md +54 -0
- mGST/additional_fns.py +962 -0
- mGST/algorithm.py +733 -0
- mGST/compatibility.py +238 -0
- mGST/low_level_jit.py +694 -0
- mGST/optimization.py +349 -0
- mGST/qiskit_interface.py +282 -0
- mGST/reporting/figure_gen.py +334 -0
- mGST/reporting/reporting.py +710 -0
mGST/compatibility.py
ADDED
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Interface to pyGSTi
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
import numpy as np
|
|
6
|
+
from pygsti.baseobjs import Basis, Label
|
|
7
|
+
from pygsti.circuits import create_lsgst_circuits
|
|
8
|
+
from pygsti.models.modelconstruction import create_explicit_model_from_expressions
|
|
9
|
+
from pygsti.report.reportables import entanglement_fidelity
|
|
10
|
+
from pygsti.tools import change_basis
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def pygsti_model_to_arrays(model, basis="pp"):
|
|
14
|
+
"""Turn the gate set of a pygsti model into numpy arrays used by mGST.
|
|
15
|
+
|
|
16
|
+
Parameters
|
|
17
|
+
----------
|
|
18
|
+
model : pygsti ExplicitOpModel object
|
|
19
|
+
Contains the model parameters in the Pauli transfer matrix formalism
|
|
20
|
+
|
|
21
|
+
basis : {'pp','std'}
|
|
22
|
+
The basis in which the output gate set will be given. It can be either
|
|
23
|
+
'pp' (Pauli basis) or 'std' (standard basis)
|
|
24
|
+
|
|
25
|
+
Returns
|
|
26
|
+
-------
|
|
27
|
+
X : numpy array
|
|
28
|
+
Gate set tensor of shape (Number of Gates, Kraus rank, dimension^2, dimension^2)
|
|
29
|
+
E : numpy array
|
|
30
|
+
POVM matrix of shape (#POVM elements, dimension^2)
|
|
31
|
+
rho : numpy array
|
|
32
|
+
Initial state vector of shape (dimension^2)
|
|
33
|
+
"""
|
|
34
|
+
X = []
|
|
35
|
+
op_Labels = list(model.__dict__["operations"].keys())
|
|
36
|
+
effect_Labels = list(model["Mdefault"].keys())
|
|
37
|
+
E = np.array([model["Mdefault"][label].to_dense().reshape(-1) for label in effect_Labels])
|
|
38
|
+
rho = model["rho0"].to_dense().reshape(-1)
|
|
39
|
+
for op_Label in op_Labels:
|
|
40
|
+
X.append(model[op_Label].to_dense())
|
|
41
|
+
if basis == "pp":
|
|
42
|
+
return (np.array(X).astype(np.complex128), E.astype(np.complex128), rho.astype(np.complex128))
|
|
43
|
+
if basis == "std":
|
|
44
|
+
return pp2std(np.array(X), E, rho)
|
|
45
|
+
raise ValueError(f"Wrong basis input, use either std or pp")
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def average_gate_fidelities(model1, model2, pdim, basis_string="pp"):
|
|
49
|
+
"""Return the average gate fidelities between gates of two pygsti models.
|
|
50
|
+
|
|
51
|
+
Parameters
|
|
52
|
+
----------
|
|
53
|
+
model : pygsti ExplicitOpModel object
|
|
54
|
+
Contains the model parameters in the Pauli transfer matrix formalism
|
|
55
|
+
model2 : pygsti ExplicitOpModel object
|
|
56
|
+
Contains the model parameters in the Pauli transfer matrix formalism
|
|
57
|
+
pdim : int
|
|
58
|
+
physical dimension
|
|
59
|
+
basis : {'pp','std'}
|
|
60
|
+
The basis in which the input models are gíven. It can be either
|
|
61
|
+
'pp' (Pauli basis) or 'std' (standard basis, Default)
|
|
62
|
+
|
|
63
|
+
Returns
|
|
64
|
+
-------
|
|
65
|
+
fidelities : 1D numpy array
|
|
66
|
+
Array containing the average gate fidelities for all gates
|
|
67
|
+
"""
|
|
68
|
+
ent_fids = []
|
|
69
|
+
basis = Basis.cast(basis_string, pdim**2)
|
|
70
|
+
labels1 = list(model1.__dict__["operations"].keys())
|
|
71
|
+
labels2 = list(model2.__dict__["operations"].keys())
|
|
72
|
+
|
|
73
|
+
for i, label in enumerate(labels1):
|
|
74
|
+
ent_fids.append(float(entanglement_fidelity(model1[label], model2[labels2[i]], basis)))
|
|
75
|
+
fidelities = (np.array(ent_fids) * pdim + 1) / (pdim + 1)
|
|
76
|
+
return fidelities
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def model_agfs(model, pdim):
|
|
80
|
+
"""Return the average gate fidelities between gates of two pygsti models.
|
|
81
|
+
|
|
82
|
+
Parameters
|
|
83
|
+
----------
|
|
84
|
+
model : pygsti ExplicitOpModel object
|
|
85
|
+
Contains the model parameters in the Pauli transfer matrix formalism
|
|
86
|
+
pdim : int
|
|
87
|
+
physical dimension
|
|
88
|
+
|
|
89
|
+
Returns
|
|
90
|
+
-------
|
|
91
|
+
fidelities : 1D numpy array
|
|
92
|
+
Average gate fidelities between all different gates of the input model
|
|
93
|
+
"""
|
|
94
|
+
ent_fids = []
|
|
95
|
+
basis = Basis.cast("pp", pdim**2)
|
|
96
|
+
labels = list(model.__dict__["operations"].keys())
|
|
97
|
+
for i, _ in enumerate(labels):
|
|
98
|
+
for j, _ in enumerate(labels):
|
|
99
|
+
if j > i:
|
|
100
|
+
ent_fids.append(float(entanglement_fidelity(model[labels[i]], model[labels[j]], basis)))
|
|
101
|
+
fidelities = (np.array(ent_fids) * pdim + 1) / (pdim + 1)
|
|
102
|
+
return fidelities
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
def arrays_to_pygsti_model(X, E, rho, basis="std"):
|
|
106
|
+
"""Turns a gate set given by numpy arrays into a pygsti model
|
|
107
|
+
|
|
108
|
+
pygsti model is by default in Pauli-basis
|
|
109
|
+
|
|
110
|
+
Parameters
|
|
111
|
+
----------
|
|
112
|
+
X : numpy array
|
|
113
|
+
Gate set tensor of shape (Number of Gates, Kraus rank, dimension^2, dimension^2)
|
|
114
|
+
E : numpy array
|
|
115
|
+
POVM matrix of shape (#POVM elements, dimension^2)
|
|
116
|
+
rho : numpy array
|
|
117
|
+
Initial state vector of shape (dimension^2)
|
|
118
|
+
basis : {'pp','std'}
|
|
119
|
+
The basis in which the INPUT gate set is given. It can be either
|
|
120
|
+
'pp' (Pauli basis) or 'std' (standard basis)
|
|
121
|
+
|
|
122
|
+
Returns
|
|
123
|
+
-------
|
|
124
|
+
model : pygsti ExplicitOpModel object
|
|
125
|
+
Contains the model parameters in the Pauli transfer matrix formalism
|
|
126
|
+
"""
|
|
127
|
+
d = X.shape[0]
|
|
128
|
+
pdim = int(np.sqrt(len(rho)))
|
|
129
|
+
Id = np.zeros(pdim**2)
|
|
130
|
+
Id[0] = 1
|
|
131
|
+
effect_label_str = [f"%i" % k for k in range(E.shape[0])]
|
|
132
|
+
if basis == "std":
|
|
133
|
+
X, E, rho = std2pp(X, E, rho)
|
|
134
|
+
mdl_out = create_explicit_model_from_expressions(
|
|
135
|
+
list(range(int(np.log(pdim) / np.log(2)))),
|
|
136
|
+
[Label(f"G%i" % i) for i in range(d)],
|
|
137
|
+
[f":".join([f"I(%i)" % i for i in range(int(np.log(pdim) / np.log(2)))]) for length in range(d)],
|
|
138
|
+
effect_labels=effect_label_str,
|
|
139
|
+
)
|
|
140
|
+
mdl_out["rho0"] = np.real(rho)
|
|
141
|
+
mdl_out["Mdefault"].from_vector(np.real(E).reshape(-1))
|
|
142
|
+
for i in range(d):
|
|
143
|
+
mdl_out[Label(f"G%i" % i)] = np.real(X[i])
|
|
144
|
+
return mdl_out
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
def std2pp(X, E, rho):
|
|
148
|
+
"""Basis change of an mGST model from the standard basis to the Pauli basis
|
|
149
|
+
|
|
150
|
+
Parameters
|
|
151
|
+
----------
|
|
152
|
+
X : numpy array
|
|
153
|
+
Gate set tensor of shape (Number of Gates, Kraus rank, dimension^2, dimension^2)
|
|
154
|
+
in standard basis
|
|
155
|
+
E : numpy array
|
|
156
|
+
POVM matrix of shape (#POVM elements, dimension^2) in standard basis
|
|
157
|
+
rho : numpy array
|
|
158
|
+
Initial state vector of shape (dimension^2) in standard basis
|
|
159
|
+
|
|
160
|
+
Returns
|
|
161
|
+
-------
|
|
162
|
+
Xpp : numpy array
|
|
163
|
+
Gate set tensor of shape (Number of Gates, Kraus rank, dimension^2, dimension^2)
|
|
164
|
+
in Pauli basis
|
|
165
|
+
Epp : numpy array
|
|
166
|
+
POVM matrix of shape (#POVM elements, dimension^2) in Pauli basis
|
|
167
|
+
rhopp : numpy array
|
|
168
|
+
Initial state vector of shape (dimension^2) in Pauli basis
|
|
169
|
+
"""
|
|
170
|
+
Xpp = np.array([np.array(change_basis(X[i], "std", "pp")) for i in range(X.shape[0])])
|
|
171
|
+
Epp = np.array([np.array(change_basis(E[i], "std", "pp")) for i in range(E.shape[0])])
|
|
172
|
+
return (Xpp.astype(np.complex128), Epp.astype(np.complex128), change_basis(rho, "std", "pp").astype(np.complex128))
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
def pp2std(X, E, rho):
|
|
176
|
+
"""Basis change of an mGST model from the Pauli basis to the standard basis.
|
|
177
|
+
|
|
178
|
+
Parameters
|
|
179
|
+
----------
|
|
180
|
+
X : numpy array
|
|
181
|
+
Gate set tensor of shape (Number of Gates, Kraus rank, dimension^2, dimension^2)
|
|
182
|
+
in Pauli basis
|
|
183
|
+
E : numpy array
|
|
184
|
+
POVM matrix of shape (#POVM elements, dimension^2) in Pauli basis
|
|
185
|
+
rho : numpy array
|
|
186
|
+
Initial state vector of shape (dimension^2) in Pauli basis
|
|
187
|
+
|
|
188
|
+
Returns
|
|
189
|
+
-------
|
|
190
|
+
Xstd : numpy array
|
|
191
|
+
Gate set tensor of shape (Number of Gates, Kraus rank, dimension^2, dimension^2)
|
|
192
|
+
in standard basis
|
|
193
|
+
Estd : numpy array
|
|
194
|
+
POVM matrix of shape (#POVM elements, dimension^2) in standard basis
|
|
195
|
+
rhostd : numpy array
|
|
196
|
+
Initial state vector of shape (dimension^2) in standard
|
|
197
|
+
"""
|
|
198
|
+
Xstd = np.array([np.array(change_basis(X[i], "pp", "std")) for i in range(X.shape[0])])
|
|
199
|
+
Estd = np.array([np.array(change_basis(E[i], "pp", "std")) for i in range(E.shape[0])])
|
|
200
|
+
return (
|
|
201
|
+
Xstd.astype(np.complex128),
|
|
202
|
+
Estd.astype(np.complex128),
|
|
203
|
+
change_basis(rho, "pp", "std").astype(np.complex128),
|
|
204
|
+
)
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
def pygstiExp_to_list(model, max_germ_len):
|
|
208
|
+
"""Takes the sequences of a pyGSTi model and turns them into a sequence list for mGST.
|
|
209
|
+
|
|
210
|
+
Parameters
|
|
211
|
+
----------
|
|
212
|
+
model : pygsti ExplicitOpModel object
|
|
213
|
+
The model containing the gate set parameters in the Pauli transfer matrix formalism.
|
|
214
|
+
max_germ_len : int
|
|
215
|
+
The maximum number of germ repetitions in the pyGSTi circuit design.
|
|
216
|
+
|
|
217
|
+
Returns
|
|
218
|
+
-------
|
|
219
|
+
J_GST : numpy array, shape (num_experiments, max_sequence_length)
|
|
220
|
+
A 2D array where each row contains the gate indices of a gate sequence. Each gate index
|
|
221
|
+
corresponds to a specific gate in the model's target gate set.
|
|
222
|
+
"""
|
|
223
|
+
prep_fiducials = model.prep_fiducials()
|
|
224
|
+
meas_fiducials = model.meas_fiducials()
|
|
225
|
+
germs = model.germs()
|
|
226
|
+
maxLengths = [max_germ_len]
|
|
227
|
+
listOfExperiments = create_lsgst_circuits(model.target_model(), prep_fiducials, meas_fiducials, germs, maxLengths)
|
|
228
|
+
op_Labels = list(model.target_model().__dict__["operations"].keys())
|
|
229
|
+
exp_list = []
|
|
230
|
+
max_length = max((len(x.to_pythonstr(op_Labels)) for x in listOfExperiments))
|
|
231
|
+
for i, exp_current in enumerate(listOfExperiments):
|
|
232
|
+
exp = exp_current.to_pythonstr(op_Labels)
|
|
233
|
+
gate_numbers = [ord(x) - 97 for x in exp.lower()]
|
|
234
|
+
gate_numbers = np.pad(gate_numbers, (0, max_length - len(gate_numbers)), "constant", constant_values=-1)
|
|
235
|
+
exp_list.append(gate_numbers)
|
|
236
|
+
|
|
237
|
+
J_GST = np.array([[int(exp_list[i][j]) for j in range(max_length)] for i in range(len(exp_list))])
|
|
238
|
+
return J_GST
|