cirq-core 1.6.0.dev20250529190313__py3-none-any.whl → 1.6.0.dev20250530174306__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 (52) 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/circuit_diagram_info_protocol.py +1 -1
  41. cirq/protocols/qasm.py +2 -2
  42. cirq/qis/entropy_test.py +1 -1
  43. cirq/testing/consistent_protocols.py +1 -3
  44. cirq/testing/consistent_protocols_test.py +3 -3
  45. cirq/transformers/transformer_api.py +5 -5
  46. cirq/value/digits.py +5 -0
  47. cirq/value/duration.py +1 -1
  48. {cirq_core-1.6.0.dev20250529190313.dist-info → cirq_core-1.6.0.dev20250530174306.dist-info}/METADATA +1 -1
  49. {cirq_core-1.6.0.dev20250529190313.dist-info → cirq_core-1.6.0.dev20250530174306.dist-info}/RECORD +52 -52
  50. {cirq_core-1.6.0.dev20250529190313.dist-info → cirq_core-1.6.0.dev20250530174306.dist-info}/WHEEL +0 -0
  51. {cirq_core-1.6.0.dev20250529190313.dist-info → cirq_core-1.6.0.dev20250530174306.dist-info}/licenses/LICENSE +0 -0
  52. {cirq_core-1.6.0.dev20250529190313.dist-info → cirq_core-1.6.0.dev20250530174306.dist-info}/top_level.txt +0 -0
cirq/ops/identity_test.py CHANGED
@@ -26,7 +26,7 @@ import cirq
26
26
 
27
27
 
28
28
  @pytest.mark.parametrize('num_qubits', [1, 2, 4])
29
- def test_identity_init(num_qubits):
29
+ def test_identity_init(num_qubits) -> None:
30
30
  assert cirq.IdentityGate(num_qubits).num_qubits() == num_qubits
31
31
  assert cirq.qid_shape(cirq.IdentityGate(num_qubits)) == (2,) * num_qubits
32
32
  assert cirq.qid_shape(cirq.IdentityGate(3, (1, 2, 3))) == (1, 2, 3)
@@ -37,7 +37,7 @@ def test_identity_init(num_qubits):
37
37
  cirq.IdentityGate()
38
38
 
39
39
 
40
- def test_identity_on_each():
40
+ def test_identity_on_each() -> None:
41
41
  q0, q1, q2 = cirq.LineQubit.range(3)
42
42
  assert cirq.I.on_each(q0, q1, q2) == [cirq.I(q0), cirq.I(q1), cirq.I(q2)]
43
43
  assert cirq.I.on_each([q0, [q1], q2]) == [cirq.I(q0), cirq.I(q1), cirq.I(q2)]
@@ -46,7 +46,7 @@ def test_identity_on_each():
46
46
  cirq.I.on_each('abc')
47
47
 
48
48
 
49
- def test_identity_on_each_iter_second():
49
+ def test_identity_on_each_iter_second() -> None:
50
50
  class Q(cirq.Qid):
51
51
  @property
52
52
  def dimension(self) -> int:
@@ -63,7 +63,7 @@ def test_identity_on_each_iter_second():
63
63
  assert cirq.I.on_each(q) == [cirq.I(q)]
64
64
 
65
65
 
66
- def test_identity_on_each_only_single_qubit():
66
+ def test_identity_on_each_only_single_qubit() -> None:
67
67
  q0, q1 = cirq.LineQubit.range(2)
68
68
  q0_3, q1_3 = q0.with_dimension(3), q1.with_dimension(3)
69
69
  assert cirq.I.on_each(q0, q1) == [cirq.I.on(q0), cirq.I.on(q1)]
@@ -73,7 +73,7 @@ def test_identity_on_each_only_single_qubit():
73
73
  ]
74
74
 
75
75
 
76
- def test_identity_on_each_two_qubits():
76
+ def test_identity_on_each_two_qubits() -> None:
77
77
  q0, q1, q2, q3 = cirq.LineQubit.range(4)
78
78
  q0_3, q1_3 = q0.with_dimension(3), q1.with_dimension(3)
79
79
  assert cirq.IdentityGate(2).on_each([(q0, q1)]) == [cirq.IdentityGate(2)(q0, q1)]
@@ -96,14 +96,14 @@ def test_identity_on_each_two_qubits():
96
96
 
97
97
 
98
98
  @pytest.mark.parametrize('num_qubits', [1, 2, 4])
99
- def test_identity_unitary(num_qubits):
99
+ def test_identity_unitary(num_qubits) -> None:
100
100
  i = cirq.IdentityGate(num_qubits)
101
101
  assert np.allclose(cirq.unitary(i), np.identity(2**num_qubits))
102
102
  i3 = cirq.IdentityGate(num_qubits, (3,) * num_qubits)
103
103
  assert np.allclose(cirq.unitary(i3), np.identity(3**num_qubits))
104
104
 
105
105
 
106
- def test_identity_str():
106
+ def test_identity_str() -> None:
107
107
  assert str(cirq.IdentityGate(1)) == 'I'
108
108
  assert str(cirq.IdentityGate(2)) == 'I(2)'
109
109
  # Qid shape is not included in str
@@ -111,13 +111,13 @@ def test_identity_str():
111
111
  assert str(cirq.IdentityGate(2, (1, 2))) == 'I(2)'
112
112
 
113
113
 
114
- def test_identity_repr():
114
+ def test_identity_repr() -> None:
115
115
  assert repr(cirq.I) == 'cirq.I'
116
116
  assert repr(cirq.IdentityGate(5)) == 'cirq.IdentityGate(5)'
117
117
  assert repr(cirq.IdentityGate(qid_shape=(2, 3))) == 'cirq.IdentityGate(qid_shape=(2, 3))'
118
118
 
119
119
 
120
- def test_identity_apply_unitary():
120
+ def test_identity_apply_unitary() -> None:
121
121
  v = np.array([1, 0])
122
122
  result = cirq.apply_unitary(cirq.I, cirq.ApplyUnitaryArgs(v, np.array([0, 1]), (0,)))
123
123
  assert result is v
@@ -129,7 +129,7 @@ def test_identity_apply_unitary():
129
129
  assert result is v
130
130
 
131
131
 
132
- def test_identity_eq():
132
+ def test_identity_eq() -> None:
133
133
  equals_tester = cirq.testing.EqualsTester()
134
134
  equals_tester.make_equality_group(
135
135
  lambda: cirq.I, lambda: cirq.IdentityGate(1), lambda: cirq.IdentityGate(1, (2,))
@@ -140,12 +140,12 @@ def test_identity_eq():
140
140
  equals_tester.add_equality_group(cirq.IdentityGate(4, (1, 2, 3, 4)))
141
141
 
142
142
 
143
- def test_identity_trace_distance_bound():
143
+ def test_identity_trace_distance_bound() -> None:
144
144
  assert cirq.I._trace_distance_bound_() == 0
145
145
  assert cirq.IdentityGate(num_qubits=2)._trace_distance_bound_() == 0
146
146
 
147
147
 
148
- def test_identity_pow():
148
+ def test_identity_pow() -> None:
149
149
  I = cirq.I
150
150
  q = cirq.NamedQubit('q')
151
151
 
@@ -159,28 +159,29 @@ def test_identity_pow():
159
159
  _ = I(q) ** q
160
160
 
161
161
 
162
- def test_pauli_expansion_notimplemented():
162
+ def test_pauli_expansion_notimplemented() -> None:
163
163
  assert cirq.IdentityGate(1, (3,))._pauli_expansion_() == NotImplemented
164
164
 
165
165
 
166
166
  @pytest.mark.parametrize(
167
167
  'gate_type, num_qubits', itertools.product((cirq.IdentityGate,), range(1, 5))
168
168
  )
169
- def test_consistent_protocols(gate_type, num_qubits):
169
+ def test_consistent_protocols(gate_type, num_qubits) -> None:
170
170
  gate = gate_type(num_qubits=num_qubits)
171
171
  cirq.testing.assert_implements_consistent_protocols(gate, qubit_count=num_qubits)
172
172
 
173
173
 
174
- def test_identity_global():
174
+ def test_identity_global() -> None:
175
175
  qubits = cirq.LineQubit.range(3)
176
176
  assert cirq.identity_each(*qubits) == cirq.IdentityGate(3).on(*qubits)
177
177
  qids = cirq.LineQid.for_qid_shape((1, 2, 3))
178
178
  assert cirq.identity_each(*qids) == cirq.IdentityGate(3, (1, 2, 3)).on(*qids)
179
179
  with pytest.raises(ValueError, match='Not a cirq.Qid'):
180
- cirq.identity_each(qubits) # The user forgot to expand the list for example.
180
+ # The user forgot to expand the list for example.
181
+ cirq.identity_each(qubits) # type: ignore[arg-type]
181
182
 
182
183
 
183
- def test_identity_mul():
184
+ def test_identity_mul() -> None:
184
185
  class UnknownGate(cirq.testing.SingleQubitGate):
185
186
  pass
186
187
 
@@ -207,19 +208,19 @@ def test_identity_mul():
207
208
  assert 1j * i == cirq.PauliString(coefficient=1j)
208
209
 
209
210
 
210
- def test_identity_short_circuits_act_on():
211
+ def test_identity_short_circuits_act_on() -> None:
211
212
  args = mock.Mock(cirq.SimulationState)
212
213
  args._act_on_fallback_.side_effect = mock.Mock(side_effect=Exception('No!'))
213
214
  cirq.act_on(cirq.IdentityGate(1)(cirq.LineQubit(0)), args)
214
215
 
215
216
 
216
- def test_identity_commutes():
217
+ def test_identity_commutes() -> None:
217
218
  assert cirq.commutes(cirq.I, cirq.X)
218
219
  with pytest.raises(TypeError):
219
220
  cirq.commutes(cirq.I, "Gate")
220
221
 
221
222
 
222
- def test_identity_diagram():
223
+ def test_identity_diagram() -> None:
223
224
  cirq.testing.assert_has_diagram(
224
225
  cirq.Circuit(cirq.IdentityGate(3).on_each(cirq.LineQubit.range(3))),
225
226
  """
@@ -8,7 +8,7 @@ import pytest
8
8
  import cirq
9
9
 
10
10
 
11
- def test_kraus_channel_from_channel():
11
+ def test_kraus_channel_from_channel() -> None:
12
12
  q0 = cirq.LineQubit(0)
13
13
  dp = cirq.depolarize(0.1)
14
14
  kc = cirq.KrausChannel.from_channel(dp, key='dp')
@@ -24,7 +24,7 @@ def test_kraus_channel_from_channel():
24
24
  assert results.measurements['dp'] in range(4)
25
25
 
26
26
 
27
- def test_kraus_channel_equality():
27
+ def test_kraus_channel_equality() -> None:
28
28
  dp_pt1 = cirq.depolarize(0.1)
29
29
  dp_pt2 = cirq.depolarize(0.2)
30
30
  kc_a1 = cirq.KrausChannel.from_channel(dp_pt1, key='a')
@@ -47,7 +47,7 @@ def test_kraus_channel_equality():
47
47
  assert x_meas != x_meas_inv
48
48
 
49
49
 
50
- def test_kraus_channel_remap_keys():
50
+ def test_kraus_channel_remap_keys() -> None:
51
51
  dp = cirq.depolarize(0.1)
52
52
  kc = cirq.KrausChannel.from_channel(dp)
53
53
  with pytest.raises(TypeError):
@@ -65,7 +65,7 @@ def test_kraus_channel_remap_keys():
65
65
  assert cirq.with_measurement_key_mapping(kc_a, {'a': 'b'}) == kc_b
66
66
 
67
67
 
68
- def test_kraus_channel_from_kraus():
68
+ def test_kraus_channel_from_kraus() -> None:
69
69
  q0 = cirq.LineQubit(0)
70
70
  # This is equivalent to an X-basis measurement.
71
71
  ops = [np.array([[1, 1], [1, 1]]) * 0.5, np.array([[1, -1], [-1, 1]]) * 0.5]
@@ -80,7 +80,7 @@ def test_kraus_channel_from_kraus():
80
80
  assert results.measurements['x_meas'] == 0
81
81
 
82
82
 
83
- def test_kraus_channel_str():
83
+ def test_kraus_channel_str() -> None:
84
84
  # This is equivalent to an X-basis measurement.
85
85
  ops = [np.array([[1, 1], [1, 1]]) * 0.5, np.array([[1, -1], [-1, 1]]) * 0.5]
86
86
  x_meas = cirq.KrausChannel(ops)
@@ -99,7 +99,7 @@ def test_kraus_channel_str():
99
99
  )
100
100
 
101
101
 
102
- def test_kraus_channel_repr():
102
+ def test_kraus_channel_repr() -> None:
103
103
  # This is equivalent to an X-basis measurement.
104
104
  ops = [
105
105
  np.array([[1, 1], [1, 1]], dtype=np.complex64) * 0.5,
@@ -116,14 +116,14 @@ key='x_meas')"""
116
116
  )
117
117
 
118
118
 
119
- def test_empty_ops_fails():
120
- ops = []
119
+ def test_empty_ops_fails() -> None:
120
+ ops: list[np.ndarray] = []
121
121
 
122
122
  with pytest.raises(ValueError, match='must have at least one operation'):
123
123
  _ = cirq.KrausChannel(kraus_ops=ops, key='m')
124
124
 
125
125
 
126
- def test_ops_mismatch_fails():
126
+ def test_ops_mismatch_fails() -> None:
127
127
  op2 = np.zeros((4, 4))
128
128
  op2[1][1] = 1
129
129
  ops = [np.array([[1, 0], [0, 0]]), op2]
@@ -132,14 +132,14 @@ def test_ops_mismatch_fails():
132
132
  _ = cirq.KrausChannel(kraus_ops=ops, key='m')
133
133
 
134
134
 
135
- def test_nonqubit_kraus_ops_fails():
135
+ def test_nonqubit_kraus_ops_fails() -> None:
136
136
  ops = [np.array([[1, 0, 0], [0, 0, 0]]), np.array([[0, 0, 0], [0, 1, 0]])]
137
137
 
138
138
  with pytest.raises(ValueError, match='Input Kraus ops'):
139
139
  _ = cirq.KrausChannel(kraus_ops=ops, key='m')
140
140
 
141
141
 
142
- def test_validate():
142
+ def test_validate() -> None:
143
143
  # Not quite CPTP.
144
144
  ops = [np.array([[1, 0], [0, 0]]), np.array([[0, 0], [0, 0.9]])]
145
145
  with pytest.raises(ValueError, match='CPTP map'):
@@ -19,16 +19,16 @@ from cirq.devices.grid_qubit_test import _test_qid_pickled_hash
19
19
  from cirq.ops.named_qubit import _pad_digits
20
20
 
21
21
 
22
- def test_init():
22
+ def test_init() -> None:
23
23
  q = cirq.NamedQubit('a')
24
24
  assert q.name == 'a'
25
25
 
26
- q = cirq.NamedQid('a', dimension=3)
27
- assert q.name == 'a'
28
- assert q.dimension == 3
26
+ qid = cirq.NamedQid('a', dimension=3)
27
+ assert qid.name == 'a'
28
+ assert qid.dimension == 3
29
29
 
30
30
 
31
- def test_named_qubit_str():
31
+ def test_named_qubit_str() -> None:
32
32
  q = cirq.NamedQubit('a')
33
33
  assert q.name == 'a'
34
34
  assert str(q) == 'a'
@@ -37,14 +37,14 @@ def test_named_qubit_str():
37
37
  assert str(qid) == 'a (d=3)'
38
38
 
39
39
 
40
- def test_named_qubit_repr():
40
+ def test_named_qubit_repr() -> None:
41
41
  q = cirq.NamedQubit('a')
42
42
  assert repr(q) == "cirq.NamedQubit('a')"
43
43
  qid = cirq.NamedQid('a', dimension=3)
44
44
  assert repr(qid) == "cirq.NamedQid('a', dimension=3)"
45
45
 
46
46
 
47
- def test_named_qubit_pickled_hash():
47
+ def test_named_qubit_pickled_hash() -> None:
48
48
  # Use a name that is unlikely to be used by any other tests.
49
49
  x = "test_named_qubit_pickled_hash"
50
50
  q_bad = cirq.NamedQubit(x)
@@ -53,7 +53,7 @@ def test_named_qubit_pickled_hash():
53
53
  _test_qid_pickled_hash(q, q_bad)
54
54
 
55
55
 
56
- def test_named_qid_pickled_hash():
56
+ def test_named_qid_pickled_hash() -> None:
57
57
  # Use a name that is unlikely to be used by any other tests.
58
58
  x = "test_named_qid_pickled_hash"
59
59
  q_bad = cirq.NamedQid(x, dimension=3)
@@ -62,7 +62,7 @@ def test_named_qid_pickled_hash():
62
62
  _test_qid_pickled_hash(q, q_bad)
63
63
 
64
64
 
65
- def test_named_qubit_order():
65
+ def test_named_qubit_order() -> None:
66
66
  order = cirq.testing.OrderTester()
67
67
  order.add_ascending(
68
68
  cirq.NamedQid('', dimension=1),
@@ -110,7 +110,7 @@ def test_named_qubit_order():
110
110
  )
111
111
 
112
112
 
113
- def test_pad_digits():
113
+ def test_pad_digits() -> None:
114
114
  assert _pad_digits('') == ''
115
115
  assert _pad_digits('a') == 'a'
116
116
  assert _pad_digits('a0') == 'a00000000:1'
@@ -121,7 +121,7 @@ def test_pad_digits():
121
121
  assert _pad_digits('a00000000:8') == 'a00000000:8:00000008:1'
122
122
 
123
123
 
124
- def test_named_qubit_range():
124
+ def test_named_qubit_range() -> None:
125
125
  qubits = cirq.NamedQubit.range(2, prefix='a')
126
126
  assert qubits == [cirq.NamedQubit('a0'), cirq.NamedQubit('a1')]
127
127
 
@@ -129,7 +129,7 @@ def test_named_qubit_range():
129
129
  assert qubits == [cirq.NamedQubit('a-1'), cirq.NamedQubit('a1'), cirq.NamedQubit('a3')]
130
130
 
131
131
 
132
- def test_named_qid_range():
132
+ def test_named_qid_range() -> None:
133
133
  qids = cirq.NamedQid.range(2, prefix='a', dimension=3)
134
134
  assert qids == [cirq.NamedQid('a0', dimension=3), cirq.NamedQid('a1', dimension=3)]
135
135
 
@@ -151,7 +151,7 @@ def test_named_qid_range():
151
151
  ]
152
152
 
153
153
 
154
- def test_to_json():
154
+ def test_to_json() -> None:
155
155
  assert cirq.NamedQubit('c')._json_dict_() == {'name': 'c'}
156
156
 
157
157
  assert cirq.NamedQid('c', dimension=3)._json_dict_() == {'name': 'c', 'dimension': 3}
cirq/ops/op_tree_test.py CHANGED
@@ -21,7 +21,7 @@ import pytest
21
21
  import cirq
22
22
 
23
23
 
24
- def test_flatten_op_tree():
24
+ def test_flatten_op_tree() -> None:
25
25
  operations = [
26
26
  cirq.GateOperation(cirq.testing.SingleQubitGate(), [cirq.NamedQubit(str(i))])
27
27
  for i in range(10)
@@ -49,33 +49,33 @@ def test_flatten_op_tree():
49
49
 
50
50
  # Bad trees.
51
51
  with pytest.raises(TypeError):
52
- _ = list(cirq.flatten_op_tree(None))
52
+ _ = list(cirq.flatten_op_tree(None)) # type: ignore[arg-type]
53
53
  with pytest.raises(TypeError):
54
- _ = list(cirq.flatten_op_tree(5))
54
+ _ = list(cirq.flatten_op_tree(5)) # type: ignore[arg-type]
55
55
  with pytest.raises(TypeError):
56
- _ = list(cirq.flatten_op_tree([operations[0], (4,)]))
56
+ _ = list(cirq.flatten_op_tree([operations[0], (4,)])) # type: ignore[list-item]
57
57
 
58
58
 
59
- def test_flatten_to_ops_or_moments():
59
+ def test_flatten_to_ops_or_moments() -> None:
60
60
  operations = [
61
61
  cirq.GateOperation(cirq.testing.SingleQubitGate(), [cirq.NamedQubit(str(i))])
62
62
  for i in range(10)
63
63
  ]
64
- op_tree = [operations[0], cirq.Moment(operations[1:5]), operations[5:]]
64
+ op_tree: cirq.OP_TREE = [operations[0], cirq.Moment(operations[1:5]), operations[5:]]
65
65
  output = [operations[0], cirq.Moment(operations[1:5])] + operations[5:]
66
66
  assert list(cirq.flatten_to_ops_or_moments(op_tree)) == output
67
67
  assert list(cirq.flatten_op_tree(op_tree, preserve_moments=True)) == output
68
68
 
69
69
  # Bad trees.
70
70
  with pytest.raises(TypeError):
71
- _ = list(cirq.flatten_to_ops_or_moments(None))
71
+ _ = list(cirq.flatten_to_ops_or_moments(None)) # type: ignore[arg-type]
72
72
  with pytest.raises(TypeError):
73
- _ = list(cirq.flatten_to_ops_or_moments(5))
73
+ _ = list(cirq.flatten_to_ops_or_moments(5)) # type: ignore[arg-type]
74
74
  with pytest.raises(TypeError):
75
- _ = list(cirq.flatten_to_ops_or_moments([operations[0], (4,)]))
75
+ _ = list(cirq.flatten_to_ops_or_moments([operations[0], (4,)])) # type: ignore[list-item]
76
76
 
77
77
 
78
- def test_freeze_op_tree():
78
+ def test_freeze_op_tree() -> None:
79
79
  operations = [
80
80
  cirq.GateOperation(cirq.testing.SingleQubitGate(), [cirq.NamedQubit(str(i))])
81
81
  for i in range(10)
@@ -97,29 +97,29 @@ def test_freeze_op_tree():
97
97
 
98
98
  # Bad trees.
99
99
  with pytest.raises(TypeError):
100
- cirq.freeze_op_tree(None)
100
+ cirq.freeze_op_tree(None) # type: ignore[arg-type]
101
101
  with pytest.raises(TypeError):
102
- cirq.freeze_op_tree(5)
102
+ cirq.freeze_op_tree(5) # type: ignore[arg-type]
103
103
  with pytest.raises(TypeError):
104
- _ = cirq.freeze_op_tree([operations[0], (4,)])
104
+ _ = cirq.freeze_op_tree([operations[0], (4,)]) # type: ignore[list-item]
105
105
 
106
106
 
107
- def test_transform_bad_tree():
107
+ def test_transform_bad_tree() -> None:
108
108
  with pytest.raises(TypeError):
109
- _ = list(cirq.transform_op_tree(None))
109
+ _ = list(cirq.transform_op_tree(None)) # type: ignore[arg-type]
110
110
  with pytest.raises(TypeError):
111
- _ = list(cirq.transform_op_tree(5))
111
+ _ = list(cirq.transform_op_tree(5)) # type: ignore[arg-type]
112
112
  with pytest.raises(TypeError):
113
113
  _ = list(
114
114
  cirq.flatten_op_tree(
115
115
  cirq.transform_op_tree(
116
- [cirq.GateOperation(cirq.Gate(), [cirq.NamedQubit('q')]), (4,)]
116
+ [cirq.GateOperation(cirq.Gate(), [cirq.NamedQubit('q')]), (4,)] # type: ignore
117
117
  )
118
118
  )
119
119
  )
120
120
 
121
121
 
122
- def test_transform_leaves():
122
+ def test_transform_leaves() -> None:
123
123
  gs = [cirq.testing.SingleQubitGate() for _ in range(10)]
124
124
  operations = [cirq.GateOperation(gs[i], [cirq.NamedQubit(str(i))]) for i in range(10)]
125
125
  expected = [cirq.GateOperation(gs[i], [cirq.NamedQubit(str(i) + 'a')]) for i in range(10)]
@@ -153,7 +153,7 @@ def test_transform_leaves():
153
153
  )
154
154
 
155
155
 
156
- def test_transform_internal_nodes():
156
+ def test_transform_internal_nodes() -> None:
157
157
  operations = [
158
158
  cirq.GateOperation(cirq.testing.SingleQubitGate(), [cirq.LineQubit(2 * i)])
159
159
  for i in range(10)
@@ -26,7 +26,7 @@ import cirq
26
26
  @pytest.mark.parametrize(
27
27
  'phase_exponent', [-0.5, 0, 0.5, 1, sympy.Symbol('p'), sympy.Symbol('p') + 1]
28
28
  )
29
- def test_phased_x_consistent_protocols(phase_exponent):
29
+ def test_phased_x_consistent_protocols(phase_exponent) -> None:
30
30
  cirq.testing.assert_implements_consistent_protocols(
31
31
  cirq.PhasedXPowGate(phase_exponent=phase_exponent, exponent=1.0)
32
32
  )
@@ -35,7 +35,7 @@ def test_phased_x_consistent_protocols(phase_exponent):
35
35
  )
36
36
 
37
37
 
38
- def test_init():
38
+ def test_init() -> None:
39
39
  g = cirq.PhasedXPowGate(phase_exponent=0.75, exponent=0.25, global_shift=0.1)
40
40
  assert g.phase_exponent == 0.75
41
41
  assert g.exponent == 0.25
@@ -53,13 +53,13 @@ def test_init():
53
53
 
54
54
 
55
55
  @pytest.mark.parametrize('sym', [sympy.Symbol('a'), sympy.Symbol('a') + 1])
56
- def test_no_symbolic_qasm_but_fails_gracefully(sym):
56
+ def test_no_symbolic_qasm_but_fails_gracefully(sym) -> None:
57
57
  q = cirq.NamedQubit('q')
58
58
  v = cirq.PhasedXPowGate(phase_exponent=sym).on(q)
59
59
  assert cirq.qasm(v, args=cirq.QasmArgs(), default=None) is None
60
60
 
61
61
 
62
- def test_extrapolate():
62
+ def test_extrapolate() -> None:
63
63
  g = cirq.PhasedXPowGate(phase_exponent=0.25)
64
64
  assert g**0.25 == (g**0.5) ** 0.5
65
65
 
@@ -73,7 +73,7 @@ def test_extrapolate():
73
73
  assert g**0.5 != (g**3) ** 0.5 == g**-0.5
74
74
 
75
75
 
76
- def test_eq():
76
+ def test_eq() -> None:
77
77
  eq = cirq.testing.EqualsTester()
78
78
  eq.add_equality_group(
79
79
  cirq.PhasedXPowGate(phase_exponent=0),
@@ -124,7 +124,7 @@ def test_eq():
124
124
  )
125
125
 
126
126
 
127
- def test_approx_eq():
127
+ def test_approx_eq() -> None:
128
128
  assert cirq.approx_eq(
129
129
  cirq.PhasedXPowGate(phase_exponent=0.1, exponent=0.2, global_shift=0.3),
130
130
  cirq.PhasedXPowGate(phase_exponent=0.1, exponent=0.2, global_shift=0.3),
@@ -142,7 +142,7 @@ def test_approx_eq():
142
142
  )
143
143
 
144
144
 
145
- def test_str_repr():
145
+ def test_str_repr() -> None:
146
146
  assert str(cirq.PhasedXPowGate(phase_exponent=0.25)) == 'PhX(0.25)'
147
147
  assert str(cirq.PhasedXPowGate(phase_exponent=0.25, exponent=0.5)) == 'PhX(0.25)**0.5'
148
148
  assert repr(
@@ -158,7 +158,7 @@ def test_str_repr():
158
158
  @pytest.mark.parametrize(
159
159
  'resolve_fn, global_shift', [(cirq.resolve_parameters, 0), (cirq.resolve_parameters_once, 0.1)]
160
160
  )
161
- def test_parameterize(resolve_fn, global_shift):
161
+ def test_parameterize(resolve_fn, global_shift) -> None:
162
162
  parameterized_gate = cirq.PhasedXPowGate(
163
163
  exponent=sympy.Symbol('a'), phase_exponent=sympy.Symbol('b'), global_shift=global_shift
164
164
  )
@@ -189,24 +189,24 @@ def test_parameterize(resolve_fn, global_shift):
189
189
  assert cirq.is_parameterized(unparameterized_gate ** sympy.Symbol('a'))
190
190
  assert cirq.is_parameterized(unparameterized_gate ** (sympy.Symbol('a') + 1))
191
191
 
192
- resolver = {'a': 0.5j}
192
+ resolver_dict = {'a': 0.5j}
193
193
  with pytest.raises(ValueError, match='complex value'):
194
194
  resolve_fn(
195
195
  cirq.PhasedXPowGate(
196
196
  exponent=sympy.Symbol('a'), phase_exponent=0.2, global_shift=global_shift
197
197
  ),
198
- resolver,
198
+ resolver_dict,
199
199
  )
200
200
  with pytest.raises(ValueError, match='complex value'):
201
201
  resolve_fn(
202
202
  cirq.PhasedXPowGate(
203
203
  exponent=0.1, phase_exponent=sympy.Symbol('a'), global_shift=global_shift
204
204
  ),
205
- resolver,
205
+ resolver_dict,
206
206
  )
207
207
 
208
208
 
209
- def test_trace_bound():
209
+ def test_trace_bound() -> None:
210
210
  assert (
211
211
  cirq.trace_distance_bound(cirq.PhasedXPowGate(phase_exponent=0.25, exponent=0.001)) < 0.01
212
212
  )
@@ -218,7 +218,7 @@ def test_trace_bound():
218
218
  )
219
219
 
220
220
 
221
- def test_diagram():
221
+ def test_diagram() -> None:
222
222
  q = cirq.NamedQubit('q')
223
223
  c = cirq.Circuit(
224
224
  cirq.PhasedXPowGate(phase_exponent=sympy.Symbol('a'), exponent=sympy.Symbol('b')).on(q),
@@ -236,7 +236,7 @@ q: ───PhX(a)^b───PhX(2*a)^(b + 1)───PhX(0.25)───PhX(1)
236
236
  )
237
237
 
238
238
 
239
- def test_phase_by():
239
+ def test_phase_by() -> None:
240
240
  g = cirq.PhasedXPowGate(phase_exponent=0.25)
241
241
  g2 = cirq.phase_by(g, 0.25, 0)
242
242
  assert g2 == cirq.PhasedXPowGate(phase_exponent=0.75)
@@ -257,7 +257,7 @@ def test_phase_by():
257
257
  @pytest.mark.parametrize(
258
258
  'exponent,phase_exponent', itertools.product(np.arange(-2.5, 2.75, 0.25), repeat=2)
259
259
  )
260
- def test_exponent_consistency(exponent, phase_exponent):
260
+ def test_exponent_consistency(exponent, phase_exponent) -> None:
261
261
  """Verifies that instances of PhasedX gate expose consistent exponents."""
262
262
  g = cirq.PhasedXPowGate(exponent=exponent, phase_exponent=phase_exponent)
263
263
  assert g.exponent in [exponent, -exponent]
@@ -271,7 +271,7 @@ def test_exponent_consistency(exponent, phase_exponent):
271
271
  assert np.all(u == u2)
272
272
 
273
273
 
274
- def test_approx_eq_for_close_phase_exponents():
274
+ def test_approx_eq_for_close_phase_exponents() -> None:
275
275
  gate1 = cirq.PhasedXPowGate(phase_exponent=0)
276
276
  gate2 = cirq.PhasedXPowGate(phase_exponent=1e-12)
277
277
  gate3 = cirq.PhasedXPowGate(phase_exponent=2e-12)
@@ -3,6 +3,7 @@
3
3
  from __future__ import annotations
4
4
 
5
5
  import random
6
+ from typing import cast
6
7
 
7
8
  import numpy as np
8
9
  import pytest
@@ -11,14 +12,14 @@ import sympy
11
12
  import cirq
12
13
 
13
14
 
14
- def test_init_properties():
15
+ def test_init_properties() -> None:
15
16
  g = cirq.PhasedXZGate(x_exponent=0.125, z_exponent=0.25, axis_phase_exponent=0.375)
16
17
  assert g.x_exponent == 0.125
17
18
  assert g.z_exponent == 0.25
18
19
  assert g.axis_phase_exponent == 0.375
19
20
 
20
21
 
21
- def test_eq():
22
+ def test_eq() -> None:
22
23
  eq = cirq.testing.EqualsTester()
23
24
  eq.make_equality_group(
24
25
  lambda: cirq.PhasedXZGate(x_exponent=0.25, z_exponent=0.5, axis_phase_exponent=0.75)
@@ -61,7 +62,7 @@ def test_from_zyz_exponents(z0: float, y: float, z1: float) -> None:
61
62
  )
62
63
 
63
64
 
64
- def test_canonicalization():
65
+ def test_canonicalization() -> None:
65
66
  def f(x, z, a):
66
67
  return cirq.PhasedXZGate(x_exponent=x, z_exponent=z, axis_phase_exponent=a)
67
68
 
@@ -148,7 +149,7 @@ def test_canonicalization():
148
149
  assert t.axis_phase_exponent == 0
149
150
 
150
151
 
151
- def test_from_matrix():
152
+ def test_from_matrix() -> None:
152
153
  # Axis rotations.
153
154
  assert cirq.approx_eq(
154
155
  cirq.PhasedXZGate.from_matrix(cirq.unitary(cirq.X**0.1)),
@@ -220,7 +221,7 @@ def test_from_matrix():
220
221
  np.array([[0, 1], [1j, 0]]),
221
222
  ],
222
223
  )
223
- def test_from_matrix_close_unitary(unitary: np.ndarray):
224
+ def test_from_matrix_close_unitary(unitary: np.ndarray) -> None:
224
225
  cirq.testing.assert_allclose_up_to_global_phase(
225
226
  cirq.unitary(cirq.PhasedXZGate.from_matrix(unitary)), unitary, atol=1e-8
226
227
  )
@@ -235,14 +236,14 @@ def test_from_matrix_close_unitary(unitary: np.ndarray):
235
236
  np.array([[0, 1], [1j, 0]]),
236
237
  ],
237
238
  )
238
- def test_from_matrix_close_kraus(unitary: np.ndarray):
239
+ def test_from_matrix_close_kraus(unitary: np.ndarray) -> None:
239
240
  gate = cirq.PhasedXZGate.from_matrix(unitary)
240
241
  kraus = cirq.kraus(gate)
241
242
  assert len(kraus) == 1
242
243
  cirq.testing.assert_allclose_up_to_global_phase(kraus[0], unitary, atol=1e-8)
243
244
 
244
245
 
245
- def test_protocols():
246
+ def test_protocols() -> None:
246
247
  a = random.random()
247
248
  b = random.random()
248
249
  c = random.random()
@@ -259,7 +260,7 @@ def test_protocols():
259
260
  cirq.testing.assert_implements_consistent_protocols(g)
260
261
 
261
262
 
262
- def test_inverse():
263
+ def test_inverse() -> None:
263
264
  a = random.random()
264
265
  b = random.random()
265
266
  c = random.random()
@@ -267,12 +268,14 @@ def test_inverse():
267
268
  g = cirq.PhasedXZGate(x_exponent=a, z_exponent=b, axis_phase_exponent=c).on(q)
268
269
 
269
270
  cirq.testing.assert_allclose_up_to_global_phase(
270
- cirq.unitary(g**-1), np.transpose(np.conjugate(cirq.unitary(g))), atol=1e-8
271
+ cirq.unitary(cast(cirq.GateOperation, g) ** -1),
272
+ np.transpose(np.conjugate(cirq.unitary(g))),
273
+ atol=1e-8,
271
274
  )
272
275
 
273
276
 
274
277
  @pytest.mark.parametrize('resolve_fn', [cirq.resolve_parameters, cirq.resolve_parameters_once])
275
- def test_parameterized(resolve_fn):
278
+ def test_parameterized(resolve_fn) -> None:
276
279
  a = random.random()
277
280
  b = random.random()
278
281
  c = random.random()
@@ -299,7 +302,7 @@ def test_parameterized(resolve_fn):
299
302
  resolve_fn(cirq.PhasedXZGate(x_exponent=a, z_exponent=b, axis_phase_exponent=t), resolver)
300
303
 
301
304
 
302
- def test_str_diagram():
305
+ def test_str_diagram() -> None:
303
306
  g = cirq.PhasedXZGate(x_exponent=0.5, z_exponent=0.25, axis_phase_exponent=0.125)
304
307
 
305
308
  assert str(g) == "PhXZ(a=0.125,x=0.5,z=0.25)"