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
cirq/_version.py CHANGED
@@ -28,4 +28,4 @@ if sys.version_info < (3, 11, 0): # pragma: no cover
28
28
  'of cirq (e.g. "python -m pip install cirq==1.5.0")'
29
29
  )
30
30
 
31
- __version__ = "1.6.0.dev20250529194600"
31
+ __version__ = "1.6.0.dev20250530203656"
cirq/_version_test.py CHANGED
@@ -3,4 +3,4 @@ import cirq
3
3
 
4
4
 
5
5
  def test_version() -> None:
6
- assert cirq.__version__ == "1.6.0.dev20250529194600"
6
+ assert cirq.__version__ == "1.6.0.dev20250530203656"
@@ -20,8 +20,8 @@ import cirq
20
20
  from cirq.circuits._bucket_priority_queue import BucketPriorityQueue
21
21
 
22
22
 
23
- def test_init():
24
- q = BucketPriorityQueue()
23
+ def test_init() -> None:
24
+ q: BucketPriorityQueue = BucketPriorityQueue()
25
25
  assert not q.drop_duplicate_entries
26
26
  assert list(q) == []
27
27
  assert len(q) == 0
@@ -42,7 +42,7 @@ def test_init():
42
42
  assert bool(q)
43
43
 
44
44
 
45
- def test_eq():
45
+ def test_eq() -> None:
46
46
  eq = cirq.testing.EqualsTester()
47
47
  eq.add_equality_group(
48
48
  BucketPriorityQueue(),
@@ -71,8 +71,8 @@ def test_eq():
71
71
  )
72
72
 
73
73
 
74
- def test_enqueue_dequeue():
75
- q = BucketPriorityQueue()
74
+ def test_enqueue_dequeue() -> None:
75
+ q: BucketPriorityQueue = BucketPriorityQueue()
76
76
  q.enqueue(5, 'a')
77
77
  assert q == BucketPriorityQueue([(5, 'a')])
78
78
  q.enqueue(4, 'b')
@@ -85,10 +85,10 @@ def test_enqueue_dequeue():
85
85
  _ = q.dequeue()
86
86
 
87
87
 
88
- def test_drop_duplicates_enqueue():
89
- q0 = BucketPriorityQueue()
90
- q1 = BucketPriorityQueue(drop_duplicate_entries=False)
91
- q2 = BucketPriorityQueue(drop_duplicate_entries=True)
88
+ def test_drop_duplicates_enqueue() -> None:
89
+ q0: BucketPriorityQueue = BucketPriorityQueue()
90
+ q1: BucketPriorityQueue = BucketPriorityQueue(drop_duplicate_entries=False)
91
+ q2: BucketPriorityQueue = BucketPriorityQueue(drop_duplicate_entries=True)
92
92
  for q in [q0, q1, q2]:
93
93
  for _ in range(2):
94
94
  q.enqueue(0, 'a')
@@ -97,10 +97,10 @@ def test_drop_duplicates_enqueue():
97
97
  assert q2 == BucketPriorityQueue([(0, 'a')], drop_duplicate_entries=True)
98
98
 
99
99
 
100
- def test_drop_duplicates_dequeue():
101
- q0 = BucketPriorityQueue()
102
- q1 = BucketPriorityQueue(drop_duplicate_entries=False)
103
- q2 = BucketPriorityQueue(drop_duplicate_entries=True)
100
+ def test_drop_duplicates_dequeue() -> None:
101
+ q0: BucketPriorityQueue = BucketPriorityQueue()
102
+ q1: BucketPriorityQueue = BucketPriorityQueue(drop_duplicate_entries=False)
103
+ q2: BucketPriorityQueue = BucketPriorityQueue(drop_duplicate_entries=True)
104
104
  for q in [q0, q1, q2]:
105
105
  q.enqueue(0, 'a')
106
106
  q.enqueue(0, 'b')
@@ -113,11 +113,11 @@ def test_drop_duplicates_dequeue():
113
113
  assert q2 == BucketPriorityQueue([(0, 'b'), (0, 'a')], drop_duplicate_entries=True)
114
114
 
115
115
 
116
- def test_same_priority_fifo():
116
+ def test_same_priority_fifo() -> None:
117
117
  a = (5, 'a')
118
118
  b = (5, 'b')
119
119
  for x, y in [(a, b), (b, a)]:
120
- q = BucketPriorityQueue()
120
+ q: BucketPriorityQueue = BucketPriorityQueue()
121
121
  q.enqueue(*x)
122
122
  q.enqueue(*y)
123
123
  assert q
@@ -127,23 +127,23 @@ def test_same_priority_fifo():
127
127
  assert not q
128
128
 
129
129
 
130
- def test_supports_arbitrary_offsets():
130
+ def test_supports_arbitrary_offsets() -> None:
131
131
  m = 1 << 60
132
132
 
133
- q_neg = BucketPriorityQueue()
133
+ q_neg: BucketPriorityQueue = BucketPriorityQueue()
134
134
  q_neg.enqueue(-m + 0, 'b')
135
135
  q_neg.enqueue(-m - 4, 'a')
136
136
  q_neg.enqueue(-m + 4, 'c')
137
137
  assert list(q_neg) == [(-m - 4, 'a'), (-m, 'b'), (-m + 4, 'c')]
138
138
 
139
- q_pos = BucketPriorityQueue()
139
+ q_pos: BucketPriorityQueue = BucketPriorityQueue()
140
140
  q_pos.enqueue(m + 0, 'b')
141
141
  q_pos.enqueue(m + 4, 'c')
142
142
  q_pos.enqueue(m - 4, 'a')
143
143
  assert list(q_pos) == [(m - 4, 'a'), (m, 'b'), (m + 4, 'c')]
144
144
 
145
145
 
146
- def test_repr():
146
+ def test_repr() -> None:
147
147
  r = repr(BucketPriorityQueue(entries=[(1, 2), (3, 4)], drop_duplicate_entries=True))
148
148
  assert r.endswith('BucketPriorityQueue(entries=[(1, 2), (3, 4)], drop_duplicate_entries=True)')
149
149
 
@@ -154,7 +154,7 @@ def test_repr():
154
154
  )
155
155
 
156
156
 
157
- def test_str():
157
+ def test_str() -> None:
158
158
  s = str(BucketPriorityQueue(entries=[(1, 2), (3, 4)], drop_duplicate_entries=True))
159
159
  assert (
160
160
  s
@@ -28,7 +28,7 @@ from cirq.circuits.circuit_operation import _full_join_string_lists
28
28
  ALL_SIMULATORS = (cirq.Simulator(), cirq.DensityMatrixSimulator(), cirq.CliffordSimulator())
29
29
 
30
30
 
31
- def test_properties():
31
+ def test_properties() -> None:
32
32
  a, b, c = cirq.LineQubit.range(3)
33
33
  circuit = cirq.FrozenCircuit(
34
34
  cirq.X(a),
@@ -50,7 +50,7 @@ def test_properties():
50
50
  assert op == circuit.to_op()
51
51
 
52
52
 
53
- def test_circuit_type():
53
+ def test_circuit_type() -> None:
54
54
  a, b, c = cirq.LineQubit.range(3)
55
55
  circuit = cirq.Circuit(
56
56
  cirq.X(a),
@@ -60,10 +60,10 @@ def test_circuit_type():
60
60
  cirq.measure(a, b, c, key='m'),
61
61
  )
62
62
  with pytest.raises(TypeError, match='Expected circuit of type FrozenCircuit'):
63
- _ = cirq.CircuitOperation(circuit)
63
+ _ = cirq.CircuitOperation(circuit) # type: ignore[arg-type]
64
64
 
65
65
 
66
- def test_non_invertible_circuit():
66
+ def test_non_invertible_circuit() -> None:
67
67
  a, b, c = cirq.LineQubit.range(3)
68
68
  circuit = cirq.FrozenCircuit(
69
69
  cirq.X(a),
@@ -76,7 +76,7 @@ def test_non_invertible_circuit():
76
76
  _ = cirq.CircuitOperation(circuit, repetitions=-2)
77
77
 
78
78
 
79
- def test_repetitions_and_ids_length_mismatch():
79
+ def test_repetitions_and_ids_length_mismatch() -> None:
80
80
  a, b, c = cirq.LineQubit.range(3)
81
81
  circuit = cirq.FrozenCircuit(
82
82
  cirq.X(a),
@@ -89,7 +89,7 @@ def test_repetitions_and_ids_length_mismatch():
89
89
  _ = cirq.CircuitOperation(circuit, repetitions=2, repetition_ids=['a', 'b', 'c'])
90
90
 
91
91
 
92
- def test_is_measurement_memoization():
92
+ def test_is_measurement_memoization() -> None:
93
93
  a = cirq.LineQubit(0)
94
94
  circuit = cirq.FrozenCircuit(cirq.measure(a, key='m'))
95
95
  c_op = cirq.CircuitOperation(circuit)
@@ -100,7 +100,7 @@ def test_is_measurement_memoization():
100
100
  assert hasattr(circuit, cache_name)
101
101
 
102
102
 
103
- def test_invalid_measurement_keys():
103
+ def test_invalid_measurement_keys() -> None:
104
104
  a = cirq.LineQubit(0)
105
105
  circuit = cirq.FrozenCircuit(cirq.measure(a, key='m'))
106
106
  c_op = cirq.CircuitOperation(circuit)
@@ -120,7 +120,7 @@ def test_invalid_measurement_keys():
120
120
  _ = cirq.CircuitOperation(circuit, measurement_key_map={'m:a': 'ma'})
121
121
 
122
122
 
123
- def test_invalid_qubit_mapping():
123
+ def test_invalid_qubit_mapping() -> None:
124
124
  q = cirq.LineQubit(0)
125
125
  q3 = cirq.LineQid(1, dimension=3)
126
126
 
@@ -138,7 +138,7 @@ def test_invalid_qubit_mapping():
138
138
  _ = c_op.with_qubit_mapping(lambda q: q3)
139
139
 
140
140
 
141
- def test_circuit_sharing():
141
+ def test_circuit_sharing() -> None:
142
142
  a, b, c = cirq.LineQubit.range(3)
143
143
  circuit = cirq.FrozenCircuit(
144
144
  cirq.X(a),
@@ -158,7 +158,7 @@ def test_circuit_sharing():
158
158
  assert hash(op1) == hash(op3)
159
159
 
160
160
 
161
- def test_with_qubits():
161
+ def test_with_qubits() -> None:
162
162
  a, b, c, d = cirq.LineQubit.range(4)
163
163
  circuit = cirq.FrozenCircuit(cirq.H(a), cirq.CX(a, b))
164
164
  op_base = cirq.CircuitOperation(circuit)
@@ -195,10 +195,10 @@ def test_with_qubits():
195
195
  _ = op_base.with_qubit_mapping(lambda q: b)
196
196
  # with_qubit_mapping requires exactly one argument.
197
197
  with pytest.raises(TypeError, match='must be a function or dict'):
198
- _ = op_base.with_qubit_mapping('bad arg')
198
+ _ = op_base.with_qubit_mapping('bad arg') # type: ignore[arg-type]
199
199
 
200
200
 
201
- def test_with_measurement_keys():
201
+ def test_with_measurement_keys() -> None:
202
202
  a, b = cirq.LineQubit.range(2)
203
203
  circuit = cirq.FrozenCircuit(cirq.X(a), cirq.measure(b, key='mb'), cirq.measure(a, key='ma'))
204
204
  op_base = cirq.CircuitOperation(circuit)
@@ -215,7 +215,7 @@ def test_with_measurement_keys():
215
215
  _ = op_base.with_measurement_key_mapping({'ma': 'mb'})
216
216
 
217
217
 
218
- def test_with_params():
218
+ def test_with_params() -> None:
219
219
  a = cirq.LineQubit(0)
220
220
  z_exp = sympy.Symbol('z_exp')
221
221
  x_exp = sympy.Symbol('x_exp')
@@ -242,7 +242,7 @@ def test_with_params():
242
242
  )
243
243
 
244
244
 
245
- def test_recursive_params():
245
+ def test_recursive_params() -> None:
246
246
  q = cirq.LineQubit(0)
247
247
  a, a2, b, b2 = sympy.symbols('a a2 b b2')
248
248
  circuitop = cirq.CircuitOperation(
@@ -359,7 +359,7 @@ def test_replace_repetition_ids() -> None:
359
359
  @pytest.mark.parametrize('add_measurements', [True, False])
360
360
  @pytest.mark.parametrize('use_repetition_ids', [True, False])
361
361
  @pytest.mark.parametrize('initial_reps', [0, 1, 2, 3])
362
- def test_repeat_zero_times(add_measurements, use_repetition_ids, initial_reps):
362
+ def test_repeat_zero_times(add_measurements, use_repetition_ids, initial_reps) -> None:
363
363
  q = cirq.LineQubit(0)
364
364
  subcircuit = cirq.Circuit(cirq.X(q))
365
365
  if add_measurements:
@@ -374,7 +374,7 @@ def test_repeat_zero_times(add_measurements, use_repetition_ids, initial_reps):
374
374
  assert np.allclose(result.state_vector(), [1, 0])
375
375
 
376
376
 
377
- def test_no_repetition_ids():
377
+ def test_no_repetition_ids() -> None:
378
378
  def default_repetition_ids(self): # pragma: no cover
379
379
  assert False, "Should not call default_repetition_ids"
380
380
 
@@ -395,7 +395,7 @@ def test_no_repetition_ids():
395
395
  assert op2.repetition_ids is None
396
396
 
397
397
 
398
- def test_parameterized_repeat():
398
+ def test_parameterized_repeat() -> None:
399
399
  q = cirq.LineQubit(0)
400
400
  op = cirq.CircuitOperation(cirq.FrozenCircuit(cirq.X(q))) ** sympy.Symbol('a')
401
401
  assert cirq.parameter_names(op) == {'a'}
@@ -455,7 +455,7 @@ def test_parameterized_repeat():
455
455
  cirq.Simulator().simulate(cirq.Circuit(op))
456
456
 
457
457
 
458
- def test_parameterized_repeat_side_effects():
458
+ def test_parameterized_repeat_side_effects() -> None:
459
459
  q = cirq.LineQubit(0)
460
460
  op = cirq.CircuitOperation(
461
461
  cirq.FrozenCircuit(cirq.X(q).with_classical_controls('c'), cirq.measure(q, key='m')),
@@ -520,7 +520,7 @@ def test_parameterized_repeat_side_effects():
520
520
  )
521
521
 
522
522
 
523
- def test_parameterized_repeat_side_effects_when_not_using_rep_ids():
523
+ def test_parameterized_repeat_side_effects_when_not_using_rep_ids() -> None:
524
524
  q = cirq.LineQubit(0)
525
525
  op = cirq.CircuitOperation(
526
526
  cirq.FrozenCircuit(cirq.X(q).with_classical_controls('c'), cirq.measure(q, key='m')),
@@ -546,7 +546,7 @@ def test_parameterized_repeat_side_effects_when_not_using_rep_ids():
546
546
  op.repeat(repetition_ids=['x', 'y'])
547
547
 
548
548
 
549
- def test_qid_shape():
549
+ def test_qid_shape() -> None:
550
550
  circuit = cirq.FrozenCircuit(
551
551
  cirq.IdentityGate(qid_shape=(q.dimension,)).on(q)
552
552
  for q in cirq.LineQid.for_qid_shape((1, 2, 3, 4))
@@ -561,7 +561,7 @@ def test_qid_shape():
561
561
  assert cirq.num_qubits(id_op) == 3
562
562
 
563
563
 
564
- def test_string_format():
564
+ def test_string_format() -> None:
565
565
  x, y, z = cirq.LineQubit.range(3)
566
566
 
567
567
  fc0 = cirq.FrozenCircuit()
@@ -735,7 +735,7 @@ cirq.CircuitOperation(
735
735
  )
736
736
 
737
737
 
738
- def test_json_dict():
738
+ def test_json_dict() -> None:
739
739
  a, b, c = cirq.LineQubit.range(3)
740
740
  circuit = cirq.FrozenCircuit(
741
741
  cirq.X(a),
@@ -764,7 +764,7 @@ def test_json_dict():
764
764
  }
765
765
 
766
766
 
767
- def test_terminal_matches():
767
+ def test_terminal_matches() -> None:
768
768
  a, b = cirq.LineQubit.range(2)
769
769
  fc = cirq.FrozenCircuit(cirq.H(a), cirq.measure(b, key='m1'))
770
770
  op = cirq.CircuitOperation(fc)
@@ -802,23 +802,23 @@ def test_terminal_matches():
802
802
  assert c.are_any_measurements_terminal()
803
803
 
804
804
 
805
- def test_nonterminal_in_subcircuit():
805
+ def test_nonterminal_in_subcircuit() -> None:
806
806
  a, b = cirq.LineQubit.range(2)
807
807
  fc = cirq.FrozenCircuit(cirq.H(a), cirq.measure(b, key='m1'), cirq.X(b))
808
- op = cirq.CircuitOperation(fc)
809
- c = cirq.Circuit(cirq.X(a), op)
810
- assert isinstance(op, cirq.CircuitOperation)
808
+ circuit_op = cirq.CircuitOperation(fc)
809
+ c = cirq.Circuit(cirq.X(a), circuit_op)
810
+ assert isinstance(circuit_op, cirq.CircuitOperation)
811
811
  assert not c.are_all_measurements_terminal()
812
812
  assert not c.are_any_measurements_terminal()
813
813
 
814
- op = op.with_tags('test')
814
+ op = circuit_op.with_tags('test')
815
815
  c = cirq.Circuit(cirq.X(a), op)
816
816
  assert not isinstance(op, cirq.CircuitOperation)
817
817
  assert not c.are_all_measurements_terminal()
818
818
  assert not c.are_any_measurements_terminal()
819
819
 
820
820
 
821
- def test_decompose_applies_maps():
821
+ def test_decompose_applies_maps() -> None:
822
822
  a, b, c = cirq.LineQubit.range(3)
823
823
  exp = sympy.Symbol('exp')
824
824
  theta = sympy.Symbol('theta')
@@ -846,7 +846,7 @@ def test_decompose_applies_maps():
846
846
  assert cirq.Circuit(cirq.decompose_once(op)) == expected_circuit
847
847
 
848
848
 
849
- def test_decompose_loops():
849
+ def test_decompose_loops() -> None:
850
850
  a, b = cirq.LineQubit.range(2)
851
851
  circuit = cirq.FrozenCircuit(cirq.H(a), cirq.CX(a, b))
852
852
  base_op = cirq.CircuitOperation(circuit)
@@ -862,7 +862,7 @@ def test_decompose_loops():
862
862
  assert cirq.Circuit(cirq.decompose_once(op)) == expected_circuit
863
863
 
864
864
 
865
- def test_decompose_loops_with_measurements():
865
+ def test_decompose_loops_with_measurements() -> None:
866
866
  a, b = cirq.LineQubit.range(2)
867
867
  circuit = cirq.FrozenCircuit(cirq.H(a), cirq.CX(a, b), cirq.measure(a, b, key='m'))
868
868
  base_op = cirq.CircuitOperation(circuit)
@@ -882,7 +882,7 @@ def test_decompose_loops_with_measurements():
882
882
  assert cirq.Circuit(cirq.decompose_once(op)) == expected_circuit
883
883
 
884
884
 
885
- def test_decompose_loops_with_measurements_use_rep_ids():
885
+ def test_decompose_loops_with_measurements_use_rep_ids() -> None:
886
886
  a, b = cirq.LineQubit.range(2)
887
887
  circuit = cirq.FrozenCircuit(cirq.H(a), cirq.CX(a, b), cirq.measure(a, b, key='m'))
888
888
  base_op = cirq.CircuitOperation(circuit, use_repetition_ids=True)
@@ -902,7 +902,7 @@ def test_decompose_loops_with_measurements_use_rep_ids():
902
902
  assert cirq.Circuit(cirq.decompose_once(op)) == expected_circuit
903
903
 
904
904
 
905
- def test_decompose_nested():
905
+ def test_decompose_nested() -> None:
906
906
  a, b, c, d = cirq.LineQubit.range(4)
907
907
  exp1 = sympy.Symbol('exp1')
908
908
  exp_half = sympy.Symbol('exp_half')
@@ -982,7 +982,7 @@ def test_decompose_nested():
982
982
  assert final_op.mapped_circuit(deep=True) == expected_circuit
983
983
 
984
984
 
985
- def test_decompose_repeated_nested_measurements():
985
+ def test_decompose_repeated_nested_measurements() -> None:
986
986
  # Details of this test described at
987
987
  # https://tinyurl.com/measurement-repeated-circuitop#heading=h.sbgxcsyin9wt.
988
988
  a = cirq.LineQubit(0)
@@ -1034,7 +1034,7 @@ def test_decompose_repeated_nested_measurements():
1034
1034
  assert op3.mapped_circuit(deep=True) == expected_circuit
1035
1035
 
1036
1036
 
1037
- def test_keys_under_parent_path():
1037
+ def test_keys_under_parent_path() -> None:
1038
1038
  a = cirq.LineQubit(0)
1039
1039
  op1 = cirq.CircuitOperation(cirq.FrozenCircuit(cirq.measure(a, key='A')))
1040
1040
  assert cirq.measurement_key_names(op1) == {'A'}
@@ -1048,7 +1048,7 @@ def test_keys_under_parent_path():
1048
1048
  assert cirq.measurement_key_names(op4_rep) == {'C:B:0:A', 'C:B:1:A'}
1049
1049
 
1050
1050
 
1051
- def test_mapped_circuit_preserves_moments():
1051
+ def test_mapped_circuit_preserves_moments() -> None:
1052
1052
  q0, q1 = cirq.LineQubit.range(2)
1053
1053
  fc = cirq.FrozenCircuit(cirq.Moment(cirq.X(q0)), cirq.Moment(cirq.X(q1)))
1054
1054
  op = cirq.CircuitOperation(fc)
@@ -1056,7 +1056,7 @@ def test_mapped_circuit_preserves_moments():
1056
1056
  assert op.repeat(3).mapped_circuit(deep=True) == fc * 3
1057
1057
 
1058
1058
 
1059
- def test_mapped_op():
1059
+ def test_mapped_op() -> None:
1060
1060
  q0, q1 = cirq.LineQubit.range(2)
1061
1061
  a, b = (sympy.Symbol(x) for x in 'ab')
1062
1062
  fc1 = cirq.FrozenCircuit(cirq.X(q0) ** a, cirq.measure(q0, q1, key='m'))
@@ -1072,14 +1072,14 @@ def test_mapped_op():
1072
1072
  assert op1.mapped_op() == op2
1073
1073
 
1074
1074
 
1075
- def test_tag_propagation():
1075
+ def test_tag_propagation() -> None:
1076
1076
  # Tags are not propagated from the CircuitOperation to its components.
1077
1077
  # TODO: support tag propagation for better serialization.
1078
1078
  a, b, c = cirq.LineQubit.range(3)
1079
1079
  circuit = cirq.FrozenCircuit(cirq.X(a), cirq.H(b), cirq.H(c), cirq.CZ(a, c))
1080
- op = cirq.CircuitOperation(circuit)
1080
+ circuit_op = cirq.CircuitOperation(circuit)
1081
1081
  test_tag = 'test_tag'
1082
- op = op.with_tags(test_tag)
1082
+ op = circuit_op.with_tags(test_tag)
1083
1083
 
1084
1084
  assert test_tag in op.tags
1085
1085
 
@@ -1089,13 +1089,15 @@ def test_tag_propagation():
1089
1089
  assert test_tag not in op.tags
1090
1090
 
1091
1091
 
1092
- def test_mapped_circuit_keeps_keys_under_parent_path():
1092
+ def test_mapped_circuit_keeps_keys_under_parent_path() -> None:
1093
1093
  q = cirq.LineQubit(0)
1094
+ bit_flip = cirq.bit_flip(0.5)
1095
+ assert isinstance(bit_flip, cirq.BitFlipChannel)
1094
1096
  op1 = cirq.CircuitOperation(
1095
1097
  cirq.FrozenCircuit(
1096
1098
  cirq.measure(q, key='A'),
1097
1099
  cirq.measure_single_paulistring(cirq.X(q), key='B'),
1098
- cirq.MixedUnitaryChannel.from_mixture(cirq.bit_flip(0.5), key='C').on(q),
1100
+ cirq.MixedUnitaryChannel.from_mixture(bit_flip, key='C').on(q),
1099
1101
  cirq.KrausChannel.from_channel(cirq.phase_damp(0.5), key='D').on(q),
1100
1102
  )
1101
1103
  )
@@ -1103,7 +1105,7 @@ def test_mapped_circuit_keeps_keys_under_parent_path():
1103
1105
  assert cirq.measurement_key_names(op2.mapped_circuit()) == {'X:A', 'X:B', 'X:C', 'X:D'}
1104
1106
 
1105
1107
 
1106
- def test_mapped_circuit_allows_repeated_keys():
1108
+ def test_mapped_circuit_allows_repeated_keys() -> None:
1107
1109
  q = cirq.LineQubit(0)
1108
1110
  op1 = cirq.CircuitOperation(cirq.FrozenCircuit(cirq.measure(q, key='A')))
1109
1111
  op2 = cirq.CircuitOperation(cirq.FrozenCircuit(op1, op1))
@@ -1111,16 +1113,16 @@ def test_mapped_circuit_allows_repeated_keys():
1111
1113
  cirq.testing.assert_has_diagram(
1112
1114
  circuit, "0: ───M('A')───M('A')───", use_unicode_characters=True
1113
1115
  )
1114
- op1 = cirq.measure(q, key='A')
1115
- op2 = cirq.CircuitOperation(cirq.FrozenCircuit(op1, op1))
1116
- circuit = op2.mapped_circuit()
1116
+ op3 = cirq.measure(q, key='A')
1117
+ op4 = cirq.CircuitOperation(cirq.FrozenCircuit(op3, op3))
1118
+ circuit = op4.mapped_circuit()
1117
1119
  cirq.testing.assert_has_diagram(
1118
1120
  circuit, "0: ───M('A')───M('A')───", use_unicode_characters=True
1119
1121
  )
1120
1122
 
1121
1123
 
1122
1124
  @pytest.mark.parametrize('sim', ALL_SIMULATORS)
1123
- def test_simulate_no_repetition_ids_both_levels(sim):
1125
+ def test_simulate_no_repetition_ids_both_levels(sim) -> None:
1124
1126
  q = cirq.LineQubit(0)
1125
1127
  inner = cirq.Circuit(cirq.measure(q, key='a'))
1126
1128
  middle = cirq.Circuit(cirq.CircuitOperation(inner.freeze(), repetitions=2))
@@ -1131,7 +1133,7 @@ def test_simulate_no_repetition_ids_both_levels(sim):
1131
1133
 
1132
1134
 
1133
1135
  @pytest.mark.parametrize('sim', ALL_SIMULATORS)
1134
- def test_simulate_no_repetition_ids_outer(sim):
1136
+ def test_simulate_no_repetition_ids_outer(sim) -> None:
1135
1137
  q = cirq.LineQubit(0)
1136
1138
  inner = cirq.Circuit(cirq.measure(q, key='a'))
1137
1139
  middle = cirq.Circuit(
@@ -1145,7 +1147,7 @@ def test_simulate_no_repetition_ids_outer(sim):
1145
1147
 
1146
1148
 
1147
1149
  @pytest.mark.parametrize('sim', ALL_SIMULATORS)
1148
- def test_simulate_no_repetition_ids_inner(sim):
1150
+ def test_simulate_no_repetition_ids_inner(sim) -> None:
1149
1151
  q = cirq.LineQubit(0)
1150
1152
  inner = cirq.Circuit(cirq.measure(q, key='a'))
1151
1153
  middle = cirq.Circuit(cirq.CircuitOperation(inner.freeze(), repetitions=2))
@@ -1159,7 +1161,7 @@ def test_simulate_no_repetition_ids_inner(sim):
1159
1161
 
1160
1162
 
1161
1163
  @pytest.mark.parametrize('sim', ALL_SIMULATORS)
1162
- def test_repeat_until(sim):
1164
+ def test_repeat_until(sim) -> None:
1163
1165
  q = cirq.LineQubit(0)
1164
1166
  key = cirq.MeasurementKey('m')
1165
1167
  c = cirq.Circuit(
@@ -1176,7 +1178,7 @@ def test_repeat_until(sim):
1176
1178
 
1177
1179
 
1178
1180
  @pytest.mark.parametrize('sim', ALL_SIMULATORS)
1179
- def test_repeat_until_sympy(sim):
1181
+ def test_repeat_until_sympy(sim) -> None:
1180
1182
  q1, q2 = cirq.LineQubit.range(2)
1181
1183
  circuitop = cirq.CircuitOperation(
1182
1184
  cirq.FrozenCircuit(cirq.X(q2), cirq.measure(q2, key='b')),
@@ -1193,7 +1195,7 @@ def test_repeat_until_sympy(sim):
1193
1195
 
1194
1196
 
1195
1197
  @pytest.mark.parametrize('sim', [cirq.Simulator(), cirq.DensityMatrixSimulator()])
1196
- def test_post_selection(sim):
1198
+ def test_post_selection(sim) -> None:
1197
1199
  q = cirq.LineQubit(0)
1198
1200
  key = cirq.MeasurementKey('m')
1199
1201
  c = cirq.Circuit(
@@ -1208,7 +1210,7 @@ def test_post_selection(sim):
1208
1210
  assert result.records['m'][0][i] == (0,)
1209
1211
 
1210
1212
 
1211
- def test_repeat_until_diagram():
1213
+ def test_repeat_until_diagram() -> None:
1212
1214
  q = cirq.LineQubit(0)
1213
1215
  key = cirq.MeasurementKey('m')
1214
1216
  c = cirq.Circuit(
@@ -1226,7 +1228,7 @@ def test_repeat_until_diagram():
1226
1228
  )
1227
1229
 
1228
1230
 
1229
- def test_repeat_until_error():
1231
+ def test_repeat_until_error() -> None:
1230
1232
  q = cirq.LineQubit(0)
1231
1233
  with pytest.raises(ValueError, match='Cannot use repetitions with repeat_until'):
1232
1234
  cirq.CircuitOperation(
@@ -1241,7 +1243,7 @@ def test_repeat_until_error():
1241
1243
  )
1242
1244
 
1243
1245
 
1244
- def test_repeat_until_protocols():
1246
+ def test_repeat_until_protocols() -> None:
1245
1247
  q = cirq.LineQubit(0)
1246
1248
  op = cirq.CircuitOperation(
1247
1249
  cirq.FrozenCircuit(cirq.H(q) ** sympy.Symbol('p'), cirq.measure(q, key='a')),
@@ -1272,7 +1274,7 @@ def test_repeat_until_protocols():
1272
1274
  assert not cirq.control_keys(resolved)
1273
1275
 
1274
1276
 
1275
- def test_inner_repeat_until_simulate():
1277
+ def test_inner_repeat_until_simulate() -> None:
1276
1278
  sim = cirq.Simulator()
1277
1279
  q = cirq.LineQubit(0)
1278
1280
  inner_loop = cirq.CircuitOperation(
@@ -24,7 +24,7 @@ import sympy
24
24
  import cirq
25
25
 
26
26
 
27
- def test_from_moments():
27
+ def test_from_moments() -> None:
28
28
  a, b, c, d = cirq.LineQubit.range(4)
29
29
  moment = cirq.Moment(cirq.Z(a), cirq.Z(b))
30
30
  subcircuit = cirq.FrozenCircuit.from_moments(cirq.X(c), cirq.Y(d))
@@ -51,10 +51,11 @@ def test_from_moments():
51
51
  cirq.Moment(cirq.measure(a, b, key='ab'), cirq.measure(c, d, key='cd')),
52
52
  )
53
53
  assert circuit[0] is moment
54
+ assert isinstance(circuit[1].operations[0], cirq.CircuitOperation)
54
55
  assert circuit[1].operations[0].circuit is subcircuit
55
56
 
56
57
 
57
- def test_freeze_and_unfreeze():
58
+ def test_freeze_and_unfreeze() -> None:
58
59
  a, b = cirq.LineQubit.range(2)
59
60
  c = cirq.Circuit(cirq.X(a), cirq.H(b))
60
61
 
@@ -80,7 +81,7 @@ def test_freeze_and_unfreeze():
80
81
  assert fcc is not f
81
82
 
82
83
 
83
- def test_immutable():
84
+ def test_immutable() -> None:
84
85
  q = cirq.LineQubit(0)
85
86
  c = cirq.FrozenCircuit(cirq.X(q), cirq.H(q))
86
87
 
@@ -89,10 +90,10 @@ def test_immutable():
89
90
  AttributeError,
90
91
  match="(can't set attribute)|(property 'moments' of 'FrozenCircuit' object has no setter)",
91
92
  ):
92
- c.moments = (cirq.Moment(cirq.H(q)), cirq.Moment(cirq.X(q)))
93
+ c.moments = (cirq.Moment(cirq.H(q)), cirq.Moment(cirq.X(q))) # type: ignore[misc]
93
94
 
94
95
 
95
- def test_tagged_circuits():
96
+ def test_tagged_circuits() -> None:
96
97
  q = cirq.LineQubit(0)
97
98
  ops = [cirq.X(q), cirq.H(q)]
98
99
  tags = [sympy.Symbol("a"), "b"]