iqm-benchmarks 2.43__py3-none-any.whl → 2.45__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/benchmark_definition.py +1 -0
- iqm/benchmarks/compressive_gst/compressive_gst.py +100 -46
- iqm/benchmarks/compressive_gst/gst_analysis.py +480 -381
- iqm/benchmarks/entanglement/ghz.py +5 -5
- iqm/benchmarks/entanglement/graph_states.py +21 -21
- iqm/benchmarks/optimization/qscore.py +2 -2
- iqm/benchmarks/quantum_volume/clops.py +2 -3
- iqm/benchmarks/randomized_benchmarking/eplg/eplg.py +23 -24
- iqm/benchmarks/utils.py +72 -8
- iqm/benchmarks/utils_plots.py +309 -65
- {iqm_benchmarks-2.43.dist-info → iqm_benchmarks-2.45.dist-info}/METADATA +2 -2
- {iqm_benchmarks-2.43.dist-info → iqm_benchmarks-2.45.dist-info}/RECORD +22 -22
- mGST/additional_fns.py +35 -20
- mGST/algorithm.py +73 -57
- mGST/low_level_jit.py +122 -56
- mGST/optimization.py +12 -6
- mGST/qiskit_interface.py +64 -87
- mGST/reporting/figure_gen.py +390 -57
- mGST/reporting/reporting.py +209 -11
- {iqm_benchmarks-2.43.dist-info → iqm_benchmarks-2.45.dist-info}/WHEEL +0 -0
- {iqm_benchmarks-2.43.dist-info → iqm_benchmarks-2.45.dist-info}/licenses/LICENSE +0 -0
- {iqm_benchmarks-2.43.dist-info → iqm_benchmarks-2.45.dist-info}/top_level.txt +0 -0
|
@@ -96,7 +96,7 @@ def fidelity_ghz_randomized_measurements(
|
|
|
96
96
|
p_sum = []
|
|
97
97
|
for sb in c_id_keys:
|
|
98
98
|
for sa in c_keys:
|
|
99
|
-
exponent = hamming(list(sa), list(sb)) * num_qubits
|
|
99
|
+
exponent = hamming(np.array(list(sa)), np.array(list(sb))) * num_qubits
|
|
100
100
|
p_sum.append(np.power(-2, -exponent) * probabilities_sample[sa] * ideal_probabilities[u][sb])
|
|
101
101
|
fid_rm.append((2**num_qubits) * sum(p_sum))
|
|
102
102
|
values = {"fidelity": np.mean(fid_rm)}
|
|
@@ -117,7 +117,7 @@ def fidelity_ghz_randomized_measurements(
|
|
|
117
117
|
p_sum = []
|
|
118
118
|
for sb in c_id_keys:
|
|
119
119
|
for sa in c_keys:
|
|
120
|
-
exponent = hamming(list(sa), list(sb)) * num_qubits
|
|
120
|
+
exponent = hamming(np.array(list(sa)), np.array(list(sb))) * num_qubits
|
|
121
121
|
p_sum.append(np.power(-2, -exponent) * probabilities_sample[sa] * ideal_probabilities[u][sb])
|
|
122
122
|
fid_rm_rem.append((2**num_qubits) * sum(p_sum))
|
|
123
123
|
values = values | {"fidelity_rem": np.mean(fid_rm_rem)}
|
|
@@ -145,7 +145,6 @@ def fidelity_ghz_coherences(dataset: xr.Dataset, qubit_layout: List[int], circui
|
|
|
145
145
|
phases = [np.pi * i / (num_qubits + 1) for i in range(2 * num_qubits + 2)]
|
|
146
146
|
idx = BenchmarkObservationIdentifier(qubit_layout).string_identifier
|
|
147
147
|
transpiled_circuits = circuits["transpiled_circuits"]
|
|
148
|
-
num_shots = dataset.attrs["shots"]
|
|
149
148
|
num_circuits = len(transpiled_circuits[f"{qubit_layout}_native_ghz"].circuits)
|
|
150
149
|
|
|
151
150
|
# Computing the phase acquired by the |11...1> component for each interval
|
|
@@ -155,8 +154,9 @@ def fidelity_ghz_coherences(dataset: xr.Dataset, qubit_layout: List[int], circui
|
|
|
155
154
|
counts = xrvariable_to_counts(dataset, f"{idx}", num_circuits)
|
|
156
155
|
all_zero_probability_list = [] # An ordered list for storing the probabilities of returning to the |00..0> state
|
|
157
156
|
for count in counts[1:]:
|
|
157
|
+
normalization = np.sum(list(count.values()))
|
|
158
158
|
if "0" * num_qubits in count.keys():
|
|
159
|
-
probability = count["0" * num_qubits] /
|
|
159
|
+
probability = count["0" * num_qubits] / normalization
|
|
160
160
|
else:
|
|
161
161
|
probability = 0
|
|
162
162
|
all_zero_probability_list.append(probability)
|
|
@@ -165,7 +165,7 @@ def fidelity_ghz_coherences(dataset: xr.Dataset, qubit_layout: List[int], circui
|
|
|
165
165
|
i_n = np.abs(np.dot(complex_coefficients, np.array(all_zero_probability_list))) / (len(phases))
|
|
166
166
|
|
|
167
167
|
# Extracting the probabilities of the 00...0 and 11...1 bit strings
|
|
168
|
-
probs_direct = {label: count /
|
|
168
|
+
probs_direct = {label: count / np.sum(list(counts[0].values())) for label, count in counts[0].items()}
|
|
169
169
|
|
|
170
170
|
# Computing GHZ state fidelity from i_n and the probabilities according to the method in [Mooney, 2021]
|
|
171
171
|
p0 = probs_direct["0" * num_qubits] if "0" * num_qubits in probs_direct.keys() else 0
|
|
@@ -439,34 +439,29 @@ def plot_max_negativities_graph(
|
|
|
439
439
|
fig = plt.figure()
|
|
440
440
|
ax = plt.axes()
|
|
441
441
|
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
else:
|
|
446
|
-
graph_backend = backend_coupling_map.graph.to_undirected(multigraph=False)
|
|
447
|
-
qubit_positions = GraphPositions.create_positions(graph_backend)
|
|
448
|
-
else:
|
|
449
|
-
graph_backend = backend_coupling_map.graph.to_undirected(multigraph=False)
|
|
450
|
-
if num_qubits in (20, 7):
|
|
451
|
-
station = "garnet" if num_qubits == 20 else "deneb"
|
|
452
|
-
qubit_positions = GraphPositions.predefined_stations[station]
|
|
453
|
-
else:
|
|
454
|
-
qubit_positions = GraphPositions.create_positions(graph_backend)
|
|
442
|
+
qubit_positions = GraphPositions.get_positions(
|
|
443
|
+
station=station, graph=backend_coupling_map.graph.to_undirected(multigraph=False), num_qubits=num_qubits
|
|
444
|
+
)
|
|
455
445
|
|
|
456
446
|
# Normalize negativity values to the range [0, 1] for color mapping
|
|
457
447
|
norm = plt.Normalize(vmin=cast(float, min(negativity_values)), vmax=cast(float, max(negativity_values)))
|
|
458
|
-
edge_colors = [
|
|
448
|
+
edge_colors = [
|
|
449
|
+
cmap(norm(negativity_edges[edge])) if edge in qubit_pairs else "lightgray" for edge in backend_coupling_map
|
|
450
|
+
] #
|
|
451
|
+
nodes = list(set(v for edge in backend_coupling_map for v in edge))
|
|
452
|
+
active_nodes = list(set(v for edge in qubit_pairs for v in edge))
|
|
453
|
+
node_colors = ["lightgray" if v not in active_nodes else "k" for v in nodes]
|
|
459
454
|
|
|
460
455
|
nx.draw_networkx(
|
|
461
456
|
rx_to_nx_graph(backend_coupling_map),
|
|
462
457
|
pos=qubit_positions,
|
|
463
|
-
nodelist=
|
|
464
|
-
|
|
458
|
+
nodelist=nodes,
|
|
459
|
+
edgelist=list(backend_coupling_map),
|
|
460
|
+
labels={x: qubit_names[x] for x in nodes},
|
|
465
461
|
font_size=6.5,
|
|
466
|
-
edgelist=qubit_pairs,
|
|
467
462
|
width=4.0,
|
|
468
463
|
edge_color=edge_colors,
|
|
469
|
-
node_color=
|
|
464
|
+
node_color=node_colors,
|
|
470
465
|
font_color="w",
|
|
471
466
|
ax=ax,
|
|
472
467
|
)
|
|
@@ -490,6 +485,8 @@ def plot_max_negativities_graph(
|
|
|
490
485
|
f"{shots_string}; Bootstraps: {num_bootstraps}"
|
|
491
486
|
f"\n{timestamp}"
|
|
492
487
|
)
|
|
488
|
+
# Invert y-axis to match the intended qubit positions
|
|
489
|
+
plt.gca().invert_yaxis()
|
|
493
490
|
plt.close()
|
|
494
491
|
|
|
495
492
|
return fig_name, fig
|
|
@@ -955,7 +952,7 @@ def negativity_analysis(run: BenchmarkRunResult) -> BenchmarkAnalysisResult:
|
|
|
955
952
|
dataset = run.dataset.copy(deep=True)
|
|
956
953
|
qcvv_logger.info("Dataset imported OK")
|
|
957
954
|
backend_name = dataset.attrs["backend_name"]
|
|
958
|
-
|
|
955
|
+
coupling_map_full = dataset.attrs["coupling_map_full"]
|
|
959
956
|
qubit_names = dataset.attrs["qubit_names"]
|
|
960
957
|
execution_timestamp = dataset.attrs["execution_timestamp"]
|
|
961
958
|
tomography = dataset.attrs["tomography"]
|
|
@@ -1004,7 +1001,7 @@ def negativity_analysis(run: BenchmarkRunResult) -> BenchmarkAnalysisResult:
|
|
|
1004
1001
|
|
|
1005
1002
|
fig_name, fig = plot_max_negativities_graph(
|
|
1006
1003
|
negativities=max_negativities,
|
|
1007
|
-
backend_coupling_map=
|
|
1004
|
+
backend_coupling_map=coupling_map_full,
|
|
1008
1005
|
qubit_names=qubit_names,
|
|
1009
1006
|
timestamp=execution_timestamp,
|
|
1010
1007
|
tomography=tomography,
|
|
@@ -1066,8 +1063,11 @@ class GraphStateBenchmark(Benchmark):
|
|
|
1066
1063
|
dataset.attrs["execution_timestamp"] = self.execution_timestamp
|
|
1067
1064
|
dataset.attrs["backend_configuration_name"] = self.backend_configuration_name
|
|
1068
1065
|
dataset.attrs["backend_name"] = self.backend.name
|
|
1069
|
-
dataset.attrs["qubit_names"] = {
|
|
1066
|
+
dataset.attrs["qubit_names"] = {
|
|
1067
|
+
qubit: self.backend.index_to_qubit_name(qubit) for qubit in np.arange(self.backend.num_qubits)
|
|
1068
|
+
}
|
|
1070
1069
|
dataset.attrs["coupling_map"] = self.coupling_map
|
|
1070
|
+
dataset.attrs["coupling_map_full"] = self.backend.coupling_map
|
|
1071
1071
|
|
|
1072
1072
|
for key, value in self.configuration:
|
|
1073
1073
|
if key == "benchmark": # Avoid saving the class object
|
|
@@ -83,9 +83,9 @@ def calculate_optimal_angles_for_QAOA_p1(graph: Graph) -> List[float]:
|
|
|
83
83
|
x_init = [0.15, -0.28]
|
|
84
84
|
|
|
85
85
|
minimizer_kwargs = {"method": "L-BFGS-B", "bounds": bounds}
|
|
86
|
-
res = basinhopping(get_expected_zz_edgedensity, x_init, minimizer_kwargs=minimizer_kwargs, niter=10, T=2)
|
|
86
|
+
res = basinhopping(get_expected_zz_edgedensity, x_init, minimizer_kwargs=minimizer_kwargs, niter=10, T=2) # type: ignore
|
|
87
87
|
|
|
88
|
-
return res.x
|
|
88
|
+
return list(res.x)
|
|
89
89
|
|
|
90
90
|
|
|
91
91
|
def cut_cost_function(x: str, graph: Graph) -> int:
|
|
@@ -21,7 +21,6 @@ from math import floor, pi
|
|
|
21
21
|
from time import perf_counter, strftime
|
|
22
22
|
from typing import Any, Dict, List, Sequence, Tuple, Type
|
|
23
23
|
|
|
24
|
-
import matplotlib as mpl
|
|
25
24
|
from matplotlib.figure import Figure
|
|
26
25
|
import matplotlib.pyplot as plt
|
|
27
26
|
import numpy as np
|
|
@@ -178,8 +177,8 @@ def retrieve_clops_elapsed_times(job_meta: Dict[str, Dict[str, Any]]) -> Dict[st
|
|
|
178
177
|
# submit_i = datetime.strptime(x["submit_start"], job_time_format)
|
|
179
178
|
execution_f = datetime.strptime(x["execution_end"], job_time_format)
|
|
180
179
|
execution_i = datetime.strptime(x["execution_start"], job_time_format)
|
|
181
|
-
job_f = datetime.strptime(x["
|
|
182
|
-
job_i = datetime.strptime(x["
|
|
180
|
+
job_f = datetime.strptime(x["ready"], job_time_format)
|
|
181
|
+
job_i = datetime.strptime(x["received"], job_time_format)
|
|
183
182
|
|
|
184
183
|
all_job_elapsed[update][batch] = {
|
|
185
184
|
"job_total": job_f - job_i,
|
|
@@ -5,6 +5,7 @@ Error Per Layered Gate (EPLG).
|
|
|
5
5
|
from time import strftime
|
|
6
6
|
from typing import Dict, Optional, Sequence, Tuple, Type, cast
|
|
7
7
|
|
|
8
|
+
from matplotlib.colors import to_rgba
|
|
8
9
|
from matplotlib.figure import Figure
|
|
9
10
|
import matplotlib.pyplot as plt
|
|
10
11
|
import networkx as nx
|
|
@@ -76,38 +77,35 @@ def plot_layered_fidelities_graph(
|
|
|
76
77
|
fig = plt.figure()
|
|
77
78
|
ax = plt.axes()
|
|
78
79
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
else:
|
|
83
|
-
if num_qubits in (20, 7):
|
|
84
|
-
station = "garnet" if num_qubits == 20 else "deneb"
|
|
85
|
-
qubit_positions = GraphPositions.predefined_stations[station]
|
|
86
|
-
else:
|
|
87
|
-
graph_backend = backend_coupling_map.graph.to_undirected(multigraph=False)
|
|
88
|
-
qubit_positions = GraphPositions.create_positions(graph_backend)
|
|
89
|
-
else:
|
|
90
|
-
graph_backend = backend_coupling_map.graph.to_undirected(multigraph=False)
|
|
91
|
-
if num_qubits in (20, 7):
|
|
92
|
-
station = "garnet" if num_qubits == 20 else "deneb"
|
|
93
|
-
qubit_positions = GraphPositions.predefined_stations[station]
|
|
94
|
-
else:
|
|
95
|
-
qubit_positions = GraphPositions.create_positions(graph_backend)
|
|
80
|
+
qubit_positions = GraphPositions.get_positions(
|
|
81
|
+
station=station, graph=backend_coupling_map.graph.to_undirected(multigraph=False), num_qubits=num_qubits
|
|
82
|
+
)
|
|
96
83
|
|
|
97
84
|
# Normalize fidelity values to the range [0, 1] for color mapping
|
|
98
85
|
norm = plt.Normalize(vmin=cast(float, min(fidelity_values)), vmax=cast(float, max(fidelity_values)))
|
|
99
|
-
edge_colors = [
|
|
86
|
+
edge_colors = []
|
|
87
|
+
for edge in backend_coupling_map:
|
|
88
|
+
if edge in fidelity_edges:
|
|
89
|
+
edge_colors.append(cmap(norm(fidelity_edges[edge])))
|
|
90
|
+
elif (edge[1], edge[0]) in fidelity_edges:
|
|
91
|
+
edge_colors.append(cmap(norm(fidelity_edges[(edge[1], edge[0])])))
|
|
92
|
+
else:
|
|
93
|
+
edge_colors.append(to_rgba("lightgray"))
|
|
94
|
+
|
|
95
|
+
nodes = list(set(v for edge in backend_coupling_map for v in edge))
|
|
96
|
+
active_nodes = list(set(v for edge in qubit_pairs for v in edge))
|
|
97
|
+
node_colors = ["lightgray" if v not in active_nodes else "k" for v in nodes]
|
|
100
98
|
|
|
101
99
|
nx.draw_networkx(
|
|
102
100
|
rx_to_nx_graph(backend_coupling_map),
|
|
103
101
|
pos=qubit_positions,
|
|
104
|
-
nodelist=
|
|
105
|
-
|
|
102
|
+
nodelist=nodes,
|
|
103
|
+
edgelist=list(backend_coupling_map),
|
|
104
|
+
labels={x: qubit_names[x] for x in nodes},
|
|
106
105
|
font_size=6.5,
|
|
107
|
-
edgelist=qubit_pairs,
|
|
108
106
|
width=4.0,
|
|
109
107
|
edge_color=edge_colors,
|
|
110
|
-
node_color=
|
|
108
|
+
node_color=node_colors,
|
|
111
109
|
font_color="w",
|
|
112
110
|
ax=ax,
|
|
113
111
|
)
|
|
@@ -116,7 +114,7 @@ def plot_layered_fidelities_graph(
|
|
|
116
114
|
sm = plt.cm.ScalarMappable(cmap=cmap, norm=norm)
|
|
117
115
|
sm.set_array([])
|
|
118
116
|
cbar = fig.colorbar(sm, ax=ax, shrink=0.5, label="Layered Fidelity (%)", format="%.2f")
|
|
119
|
-
cbar.set_ticks(np.linspace(min(fidelity_values), max(fidelity_values), 5, endpoint=True))
|
|
117
|
+
cbar.set_ticks(tuple(np.linspace(min(fidelity_values), max(fidelity_values), 5, endpoint=True)))
|
|
120
118
|
|
|
121
119
|
station_string = "IQM Backend" if station is None else station.capitalize()
|
|
122
120
|
|
|
@@ -124,6 +122,7 @@ def plot_layered_fidelities_graph(
|
|
|
124
122
|
f"EPLG estimate: {eplg_estimate['value']:.2e} +/- {eplg_estimate['uncertainty']:.2e}\n" if eplg_estimate else ""
|
|
125
123
|
)
|
|
126
124
|
plt.title(f"Layered fidelities for qubit pairs in {station_string}\n" f"{eplg_string}{timestamp}")
|
|
125
|
+
plt.gca().invert_yaxis()
|
|
127
126
|
plt.close()
|
|
128
127
|
|
|
129
128
|
return fig_name, fig
|
|
@@ -190,8 +189,8 @@ def eplg_analysis(run: BenchmarkRunResult) -> BenchmarkAnalysisResult:
|
|
|
190
189
|
backend_num_qubits=backend_num_qubits,
|
|
191
190
|
edge_list=edges,
|
|
192
191
|
timestamp=timestamp,
|
|
193
|
-
disjoint_layers=disjoint_layers,
|
|
194
192
|
station=backend_configuration_name,
|
|
193
|
+
disjoint_layers=disjoint_layers,
|
|
195
194
|
qubit_names=qubit_names,
|
|
196
195
|
is_eplg=True,
|
|
197
196
|
)
|
iqm/benchmarks/utils.py
CHANGED
|
@@ -48,6 +48,9 @@ from iqm.qiskit_iqm.iqm_job import IQMJob
|
|
|
48
48
|
from iqm.qiskit_iqm.iqm_provider import IQMProvider
|
|
49
49
|
|
|
50
50
|
|
|
51
|
+
# pylint: disable=too-many-lines
|
|
52
|
+
|
|
53
|
+
|
|
51
54
|
def timeit(f):
|
|
52
55
|
"""Calculates the amount of time a function takes to execute.
|
|
53
56
|
|
|
@@ -283,12 +286,18 @@ def get_active_qubits(qc: QuantumCircuit) -> List[int]:
|
|
|
283
286
|
return list(active_qubits)
|
|
284
287
|
|
|
285
288
|
|
|
286
|
-
def extract_fidelities(cal_url: str) ->
|
|
289
|
+
def extract_fidelities(cal_url: str, all_metrics: bool = False) -> Union[
|
|
290
|
+
Tuple[List[List[int]], List[float], str, Dict[int, int]],
|
|
291
|
+
Tuple[List[List[int]], List[float], str, Dict[int, int], Dict[str, Dict[Union[int, Tuple[int, int]], float]]],
|
|
292
|
+
]:
|
|
287
293
|
"""Returns couplings and CZ-fidelities from calibration data URL
|
|
288
294
|
|
|
289
295
|
Args:
|
|
290
296
|
cal_url: str
|
|
291
297
|
The url under which the calibration data for the backend can be found
|
|
298
|
+
all_metrics: bool
|
|
299
|
+
If True, returns a dictionary with all metrics from the calibration data
|
|
300
|
+
Default is False
|
|
292
301
|
Returns:
|
|
293
302
|
list_couplings: List[List[int]]
|
|
294
303
|
A list of pairs, each of which is a qubit coupling for which the calibration
|
|
@@ -297,6 +306,13 @@ def extract_fidelities(cal_url: str) -> tuple[list[list[int]], list[float], str]
|
|
|
297
306
|
A list of CZ fidelities from the calibration url, ordered in the same way as list_couplings
|
|
298
307
|
topology: str
|
|
299
308
|
Name of the chip topology layout, currently either "star" or "crystal"
|
|
309
|
+
qubit_mapping: Dict[int, int]
|
|
310
|
+
Enumerating all calibrated qubits starting from 0. For instance if on a 5 qubit chip the qubits 2, 3 are calibrated,
|
|
311
|
+
the mapping will be {2: 0, 3: 1}.
|
|
312
|
+
metrics_dict: Dict
|
|
313
|
+
Dictionary of all metrics (returned only if all_metrics=True)
|
|
314
|
+
Format: {metric_name: {qubit: value}} for single qubit metrics
|
|
315
|
+
Format: {metric_name: {(qubit_1, qubit_2): value}} for two qubit metrics
|
|
300
316
|
"""
|
|
301
317
|
headers = {"Accept": "application/json", "Authorization": "Bearer " + os.environ["IQM_TOKEN"]}
|
|
302
318
|
r = requests.get(cal_url, headers=headers, timeout=60)
|
|
@@ -304,6 +320,7 @@ def extract_fidelities(cal_url: str) -> tuple[list[list[int]], list[float], str]
|
|
|
304
320
|
cal_keys = {
|
|
305
321
|
el2["key"]: (i, j) for i, el1 in enumerate(calibration["calibrations"]) for j, el2 in enumerate(el1["metrics"])
|
|
306
322
|
}
|
|
323
|
+
resonator_names = ["COMPR", "COMP_R", "MPR1", "MPR_1"]
|
|
307
324
|
list_couplings = []
|
|
308
325
|
list_fids = []
|
|
309
326
|
if "double_move_gate_fidelity" in cal_keys.keys():
|
|
@@ -313,18 +330,65 @@ def extract_fidelities(cal_url: str) -> tuple[list[list[int]], list[float], str]
|
|
|
313
330
|
i, j = cal_keys["cz_gate_fidelity"]
|
|
314
331
|
topology = "crystal"
|
|
315
332
|
for item in calibration["calibrations"][i]["metrics"][j]["metrics"]:
|
|
316
|
-
qb1 =
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
333
|
+
qb1 = (
|
|
334
|
+
int(item["locus"][0][2:])
|
|
335
|
+
if not any(resonator in item["locus"][0] for resonator in resonator_names)
|
|
336
|
+
else 0
|
|
337
|
+
)
|
|
338
|
+
qb2 = (
|
|
339
|
+
int(item["locus"][1][2:])
|
|
340
|
+
if not any(resonator in item["locus"][1] for resonator in resonator_names)
|
|
341
|
+
else 0
|
|
342
|
+
)
|
|
343
|
+
list_couplings.append([qb1, qb2])
|
|
322
344
|
list_fids.append(float(item["value"]))
|
|
323
345
|
calibrated_qubits = set(np.array(list_couplings).reshape(-1))
|
|
346
|
+
|
|
347
|
+
# Process all metrics if all_metrics is True
|
|
348
|
+
metrics_dict: Dict[str, Dict[Union[int, Tuple[int, int]], float]] = {}
|
|
349
|
+
for metric_key, (i, j) in cal_keys.items():
|
|
350
|
+
metric_data = calibration["calibrations"][i]["metrics"][j]["metrics"]
|
|
351
|
+
metrics_dict[metric_key] = {}
|
|
352
|
+
|
|
353
|
+
for item in metric_data:
|
|
354
|
+
# Determine if it's a single or two-qubit metric
|
|
355
|
+
if "component" in item:
|
|
356
|
+
# Single qubit metric
|
|
357
|
+
component = item["component"]
|
|
358
|
+
if not any(resonator in component for resonator in resonator_names):
|
|
359
|
+
qb = int(component[2:])
|
|
360
|
+
metrics_dict[metric_key][qb] = float(item["value"])
|
|
361
|
+
calibrated_qubits.add(qb) # Add qubits that have a single qubit metric
|
|
362
|
+
if "locus" in item and len(item["locus"]) == 2:
|
|
363
|
+
# Two qubit metric
|
|
364
|
+
locus = item["locus"]
|
|
365
|
+
if not (any(resonator in locus[0] for resonator in resonator_names) or any(resonator in locus[1] for resonator in resonator_names)):
|
|
366
|
+
qb1 = int(locus[0][2:])
|
|
367
|
+
qb2 = int(locus[1][2:])
|
|
368
|
+
metrics_dict[metric_key][(qb1, qb2)] = float(item["value"])
|
|
369
|
+
|
|
370
|
+
# Enumerate all calibrated qubits starting from 0
|
|
324
371
|
qubit_mapping = {qubit: idx for idx, qubit in enumerate(calibrated_qubits)}
|
|
325
372
|
list_couplings = [[qubit_mapping[edge[0]], qubit_mapping[edge[1]]] for edge in list_couplings]
|
|
326
373
|
|
|
327
|
-
|
|
374
|
+
# Apply the qubit mapping to metrics_dict
|
|
375
|
+
remapped_metrics_dict = {}
|
|
376
|
+
for metric_key, metric_values in metrics_dict.items():
|
|
377
|
+
remapped_metrics_dict[metric_key] = {}
|
|
378
|
+
for key, value in metric_values.items():
|
|
379
|
+
if isinstance(key, tuple):
|
|
380
|
+
# Two-qubit metric
|
|
381
|
+
remapped_metrics_dict[metric_key][(qubit_mapping[key[0]], qubit_mapping[key[1]])] = value
|
|
382
|
+
else:
|
|
383
|
+
# Single-qubit metric
|
|
384
|
+
remapped_metrics_dict[metric_key][qubit_mapping[key]] = value
|
|
385
|
+
metrics_dict = remapped_metrics_dict
|
|
386
|
+
|
|
387
|
+
# If all_metrics is False, only return everything related to CZ fidelites
|
|
388
|
+
if not all_metrics:
|
|
389
|
+
return list_couplings, list_fids, topology, qubit_mapping
|
|
390
|
+
|
|
391
|
+
return list_couplings, list_fids, topology, qubit_mapping, metrics_dict
|
|
328
392
|
|
|
329
393
|
|
|
330
394
|
# pylint: disable=too-many-branches
|