cirq-core 1.3.0.dev20231201141002__py3-none-any.whl → 1.4.0__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.
- cirq/__init__.py +4 -0
- cirq/_compat.py +9 -11
- cirq/_compat_test.py +45 -56
- cirq/_version.py +31 -1
- cirq/_version_test.py +1 -1
- cirq/circuits/circuit.py +13 -8
- cirq/circuits/circuit_operation.py +2 -1
- cirq/circuits/circuit_test.py +2 -2
- cirq/circuits/frozen_circuit.py +3 -2
- cirq/circuits/moment.py +12 -10
- cirq/circuits/qasm_output.py +5 -1
- cirq/circuits/qasm_output_test.py +25 -10
- cirq/contrib/qcircuit/qcircuit_diagram_info.py +9 -7
- cirq/contrib/quimb/mps_simulator_test.py +1 -1
- cirq/contrib/quimb/state_vector.py +9 -2
- cirq/contrib/svg/svg.py +2 -1
- cirq/contrib/svg/svg_test.py +1 -0
- cirq/devices/grid_qubit.py +85 -32
- cirq/devices/grid_qubit_test.py +22 -4
- cirq/devices/line_qubit.py +74 -26
- cirq/devices/line_qubit_test.py +19 -0
- cirq/devices/noise_utils.py +33 -31
- cirq/devices/noise_utils_test.py +1 -84
- cirq/devices/superconducting_qubits_noise_properties.py +7 -6
- cirq/experiments/__init__.py +8 -0
- cirq/experiments/qubit_characterizations.py +288 -44
- cirq/experiments/qubit_characterizations_test.py +61 -7
- cirq/experiments/random_quantum_circuit_generation.py +1 -1
- cirq/experiments/single_qubit_readout_calibration.py +132 -6
- cirq/experiments/single_qubit_readout_calibration_test.py +3 -1
- cirq/experiments/t1_decay_experiment.py +14 -7
- cirq/experiments/t1_decay_experiment_test.py +14 -26
- cirq/experiments/two_qubit_xeb.py +483 -0
- cirq/experiments/two_qubit_xeb_test.py +304 -0
- cirq/json_resolver_cache.py +2 -0
- cirq/linalg/decompositions.py +11 -13
- cirq/linalg/decompositions_test.py +1 -3
- cirq/linalg/diagonalize.py +5 -4
- cirq/linalg/predicates.py +8 -6
- cirq/linalg/transformations.py +2 -1
- cirq/linalg/transformations_test.py +1 -1
- cirq/ops/__init__.py +2 -0
- cirq/ops/clifford_gate.py +59 -16
- cirq/ops/common_gates_test.py +1 -2
- cirq/ops/control_values.py +4 -3
- cirq/ops/controlled_gate_test.py +1 -3
- cirq/ops/gate_operation.py +10 -1
- cirq/ops/named_qubit.py +74 -28
- cirq/ops/named_qubit_test.py +19 -0
- cirq/ops/parity_gates.py +5 -0
- cirq/ops/parity_gates_test.py +2 -10
- cirq/ops/pauli_gates.py +5 -2
- cirq/ops/pauli_string.py +2 -2
- cirq/ops/permutation_gate.py +16 -18
- cirq/ops/phased_iswap_gate_test.py +1 -3
- cirq/ops/phased_x_gate.py +1 -1
- cirq/ops/phased_x_z_gate.py +17 -1
- cirq/ops/phased_x_z_gate_test.py +24 -0
- cirq/ops/qid_util.py +4 -8
- cirq/ops/qubit_manager.py +7 -4
- cirq/ops/qubit_manager_test.py +20 -0
- cirq/ops/raw_types.py +5 -2
- cirq/ops/raw_types_test.py +14 -15
- cirq/ops/uniform_superposition_gate.py +123 -0
- cirq/ops/uniform_superposition_gate_test.py +94 -0
- cirq/protocols/approximate_equality_protocol_test.py +2 -2
- cirq/protocols/circuit_diagram_info_protocol.py +6 -4
- cirq/protocols/commutes_protocol.py +2 -4
- cirq/protocols/decompose_protocol.py +7 -12
- cirq/protocols/decompose_protocol_test.py +7 -3
- cirq/protocols/has_stabilizer_effect_protocol.py +1 -5
- cirq/protocols/has_stabilizer_effect_protocol_test.py +13 -4
- cirq/protocols/json_serialization.py +51 -181
- cirq/protocols/json_serialization_test.py +13 -47
- cirq/protocols/json_test_data/CircuitOperation.json +131 -148
- cirq/protocols/json_test_data/CircuitOperation.json_inward +55 -0
- cirq/protocols/json_test_data/CircuitOperation.repr_inward +6 -0
- cirq/protocols/json_test_data/FrozenCircuit.json +196 -210
- cirq/protocols/json_test_data/FrozenCircuit.json_inward +35 -0
- cirq/protocols/json_test_data/FrozenCircuit.repr_inward +4 -0
- cirq/protocols/json_test_data/UniformSuperpositionGate.json +5 -0
- cirq/protocols/json_test_data/UniformSuperpositionGate.repr +1 -0
- cirq/protocols/json_test_data/cirq.MSGate.json +4 -0
- cirq/protocols/json_test_data/cirq.MSGate.repr +1 -0
- cirq/protocols/json_test_data/spec.py +2 -0
- cirq/protocols/pow_protocol_test.py +1 -3
- cirq/protocols/resolve_parameters.py +4 -2
- cirq/qis/__init__.py +10 -0
- cirq/qis/clifford_tableau.py +8 -2
- cirq/qis/noise_utils.py +123 -0
- cirq/qis/noise_utils_test.py +97 -0
- cirq/sim/classical_simulator.py +227 -87
- cirq/sim/classical_simulator_test.py +135 -0
- cirq/sim/clifford/clifford_simulator_test.py +4 -2
- cirq/sim/mux.py +5 -3
- cirq/sim/simulation_product_state.py +15 -10
- cirq/sim/simulation_state.py +1 -1
- cirq/sim/simulation_state_test.py +2 -2
- cirq/sim/simulator_base.py +3 -3
- cirq/sim/state_vector_simulation_state.py +4 -4
- cirq/sim/state_vector_simulator.py +17 -2
- cirq/study/__init__.py +1 -0
- cirq/study/result.py +14 -0
- cirq/study/result_test.py +6 -0
- cirq/study/sweeps.py +4 -2
- cirq/study/sweeps_test.py +8 -0
- cirq/testing/__init__.py +6 -1
- cirq/testing/_compat_test_data/__init__.py +3 -3
- cirq/testing/_compat_test_data/module_a/__init__.py +2 -2
- cirq/testing/circuit_compare.py +1 -1
- cirq/testing/consistent_qasm.py +6 -0
- cirq/testing/gate_features.py +10 -0
- cirq/testing/lin_alg_utils.py +5 -3
- cirq/transformers/__init__.py +15 -0
- cirq/transformers/analytical_decompositions/controlled_gate_decomposition.py +3 -1
- cirq/transformers/analytical_decompositions/two_qubit_to_cz.py +24 -0
- cirq/transformers/analytical_decompositions/two_qubit_to_cz_test.py +17 -0
- cirq/transformers/dynamical_decoupling.py +122 -0
- cirq/transformers/dynamical_decoupling_test.py +123 -0
- cirq/transformers/gauge_compiling/__init__.py +26 -0
- cirq/transformers/gauge_compiling/cz_gauge.py +46 -0
- cirq/transformers/gauge_compiling/cz_gauge_test.py +23 -0
- cirq/transformers/gauge_compiling/gauge_compiling.py +214 -0
- cirq/transformers/gauge_compiling/gauge_compiling_test.py +41 -0
- cirq/transformers/gauge_compiling/gauge_compiling_test_utils.py +83 -0
- cirq/transformers/gauge_compiling/gauge_compiling_test_utils_test.py +52 -0
- cirq/transformers/gauge_compiling/iswap_gauge.py +105 -0
- cirq/transformers/gauge_compiling/iswap_gauge_test.py +23 -0
- cirq/transformers/gauge_compiling/spin_inversion_gauge.py +33 -0
- cirq/transformers/gauge_compiling/spin_inversion_gauge_test.py +37 -0
- cirq/transformers/gauge_compiling/sqrt_cz_gauge.py +64 -0
- cirq/transformers/gauge_compiling/sqrt_cz_gauge_test.py +27 -0
- cirq/transformers/gauge_compiling/sqrt_iswap_gauge.py +94 -0
- cirq/transformers/gauge_compiling/sqrt_iswap_gauge_test.py +22 -0
- cirq/transformers/heuristic_decompositions/two_qubit_gate_tabulation.py +1 -0
- cirq/transformers/merge_k_qubit_gates_test.py +23 -23
- cirq/transformers/merge_single_qubit_gates_test.py +14 -14
- cirq/transformers/optimize_for_target_gateset.py +39 -17
- cirq/transformers/optimize_for_target_gateset_test.py +189 -39
- cirq/transformers/qubit_management_transformers.py +1 -1
- cirq/transformers/routing/visualize_routed_circuit_test.py +17 -17
- cirq/transformers/stratify_test.py +13 -13
- cirq/transformers/target_gatesets/compilation_target_gateset.py +26 -2
- cirq/transformers/target_gatesets/compilation_target_gateset_test.py +16 -16
- cirq/transformers/target_gatesets/cz_gateset.py +4 -0
- cirq/transformers/transformer_api.py +1 -2
- cirq/transformers/transformer_primitives.py +15 -14
- cirq/transformers/transformer_primitives_test.py +99 -72
- cirq/value/classical_data.py +6 -6
- cirq/value/value_equality_attr.py +4 -0
- cirq/work/sampler.py +3 -4
- cirq/work/sampler_test.py +25 -0
- {cirq_core-1.3.0.dev20231201141002.dist-info → cirq_core-1.4.0.dist-info}/METADATA +10 -19
- {cirq_core-1.3.0.dev20231201141002.dist-info → cirq_core-1.4.0.dist-info}/RECORD +157 -130
- {cirq_core-1.3.0.dev20231201141002.dist-info → cirq_core-1.4.0.dist-info}/WHEEL +1 -1
- {cirq_core-1.3.0.dev20231201141002.dist-info → cirq_core-1.4.0.dist-info}/LICENSE +0 -0
- {cirq_core-1.3.0.dev20231201141002.dist-info → cirq_core-1.4.0.dist-info}/top_level.txt +0 -0
|
@@ -18,6 +18,10 @@ from typing import Any, Dict, Iterable, List, Optional, TYPE_CHECKING
|
|
|
18
18
|
|
|
19
19
|
import sympy
|
|
20
20
|
import numpy as np
|
|
21
|
+
import matplotlib.pyplot as plt
|
|
22
|
+
import cirq.vis.heatmap as cirq_heatmap
|
|
23
|
+
import cirq.vis.histogram as cirq_histogram
|
|
24
|
+
from cirq.devices import grid_qubit
|
|
21
25
|
from cirq import circuits, ops, study
|
|
22
26
|
|
|
23
27
|
if TYPE_CHECKING:
|
|
@@ -51,6 +55,124 @@ class SingleQubitReadoutCalibrationResult:
|
|
|
51
55
|
'timestamp': self.timestamp,
|
|
52
56
|
}
|
|
53
57
|
|
|
58
|
+
def plot_heatmap(
|
|
59
|
+
self,
|
|
60
|
+
axs: Optional[tuple[plt.Axes, plt.Axes]] = None,
|
|
61
|
+
annotation_format: str = '0.1%',
|
|
62
|
+
**plot_kwargs: Any,
|
|
63
|
+
) -> tuple[plt.Axes, plt.Axes]:
|
|
64
|
+
"""Plot a heatmap of the readout errors. If qubits are not cirq.GridQubits, throws an error.
|
|
65
|
+
|
|
66
|
+
Args:
|
|
67
|
+
axs: a tuple of the plt.Axes to plot on. If not given, a new figure is created,
|
|
68
|
+
plotted on, and shown.
|
|
69
|
+
annotation_format: The format string for the numbers in the heatmap.
|
|
70
|
+
**plot_kwargs: Arguments to be passed to 'cirq.Heatmap.plot()'.
|
|
71
|
+
Returns:
|
|
72
|
+
The two plt.Axes containing the plot.
|
|
73
|
+
|
|
74
|
+
Raises:
|
|
75
|
+
ValueError: axs does not contain two plt.Axes
|
|
76
|
+
TypeError: qubits are not cirq.GridQubits
|
|
77
|
+
"""
|
|
78
|
+
|
|
79
|
+
if axs is None:
|
|
80
|
+
_, axs = plt.subplots(1, 2, dpi=200, facecolor='white', figsize=(12, 4))
|
|
81
|
+
|
|
82
|
+
else:
|
|
83
|
+
if (
|
|
84
|
+
not isinstance(axs, (tuple, list, np.ndarray))
|
|
85
|
+
or len(axs) != 2
|
|
86
|
+
or type(axs[0]) != plt.Axes
|
|
87
|
+
or type(axs[1]) != plt.Axes
|
|
88
|
+
): # pragma: no cover
|
|
89
|
+
raise ValueError('axs should be a length-2 tuple of plt.Axes') # pragma: no cover
|
|
90
|
+
for ax, title, data in zip(
|
|
91
|
+
axs,
|
|
92
|
+
['$|0\\rangle$ errors', '$|1\\rangle$ errors'],
|
|
93
|
+
[self.zero_state_errors, self.one_state_errors],
|
|
94
|
+
):
|
|
95
|
+
data_with_grid_qubit_keys = {}
|
|
96
|
+
for qubit in data:
|
|
97
|
+
if type(qubit) != grid_qubit.GridQubit:
|
|
98
|
+
raise TypeError(f'{qubit} must be of type cirq.GridQubit') # pragma: no cover
|
|
99
|
+
data_with_grid_qubit_keys[qubit] = data[qubit] # just for typecheck
|
|
100
|
+
_, _ = cirq_heatmap.Heatmap(data_with_grid_qubit_keys).plot(
|
|
101
|
+
ax, annotation_format=annotation_format, title=title, **plot_kwargs
|
|
102
|
+
)
|
|
103
|
+
return axs[0], axs[1]
|
|
104
|
+
|
|
105
|
+
def plot_integrated_histogram(
|
|
106
|
+
self,
|
|
107
|
+
ax: Optional[plt.Axes] = None,
|
|
108
|
+
cdf_on_x: bool = False,
|
|
109
|
+
axis_label: str = 'Readout error rate',
|
|
110
|
+
semilog: bool = True,
|
|
111
|
+
median_line: bool = True,
|
|
112
|
+
median_label: Optional[str] = 'median',
|
|
113
|
+
mean_line: bool = False,
|
|
114
|
+
mean_label: Optional[str] = 'mean',
|
|
115
|
+
show_zero: bool = False,
|
|
116
|
+
title: Optional[str] = None,
|
|
117
|
+
**kwargs,
|
|
118
|
+
) -> plt.Axes:
|
|
119
|
+
"""Plot the readout errors using cirq.integrated_histogram().
|
|
120
|
+
|
|
121
|
+
Args:
|
|
122
|
+
ax: The axis to plot on. If None, we generate one.
|
|
123
|
+
cdf_on_x: If True, flip the axes compared the above example.
|
|
124
|
+
axis_label: Label for x axis (y-axis if cdf_on_x is True).
|
|
125
|
+
semilog: If True, force the x-axis to be logarithmic.
|
|
126
|
+
median_line: If True, draw a vertical line on the median value.
|
|
127
|
+
median_label: If drawing median line, optional label for it.
|
|
128
|
+
mean_line: If True, draw a vertical line on the mean value.
|
|
129
|
+
mean_label: If drawing mean line, optional label for it.
|
|
130
|
+
title: Title of the plot. If None, we assign "N={len(data)}".
|
|
131
|
+
show_zero: If True, moves the step plot up by one unit by prepending 0
|
|
132
|
+
to the data.
|
|
133
|
+
**kwargs: Kwargs to forward to `ax.step()`. Some examples are
|
|
134
|
+
color: Color of the line.
|
|
135
|
+
linestyle: Linestyle to use for the plot.
|
|
136
|
+
lw: linewidth for integrated histogram.
|
|
137
|
+
ms: marker size for a histogram trace.
|
|
138
|
+
Returns:
|
|
139
|
+
The axis that was plotted on.
|
|
140
|
+
"""
|
|
141
|
+
|
|
142
|
+
ax = cirq_histogram.integrated_histogram(
|
|
143
|
+
data=self.zero_state_errors,
|
|
144
|
+
ax=ax,
|
|
145
|
+
cdf_on_x=cdf_on_x,
|
|
146
|
+
semilog=semilog,
|
|
147
|
+
median_line=median_line,
|
|
148
|
+
median_label=median_label,
|
|
149
|
+
mean_line=mean_line,
|
|
150
|
+
mean_label=mean_label,
|
|
151
|
+
show_zero=show_zero,
|
|
152
|
+
color='C0',
|
|
153
|
+
label='$|0\\rangle$ errors',
|
|
154
|
+
**kwargs,
|
|
155
|
+
)
|
|
156
|
+
ax = cirq_histogram.integrated_histogram(
|
|
157
|
+
data=self.one_state_errors,
|
|
158
|
+
ax=ax,
|
|
159
|
+
cdf_on_x=cdf_on_x,
|
|
160
|
+
axis_label=axis_label,
|
|
161
|
+
semilog=semilog,
|
|
162
|
+
median_line=median_line,
|
|
163
|
+
median_label=median_label,
|
|
164
|
+
mean_line=mean_line,
|
|
165
|
+
mean_label=mean_label,
|
|
166
|
+
show_zero=show_zero,
|
|
167
|
+
title=title,
|
|
168
|
+
color='C1',
|
|
169
|
+
label='$|1\\rangle$ errors',
|
|
170
|
+
**kwargs,
|
|
171
|
+
)
|
|
172
|
+
ax.legend(loc='best')
|
|
173
|
+
ax.set_ylabel('Percentile')
|
|
174
|
+
return ax
|
|
175
|
+
|
|
54
176
|
@classmethod
|
|
55
177
|
def _from_json_dict_(
|
|
56
178
|
cls, zero_state_errors, one_state_errors, repetitions, timestamp, **kwargs
|
|
@@ -221,15 +343,19 @@ def estimate_parallel_single_qubit_readout_errors(
|
|
|
221
343
|
trial_idx += 1
|
|
222
344
|
|
|
223
345
|
zero_state_errors = {
|
|
224
|
-
q:
|
|
225
|
-
|
|
226
|
-
|
|
346
|
+
q: (
|
|
347
|
+
zero_state_trials[0][qubit_idx] / zero_state_totals[0][qubit_idx]
|
|
348
|
+
if zero_state_totals[0][qubit_idx] > 0
|
|
349
|
+
else np.nan
|
|
350
|
+
)
|
|
227
351
|
for qubit_idx, q in enumerate(qubits)
|
|
228
352
|
}
|
|
229
353
|
one_state_errors = {
|
|
230
|
-
q:
|
|
231
|
-
|
|
232
|
-
|
|
354
|
+
q: (
|
|
355
|
+
one_state_trials[0][qubit_idx] / one_state_totals[0][qubit_idx]
|
|
356
|
+
if one_state_totals[0][qubit_idx] > 0
|
|
357
|
+
else np.nan
|
|
358
|
+
)
|
|
233
359
|
for qubit_idx, q in enumerate(qubits)
|
|
234
360
|
}
|
|
235
361
|
|
|
@@ -87,7 +87,7 @@ def test_estimate_single_qubit_readout_errors_with_noise():
|
|
|
87
87
|
|
|
88
88
|
|
|
89
89
|
def test_estimate_parallel_readout_errors_no_noise():
|
|
90
|
-
qubits = cirq.
|
|
90
|
+
qubits = [cirq.GridQubit(i, 0) for i in range(10)]
|
|
91
91
|
sampler = cirq.Simulator()
|
|
92
92
|
repetitions = 1000
|
|
93
93
|
result = cirq.estimate_parallel_single_qubit_readout_errors(
|
|
@@ -97,6 +97,8 @@ def test_estimate_parallel_readout_errors_no_noise():
|
|
|
97
97
|
assert result.one_state_errors == {q: 0 for q in qubits}
|
|
98
98
|
assert result.repetitions == repetitions
|
|
99
99
|
assert isinstance(result.timestamp, float)
|
|
100
|
+
_ = result.plot_integrated_histogram()
|
|
101
|
+
_, _ = result.plot_heatmap()
|
|
100
102
|
|
|
101
103
|
|
|
102
104
|
def test_estimate_parallel_readout_errors_all_zeros():
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
# See the License for the specific language governing permissions and
|
|
13
13
|
# limitations under the License.
|
|
14
14
|
|
|
15
|
-
from typing import Any, Optional, TYPE_CHECKING
|
|
15
|
+
from typing import Any, Optional, Sequence, TYPE_CHECKING, cast
|
|
16
16
|
|
|
17
17
|
import warnings
|
|
18
18
|
import pandas as pd
|
|
@@ -77,7 +77,12 @@ def t1_decay(
|
|
|
77
77
|
|
|
78
78
|
var = sympy.Symbol('delay_ns')
|
|
79
79
|
|
|
80
|
-
|
|
80
|
+
if min_delay_nanos == 0:
|
|
81
|
+
min_delay_nanos = 0.4
|
|
82
|
+
sweep_vals_ns = np.unique(
|
|
83
|
+
np.round(np.logspace(np.log10(min_delay_nanos), np.log10(max_delay_nanos), num_points))
|
|
84
|
+
)
|
|
85
|
+
sweep = study.Points(var, cast(Sequence[float], sweep_vals_ns))
|
|
81
86
|
|
|
82
87
|
circuit = circuits.Circuit(
|
|
83
88
|
ops.X(qubit), ops.wait(qubit, nanos=var), ops.measure(qubit, key='output')
|
|
@@ -118,8 +123,8 @@ class T1DecayResult:
|
|
|
118
123
|
def constant(self) -> float:
|
|
119
124
|
"""The t1 decay constant."""
|
|
120
125
|
|
|
121
|
-
def exp_decay(x, t1):
|
|
122
|
-
return np.exp(-x / t1)
|
|
126
|
+
def exp_decay(x, t1, a, b):
|
|
127
|
+
return a * np.exp(-x / t1) + b
|
|
123
128
|
|
|
124
129
|
xs = self._data['delay_ns']
|
|
125
130
|
ts = self._data['true_count']
|
|
@@ -132,8 +137,8 @@ class T1DecayResult:
|
|
|
132
137
|
|
|
133
138
|
# Fit to exponential decay to find the t1 constant
|
|
134
139
|
try:
|
|
135
|
-
popt, _ = optimize.curve_fit(exp_decay, xs, probs, p0=[t1_guess])
|
|
136
|
-
t1 = popt[0]
|
|
140
|
+
self.popt, _ = optimize.curve_fit(exp_decay, xs, probs, p0=[t1_guess, 1.0, 0.0])
|
|
141
|
+
t1 = self.popt[0]
|
|
137
142
|
return t1
|
|
138
143
|
except RuntimeError:
|
|
139
144
|
warnings.warn("Optimal parameters could not be found for curve fit", RuntimeWarning)
|
|
@@ -166,7 +171,9 @@ class T1DecayResult:
|
|
|
166
171
|
ax.plot(xs, ts / (fs + ts), 'ro-', **plot_kwargs)
|
|
167
172
|
|
|
168
173
|
if include_fit and not np.isnan(self.constant):
|
|
169
|
-
|
|
174
|
+
t1 = self.constant
|
|
175
|
+
t1, a, b = self.popt
|
|
176
|
+
ax.plot(xs, a * np.exp(-xs / t1) + b, label='curve fit')
|
|
170
177
|
plt.legend()
|
|
171
178
|
|
|
172
179
|
ax.set_xlabel(r"Delay between initialization and measurement (nanoseconds)")
|
|
@@ -53,7 +53,7 @@ def test_plot_does_not_raise_error():
|
|
|
53
53
|
repetitions=10,
|
|
54
54
|
max_delay=cirq.Duration(nanos=500),
|
|
55
55
|
)
|
|
56
|
-
results.plot()
|
|
56
|
+
results.plot(include_fit=True)
|
|
57
57
|
|
|
58
58
|
|
|
59
59
|
def test_result_eq():
|
|
@@ -61,7 +61,7 @@ def test_result_eq():
|
|
|
61
61
|
eq.make_equality_group(
|
|
62
62
|
lambda: cirq.experiments.T1DecayResult(
|
|
63
63
|
data=pd.DataFrame(
|
|
64
|
-
columns=['delay_ns', 'false_count', 'true_count'], index=[0], data=[[100
|
|
64
|
+
columns=['delay_ns', 'false_count', 'true_count'], index=[0], data=[[100, 2, 8]]
|
|
65
65
|
)
|
|
66
66
|
)
|
|
67
67
|
)
|
|
@@ -103,7 +103,7 @@ def test_sudden_decay_results():
|
|
|
103
103
|
data=pd.DataFrame(
|
|
104
104
|
columns=['delay_ns', 'false_count', 'true_count'],
|
|
105
105
|
index=range(4),
|
|
106
|
-
data=[[100.0, 0, 10], [
|
|
106
|
+
data=[[100.0, 0, 10], [215.0, 0, 10], [464.0, 0, 10], [1000.0, 10, 0]],
|
|
107
107
|
)
|
|
108
108
|
)
|
|
109
109
|
|
|
@@ -117,13 +117,14 @@ def test_all_on_results():
|
|
|
117
117
|
min_delay=cirq.Duration(nanos=100),
|
|
118
118
|
max_delay=cirq.Duration(micros=1),
|
|
119
119
|
)
|
|
120
|
-
|
|
120
|
+
desired = cirq.experiments.T1DecayResult(
|
|
121
121
|
data=pd.DataFrame(
|
|
122
122
|
columns=['delay_ns', 'false_count', 'true_count'],
|
|
123
123
|
index=range(4),
|
|
124
|
-
data=[[100.0, 0, 10], [
|
|
124
|
+
data=[[100.0, 0, 10], [215.0, 0, 10], [464.0, 0, 10], [1000.0, 0, 10]],
|
|
125
125
|
)
|
|
126
126
|
)
|
|
127
|
+
assert results == desired, f'{results.data=} {desired.data=}'
|
|
127
128
|
|
|
128
129
|
|
|
129
130
|
def test_all_off_results():
|
|
@@ -135,13 +136,14 @@ def test_all_off_results():
|
|
|
135
136
|
min_delay=cirq.Duration(nanos=100),
|
|
136
137
|
max_delay=cirq.Duration(micros=1),
|
|
137
138
|
)
|
|
138
|
-
|
|
139
|
+
desired = cirq.experiments.T1DecayResult(
|
|
139
140
|
data=pd.DataFrame(
|
|
140
141
|
columns=['delay_ns', 'false_count', 'true_count'],
|
|
141
142
|
index=range(4),
|
|
142
|
-
data=[[100.0, 10, 0], [
|
|
143
|
+
data=[[100.0, 10, 0], [215.0, 10, 0], [464.0, 10, 0], [1000.0, 10, 0]],
|
|
143
144
|
)
|
|
144
145
|
)
|
|
146
|
+
assert results == desired, f'{results.data=} {desired.data=}'
|
|
145
147
|
|
|
146
148
|
|
|
147
149
|
@pytest.mark.usefixtures('closefigures')
|
|
@@ -150,28 +152,14 @@ def test_curve_fit_plot_works():
|
|
|
150
152
|
data=pd.DataFrame(
|
|
151
153
|
columns=['delay_ns', 'false_count', 'true_count'],
|
|
152
154
|
index=range(4),
|
|
153
|
-
data=[[100.0, 6, 4], [
|
|
155
|
+
data=[[100.0, 6, 4], [215.0, 10, 0], [464.0, 10, 0], [1000.0, 10, 0]],
|
|
154
156
|
)
|
|
155
157
|
)
|
|
156
158
|
|
|
157
159
|
good_fit.plot(include_fit=True)
|
|
158
160
|
|
|
159
161
|
|
|
160
|
-
@pytest.mark.
|
|
161
|
-
def test_curve_fit_plot_warning():
|
|
162
|
-
bad_fit = cirq.experiments.T1DecayResult(
|
|
163
|
-
data=pd.DataFrame(
|
|
164
|
-
columns=['delay_ns', 'false_count', 'true_count'],
|
|
165
|
-
index=range(4),
|
|
166
|
-
data=[[100.0, 10, 0], [400.0, 10, 0], [700.0, 10, 0], [1000.0, 10, 0]],
|
|
167
|
-
)
|
|
168
|
-
)
|
|
169
|
-
|
|
170
|
-
with pytest.warns(RuntimeWarning, match='Optimal parameters could not be found for curve fit'):
|
|
171
|
-
bad_fit.plot(include_fit=True)
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
@pytest.mark.parametrize('t1', [200, 500, 700])
|
|
162
|
+
@pytest.mark.parametrize('t1', [200.0, 500.0, 700.0])
|
|
175
163
|
def test_noise_model_continous(t1):
|
|
176
164
|
class GradualDecay(cirq.NoiseModel):
|
|
177
165
|
def __init__(self, t1: float):
|
|
@@ -196,10 +184,10 @@ def test_noise_model_continous(t1):
|
|
|
196
184
|
results = cirq.experiments.t1_decay(
|
|
197
185
|
sampler=cirq.DensityMatrixSimulator(noise=GradualDecay(t1)),
|
|
198
186
|
qubit=cirq.GridQubit(0, 0),
|
|
199
|
-
num_points=
|
|
187
|
+
num_points=10,
|
|
200
188
|
repetitions=10,
|
|
201
|
-
min_delay=cirq.Duration(nanos=
|
|
202
|
-
max_delay=cirq.Duration(micros=
|
|
189
|
+
min_delay=cirq.Duration(nanos=1),
|
|
190
|
+
max_delay=cirq.Duration(micros=10),
|
|
203
191
|
)
|
|
204
192
|
|
|
205
193
|
assert np.isclose(results.constant, t1, 50)
|