cirq-core 1.7.0.dev20250807224154__py3-none-any.whl → 1.7.0.dev20250812001555__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 cirq-core might be problematic. Click here for more details.
- cirq/_version.py +1 -1
- cirq/_version_test.py +1 -1
- cirq/contrib/noise_models/noise_models.py +8 -8
- cirq/contrib/quimb/grid_circuits.py +1 -1
- cirq/contrib/quimb/grid_circuits_test.py +10 -5
- cirq/contrib/quimb/mps_simulator.py +3 -3
- cirq/contrib/quimb/mps_simulator_test.py +41 -42
- cirq/contrib/quimb/state_vector_test.py +14 -13
- cirq/contrib/quirk/export_to_quirk_test.py +2 -2
- cirq/contrib/quirk/linearize_circuit.py +1 -1
- cirq/contrib/routing/device.py +1 -1
- cirq/contrib/routing/device_test.py +7 -5
- cirq/contrib/routing/greedy_test.py +7 -2
- cirq/contrib/routing/initialization_test.py +1 -1
- cirq/contrib/routing/router_test.py +9 -10
- cirq/contrib/routing/swap_network_test.py +10 -4
- cirq/contrib/routing/utils_test.py +4 -4
- cirq/contrib/shuffle_circuits/shuffle_circuits_with_readout_benchmarking.py +9 -9
- cirq/contrib/shuffle_circuits/shuffle_circuits_with_readout_benchmarking_test.py +18 -16
- cirq/contrib/svg/svg.py +1 -1
- cirq/devices/grid_device_metadata_test.py +12 -12
- cirq/devices/grid_qubit_test.py +52 -52
- cirq/devices/line_qubit_test.py +37 -37
- cirq/devices/named_topologies.py +7 -5
- cirq/devices/named_topologies_test.py +3 -2
- cirq/devices/noise_model.py +1 -1
- cirq/devices/noise_properties_test.py +1 -1
- cirq/devices/noise_utils.py +1 -1
- cirq/devices/noise_utils_test.py +6 -6
- cirq/devices/superconducting_qubits_noise_properties_test.py +31 -24
- cirq/devices/thermal_noise_model_test.py +48 -44
- cirq/devices/unconstrained_device.py +1 -1
- cirq/devices/unconstrained_device_test.py +3 -3
- cirq/experiments/benchmarking/parallel_xeb.py +24 -17
- cirq/experiments/benchmarking/parallel_xeb_test.py +42 -28
- cirq/experiments/fidelity_estimation.py +5 -5
- cirq/experiments/fidelity_estimation_test.py +7 -7
- cirq/experiments/purity_estimation.py +1 -1
- cirq/experiments/purity_estimation_test.py +1 -1
- cirq/experiments/qubit_characterizations_test.py +10 -10
- cirq/experiments/random_quantum_circuit_generation.py +1 -1
- cirq/experiments/random_quantum_circuit_generation_test.py +18 -13
- cirq/experiments/readout_confusion_matrix_test.py +12 -8
- cirq/experiments/single_qubit_readout_calibration_test.py +13 -13
- cirq/experiments/t2_decay_experiment.py +1 -1
- cirq/experiments/t2_decay_experiment_test.py +13 -13
- cirq/experiments/two_qubit_xeb_test.py +20 -22
- cirq/experiments/xeb_fitting.py +3 -3
- cirq/experiments/xeb_fitting_test.py +21 -19
- cirq/experiments/xeb_sampling.py +2 -2
- cirq/experiments/xeb_sampling_test.py +9 -9
- cirq/experiments/xeb_simulation.py +1 -1
- cirq/experiments/xeb_simulation_test.py +6 -6
- cirq/ops/measure_util.py +2 -0
- {cirq_core-1.7.0.dev20250807224154.dist-info → cirq_core-1.7.0.dev20250812001555.dist-info}/METADATA +1 -1
- {cirq_core-1.7.0.dev20250807224154.dist-info → cirq_core-1.7.0.dev20250812001555.dist-info}/RECORD +59 -59
- {cirq_core-1.7.0.dev20250807224154.dist-info → cirq_core-1.7.0.dev20250812001555.dist-info}/WHEEL +0 -0
- {cirq_core-1.7.0.dev20250807224154.dist-info → cirq_core-1.7.0.dev20250812001555.dist-info}/licenses/LICENSE +0 -0
- {cirq_core-1.7.0.dev20250807224154.dist-info → cirq_core-1.7.0.dev20250812001555.dist-info}/top_level.txt +0 -0
|
@@ -37,8 +37,8 @@ _PAIRS = ((cirq.q(0, 0), cirq.q(0, 1)), (cirq.q(0, 2), cirq.q(0, 3)), (cirq.q(0,
|
|
|
37
37
|
|
|
38
38
|
class TestXEBWideCircuitInfo:
|
|
39
39
|
|
|
40
|
-
def test_from_circuit(self):
|
|
41
|
-
permutation = [1, 2, 0]
|
|
40
|
+
def test_from_circuit(self) -> None:
|
|
41
|
+
permutation = np.array([1, 2, 0])
|
|
42
42
|
target = cirq.CircuitOperation(cirq.FrozenCircuit(cirq.CNOT(*_QUBITS)))
|
|
43
43
|
wide_circuit = xeb.XEBWideCircuitInfo.from_narrow_circuits(
|
|
44
44
|
_CIRCUIT_TEMPLATES, permutation=permutation, pairs=_PAIRS, target=target
|
|
@@ -65,7 +65,7 @@ class TestXEBWideCircuitInfo:
|
|
|
65
65
|
narrow_template_indices=permutation,
|
|
66
66
|
)
|
|
67
67
|
|
|
68
|
-
def test_sliced_circuit(self):
|
|
68
|
+
def test_sliced_circuit(self) -> None:
|
|
69
69
|
wid_circuit = xeb.XEBWideCircuitInfo(
|
|
70
70
|
wide_circuit=cirq.Circuit.from_moments(
|
|
71
71
|
[
|
|
@@ -114,10 +114,14 @@ class TestXEBWideCircuitInfo:
|
|
|
114
114
|
assert wid_circuit.sliced_circuits([1]) == [sliced_circuit]
|
|
115
115
|
|
|
116
116
|
|
|
117
|
-
def test_create_combination_circuits():
|
|
117
|
+
def test_create_combination_circuits() -> None:
|
|
118
118
|
wide_circuits_info = xeb.create_combination_circuits(
|
|
119
119
|
_CIRCUIT_TEMPLATES,
|
|
120
|
-
[
|
|
120
|
+
[
|
|
121
|
+
rqcg.CircuitLibraryCombination(
|
|
122
|
+
layer=None, combinations=np.array([[1, 2, 0]]), pairs=_PAIRS
|
|
123
|
+
)
|
|
124
|
+
],
|
|
121
125
|
target=cirq.CNOT(*_QUBITS),
|
|
122
126
|
)
|
|
123
127
|
|
|
@@ -142,10 +146,14 @@ def test_create_combination_circuits():
|
|
|
142
146
|
]
|
|
143
147
|
|
|
144
148
|
|
|
145
|
-
def test_create_combination_circuits_with_target_dict():
|
|
149
|
+
def test_create_combination_circuits_with_target_dict() -> None:
|
|
146
150
|
wide_circuits_info = xeb.create_combination_circuits(
|
|
147
151
|
_CIRCUIT_TEMPLATES,
|
|
148
|
-
[
|
|
152
|
+
[
|
|
153
|
+
rqcg.CircuitLibraryCombination(
|
|
154
|
+
layer=None, combinations=np.array([[1, 2, 0]]), pairs=_PAIRS
|
|
155
|
+
)
|
|
156
|
+
],
|
|
149
157
|
target={_PAIRS[0]: cirq.CNOT(*_QUBITS), _PAIRS[1]: cirq.CZ(*_QUBITS)},
|
|
150
158
|
)
|
|
151
159
|
|
|
@@ -164,7 +172,7 @@ def test_create_combination_circuits_with_target_dict():
|
|
|
164
172
|
]
|
|
165
173
|
|
|
166
174
|
|
|
167
|
-
def test_simulate_circuit():
|
|
175
|
+
def test_simulate_circuit() -> None:
|
|
168
176
|
sim = cirq.Simulator(seed=0)
|
|
169
177
|
circuit = cirq.Circuit.from_moments(
|
|
170
178
|
cirq.X.on_each(_QUBITS),
|
|
@@ -180,7 +188,7 @@ def test_simulate_circuit():
|
|
|
180
188
|
np.testing.assert_allclose(result, [[0, 1, 0, 0], [1, 0, 0, 0]]) # |01> # |00>
|
|
181
189
|
|
|
182
190
|
|
|
183
|
-
def test_simulate_circuit_library():
|
|
191
|
+
def test_simulate_circuit_library() -> None:
|
|
184
192
|
circuit_templates = [
|
|
185
193
|
cirq.Circuit.from_moments(
|
|
186
194
|
cirq.X.on_each(_QUBITS),
|
|
@@ -199,7 +207,7 @@ def test_simulate_circuit_library():
|
|
|
199
207
|
np.testing.assert_allclose(result, [[[0, 1, 0, 0], [1, 0, 0, 0]]]) # |01> # |00>
|
|
200
208
|
|
|
201
209
|
|
|
202
|
-
def test_simulate_circuit_library_with_target_dict():
|
|
210
|
+
def test_simulate_circuit_library_with_target_dict() -> None:
|
|
203
211
|
circuit_templates = [
|
|
204
212
|
cirq.Circuit.from_moments(
|
|
205
213
|
[cirq.H(_QUBITS[0]), cirq.X(_QUBITS[1])],
|
|
@@ -219,13 +227,15 @@ def test_simulate_circuit_library_with_target_dict():
|
|
|
219
227
|
)
|
|
220
228
|
|
|
221
229
|
# First pair result.
|
|
222
|
-
np.testing.assert_allclose(
|
|
230
|
+
np.testing.assert_allclose(
|
|
231
|
+
result[_PAIRS[0]], [[[0.25, 0.25, 0.25, 0.25], [0.0, 1.0, 0.0, 0.0]]]
|
|
232
|
+
)
|
|
223
233
|
|
|
224
234
|
# Second pair result.
|
|
225
235
|
np.testing.assert_allclose(result[_PAIRS[1]], [[[0, 0, 1, 0], [1, 0, 0, 0]]]) # |10> # |00>
|
|
226
236
|
|
|
227
237
|
|
|
228
|
-
def test_sample_all_circuits():
|
|
238
|
+
def test_sample_all_circuits() -> None:
|
|
229
239
|
wide_circuits = [
|
|
230
240
|
cirq.Circuit.from_moments(
|
|
231
241
|
[cirq.Y.on_each(*_PAIRS[0]), cirq.Z.on_each(*_PAIRS[1]), cirq.X.on_each(*_PAIRS[2])],
|
|
@@ -252,7 +262,7 @@ def test_sample_all_circuits():
|
|
|
252
262
|
) # |01>
|
|
253
263
|
|
|
254
264
|
|
|
255
|
-
def test_estimate_fidelities():
|
|
265
|
+
def test_estimate_fidelities() -> None:
|
|
256
266
|
sampling_result = [{str(_PAIRS[0]): np.array([0.15, 0.15, 0.35, 0.35])}]
|
|
257
267
|
|
|
258
268
|
simulation_results = [[np.array([0.1, 0.2, 0.3, 0.4])]]
|
|
@@ -278,12 +288,14 @@ def test_estimate_fidelities():
|
|
|
278
288
|
],
|
|
279
289
|
)
|
|
280
290
|
|
|
281
|
-
assert result ==
|
|
282
|
-
|
|
283
|
-
]
|
|
291
|
+
assert len(result) == 1
|
|
292
|
+
xeb_fidelity = result[0]
|
|
293
|
+
assert xeb_fidelity.pair == _PAIRS[0]
|
|
294
|
+
assert xeb_fidelity.cycle_depth == 1
|
|
295
|
+
assert xeb_fidelity.fidelity == pytest.approx(0.785, abs=2e-4)
|
|
284
296
|
|
|
285
297
|
|
|
286
|
-
def test_estimate_fidelities_with_dict_target():
|
|
298
|
+
def test_estimate_fidelities_with_dict_target() -> None:
|
|
287
299
|
sampling_result = [{str(_PAIRS[0]): np.array([0.15, 0.15, 0.35, 0.35])}]
|
|
288
300
|
|
|
289
301
|
simulation_results = {_PAIRS[0]: [[np.array([0.1, 0.2, 0.3, 0.4])]]}
|
|
@@ -309,9 +321,11 @@ def test_estimate_fidelities_with_dict_target():
|
|
|
309
321
|
],
|
|
310
322
|
)
|
|
311
323
|
|
|
312
|
-
assert result ==
|
|
313
|
-
|
|
314
|
-
]
|
|
324
|
+
assert len(result) == 1
|
|
325
|
+
xeb_fidelity = result[0]
|
|
326
|
+
assert xeb_fidelity.pair == _PAIRS[0]
|
|
327
|
+
assert xeb_fidelity.cycle_depth == 1
|
|
328
|
+
assert xeb_fidelity.fidelity == pytest.approx(0.785, abs=2e-4)
|
|
315
329
|
|
|
316
330
|
|
|
317
331
|
def _assert_fidelities_approx_equal(fids, expected: float, atol: float):
|
|
@@ -323,7 +337,7 @@ def _assert_fidelities_approx_equal(fids, expected: float, atol: float):
|
|
|
323
337
|
|
|
324
338
|
@pytest.mark.parametrize('target', [cirq.CZ, cirq.Circuit(cirq.CZ(*_QUBITS)), cirq.CZ(*_QUBITS)])
|
|
325
339
|
@pytest.mark.parametrize('pairs', [_PAIRS[:1], _PAIRS[:2]])
|
|
326
|
-
def test_parallel_two_qubit_xeb(target, pairs):
|
|
340
|
+
def test_parallel_two_qubit_xeb(target, pairs) -> None:
|
|
327
341
|
sampler = cirq.DensityMatrixSimulator(noise=cirq.depolarize(0.03), seed=0)
|
|
328
342
|
result = xeb.parallel_two_qubit_xeb(
|
|
329
343
|
sampler=sampler,
|
|
@@ -349,17 +363,17 @@ class ExampleDevice(cirq.Device):
|
|
|
349
363
|
|
|
350
364
|
|
|
351
365
|
class ExampleProcessor:
|
|
352
|
-
def get_device(self):
|
|
366
|
+
def get_device(self) -> ExampleDevice:
|
|
353
367
|
return ExampleDevice()
|
|
354
368
|
|
|
355
369
|
|
|
356
370
|
class DensityMatrixSimulatorWithProcessor(cirq.DensityMatrixSimulator):
|
|
357
371
|
@property
|
|
358
|
-
def processor(self):
|
|
372
|
+
def processor(self) -> ExampleProcessor:
|
|
359
373
|
return ExampleProcessor()
|
|
360
374
|
|
|
361
375
|
|
|
362
|
-
def test_parallel_two_qubit_xeb_with_device():
|
|
376
|
+
def test_parallel_two_qubit_xeb_with_device() -> None:
|
|
363
377
|
target = cirq.CZ
|
|
364
378
|
sampler = DensityMatrixSimulatorWithProcessor(noise=cirq.depolarize(0.03), seed=0)
|
|
365
379
|
result = xeb.parallel_two_qubit_xeb(
|
|
@@ -380,7 +394,7 @@ def test_parallel_two_qubit_xeb_with_device():
|
|
|
380
394
|
assert result.all_qubit_pairs == pairs
|
|
381
395
|
|
|
382
396
|
|
|
383
|
-
def test_parallel_two_qubit_xeb_with_dict_target():
|
|
397
|
+
def test_parallel_two_qubit_xeb_with_dict_target() -> None:
|
|
384
398
|
target = {p: cirq.Circuit(cirq.CZ(*_QUBITS)) for p in _PAIRS[:2]}
|
|
385
399
|
target[_PAIRS[2]] = cirq.CZ(*_QUBITS)
|
|
386
400
|
sampler = cirq.DensityMatrixSimulator(noise=cirq.depolarize(0.03), seed=0)
|
|
@@ -395,7 +409,7 @@ def test_parallel_two_qubit_xeb_with_dict_target():
|
|
|
395
409
|
assert result.all_qubit_pairs == _PAIRS
|
|
396
410
|
|
|
397
411
|
|
|
398
|
-
def test_parallel_two_qubit_xeb_with_ideal_target():
|
|
412
|
+
def test_parallel_two_qubit_xeb_with_ideal_target() -> None:
|
|
399
413
|
target = {p: cirq.Circuit(cirq.CZ(*_QUBITS)) for p in _PAIRS[:2]}
|
|
400
414
|
target[_PAIRS[2]] = cirq.CZ(*_QUBITS)
|
|
401
415
|
sampler = cirq.DensityMatrixSimulator(noise=cirq.depolarize(0.03), seed=0)
|
|
@@ -417,7 +431,7 @@ def threading_pool() -> Iterator[futures.Executor]:
|
|
|
417
431
|
yield pool
|
|
418
432
|
|
|
419
433
|
|
|
420
|
-
def test_parallel_two_qubit_xeb_with_dict_target_and_pool(threading_pool):
|
|
434
|
+
def test_parallel_two_qubit_xeb_with_dict_target_and_pool(threading_pool) -> None:
|
|
421
435
|
target = {p: cirq.Circuit(cirq.CZ(*_QUBITS)) for p in _PAIRS}
|
|
422
436
|
sampler = cirq.DensityMatrixSimulator(noise=cirq.depolarize(0.03), seed=0)
|
|
423
437
|
result = xeb.parallel_two_qubit_xeb(
|
|
@@ -432,7 +446,7 @@ def test_parallel_two_qubit_xeb_with_dict_target_and_pool(threading_pool):
|
|
|
432
446
|
assert result.all_qubit_pairs == _PAIRS
|
|
433
447
|
|
|
434
448
|
|
|
435
|
-
def test_parallel_two_qubit_xeb_with_invalid_input_raises():
|
|
449
|
+
def test_parallel_two_qubit_xeb_with_invalid_input_raises() -> None:
|
|
436
450
|
with pytest.raises(AssertionError):
|
|
437
451
|
_ = xeb.parallel_two_qubit_xeb(
|
|
438
452
|
sampler=cirq.Simulator(seed=0), target={_PAIRS[0]: cirq.CZ}, pairs=_PAIRS
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
|
|
17
17
|
from __future__ import annotations
|
|
18
18
|
|
|
19
|
-
from typing import Callable,
|
|
19
|
+
from typing import Callable, Sequence, TYPE_CHECKING
|
|
20
20
|
|
|
21
21
|
import numpy as np
|
|
22
22
|
|
|
@@ -141,7 +141,7 @@ def xeb_fidelity(
|
|
|
141
141
|
circuit: cirq.Circuit,
|
|
142
142
|
bitstrings: Sequence[int],
|
|
143
143
|
qubit_order: QubitOrderOrList = QubitOrder.DEFAULT,
|
|
144
|
-
amplitudes:
|
|
144
|
+
amplitudes: np.ndarray | None = None,
|
|
145
145
|
estimator: Callable[[int, Sequence[float]], float] = linear_xeb_fidelity_from_probabilities,
|
|
146
146
|
) -> float:
|
|
147
147
|
"""Estimates XEB fidelity from one circuit using user-supplied estimator.
|
|
@@ -169,7 +169,7 @@ def xeb_fidelity(
|
|
|
169
169
|
`cirq.final_state_vector`.
|
|
170
170
|
qubit_order: Qubit order used to construct bitstrings enumerating
|
|
171
171
|
qubits starting with the most significant qubit.
|
|
172
|
-
amplitudes: Optional
|
|
172
|
+
amplitudes: Optional array of output amplitudes at bitstring indices.
|
|
173
173
|
If provided, simulation is skipped. Useful for large circuits
|
|
174
174
|
when an offline simulation had already been performed.
|
|
175
175
|
estimator: Fidelity estimator to use, see above. Defaults to the
|
|
@@ -206,7 +206,7 @@ def linear_xeb_fidelity(
|
|
|
206
206
|
circuit: cirq.Circuit,
|
|
207
207
|
bitstrings: Sequence[int],
|
|
208
208
|
qubit_order: QubitOrderOrList = QubitOrder.DEFAULT,
|
|
209
|
-
amplitudes:
|
|
209
|
+
amplitudes: np.ndarray | None = None,
|
|
210
210
|
) -> float:
|
|
211
211
|
"""Estimates XEB fidelity from one circuit using linear estimator."""
|
|
212
212
|
return xeb_fidelity(
|
|
@@ -222,7 +222,7 @@ def log_xeb_fidelity(
|
|
|
222
222
|
circuit: cirq.Circuit,
|
|
223
223
|
bitstrings: Sequence[int],
|
|
224
224
|
qubit_order: QubitOrderOrList = QubitOrder.DEFAULT,
|
|
225
|
-
amplitudes:
|
|
225
|
+
amplitudes: np.ndarray | None = None,
|
|
226
226
|
) -> float:
|
|
227
227
|
"""Estimates XEB fidelity from one circuit using logarithmic estimator."""
|
|
228
228
|
return xeb_fidelity(
|
|
@@ -25,7 +25,7 @@ import cirq
|
|
|
25
25
|
|
|
26
26
|
def sample_noisy_bitstrings(
|
|
27
27
|
circuit: cirq.Circuit, qubit_order: Sequence[cirq.Qid], depolarization: float, repetitions: int
|
|
28
|
-
) ->
|
|
28
|
+
) -> Sequence[int]:
|
|
29
29
|
assert 0 <= depolarization <= 1
|
|
30
30
|
dim = np.prod(circuit.qid_shape(), dtype=np.int64)
|
|
31
31
|
n_incoherent = int(depolarization * repetitions)
|
|
@@ -34,7 +34,7 @@ def sample_noisy_bitstrings(
|
|
|
34
34
|
circuit_with_measurements = cirq.Circuit(circuit, cirq.measure(*qubit_order, key='m'))
|
|
35
35
|
r = cirq.sample(circuit_with_measurements, repetitions=n_coherent)
|
|
36
36
|
coherent_samples = r.data['m'].to_numpy()
|
|
37
|
-
return np.concatenate((coherent_samples, incoherent_samples))
|
|
37
|
+
return np.concatenate((coherent_samples, incoherent_samples)).tolist()
|
|
38
38
|
|
|
39
39
|
|
|
40
40
|
def make_random_quantum_circuit(qubits: Sequence[cirq.Qid], depth: int) -> cirq.Circuit:
|
|
@@ -69,7 +69,7 @@ def make_random_quantum_circuit(qubits: Sequence[cirq.Qid], depth: int) -> cirq.
|
|
|
69
69
|
),
|
|
70
70
|
),
|
|
71
71
|
)
|
|
72
|
-
def test_xeb_fidelity(depolarization, estimator):
|
|
72
|
+
def test_xeb_fidelity(depolarization, estimator) -> None:
|
|
73
73
|
prng_state = np.random.get_state()
|
|
74
74
|
np.random.seed(0)
|
|
75
75
|
|
|
@@ -95,7 +95,7 @@ def test_xeb_fidelity(depolarization, estimator):
|
|
|
95
95
|
np.random.set_state(prng_state)
|
|
96
96
|
|
|
97
97
|
|
|
98
|
-
def test_linear_and_log_xeb_fidelity():
|
|
98
|
+
def test_linear_and_log_xeb_fidelity() -> None:
|
|
99
99
|
prng_state = np.random.get_state()
|
|
100
100
|
np.random.seed(0)
|
|
101
101
|
|
|
@@ -122,7 +122,7 @@ def test_linear_and_log_xeb_fidelity():
|
|
|
122
122
|
np.random.set_state(prng_state)
|
|
123
123
|
|
|
124
124
|
|
|
125
|
-
def test_xeb_fidelity_invalid_qubits():
|
|
125
|
+
def test_xeb_fidelity_invalid_qubits() -> None:
|
|
126
126
|
q0, q1, q2 = cirq.LineQubit.range(3)
|
|
127
127
|
circuit = cirq.Circuit(cirq.H(q0), cirq.CNOT(q0, q1))
|
|
128
128
|
bitstrings = sample_noisy_bitstrings(circuit, (q0, q1, q2), 0.9, 10)
|
|
@@ -130,7 +130,7 @@ def test_xeb_fidelity_invalid_qubits():
|
|
|
130
130
|
cirq.xeb_fidelity(circuit, bitstrings, (q0, q2))
|
|
131
131
|
|
|
132
132
|
|
|
133
|
-
def test_xeb_fidelity_invalid_bitstrings():
|
|
133
|
+
def test_xeb_fidelity_invalid_bitstrings() -> None:
|
|
134
134
|
q0, q1 = cirq.LineQubit.range(2)
|
|
135
135
|
circuit = cirq.Circuit(cirq.H(q0), cirq.CNOT(q0, q1))
|
|
136
136
|
bitstrings = [0, 1, 2, 3, 4]
|
|
@@ -138,7 +138,7 @@ def test_xeb_fidelity_invalid_bitstrings():
|
|
|
138
138
|
cirq.xeb_fidelity(circuit, bitstrings, (q0, q1))
|
|
139
139
|
|
|
140
140
|
|
|
141
|
-
def test_xeb_fidelity_tuple_input():
|
|
141
|
+
def test_xeb_fidelity_tuple_input() -> None:
|
|
142
142
|
q0, q1 = cirq.LineQubit.range(2)
|
|
143
143
|
circuit = cirq.Circuit(cirq.H(q0), cirq.CNOT(q0, q1))
|
|
144
144
|
bitstrings = [0, 1, 2]
|
|
@@ -20,7 +20,7 @@ import numpy as np
|
|
|
20
20
|
|
|
21
21
|
|
|
22
22
|
def purity_from_probabilities(
|
|
23
|
-
hilbert_space_dimension: int, probabilities: Sequence[float]
|
|
23
|
+
hilbert_space_dimension: int, probabilities: np.ndarray | Sequence[float]
|
|
24
24
|
) -> float:
|
|
25
25
|
"""Purity estimator from speckle purity benchmarking.
|
|
26
26
|
|
|
@@ -19,7 +19,7 @@ import numpy as np
|
|
|
19
19
|
from cirq.experiments import purity_from_probabilities
|
|
20
20
|
|
|
21
21
|
|
|
22
|
-
def test_purity_from_probabilities():
|
|
22
|
+
def test_purity_from_probabilities() -> None:
|
|
23
23
|
probabilities = np.random.uniform(0, 1, size=4)
|
|
24
24
|
probabilities /= np.sum(probabilities)
|
|
25
25
|
purity = purity_from_probabilities(4, probabilities)
|
|
@@ -33,7 +33,7 @@ from cirq.experiments import (
|
|
|
33
33
|
)
|
|
34
34
|
|
|
35
35
|
|
|
36
|
-
def test_single_qubit_cliffords():
|
|
36
|
+
def test_single_qubit_cliffords() -> None:
|
|
37
37
|
I = np.eye(2)
|
|
38
38
|
X = np.array([[0, 1], [1, 0]])
|
|
39
39
|
Y = np.array([[0, -1j], [1j, 0]])
|
|
@@ -108,7 +108,7 @@ def test_single_qubit_cliffords():
|
|
|
108
108
|
|
|
109
109
|
|
|
110
110
|
@mock.patch.dict(os.environ, clear='CIRQ_TESTING')
|
|
111
|
-
def test_single_qubit_randomized_benchmarking():
|
|
111
|
+
def test_single_qubit_randomized_benchmarking() -> None:
|
|
112
112
|
# Check that the ground state population at the end of the Clifford
|
|
113
113
|
# sequences is always unity.
|
|
114
114
|
simulator = sim.Simulator()
|
|
@@ -121,7 +121,7 @@ def test_single_qubit_randomized_benchmarking():
|
|
|
121
121
|
|
|
122
122
|
|
|
123
123
|
@mock.patch.dict(os.environ, clear='CIRQ_TESTING')
|
|
124
|
-
def test_parallel_single_qubit_parallel_single_qubit_randomized_benchmarking():
|
|
124
|
+
def test_parallel_single_qubit_parallel_single_qubit_randomized_benchmarking() -> None:
|
|
125
125
|
# Check that the ground state population at the end of the Clifford
|
|
126
126
|
# sequences is always unity.
|
|
127
127
|
simulator = sim.Simulator()
|
|
@@ -140,7 +140,7 @@ def test_parallel_single_qubit_parallel_single_qubit_randomized_benchmarking():
|
|
|
140
140
|
_ = results.plot_integrated_histogram()
|
|
141
141
|
|
|
142
142
|
|
|
143
|
-
def test_two_qubit_randomized_benchmarking():
|
|
143
|
+
def test_two_qubit_randomized_benchmarking() -> None:
|
|
144
144
|
# Check that the ground state population at the end of the Clifford
|
|
145
145
|
# sequences is always unity.
|
|
146
146
|
simulator = sim.Simulator()
|
|
@@ -154,7 +154,7 @@ def test_two_qubit_randomized_benchmarking():
|
|
|
154
154
|
assert np.isclose(np.mean(g_pops), 1.0)
|
|
155
155
|
|
|
156
156
|
|
|
157
|
-
def test_single_qubit_state_tomography():
|
|
157
|
+
def test_single_qubit_state_tomography() -> None:
|
|
158
158
|
# Check that the density matrices of the output states of X/2, Y/2 and
|
|
159
159
|
# H + Y gates closely match the ideal cases.
|
|
160
160
|
# Checks that unique tomography keys are generated
|
|
@@ -187,7 +187,7 @@ def test_single_qubit_state_tomography():
|
|
|
187
187
|
np.testing.assert_almost_equal(act_rho_5, tar_rho_5, decimal=1)
|
|
188
188
|
|
|
189
189
|
|
|
190
|
-
def test_two_qubit_state_tomography():
|
|
190
|
+
def test_two_qubit_state_tomography() -> None:
|
|
191
191
|
# Check that the density matrices of the four Bell states closely match
|
|
192
192
|
# the ideal cases. In addition, check that the output states of
|
|
193
193
|
# single-qubit rotations (H, H), (X/2, Y/2), (Y/2, X/2) have the correct
|
|
@@ -231,14 +231,14 @@ def test_two_qubit_state_tomography():
|
|
|
231
231
|
|
|
232
232
|
|
|
233
233
|
@pytest.mark.usefixtures('closefigures')
|
|
234
|
-
def test_tomography_plot_raises_for_incorrect_number_of_axes():
|
|
234
|
+
def test_tomography_plot_raises_for_incorrect_number_of_axes() -> None:
|
|
235
235
|
simulator = sim.Simulator()
|
|
236
236
|
qubit = GridQubit(0, 0)
|
|
237
237
|
circuit = circuits.Circuit(ops.X(qubit) ** 0.5)
|
|
238
238
|
result = single_qubit_state_tomography(simulator, qubit, circuit, 1000)
|
|
239
239
|
with pytest.raises(TypeError): # ax is not a list[plt.Axes]
|
|
240
240
|
ax = plt.subplot()
|
|
241
|
-
result.plot(ax)
|
|
241
|
+
result.plot(ax) # type: ignore[arg-type]
|
|
242
242
|
with pytest.raises(ValueError):
|
|
243
243
|
_, axes = plt.subplots(1, 3)
|
|
244
244
|
result.plot(axes)
|
|
@@ -247,7 +247,7 @@ def test_tomography_plot_raises_for_incorrect_number_of_axes():
|
|
|
247
247
|
@pytest.mark.parametrize('num_cliffords', range(5, 10))
|
|
248
248
|
@pytest.mark.parametrize('use_xy_basis', [False, True])
|
|
249
249
|
@pytest.mark.parametrize('strict_basis', [False, True])
|
|
250
|
-
def test_single_qubit_cliffords_gateset(num_cliffords, use_xy_basis, strict_basis):
|
|
250
|
+
def test_single_qubit_cliffords_gateset(num_cliffords, use_xy_basis, strict_basis) -> None:
|
|
251
251
|
qubits = [GridQubit(0, i) for i in range(4)]
|
|
252
252
|
c1_in_xy = cirq.experiments.qubit_characterizations.RBParameters(
|
|
253
253
|
use_xy_basis=use_xy_basis, strict_basis=strict_basis
|
|
@@ -260,7 +260,7 @@ def test_single_qubit_cliffords_gateset(num_cliffords, use_xy_basis, strict_basi
|
|
|
260
260
|
qubits, num_cliffords, c1_in_xy
|
|
261
261
|
)
|
|
262
262
|
device = cirq.testing.ValidatingTestDevice(
|
|
263
|
-
qubits=qubits, allowed_gates=(cirq.ops.PhasedXZGate, cirq.MeasurementGate)
|
|
263
|
+
qubits=set(qubits), allowed_gates=(cirq.ops.PhasedXZGate, cirq.MeasurementGate)
|
|
264
264
|
)
|
|
265
265
|
device.validate_circuit(c)
|
|
266
266
|
|
|
@@ -38,7 +38,7 @@ from cirq.experiments.random_quantum_circuit_generation import (
|
|
|
38
38
|
SINGLE_QUBIT_LAYER = dict[cirq.GridQubit, cirq.Gate | None]
|
|
39
39
|
|
|
40
40
|
|
|
41
|
-
def test_random_rotation_between_two_qubit_circuit():
|
|
41
|
+
def test_random_rotation_between_two_qubit_circuit() -> None:
|
|
42
42
|
q0, q1 = cirq.LineQubit.range(2)
|
|
43
43
|
circuit = random_rotations_between_two_qubit_circuit(q0, q1, 4, seed=52)
|
|
44
44
|
assert len(circuit) == 4 * 2 + 1
|
|
@@ -75,7 +75,7 @@ X^0.5 PhX(0.25)^0.5
|
|
|
75
75
|
)
|
|
76
76
|
|
|
77
77
|
|
|
78
|
-
def test_generate_library_of_2q_circuits():
|
|
78
|
+
def test_generate_library_of_2q_circuits() -> None:
|
|
79
79
|
circuits = generate_library_of_2q_circuits(
|
|
80
80
|
n_library_circuits=5, two_qubit_gate=cirq.CNOT, max_cycle_depth=13, random_state=9
|
|
81
81
|
)
|
|
@@ -89,7 +89,7 @@ def test_generate_library_of_2q_circuits():
|
|
|
89
89
|
assert m2.operations[0].gate == cirq.CNOT
|
|
90
90
|
|
|
91
91
|
|
|
92
|
-
def test_generate_library_of_2q_circuits_custom_qubits():
|
|
92
|
+
def test_generate_library_of_2q_circuits_custom_qubits() -> None:
|
|
93
93
|
circuits = generate_library_of_2q_circuits(
|
|
94
94
|
n_library_circuits=5,
|
|
95
95
|
two_qubit_gate=cirq.ISWAP**0.5,
|
|
@@ -117,7 +117,7 @@ def _gridqubits_to_graph_device(qubits: Iterable[cirq.GridQubit]):
|
|
|
117
117
|
)
|
|
118
118
|
|
|
119
119
|
|
|
120
|
-
def test_get_random_combinations_for_device():
|
|
120
|
+
def test_get_random_combinations_for_device() -> None:
|
|
121
121
|
graph = _gridqubits_to_graph_device(cirq.GridQubit.rect(3, 3))
|
|
122
122
|
n_combinations = 4
|
|
123
123
|
combinations = get_random_combinations_for_device(
|
|
@@ -136,7 +136,7 @@ def test_get_random_combinations_for_device():
|
|
|
136
136
|
assert cirq.experiments.HALF_GRID_STAGGERED_PATTERN[i] == comb.layer
|
|
137
137
|
|
|
138
138
|
|
|
139
|
-
def test_get_random_combinations_for_small_device():
|
|
139
|
+
def test_get_random_combinations_for_small_device() -> None:
|
|
140
140
|
graph = _gridqubits_to_graph_device(cirq.GridQubit.rect(3, 1))
|
|
141
141
|
n_combinations = 4
|
|
142
142
|
combinations = get_random_combinations_for_device(
|
|
@@ -145,7 +145,8 @@ def test_get_random_combinations_for_small_device():
|
|
|
145
145
|
assert len(combinations) == 2 # 3x1 device only fits two layers
|
|
146
146
|
|
|
147
147
|
|
|
148
|
-
def test_get_random_combinations_for_pairs():
|
|
148
|
+
def test_get_random_combinations_for_pairs() -> None:
|
|
149
|
+
all_pairs: list[list[tuple[cirq.Qid, cirq.Qid]]]
|
|
149
150
|
all_pairs = [
|
|
150
151
|
[(cirq.LineQubit(0), cirq.LineQubit(1)), (cirq.LineQubit(2), cirq.LineQubit(3))],
|
|
151
152
|
[(cirq.LineQubit(1), cirq.LineQubit(2))],
|
|
@@ -167,7 +168,11 @@ def test_get_random_combinations_for_pairs():
|
|
|
167
168
|
assert comb.pairs == all_pairs[i]
|
|
168
169
|
|
|
169
170
|
|
|
170
|
-
def test_get_random_combinations_for_layer_circuit():
|
|
171
|
+
def test_get_random_combinations_for_layer_circuit() -> None:
|
|
172
|
+
q0: cirq.Qid
|
|
173
|
+
q1: cirq.Qid
|
|
174
|
+
q2: cirq.Qid
|
|
175
|
+
q3: cirq.Qid
|
|
171
176
|
q0, q1, q2, q3 = cirq.LineQubit.range(4)
|
|
172
177
|
circuit = cirq.Circuit(cirq.CNOT(q0, q1), cirq.CNOT(q2, q3), cirq.CNOT(q1, q2))
|
|
173
178
|
combinations = get_random_combinations_for_layer_circuit(
|
|
@@ -186,7 +191,7 @@ def test_get_random_combinations_for_layer_circuit():
|
|
|
186
191
|
assert comb.layer == circuit.moments[i]
|
|
187
192
|
|
|
188
193
|
|
|
189
|
-
def test_get_random_combinations_for_bad_layer_circuit():
|
|
194
|
+
def test_get_random_combinations_for_bad_layer_circuit() -> None:
|
|
190
195
|
q0, q1, q2, q3 = cirq.LineQubit.range(4)
|
|
191
196
|
circuit = cirq.Circuit(
|
|
192
197
|
cirq.H.on_each(q0, q1, q2, q3), cirq.CNOT(q0, q1), cirq.CNOT(q2, q3), cirq.CNOT(q1, q2)
|
|
@@ -198,7 +203,7 @@ def test_get_random_combinations_for_bad_layer_circuit():
|
|
|
198
203
|
)
|
|
199
204
|
|
|
200
205
|
|
|
201
|
-
def test_get_grid_interaction_layer_circuit():
|
|
206
|
+
def test_get_grid_interaction_layer_circuit() -> None:
|
|
202
207
|
graph = _gridqubits_to_graph_device(cirq.GridQubit.rect(3, 3))
|
|
203
208
|
layer_circuit = get_grid_interaction_layer_circuit(graph)
|
|
204
209
|
|
|
@@ -225,7 +230,7 @@ def test_get_grid_interaction_layer_circuit():
|
|
|
225
230
|
assert layer_circuit == should_be
|
|
226
231
|
|
|
227
232
|
|
|
228
|
-
def test_random_combinations_layer_circuit_vs_device():
|
|
233
|
+
def test_random_combinations_layer_circuit_vs_device() -> None:
|
|
229
234
|
# Random combinations from layer circuit is the same as getting it directly from graph
|
|
230
235
|
graph = _gridqubits_to_graph_device(cirq.GridQubit.rect(3, 3))
|
|
231
236
|
layer_circuit = get_grid_interaction_layer_circuit(graph)
|
|
@@ -373,7 +378,7 @@ def test_random_rotations_between_grid_interaction_layers(
|
|
|
373
378
|
expected_circuit_length: int,
|
|
374
379
|
single_qubit_layers_slice: slice,
|
|
375
380
|
two_qubit_layers_slice: slice,
|
|
376
|
-
):
|
|
381
|
+
) -> None:
|
|
377
382
|
qubits = set(qubits)
|
|
378
383
|
circuit = random_rotations_between_grid_interaction_layers_circuit(
|
|
379
384
|
qubits,
|
|
@@ -396,7 +401,7 @@ def test_random_rotations_between_grid_interaction_layers(
|
|
|
396
401
|
)
|
|
397
402
|
|
|
398
403
|
|
|
399
|
-
def test_grid_interaction_layer_repr():
|
|
404
|
+
def test_grid_interaction_layer_repr() -> None:
|
|
400
405
|
layer = GridInteractionLayer(col_offset=0, vertical=True, stagger=False)
|
|
401
406
|
assert repr(layer) == (
|
|
402
407
|
'cirq.experiments.GridInteractionLayer(col_offset=0, vertical=True, stagger=False)'
|
|
@@ -462,7 +467,7 @@ def _coupled_qubit_pairs(
|
|
|
462
467
|
return pairs
|
|
463
468
|
|
|
464
469
|
|
|
465
|
-
def test_generate_library_of_2q_circuits_with_tags():
|
|
470
|
+
def test_generate_library_of_2q_circuits_with_tags() -> None:
|
|
466
471
|
circuits = generate_library_of_2q_circuits(
|
|
467
472
|
n_library_circuits=5,
|
|
468
473
|
two_qubit_gate=cirq.FSimGate(3, 4),
|
|
@@ -14,6 +14,8 @@
|
|
|
14
14
|
|
|
15
15
|
from __future__ import annotations
|
|
16
16
|
|
|
17
|
+
from typing import Sequence
|
|
18
|
+
|
|
17
19
|
import numpy as np
|
|
18
20
|
import pytest
|
|
19
21
|
|
|
@@ -49,7 +51,7 @@ def add_readout_error(
|
|
|
49
51
|
return noisy_measurements.astype(int)
|
|
50
52
|
|
|
51
53
|
|
|
52
|
-
def get_expected_cm(num_qubits: int, p0: float, p1: float):
|
|
54
|
+
def get_expected_cm(num_qubits: int, p0: float, p1: float) -> np.ndarray:
|
|
53
55
|
expected_cm = np.zeros((2**num_qubits,) * 2)
|
|
54
56
|
for i in range(2**num_qubits):
|
|
55
57
|
for j in range(2**num_qubits):
|
|
@@ -66,7 +68,7 @@ def get_expected_cm(num_qubits: int, p0: float, p1: float):
|
|
|
66
68
|
|
|
67
69
|
|
|
68
70
|
@pytest.mark.parametrize('p0, p1', [(0, 0), (0.2, 0.4), (0.5, 0.5), (0.6, 0.3), (1.0, 1.0)])
|
|
69
|
-
def test_measure_confusion_matrix_with_noise(p0, p1):
|
|
71
|
+
def test_measure_confusion_matrix_with_noise(p0, p1) -> None:
|
|
70
72
|
sampler = NoisySingleQubitReadoutSampler(p0, p1, seed=1234)
|
|
71
73
|
num_qubits = 4
|
|
72
74
|
qubits = cirq.LineQubit.range(num_qubits)
|
|
@@ -113,8 +115,8 @@ def test_measure_confusion_matrix_with_noise(p0, p1):
|
|
|
113
115
|
assert l2norm(corrected_result) <= l2norm(sampled_result)
|
|
114
116
|
|
|
115
117
|
|
|
116
|
-
def test_from_measurement():
|
|
117
|
-
qubits = cirq.LineQubit.range(3)
|
|
118
|
+
def test_from_measurement() -> None:
|
|
119
|
+
qubits: Sequence[cirq.Qid] = cirq.LineQubit.range(3)
|
|
118
120
|
confuse_02 = np.array([[0, 1, 0, 0], [0, 0, 0, 1], [1, 0, 0, 0], [0, 0, 1, 0]])
|
|
119
121
|
confuse_1 = np.array([[0, 1], [1, 0]])
|
|
120
122
|
op = cirq.measure(
|
|
@@ -123,6 +125,7 @@ def test_from_measurement():
|
|
|
123
125
|
invert_mask=(True, False),
|
|
124
126
|
confusion_map={(0, 2): confuse_02, (1,): confuse_1},
|
|
125
127
|
)
|
|
128
|
+
assert isinstance(op.gate, cirq.MeasurementGate)
|
|
126
129
|
tcm = cirq.TensoredConfusionMatrices.from_measurement(op.gate, op.qubits)
|
|
127
130
|
expected_tcm = cirq.TensoredConfusionMatrices(
|
|
128
131
|
[confuse_02, confuse_1], ((qubits[0], qubits[2]), (qubits[1],)), repetitions=0, timestamp=0
|
|
@@ -130,11 +133,12 @@ def test_from_measurement():
|
|
|
130
133
|
assert tcm == expected_tcm
|
|
131
134
|
|
|
132
135
|
no_cm_op = cirq.measure(*qubits, key='a')
|
|
136
|
+
assert isinstance(no_cm_op.gate, cirq.MeasurementGate)
|
|
133
137
|
with pytest.raises(ValueError, match="Measurement has no confusion matrices"):
|
|
134
138
|
_ = cirq.TensoredConfusionMatrices.from_measurement(no_cm_op.gate, no_cm_op.qubits)
|
|
135
139
|
|
|
136
140
|
|
|
137
|
-
def test_readout_confusion_matrix_raises():
|
|
141
|
+
def test_readout_confusion_matrix_raises() -> None:
|
|
138
142
|
num_qubits = 2
|
|
139
143
|
confusion_matrix = get_expected_cm(num_qubits, 0.1, 0.2)
|
|
140
144
|
qubits = cirq.LineQubit.range(4)
|
|
@@ -174,7 +178,7 @@ def test_readout_confusion_matrix_raises():
|
|
|
174
178
|
_ = readout_cm.apply(np.asarray([1 / 16] * 16), method='l1norm')
|
|
175
179
|
|
|
176
180
|
|
|
177
|
-
def test_readout_confusion_matrix_repr_and_equality():
|
|
181
|
+
def test_readout_confusion_matrix_repr_and_equality() -> None:
|
|
178
182
|
mat1 = cirq.testing.random_orthogonal(4, random_state=1234)
|
|
179
183
|
mat2 = cirq.testing.random_orthogonal(2, random_state=1234)
|
|
180
184
|
q = cirq.LineQubit.range(3)
|
|
@@ -245,8 +249,8 @@ def _add_noise_and_mitigate_ghz(
|
|
|
245
249
|
return (*tcm.readout_mitigation_pauli_uncorrelated(qubits, noisy_measurements), z, dz)
|
|
246
250
|
|
|
247
251
|
|
|
248
|
-
def test_uncorrelated_readout_mitigation_pauli():
|
|
249
|
-
n_all =
|
|
252
|
+
def test_uncorrelated_readout_mitigation_pauli() -> None:
|
|
253
|
+
n_all = list(range(2, 35))
|
|
250
254
|
z_all_mit = []
|
|
251
255
|
dz_all_mit = []
|
|
252
256
|
z_all_raw = []
|