cirq-core 1.6.0.dev20250529194600__py3-none-any.whl → 1.6.0.dev20250530203656__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 (50) hide show
  1. cirq/_version.py +1 -1
  2. cirq/_version_test.py +1 -1
  3. cirq/circuits/_bucket_priority_queue_test.py +20 -20
  4. cirq/circuits/circuit_operation_test.py +58 -56
  5. cirq/circuits/frozen_circuit_test.py +6 -5
  6. cirq/circuits/qasm_output_test.py +22 -22
  7. cirq/circuits/text_diagram_drawer_test.py +17 -17
  8. cirq/contrib/custom_simulators/custom_state_simulator_test.py +11 -10
  9. cirq/contrib/qasm_import/_lexer_test.py +47 -13
  10. cirq/contrib/qasm_import/_parser_test.py +5 -5
  11. cirq/contrib/qasm_import/qasm_test.py +4 -4
  12. cirq/contrib/quirk/export_to_quirk_test.py +16 -16
  13. cirq/devices/insertion_noise_model.py +2 -2
  14. cirq/linalg/transformations_test.py +71 -43
  15. cirq/ops/boolean_hamiltonian_test.py +8 -8
  16. cirq/ops/classically_controlled_operation_test.py +51 -51
  17. cirq/ops/clifford_gate_test.py +58 -54
  18. cirq/ops/common_gate_families_test.py +9 -7
  19. cirq/ops/common_gates_test.py +81 -81
  20. cirq/ops/control_values_test.py +17 -17
  21. cirq/ops/controlled_gate_test.py +34 -32
  22. cirq/ops/diagonal_gate_test.py +11 -11
  23. cirq/ops/eigen_gate_test.py +28 -20
  24. cirq/ops/fourier_transform.py +1 -3
  25. cirq/ops/fourier_transform_test.py +13 -12
  26. cirq/ops/gate_operation_test.py +43 -42
  27. cirq/ops/global_phase_op_test.py +22 -20
  28. cirq/ops/identity_test.py +21 -20
  29. cirq/ops/kraus_channel_test.py +11 -11
  30. cirq/ops/named_qubit_test.py +13 -13
  31. cirq/ops/op_tree_test.py +19 -19
  32. cirq/ops/phased_x_gate_test.py +16 -16
  33. cirq/ops/phased_x_z_gate_test.py +14 -11
  34. cirq/ops/projector_test.py +16 -16
  35. cirq/ops/qubit_order_test.py +10 -10
  36. cirq/ops/raw_types.py +2 -2
  37. cirq/ops/raw_types_test.py +51 -49
  38. cirq/ops/wait_gate.py +1 -1
  39. cirq/ops/wait_gate_test.py +6 -6
  40. cirq/protocols/qasm.py +2 -2
  41. cirq/qis/entropy_test.py +1 -1
  42. cirq/testing/consistent_protocols.py +1 -3
  43. cirq/testing/consistent_protocols_test.py +3 -3
  44. cirq/value/digits.py +5 -0
  45. cirq/value/duration.py +1 -1
  46. {cirq_core-1.6.0.dev20250529194600.dist-info → cirq_core-1.6.0.dev20250530203656.dist-info}/METADATA +1 -1
  47. {cirq_core-1.6.0.dev20250529194600.dist-info → cirq_core-1.6.0.dev20250530203656.dist-info}/RECORD +50 -50
  48. {cirq_core-1.6.0.dev20250529194600.dist-info → cirq_core-1.6.0.dev20250530203656.dist-info}/WHEEL +0 -0
  49. {cirq_core-1.6.0.dev20250529194600.dist-info → cirq_core-1.6.0.dev20250530203656.dist-info}/licenses/LICENSE +0 -0
  50. {cirq_core-1.6.0.dev20250529194600.dist-info → cirq_core-1.6.0.dev20250530203656.dist-info}/top_level.txt +0 -0
@@ -8,7 +8,7 @@ import pytest
8
8
  import cirq
9
9
 
10
10
 
11
- def test_projector_matrix():
11
+ def test_projector_matrix() -> None:
12
12
  q0 = cirq.NamedQubit('q0')
13
13
 
14
14
  zero_projector = cirq.ProjectorString({q0: 0})
@@ -18,11 +18,11 @@ def test_projector_matrix():
18
18
  np.testing.assert_allclose(zero_projector.matrix().toarray(), [[1.0, 0.0], [0.0, 0.0]])
19
19
  np.testing.assert_allclose(one_projector.matrix().toarray(), [[0.0, 0.0], [0.0, 1.0]])
20
20
  np.testing.assert_allclose(
21
- coeff_projector.matrix().toarray(), [[1.23 + 4.56j, 0.0], [0.0, 0.0]]
21
+ coeff_projector.matrix().toarray(), np.asarray([[1.23 + 4.56j, 0.0], [0.0, 0.0]])
22
22
  )
23
23
 
24
24
 
25
- def test_projector_repr():
25
+ def test_projector_repr() -> None:
26
26
  q0 = cirq.NamedQubit('q0')
27
27
 
28
28
  assert (
@@ -31,14 +31,14 @@ def test_projector_repr():
31
31
  )
32
32
 
33
33
 
34
- def test_projector_from_np_array():
34
+ def test_projector_from_np_array() -> None:
35
35
  q0 = cirq.NamedQubit('q0')
36
36
 
37
37
  zero_projector = cirq.ProjectorString({q0: 0})
38
38
  np.testing.assert_allclose(zero_projector.matrix().toarray(), [[1.0, 0.0], [0.0, 0.0]])
39
39
 
40
40
 
41
- def test_projector_matrix_missing_qid():
41
+ def test_projector_matrix_missing_qid() -> None:
42
42
  q0, q1 = cirq.LineQubit.range(2)
43
43
  proj = cirq.ProjectorString({q0: 0})
44
44
  proj_with_coefficient = cirq.ProjectorString({q0: 0}, 1.23 + 4.56j)
@@ -56,7 +56,7 @@ def test_projector_matrix_missing_qid():
56
56
  )
57
57
 
58
58
 
59
- def test_equality():
59
+ def test_equality() -> None:
60
60
  q0 = cirq.NamedQubit('q0')
61
61
 
62
62
  obj1a = cirq.ProjectorString({q0: 0})
@@ -70,7 +70,7 @@ def test_equality():
70
70
  eq.add_equality_group(obj3)
71
71
 
72
72
 
73
- def test_get_values():
73
+ def test_get_values() -> None:
74
74
  q0 = cirq.NamedQubit('q0')
75
75
  d = cirq.ProjectorString({q0: 0}, 1.23 + 4.56j)
76
76
 
@@ -79,14 +79,14 @@ def test_get_values():
79
79
  assert d.coefficient == 1.23 + 4.56j
80
80
 
81
81
 
82
- def test_expectation_from_state_vector_basis_states_empty():
82
+ def test_expectation_from_state_vector_basis_states_empty() -> None:
83
83
  q0 = cirq.NamedQubit('q0')
84
84
  d = cirq.ProjectorString({})
85
85
 
86
86
  np.testing.assert_allclose(d.expectation_from_state_vector(np.array([1.0, 0.0]), {q0: 0}), 1.0)
87
87
 
88
88
 
89
- def test_expectation_from_state_vector_basis_states_single_qubits():
89
+ def test_expectation_from_state_vector_basis_states_single_qubits() -> None:
90
90
  q0 = cirq.NamedQubit('q0')
91
91
  d = cirq.ProjectorString({q0: 0})
92
92
 
@@ -94,7 +94,7 @@ def test_expectation_from_state_vector_basis_states_single_qubits():
94
94
  np.testing.assert_allclose(d.expectation_from_state_vector(np.array([0.0, 1.0]), {q0: 0}), 0.0)
95
95
 
96
96
 
97
- def test_expectation_from_state_vector_basis_states_three_qubits():
97
+ def test_expectation_from_state_vector_basis_states_three_qubits() -> None:
98
98
  q0 = cirq.NamedQubit('q0')
99
99
  q1 = cirq.NamedQubit('q1')
100
100
  q2 = cirq.NamedQubit('q2')
@@ -144,7 +144,7 @@ def test_expectation_from_state_vector_basis_states_three_qubits():
144
144
  )
145
145
 
146
146
 
147
- def test_expectation_from_density_matrix_three_qubits():
147
+ def test_expectation_from_density_matrix_three_qubits() -> None:
148
148
  q0 = cirq.NamedQubit('q0')
149
149
  q1 = cirq.NamedQubit('q1')
150
150
  q2 = cirq.NamedQubit('q2')
@@ -194,7 +194,7 @@ def test_expectation_from_density_matrix_three_qubits():
194
194
  )
195
195
 
196
196
 
197
- def test_consistency_state_vector_and_density_matrix():
197
+ def test_consistency_state_vector_and_density_matrix() -> None:
198
198
  q0 = cirq.NamedQubit('q0')
199
199
  q1 = cirq.NamedQubit('q1')
200
200
  q2 = cirq.NamedQubit('q2')
@@ -212,7 +212,7 @@ def test_consistency_state_vector_and_density_matrix():
212
212
  )
213
213
 
214
214
 
215
- def test_expectation_higher_dims():
215
+ def test_expectation_higher_dims() -> None:
216
216
  qubit = cirq.NamedQid('q0', dimension=2)
217
217
  qutrit = cirq.NamedQid('q1', dimension=3)
218
218
 
@@ -224,7 +224,7 @@ def test_expectation_higher_dims():
224
224
  _ = (d.expectation_from_state_vector(np.zeros(2 * 3), {qubit: 0, qutrit: 0}),)
225
225
 
226
226
 
227
- def test_expectation_with_coefficient():
227
+ def test_expectation_with_coefficient() -> None:
228
228
  q0 = cirq.NamedQubit('q0')
229
229
  d = cirq.ProjectorString({q0: 0}, coefficient=(0.6 + 0.4j))
230
230
 
@@ -237,7 +237,7 @@ def test_expectation_with_coefficient():
237
237
  )
238
238
 
239
239
 
240
- def test_expectation_from_density_matrix_basis_states_empty():
240
+ def test_expectation_from_density_matrix_basis_states_empty() -> None:
241
241
  q0 = cirq.NamedQubit('q0')
242
242
  d = cirq.ProjectorString({})
243
243
 
@@ -246,7 +246,7 @@ def test_expectation_from_density_matrix_basis_states_empty():
246
246
  )
247
247
 
248
248
 
249
- def test_expectation_from_density_matrix_basis_states_single_qubits():
249
+ def test_expectation_from_density_matrix_basis_states_single_qubits() -> None:
250
250
  q0 = cirq.NamedQubit('q0')
251
251
  d = cirq.ProjectorString({q0: 0})
252
252
 
@@ -19,7 +19,7 @@ import pytest
19
19
  import cirq
20
20
 
21
21
 
22
- def test_default():
22
+ def test_default() -> None:
23
23
  a2 = cirq.NamedQubit('a2')
24
24
  a10 = cirq.NamedQubit('a10')
25
25
  b = cirq.NamedQubit('b')
@@ -32,7 +32,7 @@ def test_default():
32
32
  assert sorted([q5, a10, a2, b, q4]) == [q4, q5, a2, a10, b]
33
33
 
34
34
 
35
- def test_default_grouping():
35
+ def test_default_grouping() -> None:
36
36
  presorted = (
37
37
  cirq.GridQubit(0, 1),
38
38
  cirq.GridQubit(1, 0),
@@ -50,7 +50,7 @@ def test_default_grouping():
50
50
  assert cirq.QubitOrder.DEFAULT.order_for(reversed(presorted)) == presorted
51
51
 
52
52
 
53
- def test_explicit():
53
+ def test_explicit() -> None:
54
54
  a2 = cirq.NamedQubit('a2')
55
55
  a10 = cirq.NamedQubit('a10')
56
56
  b = cirq.NamedQubit('b')
@@ -64,7 +64,7 @@ def test_explicit():
64
64
  _ = q.order_for([cirq.NamedQubit('c')])
65
65
 
66
66
 
67
- def test_explicit_with_fallback():
67
+ def test_explicit_with_fallback() -> None:
68
68
  a2 = cirq.NamedQubit('a2')
69
69
  a10 = cirq.NamedQubit('a10')
70
70
  b = cirq.NamedQubit('b')
@@ -76,7 +76,7 @@ def test_explicit_with_fallback():
76
76
  assert q.order_for([a10, a2]) == (b, a2, a10)
77
77
 
78
78
 
79
- def test_sorted_by():
79
+ def test_sorted_by() -> None:
80
80
  a = cirq.NamedQubit('2')
81
81
  b = cirq.NamedQubit('10')
82
82
  c = cirq.NamedQubit('-5')
@@ -88,7 +88,7 @@ def test_sorted_by():
88
88
  assert q.order_for([a, b, c]) == (b, a, c)
89
89
 
90
90
 
91
- def test_map():
91
+ def test_map() -> None:
92
92
  b = cirq.NamedQubit('b!')
93
93
  q = cirq.QubitOrder.explicit([cirq.NamedQubit('b')]).map(
94
94
  internalize=lambda e: cirq.NamedQubit(e.name[:-1]),
@@ -99,7 +99,7 @@ def test_map():
99
99
  assert q.order_for([b]) == (b,)
100
100
 
101
101
 
102
- def test_qubit_order_or_list():
102
+ def test_qubit_order_or_list() -> None:
103
103
  b = cirq.NamedQubit('b')
104
104
 
105
105
  implied_by_list = cirq.QubitOrder.as_qubit_order([b])
@@ -116,7 +116,7 @@ def test_qubit_order_or_list():
116
116
  assert ordered is passed_through
117
117
 
118
118
 
119
- def test_qubit_order_iterator():
119
+ def test_qubit_order_iterator() -> None:
120
120
  generator = (q for q in cirq.LineQubit.range(5))
121
121
  assert cirq.QubitOrder.explicit(generator).order_for((cirq.LineQubit(3),)) == tuple(
122
122
  cirq.LineQubit.range(5)
@@ -128,6 +128,6 @@ def test_qubit_order_iterator():
128
128
  )
129
129
 
130
130
 
131
- def test_qubit_order_invalid():
131
+ def test_qubit_order_invalid() -> None:
132
132
  with pytest.raises(ValueError, match="Don't know how to interpret <5> as a Basis."):
133
- _ = cirq.QubitOrder.as_qubit_order(5)
133
+ _ = cirq.QubitOrder.as_qubit_order(5) # type: ignore[arg-type]
cirq/ops/raw_types.py CHANGED
@@ -227,7 +227,7 @@ class Gate(metaclass=value.ABCMetaImplementAnyOneOf):
227
227
  if __cirq_debug__.get():
228
228
  _validate_qid_shape(self, qubits)
229
229
 
230
- def on(self, *qubits: Qid) -> Operation:
230
+ def on(self, *qubits: Qid) -> cirq.Operation:
231
231
  """Returns an application of this gate to the given qubits.
232
232
 
233
233
  Args:
@@ -654,7 +654,7 @@ class Operation(metaclass=abc.ABCMeta):
654
654
  *self.qubits
655
655
  )
656
656
 
657
- def validate_args(self, qubits: Sequence[cirq.Qid]):
657
+ def validate_args(self, qubits: Sequence[cirq.Qid]) -> None:
658
658
  """Raises an exception if the `qubits` don't match this operation's qid
659
659
  shape.
660
660
 
@@ -14,7 +14,7 @@
14
14
 
15
15
  from __future__ import annotations
16
16
 
17
- from typing import AbstractSet, Any, Iterator
17
+ from typing import AbstractSet, Any, cast, Iterator
18
18
 
19
19
  import numpy as np
20
20
  import pytest
@@ -28,7 +28,7 @@ class ValidQubit(cirq.Qid):
28
28
  self._name = name
29
29
 
30
30
  @property
31
- def dimension(self):
31
+ def dimension(self) -> int:
32
32
  return 2
33
33
 
34
34
  def _comparison_key(self):
@@ -51,19 +51,19 @@ class ValidQid(cirq.Qid):
51
51
  def dimension(self):
52
52
  return self._dimension
53
53
 
54
- def with_dimension(self, dimension):
54
+ def with_dimension(self, dimension) -> ValidQid:
55
55
  return ValidQid(self._name, dimension)
56
56
 
57
57
  def _comparison_key(self):
58
58
  return self._name
59
59
 
60
60
 
61
- def test_wrapped_qid():
61
+ def test_wrapped_qid() -> None:
62
62
  assert type(ValidQubit('a').with_dimension(3)) is not ValidQubit
63
63
  assert type(ValidQubit('a').with_dimension(2)) is ValidQubit
64
64
  assert type(ValidQubit('a').with_dimension(5).with_dimension(2)) is ValidQubit
65
65
  assert ValidQubit('a').with_dimension(3).with_dimension(4) == ValidQubit('a').with_dimension(4)
66
- assert ValidQubit('a').with_dimension(3).qubit == ValidQubit('a')
66
+ assert ValidQubit('a').with_dimension(3).qubit == ValidQubit('a') # type: ignore[attr-defined]
67
67
  assert ValidQubit('a').with_dimension(3) == ValidQubit('a').with_dimension(3)
68
68
  assert ValidQubit('a').with_dimension(3) < ValidQubit('a').with_dimension(4)
69
69
  assert ValidQubit('a').with_dimension(3) < ValidQubit('b').with_dimension(3)
@@ -74,7 +74,7 @@ def test_wrapped_qid():
74
74
  )
75
75
  assert str(ValidQubit('a').with_dimension(3)) == 'TQ_a (d=3)'
76
76
 
77
- assert ValidQubit('zz').with_dimension(3)._json_dict_() == {
77
+ assert ValidQubit('zz').with_dimension(3)._json_dict_() == { # type: ignore[attr-defined]
78
78
  'qubit': ValidQubit('zz'),
79
79
  'dimension': 3,
80
80
  }
@@ -88,7 +88,7 @@ def test_wrapped_qid():
88
88
  assert ValidQubit('zz') >= ValidQubit('aa')
89
89
 
90
90
 
91
- def test_qid_dimension():
91
+ def test_qid_dimension() -> None:
92
92
  assert ValidQubit('a').dimension == 2
93
93
  assert ValidQubit('a').with_dimension(3).dimension == 3
94
94
  with pytest.raises(ValueError, match='Wrong qid dimension'):
@@ -109,7 +109,7 @@ class ValiGate(cirq.Gate):
109
109
  def _num_qubits_(self):
110
110
  return 2
111
111
 
112
- def validate_args(self, qubits):
112
+ def validate_args(self, qubits) -> None:
113
113
  if len(qubits) == 1:
114
114
  return # Bypass check for some tests
115
115
  super().validate_args(qubits)
@@ -118,7 +118,7 @@ class ValiGate(cirq.Gate):
118
118
  return True
119
119
 
120
120
 
121
- def test_gate():
121
+ def test_gate() -> None:
122
122
  a, b, c = cirq.LineQubit.range(3)
123
123
 
124
124
  g = ValiGate()
@@ -138,7 +138,7 @@ def test_gate():
138
138
  assert g.controlled(0) is g
139
139
 
140
140
 
141
- def test_op():
141
+ def test_op() -> None:
142
142
  a, b, c, d = cirq.LineQubit.range(4)
143
143
  g = ValiGate()
144
144
  op = g(a, b)
@@ -148,7 +148,7 @@ def test_op():
148
148
  assert controlled_op.controls == (c, d)
149
149
 
150
150
 
151
- def test_op_validate():
151
+ def test_op_validate() -> None:
152
152
  op = cirq.X(cirq.LineQid(0, 2))
153
153
  op2 = cirq.CNOT(*cirq.LineQid.range(2, dimension=2))
154
154
  op.validate_args([cirq.LineQid(1, 2)]) # Valid
@@ -161,7 +161,7 @@ def test_op_validate():
161
161
  op2.validate_args([cirq.LineQid(1, 2), cirq.LineQid(1, 2)])
162
162
 
163
163
 
164
- def test_disable_op_validation():
164
+ def test_disable_op_validation() -> None:
165
165
  q0, q1 = cirq.LineQubit.range(2)
166
166
  h_op = cirq.H(q0)
167
167
 
@@ -184,7 +184,7 @@ def test_disable_op_validation():
184
184
  h_op.validate_args([q0, q1])
185
185
 
186
186
 
187
- def test_default_validation_and_inverse():
187
+ def test_default_validation_and_inverse() -> None:
188
188
  class TestGate(cirq.Gate):
189
189
  def _num_qubits_(self):
190
190
  return 2
@@ -206,13 +206,15 @@ def test_default_validation_and_inverse():
206
206
  with pytest.raises(ValueError, match='number of qubits'):
207
207
  TestGate().on(a)
208
208
 
209
- t = TestGate().on(a, b)
210
- i = t**-1
209
+ t = cast(cirq.GateOperation, TestGate().on(a, b))
210
+ i = cast(cirq.GateOperation, t**-1)
211
211
  assert i**-1 == t
212
212
  assert t**-1 == i
213
213
  assert cirq.decompose(i) == [cirq.X(a), cirq.S(b) ** -1, cirq.Z(a)]
214
- assert [*i._decompose_()] == [cirq.X(a), cirq.S(b) ** -1, cirq.Z(a)]
215
- assert [*i.gate._decompose_([a, b])] == [cirq.X(a), cirq.S(b) ** -1, cirq.Z(a)]
214
+ assert [*i._decompose_()] == [cirq.X(a), cirq.S(b) ** -1, cirq.Z(a)] # type: ignore[misc]
215
+ gate = i.gate
216
+ assert gate is not None
217
+ assert [*gate._decompose_([a, b])] == [cirq.X(a), cirq.S(b) ** -1, cirq.Z(a)] # type: ignore
216
218
  cirq.testing.assert_allclose_up_to_global_phase(
217
219
  cirq.unitary(i), cirq.unitary(t).conj().T, atol=1e-8
218
220
  )
@@ -220,7 +222,7 @@ def test_default_validation_and_inverse():
220
222
  cirq.testing.assert_implements_consistent_protocols(i, local_vals={'TestGate': TestGate})
221
223
 
222
224
 
223
- def test_default_no_qubits():
225
+ def test_default_no_qubits() -> None:
224
226
  class TestOp(cirq.Operation):
225
227
  def with_qubits(self, *new_qubits):
226
228
  raise NotImplementedError()
@@ -231,11 +233,11 @@ def test_default_no_qubits():
231
233
 
232
234
  op = TestOp()
233
235
  assert op.controlled_by(*[]) is op
234
- op = TestOp().with_tags("abc")
235
- assert op.classical_controls == frozenset()
236
+ tagged_op = TestOp().with_tags("abc")
237
+ assert tagged_op.classical_controls == frozenset()
236
238
 
237
239
 
238
- def test_default_inverse():
240
+ def test_default_inverse() -> None:
239
241
  class TestGate(cirq.Gate):
240
242
  def _num_qubits_(self):
241
243
  return 3
@@ -250,7 +252,7 @@ def test_default_inverse():
250
252
  )
251
253
 
252
254
 
253
- def test_no_inverse_if_not_unitary():
255
+ def test_no_inverse_if_not_unitary() -> None:
254
256
  class TestGate(cirq.Gate):
255
257
  def _num_qubits_(self):
256
258
  return 1
@@ -261,7 +263,7 @@ def test_no_inverse_if_not_unitary():
261
263
  assert cirq.inverse(TestGate(), None) is None
262
264
 
263
265
 
264
- def test_default_qudit_inverse():
266
+ def test_default_qudit_inverse() -> None:
265
267
  class TestGate(cirq.Gate):
266
268
  def _qid_shape_(self):
267
269
  return (1, 2, 3)
@@ -286,11 +288,11 @@ def test_default_qudit_inverse():
286
288
  (-cirq.X * sympy.Symbol('s'), -sympy.Symbol('s') * cirq.X),
287
289
  ),
288
290
  )
289
- def test_gate_algebra(expression, expected_result):
291
+ def test_gate_algebra(expression, expected_result) -> None:
290
292
  assert expression == expected_result
291
293
 
292
294
 
293
- def test_gate_shape():
295
+ def test_gate_shape() -> None:
294
296
  class ShapeGate(cirq.Gate):
295
297
  def _qid_shape_(self):
296
298
  return (1, 2, 3, 4)
@@ -319,7 +321,7 @@ def test_gate_shape():
319
321
  assert dep_gate.num_qubits() == 3
320
322
 
321
323
 
322
- def test_gate_shape_protocol():
324
+ def test_gate_shape_protocol() -> None:
323
325
  """This test is only needed while the `_num_qubits_` and `_qid_shape_`
324
326
  methods are implemented as alternatives. This can be removed once the
325
327
  deprecated `num_qubits` method is removed."""
@@ -379,7 +381,7 @@ def test_gate_shape_protocol():
379
381
  assert QubitGate().num_qubits() == 2 # Deprecated
380
382
 
381
383
 
382
- def test_operation_shape():
384
+ def test_operation_shape() -> None:
383
385
  class FixedQids(cirq.Operation):
384
386
  def with_qubits(self, *new_qids):
385
387
  raise NotImplementedError
@@ -421,12 +423,12 @@ def test_operation_shape():
421
423
  assert cirq.num_qubits(shape_op) == 4
422
424
 
423
425
 
424
- def test_gate_json_dict():
426
+ def test_gate_json_dict() -> None:
425
427
  g = cirq.CSWAP # not an eigen gate (which has its own _json_dict_)
426
428
  assert g._json_dict_() == {}
427
429
 
428
430
 
429
- def test_inverse_composite_diagram_info():
431
+ def test_inverse_composite_diagram_info() -> None:
430
432
  class Gate(cirq.Gate):
431
433
  def _decompose_(self, qubits):
432
434
  return cirq.S.on(qubits[0])
@@ -453,7 +455,7 @@ def test_inverse_composite_diagram_info():
453
455
  )
454
456
 
455
457
 
456
- def test_tagged_operation_equality():
458
+ def test_tagged_operation_equality() -> None:
457
459
  eq = cirq.testing.EqualsTester()
458
460
  q1 = cirq.GridQubit(1, 1)
459
461
  op = cirq.X(q1)
@@ -470,7 +472,7 @@ def test_tagged_operation_equality():
470
472
  )
471
473
 
472
474
 
473
- def test_tagged_operation():
475
+ def test_tagged_operation() -> None:
474
476
  q1 = cirq.GridQubit(1, 1)
475
477
  q2 = cirq.GridQubit(2, 2)
476
478
  op = cirq.X(q1).with_tags('tag1')
@@ -491,7 +493,7 @@ def test_tagged_operation():
491
493
  _ = cirq.X(q1).with_tags(cirq.Circuit)
492
494
 
493
495
 
494
- def test_with_tags_returns_same_instance_if_possible():
496
+ def test_with_tags_returns_same_instance_if_possible() -> None:
495
497
  untagged = cirq.X(cirq.GridQubit(1, 1))
496
498
  assert untagged.with_tags() is untagged
497
499
 
@@ -499,7 +501,7 @@ def test_with_tags_returns_same_instance_if_possible():
499
501
  assert tagged.with_tags() is tagged
500
502
 
501
503
 
502
- def test_tagged_measurement():
504
+ def test_tagged_measurement() -> None:
503
505
  assert not cirq.is_measurement(cirq.global_phase_operation(coefficient=-1.0).with_tags('tag0'))
504
506
 
505
507
  a = cirq.LineQubit(0)
@@ -513,14 +515,14 @@ def test_tagged_measurement():
513
515
  assert cirq.with_measurement_key_mapping(op, {'x': 'k'}) == op
514
516
 
515
517
 
516
- def test_cannot_remap_non_measurement_gate():
518
+ def test_cannot_remap_non_measurement_gate() -> None:
517
519
  a = cirq.LineQubit(0)
518
520
  op = cirq.X(a).with_tags('tag')
519
521
 
520
522
  assert cirq.with_measurement_key_mapping(op, {'m': 'k'}) is NotImplemented
521
523
 
522
524
 
523
- def test_circuit_diagram():
525
+ def test_circuit_diagram() -> None:
524
526
  class TaggyTag:
525
527
  """Tag with a custom str function to test circuit diagrams."""
526
528
 
@@ -538,7 +540,7 @@ def test_circuit_diagram():
538
540
  exponent_qubit_index=None,
539
541
  auto_exponent_parens=True,
540
542
  )
541
- args = cirq.CircuitDiagramInfoArgs(None, None, None, None, None, False)
543
+ args = cirq.CircuitDiagramInfoArgs(None, None, False, None, None, False)
542
544
  assert cirq.circuit_diagram_info(tagged_h) == expected
543
545
  assert cirq.circuit_diagram_info(tagged_h, args) == cirq.circuit_diagram_info(h)
544
546
 
@@ -555,7 +557,7 @@ def test_circuit_diagram():
555
557
  assert c.to_text_diagram(include_tags=False) == diagram_without_tags
556
558
 
557
559
 
558
- def test_circuit_diagram_tagged_global_phase():
560
+ def test_circuit_diagram_tagged_global_phase() -> None:
559
561
  # Tests global phase operation
560
562
  q = cirq.NamedQubit('a')
561
563
  global_phase = cirq.global_phase_operation(coefficient=-1.0).with_tags('tag0')
@@ -622,7 +624,7 @@ global phase: 0.5π[tag1] 0.5π[tag2]
622
624
  )
623
625
 
624
626
 
625
- def test_circuit_diagram_no_circuit_diagram():
627
+ def test_circuit_diagram_no_circuit_diagram() -> None:
626
628
  class NoCircuitDiagram(cirq.Gate):
627
629
  def num_qubits(self) -> int:
628
630
  return 1
@@ -637,7 +639,7 @@ def test_circuit_diagram_no_circuit_diagram():
637
639
  assert cirq.Circuit(NoCircuitDiagram()(q).with_tags('taggy')).to_text_diagram() == expected
638
640
 
639
641
 
640
- def test_tagged_operation_forwards_protocols():
642
+ def test_tagged_operation_forwards_protocols() -> None:
641
643
  """The results of all protocols applied to an operation with a tag should
642
644
  be equivalent to the result without tags.
643
645
  """
@@ -719,7 +721,7 @@ def test_tagged_operation_forwards_protocols():
719
721
  assert tagged_mixture[1][0] == flip_mixture[1][0]
720
722
  assert np.isclose(tagged_mixture[1][1], flip_mixture[1][1]).all()
721
723
 
722
- qubit_map = {q1: 'q1'}
724
+ qubit_map: dict[cirq.Qid, str] = {q1: 'q1'}
723
725
  qasm_args = cirq.QasmArgs(qubit_id_map=qubit_map)
724
726
  assert cirq.qasm(h, args=qasm_args) == cirq.qasm(tagged_h, args=qasm_args)
725
727
 
@@ -746,7 +748,7 @@ class ParameterizableTag:
746
748
 
747
749
 
748
750
  @pytest.mark.parametrize('resolve_fn', [cirq.resolve_parameters, cirq.resolve_parameters_once])
749
- def test_tagged_operation_resolves_parameterized_tags(resolve_fn):
751
+ def test_tagged_operation_resolves_parameterized_tags(resolve_fn) -> None:
750
752
  q = cirq.GridQubit(0, 0)
751
753
  tag = ParameterizableTag(sympy.Symbol('t'))
752
754
  assert cirq.is_parameterized(tag)
@@ -760,7 +762,7 @@ def test_tagged_operation_resolves_parameterized_tags(resolve_fn):
760
762
  assert cirq.parameter_names(resolved_op) == set()
761
763
 
762
764
 
763
- def test_inverse_composite_standards():
765
+ def test_inverse_composite_standards() -> None:
764
766
  @cirq.value_equality
765
767
  class Gate(cirq.Gate):
766
768
  def __init__(self, param: cirq.TParamVal):
@@ -801,7 +803,7 @@ def test_inverse_composite_standards():
801
803
  assert str(g) == 'C(a)†'
802
804
 
803
805
 
804
- def test_tagged_act_on():
806
+ def test_tagged_act_on() -> None:
805
807
  class YesActOn(cirq.Gate):
806
808
  def _num_qubits_(self) -> int:
807
809
  return 1
@@ -835,7 +837,7 @@ def test_tagged_act_on():
835
837
  cirq.act_on(MissingActOn().with_tags("test"), args)
836
838
 
837
839
 
838
- def test_single_qubit_gate_validates_on_each():
840
+ def test_single_qubit_gate_validates_on_each() -> None:
839
841
  class Example(cirq.testing.SingleQubitGate):
840
842
  def matrix(self):
841
843
  pass
@@ -859,7 +861,7 @@ def test_single_qubit_gate_validates_on_each():
859
861
  _ = g.on_each(*test_non_qubits)
860
862
 
861
863
 
862
- def test_on_each():
864
+ def test_on_each() -> None:
863
865
  class CustomGate(cirq.testing.SingleQubitGate):
864
866
  pass
865
867
 
@@ -890,7 +892,7 @@ def test_on_each():
890
892
  assert c.on_each(qubit_iterator) == [c(a), c(b), c(a), c(b)]
891
893
 
892
894
 
893
- def test_on_each_two_qubits():
895
+ def test_on_each_two_qubits() -> None:
894
896
  a = cirq.NamedQubit('a')
895
897
  b = cirq.NamedQubit('b')
896
898
  g = cirq.testing.TwoQubitGate()
@@ -945,7 +947,7 @@ def test_on_each_two_qubits():
945
947
  assert g.on_each(qubit_iterator) == [g(a, b), g(a, b)]
946
948
 
947
949
 
948
- def test_on_each_three_qubits():
950
+ def test_on_each_three_qubits() -> None:
949
951
  a = cirq.NamedQubit('a')
950
952
  b = cirq.NamedQubit('b')
951
953
  c = cirq.NamedQubit('c')
@@ -995,7 +997,7 @@ def test_on_each_three_qubits():
995
997
  assert g.on_each(qubit_iterator) == [g(a, b, c), g(a, b, c)]
996
998
 
997
999
 
998
- def test_on_each_iterable_qid():
1000
+ def test_on_each_iterable_qid() -> None:
999
1001
  class QidIter(cirq.Qid):
1000
1002
  @property
1001
1003
  def dimension(self) -> int:
@@ -1013,7 +1015,7 @@ def test_on_each_iterable_qid():
1013
1015
  @pytest.mark.parametrize(
1014
1016
  'op', [cirq.X(cirq.NamedQubit("q")), cirq.X(cirq.NamedQubit("q")).with_tags("tagged_op")]
1015
1017
  )
1016
- def test_with_methods_return_self_on_empty_conditions(op):
1018
+ def test_with_methods_return_self_on_empty_conditions(op) -> None:
1017
1019
  assert op is op.with_tags(*[])
1018
1020
  assert op is op.with_classical_controls(*[])
1019
1021
  assert op is op.controlled_by(*[])
cirq/ops/wait_gate.py CHANGED
@@ -33,7 +33,7 @@ class WaitGate(raw_types.Gate):
33
33
 
34
34
  def __init__(
35
35
  self,
36
- duration: cirq.DURATION_LIKE,
36
+ duration: cirq.DURATION_LIKE | int,
37
37
  num_qubits: int | None = None,
38
38
  qid_shape: tuple[int, ...] | None = None,
39
39
  ) -> None:
@@ -22,7 +22,7 @@ import sympy
22
22
  import cirq
23
23
 
24
24
 
25
- def test_init():
25
+ def test_init() -> None:
26
26
  g = cirq.WaitGate(datetime.timedelta(0, 0, 5))
27
27
  assert g.duration == cirq.Duration(micros=5)
28
28
 
@@ -39,13 +39,13 @@ def test_init():
39
39
  _ = cirq.WaitGate(2)
40
40
 
41
41
 
42
- def test_eq():
42
+ def test_eq() -> None:
43
43
  eq = cirq.testing.EqualsTester()
44
44
  eq.add_equality_group(cirq.WaitGate(0), cirq.WaitGate(cirq.Duration()))
45
45
  eq.make_equality_group(lambda: cirq.WaitGate(cirq.Duration(nanos=4)))
46
46
 
47
47
 
48
- def test_protocols():
48
+ def test_protocols() -> None:
49
49
  t = sympy.Symbol('t')
50
50
  p = cirq.WaitGate(cirq.Duration(millis=5 * t))
51
51
  c = cirq.WaitGate(cirq.Duration(millis=2))
@@ -70,7 +70,7 @@ def test_protocols():
70
70
  assert cirq.decompose(p.on(q)) == []
71
71
 
72
72
 
73
- def test_qid_shape():
73
+ def test_qid_shape() -> None:
74
74
  assert cirq.qid_shape(cirq.WaitGate(0, qid_shape=(2, 3))) == (2, 3)
75
75
  assert cirq.qid_shape(cirq.WaitGate(0, num_qubits=3)) == (2, 2, 2)
76
76
  with pytest.raises(ValueError, match='empty set of qubits'):
@@ -87,7 +87,7 @@ def test_resolve_parameters(num_qubits: int) -> None:
87
87
  assert cirq.num_qubits(resolved) == num_qubits
88
88
 
89
89
 
90
- def test_json():
90
+ def test_json() -> None:
91
91
  q0, q1 = cirq.GridQubit.rect(1, 2)
92
92
  qtrit = cirq.GridQid(1, 2, dimension=3)
93
93
  cirq.testing.assert_json_roundtrip_works(cirq.wait(q0, nanos=10))
@@ -96,5 +96,5 @@ def test_json():
96
96
  cirq.testing.assert_json_roundtrip_works(cirq.wait(qtrit, q1, nanos=10))
97
97
 
98
98
 
99
- def test_str():
99
+ def test_str() -> None:
100
100
  assert str(cirq.WaitGate(cirq.Duration(nanos=5))) == 'WaitGate(5 ns)'