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.

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.dev20250812001555.dist-info}/METADATA +1 -1
  56. {cirq_core-1.7.0.dev20250807224154.dist-info → cirq_core-1.7.0.dev20250812001555.dist-info}/RECORD +59 -59
  57. {cirq_core-1.7.0.dev20250807224154.dist-info → cirq_core-1.7.0.dev20250812001555.dist-info}/WHEEL +0 -0
  58. {cirq_core-1.7.0.dev20250807224154.dist-info → cirq_core-1.7.0.dev20250812001555.dist-info}/licenses/LICENSE +0 -0
  59. {cirq_core-1.7.0.dev20250807224154.dist-info → cirq_core-1.7.0.dev20250812001555.dist-info}/top_level.txt +0 -0
@@ -24,18 +24,18 @@ import pytest
24
24
  import cirq
25
25
 
26
26
 
27
- def test_init():
27
+ def test_init() -> None:
28
28
  q = cirq.GridQubit(3, 4)
29
29
  assert q.row == 3
30
30
  assert q.col == 4
31
31
 
32
- q = cirq.GridQid(1, 2, dimension=3)
33
- assert q.row == 1
34
- assert q.col == 2
35
- assert q.dimension == 3
32
+ qid = cirq.GridQid(1, 2, dimension=3)
33
+ assert qid.row == 1
34
+ assert qid.col == 2
35
+ assert qid.dimension == 3
36
36
 
37
37
 
38
- def test_eq():
38
+ def test_eq() -> None:
39
39
  eq = cirq.testing.EqualsTester()
40
40
  eq.make_equality_group(lambda: cirq.GridQubit(0, 0), lambda: cirq.GridQid(0, 0, dimension=2))
41
41
  eq.make_equality_group(lambda: cirq.GridQubit(1, 0), lambda: cirq.GridQid(1, 0, dimension=2))
@@ -43,7 +43,7 @@ def test_eq():
43
43
  eq.make_equality_group(lambda: cirq.GridQid(0, 0, dimension=3))
44
44
 
45
45
 
46
- def test_grid_qubit_pickled_hash():
46
+ def test_grid_qubit_pickled_hash() -> None:
47
47
  # Use a large number that is unlikely to be used by any other tests.
48
48
  row, col = 123456789, 2345678910
49
49
  q_bad = cirq.GridQubit(row, col)
@@ -52,7 +52,7 @@ def test_grid_qubit_pickled_hash():
52
52
  _test_qid_pickled_hash(q, q_bad)
53
53
 
54
54
 
55
- def test_grid_qid_pickled_hash():
55
+ def test_grid_qid_pickled_hash() -> None:
56
56
  # Use a large number that is unlikely to be used by any other tests.
57
57
  row, col = 123456789, 2345678910
58
58
  q_bad = cirq.GridQid(row, col, dimension=3)
@@ -74,12 +74,12 @@ def _test_qid_pickled_hash(q: cirq.Qid, q_bad: cirq.Qid) -> None:
74
74
  assert hash(q_ok) == hash(q)
75
75
 
76
76
 
77
- def test_str():
77
+ def test_str() -> None:
78
78
  assert str(cirq.GridQubit(5, 2)) == 'q(5, 2)'
79
79
  assert str(cirq.GridQid(5, 2, dimension=3)) == 'q(5, 2) (d=3)'
80
80
 
81
81
 
82
- def test_circuit_info():
82
+ def test_circuit_info() -> None:
83
83
  assert cirq.circuit_diagram_info(cirq.GridQubit(5, 2)) == cirq.CircuitDiagramInfo(
84
84
  wire_symbols=('(5, 2)',)
85
85
  )
@@ -88,12 +88,12 @@ def test_circuit_info():
88
88
  )
89
89
 
90
90
 
91
- def test_repr():
91
+ def test_repr() -> None:
92
92
  cirq.testing.assert_equivalent_repr(cirq.GridQubit(5, 2))
93
93
  cirq.testing.assert_equivalent_repr(cirq.GridQid(5, 2, dimension=3))
94
94
 
95
95
 
96
- def test_cmp():
96
+ def test_cmp() -> None:
97
97
  order = cirq.testing.OrderTester()
98
98
  order.add_ascending_equivalence_group(cirq.GridQubit(0, 0), cirq.GridQid(0, 0, dimension=2))
99
99
  order.add_ascending(
@@ -110,7 +110,7 @@ def test_cmp():
110
110
  )
111
111
 
112
112
 
113
- def test_cmp_failure():
113
+ def test_cmp_failure() -> None:
114
114
  with pytest.raises(TypeError, match='not supported between instances'):
115
115
  _ = 0 < cirq.GridQubit(0, 0)
116
116
  with pytest.raises(TypeError, match='not supported between instances'):
@@ -121,7 +121,7 @@ def test_cmp_failure():
121
121
  _ = cirq.GridQid(1, 1, dimension=3) < 0
122
122
 
123
123
 
124
- def test_is_adjacent():
124
+ def test_is_adjacent() -> None:
125
125
  assert cirq.GridQubit(0, 0).is_adjacent(cirq.GridQubit(0, 1))
126
126
  assert cirq.GridQubit(0, 0).is_adjacent(cirq.GridQubit(0, -1))
127
127
  assert cirq.GridQubit(0, 0).is_adjacent(cirq.GridQubit(1, 0))
@@ -138,7 +138,7 @@ def test_is_adjacent():
138
138
  assert not cirq.GridQubit(500, 999).is_adjacent(cirq.GridQubit(5034, 999))
139
139
 
140
140
 
141
- def test_neighbors():
141
+ def test_neighbors() -> None:
142
142
  assert cirq.GridQubit(1, 1).neighbors() == {
143
143
  cirq.GridQubit(1, 2),
144
144
  cirq.GridQubit(2, 1),
@@ -151,7 +151,7 @@ def test_neighbors():
151
151
  assert cirq.GridQubit(1, 1).neighbors(restricted_qubits) == {cirq.GridQubit(2, 1)}
152
152
 
153
153
 
154
- def test_square():
154
+ def test_square() -> None:
155
155
  assert cirq.GridQubit.square(2, top=1, left=1) == [
156
156
  cirq.GridQubit(1, 1),
157
157
  cirq.GridQubit(1, 2),
@@ -179,7 +179,7 @@ def test_square():
179
179
  ]
180
180
 
181
181
 
182
- def test_rect():
182
+ def test_rect() -> None:
183
183
  assert cirq.GridQubit.rect(1, 2, top=5, left=6) == [cirq.GridQubit(5, 6), cirq.GridQubit(5, 7)]
184
184
  assert cirq.GridQubit.rect(2, 2) == [
185
185
  cirq.GridQubit(0, 0),
@@ -200,7 +200,7 @@ def test_rect():
200
200
  ]
201
201
 
202
202
 
203
- def test_diagram():
203
+ def test_diagram() -> None:
204
204
  s = """
205
205
  -----AB-----
206
206
  ----ABCD----
@@ -237,7 +237,7 @@ BA"""
237
237
  cirq.GridQubit.from_diagram('@')
238
238
 
239
239
 
240
- def test_addition_subtraction():
240
+ def test_addition_subtraction() -> None:
241
241
  # GridQubits
242
242
  assert cirq.GridQubit(1, 2) + (2, 5) == cirq.GridQubit(3, 7)
243
243
  assert cirq.GridQubit(1, 2) + (0, 0) == cirq.GridQubit(1, 2)
@@ -276,7 +276,7 @@ def test_addition_subtraction():
276
276
 
277
277
 
278
278
  @pytest.mark.parametrize('dtype', (np.int8, np.int16, np.int32, np.int64, int))
279
- def test_addition_subtraction_numpy_array(dtype):
279
+ def test_addition_subtraction_numpy_array(dtype) -> None:
280
280
  assert cirq.GridQubit(1, 2) + np.array([1, 2], dtype=dtype) == cirq.GridQubit(2, 4)
281
281
  assert cirq.GridQubit(1, 2) + np.array([0, 0], dtype=dtype) == cirq.GridQubit(1, 2)
282
282
  assert cirq.GridQubit(1, 2) + np.array([-1, 0], dtype=dtype) == cirq.GridQubit(0, 2)
@@ -306,18 +306,18 @@ def test_addition_subtraction_numpy_array(dtype):
306
306
  )
307
307
 
308
308
 
309
- def test_unsupported_add():
309
+ def test_unsupported_add() -> None:
310
310
  with pytest.raises(TypeError, match='1'):
311
- _ = cirq.GridQubit(1, 1) + 1
311
+ _ = cirq.GridQubit(1, 1) + 1 # type: ignore[operator]
312
312
  with pytest.raises(TypeError, match='(1,)'):
313
- _ = cirq.GridQubit(1, 1) + (1,)
313
+ _ = cirq.GridQubit(1, 1) + (1,) # type: ignore[operator]
314
314
  with pytest.raises(TypeError, match='(1, 2, 3)'):
315
- _ = cirq.GridQubit(1, 1) + (1, 2, 3)
315
+ _ = cirq.GridQubit(1, 1) + (1, 2, 3) # type: ignore[operator]
316
316
  with pytest.raises(TypeError, match='(1, 2.0)'):
317
- _ = cirq.GridQubit(1, 1) + (1, 2.0)
317
+ _ = cirq.GridQubit(1, 1) + (1, 2.0) # type: ignore[operator]
318
318
 
319
319
  with pytest.raises(TypeError, match='1'):
320
- _ = cirq.GridQubit(1, 1) - 1
320
+ _ = cirq.GridQubit(1, 1) - 1 # type: ignore[operator]
321
321
 
322
322
  with pytest.raises(TypeError, match='[1., 2.]'):
323
323
  _ = cirq.GridQubit(1, 1) + np.array([1.0, 2.0])
@@ -325,16 +325,16 @@ def test_unsupported_add():
325
325
  _ = cirq.GridQubit(1, 1) + np.array([1, 2, 3], dtype=int)
326
326
 
327
327
 
328
- def test_addition_subtraction_type_error():
328
+ def test_addition_subtraction_type_error() -> None:
329
329
  with pytest.raises(TypeError, match="bort"):
330
- _ = cirq.GridQubit(5, 3) + "bort"
330
+ _ = cirq.GridQubit(5, 3) + "bort" # type: ignore[operator]
331
331
  with pytest.raises(TypeError, match="bort"):
332
- _ = cirq.GridQubit(5, 3) - "bort"
332
+ _ = cirq.GridQubit(5, 3) - "bort" # type: ignore[operator]
333
333
 
334
334
  with pytest.raises(TypeError, match="bort"):
335
- _ = cirq.GridQid(5, 3, dimension=3) + "bort"
335
+ _ = cirq.GridQid(5, 3, dimension=3) + "bort" # type: ignore[operator]
336
336
  with pytest.raises(TypeError, match="bort"):
337
- _ = cirq.GridQid(5, 3, dimension=3) - "bort"
337
+ _ = cirq.GridQid(5, 3, dimension=3) - "bort" # type: ignore[operator]
338
338
 
339
339
  with pytest.raises(TypeError, match="Can only add GridQids with identical dimension."):
340
340
  _ = cirq.GridQid(5, 3, dimension=3) + cirq.GridQid(3, 5, dimension=4)
@@ -342,62 +342,62 @@ def test_addition_subtraction_type_error():
342
342
  _ = cirq.GridQid(5, 3, dimension=3) - cirq.GridQid(3, 5, dimension=4)
343
343
 
344
344
 
345
- def test_neg():
345
+ def test_neg() -> None:
346
346
  assert -cirq.GridQubit(1, 2) == cirq.GridQubit(-1, -2)
347
347
  assert -cirq.GridQid(1, 2, dimension=3) == cirq.GridQid(-1, -2, dimension=3)
348
348
 
349
349
 
350
- def test_to_json():
350
+ def test_to_json() -> None:
351
351
  assert cirq.GridQubit(5, 6)._json_dict_() == {'row': 5, 'col': 6}
352
352
 
353
353
  assert cirq.GridQid(5, 6, dimension=3)._json_dict_() == {'row': 5, 'col': 6, 'dimension': 3}
354
354
 
355
355
 
356
- def test_immutable():
356
+ def test_immutable() -> None:
357
357
  # Match one of two strings. The second one is message returned since python 3.11.
358
358
  with pytest.raises(
359
359
  AttributeError,
360
360
  match="(can't set attribute)|(property 'col' of 'GridQubit' object has no setter)",
361
361
  ):
362
362
  q = cirq.GridQubit(1, 2)
363
- q.col = 3
363
+ q.col = 3 # type: ignore[misc]
364
364
 
365
365
  with pytest.raises(
366
366
  AttributeError,
367
367
  match="(can't set attribute)|(property 'row' of 'GridQubit' object has no setter)",
368
368
  ):
369
369
  q = cirq.GridQubit(1, 2)
370
- q.row = 3
370
+ q.row = 3 # type: ignore[misc]
371
371
 
372
372
  with pytest.raises(
373
373
  AttributeError,
374
374
  match="(can't set attribute)|(property 'col' of 'GridQid' object has no setter)",
375
375
  ):
376
- q = cirq.GridQid(1, 2, dimension=3)
377
- q.col = 3
376
+ qid = cirq.GridQid(1, 2, dimension=3)
377
+ qid.col = 3 # type: ignore[misc]
378
378
 
379
379
  with pytest.raises(
380
380
  AttributeError,
381
381
  match="(can't set attribute)|(property 'row' of 'GridQid' object has no setter)",
382
382
  ):
383
- q = cirq.GridQid(1, 2, dimension=3)
384
- q.row = 3
383
+ qid = cirq.GridQid(1, 2, dimension=3)
384
+ qid.row = 3 # type: ignore[misc]
385
385
 
386
386
  with pytest.raises(
387
387
  AttributeError,
388
388
  match="(can't set attribute)|(property 'dimension' of 'GridQid' object has no setter)",
389
389
  ):
390
- q = cirq.GridQid(1, 2, dimension=3)
391
- q.dimension = 3
390
+ qid = cirq.GridQid(1, 2, dimension=3)
391
+ qid.dimension = 3 # type: ignore[misc]
392
392
 
393
393
 
394
- def test_complex():
394
+ def test_complex() -> None:
395
395
  assert complex(cirq.GridQubit(row=1, col=2)) == 2 + 1j
396
396
  assert isinstance(complex(cirq.GridQubit(row=1, col=2)), complex)
397
397
 
398
398
 
399
399
  @pytest.mark.parametrize('dtype', (np.int8, np.int64, float, np.float64))
400
- def test_numpy_index(dtype):
400
+ def test_numpy_index(dtype) -> None:
401
401
  np5, np6, np3 = [dtype(i) for i in [5, 6, 3]]
402
402
  q = cirq.GridQubit(np5, np6)
403
403
  assert hash(q) == hash(cirq.GridQubit(5, 6))
@@ -406,19 +406,19 @@ def test_numpy_index(dtype):
406
406
  assert q.dimension == 2
407
407
  assert isinstance(q.dimension, int)
408
408
 
409
- q = cirq.GridQid(np5, np6, dimension=np3)
410
- assert hash(q) == hash(cirq.GridQid(5, 6, dimension=3))
411
- assert q.row == 5
412
- assert q.col == 6
413
- assert q.dimension == 3
414
- assert isinstance(q.dimension, int)
409
+ qid = cirq.GridQid(np5, np6, dimension=np3)
410
+ assert hash(qid) == hash(cirq.GridQid(5, 6, dimension=3))
411
+ assert qid.row == 5
412
+ assert qid.col == 6
413
+ assert qid.dimension == 3
414
+ assert isinstance(qid.dimension, int)
415
415
 
416
416
 
417
417
  @pytest.mark.parametrize('dtype', (float, np.float64))
418
- def test_non_integer_index(dtype):
418
+ def test_non_integer_index(dtype) -> None:
419
419
  # Not supported type-wise, but is used in practice, so behavior needs to be preserved.
420
420
  q = cirq.GridQubit(dtype(5.5), dtype(6.5))
421
- assert hash(q) == hash(cirq.GridQubit(5.5, 6.5))
421
+ assert hash(q) == hash(cirq.GridQubit(5.5, 6.5)) # type: ignore[arg-type]
422
422
  assert q.row == 5.5
423
423
  assert q.col == 6.5
424
424
  assert isinstance(q.row, dtype)
@@ -21,16 +21,16 @@ import cirq
21
21
  from cirq.devices.grid_qubit_test import _test_qid_pickled_hash
22
22
 
23
23
 
24
- def test_init():
24
+ def test_init() -> None:
25
25
  q = cirq.LineQubit(1)
26
26
  assert q.x == 1
27
27
 
28
- q = cirq.LineQid(1, dimension=3)
29
- assert q.x == 1
30
- assert q.dimension == 3
28
+ qid = cirq.LineQid(1, dimension=3)
29
+ assert qid.x == 1
30
+ assert qid.dimension == 3
31
31
 
32
32
 
33
- def test_eq():
33
+ def test_eq() -> None:
34
34
  eq = cirq.testing.EqualsTester()
35
35
  eq.make_equality_group(lambda: cirq.LineQubit(1), lambda: cirq.LineQid(1, dimension=2))
36
36
  eq.add_equality_group(cirq.LineQubit(2))
@@ -38,17 +38,17 @@ def test_eq():
38
38
  eq.add_equality_group(cirq.LineQid(1, dimension=3))
39
39
 
40
40
 
41
- def test_str():
41
+ def test_str() -> None:
42
42
  assert str(cirq.LineQubit(5)) == 'q(5)'
43
43
  assert str(cirq.LineQid(5, dimension=3)) == 'q(5) (d=3)'
44
44
 
45
45
 
46
- def test_repr():
46
+ def test_repr() -> None:
47
47
  cirq.testing.assert_equivalent_repr(cirq.LineQubit(5))
48
48
  cirq.testing.assert_equivalent_repr(cirq.LineQid(5, dimension=3))
49
49
 
50
50
 
51
- def test_cmp():
51
+ def test_cmp() -> None:
52
52
  order = cirq.testing.OrderTester()
53
53
  order.add_ascending_equivalence_group(cirq.LineQubit(0), cirq.LineQid(0, 2))
54
54
  order.add_ascending(
@@ -60,7 +60,7 @@ def test_cmp():
60
60
  )
61
61
 
62
62
 
63
- def test_cmp_failure():
63
+ def test_cmp_failure() -> None:
64
64
  with pytest.raises(TypeError, match='not supported between instances'):
65
65
  _ = 0 < cirq.LineQubit(1)
66
66
  with pytest.raises(TypeError, match='not supported between instances'):
@@ -71,7 +71,7 @@ def test_cmp_failure():
71
71
  _ = cirq.LineQid(1, 3) < 0
72
72
 
73
73
 
74
- def test_line_qubit_pickled_hash():
74
+ def test_line_qubit_pickled_hash() -> None:
75
75
  # Use a large number that is unlikely to be used by any other tests.
76
76
  x = 1234567891011
77
77
  q_bad = cirq.LineQubit(x)
@@ -80,7 +80,7 @@ def test_line_qubit_pickled_hash():
80
80
  _test_qid_pickled_hash(q, q_bad)
81
81
 
82
82
 
83
- def test_line_qid_pickled_hash():
83
+ def test_line_qid_pickled_hash() -> None:
84
84
  # Use a large number that is unlikely to be used by any other tests.
85
85
  x = 1234567891011
86
86
  q_bad = cirq.LineQid(x, dimension=3)
@@ -89,7 +89,7 @@ def test_line_qid_pickled_hash():
89
89
  _test_qid_pickled_hash(q, q_bad)
90
90
 
91
91
 
92
- def test_is_adjacent():
92
+ def test_is_adjacent() -> None:
93
93
  assert cirq.LineQubit(1).is_adjacent(cirq.LineQubit(2))
94
94
  assert cirq.LineQubit(1).is_adjacent(cirq.LineQubit(0))
95
95
  assert cirq.LineQubit(2).is_adjacent(cirq.LineQubit(3))
@@ -100,13 +100,13 @@ def test_is_adjacent():
100
100
  assert not cirq.LineQubit(2).is_adjacent(cirq.LineQid(0, 3))
101
101
 
102
102
 
103
- def test_neighborhood():
103
+ def test_neighborhood() -> None:
104
104
  assert cirq.LineQubit(1).neighbors() == {cirq.LineQubit(0), cirq.LineQubit(2)}
105
105
  restricted_qubits = [cirq.LineQubit(2), cirq.LineQubit(3)]
106
106
  assert cirq.LineQubit(1).neighbors(restricted_qubits) == {cirq.LineQubit(2)}
107
107
 
108
108
 
109
- def test_range():
109
+ def test_range() -> None:
110
110
  assert cirq.LineQubit.range(0) == []
111
111
  assert cirq.LineQubit.range(1) == [cirq.LineQubit(0)]
112
112
  assert cirq.LineQubit.range(2) == [cirq.LineQubit(0), cirq.LineQubit(1)]
@@ -127,7 +127,7 @@ def test_range():
127
127
  assert cirq.LineQubit.range(1, 5, 2) == [cirq.LineQubit(1), cirq.LineQubit(3)]
128
128
 
129
129
 
130
- def test_qid_range():
130
+ def test_qid_range() -> None:
131
131
  assert cirq.LineQid.range(0, dimension=3) == []
132
132
  assert cirq.LineQid.range(1, dimension=3) == [cirq.LineQid(0, 3)]
133
133
  assert cirq.LineQid.range(2, dimension=3) == [cirq.LineQid(0, 3), cirq.LineQid(1, 3)]
@@ -152,7 +152,7 @@ def test_qid_range():
152
152
  assert cirq.LineQid.range(1, 5, 2, dimension=2) == [cirq.LineQid(1, 2), cirq.LineQid(3, 2)]
153
153
 
154
154
 
155
- def test_for_qid_shape():
155
+ def test_for_qid_shape() -> None:
156
156
  assert cirq.LineQid.for_qid_shape(()) == []
157
157
  assert cirq.LineQid.for_qid_shape((4, 2, 3, 1)) == [
158
158
  cirq.LineQid(0, 4),
@@ -180,7 +180,7 @@ def test_for_qid_shape():
180
180
  ]
181
181
 
182
182
 
183
- def test_addition_subtraction():
183
+ def test_addition_subtraction() -> None:
184
184
  assert cirq.LineQubit(1) + 2 == cirq.LineQubit(3)
185
185
  assert cirq.LineQubit(3) - 1 == cirq.LineQubit(2)
186
186
  assert 1 + cirq.LineQubit(4) == cirq.LineQubit(5)
@@ -199,16 +199,16 @@ def test_addition_subtraction():
199
199
  )
200
200
 
201
201
 
202
- def test_addition_subtraction_type_error():
202
+ def test_addition_subtraction_type_error() -> None:
203
203
  with pytest.raises(TypeError, match='dave'):
204
- _ = cirq.LineQubit(1) + 'dave'
204
+ _ = cirq.LineQubit(1) + 'dave' # type: ignore[operator]
205
205
  with pytest.raises(TypeError, match='dave'):
206
- _ = cirq.LineQubit(1) - 'dave'
206
+ _ = cirq.LineQubit(1) - 'dave' # type: ignore[operator]
207
207
 
208
208
  with pytest.raises(TypeError, match='dave'):
209
- _ = cirq.LineQid(1, 3) + 'dave'
209
+ _ = cirq.LineQid(1, 3) + 'dave' # type: ignore[operator]
210
210
  with pytest.raises(TypeError, match='dave'):
211
- _ = cirq.LineQid(1, 3) - 'dave'
211
+ _ = cirq.LineQid(1, 3) - 'dave' # type: ignore[operator]
212
212
 
213
213
  with pytest.raises(TypeError, match="Can only add LineQids with identical dimension."):
214
214
  _ = cirq.LineQid(5, dimension=3) + cirq.LineQid(3, dimension=4)
@@ -217,17 +217,17 @@ def test_addition_subtraction_type_error():
217
217
  _ = cirq.LineQid(5, dimension=3) - cirq.LineQid(3, dimension=4)
218
218
 
219
219
 
220
- def test_neg():
220
+ def test_neg() -> None:
221
221
  assert -cirq.LineQubit(1) == cirq.LineQubit(-1)
222
222
  assert -cirq.LineQid(1, dimension=3) == cirq.LineQid(-1, dimension=3)
223
223
 
224
224
 
225
- def test_json_dict():
225
+ def test_json_dict() -> None:
226
226
  assert cirq.LineQubit(5)._json_dict_() == {'x': 5}
227
227
  assert cirq.LineQid(5, 3)._json_dict_() == {'x': 5, 'dimension': 3}
228
228
 
229
229
 
230
- def test_for_gate():
230
+ def test_for_gate() -> None:
231
231
  class NoQidGate:
232
232
  def _qid_shape_(self):
233
233
  return ()
@@ -263,24 +263,24 @@ def test_for_gate():
263
263
  ]
264
264
 
265
265
 
266
- def test_immutable():
266
+ def test_immutable() -> None:
267
267
  # Match one of two strings. The second one is message returned since python 3.11.
268
268
  with pytest.raises(
269
269
  AttributeError,
270
270
  match="(can't set attribute)|(property 'x' of 'LineQubit' object has no setter)",
271
271
  ):
272
272
  q = cirq.LineQubit(5)
273
- q.x = 6
273
+ q.x = 6 # type: ignore[misc]
274
274
 
275
275
  with pytest.raises(
276
276
  AttributeError,
277
277
  match="(can't set attribute)|(property 'x' of 'LineQid' object has no setter)",
278
278
  ):
279
- q = cirq.LineQid(5, dimension=4)
280
- q.x = 6
279
+ qid = cirq.LineQid(5, dimension=4)
280
+ qid.x = 6 # type: ignore[misc]
281
281
 
282
282
 
283
- def test_numeric():
283
+ def test_numeric() -> None:
284
284
  assert int(cirq.LineQubit(x=5)) == 5
285
285
  assert float(cirq.LineQubit(x=5)) == 5
286
286
  assert complex(cirq.LineQubit(x=5)) == 5 + 0j
@@ -290,7 +290,7 @@ def test_numeric():
290
290
 
291
291
 
292
292
  @pytest.mark.parametrize('dtype', (np.int8, np.int64, float, np.float64))
293
- def test_numpy_index(dtype):
293
+ def test_numpy_index(dtype) -> None:
294
294
  np5 = dtype(5)
295
295
  q = cirq.LineQubit(np5)
296
296
  assert hash(q) == 5
@@ -298,15 +298,15 @@ def test_numpy_index(dtype):
298
298
  assert q.dimension == 2
299
299
  assert isinstance(q.dimension, int)
300
300
 
301
- q = cirq.LineQid(np5, dtype(3))
302
- hash(q) # doesn't throw
303
- assert q.x == 5
304
- assert q.dimension == 3
305
- assert isinstance(q.dimension, int)
301
+ qid = cirq.LineQid(np5, dtype(3))
302
+ hash(qid) # doesn't throw
303
+ assert qid.x == 5
304
+ assert qid.dimension == 3
305
+ assert isinstance(qid.dimension, int)
306
306
 
307
307
 
308
308
  @pytest.mark.parametrize('dtype', (float, np.float64))
309
- def test_non_integer_index(dtype):
309
+ def test_non_integer_index(dtype) -> None:
310
310
  # Not supported type-wise, but is used in practice, so behavior needs to be preserved.
311
311
  q = cirq.LineQubit(dtype(5.5))
312
312
  assert q.x == 5.5
@@ -66,7 +66,7 @@ def _node_and_coordinates(
66
66
 
67
67
  def draw_gridlike(
68
68
  graph: nx.Graph, ax: plt.Axes | None = None, tilted: bool = True, **kwargs
69
- ) -> dict[Any, tuple[int, int]]:
69
+ ) -> dict[_GRIDLIKE_NODE, tuple[int, int]]:
70
70
  """Draw a grid-like graph using Matplotlib.
71
71
 
72
72
  This wraps nx.draw_networkx to produce a matplotlib drawing of the graph. Nodes
@@ -220,7 +220,7 @@ class TiltedSquareLattice(NamedTopology):
220
220
  n_nodes += ((self.width + 1) // 2) * ((self.height + 1) // 2)
221
221
  object.__setattr__(self, 'n_nodes', n_nodes)
222
222
 
223
- def draw(self, ax=None, tilted=True, **kwargs):
223
+ def draw(self, ax=None, tilted=True, **kwargs) -> dict[_GRIDLIKE_NODE, tuple[int, int]]:
224
224
  """Draw this graph using Matplotlib.
225
225
 
226
226
  Args:
@@ -301,7 +301,7 @@ def get_placements(
301
301
 
302
302
  def _is_valid_placement_helper(
303
303
  big_graph: nx.Graph, small_mapped: nx.Graph, small_to_big_mapping: dict
304
- ):
304
+ ) -> bool:
305
305
  """Helper function for `is_valid_placement` that assumes the mapping of `small_graph` has
306
306
  already occurred.
307
307
 
@@ -311,7 +311,9 @@ def _is_valid_placement_helper(
311
311
  return (subgraph.nodes == small_mapped.nodes) and (subgraph.edges == small_mapped.edges)
312
312
 
313
313
 
314
- def is_valid_placement(big_graph: nx.Graph, small_graph: nx.Graph, small_to_big_mapping: dict):
314
+ def is_valid_placement(
315
+ big_graph: nx.Graph, small_graph: nx.Graph, small_to_big_mapping: dict
316
+ ) -> bool:
315
317
  """Return whether the given placement is a valid placement of small_graph onto big_graph.
316
318
 
317
319
  This is done by making sure all the nodes and edges on the mapped version of `small_graph`
@@ -338,7 +340,7 @@ def draw_placements(
338
340
  axes: Sequence[plt.Axes] | None = None,
339
341
  tilted: bool = True,
340
342
  bad_placement_callback: Callable[[plt.Axes, int], None] | None = None,
341
- ):
343
+ ) -> None:
342
344
  """Draw a visualization of placements from small_graph onto big_graph using Matplotlib.
343
345
 
344
346
  The entire `big_graph` will be drawn with default blue colored nodes. `small_graph` nodes
@@ -108,7 +108,7 @@ def test_draw_gridlike(tilted) -> None:
108
108
  ax = MagicMock()
109
109
  pos = draw_gridlike(graph, tilted=tilted, ax=ax)
110
110
  ax.scatter.assert_called()
111
- for (row, column), _ in pos.items():
111
+ for row, column in pos.keys(): # type: ignore[misc]
112
112
  assert 0 <= row < 3
113
113
  assert 0 <= column < 3
114
114
 
@@ -120,7 +120,8 @@ def test_draw_gridlike_qubits(tilted) -> None:
120
120
  ax = MagicMock()
121
121
  pos = draw_gridlike(graph, tilted=tilted, ax=ax)
122
122
  ax.scatter.assert_called()
123
- for q, _ in pos.items():
123
+ for q in pos.keys():
124
+ assert isinstance(q, cirq.GridQubit)
124
125
  assert 0 <= q.row < 3
125
126
  assert 0 <= q.col < 3
126
127
 
@@ -235,7 +235,7 @@ class ConstantQubitNoiseModel(NoiseModel):
235
235
  def __repr__(self) -> str:
236
236
  return f'cirq.ConstantQubitNoiseModel({self.qubit_noise_gate!r})'
237
237
 
238
- def noisy_moment(self, moment: cirq.Moment, system_qubits: Sequence[cirq.Qid]):
238
+ def noisy_moment(self, moment: cirq.Moment, system_qubits: Sequence[cirq.Qid]) -> cirq.OP_TREE:
239
239
  # Noise should not be appended to previously-added noise.
240
240
  if self.is_virtual_moment(moment):
241
241
  return moment
@@ -34,7 +34,7 @@ class SampleNoiseProperties(NoiseProperties):
34
34
  self.qubits = system_qubits
35
35
  self.qubit_pairs = qubit_pairs
36
36
 
37
- def build_noise_models(self):
37
+ def build_noise_models(self) -> list[cirq.NoiseModel]:
38
38
  add_h = InsertionNoiseModel({OpIdentifier(cirq.Gate, q): cirq.H(q) for q in self.qubits})
39
39
  add_iswap = InsertionNoiseModel(
40
40
  {OpIdentifier(cirq.Gate, *qs): cirq.ISWAP(*qs) for qs in self.qubit_pairs}
@@ -48,7 +48,7 @@ class OpIdentifier:
48
48
  def _predicate(self, *args, **kwargs):
49
49
  return self._gate_family._predicate(*args, **kwargs)
50
50
 
51
- def is_proper_subtype_of(self, op_id: OpIdentifier):
51
+ def is_proper_subtype_of(self, op_id: OpIdentifier) -> bool:
52
52
  """Returns true if this is contained within op_id, but not equal to it.
53
53
 
54
54
  If this returns true, (x in self) implies (x in op_id), but the reverse
@@ -18,13 +18,13 @@ import cirq
18
18
  from cirq.devices.noise_utils import OpIdentifier
19
19
 
20
20
 
21
- def test_op_identifier():
21
+ def test_op_identifier() -> None:
22
22
  op_id = OpIdentifier(cirq.XPowGate)
23
23
  assert cirq.X(cirq.LineQubit(1)) in op_id
24
24
  assert cirq.Rx(rads=1) in op_id
25
25
 
26
26
 
27
- def test_op_identifier_subtypes():
27
+ def test_op_identifier_subtypes() -> None:
28
28
  gate_id = OpIdentifier(cirq.Gate)
29
29
  xpow_id = OpIdentifier(cirq.XPowGate)
30
30
  x_on_q0_id = OpIdentifier(cirq.XPowGate, cirq.LineQubit(0))
@@ -34,7 +34,7 @@ def test_op_identifier_subtypes():
34
34
  assert not xpow_id.is_proper_subtype_of(xpow_id)
35
35
 
36
36
 
37
- def test_op_id_str():
37
+ def test_op_id_str() -> None:
38
38
  op_id = OpIdentifier(cirq.XPowGate, cirq.LineQubit(0))
39
39
  assert str(op_id) == "<class 'cirq.ops.common_gates.XPowGate'>(cirq.LineQubit(0),)"
40
40
  assert repr(op_id) == (
@@ -42,7 +42,7 @@ def test_op_id_str():
42
42
  )
43
43
 
44
44
 
45
- def test_op_id_swap():
45
+ def test_op_id_swap() -> None:
46
46
  q0, q1 = cirq.LineQubit.range(2)
47
47
  base_id = OpIdentifier(cirq.CZPowGate, q0, q1)
48
48
  swap_id = OpIdentifier(base_id.gate_type, *base_id.qubits[::-1])
@@ -52,8 +52,8 @@ def test_op_id_swap():
52
52
  assert cirq.CZ(q1, q0) in swap_id
53
53
 
54
54
 
55
- def test_op_id_instance():
55
+ def test_op_id_instance() -> None:
56
56
  q0 = cirq.LineQubit.range(1)[0]
57
57
  gate = cirq.SingleQubitCliffordGate.from_xz_map((cirq.X, False), (cirq.Z, False))
58
- op_id = OpIdentifier(gate, q0)
58
+ op_id = OpIdentifier(type(gate), q0)
59
59
  cirq.testing.assert_equivalent_repr(op_id)