cirq-core 1.7.0.dev20250818230756__py3-none-any.whl → 1.7.0.dev20250820205919__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 (57) hide show
  1. cirq/_version.py +1 -1
  2. cirq/_version_test.py +1 -1
  3. cirq/experiments/z_phase_calibration_test.py +8 -7
  4. cirq/interop/quirk/cells/arithmetic_cells.py +1 -1
  5. cirq/interop/quirk/cells/cell_test.py +5 -5
  6. cirq/interop/quirk/cells/composite_cell_test.py +5 -3
  7. cirq/interop/quirk/cells/control_cells.py +2 -2
  8. cirq/interop/quirk/cells/input_cells.py +3 -3
  9. cirq/interop/quirk/cells/input_rotation_cells.py +2 -2
  10. cirq/interop/quirk/cells/swap_cell.py +2 -2
  11. cirq/interop/quirk/cells/testing.py +1 -1
  12. cirq/interop/quirk/url_to_circuit.py +2 -2
  13. cirq/interop/quirk/url_to_circuit_test.py +11 -11
  14. cirq/linalg/decompositions.py +1 -1
  15. cirq/linalg/decompositions_test.py +52 -50
  16. cirq/linalg/diagonalize_test.py +2 -2
  17. cirq/linalg/predicates.py +1 -1
  18. cirq/linalg/predicates_test.py +24 -24
  19. cirq/linalg/transformations.py +6 -4
  20. cirq/neutral_atoms/neutral_atom_devices.py +1 -1
  21. cirq/ops/classically_controlled_operation.py +2 -2
  22. cirq/ops/clifford_gate.py +1 -1
  23. cirq/ops/common_channels_test.py +1 -1
  24. cirq/ops/common_gates.py +2 -2
  25. cirq/ops/controlled_operation.py +2 -2
  26. cirq/ops/controlled_operation_test.py +17 -16
  27. cirq/ops/dense_pauli_string_test.py +41 -37
  28. cirq/ops/eigen_gate_test.py +0 -7
  29. cirq/ops/gateset.py +3 -3
  30. cirq/ops/gateset_test.py +23 -23
  31. cirq/ops/linear_combinations.py +1 -1
  32. cirq/ops/linear_combinations_test.py +103 -89
  33. cirq/ops/matrix_gates_test.py +31 -31
  34. cirq/ops/measure_util_test.py +11 -10
  35. cirq/ops/measurement_gate_test.py +23 -22
  36. cirq/ops/pauli_gates.py +1 -1
  37. cirq/ops/pauli_measurement_gate_test.py +12 -12
  38. cirq/ops/pauli_string_phasor_test.py +45 -40
  39. cirq/ops/pauli_string_raw_types_test.py +5 -4
  40. cirq/ops/pauli_string_test.py +190 -118
  41. cirq/ops/permutation_gate.py +1 -1
  42. cirq/ops/raw_types.py +3 -4
  43. cirq/ops/raw_types_test.py +1 -1
  44. cirq/ops/three_qubit_gates.py +3 -3
  45. cirq/protocols/act_on_protocol.py +1 -1
  46. cirq/protocols/act_on_protocol_test.py +4 -4
  47. cirq/protocols/apply_channel_protocol_test.py +19 -18
  48. cirq/protocols/apply_mixture_protocol_test.py +20 -19
  49. cirq/protocols/apply_unitary_protocol_test.py +31 -23
  50. cirq/protocols/approximate_equality_protocol_test.py +22 -16
  51. cirq/protocols/circuit_diagram_info_protocol.py +4 -4
  52. cirq/protocols/commutes_protocol_test.py +4 -4
  53. {cirq_core-1.7.0.dev20250818230756.dist-info → cirq_core-1.7.0.dev20250820205919.dist-info}/METADATA +1 -1
  54. {cirq_core-1.7.0.dev20250818230756.dist-info → cirq_core-1.7.0.dev20250820205919.dist-info}/RECORD +57 -57
  55. {cirq_core-1.7.0.dev20250818230756.dist-info → cirq_core-1.7.0.dev20250820205919.dist-info}/WHEEL +0 -0
  56. {cirq_core-1.7.0.dev20250818230756.dist-info → cirq_core-1.7.0.dev20250820205919.dist-info}/licenses/LICENSE +0 -0
  57. {cirq_core-1.7.0.dev20250818230756.dist-info → cirq_core-1.7.0.dev20250820205919.dist-info}/top_level.txt +0 -0
cirq/ops/common_gates.py CHANGED
@@ -274,7 +274,7 @@ class XPowGate(eigen_gate.EigenGate):
274
274
  return args.format('rx({0:half_turns}) {1};\n', self._exponent, qubits[0])
275
275
 
276
276
  @property
277
- def phase_exponent(self):
277
+ def phase_exponent(self) -> float:
278
278
  return 0.0
279
279
 
280
280
  def _phase_by_(self, phase_turns, qubit_index):
@@ -467,7 +467,7 @@ class YPowGate(eigen_gate.EigenGate):
467
467
  return args.format('ry({0:half_turns}) {1};\n', self._exponent, qubits[0])
468
468
 
469
469
  @property
470
- def phase_exponent(self):
470
+ def phase_exponent(self) -> float:
471
471
  return 0.5
472
472
 
473
473
  def _phase_by_(self, phase_turns, qubit_index):
@@ -124,10 +124,10 @@ class ControlledOperation(raw_types.Operation):
124
124
  )
125
125
 
126
126
  @property
127
- def qubits(self):
127
+ def qubits(self) -> tuple[cirq.Qid, ...]:
128
128
  return self.controls + self.sub_operation.qubits
129
129
 
130
- def with_qubits(self, *new_qubits):
130
+ def with_qubits(self, *new_qubits) -> ControlledOperation:
131
131
  n = len(self.controls)
132
132
  return ControlledOperation(
133
133
  new_qubits[:n], self.sub_operation.with_qubits(*new_qubits[n:]), self.control_values
@@ -17,7 +17,7 @@ from __future__ import annotations
17
17
  import itertools
18
18
  import re
19
19
  from types import EllipsisType, NotImplementedType
20
- from typing import cast
20
+ from typing import cast, Sequence
21
21
 
22
22
  import numpy as np
23
23
  import pytest
@@ -74,7 +74,7 @@ class GateAllocatingNewSpaceForResult(cirq.testing.SingleQubitGate):
74
74
  return 'cirq.ops.controlled_operation_test.GateAllocatingNewSpaceForResult()'
75
75
 
76
76
 
77
- def test_controlled_operation_init():
77
+ def test_controlled_operation_init() -> None:
78
78
  class G(cirq.testing.SingleQubitGate):
79
79
  def _has_mixture_(self):
80
80
  return True
@@ -123,7 +123,7 @@ def test_controlled_operation_init():
123
123
  _ = cirq.ControlledOperation([cb], cirq.PhaseDampingChannel(1)(q))
124
124
 
125
125
 
126
- def test_controlled_operation_eq():
126
+ def test_controlled_operation_eq() -> None:
127
127
  c1 = cirq.NamedQubit('c1')
128
128
  q1 = cirq.NamedQubit('q1')
129
129
  c2 = cirq.NamedQubit('c2')
@@ -148,7 +148,7 @@ def test_controlled_operation_eq():
148
148
  )
149
149
 
150
150
 
151
- def test_str():
151
+ def test_str() -> None:
152
152
  c1 = cirq.NamedQubit('c1')
153
153
  c2 = cirq.NamedQubit('c2')
154
154
  q2 = cirq.NamedQubit('q2')
@@ -190,7 +190,7 @@ def test_str():
190
190
  )
191
191
 
192
192
 
193
- def test_repr():
193
+ def test_repr() -> None:
194
194
  a, b, c, d = cirq.LineQubit.range(4)
195
195
 
196
196
  ch = cirq.H(a).controlled_by(b)
@@ -231,7 +231,8 @@ class MultiH(cirq.Gate):
231
231
  return True
232
232
 
233
233
 
234
- def test_circuit_diagram():
234
+ def test_circuit_diagram() -> None:
235
+ qubits: Sequence[cirq.Qid]
235
236
  qubits = cirq.LineQubit.range(3)
236
237
  c = cirq.Circuit()
237
238
  c.append(cirq.ControlledOperation(qubits[:1], MultiH(2)(*qubits[1:])))
@@ -302,7 +303,7 @@ class MockGate(cirq.testing.TwoQubitGate):
302
303
  return True
303
304
 
304
305
 
305
- def test_controlled_diagram_exponent():
306
+ def test_controlled_diagram_exponent() -> None:
306
307
  for q in itertools.permutations(cirq.LineQubit.range(5)):
307
308
  for idx in [None, 0, 1]:
308
309
  op = MockGate(idx)(*q[:2]).controlled_by(*q[2:])
@@ -310,7 +311,7 @@ def test_controlled_diagram_exponent():
310
311
  assert cirq.circuit_diagram_info(op).exponent_qubit_index == len(q[2:]) + add
311
312
 
312
313
 
313
- def test_uninformed_circuit_diagram_info():
314
+ def test_uninformed_circuit_diagram_info() -> None:
314
315
  qbits = cirq.LineQubit.range(3)
315
316
  mock_gate = MockGate()
316
317
  c_op = cirq.ControlledOperation(qbits[:1], mock_gate(*qbits[1:]))
@@ -323,7 +324,7 @@ def test_uninformed_circuit_diagram_info():
323
324
  assert mock_gate.captured_diagram_args == args
324
325
 
325
326
 
326
- def test_non_diagrammable_subop():
327
+ def test_non_diagrammable_subop() -> None:
327
328
  qbits = cirq.LineQubit.range(2)
328
329
 
329
330
  class UndiagrammableGate(cirq.testing.SingleQubitGate):
@@ -369,7 +370,7 @@ def test_non_diagrammable_subop():
369
370
  )
370
371
  def test_controlled_operation_is_consistent(
371
372
  gate: cirq.GateOperation, should_decompose_to_target: bool
372
- ):
373
+ ) -> None:
373
374
  cb = cirq.NamedQubit('ctr')
374
375
  cgate = cirq.ControlledOperation([cb], gate)
375
376
  cirq.testing.assert_implements_consistent_protocols(cgate)
@@ -395,7 +396,7 @@ def test_controlled_operation_is_consistent(
395
396
  cirq.testing.assert_decompose_ends_at_default_gateset(cgate)
396
397
 
397
398
 
398
- def test_controlled_circuit_operation_is_consistent():
399
+ def test_controlled_circuit_operation_is_consistent() -> None:
399
400
  op = cirq.CircuitOperation(
400
401
  cirq.FrozenCircuit(
401
402
  cirq.XXPowGate(exponent=0.25, global_shift=-0.5).on(*cirq.LineQubit.range(2))
@@ -416,7 +417,7 @@ def test_controlled_circuit_operation_is_consistent():
416
417
 
417
418
 
418
419
  @pytest.mark.parametrize('resolve_fn', [cirq.resolve_parameters, cirq.resolve_parameters_once])
419
- def test_parameterizable(resolve_fn):
420
+ def test_parameterizable(resolve_fn) -> None:
420
421
  a = sympy.Symbol('a')
421
422
  qubits = cirq.LineQubit.range(3)
422
423
 
@@ -434,7 +435,7 @@ def test_parameterizable(resolve_fn):
434
435
  resolve_fn(cchan, cirq.ParamResolver({'a': 0.1}))
435
436
 
436
437
 
437
- def test_bounded_effect():
438
+ def test_bounded_effect() -> None:
438
439
  qubits = cirq.LineQubit.range(3)
439
440
  cy = cirq.ControlledOperation(qubits[:1], cirq.Y(qubits[1]))
440
441
  assert cirq.trace_distance_bound(cy**0.001) < 0.01
@@ -444,8 +445,8 @@ def test_bounded_effect():
444
445
  assert cirq.approx_eq(cirq.trace_distance_bound(cy), 1.0)
445
446
 
446
447
 
447
- def test_controlled_operation_gate():
448
- gate = cirq.X.controlled(control_values=[0, 1], control_qid_shape=[2, 3])
448
+ def test_controlled_operation_gate() -> None:
449
+ gate = cirq.X.controlled(control_values=[0, 1], control_qid_shape=(2, 3))
449
450
  op = gate.on(cirq.LineQubit(0), cirq.LineQid(1, 3), cirq.LineQubit(2))
450
451
  assert op.gate == gate
451
452
 
@@ -464,7 +465,7 @@ def test_controlled_operation_gate():
464
465
  assert op.gate is None
465
466
 
466
467
 
467
- def test_controlled_mixture():
468
+ def test_controlled_mixture() -> None:
468
469
  a, b = cirq.LineQubit.range(2)
469
470
  c_yes = cirq.ControlledOperation(controls=[b], sub_operation=cirq.phase_flip(0.25).on(a))
470
471
  assert cirq.has_mixture(c_yes)
@@ -24,7 +24,7 @@ import cirq
24
24
  from cirq.ops.dense_pauli_string import _vectorized_pauli_mul_phase
25
25
 
26
26
 
27
- def test_init():
27
+ def test_init() -> None:
28
28
  mask = np.array([0, 3, 1, 2], dtype=np.uint8)
29
29
  p = cirq.DensePauliString(coefficient=2, pauli_mask=mask)
30
30
  m = cirq.MutableDensePauliString(coefficient=3, pauli_mask=mask)
@@ -50,10 +50,10 @@ def test_init():
50
50
  assert cirq.DensePauliString([1, 'X', cirq.X]) == cirq.DensePauliString('XXX')
51
51
  assert list(cirq.DensePauliString('XXX')) == [cirq.X, cirq.X, cirq.X]
52
52
  with pytest.raises(TypeError, match='Expected a cirq.PAULI_GATE_LIKE'):
53
- _ = cirq.DensePauliString([object()])
53
+ _ = cirq.DensePauliString([object()]) # type: ignore[list-item]
54
54
 
55
55
 
56
- def test_value_to_char_correspondence():
56
+ def test_value_to_char_correspondence() -> None:
57
57
  d = cirq.DensePauliString
58
58
  assert [d.I_VAL, d.X_VAL, d.Y_VAL, d.Z_VAL] == [0, 1, 2, 3]
59
59
  assert list(d([cirq.I, cirq.X, cirq.Y, cirq.Z]).pauli_mask) == [0, 1, 2, 3]
@@ -69,7 +69,7 @@ def test_value_to_char_correspondence():
69
69
  assert d('Z') * d('Y') == -1j * d('X')
70
70
 
71
71
 
72
- def test_from_text():
72
+ def test_from_text() -> None:
73
73
  d = cirq.DensePauliString
74
74
  m = cirq.MutableDensePauliString
75
75
 
@@ -86,7 +86,7 @@ def test_from_text():
86
86
  _ = d('2')
87
87
 
88
88
 
89
- def test_immutable_eq():
89
+ def test_immutable_eq() -> None:
90
90
  eq = cirq.testing.EqualsTester()
91
91
 
92
92
  # Immutables
@@ -103,7 +103,7 @@ def test_immutable_eq():
103
103
  eq.make_equality_group(lambda: cirq.MutableDensePauliString(coefficient=2, pauli_mask=[2]))
104
104
 
105
105
 
106
- def test_eye():
106
+ def test_eye() -> None:
107
107
  f = cirq.DensePauliString
108
108
  m = cirq.MutableDensePauliString
109
109
  assert cirq.BaseDensePauliString.eye(4) == f('IIII')
@@ -111,7 +111,7 @@ def test_eye():
111
111
  assert cirq.MutableDensePauliString.eye(4) == m('IIII')
112
112
 
113
113
 
114
- def test_sparse():
114
+ def test_sparse() -> None:
115
115
  a, b, c = cirq.LineQubit.range(3)
116
116
  p = -cirq.DensePauliString('XYZ')
117
117
  assert p.sparse() == cirq.PauliString(-1, cirq.X(a), cirq.Y(b), cirq.Z(c))
@@ -122,12 +122,14 @@ def test_sparse():
122
122
  _ = p.sparse(cirq.GridQubit.rect(2, 2))
123
123
 
124
124
 
125
- def test_mul_vectorized_pauli_mul_phase():
125
+ def test_mul_vectorized_pauli_mul_phase() -> None:
126
126
  f = _vectorized_pauli_mul_phase
127
127
  paulis = [cirq.I, cirq.X, cirq.Y, cirq.Z]
128
128
  q = cirq.LineQubit(0)
129
129
 
130
130
  # Check single qubit cases.
131
+ sparse1: cirq.PauliString
132
+ sparse2: cirq.PauliString
131
133
  for i in range(4):
132
134
  for j in range(4):
133
135
  sparse1 = cirq.PauliString(paulis[i].on(q))
@@ -146,7 +148,7 @@ def test_mul_vectorized_pauli_mul_phase():
146
148
  )
147
149
 
148
150
 
149
- def test_mul():
151
+ def test_mul() -> None:
150
152
  f = cirq.DensePauliString
151
153
 
152
154
  # Scalar.
@@ -193,22 +195,23 @@ def test_mul():
193
195
 
194
196
  # Unknown number type
195
197
  class UnknownNumber(numbers.Number):
196
- pass
198
+ def __hash__(self):
199
+ return hash(complex(self)) # pragma: no cover
197
200
 
198
201
  with pytest.raises(TypeError):
199
202
  _ = UnknownNumber() * f('I')
200
203
 
201
204
 
202
- def test_imul():
205
+ def test_imul() -> None:
203
206
  f = cirq.DensePauliString
204
207
  m = cirq.MutableDensePauliString
205
208
 
206
209
  # Immutable not modified by imul.
207
- p = f('III')
208
- p2 = p
209
- p2 *= 2
210
- assert p.coefficient == 1
211
- assert p is not p2
210
+ pf = f('III')
211
+ pf2 = pf
212
+ pf2 *= 2
213
+ assert pf.coefficient == 1
214
+ assert pf is not pf2
212
215
 
213
216
  # Mutable is modified by imul.
214
217
  p = m('III')
@@ -239,19 +242,20 @@ def test_imul():
239
242
 
240
243
  # Unknown number type
241
244
  class UnknownNumber(numbers.Number):
242
- pass
245
+ def __hash__(self):
246
+ return hash(complex(self)) # pragma: no cover
243
247
 
244
248
  with pytest.raises(TypeError):
245
249
  p *= UnknownNumber()
246
250
 
247
251
 
248
- def test_pos_neg():
252
+ def test_pos_neg() -> None:
249
253
  p = 1j * cirq.DensePauliString('XYZ')
250
254
  assert +p == p
251
255
  assert -p == -1 * p
252
256
 
253
257
 
254
- def test_abs():
258
+ def test_abs() -> None:
255
259
  f = cirq.DensePauliString
256
260
  m = cirq.DensePauliString
257
261
  assert abs(-f('XX')) == f('XX')
@@ -259,7 +263,7 @@ def test_abs():
259
263
  assert abs(2j * m('XX')) == 2 * f('XX')
260
264
 
261
265
 
262
- def test_approx_eq():
266
+ def test_approx_eq() -> None:
263
267
  f = cirq.DensePauliString
264
268
  m = cirq.MutableDensePauliString
265
269
 
@@ -278,7 +282,7 @@ def test_approx_eq():
278
282
  assert not cirq.approx_eq(f('X'), f('Y'), atol=500)
279
283
 
280
284
 
281
- def test_pow():
285
+ def test_pow() -> None:
282
286
  f = cirq.DensePauliString
283
287
  m = cirq.DensePauliString
284
288
  p = 1j * f('IXYZ')
@@ -314,7 +318,7 @@ def test_pow():
314
318
  assert m('X') ** 3 == f('X')
315
319
 
316
320
 
317
- def test_div():
321
+ def test_div() -> None:
318
322
  f = cirq.DensePauliString
319
323
  t = sympy.Symbol('t')
320
324
  assert f('X') / 2 == 0.5 * f('X')
@@ -323,7 +327,7 @@ def test_div():
323
327
  _ = f('X') / object()
324
328
 
325
329
 
326
- def test_str():
330
+ def test_str() -> None:
327
331
  f = cirq.DensePauliString
328
332
  m = cirq.MutableDensePauliString
329
333
 
@@ -338,7 +342,7 @@ def test_str():
338
342
  assert str(f('XX', coefficient=sympy.Symbol('t'))) == 't*XX'
339
343
 
340
344
 
341
- def test_repr():
345
+ def test_repr() -> None:
342
346
  f = cirq.DensePauliString
343
347
  m = cirq.MutableDensePauliString
344
348
  cirq.testing.assert_equivalent_repr(f(''))
@@ -351,7 +355,7 @@ def test_repr():
351
355
  cirq.testing.assert_equivalent_repr(m(coefficient=sympy.Symbol('c'), pauli_mask=[0, 3, 2, 1]))
352
356
 
353
357
 
354
- def test_one_hot():
358
+ def test_one_hot() -> None:
355
359
  f = cirq.DensePauliString
356
360
  m = cirq.MutableDensePauliString
357
361
 
@@ -374,7 +378,7 @@ def test_one_hot():
374
378
  _ = cirq.BaseDensePauliString.one_hot(index=0, length=0, pauli=cirq.X)
375
379
 
376
380
 
377
- def test_protocols():
381
+ def test_protocols() -> None:
378
382
  t = sympy.Symbol('t')
379
383
  cirq.testing.assert_implements_consistent_protocols(cirq.DensePauliString('Y'))
380
384
  cirq.testing.assert_implements_consistent_protocols(-cirq.DensePauliString('Z'))
@@ -400,7 +404,7 @@ def test_protocols():
400
404
 
401
405
 
402
406
  @pytest.mark.parametrize('resolve_fn', [cirq.resolve_parameters, cirq.resolve_parameters_once])
403
- def test_parameterizable(resolve_fn):
407
+ def test_parameterizable(resolve_fn) -> None:
404
408
  t = sympy.Symbol('t')
405
409
  x = cirq.DensePauliString('X')
406
410
  xt = x * t
@@ -415,7 +419,7 @@ def test_parameterizable(resolve_fn):
415
419
  assert resolve_fn(xt(q).gate, {'t': 2}) == x2
416
420
 
417
421
 
418
- def test_item_immutable():
422
+ def test_item_immutable() -> None:
419
423
  p = -cirq.DensePauliString('XYIZ')
420
424
  assert p[-1] == cirq.Z
421
425
  assert p[0] == cirq.X
@@ -437,7 +441,7 @@ def test_item_immutable():
437
441
  assert p[::2] == cirq.DensePauliString('XI')
438
442
 
439
443
 
440
- def test_item_mutable():
444
+ def test_item_mutable() -> None:
441
445
  m = cirq.MutableDensePauliString
442
446
  p = m('XYIZ', coefficient=-1)
443
447
  assert p[-1] == cirq.Z
@@ -448,9 +452,9 @@ def test_item_mutable():
448
452
  with pytest.raises(IndexError):
449
453
  _ = p[4]
450
454
  with pytest.raises(TypeError):
451
- _ = p["test"]
455
+ _ = p["test"] # type: ignore[call-overload]
452
456
  with pytest.raises(TypeError):
453
- p["test"] = 'X'
457
+ p["test"] = 'X' # type: ignore[call-overload]
454
458
 
455
459
  p[2] = cirq.X
456
460
  assert p == m('XYXZ', coefficient=-1)
@@ -482,7 +486,7 @@ def test_item_mutable():
482
486
  assert p == m('ZYXX', coefficient=-1)
483
487
 
484
488
 
485
- def test_tensor_product():
489
+ def test_tensor_product() -> None:
486
490
  f = cirq.DensePauliString
487
491
  m = cirq.MutableDensePauliString
488
492
  assert (2 * f('XX')).tensor_product(-f('XI')) == -2 * f('XXXI')
@@ -491,7 +495,7 @@ def test_tensor_product():
491
495
  assert m('XX', coefficient=2).tensor_product(m('XI', coefficient=-1)) == -2 * m('XXXI')
492
496
 
493
497
 
494
- def test_commutes():
498
+ def test_commutes() -> None:
495
499
  f = cirq.DensePauliString
496
500
  m = cirq.MutableDensePauliString
497
501
 
@@ -507,7 +511,7 @@ def test_commutes():
507
511
  assert cirq.commutes(f('XX'), "test", default=NotImplemented) is NotImplemented
508
512
 
509
513
 
510
- def test_copy():
514
+ def test_copy() -> None:
511
515
  p = -cirq.DensePauliString('XYZ')
512
516
  m = cirq.MutableDensePauliString('XYZ', coefficient=-1)
513
517
 
@@ -545,7 +549,7 @@ def test_copy():
545
549
  assert cirq.MutableDensePauliString('XYZ').copy(pauli_mask=mask).pauli_mask is mask
546
550
 
547
551
 
548
- def test_gaussian_elimination():
552
+ def test_gaussian_elimination() -> None:
549
553
  def table(*rows: str) -> list[cirq.MutableDensePauliString]:
550
554
  coefs = {'i': 1j, '-': -1, '+': 1}
551
555
  return [
@@ -626,7 +630,7 @@ def test_gaussian_elimination():
626
630
  )
627
631
 
628
632
 
629
- def test_idiv():
633
+ def test_idiv() -> None:
630
634
  p = cirq.MutableDensePauliString('XYZ', coefficient=2)
631
635
  p /= 2
632
636
  assert p == cirq.MutableDensePauliString('XYZ')
@@ -635,7 +639,7 @@ def test_idiv():
635
639
  p /= object()
636
640
 
637
641
 
638
- def test_symbolic():
642
+ def test_symbolic() -> None:
639
643
  t = sympy.Symbol('t')
640
644
  r = sympy.Symbol('r')
641
645
  m = cirq.MutableDensePauliString('XYZ', coefficient=t)
@@ -34,10 +34,6 @@ class CExpZinGate(cirq.EigenGate, cirq.testing.TwoQubitGate):
34
34
  def __init__(self, quarter_turns: value.TParamVal) -> None:
35
35
  super().__init__(exponent=quarter_turns)
36
36
 
37
- @property
38
- def exponent(self):
39
- return self._exponent
40
-
41
37
  def _with_exponent(self, exponent):
42
38
  return CExpZinGate(exponent)
43
39
 
@@ -50,9 +46,6 @@ class CExpZinGate(cirq.EigenGate, cirq.testing.TwoQubitGate):
50
46
 
51
47
 
52
48
  class ZGateDef(cirq.EigenGate, cirq.testing.SingleQubitGate):
53
- @property
54
- def exponent(self):
55
- return self._exponent
56
49
 
57
50
  def _eigen_components(self) -> list[tuple[float, np.ndarray]]:
58
51
  return [(0, np.diag([1, 0])), (1, np.diag([0, 1]))]
cirq/ops/gateset.py CHANGED
@@ -16,7 +16,7 @@
16
16
 
17
17
  from __future__ import annotations
18
18
 
19
- from typing import Any, Callable, cast, Hashable, Sequence, TYPE_CHECKING
19
+ from typing import Any, Callable, cast, Hashable, Iterable, TYPE_CHECKING
20
20
 
21
21
  from cirq import protocols, value
22
22
  from cirq.ops import global_phase_op, op_tree, raw_types
@@ -105,8 +105,8 @@ class GateFamily:
105
105
  name: str | None = None,
106
106
  description: str | None = None,
107
107
  ignore_global_phase: bool = True,
108
- tags_to_accept: Sequence[Hashable] = (),
109
- tags_to_ignore: Sequence[Hashable] = (),
108
+ tags_to_accept: Iterable[Hashable] = (),
109
+ tags_to_ignore: Iterable[Hashable] = (),
110
110
  ) -> None:
111
111
  """Init GateFamily.
112
112
 
cirq/ops/gateset_test.py CHANGED
@@ -56,7 +56,7 @@ q = cirq.NamedQubit("q")
56
56
 
57
57
 
58
58
  @pytest.mark.parametrize('gate', [CustomX, CustomXPowGate])
59
- def test_gate_family_init(gate):
59
+ def test_gate_family_init(gate) -> None:
60
60
  name = 'test_name'
61
61
  description = 'test_description'
62
62
  g = cirq.GateFamily(gate=gate, name=name, description=description)
@@ -75,7 +75,7 @@ def test_gate_family_init(gate):
75
75
  (CustomXPowGate, [], []),
76
76
  ],
77
77
  )
78
- def test_gate_family_default_name_and_description(gate, tags_to_accept, tags_to_ignore):
78
+ def test_gate_family_default_name_and_description(gate, tags_to_accept, tags_to_ignore) -> None:
79
79
  g = cirq.GateFamily(gate, tags_to_accept=tags_to_accept, tags_to_ignore=tags_to_ignore)
80
80
  assert re.match('.*GateFamily.*CustomX.*', g.name)
81
81
  assert re.match('Accepts.*instances.*CustomX.*', g.description)
@@ -97,7 +97,7 @@ def test_gate_family_default_name_and_description(gate, tags_to_accept, tags_to_
97
97
  )
98
98
  def test_gate_family_equality_with_tags(
99
99
  tags_to_accept_fam1, tags_to_ignore_fam1, tags_to_accept_fam2, tags_to_ignore_fam2
100
- ):
100
+ ) -> None:
101
101
  gate_fam1 = cirq.GateFamily(
102
102
  cirq.X, tags_to_accept=tags_to_accept_fam1, tags_to_ignore=tags_to_ignore_fam1
103
103
  )
@@ -108,9 +108,9 @@ def test_gate_family_equality_with_tags(
108
108
  assert gate_fam1 == gate_fam2
109
109
 
110
110
 
111
- def test_invalid_gate_family():
111
+ def test_invalid_gate_family() -> None:
112
112
  with pytest.raises(ValueError, match='instance or subclass of `cirq.Gate`'):
113
- _ = cirq.GateFamily(gate=cirq.Operation)
113
+ _ = cirq.GateFamily(gate=cirq.Operation) # type: ignore[arg-type]
114
114
 
115
115
  with pytest.raises(ValueError, match='non-parameterized instance of `cirq.Gate`'):
116
116
  _ = cirq.GateFamily(gate=CustomX ** sympy.Symbol('theta'))
@@ -119,31 +119,31 @@ def test_invalid_gate_family():
119
119
  _ = cirq.GateFamily(gate=cirq.H, tags_to_accept={'a', 'b'}, tags_to_ignore={'b', 'c'})
120
120
 
121
121
 
122
- def test_gate_family_immutable():
122
+ def test_gate_family_immutable() -> None:
123
123
  g = cirq.GateFamily(CustomX)
124
124
  # Match one of two strings. The second one is message returned since python 3.11.
125
125
  with pytest.raises(
126
126
  AttributeError,
127
127
  match="(can't set attribute)|(property 'gate' of 'GateFamily' object has no setter)",
128
128
  ):
129
- g.gate = CustomXPowGate
129
+ g.gate = CustomXPowGate # type: ignore[misc]
130
130
  with pytest.raises(
131
131
  AttributeError,
132
132
  match="(can't set attribute)|(property 'name' of 'GateFamily' object has no setter)",
133
133
  ):
134
- g.name = 'new name'
134
+ g.name = 'new name' # type: ignore[misc]
135
135
  with pytest.raises(
136
136
  AttributeError,
137
137
  match="(can't set attribute)|(property 'description' of 'GateFamily' object has no setter)",
138
138
  ):
139
- g.description = 'new description'
139
+ g.description = 'new description' # type: ignore[misc]
140
140
 
141
141
 
142
142
  @pytest.mark.parametrize(
143
143
  'gate', [CustomX, CustomXPowGate(exponent=0.5, global_shift=0.1), CustomXPowGate]
144
144
  )
145
145
  @pytest.mark.parametrize('name, description', [(None, None), ('custom_name', 'custom_description')])
146
- def test_gate_family_repr_and_str(gate, name, description):
146
+ def test_gate_family_repr_and_str(gate, name, description) -> None:
147
147
  g = cirq.GateFamily(gate, name=name, description=description)
148
148
  cirq.testing.assert_equivalent_repr(g)
149
149
  assert g.name in str(g)
@@ -152,13 +152,13 @@ def test_gate_family_repr_and_str(gate, name, description):
152
152
 
153
153
  @pytest.mark.parametrize('gate', [cirq.X, cirq.XPowGate(), cirq.XPowGate])
154
154
  @pytest.mark.parametrize('name, description', [(None, None), ('custom_name', 'custom_description')])
155
- def test_gate_family_json(gate, name, description):
155
+ def test_gate_family_json(gate, name, description) -> None:
156
156
  g = cirq.GateFamily(gate, name=name, description=description)
157
157
  g_json = cirq.to_json(g)
158
158
  assert cirq.read_json(json_text=g_json) == g
159
159
 
160
160
 
161
- def test_gate_family_eq():
161
+ def test_gate_family_eq() -> None:
162
162
  eq = cirq.testing.EqualsTester()
163
163
  eq.add_equality_group(cirq.GateFamily(CustomX))
164
164
  eq.add_equality_group(cirq.GateFamily(CustomX**3))
@@ -206,7 +206,7 @@ def test_gate_family_eq():
206
206
  ),
207
207
  ],
208
208
  )
209
- def test_gate_family_predicate_and_containment(gate_family, gates_to_check):
209
+ def test_gate_family_predicate_and_containment(gate_family, gates_to_check) -> None:
210
210
  for gate, result in gates_to_check:
211
211
  assert gate_family._predicate(gate) == result
212
212
  assert (gate in gate_family) == result
@@ -265,7 +265,7 @@ def test_gate_family_predicate_and_containment(gate_family, gates_to_check):
265
265
  ),
266
266
  ],
267
267
  )
268
- def test_gate_family_tagged_operations(gate_family, gates_to_check):
268
+ def test_gate_family_tagged_operations(gate_family, gates_to_check) -> None:
269
269
  for gate, result in gates_to_check:
270
270
  assert (gate in gate_family) == result
271
271
 
@@ -296,7 +296,7 @@ gateset = cirq.Gateset(
296
296
  )
297
297
 
298
298
 
299
- def test_gateset_init():
299
+ def test_gateset_init() -> None:
300
300
  assert gateset.name == 'custom gateset'
301
301
  assert gateset.gates == frozenset(
302
302
  [
@@ -308,7 +308,7 @@ def test_gateset_init():
308
308
 
309
309
 
310
310
  @pytest.mark.parametrize('g', [gateset, cirq.Gateset(name='empty gateset')])
311
- def test_gateset_repr_and_str(g):
311
+ def test_gateset_repr_and_str(g) -> None:
312
312
  cirq.testing.assert_equivalent_repr(g)
313
313
  assert g.name in str(g)
314
314
  for gate_family in g.gates:
@@ -328,7 +328,7 @@ def test_gateset_repr_and_str(g):
328
328
  (cirq.testing.TwoQubitGate(), True),
329
329
  ],
330
330
  )
331
- def test_gateset_contains(gate, result):
331
+ def test_gateset_contains(gate, result) -> None:
332
332
  assert (gate in gateset) is result
333
333
  op = gate(*cirq.LineQubit.range(gate.num_qubits()))
334
334
  assert (op in gateset) is result
@@ -339,7 +339,7 @@ def test_gateset_contains(gate, result):
339
339
 
340
340
 
341
341
  @pytest.mark.parametrize('use_circuit_op', [True, False])
342
- def test_gateset_validate(use_circuit_op):
342
+ def test_gateset_validate(use_circuit_op) -> None:
343
343
  def optree_and_circuit(optree):
344
344
  yield optree
345
345
  yield cirq.Circuit(optree)
@@ -374,14 +374,14 @@ def test_gateset_validate(use_circuit_op):
374
374
  )
375
375
 
376
376
 
377
- def test_gateset_validate_circuit_op_negative_reps():
377
+ def test_gateset_validate_circuit_op_negative_reps() -> None:
378
378
  gate = CustomXPowGate(exponent=0.5)
379
379
  op = cirq.CircuitOperation(cirq.FrozenCircuit(gate.on(cirq.LineQubit(0))), repetitions=-1)
380
380
  assert op not in cirq.Gateset(gate)
381
381
  assert op**-1 in cirq.Gateset(gate)
382
382
 
383
383
 
384
- def test_with_params():
384
+ def test_with_params() -> None:
385
385
  assert gateset.with_params() is gateset
386
386
  assert (
387
387
  gateset.with_params(name=gateset.name, unroll_circuit_op=gateset._unroll_circuit_op)
@@ -392,7 +392,7 @@ def test_with_params():
392
392
  assert gateset_with_params._unroll_circuit_op is False
393
393
 
394
394
 
395
- def test_gateset_eq():
395
+ def test_gateset_eq() -> None:
396
396
  eq = cirq.testing.EqualsTester()
397
397
  eq.add_equality_group(cirq.Gateset(CustomX))
398
398
  eq.add_equality_group(cirq.Gateset(CustomX**3))
@@ -427,7 +427,7 @@ def test_gateset_eq():
427
427
  )
428
428
 
429
429
 
430
- def test_gateset_contains_with_tags():
430
+ def test_gateset_contains_with_tags() -> None:
431
431
  tag = "PhysicalZTag"
432
432
  gf_accept = cirq.GateFamily(cirq.ZPowGate, tags_to_accept=[tag])
433
433
  gf_ignore = cirq.GateFamily(cirq.ZPowGate, tags_to_ignore=[tag])
@@ -447,7 +447,7 @@ def test_gateset_contains_with_tags():
447
447
  assert op_with_tag in cirq.Gateset(gf_accept, gf_ignore)
448
448
 
449
449
 
450
- def test_gateset_contains_op_with_no_gate():
450
+ def test_gateset_contains_op_with_no_gate() -> None:
451
451
  gf = cirq.GateFamily(cirq.ZPowGate)
452
452
  op = cirq.X(cirq.q(1)).with_classical_controls('a')
453
453
  assert op.gate is None
@@ -473,7 +473,7 @@ class PauliSum:
473
473
 
474
474
  @classmethod
475
475
  def from_boolean_expression(
476
- cls, boolean_expr: sympy.Expr, qubit_map: dict[str, cirq.Qid]
476
+ cls, boolean_expr: sympy.Expr, qubit_map: Mapping[str, cirq.Qid]
477
477
  ) -> PauliSum:
478
478
  """Builds the Hamiltonian representation of a Boolean expression.
479
479