cirq-core 1.7.0.dev20250807224154__py3-none-any.whl → 1.7.0.dev20250812021254__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.

Files changed (59) hide show
  1. cirq/_version.py +1 -1
  2. cirq/_version_test.py +1 -1
  3. cirq/contrib/noise_models/noise_models.py +8 -8
  4. cirq/contrib/quimb/grid_circuits.py +1 -1
  5. cirq/contrib/quimb/grid_circuits_test.py +10 -5
  6. cirq/contrib/quimb/mps_simulator.py +3 -3
  7. cirq/contrib/quimb/mps_simulator_test.py +41 -42
  8. cirq/contrib/quimb/state_vector_test.py +14 -13
  9. cirq/contrib/quirk/export_to_quirk_test.py +2 -2
  10. cirq/contrib/quirk/linearize_circuit.py +1 -1
  11. cirq/contrib/routing/device.py +1 -1
  12. cirq/contrib/routing/device_test.py +7 -5
  13. cirq/contrib/routing/greedy_test.py +7 -2
  14. cirq/contrib/routing/initialization_test.py +1 -1
  15. cirq/contrib/routing/router_test.py +9 -10
  16. cirq/contrib/routing/swap_network_test.py +10 -4
  17. cirq/contrib/routing/utils_test.py +4 -4
  18. cirq/contrib/shuffle_circuits/shuffle_circuits_with_readout_benchmarking.py +9 -9
  19. cirq/contrib/shuffle_circuits/shuffle_circuits_with_readout_benchmarking_test.py +18 -16
  20. cirq/contrib/svg/svg.py +1 -1
  21. cirq/devices/grid_device_metadata_test.py +12 -12
  22. cirq/devices/grid_qubit_test.py +52 -52
  23. cirq/devices/line_qubit_test.py +37 -37
  24. cirq/devices/named_topologies.py +7 -5
  25. cirq/devices/named_topologies_test.py +3 -2
  26. cirq/devices/noise_model.py +1 -1
  27. cirq/devices/noise_properties_test.py +1 -1
  28. cirq/devices/noise_utils.py +1 -1
  29. cirq/devices/noise_utils_test.py +6 -6
  30. cirq/devices/superconducting_qubits_noise_properties_test.py +31 -24
  31. cirq/devices/thermal_noise_model_test.py +48 -44
  32. cirq/devices/unconstrained_device.py +1 -1
  33. cirq/devices/unconstrained_device_test.py +3 -3
  34. cirq/experiments/benchmarking/parallel_xeb.py +24 -17
  35. cirq/experiments/benchmarking/parallel_xeb_test.py +42 -28
  36. cirq/experiments/fidelity_estimation.py +5 -5
  37. cirq/experiments/fidelity_estimation_test.py +7 -7
  38. cirq/experiments/purity_estimation.py +1 -1
  39. cirq/experiments/purity_estimation_test.py +1 -1
  40. cirq/experiments/qubit_characterizations_test.py +10 -10
  41. cirq/experiments/random_quantum_circuit_generation.py +1 -1
  42. cirq/experiments/random_quantum_circuit_generation_test.py +18 -13
  43. cirq/experiments/readout_confusion_matrix_test.py +12 -8
  44. cirq/experiments/single_qubit_readout_calibration_test.py +13 -13
  45. cirq/experiments/t2_decay_experiment.py +1 -1
  46. cirq/experiments/t2_decay_experiment_test.py +13 -13
  47. cirq/experiments/two_qubit_xeb_test.py +20 -22
  48. cirq/experiments/xeb_fitting.py +3 -3
  49. cirq/experiments/xeb_fitting_test.py +21 -19
  50. cirq/experiments/xeb_sampling.py +2 -2
  51. cirq/experiments/xeb_sampling_test.py +9 -9
  52. cirq/experiments/xeb_simulation.py +1 -1
  53. cirq/experiments/xeb_simulation_test.py +6 -6
  54. cirq/ops/measure_util.py +2 -0
  55. {cirq_core-1.7.0.dev20250807224154.dist-info → cirq_core-1.7.0.dev20250812021254.dist-info}/METADATA +1 -1
  56. {cirq_core-1.7.0.dev20250807224154.dist-info → cirq_core-1.7.0.dev20250812021254.dist-info}/RECORD +59 -59
  57. {cirq_core-1.7.0.dev20250807224154.dist-info → cirq_core-1.7.0.dev20250812021254.dist-info}/WHEEL +0 -0
  58. {cirq_core-1.7.0.dev20250807224154.dist-info → cirq_core-1.7.0.dev20250812021254.dist-info}/licenses/LICENSE +0 -0
  59. {cirq_core-1.7.0.dev20250807224154.dist-info → cirq_core-1.7.0.dev20250812021254.dist-info}/top_level.txt +0 -0
@@ -22,7 +22,7 @@ import pytest
22
22
  import cirq
23
23
 
24
24
 
25
- def test_single_qubit_readout_result_repr():
25
+ def test_single_qubit_readout_result_repr() -> None:
26
26
  result = cirq.experiments.SingleQubitReadoutCalibrationResult(
27
27
  zero_state_errors={cirq.LineQubit(0): 0.1},
28
28
  one_state_errors={cirq.LineQubit(0): 0.2},
@@ -61,7 +61,7 @@ class NoisySingleQubitReadoutSampler(cirq.Sampler):
61
61
  return results
62
62
 
63
63
 
64
- def test_estimate_single_qubit_readout_errors_no_noise():
64
+ def test_estimate_single_qubit_readout_errors_no_noise() -> None:
65
65
  qubits = cirq.LineQubit.range(10)
66
66
  sampler = cirq.Simulator()
67
67
  repetitions = 1000
@@ -74,7 +74,7 @@ def test_estimate_single_qubit_readout_errors_no_noise():
74
74
  assert isinstance(result.timestamp, float)
75
75
 
76
76
 
77
- def test_estimate_single_qubit_readout_errors_with_noise():
77
+ def test_estimate_single_qubit_readout_errors_with_noise() -> None:
78
78
  qubits = cirq.LineQubit.range(5)
79
79
  sampler = NoisySingleQubitReadoutSampler(p0=0.1, p1=0.2, seed=1234)
80
80
  repetitions = 1000
@@ -89,7 +89,7 @@ def test_estimate_single_qubit_readout_errors_with_noise():
89
89
  assert isinstance(result.timestamp, float)
90
90
 
91
91
 
92
- def test_estimate_parallel_readout_errors_no_noise():
92
+ def test_estimate_parallel_readout_errors_no_noise() -> None:
93
93
  qubits = [cirq.GridQubit(i, 0) for i in range(10)]
94
94
  sampler = cirq.Simulator()
95
95
  repetitions = 1000
@@ -104,7 +104,7 @@ def test_estimate_parallel_readout_errors_no_noise():
104
104
  _, _ = result.plot_heatmap()
105
105
 
106
106
 
107
- def test_estimate_parallel_readout_errors_all_zeros():
107
+ def test_estimate_parallel_readout_errors_all_zeros() -> None:
108
108
  qubits = cirq.LineQubit.range(10)
109
109
  sampler = cirq.ZerosSampler()
110
110
  repetitions = 1000
@@ -117,7 +117,7 @@ def test_estimate_parallel_readout_errors_all_zeros():
117
117
  assert isinstance(result.timestamp, float)
118
118
 
119
119
 
120
- def test_estimate_parallel_readout_errors_bad_bit_string():
120
+ def test_estimate_parallel_readout_errors_bad_bit_string() -> None:
121
121
  qubits = cirq.LineQubit.range(4)
122
122
  with pytest.raises(ValueError, match='but was None'):
123
123
  _ = cirq.estimate_parallel_single_qubit_readout_errors(
@@ -126,7 +126,7 @@ def test_estimate_parallel_readout_errors_bad_bit_string():
126
126
  repetitions=1000,
127
127
  trials=35,
128
128
  trials_per_batch=10,
129
- bit_strings=[[1] * 4],
129
+ bit_strings=[[1] * 4], # type: ignore[arg-type]
130
130
  )
131
131
  with pytest.raises(ValueError, match='0 or 1'):
132
132
  _ = cirq.estimate_parallel_single_qubit_readout_errors(
@@ -138,7 +138,7 @@ def test_estimate_parallel_readout_errors_bad_bit_string():
138
138
  )
139
139
 
140
140
 
141
- def test_estimate_parallel_readout_errors_zero_reps():
141
+ def test_estimate_parallel_readout_errors_zero_reps() -> None:
142
142
  qubits = cirq.LineQubit.range(10)
143
143
  with pytest.raises(ValueError, match='non-zero repetition'):
144
144
  _ = cirq.estimate_parallel_single_qubit_readout_errors(
@@ -146,7 +146,7 @@ def test_estimate_parallel_readout_errors_zero_reps():
146
146
  )
147
147
 
148
148
 
149
- def test_estimate_parallel_readout_errors_zero_trials():
149
+ def test_estimate_parallel_readout_errors_zero_trials() -> None:
150
150
  qubits = cirq.LineQubit.range(10)
151
151
  with pytest.raises(ValueError, match='non-zero trials'):
152
152
  _ = cirq.estimate_parallel_single_qubit_readout_errors(
@@ -154,7 +154,7 @@ def test_estimate_parallel_readout_errors_zero_trials():
154
154
  )
155
155
 
156
156
 
157
- def test_estimate_parallel_readout_errors_zero_batch():
157
+ def test_estimate_parallel_readout_errors_zero_batch() -> None:
158
158
  qubits = cirq.LineQubit.range(10)
159
159
  with pytest.raises(ValueError, match='non-zero trials_per_batch'):
160
160
  _ = cirq.estimate_parallel_single_qubit_readout_errors(
@@ -162,7 +162,7 @@ def test_estimate_parallel_readout_errors_zero_batch():
162
162
  )
163
163
 
164
164
 
165
- def test_estimate_parallel_readout_errors_batching():
165
+ def test_estimate_parallel_readout_errors_batching() -> None:
166
166
  qubits = cirq.LineQubit.range(5)
167
167
  sampler = cirq.ZerosSampler()
168
168
  repetitions = 1000
@@ -175,7 +175,7 @@ def test_estimate_parallel_readout_errors_batching():
175
175
  assert isinstance(result.timestamp, float)
176
176
 
177
177
 
178
- def test_estimate_parallel_readout_errors_with_noise():
178
+ def test_estimate_parallel_readout_errors_with_noise() -> None:
179
179
  qubits = cirq.LineQubit.range(5)
180
180
  sampler = NoisySingleQubitReadoutSampler(p0=0.1, p1=0.2, seed=1234)
181
181
  repetitions = 1000
@@ -190,7 +190,7 @@ def test_estimate_parallel_readout_errors_with_noise():
190
190
  assert isinstance(result.timestamp, float)
191
191
 
192
192
 
193
- def test_estimate_parallel_readout_errors_missing_qubits():
193
+ def test_estimate_parallel_readout_errors_missing_qubits() -> None:
194
194
  qubits = cirq.LineQubit.range(4)
195
195
 
196
196
  result = cirq.estimate_parallel_single_qubit_readout_errors(
@@ -48,7 +48,7 @@ def t2_decay(
48
48
  repetitions: int = 1000,
49
49
  delay_sweep: study.Sweep | None = None,
50
50
  num_pulses: list[int] | None = None,
51
- ) -> cirq.experiments.T2DecayResult | list[cirq.experiments.T2DecayResult]:
51
+ ) -> cirq.experiments.T2DecayResult:
52
52
  """Runs a t2 transverse relaxation experiment.
53
53
 
54
54
  Initializes a qubit into a superposition state, evolves the system using
@@ -22,7 +22,7 @@ import cirq
22
22
  import cirq.experiments.t2_decay_experiment as t2
23
23
 
24
24
 
25
- def test_init_t2_decay_result():
25
+ def test_init_t2_decay_result() -> None:
26
26
  x_data = pd.DataFrame(
27
27
  columns=['delay_ns', 0, 1], index=range(2), data=[[100.0, 0, 10], [1000.0, 10, 0]]
28
28
  )
@@ -42,7 +42,7 @@ def test_init_t2_decay_result():
42
42
 
43
43
 
44
44
  @pytest.mark.usefixtures('closefigures')
45
- def test_plot_does_not_raise_error():
45
+ def test_plot_does_not_raise_error() -> None:
46
46
  class _TimeDependentDecay(cirq.NoiseModel):
47
47
  def noisy_moment(self, moment, system_qubits):
48
48
  duration = max(
@@ -67,7 +67,7 @@ def test_plot_does_not_raise_error():
67
67
  results.plot_bloch_vector()
68
68
 
69
69
 
70
- def test_result_eq():
70
+ def test_result_eq() -> None:
71
71
  example_data = pd.DataFrame(
72
72
  columns=['delay_ns', 0, 1],
73
73
  index=range(5),
@@ -85,7 +85,7 @@ def test_result_eq():
85
85
  eq.add_equality_group(cirq.experiments.T2DecayResult(example_data, other_data))
86
86
 
87
87
 
88
- def test_sudden_decay_results():
88
+ def test_sudden_decay_results() -> None:
89
89
  class _SuddenDecay(cirq.NoiseModel):
90
90
  def noisy_moment(self, moment, system_qubits):
91
91
  duration = max(
@@ -117,7 +117,7 @@ def test_sudden_decay_results():
117
117
 
118
118
 
119
119
  @pytest.mark.parametrize('experiment_type', [t2.ExperimentType.HAHN_ECHO, t2.ExperimentType.CPMG])
120
- def test_spin_echo_cancels_out_constant_rate_phase(experiment_type):
120
+ def test_spin_echo_cancels_out_constant_rate_phase(experiment_type) -> None:
121
121
  class _TimeDependentPhase(cirq.NoiseModel):
122
122
  def noisy_moment(self, moment, system_qubits):
123
123
  duration = max(
@@ -151,7 +151,7 @@ def test_spin_echo_cancels_out_constant_rate_phase(experiment_type):
151
151
  'experiment_type',
152
152
  [t2.ExperimentType.RAMSEY, t2.ExperimentType.HAHN_ECHO, t2.ExperimentType.CPMG],
153
153
  )
154
- def test_all_on_results(experiment_type):
154
+ def test_all_on_results(experiment_type) -> None:
155
155
  pulses = [1] if experiment_type == t2.ExperimentType.CPMG else None
156
156
  results = t2.t2_decay(
157
157
  sampler=cirq.Simulator(),
@@ -174,7 +174,7 @@ def test_all_on_results(experiment_type):
174
174
  'experiment_type',
175
175
  [t2.ExperimentType.RAMSEY, t2.ExperimentType.HAHN_ECHO, t2.ExperimentType.CPMG],
176
176
  )
177
- def test_all_off_results(experiment_type):
177
+ def test_all_off_results(experiment_type) -> None:
178
178
  pulses = [1] if experiment_type == t2.ExperimentType.CPMG else None
179
179
  results = t2.t2_decay(
180
180
  sampler=cirq.DensityMatrixSimulator(noise=cirq.amplitude_damp(1)),
@@ -204,7 +204,7 @@ def test_all_off_results(experiment_type):
204
204
  'experiment_type',
205
205
  [t2.ExperimentType.RAMSEY, t2.ExperimentType.HAHN_ECHO, t2.ExperimentType.CPMG],
206
206
  )
207
- def test_custom_delay_sweep(experiment_type):
207
+ def test_custom_delay_sweep(experiment_type) -> None:
208
208
  pulses = [1] if experiment_type == t2.ExperimentType.CPMG else None
209
209
  results = t2.t2_decay(
210
210
  sampler=cirq.DensityMatrixSimulator(noise=cirq.amplitude_damp(1)),
@@ -231,7 +231,7 @@ def test_custom_delay_sweep(experiment_type):
231
231
  )
232
232
 
233
233
 
234
- def test_multiple_pulses():
234
+ def test_multiple_pulses() -> None:
235
235
  results = t2.t2_decay(
236
236
  sampler=cirq.DensityMatrixSimulator(noise=cirq.amplitude_damp(1)),
237
237
  qubit=cirq.GridQubit(0, 0),
@@ -302,7 +302,7 @@ def test_multiple_pulses():
302
302
  assert results.expectation_pauli_x.equals(expected)
303
303
 
304
304
 
305
- def test_bad_args():
305
+ def test_bad_args() -> None:
306
306
  with pytest.raises(ValueError, match='repetitions <= 0'):
307
307
  _ = cirq.experiments.t2_decay(
308
308
  sampler=cirq.Simulator(),
@@ -388,7 +388,7 @@ def test_bad_args():
388
388
  )
389
389
 
390
390
 
391
- def test_cpmg_circuit():
391
+ def test_cpmg_circuit() -> None:
392
392
  """Tests sub-component to make sure CPMG circuit is generated correctly."""
393
393
  q = cirq.GridQubit(1, 1)
394
394
  t = sympy.Symbol('t')
@@ -406,7 +406,7 @@ def test_cpmg_circuit():
406
406
  assert circuit == expected
407
407
 
408
408
 
409
- def test_cpmg_sweep():
409
+ def test_cpmg_sweep() -> None:
410
410
  sweep = t2._cpmg_sweep([1, 3, 5])
411
411
  expected = cirq.Zip(
412
412
  cirq.Points('pulse_0', [1, 1, 1]),
@@ -418,7 +418,7 @@ def test_cpmg_sweep():
418
418
  assert sweep == expected
419
419
 
420
420
 
421
- def test_str():
421
+ def test_str() -> None:
422
422
  x_data = pd.DataFrame(
423
423
  columns=['delay_ns', 0, 1], index=range(2), data=[[100.0, 0, 10], [1000.0, 10, 0]]
424
424
  )
@@ -36,7 +36,7 @@ def _manhattan_distance(qubit1: cirq.GridQubit, qubit2: cirq.GridQubit) -> int:
36
36
 
37
37
  class MockDevice(cirq.Device):
38
38
  @property
39
- def metadata(self):
39
+ def metadata(self) -> cirq.DeviceMetadata:
40
40
  qubits = cirq.GridQubit.rect(3, 2, 4, 3)
41
41
  graph = nx.Graph(
42
42
  pair for pair in itertools.combinations(qubits, 2) if _manhattan_distance(*pair) == 1
@@ -45,21 +45,19 @@ class MockDevice(cirq.Device):
45
45
 
46
46
 
47
47
  class MockProcessor:
48
- def get_device(self):
48
+ def get_device(self) -> MockDevice:
49
49
  return MockDevice()
50
50
 
51
51
 
52
52
  class DensityMatrixSimulatorWithProcessor(cirq.DensityMatrixSimulator):
53
53
  @property
54
- def processor(self):
54
+ def processor(self) -> MockProcessor:
55
55
  return MockProcessor()
56
56
 
57
57
 
58
- def test_parallel_two_qubit_xeb_simulator_without_processor_fails():
59
- sampler = (
60
- cirq.DensityMatrixSimulator(
61
- seed=0, noise=cirq.ConstantQubitNoiseModel(cirq.amplitude_damp(0.1))
62
- ),
58
+ def test_parallel_two_qubit_xeb_simulator_without_processor_fails() -> None:
59
+ sampler = cirq.DensityMatrixSimulator(
60
+ seed=0, noise=cirq.ConstantQubitNoiseModel(cirq.amplitude_damp(0.1))
63
61
  )
64
62
 
65
63
  with pytest.raises(ValueError):
@@ -90,7 +88,9 @@ def test_parallel_two_qubit_xeb_simulator_without_processor_fails():
90
88
  ),
91
89
  ],
92
90
  )
93
- def test_parallel_two_qubit_xeb(sampler: cirq.Sampler, qubits: Sequence[cirq.GridQubit] | None):
91
+ def test_parallel_two_qubit_xeb(
92
+ sampler: cirq.Sampler, qubits: Sequence[cirq.GridQubit] | None
93
+ ) -> None:
94
94
  res = cirq.experiments.parallel_two_qubit_xeb(
95
95
  sampler=sampler,
96
96
  qubits=qubits,
@@ -114,7 +114,7 @@ def test_parallel_two_qubit_xeb(sampler: cirq.Sampler, qubits: Sequence[cirq.Gri
114
114
  ],
115
115
  )
116
116
  @pytest.mark.parametrize('ax', [None, plt.subplots(1, 1, figsize=(8, 8))[1]])
117
- def test_plotting(sampler, qubits, ax):
117
+ def test_plotting(sampler, qubits, ax) -> None:
118
118
  res = cirq.experiments.parallel_two_qubit_xeb(
119
119
  sampler=sampler,
120
120
  qubits=qubits,
@@ -157,7 +157,7 @@ _TEST_RESULT = cirq.experiments.TwoQubitXEBResult(
157
157
  (cirq.GridQubit(6, 3), cirq.GridQubit(6, 4), 0.46875),
158
158
  ],
159
159
  )
160
- def test_pauli_error(q0: cirq.GridQubit, q1: cirq.GridQubit, pauli: float):
160
+ def test_pauli_error(q0: cirq.GridQubit, q1: cirq.GridQubit, pauli: float) -> None:
161
161
  assert _TEST_RESULT.pauli_error()[(q0, q1)] == pytest.approx(pauli)
162
162
 
163
163
 
@@ -183,7 +183,7 @@ class MockParallelRandomizedBenchmarkingResult(ParallelRandomizedBenchmarkingRes
183
183
  (cirq.GridQubit(6, 3), cirq.GridQubit(6, 4), 0.46875 - 0.13),
184
184
  ],
185
185
  )
186
- def test_inferred_pauli_error(q0: cirq.GridQubit, q1: cirq.GridQubit, pauli: float):
186
+ def test_inferred_pauli_error(q0: cirq.GridQubit, q1: cirq.GridQubit, pauli: float) -> None:
187
187
  combined_results = cirq.experiments.InferredXEBResult(
188
188
  rb_result=MockParallelRandomizedBenchmarkingResult({}), xeb_result=_TEST_RESULT
189
189
  )
@@ -200,7 +200,7 @@ def test_inferred_pauli_error(q0: cirq.GridQubit, q1: cirq.GridQubit, pauli: flo
200
200
  (cirq.GridQubit(6, 3), cirq.GridQubit(6, 4), 0.2709999999999999),
201
201
  ],
202
202
  )
203
- def test_inferred_xeb_error(q0: cirq.GridQubit, q1: cirq.GridQubit, xeb: float):
203
+ def test_inferred_xeb_error(q0: cirq.GridQubit, q1: cirq.GridQubit, xeb: float) -> None:
204
204
  combined_results = cirq.experiments.InferredXEBResult(
205
205
  rb_result=MockParallelRandomizedBenchmarkingResult({}), xeb_result=_TEST_RESULT
206
206
  )
@@ -208,7 +208,7 @@ def test_inferred_xeb_error(q0: cirq.GridQubit, q1: cirq.GridQubit, xeb: float):
208
208
  assert combined_results.inferred_xeb_error()[(q0, q1)] == pytest.approx(xeb)
209
209
 
210
210
 
211
- def test_inferred_single_qubit_pauli():
211
+ def test_inferred_single_qubit_pauli() -> None:
212
212
  combined_results = cirq.experiments.InferredXEBResult(
213
213
  rb_result=MockParallelRandomizedBenchmarkingResult({}), xeb_result=_TEST_RESULT
214
214
  )
@@ -233,7 +233,7 @@ def test_inferred_single_qubit_pauli():
233
233
  (cirq.GridQubit(6, 3), cirq.GridQubit(6, 4), 0.46875),
234
234
  ],
235
235
  )
236
- def test_inferred_two_qubit_pauli(q0: cirq.GridQubit, q1: cirq.GridQubit, pauli: float):
236
+ def test_inferred_two_qubit_pauli(q0: cirq.GridQubit, q1: cirq.GridQubit, pauli: float) -> None:
237
237
  combined_results = cirq.experiments.InferredXEBResult(
238
238
  rb_result=MockParallelRandomizedBenchmarkingResult({}), xeb_result=_TEST_RESULT
239
239
  )
@@ -243,7 +243,7 @@ def test_inferred_two_qubit_pauli(q0: cirq.GridQubit, q1: cirq.GridQubit, pauli:
243
243
  @pytest.mark.parametrize('ax', [None, plt.subplots(1, 1, figsize=(8, 8))[1]])
244
244
  @pytest.mark.parametrize('target_error', ['pauli', 'xeb', 'decay_constant'])
245
245
  @pytest.mark.parametrize('kind', ['single_qubit', 'two_qubit', 'both', ''])
246
- def test_inferred_plots(ax, target_error, kind):
246
+ def test_inferred_plots(ax, target_error, kind) -> None:
247
247
  combined_results = cirq.experiments.InferredXEBResult(
248
248
  rb_result=MockParallelRandomizedBenchmarkingResult({}), xeb_result=_TEST_RESULT
249
249
  )
@@ -296,7 +296,7 @@ def test_run_rb_and_xeb(
296
296
  sampler: cirq.Sampler,
297
297
  qubits: Sequence[cirq.GridQubit] | None,
298
298
  pairs: Sequence[tuple[cirq.GridQubit, cirq.GridQubit]] | None,
299
- ):
299
+ ) -> None:
300
300
  res = cirq.experiments.run_rb_and_xeb(
301
301
  sampler=sampler,
302
302
  qubits=qubits,
@@ -313,11 +313,9 @@ def test_run_rb_and_xeb(
313
313
  )
314
314
 
315
315
 
316
- def test_run_rb_and_xeb_without_processor_fails():
317
- sampler = (
318
- cirq.DensityMatrixSimulator(
319
- seed=0, noise=cirq.ConstantQubitNoiseModel(cirq.amplitude_damp(0.1))
320
- ),
316
+ def test_run_rb_and_xeb_without_processor_fails() -> None:
317
+ sampler = cirq.DensityMatrixSimulator(
318
+ seed=0, noise=cirq.ConstantQubitNoiseModel(cirq.amplitude_damp(0.1))
321
319
  )
322
320
 
323
321
  with pytest.raises(ValueError):
@@ -342,7 +342,7 @@ class XEBPhasedFSimCharacterizationOptions(XEBCharacterizationOptions):
342
342
 
343
343
  return np.asarray(initial_simplex), names
344
344
 
345
- def get_parameterized_gate(self):
345
+ def get_parameterized_gate(self) -> cirq.Gate:
346
346
  theta = THETA_SYMBOL if self.characterize_theta else self.theta_default
347
347
  zeta = ZETA_SYMBOL if self.characterize_zeta else self.zeta_default
348
348
  chi = CHI_SYMBOL if self.characterize_chi else self.chi_default
@@ -374,7 +374,7 @@ class XEBPhasedFSimCharacterizationOptions(XEBCharacterizationOptions):
374
374
 
375
375
  def with_defaults_from_gate(
376
376
  self, gate: cirq.Gate, gate_to_angles_func=phased_fsim_angles_from_gate
377
- ):
377
+ ) -> XEBPhasedFSimCharacterizationOptions:
378
378
  """A new Options class with {angle}_defaults inferred from `gate`.
379
379
 
380
380
  This keeps the same settings for the characterize_{angle} booleans, but will disregard
@@ -393,7 +393,7 @@ class XEBPhasedFSimCharacterizationOptions(XEBCharacterizationOptions):
393
393
  return protocols.dataclass_json_dict(self)
394
394
 
395
395
 
396
- def SqrtISwapXEBOptions(*args, **kwargs):
396
+ def SqrtISwapXEBOptions(*args, **kwargs) -> XEBPhasedFSimCharacterizationOptions:
397
397
  """Options for calibrating a sqrt(ISWAP) gate using XEB."""
398
398
  return XEBPhasedFSimCharacterizationOptions(*args, **kwargs).with_defaults_from_gate(
399
399
  ops.SQRT_ISWAP
@@ -16,7 +16,7 @@ from __future__ import annotations
16
16
 
17
17
  import itertools
18
18
  import multiprocessing
19
- from typing import Iterable, Iterator
19
+ from typing import Iterable, Iterator, Sequence
20
20
 
21
21
  import networkx as nx
22
22
  import numpy as np
@@ -50,7 +50,7 @@ def pool() -> Iterator[multiprocessing.pool.Pool]:
50
50
 
51
51
 
52
52
  @pytest.fixture(scope='module')
53
- def circuits_cycle_depths_sampled_df():
53
+ def circuits_cycle_depths_sampled_df() -> tuple[list[cirq.Circuit], Sequence[int], pd.DataFrame]:
54
54
  q0, q1 = cirq.LineQubit.range(2)
55
55
  circuits = [
56
56
  rqcg.random_rotations_between_two_qubit_circuit(
@@ -58,7 +58,7 @@ def circuits_cycle_depths_sampled_df():
58
58
  )
59
59
  for _ in range(2)
60
60
  ]
61
- cycle_depths = np.arange(10, 40 + 1, 10)
61
+ cycle_depths = list(range(10, 40 + 1, 10))
62
62
 
63
63
  sampled_df = sample_2q_xeb_circuits(
64
64
  sampler=cirq.Simulator(seed=53), circuits=circuits, cycle_depths=cycle_depths
@@ -67,7 +67,7 @@ def circuits_cycle_depths_sampled_df():
67
67
 
68
68
 
69
69
  @pytest.mark.parametrize('pass_cycle_depths', (True, False))
70
- def test_benchmark_2q_xeb_fidelities(circuits_cycle_depths_sampled_df, pass_cycle_depths):
70
+ def test_benchmark_2q_xeb_fidelities(circuits_cycle_depths_sampled_df, pass_cycle_depths) -> None:
71
71
  circuits, cycle_depths, sampled_df = circuits_cycle_depths_sampled_df
72
72
 
73
73
  if pass_cycle_depths:
@@ -75,7 +75,7 @@ def test_benchmark_2q_xeb_fidelities(circuits_cycle_depths_sampled_df, pass_cycl
75
75
  else:
76
76
  fid_df = benchmark_2q_xeb_fidelities(sampled_df, circuits)
77
77
  assert len(fid_df) == len(cycle_depths)
78
- assert sorted(fid_df['cycle_depth'].unique()) == cycle_depths.tolist()
78
+ assert sorted(fid_df['cycle_depth'].unique()) == cycle_depths
79
79
  assert np.all(fid_df['fidelity'] > 0.98)
80
80
 
81
81
  fit_df = fit_exponential_decays(fid_df)
@@ -84,7 +84,7 @@ def test_benchmark_2q_xeb_fidelities(circuits_cycle_depths_sampled_df, pass_cycl
84
84
  assert len(row['fidelities']) == len(cycle_depths)
85
85
 
86
86
 
87
- def test_benchmark_2q_xeb_subsample_depths(circuits_cycle_depths_sampled_df):
87
+ def test_benchmark_2q_xeb_subsample_depths(circuits_cycle_depths_sampled_df) -> None:
88
88
  circuits, _, sampled_df = circuits_cycle_depths_sampled_df
89
89
  cycle_depths = [10, 20]
90
90
  fid_df = benchmark_2q_xeb_fidelities(sampled_df, circuits, cycle_depths)
@@ -114,7 +114,7 @@ def _gridqubits_to_graph_device(qubits: Iterable[cirq.GridQubit]):
114
114
  )
115
115
 
116
116
 
117
- def test_benchmark_2q_xeb_fidelities_parallel():
117
+ def test_benchmark_2q_xeb_fidelities_parallel() -> None:
118
118
  circuits = rqcg.generate_library_of_2q_circuits(
119
119
  n_library_circuits=5, two_qubit_gate=cirq.ISWAP**0.5, max_cycle_depth=4
120
120
  )
@@ -140,7 +140,7 @@ def test_benchmark_2q_xeb_fidelities_parallel():
140
140
  assert len(row['fidelities']) == len(cycle_depths)
141
141
 
142
142
 
143
- def test_benchmark_2q_xeb_fidelities_vectorized():
143
+ def test_benchmark_2q_xeb_fidelities_vectorized() -> None:
144
144
  rs = np.random.RandomState(52)
145
145
  mock_records = [{'pure_probs': rs.rand(4), 'sampled_probs': rs.rand(4)} for _ in range(100)]
146
146
  df = pd.DataFrame(mock_records)
@@ -177,7 +177,7 @@ def test_benchmark_2q_xeb_fidelities_vectorized():
177
177
 
178
178
 
179
179
  @pytest.mark.parametrize('gate', [cirq.SQRT_ISWAP, cirq.FSimGate(np.pi / 4, 0)])
180
- def test_parameterize_phased_fsim_circuit(gate):
180
+ def test_parameterize_phased_fsim_circuit(gate) -> None:
181
181
  q0, q1 = cirq.LineQubit.range(2)
182
182
  circuit = rqcg.random_rotations_between_two_qubit_circuit(
183
183
  q0, q1, depth=3, two_qubit_op_factory=lambda a, b, _: gate(a, b), seed=52
@@ -208,7 +208,7 @@ X^0.5 PhX(0.25)^0.5
208
208
  )
209
209
 
210
210
 
211
- def test_get_initial_simplex():
211
+ def test_get_initial_simplex() -> None:
212
212
  options = SqrtISwapXEBOptions()
213
213
  simplex, names = options.get_initial_simplex_and_names()
214
214
  assert names == ['theta', 'zeta', 'chi', 'gamma', 'phi']
@@ -216,7 +216,7 @@ def test_get_initial_simplex():
216
216
  assert simplex.shape[1] == len(names)
217
217
 
218
218
 
219
- def test_characterize_phased_fsim_parameters_with_xeb(pool):
219
+ def test_characterize_phased_fsim_parameters_with_xeb(pool) -> None:
220
220
  q0, q1 = cirq.LineQubit.range(2)
221
221
  rs = np.random.RandomState(52)
222
222
  circuits = [
@@ -225,7 +225,7 @@ def test_characterize_phased_fsim_parameters_with_xeb(pool):
225
225
  )
226
226
  for _ in range(2)
227
227
  ]
228
- cycle_depths = np.arange(3, 20, 6)
228
+ cycle_depths = list(range(3, 20, 6))
229
229
  sampled_df = sample_2q_xeb_circuits(
230
230
  sampler=cirq.Simulator(seed=rs),
231
231
  circuits=circuits,
@@ -260,7 +260,7 @@ def test_characterize_phased_fsim_parameters_with_xeb(pool):
260
260
 
261
261
 
262
262
  @pytest.mark.parametrize('use_pool', (True, False))
263
- def test_parallel_full_workflow(request, use_pool):
263
+ def test_parallel_full_workflow(request, use_pool) -> None:
264
264
  circuits = rqcg.generate_library_of_2q_circuits(
265
265
  n_library_circuits=5,
266
266
  two_qubit_gate=cirq.ISWAP**0.5,
@@ -320,7 +320,7 @@ def test_parallel_full_workflow(request, use_pool):
320
320
  assert 0 <= row['layer_fid_c'] <= 1
321
321
 
322
322
 
323
- def test_fit_exponential_decays():
323
+ def test_fit_exponential_decays() -> None:
324
324
  rs = np.random.RandomState(999)
325
325
  cycle_depths = np.arange(3, 100, 11)
326
326
  fidelities = 0.95 * 0.98**cycle_depths + rs.normal(0, 0.2)
@@ -330,7 +330,7 @@ def test_fit_exponential_decays():
330
330
  assert 0 < layer_fid_std < 1e-3
331
331
 
332
332
 
333
- def test_fit_exponential_decays_negative_fids():
333
+ def test_fit_exponential_decays_negative_fids() -> None:
334
334
  rs = np.random.RandomState(999)
335
335
  cycle_depths = np.arange(3, 100, 11)
336
336
  fidelities = 0.5 * 0.5**cycle_depths + rs.normal(0, 0.2) - 0.5
@@ -342,10 +342,12 @@ def test_fit_exponential_decays_negative_fids():
342
342
  assert layer_fid_std == np.inf
343
343
 
344
344
 
345
- def test_options_with_defaults_from_gate():
345
+ def test_options_with_defaults_from_gate() -> None:
346
346
  options = XEBPhasedFSimCharacterizationOptions().with_defaults_from_gate(cirq.ISWAP**0.5)
347
+ assert options.theta_default is not None
347
348
  np.testing.assert_allclose(options.theta_default, -np.pi / 4)
348
349
  options = XEBPhasedFSimCharacterizationOptions().with_defaults_from_gate(cirq.ISWAP**-0.5)
350
+ assert options.theta_default is not None
349
351
  np.testing.assert_allclose(options.theta_default, np.pi / 4)
350
352
 
351
353
  options = XEBPhasedFSimCharacterizationOptions().with_defaults_from_gate(
@@ -365,7 +367,7 @@ def test_options_with_defaults_from_gate():
365
367
  _ = XEBPhasedFSimCharacterizationOptions().with_defaults_from_gate(cirq.XX)
366
368
 
367
369
 
368
- def test_options_defaults_set():
370
+ def test_options_defaults_set() -> None:
369
371
  o1 = XEBPhasedFSimCharacterizationOptions(
370
372
  characterize_zeta=True,
371
373
  characterize_chi=True,
@@ -424,13 +426,13 @@ def _random_angles(n, seed):
424
426
  ]
425
427
  + [cirq.PhasedFSimGate(*r) for r in _random_angles(10, 0)],
426
428
  )
427
- def test_phased_fsim_angles_from_gate(gate):
429
+ def test_phased_fsim_angles_from_gate(gate) -> None:
428
430
  angles = phased_fsim_angles_from_gate(gate)
429
431
  angles = {k.removesuffix('_default'): v for k, v in angles.items()}
430
432
  phasedfsim = cirq.PhasedFSimGate(**angles)
431
433
  np.testing.assert_allclose(cirq.unitary(phasedfsim), cirq.unitary(gate), atol=1e-9)
432
434
 
433
435
 
434
- def test_phased_fsim_angles_from_gate_unsupporet_gate():
436
+ def test_phased_fsim_angles_from_gate_unsupporet_gate() -> None:
435
437
  with pytest.raises(ValueError, match='Unknown default angles'):
436
438
  _ = phased_fsim_angles_from_gate(cirq.testing.TwoQubitGate())
@@ -159,7 +159,7 @@ class _ZippedCircuit:
159
159
  """
160
160
 
161
161
  wide_circuit: cirq.Circuit
162
- pairs: list[tuple[cirq.Qid, cirq.Qid]]
162
+ pairs: Sequence[tuple[cirq.Qid, cirq.Qid]]
163
163
  combination: list[int]
164
164
  layer_i: int
165
165
  combination_i: int
@@ -291,7 +291,7 @@ def sample_2q_xeb_circuits(
291
291
  combinations_by_layer: list[CircuitLibraryCombination] | None = None,
292
292
  shuffle: cirq.RANDOM_STATE_OR_SEED_LIKE | None = None,
293
293
  dataset_directory: str | None = None,
294
- ):
294
+ ) -> pd.DataFrame:
295
295
  """Sample two-qubit XEB circuits given a sampler.
296
296
 
297
297
  Args:
@@ -28,7 +28,7 @@ import cirq.experiments.random_quantum_circuit_generation as rqcg
28
28
  from cirq.experiments.xeb_sampling import sample_2q_xeb_circuits
29
29
 
30
30
 
31
- def test_sample_2q_xeb_circuits():
31
+ def test_sample_2q_xeb_circuits() -> None:
32
32
  q0 = cirq.NamedQubit('a')
33
33
  q1 = cirq.NamedQubit('b')
34
34
  circuits = [
@@ -37,7 +37,7 @@ def test_sample_2q_xeb_circuits():
37
37
  )
38
38
  for _ in range(2)
39
39
  ]
40
- cycle_depths = np.arange(3, 20, 6)
40
+ cycle_depths = list(range(3, 20, 6))
41
41
 
42
42
  df = sample_2q_xeb_circuits(
43
43
  sampler=cirq.Simulator(),
@@ -53,20 +53,20 @@ def test_sample_2q_xeb_circuits():
53
53
  assert np.isclose(np.sum(row['sampled_probs']), 1)
54
54
 
55
55
 
56
- def test_sample_2q_xeb_circuits_error():
56
+ def test_sample_2q_xeb_circuits_error() -> None:
57
57
  qubits = cirq.LineQubit.range(3)
58
58
  circuits = [cirq.testing.random_circuit(qubits, n_moments=5, op_density=0.8, random_state=52)]
59
- cycle_depths = np.arange(3, 50, 9)
59
+ cycle_depths = list(range(3, 50, 9))
60
60
  with pytest.raises(ValueError): # three qubit circuits
61
61
  _ = sample_2q_xeb_circuits(
62
62
  sampler=cirq.Simulator(), circuits=circuits, cycle_depths=cycle_depths
63
63
  )
64
64
 
65
65
 
66
- def test_sample_2q_xeb_circuits_no_progress(capsys):
66
+ def test_sample_2q_xeb_circuits_no_progress(capsys) -> None:
67
67
  qubits = cirq.LineQubit.range(2)
68
68
  circuits = [cirq.testing.random_circuit(qubits, n_moments=7, op_density=0.8, random_state=52)]
69
- cycle_depths = np.arange(3, 4)
69
+ cycle_depths = [3]
70
70
  _ = sample_2q_xeb_circuits(
71
71
  sampler=cirq.Simulator(), circuits=circuits, cycle_depths=cycle_depths, progress_bar=None
72
72
  )
@@ -98,7 +98,7 @@ def _assert_frame_approx_equal(df, df2, *, atol):
98
98
  assert v1 == v2, k
99
99
 
100
100
 
101
- def test_sample_2q_parallel_xeb_circuits(tmpdir):
101
+ def test_sample_2q_parallel_xeb_circuits(tmpdir) -> None:
102
102
  circuits = rqcg.generate_library_of_2q_circuits(
103
103
  n_library_circuits=5, two_qubit_gate=cirq.ISWAP**0.5, max_cycle_depth=10
104
104
  )
@@ -139,7 +139,7 @@ def test_sample_2q_parallel_xeb_circuits(tmpdir):
139
139
  )
140
140
 
141
141
 
142
- def test_sample_2q_parallel_xeb_circuits_bad_circuit_library():
142
+ def test_sample_2q_parallel_xeb_circuits_bad_circuit_library() -> None:
143
143
  circuits = rqcg.generate_library_of_2q_circuits(
144
144
  n_library_circuits=5, two_qubit_gate=cirq.ISWAP**0.5, max_cycle_depth=10
145
145
  )
@@ -161,7 +161,7 @@ def test_sample_2q_parallel_xeb_circuits_bad_circuit_library():
161
161
  )
162
162
 
163
163
 
164
- def test_sample_2q_parallel_xeb_circuits_error_bad_qubits():
164
+ def test_sample_2q_parallel_xeb_circuits_error_bad_qubits() -> None:
165
165
  circuits = rqcg.generate_library_of_2q_circuits(
166
166
  n_library_circuits=5,
167
167
  two_qubit_gate=cirq.ISWAP**0.5,
@@ -86,7 +86,7 @@ def simulate_2q_xeb_circuits(
86
86
  param_resolver: cirq.ParamResolverOrSimilarType = None,
87
87
  pool: multiprocessing.pool.Pool | None = None,
88
88
  simulator: cirq.SimulatesIntermediateState | None = None,
89
- ):
89
+ ) -> pd.DataFrame:
90
90
  """Simulate two-qubit XEB circuits.
91
91
 
92
92
  These ideal probabilities can be benchmarked against potentially noisy