cirq-core 1.7.0.dev20250911180440__py3-none-any.whl → 1.7.0.dev20250917002151__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 (65) hide show
  1. cirq/_version.py +1 -1
  2. cirq/_version_test.py +1 -1
  3. cirq/circuits/circuit_operation_test.py +5 -0
  4. cirq/ops/classically_controlled_operation.py +3 -7
  5. cirq/ops/gate_operation.py +15 -0
  6. cirq/ops/linear_combinations.py +4 -14
  7. cirq/ops/measure_util.py +7 -6
  8. cirq/ops/pauli_string_test.py +7 -6
  9. cirq/ops/raw_types.py +19 -2
  10. cirq/protocols/has_stabilizer_effect_protocol_test.py +11 -9
  11. cirq/protocols/has_unitary_protocol_test.py +3 -3
  12. cirq/protocols/json_serialization.py +3 -3
  13. cirq/protocols/json_serialization_test.py +31 -31
  14. cirq/protocols/kraus_protocol_test.py +5 -5
  15. cirq/protocols/measurement_key_protocol.py +31 -8
  16. cirq/protocols/mixture_protocol.py +1 -1
  17. cirq/protocols/mixture_protocol_test.py +7 -7
  18. cirq/protocols/mul_protocol_test.py +4 -4
  19. cirq/protocols/phase_protocol.py +13 -4
  20. cirq/protocols/pow_protocol_test.py +5 -5
  21. cirq/protocols/resolve_parameters.py +1 -1
  22. cirq/protocols/unitary_protocol_test.py +31 -19
  23. cirq/qis/clifford_tableau.py +14 -14
  24. cirq/qis/clifford_tableau_test.py +17 -17
  25. cirq/qis/entropy.py +1 -1
  26. cirq/qis/entropy_test.py +1 -1
  27. cirq/qis/states_test.py +54 -54
  28. cirq/sim/classical_simulator_test.py +56 -28
  29. cirq/sim/clifford/clifford_simulator.py +5 -5
  30. cirq/sim/clifford/clifford_simulator_test.py +50 -49
  31. cirq/sim/clifford/stabilizer_state_ch_form.py +9 -9
  32. cirq/sim/density_matrix_simulation_state.py +6 -6
  33. cirq/sim/density_matrix_simulator.py +1 -1
  34. cirq/sim/density_matrix_simulator_test.py +94 -84
  35. cirq/sim/density_matrix_utils_test.py +1 -1
  36. cirq/sim/mux_test.py +26 -26
  37. cirq/sim/simulation_product_state_test.py +7 -7
  38. cirq/sim/simulation_state.py +4 -4
  39. cirq/sim/simulation_state_base.py +1 -1
  40. cirq/sim/simulation_state_test.py +5 -5
  41. cirq/sim/simulator.py +2 -2
  42. cirq/sim/simulator_base_test.py +49 -35
  43. cirq/sim/simulator_test.py +39 -35
  44. cirq/sim/sparse_simulator.py +1 -1
  45. cirq/sim/sparse_simulator_test.py +92 -82
  46. cirq/sim/state_vector.py +1 -1
  47. cirq/sim/state_vector_simulation_state.py +7 -7
  48. cirq/sim/state_vector_simulator_test.py +9 -9
  49. cirq/sim/state_vector_test.py +37 -37
  50. cirq/study/result_test.py +20 -20
  51. cirq/study/sweepable_test.py +20 -20
  52. cirq/study/sweeps_test.py +43 -43
  53. cirq/testing/circuit_compare_test.py +16 -14
  54. cirq/testing/consistent_channels.py +2 -2
  55. cirq/testing/consistent_controlled_gate_op.py +1 -1
  56. cirq/testing/consistent_decomposition.py +4 -2
  57. cirq/testing/consistent_phase_by.py +1 -1
  58. cirq/testing/consistent_qasm.py +2 -2
  59. cirq/testing/consistent_qasm_test.py +3 -3
  60. cirq/transformers/eject_z.py +1 -0
  61. {cirq_core-1.7.0.dev20250911180440.dist-info → cirq_core-1.7.0.dev20250917002151.dist-info}/METADATA +1 -1
  62. {cirq_core-1.7.0.dev20250911180440.dist-info → cirq_core-1.7.0.dev20250917002151.dist-info}/RECORD +65 -65
  63. {cirq_core-1.7.0.dev20250911180440.dist-info → cirq_core-1.7.0.dev20250917002151.dist-info}/WHEEL +0 -0
  64. {cirq_core-1.7.0.dev20250911180440.dist-info → cirq_core-1.7.0.dev20250917002151.dist-info}/licenses/LICENSE +0 -0
  65. {cirq_core-1.7.0.dev20250911180440.dist-info → cirq_core-1.7.0.dev20250917002151.dist-info}/top_level.txt +0 -0
@@ -24,66 +24,66 @@ import sympy
24
24
  import cirq
25
25
 
26
26
 
27
- def test_to_resolvers_none():
27
+ def test_to_resolvers_none() -> None:
28
28
  assert list(cirq.to_resolvers(None)) == [cirq.ParamResolver({})]
29
29
 
30
30
 
31
- def test_to_resolvers_single():
31
+ def test_to_resolvers_single() -> None:
32
32
  resolver = cirq.ParamResolver({})
33
33
  assert list(cirq.to_resolvers(resolver)) == [resolver]
34
34
  assert list(cirq.to_resolvers({})) == [resolver]
35
35
 
36
36
 
37
- def test_to_resolvers_sweep():
37
+ def test_to_resolvers_sweep() -> None:
38
38
  sweep = cirq.Linspace('a', 0, 1, 10)
39
39
  assert list(cirq.to_resolvers(sweep)) == list(sweep)
40
40
 
41
41
 
42
- def test_to_resolvers_iterable():
42
+ def test_to_resolvers_iterable() -> None:
43
43
  resolvers = [cirq.ParamResolver({'a': 2}), cirq.ParamResolver({'a': 1})]
44
44
  assert list(cirq.to_resolvers(resolvers)) == resolvers
45
45
  assert list(cirq.to_resolvers([{'a': 2}, {'a': 1}])) == resolvers
46
46
 
47
47
 
48
- def test_to_resolvers_iterable_sweeps():
48
+ def test_to_resolvers_iterable_sweeps() -> None:
49
49
  sweeps = [cirq.Linspace('a', 0, 1, 10), cirq.Linspace('b', 0, 1, 10)]
50
50
  assert list(cirq.to_resolvers(sweeps)) == list(itertools.chain(*sweeps))
51
51
 
52
52
 
53
- def test_to_resolvers_bad():
53
+ def test_to_resolvers_bad() -> None:
54
54
  with pytest.raises(TypeError, match='Unrecognized sweepable'):
55
55
  for _ in cirq.study.to_resolvers('nope'):
56
56
  pass
57
57
 
58
58
 
59
- def test_to_sweeps_none():
59
+ def test_to_sweeps_none() -> None:
60
60
  assert cirq.study.to_sweeps(None) == [cirq.UnitSweep]
61
61
 
62
62
 
63
- def test_to_sweeps_single():
63
+ def test_to_sweeps_single() -> None:
64
64
  resolver = cirq.ParamResolver({})
65
65
  assert cirq.study.to_sweeps(resolver) == [cirq.UnitSweep]
66
66
  assert cirq.study.to_sweeps({}) == [cirq.UnitSweep]
67
67
 
68
68
 
69
- def test_to_sweeps_sweep():
69
+ def test_to_sweeps_sweep() -> None:
70
70
  sweep = cirq.Linspace('a', 0, 1, 10)
71
71
  assert cirq.study.to_sweeps(sweep) == [sweep]
72
72
 
73
73
 
74
- def test_to_sweeps_iterable():
74
+ def test_to_sweeps_iterable() -> None:
75
75
  resolvers = [cirq.ParamResolver({'a': 2}), cirq.ParamResolver({'a': 1})]
76
76
  sweeps = [cirq.study.Zip(cirq.Points('a', [2])), cirq.study.Zip(cirq.Points('a', [1]))]
77
77
  assert cirq.study.to_sweeps(resolvers) == sweeps
78
78
  assert cirq.study.to_sweeps([{'a': 2}, {'a': 1}]) == sweeps
79
79
 
80
80
 
81
- def test_to_sweeps_iterable_sweeps():
81
+ def test_to_sweeps_iterable_sweeps() -> None:
82
82
  sweeps = [cirq.Linspace('a', 0, 1, 10), cirq.Linspace('b', 0, 1, 10)]
83
83
  assert cirq.study.to_sweeps(sweeps) == sweeps
84
84
 
85
85
 
86
- def test_to_sweeps_dictionary_of_list():
86
+ def test_to_sweeps_dictionary_of_list() -> None:
87
87
  with pytest.warns(DeprecationWarning, match='dict_to_product_sweep'):
88
88
  assert cirq.study.to_sweeps({'t': [0, 2, 3]}) == cirq.study.to_sweeps(
89
89
  [{'t': 0}, {'t': 2}, {'t': 3}]
@@ -98,12 +98,12 @@ def test_to_sweeps_dictionary_of_list():
98
98
  )
99
99
 
100
100
 
101
- def test_to_sweeps_invalid():
101
+ def test_to_sweeps_invalid() -> None:
102
102
  with pytest.raises(TypeError, match='Unrecognized sweepable'):
103
103
  cirq.study.to_sweeps('nope')
104
104
 
105
105
 
106
- def test_to_sweep_sweep():
106
+ def test_to_sweep_sweep() -> None:
107
107
  sweep = cirq.Linspace('a', 0, 1, 10)
108
108
  assert cirq.to_sweep(sweep) is sweep
109
109
 
@@ -117,7 +117,7 @@ def test_to_sweep_sweep():
117
117
  lambda: cirq.ParamResolver({sympy.Symbol('a'): 1}),
118
118
  ],
119
119
  )
120
- def test_to_sweep_single_resolver(r_gen):
120
+ def test_to_sweep_single_resolver(r_gen) -> None:
121
121
  sweep = cirq.to_sweep(r_gen())
122
122
  assert isinstance(sweep, cirq.Sweep)
123
123
  assert list(sweep) == [cirq.ParamResolver({'a': 1})]
@@ -141,18 +141,18 @@ def test_to_sweep_single_resolver(r_gen):
141
141
  lambda: {object(): r for r in [{'a': 1}, {'a': 1.5}]}.values(),
142
142
  ],
143
143
  )
144
- def test_to_sweep_resolver_list(r_list_gen):
144
+ def test_to_sweep_resolver_list(r_list_gen) -> None:
145
145
  sweep = cirq.to_sweep(r_list_gen())
146
146
  assert isinstance(sweep, cirq.Sweep)
147
147
  assert list(sweep) == [cirq.ParamResolver({'a': 1}), cirq.ParamResolver({'a': 1.5})]
148
148
 
149
149
 
150
- def test_to_sweep_type_error():
150
+ def test_to_sweep_type_error() -> None:
151
151
  with pytest.raises(TypeError, match='Unexpected sweep'):
152
- cirq.to_sweep(5)
152
+ cirq.to_sweep(5) # type: ignore[arg-type]
153
153
 
154
154
 
155
- def test_to_sweeps_with_param_dict_appends_metadata():
155
+ def test_to_sweeps_with_param_dict_appends_metadata() -> None:
156
156
  params = {'a': 1, 'b': 2, 'c': 3}
157
157
  unit_map = {'a': 'ns', 'b': 'ns'}
158
158
 
@@ -167,7 +167,7 @@ def test_to_sweeps_with_param_dict_appends_metadata():
167
167
  ]
168
168
 
169
169
 
170
- def test_to_sweeps_with_param_list_appends_metadata():
170
+ def test_to_sweeps_with_param_list_appends_metadata() -> None:
171
171
  resolvers = [cirq.ParamResolver({'a': 2}), cirq.ParamResolver({'a': 1})]
172
172
  unit_map = {'a': 'ns'}
173
173
 
cirq/study/sweeps_test.py CHANGED
@@ -20,27 +20,27 @@ import sympy
20
20
  import cirq
21
21
 
22
22
 
23
- def test_product_duplicate_keys():
23
+ def test_product_duplicate_keys() -> None:
24
24
  with pytest.raises(ValueError):
25
25
  _ = cirq.Linspace('a', 0, 9, 10) * cirq.Linspace('a', 0, 10, 11)
26
26
 
27
27
 
28
- def test_zip_duplicate_keys():
28
+ def test_zip_duplicate_keys() -> None:
29
29
  with pytest.raises(ValueError):
30
30
  _ = cirq.Linspace('a', 0, 9, 10) + cirq.Linspace('a', 0, 10, 11)
31
31
 
32
32
 
33
- def test_product_wrong_type():
33
+ def test_product_wrong_type() -> None:
34
34
  with pytest.raises(TypeError):
35
- _ = cirq.Linspace('a', 0, 9, 10) * 2
35
+ _ = cirq.Linspace('a', 0, 9, 10) * 2 # type: ignore[operator]
36
36
 
37
37
 
38
- def test_zip_wrong_type():
38
+ def test_zip_wrong_type() -> None:
39
39
  with pytest.raises(TypeError):
40
- _ = cirq.Linspace('a', 0, 9, 10) + 2
40
+ _ = cirq.Linspace('a', 0, 9, 10) + 2 # type: ignore[operator]
41
41
 
42
42
 
43
- def test_linspace():
43
+ def test_linspace() -> None:
44
44
  sweep = cirq.Linspace('a', 0.34, 9.16, 7)
45
45
  assert len(sweep) == 7
46
46
  params = list(sweep.param_tuples())
@@ -49,7 +49,7 @@ def test_linspace():
49
49
  assert params[-1] == (('a', 9.16),)
50
50
 
51
51
 
52
- def test_linspace_one_point():
52
+ def test_linspace_one_point() -> None:
53
53
  sweep = cirq.Linspace('a', 0.34, 9.16, 1)
54
54
  assert len(sweep) == 1
55
55
  params = list(sweep.param_tuples())
@@ -57,7 +57,7 @@ def test_linspace_one_point():
57
57
  assert params[0] == (('a', 0.34),)
58
58
 
59
59
 
60
- def test_linspace_sympy_symbol():
60
+ def test_linspace_sympy_symbol() -> None:
61
61
  a = sympy.Symbol('a')
62
62
  sweep = cirq.Linspace(a, 0.34, 9.16, 7)
63
63
  assert len(sweep) == 7
@@ -67,14 +67,14 @@ def test_linspace_sympy_symbol():
67
67
  assert params[-1] == (('a', 9.16),)
68
68
 
69
69
 
70
- def test_points():
70
+ def test_points() -> None:
71
71
  sweep = cirq.Points('a', [1, 2, 3, 4])
72
72
  assert len(sweep) == 4
73
73
  params = list(sweep)
74
74
  assert len(params) == 4
75
75
 
76
76
 
77
- def test_zip():
77
+ def test_zip() -> None:
78
78
  sweep = cirq.Points('a', [1, 2, 3]) + cirq.Points('b', [4, 5, 6, 7])
79
79
  assert len(sweep) == 3
80
80
  assert _values(sweep, 'a') == [1, 2, 3]
@@ -86,7 +86,7 @@ def test_zip():
86
86
  ]
87
87
 
88
88
 
89
- def test_zip_longest():
89
+ def test_zip_longest() -> None:
90
90
  sweep = cirq.ZipLongest(cirq.Points('a', [1, 2, 3]), cirq.Points('b', [4, 5, 6, 7]))
91
91
  assert tuple(sweep.param_tuples()) == (
92
92
  (('a', 1), ('b', 4)),
@@ -104,7 +104,7 @@ def test_zip_longest():
104
104
  )
105
105
 
106
106
 
107
- def test_zip_longest_compatibility():
107
+ def test_zip_longest_compatibility() -> None:
108
108
  sweep = cirq.Zip(cirq.Points('a', [1, 2, 3]), cirq.Points('b', [4, 5, 6]))
109
109
  sweep_longest = cirq.ZipLongest(cirq.Points('a', [1, 2, 3]), cirq.Points('b', [4, 5, 6]))
110
110
  assert tuple(sweep.param_tuples()) == tuple(sweep_longest.param_tuples())
@@ -118,7 +118,7 @@ def test_zip_longest_compatibility():
118
118
  assert tuple(sweep.param_tuples()) == tuple(sweep_longest.param_tuples())
119
119
 
120
120
 
121
- def test_empty_zip():
121
+ def test_empty_zip() -> None:
122
122
  assert len(cirq.Zip()) == 0
123
123
  assert len(cirq.ZipLongest()) == 0
124
124
  assert str(cirq.Zip()) == 'Zip()'
@@ -126,7 +126,7 @@ def test_empty_zip():
126
126
  _ = cirq.ZipLongest(cirq.Points('e', []), cirq.Points('a', [1, 2, 3]))
127
127
 
128
128
 
129
- def test_zip_eq():
129
+ def test_zip_eq() -> None:
130
130
  et = cirq.testing.EqualsTester()
131
131
  point_sweep1 = cirq.Points('a', [1, 2, 3])
132
132
  point_sweep2 = cirq.Points('b', [4, 5, 6, 7])
@@ -146,7 +146,7 @@ def test_zip_eq():
146
146
  et.add_equality_group(cirq.Zip(point_sweep1, point_sweep2))
147
147
 
148
148
 
149
- def test_product():
149
+ def test_product() -> None:
150
150
  sweep = cirq.Points('a', [1, 2, 3]) * cirq.Points('b', [4, 5, 6, 7])
151
151
  assert len(sweep) == 12
152
152
  assert _values(sweep, 'a') == [1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3]
@@ -172,7 +172,7 @@ def test_product():
172
172
  assert list(map(list, sweep.param_tuples())) == [[(str(i), 0) for i in range(1025)]]
173
173
 
174
174
 
175
- def test_nested_product_zip():
175
+ def test_nested_product_zip() -> None:
176
176
  sweep = cirq.Product(
177
177
  cirq.Product(cirq.Points('a', [0]), cirq.Points('b', [0])),
178
178
  cirq.Zip(cirq.Points('c', [0, 1]), cirq.Points('d', [0, 1])),
@@ -183,7 +183,7 @@ def test_nested_product_zip():
183
183
  ]
184
184
 
185
185
 
186
- def test_zip_addition():
186
+ def test_zip_addition() -> None:
187
187
  zip_sweep = cirq.Zip(cirq.Points('a', [1, 2]), cirq.Points('b', [3, 4]))
188
188
  zip_sweep2 = cirq.Points('c', [5, 6]) + zip_sweep
189
189
  assert len(zip_sweep2) == 2
@@ -192,17 +192,17 @@ def test_zip_addition():
192
192
  assert _values(zip_sweep2, 'c') == [5, 6]
193
193
 
194
194
 
195
- def test_empty_product():
195
+ def test_empty_product() -> None:
196
196
  sweep = cirq.Product()
197
197
  assert len(sweep) == len(list(sweep)) == 1
198
198
  assert str(sweep) == 'Product()'
199
199
  assert list(map(list, sweep.param_tuples())) == [[]]
200
200
 
201
201
 
202
- def test_slice_access_error():
202
+ def test_slice_access_error() -> None:
203
203
  sweep = cirq.Points('a', [1, 2, 3])
204
204
  with pytest.raises(TypeError, match='<class \'str\'>'):
205
- _ = sweep['junk']
205
+ _ = sweep['junk'] # type: ignore[call-overload]
206
206
 
207
207
  with pytest.raises(IndexError):
208
208
  _ = sweep[4]
@@ -211,7 +211,7 @@ def test_slice_access_error():
211
211
  _ = sweep[-4]
212
212
 
213
213
 
214
- def test_slice_sweep():
214
+ def test_slice_sweep() -> None:
215
215
  sweep = cirq.Points('a', [1, 2, 3]) * cirq.Points('b', [4, 5, 6, 7])
216
216
 
217
217
  first_two = sweep[:2]
@@ -239,7 +239,7 @@ def test_slice_sweep():
239
239
  assert len(list(single_sweep.param_tuples())) == 1
240
240
 
241
241
 
242
- def test_access_sweep():
242
+ def test_access_sweep() -> None:
243
243
  sweep = cirq.Points('a', [1, 2, 3]) * cirq.Points('b', [4, 5, 6, 7])
244
244
 
245
245
  first_elem = sweep[-12]
@@ -259,7 +259,7 @@ def test_access_sweep():
259
259
  lambda: ({sympy.Symbol('a'): a, 'b': a + 1} for a in (0, 0.5, 1, -10)),
260
260
  ],
261
261
  )
262
- def test_list_sweep(r_list_factory):
262
+ def test_list_sweep(r_list_factory) -> None:
263
263
  sweep = cirq.ListSweep(r_list_factory())
264
264
  assert sweep.keys == ['a', 'b']
265
265
  assert len(sweep) == 4
@@ -270,13 +270,13 @@ def test_list_sweep(r_list_factory):
270
270
  assert params[3] == (('a', -10), ('b', -9))
271
271
 
272
272
 
273
- def test_list_sweep_empty():
273
+ def test_list_sweep_empty() -> None:
274
274
  assert cirq.ListSweep([]).keys == []
275
275
 
276
276
 
277
- def test_list_sweep_type_error():
277
+ def test_list_sweep_type_error() -> None:
278
278
  with pytest.raises(TypeError, match='Not a ParamResolver'):
279
- _ = cirq.ListSweep([cirq.ParamResolver(), 'bad'])
279
+ _ = cirq.ListSweep([cirq.ParamResolver(), 'bad']) # type: ignore[list-item]
280
280
 
281
281
 
282
282
  def _values(sweep, key):
@@ -284,7 +284,7 @@ def _values(sweep, key):
284
284
  return [resolver.value_of(p) for resolver in sweep]
285
285
 
286
286
 
287
- def test_equality():
287
+ def test_equality() -> None:
288
288
  et = cirq.testing.EqualsTester()
289
289
 
290
290
  et.add_equality_group(cirq.UnitSweep, cirq.UnitSweep)
@@ -320,7 +320,7 @@ def test_equality():
320
320
  et.make_equality_group(lambda: cirq.ListSweep([{'x': 1}, {'x': -1}]))
321
321
 
322
322
 
323
- def test_repr():
323
+ def test_repr() -> None:
324
324
  cirq.testing.assert_equivalent_repr(
325
325
  cirq.study.sweeps.Product(cirq.UnitSweep),
326
326
  setup_code='import cirq\nfrom collections import OrderedDict',
@@ -343,7 +343,7 @@ def test_repr():
343
343
  )
344
344
 
345
345
 
346
- def test_zip_product_str():
346
+ def test_zip_product_str() -> None:
347
347
  assert (
348
348
  str(cirq.UnitSweep + cirq.UnitSweep + cirq.UnitSweep)
349
349
  == 'cirq.UnitSweep + cirq.UnitSweep + cirq.UnitSweep'
@@ -362,7 +362,7 @@ def test_zip_product_str():
362
362
  )
363
363
 
364
364
 
365
- def test_list_sweep_str():
365
+ def test_list_sweep_str() -> None:
366
366
  assert (
367
367
  str(cirq.UnitSweep)
368
368
  == '''Sweep:
@@ -411,7 +411,7 @@ def test_list_sweep_str():
411
411
  )
412
412
 
413
413
 
414
- def test_dict_to_product_sweep():
414
+ def test_dict_to_product_sweep() -> None:
415
415
  assert cirq.dict_to_product_sweep({'t': [0, 2, 3]}) == (
416
416
  cirq.Product(cirq.Points('t', [0, 2, 3]))
417
417
  )
@@ -421,7 +421,7 @@ def test_dict_to_product_sweep():
421
421
  )
422
422
 
423
423
 
424
- def test_dict_to_zip_sweep():
424
+ def test_dict_to_zip_sweep() -> None:
425
425
  assert cirq.dict_to_zip_sweep({'t': [0, 2, 3]}) == (cirq.Zip(cirq.Points('t', [0, 2, 3])))
426
426
 
427
427
  assert cirq.dict_to_zip_sweep({'t': [0, 1], 's': [2, 3], 'r': 4}) == (
@@ -429,7 +429,7 @@ def test_dict_to_zip_sweep():
429
429
  )
430
430
 
431
431
 
432
- def test_concat_linspace():
432
+ def test_concat_linspace() -> None:
433
433
  sweep1 = cirq.Linspace('a', 0.34, 9.16, 4)
434
434
  sweep2 = cirq.Linspace('a', 10, 20, 4)
435
435
  concat_sweep = cirq.Concat(sweep1, sweep2)
@@ -444,7 +444,7 @@ def test_concat_linspace():
444
444
  assert params[7] == (('a', 20.0),)
445
445
 
446
446
 
447
- def test_concat_points():
447
+ def test_concat_points() -> None:
448
448
  sweep1 = cirq.Points('a', [1, 2])
449
449
  sweep2 = cirq.Points('a', [3, 4, 5])
450
450
  concat_sweep = cirq.Concat(sweep1, sweep2)
@@ -456,7 +456,7 @@ def test_concat_points():
456
456
  assert _values(concat_sweep, 'a') == [1, 2, 3, 4, 5]
457
457
 
458
458
 
459
- def test_concat_many_points():
459
+ def test_concat_many_points() -> None:
460
460
  sweep1 = cirq.Points('a', [1, 2])
461
461
  sweep2 = cirq.Points('a', [3, 4, 5])
462
462
  sweep3 = cirq.Points('a', [6, 7, 8])
@@ -468,7 +468,7 @@ def test_concat_many_points():
468
468
  assert _values(concat_sweep, 'a') == [1, 2, 3, 4, 5, 6, 7, 8]
469
469
 
470
470
 
471
- def test_concat_mixed():
471
+ def test_concat_mixed() -> None:
472
472
  sweep1 = cirq.Linspace('a', 0, 1, 3)
473
473
  sweep2 = cirq.Points('a', [2, 3])
474
474
  concat_sweep = cirq.Concat(sweep1, sweep2)
@@ -477,7 +477,7 @@ def test_concat_mixed():
477
477
  assert _values(concat_sweep, 'a') == [0.0, 0.5, 1.0, 2, 3]
478
478
 
479
479
 
480
- def test_concat_inconsistent_keys():
480
+ def test_concat_inconsistent_keys() -> None:
481
481
  sweep1 = cirq.Linspace('a', 0, 1, 3)
482
482
  sweep2 = cirq.Points('b', [2, 3])
483
483
 
@@ -485,7 +485,7 @@ def test_concat_inconsistent_keys():
485
485
  cirq.Concat(sweep1, sweep2)
486
486
 
487
487
 
488
- def test_concat_sympy_symbol():
488
+ def test_concat_sympy_symbol() -> None:
489
489
  a = sympy.Symbol('a')
490
490
  sweep1 = cirq.Linspace(a, 0, 1, 3)
491
491
  sweep2 = cirq.Points(a, [2, 3])
@@ -495,7 +495,7 @@ def test_concat_sympy_symbol():
495
495
  assert _values(concat_sweep, 'a') == [0.0, 0.5, 1.0, 2, 3]
496
496
 
497
497
 
498
- def test_concat_repr_and_str():
498
+ def test_concat_repr_and_str() -> None:
499
499
  sweep1 = cirq.Linspace('a', 0, 1, 3)
500
500
  sweep2 = cirq.Points('a', [2, 3])
501
501
  concat_sweep = cirq.Concat(sweep1, sweep2)
@@ -509,7 +509,7 @@ def test_concat_repr_and_str():
509
509
  assert str(concat_sweep) == expected_str
510
510
 
511
511
 
512
- def test_concat_large_sweep():
512
+ def test_concat_large_sweep() -> None:
513
513
  sweep1 = cirq.Points('a', list(range(101)))
514
514
  sweep2 = cirq.Points('a', list(range(101, 202)))
515
515
  concat_sweep = cirq.Concat(sweep1, sweep2)
@@ -518,7 +518,7 @@ def test_concat_large_sweep():
518
518
  assert _values(concat_sweep, 'a') == list(range(101)) + list(range(101, 202))
519
519
 
520
520
 
521
- def test_concat_different_keys_raises():
521
+ def test_concat_different_keys_raises() -> None:
522
522
  sweep1 = cirq.Linspace('a', 0, 1, 3)
523
523
  sweep2 = cirq.Points('b', [2, 3])
524
524
 
@@ -526,6 +526,6 @@ def test_concat_different_keys_raises():
526
526
  _ = cirq.Concat(sweep1, sweep2)
527
527
 
528
528
 
529
- def test_concat_empty_sweep_raises():
529
+ def test_concat_empty_sweep_raises() -> None:
530
530
  with pytest.raises(ValueError, match="Concat requires at least one sweep."):
531
531
  _ = cirq.Concat()
@@ -21,7 +21,7 @@ import cirq
21
21
  from cirq.testing.circuit_compare import _assert_apply_unitary_works_when_axes_transposed
22
22
 
23
23
 
24
- def test_sensitive_to_phase():
24
+ def test_sensitive_to_phase() -> None:
25
25
  q = cirq.NamedQubit('q')
26
26
 
27
27
  cirq.testing.assert_circuits_with_terminal_measurements_are_equivalent(
@@ -38,7 +38,7 @@ def test_sensitive_to_phase():
38
38
  )
39
39
 
40
40
 
41
- def test_sensitive_to_measurement_but_not_measured_phase():
41
+ def test_sensitive_to_measurement_but_not_measured_phase() -> None:
42
42
  q = cirq.NamedQubit('q')
43
43
 
44
44
  with pytest.raises(AssertionError):
@@ -80,7 +80,7 @@ def test_sensitive_to_measurement_but_not_measured_phase():
80
80
  )
81
81
 
82
82
 
83
- def test_sensitive_to_measurement_toggle():
83
+ def test_sensitive_to_measurement_toggle() -> None:
84
84
  q = cirq.NamedQubit('q')
85
85
 
86
86
  with pytest.raises(AssertionError):
@@ -103,7 +103,7 @@ def test_sensitive_to_measurement_toggle():
103
103
  )
104
104
 
105
105
 
106
- def test_measuring_qubits():
106
+ def test_measuring_qubits() -> None:
107
107
  a, b = cirq.LineQubit.range(2)
108
108
 
109
109
  with pytest.raises(AssertionError):
@@ -126,7 +126,7 @@ def test_measuring_qubits():
126
126
  @pytest.mark.parametrize(
127
127
  'circuit', [cirq.testing.random_circuit(cirq.LineQubit.range(2), 4, 0.5) for _ in range(5)]
128
128
  )
129
- def test_random_same_matrix(circuit):
129
+ def test_random_same_matrix(circuit) -> None:
130
130
  a, b = cirq.LineQubit.range(2)
131
131
  same = cirq.Circuit(
132
132
  cirq.MatrixGate(circuit.unitary(qubits_that_should_be_present=[a, b])).on(a, b)
@@ -140,7 +140,7 @@ def test_random_same_matrix(circuit):
140
140
  cirq.testing.assert_circuits_with_terminal_measurements_are_equivalent(mutable_circuit, same)
141
141
 
142
142
 
143
- def test_correct_qubit_ordering():
143
+ def test_correct_qubit_ordering() -> None:
144
144
  a, b = cirq.LineQubit.range(2)
145
145
  cirq.testing.assert_circuits_with_terminal_measurements_are_equivalent(
146
146
  cirq.Circuit(cirq.Z(a), cirq.Z(b), cirq.measure(b)),
@@ -154,7 +154,7 @@ def test_correct_qubit_ordering():
154
154
  )
155
155
 
156
156
 
157
- def test_known_old_failure():
157
+ def test_known_old_failure() -> None:
158
158
  a, b = cirq.LineQubit.range(2)
159
159
  cirq.testing.assert_circuits_with_terminal_measurements_are_equivalent(
160
160
  actual=cirq.Circuit(
@@ -170,7 +170,7 @@ def test_known_old_failure():
170
170
  )
171
171
 
172
172
 
173
- def test_assert_same_circuits():
173
+ def test_assert_same_circuits() -> None:
174
174
  a, b = cirq.LineQubit.range(2)
175
175
 
176
176
  cirq.testing.assert_same_circuits(cirq.Circuit(cirq.H(a)), cirq.Circuit(cirq.H(a)))
@@ -191,7 +191,7 @@ def test_assert_same_circuits():
191
191
  )
192
192
 
193
193
 
194
- def test_assert_circuits_have_same_unitary_given_final_permutation():
194
+ def test_assert_circuits_have_same_unitary_given_final_permutation() -> None:
195
195
  q = cirq.LineQubit.range(5)
196
196
  expected = cirq.Circuit([cirq.Moment(cirq.CNOT(q[2], q[1]), cirq.CNOT(q[3], q[0]))])
197
197
  actual = cirq.Circuit(
@@ -202,6 +202,7 @@ def test_assert_circuits_have_same_unitary_given_final_permutation():
202
202
  cirq.Moment(cirq.CNOT(q[3], q[2])),
203
203
  ]
204
204
  )
205
+ qubit_map: dict[cirq.Qid, cirq.Qid]
205
206
  qubit_map = {q[0]: q[2], q[2]: q[1], q[1]: q[0]}
206
207
  cirq.testing.assert_circuits_have_same_unitary_given_final_permutation(
207
208
  actual, expected, qubit_map
@@ -213,6 +214,7 @@ def test_assert_circuits_have_same_unitary_given_final_permutation():
213
214
  actual, expected, qubit_map=qubit_map
214
215
  )
215
216
 
217
+ bad_qubit_map: dict[cirq.Qid, cirq.Qid]
216
218
  bad_qubit_map = {q[0]: q[2], q[2]: q[4], q[4]: q[0]}
217
219
  with pytest.raises(ValueError, match="'qubit_map' must be a mapping"):
218
220
  cirq.testing.assert_circuits_have_same_unitary_given_final_permutation(
@@ -220,7 +222,7 @@ def test_assert_circuits_have_same_unitary_given_final_permutation():
220
222
  )
221
223
 
222
224
 
223
- def test_assert_has_diagram():
225
+ def test_assert_has_diagram() -> None:
224
226
  a, b = cirq.LineQubit.range(2)
225
227
  circuit = cirq.Circuit(cirq.CNOT(a, b))
226
228
  cirq.testing.assert_has_diagram(
@@ -263,7 +265,7 @@ Highlighted differences:
263
265
  assert expected_error in ex_info.value.args[0]
264
266
 
265
267
 
266
- def test_assert_has_consistent_apply_channel():
268
+ def test_assert_has_consistent_apply_channel() -> None:
267
269
  class Correct:
268
270
  def _apply_channel_(self, args: cirq.ApplyChannelArgs):
269
271
  args.target_tensor[...] = 0
@@ -329,7 +331,7 @@ def test_assert_has_consistent_apply_channel():
329
331
  cirq.testing.assert_has_consistent_apply_channel(NoApply())
330
332
 
331
333
 
332
- def test_assert_has_consistent_apply_unitary():
334
+ def test_assert_has_consistent_apply_unitary() -> None:
333
335
  class IdentityReturningUnalteredWorkspace:
334
336
  def _apply_unitary_(self, args: cirq.ApplyUnitaryArgs) -> np.ndarray:
335
337
  return args.available_buffer
@@ -461,7 +463,7 @@ def test_assert_has_consistent_apply_unitary():
461
463
  cirq.testing.assert_has_consistent_apply_unitary(cirq.X.on(cirq.NamedQubit('q')))
462
464
 
463
465
 
464
- def test_assert_has_consistent_qid_shape():
466
+ def test_assert_has_consistent_qid_shape() -> None:
465
467
  class ConsistentGate(cirq.Gate):
466
468
  def _num_qubits_(self):
467
469
  return 4
@@ -560,7 +562,7 @@ def test_assert_has_consistent_qid_shape():
560
562
  cirq.testing.assert_has_consistent_qid_shape(NoProtocol())
561
563
 
562
564
 
563
- def test_assert_apply_unitary_works_when_axes_transposed_failure():
565
+ def test_assert_apply_unitary_works_when_axes_transposed_failure() -> None:
564
566
  class BadOp:
565
567
  def _apply_unitary_(self, args: cirq.ApplyUnitaryArgs):
566
568
  # Get a more convenient view of the data.
@@ -21,7 +21,7 @@ import numpy as np
21
21
  import cirq
22
22
 
23
23
 
24
- def assert_consistent_channel(gate: Any, rtol: float = 1e-5, atol: float = 1e-8):
24
+ def assert_consistent_channel(gate: Any, rtol: float = 1e-5, atol: float = 1e-8) -> None:
25
25
  """Asserts that a given gate has Kraus operators and that they are properly normalized."""
26
26
  assert cirq.has_kraus(gate), f"Given gate {gate!r} does not return True for cirq.has_kraus."
27
27
  kraus_ops = cirq.kraus(gate)
@@ -31,7 +31,7 @@ def assert_consistent_channel(gate: Any, rtol: float = 1e-5, atol: float = 1e-8)
31
31
  )
32
32
 
33
33
 
34
- def assert_consistent_mixture(gate: Any, rtol: float = 1e-5, atol: float = 1e-8):
34
+ def assert_consistent_mixture(gate: Any, rtol: float = 1e-5, atol: float = 1e-8) -> None:
35
35
  """Asserts that a given gate is a mixture and the mixture probabilities sum to one."""
36
36
  assert cirq.has_mixture(gate), f"Give gate {gate!r} does not return for cirq.has_mixture."
37
37
  mixture = cirq.mixture(gate)
@@ -38,7 +38,7 @@ def assert_controlled_and_controlled_by_identical(
38
38
  _assert_gate_consistent(gate, num_control, control_value)
39
39
 
40
40
 
41
- def assert_controlled_unitary_consistent(gate: ops.Gate):
41
+ def assert_controlled_unitary_consistent(gate: ops.Gate) -> None:
42
42
  """Checks that unitary of ControlledGate(gate) is consistent with gate.controlled()."""
43
43
 
44
44
  u_orig = protocols.unitary(ops.ControlledGate(gate))
@@ -22,7 +22,9 @@ from cirq import circuits, devices, ops, protocols
22
22
  from cirq.testing import lin_alg_utils
23
23
 
24
24
 
25
- def assert_decompose_is_consistent_with_unitary(val: Any, ignoring_global_phase: bool = False):
25
+ def assert_decompose_is_consistent_with_unitary(
26
+ val: Any, ignoring_global_phase: bool = False
27
+ ) -> None:
26
28
  """Uses `val._unitary_` to check `val._phase_by_`'s behavior."""
27
29
  __tracebackhide__ = True
28
30
 
@@ -76,7 +78,7 @@ def _known_gate_with_no_decomposition(val: Any):
76
78
  return False
77
79
 
78
80
 
79
- def assert_decompose_ends_at_default_gateset(val: Any, ignore_known_gates: bool = True):
81
+ def assert_decompose_ends_at_default_gateset(val: Any, ignore_known_gates: bool = True) -> None:
80
82
  """Asserts that cirq.decompose(val) ends at default cirq gateset or a known gate."""
81
83
  args = () if isinstance(val, ops.Operation) else (tuple(devices.LineQid.for_gate(val)),)
82
84
  dec_once = protocols.decompose_once(val, [val(*args[0]) if args else val], *args)
@@ -23,7 +23,7 @@ from cirq import linalg, protocols
23
23
  from cirq.testing import lin_alg_utils
24
24
 
25
25
 
26
- def assert_phase_by_is_consistent_with_unitary(val: Any):
26
+ def assert_phase_by_is_consistent_with_unitary(val: Any) -> None:
27
27
  """Uses `val._unitary_` to check `val._phase_by_`'s behavior."""
28
28
 
29
29
  original = protocols.unitary(val, None)
@@ -23,7 +23,7 @@ from cirq import devices, linalg, ops, protocols
23
23
  from cirq.testing import lin_alg_utils
24
24
 
25
25
 
26
- def assert_qasm_is_consistent_with_unitary(val: Any):
26
+ def assert_qasm_is_consistent_with_unitary(val: Any) -> None:
27
27
  """Uses `val._unitary_` to check `val._qasm_`'s behavior."""
28
28
 
29
29
  # Only test if qiskit is installed.
@@ -106,7 +106,7 @@ qreg q[{num_qubits}];
106
106
  )
107
107
 
108
108
 
109
- def assert_qiskit_parsed_qasm_consistent_with_unitary(qasm, unitary): # pragma: no cover
109
+ def assert_qiskit_parsed_qasm_consistent_with_unitary(qasm, unitary) -> None: # pragma: no cover
110
110
  try:
111
111
  # We don't want to require qiskit as a dependency but
112
112
  # if Qiskit is installed, test QASM output against it.