cirq-core 1.7.0.dev20250911180440__py3-none-any.whl → 1.7.0.dev20250917002151__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 (65) hide show
  1. cirq/_version.py +1 -1
  2. cirq/_version_test.py +1 -1
  3. cirq/circuits/circuit_operation_test.py +5 -0
  4. cirq/ops/classically_controlled_operation.py +3 -7
  5. cirq/ops/gate_operation.py +15 -0
  6. cirq/ops/linear_combinations.py +4 -14
  7. cirq/ops/measure_util.py +7 -6
  8. cirq/ops/pauli_string_test.py +7 -6
  9. cirq/ops/raw_types.py +19 -2
  10. cirq/protocols/has_stabilizer_effect_protocol_test.py +11 -9
  11. cirq/protocols/has_unitary_protocol_test.py +3 -3
  12. cirq/protocols/json_serialization.py +3 -3
  13. cirq/protocols/json_serialization_test.py +31 -31
  14. cirq/protocols/kraus_protocol_test.py +5 -5
  15. cirq/protocols/measurement_key_protocol.py +31 -8
  16. cirq/protocols/mixture_protocol.py +1 -1
  17. cirq/protocols/mixture_protocol_test.py +7 -7
  18. cirq/protocols/mul_protocol_test.py +4 -4
  19. cirq/protocols/phase_protocol.py +13 -4
  20. cirq/protocols/pow_protocol_test.py +5 -5
  21. cirq/protocols/resolve_parameters.py +1 -1
  22. cirq/protocols/unitary_protocol_test.py +31 -19
  23. cirq/qis/clifford_tableau.py +14 -14
  24. cirq/qis/clifford_tableau_test.py +17 -17
  25. cirq/qis/entropy.py +1 -1
  26. cirq/qis/entropy_test.py +1 -1
  27. cirq/qis/states_test.py +54 -54
  28. cirq/sim/classical_simulator_test.py +56 -28
  29. cirq/sim/clifford/clifford_simulator.py +5 -5
  30. cirq/sim/clifford/clifford_simulator_test.py +50 -49
  31. cirq/sim/clifford/stabilizer_state_ch_form.py +9 -9
  32. cirq/sim/density_matrix_simulation_state.py +6 -6
  33. cirq/sim/density_matrix_simulator.py +1 -1
  34. cirq/sim/density_matrix_simulator_test.py +94 -84
  35. cirq/sim/density_matrix_utils_test.py +1 -1
  36. cirq/sim/mux_test.py +26 -26
  37. cirq/sim/simulation_product_state_test.py +7 -7
  38. cirq/sim/simulation_state.py +4 -4
  39. cirq/sim/simulation_state_base.py +1 -1
  40. cirq/sim/simulation_state_test.py +5 -5
  41. cirq/sim/simulator.py +2 -2
  42. cirq/sim/simulator_base_test.py +49 -35
  43. cirq/sim/simulator_test.py +39 -35
  44. cirq/sim/sparse_simulator.py +1 -1
  45. cirq/sim/sparse_simulator_test.py +92 -82
  46. cirq/sim/state_vector.py +1 -1
  47. cirq/sim/state_vector_simulation_state.py +7 -7
  48. cirq/sim/state_vector_simulator_test.py +9 -9
  49. cirq/sim/state_vector_test.py +37 -37
  50. cirq/study/result_test.py +20 -20
  51. cirq/study/sweepable_test.py +20 -20
  52. cirq/study/sweeps_test.py +43 -43
  53. cirq/testing/circuit_compare_test.py +16 -14
  54. cirq/testing/consistent_channels.py +2 -2
  55. cirq/testing/consistent_controlled_gate_op.py +1 -1
  56. cirq/testing/consistent_decomposition.py +4 -2
  57. cirq/testing/consistent_phase_by.py +1 -1
  58. cirq/testing/consistent_qasm.py +2 -2
  59. cirq/testing/consistent_qasm_test.py +3 -3
  60. cirq/transformers/eject_z.py +1 -0
  61. {cirq_core-1.7.0.dev20250911180440.dist-info → cirq_core-1.7.0.dev20250917002151.dist-info}/METADATA +1 -1
  62. {cirq_core-1.7.0.dev20250911180440.dist-info → cirq_core-1.7.0.dev20250917002151.dist-info}/RECORD +65 -65
  63. {cirq_core-1.7.0.dev20250911180440.dist-info → cirq_core-1.7.0.dev20250917002151.dist-info}/WHEEL +0 -0
  64. {cirq_core-1.7.0.dev20250911180440.dist-info → cirq_core-1.7.0.dev20250917002151.dist-info}/licenses/LICENSE +0 -0
  65. {cirq_core-1.7.0.dev20250911180440.dist-info → cirq_core-1.7.0.dev20250917002151.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.7.0.dev20250911180440"
31
+ __version__ = "1.7.0.dev20250917002151"
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.7.0.dev20250911180440"
6
+ assert cirq.__version__ == "1.7.0.dev20250917002151"
@@ -1253,22 +1253,27 @@ def test_repeat_until_protocols() -> None:
1253
1253
  # Ensure the _repeat_until has been mapped, the measurement has been mapped to the same key,
1254
1254
  # and the control keys of the subcircuit is empty (because the control key of the condition is
1255
1255
  # bound to the measurement).
1256
+ assert scoped._mapped_repeat_until is not None
1256
1257
  assert scoped._mapped_repeat_until.keys == (cirq.MeasurementKey('a', ('0',)),)
1257
1258
  assert cirq.measurement_key_objs(scoped) == {cirq.MeasurementKey('a', ('0',))}
1258
1259
  assert not cirq.control_keys(scoped)
1259
1260
  mapped = cirq.with_measurement_key_mapping(scoped, {'a': 'b'})
1261
+ assert mapped._mapped_repeat_until is not None
1260
1262
  assert mapped._mapped_repeat_until.keys == (cirq.MeasurementKey('b', ('0',)),)
1261
1263
  assert cirq.measurement_key_objs(mapped) == {cirq.MeasurementKey('b', ('0',))}
1262
1264
  assert not cirq.control_keys(mapped)
1263
1265
  prefixed = cirq.with_key_path_prefix(mapped, ('1',))
1266
+ assert prefixed._mapped_repeat_until is not None
1264
1267
  assert prefixed._mapped_repeat_until.keys == (cirq.MeasurementKey('b', ('1', '0')),)
1265
1268
  assert cirq.measurement_key_objs(prefixed) == {cirq.MeasurementKey('b', ('1', '0'))}
1266
1269
  assert not cirq.control_keys(prefixed)
1267
1270
  setpath = cirq.with_key_path(prefixed, ('2',))
1271
+ assert setpath._mapped_repeat_until is not None
1268
1272
  assert setpath._mapped_repeat_until.keys == (cirq.MeasurementKey('b', ('2',)),)
1269
1273
  assert cirq.measurement_key_objs(setpath) == {cirq.MeasurementKey('b', ('2',))}
1270
1274
  assert not cirq.control_keys(setpath)
1271
1275
  resolved = cirq.resolve_parameters(setpath, {'p': 1})
1276
+ assert resolved._mapped_repeat_until is not None
1272
1277
  assert resolved._mapped_repeat_until.keys == (cirq.MeasurementKey('b', ('2',)),)
1273
1278
  assert cirq.measurement_key_objs(resolved) == {cirq.MeasurementKey('b', ('2',))}
1274
1279
  assert not cirq.control_keys(resolved)
@@ -14,7 +14,7 @@
14
14
 
15
15
  from __future__ import annotations
16
16
 
17
- from typing import AbstractSet, Any, cast, Mapping, Sequence, TYPE_CHECKING
17
+ from typing import AbstractSet, Any, Mapping, Sequence, TYPE_CHECKING
18
18
 
19
19
  import sympy
20
20
 
@@ -207,17 +207,13 @@ class ClassicallyControlledOperation(raw_types.Operation):
207
207
  conditions = [protocols.with_measurement_key_mapping(c, key_map) for c in self._conditions]
208
208
  sub_operation = protocols.with_measurement_key_mapping(self._sub_operation, key_map)
209
209
  sub_operation = self._sub_operation if sub_operation is NotImplemented else sub_operation
210
- return cast(
211
- ClassicallyControlledOperation, sub_operation.with_classical_controls(*conditions)
212
- )
210
+ return sub_operation.with_classical_controls(*conditions)
213
211
 
214
212
  def _with_key_path_prefix_(self, prefix: tuple[str, ...]) -> ClassicallyControlledOperation:
215
213
  conditions = [protocols.with_key_path_prefix(c, prefix) for c in self._conditions]
216
214
  sub_operation = protocols.with_key_path_prefix(self._sub_operation, prefix)
217
215
  sub_operation = self._sub_operation if sub_operation is NotImplemented else sub_operation
218
- return cast(
219
- ClassicallyControlledOperation, sub_operation.with_classical_controls(*conditions)
220
- )
216
+ return sub_operation.with_classical_controls(*conditions)
221
217
 
222
218
  def _with_rescoped_keys_(
223
219
  self, path: tuple[str, ...], bindable_keys: frozenset[cirq.MeasurementKey]
@@ -331,6 +331,21 @@ class GateOperation(raw_types.Operation):
331
331
  def __rmul__(self, other: Any) -> Any:
332
332
  return self.gate._rmul_with_qubits(self._qubits, other)
333
333
 
334
+ def __add__(self, other):
335
+ return 1 * self + other
336
+
337
+ def __radd__(self, other):
338
+ return other + 1 * self
339
+
340
+ def __sub__(self, other):
341
+ return 1 * self - other
342
+
343
+ def __rsub__(self, other):
344
+ return other + -self
345
+
346
+ def __neg__(self):
347
+ return -1 * self
348
+
334
349
  def _qasm_(self, args: protocols.QasmArgs) -> str | None:
335
350
  if isinstance(self.gate, ops.GlobalPhaseGate):
336
351
  warnings.warn(
@@ -746,10 +746,6 @@ class PauliSum:
746
746
  other = PauliSum.from_pauli_strings([PauliString(coefficient=other)])
747
747
  elif isinstance(other, PauliString):
748
748
  other = PauliSum.from_pauli_strings([other])
749
- elif isinstance(other, raw_types.Operation) and isinstance(
750
- other.gate, identity.IdentityGate
751
- ):
752
- other = PauliSum.from_pauli_strings([PauliString()])
753
749
 
754
750
  if not isinstance(other, PauliSum):
755
751
  return NotImplemented
@@ -758,10 +754,9 @@ class PauliSum:
758
754
  return self
759
755
 
760
756
  def __add__(self, other):
761
- if not isinstance(other, (numbers.Complex, PauliString, PauliSum, raw_types.Operation)):
762
- return NotImplemented
763
757
  result = self.copy()
764
- result += other
758
+ if result.__iadd__(other) is NotImplemented:
759
+ return NotImplemented
765
760
  return result
766
761
 
767
762
  def __radd__(self, other):
@@ -775,10 +770,6 @@ class PauliSum:
775
770
  other = PauliSum.from_pauli_strings([PauliString(coefficient=other)])
776
771
  elif isinstance(other, PauliString):
777
772
  other = PauliSum.from_pauli_strings([other])
778
- elif isinstance(other, raw_types.Operation) and isinstance(
779
- other.gate, identity.IdentityGate
780
- ):
781
- other = PauliSum.from_pauli_strings([PauliString()])
782
773
 
783
774
  if not isinstance(other, PauliSum):
784
775
  return NotImplemented
@@ -787,10 +778,9 @@ class PauliSum:
787
778
  return self
788
779
 
789
780
  def __sub__(self, other):
790
- if not isinstance(other, (numbers.Complex, PauliString, PauliSum, raw_types.Operation)):
791
- return NotImplemented
792
781
  result = self.copy()
793
- result -= other
782
+ if result.__isub__(other) is NotImplemented:
783
+ return NotImplemented
794
784
  return result
795
785
 
796
786
  def __neg__(self):
cirq/ops/measure_util.py CHANGED
@@ -14,12 +14,12 @@
14
14
 
15
15
  from __future__ import annotations
16
16
 
17
- from typing import Callable, Iterable, overload, TYPE_CHECKING
17
+ from typing import Callable, cast, Iterable, overload, TYPE_CHECKING
18
18
 
19
19
  import numpy as np
20
20
 
21
21
  from cirq import protocols
22
- from cirq.ops import pauli_string, raw_types
22
+ from cirq.ops import gate_operation, pauli_string, raw_types
23
23
  from cirq.ops.measurement_gate import MeasurementGate
24
24
  from cirq.ops.pauli_measurement_gate import PauliMeasurementGate
25
25
 
@@ -96,7 +96,7 @@ def measure(
96
96
  key: str | cirq.MeasurementKey | None = None,
97
97
  invert_mask: tuple[bool, ...] = (),
98
98
  confusion_map: dict[tuple[int, ...], np.ndarray] | None = None,
99
- ) -> raw_types.Operation:
99
+ ) -> gate_operation.GateOperation:
100
100
  pass
101
101
 
102
102
 
@@ -107,7 +107,7 @@ def measure(
107
107
  key: str | cirq.MeasurementKey | None = None,
108
108
  invert_mask: tuple[bool, ...] = (),
109
109
  confusion_map: dict[tuple[int, ...], np.ndarray] | None = None,
110
- ) -> raw_types.Operation:
110
+ ) -> gate_operation.GateOperation:
111
111
  pass
112
112
 
113
113
 
@@ -116,7 +116,7 @@ def measure(
116
116
  key: str | cirq.MeasurementKey | None = None,
117
117
  invert_mask: tuple[bool, ...] = (),
118
118
  confusion_map: dict[tuple[int, ...], np.ndarray] | None = None,
119
- ) -> raw_types.Operation:
119
+ ) -> gate_operation.GateOperation:
120
120
  """Returns a single MeasurementGate applied to all the given qubits.
121
121
 
122
122
  The qubits are measured in the computational basis. This can also be
@@ -161,7 +161,8 @@ def measure(
161
161
  if key is None:
162
162
  key = _default_measurement_key(targets)
163
163
  qid_shape = protocols.qid_shape(targets)
164
- return MeasurementGate(len(targets), key, invert_mask, qid_shape, confusion_map).on(*targets)
164
+ gate = MeasurementGate(len(targets), key, invert_mask, qid_shape, confusion_map)
165
+ return cast(gate_operation.GateOperation, gate.on(*targets))
165
166
 
166
167
 
167
168
  M = measure
@@ -2086,12 +2086,13 @@ def test_resolve(resolve_fn) -> None:
2086
2086
  ids=str,
2087
2087
  )
2088
2088
  def test_pauli_ops_identity_gate_operation(gate1: cirq.Pauli, gate2: cirq.Pauli) -> None:
2089
- # TODO: Issue #7280 - Support addition and subtraction of identity gate operations.
2090
- if gate1 == gate2 == cirq.I:
2091
- pytest.skip('Not yet implemented per #7280')
2092
2089
  q = cirq.LineQubit(0)
2093
2090
  pauli1, pauli2 = gate1.on(q), gate2.on(q)
2094
- unitary1, unitary2 = cirq.unitary(gate1), cirq.unitary(gate2)
2091
+ if gate1 == gate2 == cirq.I:
2092
+ # PauliSum swallows I qubits, so resulting unitaries are dimensionless
2093
+ unitary1 = unitary2 = np.array([[1]])
2094
+ else:
2095
+ unitary1, unitary2 = cirq.unitary(gate1), cirq.unitary(gate2)
2095
2096
  addition = pauli1 + pauli2
2096
2097
  assert isinstance(addition, cirq.PauliSum)
2097
2098
  assert np.array_equal(addition.matrix(), unitary1 + unitary2)
@@ -2100,7 +2101,7 @@ def test_pauli_ops_identity_gate_operation(gate1: cirq.Pauli, gate2: cirq.Pauli)
2100
2101
  assert np.array_equal(subtraction.matrix(), unitary1 - unitary2)
2101
2102
 
2102
2103
 
2103
- def test_pauli_gate_multiplication_with_power():
2104
+ def test_pauli_gate_multiplication_with_power() -> None:
2104
2105
  q = cirq.LineQubit(0)
2105
2106
 
2106
2107
  # Test all Pauli gates (X, Y, Z)
@@ -2123,7 +2124,7 @@ def test_pauli_gate_multiplication_with_power():
2123
2124
  assert gate**5 * gate**0 == gate**5
2124
2125
 
2125
2126
 
2126
- def test_try_interpret_as_pauli_string():
2127
+ def test_try_interpret_as_pauli_string() -> None:
2127
2128
  from cirq.ops.pauli_string import _try_interpret_as_pauli_string
2128
2129
 
2129
2130
  q = cirq.LineQubit(0)
cirq/ops/raw_types.py CHANGED
@@ -28,6 +28,7 @@ from typing import (
28
28
  Hashable,
29
29
  Iterable,
30
30
  Mapping,
31
+ overload,
31
32
  Sequence,
32
33
  TYPE_CHECKING,
33
34
  )
@@ -687,9 +688,17 @@ class Operation(metaclass=abc.ABCMeta):
687
688
  """The classical controls gating this operation."""
688
689
  return frozenset()
689
690
 
691
+ @overload
692
+ def with_classical_controls(self) -> cirq.Operation:
693
+ pass
694
+
695
+ @overload
690
696
  def with_classical_controls(
691
697
  self, *conditions: str | cirq.MeasurementKey | cirq.Condition | sympy.Expr
692
- ) -> cirq.Operation:
698
+ ) -> cirq.ClassicallyControlledOperation:
699
+ pass
700
+
701
+ def with_classical_controls(self, *conditions):
693
702
  """Returns a classically controlled version of this operation.
694
703
 
695
704
  An operation that is classically controlled is executed iff all
@@ -957,9 +966,17 @@ class TaggedOperation(Operation):
957
966
  new_sub_operation = self.sub_operation.without_classical_controls()
958
967
  return self if new_sub_operation is self.sub_operation else new_sub_operation
959
968
 
969
+ @overload
970
+ def with_classical_controls(self) -> cirq.Operation:
971
+ pass
972
+
973
+ @overload
960
974
  def with_classical_controls(
961
975
  self, *conditions: str | cirq.MeasurementKey | cirq.Condition | sympy.Expr
962
- ) -> cirq.Operation:
976
+ ) -> cirq.ClassicallyControlledOperation:
977
+ pass
978
+
979
+ def with_classical_controls(self, *conditions):
963
980
  if not conditions:
964
981
  return self
965
982
  return self.sub_operation.with_classical_controls(*conditions)
@@ -14,6 +14,8 @@
14
14
 
15
15
  from __future__ import annotations
16
16
 
17
+ from typing import Any
18
+
17
19
  import numpy as np
18
20
 
19
21
  import cirq
@@ -50,40 +52,40 @@ class EmptyOp(cirq.Operation):
50
52
  self.q = q
51
53
 
52
54
  @property
53
- def qubits(self):
55
+ def qubits(self) -> tuple[cirq.Qid, ...]:
54
56
  return (self.q,)
55
57
 
56
- def with_qubits(self, *new_qubits): # pragma: no cover
58
+ def with_qubits(self, *new_qubits) -> cirq.Operation: # pragma: no cover
57
59
  return self
58
60
 
59
61
 
60
62
  class NoOp(EmptyOp):
61
63
  @property
62
- def gate(self):
64
+ def gate(self) -> Any:
63
65
  return No()
64
66
 
65
67
 
66
68
  class NoOp1(EmptyOp):
67
69
  @property
68
- def gate(self):
70
+ def gate(self) -> Any:
69
71
  return No1()
70
72
 
71
73
 
72
74
  class NoOp2(EmptyOp):
73
75
  @property
74
- def gate(self):
76
+ def gate(self) -> Any:
75
77
  return No2()
76
78
 
77
79
 
78
80
  class NoOp3(EmptyOp):
79
81
  @property
80
- def gate(self):
82
+ def gate(self) -> Any:
81
83
  return No3()
82
84
 
83
85
 
84
86
  class YesOp(EmptyOp):
85
87
  @property
86
- def gate(self):
88
+ def gate(self) -> Any:
87
89
  return Yes()
88
90
 
89
91
 
@@ -95,8 +97,8 @@ class OpWithUnitary(EmptyOp):
95
97
  return self.unitary
96
98
 
97
99
  @property
98
- def qubits(self):
99
- return cirq.LineQubit.range(self.unitary.shape[0].bit_length() - 1)
100
+ def qubits(self) -> tuple[cirq.Qid, ...]:
101
+ return tuple(cirq.LineQubit.range(self.unitary.shape[0].bit_length() - 1))
100
102
 
101
103
 
102
104
  class GateDecomposes(cirq.Gate):
@@ -218,8 +218,8 @@ class EmptyOp(cirq.Operation):
218
218
  """A trivial operation that will be recognized as `_apply_unitary_`-able."""
219
219
 
220
220
  @property
221
- def qubits(self):
221
+ def qubits(self) -> tuple[cirq.Qid, ...]:
222
222
  return ()
223
223
 
224
- def with_qubits(self, *new_qubits): # pragma: no cover
225
- return self
224
+ def with_qubits(self, *new_qubits) -> cirq.Operation:
225
+ raise NotImplementedError()
@@ -217,7 +217,7 @@ class CirqEncoder(json.JSONEncoder):
217
217
  super().__init__(*args, **kwargs)
218
218
  self._memo: dict[Any, dict] = {}
219
219
 
220
- def default(self, o):
220
+ def default(self, o) -> dict[str, Any] | list[Any] | float | bool:
221
221
  # Object with custom method?
222
222
  if hasattr(o, '_json_dict_'):
223
223
  json_dict = _json_dict_with_cirq_type(o)
@@ -519,7 +519,7 @@ def read_json(
519
519
  *,
520
520
  json_text: str | None = None,
521
521
  resolvers: Sequence[JsonResolver] | None = None,
522
- ):
522
+ ) -> Any:
523
523
  """Read a JSON file that optionally contains cirq objects.
524
524
 
525
525
  Args:
@@ -605,7 +605,7 @@ def read_json_gzip(
605
605
  *,
606
606
  gzip_raw: bytes | None = None,
607
607
  resolvers: Sequence[JsonResolver] | None = None,
608
- ):
608
+ ) -> Any:
609
609
  """Read a gzipped JSON file that optionally contains cirq objects.
610
610
 
611
611
  Args:
@@ -72,7 +72,7 @@ def _get_testspecs_for_modules() -> list[ModuleJsonTestSpec]:
72
72
  MODULE_TEST_SPECS = _get_testspecs_for_modules()
73
73
 
74
74
 
75
- def test_deprecated_cirq_type_in_json_dict():
75
+ def test_deprecated_cirq_type_in_json_dict() -> None:
76
76
  class HasOldJsonDict:
77
77
  # Required for testing serialization of non-cirq objects.
78
78
  __module__ = 'test.noncirq.namespace'
@@ -99,7 +99,7 @@ def test_deprecated_cirq_type_in_json_dict():
99
99
  assert_json_roundtrip_works(HasOldJsonDict(), resolvers=test_resolvers)
100
100
 
101
101
 
102
- def test_line_qubit_roundtrip():
102
+ def test_line_qubit_roundtrip() -> None:
103
103
  q1 = cirq.LineQubit(12)
104
104
  assert_json_roundtrip_works(
105
105
  q1,
@@ -110,7 +110,7 @@ def test_line_qubit_roundtrip():
110
110
  )
111
111
 
112
112
 
113
- def test_gridqubit_roundtrip():
113
+ def test_gridqubit_roundtrip() -> None:
114
114
  q = cirq.GridQubit(15, 18)
115
115
  assert_json_roundtrip_works(
116
116
  q,
@@ -122,7 +122,7 @@ def test_gridqubit_roundtrip():
122
122
  )
123
123
 
124
124
 
125
- def test_op_roundtrip():
125
+ def test_op_roundtrip() -> None:
126
126
  q = cirq.LineQubit(5)
127
127
  op1 = cirq.rx(0.123).on(q)
128
128
  assert_json_roundtrip_works(
@@ -143,7 +143,7 @@ def test_op_roundtrip():
143
143
  )
144
144
 
145
145
 
146
- def test_op_roundtrip_filename(tmpdir):
146
+ def test_op_roundtrip_filename(tmpdir) -> None:
147
147
  filename = f'{tmpdir}/op.json'
148
148
  q = cirq.LineQubit(5)
149
149
  op1 = cirq.rx(0.123).on(q)
@@ -159,7 +159,7 @@ def test_op_roundtrip_filename(tmpdir):
159
159
  assert op1 == op3
160
160
 
161
161
 
162
- def test_op_roundtrip_file_obj(tmpdir):
162
+ def test_op_roundtrip_file_obj(tmpdir) -> None:
163
163
  filename = f'{tmpdir}/op.json'
164
164
  q = cirq.LineQubit(5)
165
165
  op1 = cirq.rx(0.123).on(q)
@@ -179,7 +179,7 @@ def test_op_roundtrip_file_obj(tmpdir):
179
179
  assert op1 == op3
180
180
 
181
181
 
182
- def test_fail_to_resolve():
182
+ def test_fail_to_resolve() -> None:
183
183
  buffer = io.StringIO()
184
184
  buffer.write(
185
185
  """
@@ -207,7 +207,7 @@ Q0, Q1, Q2, Q3, Q4 = QUBITS
207
207
  # deprecation error in testing. It is cleaner to just turn it off than to assert
208
208
  # deprecation for each submodule.
209
209
  @mock.patch.dict(os.environ, clear='CIRQ_TESTING')
210
- def test_shouldnt_be_serialized_no_superfluous(mod_spec: ModuleJsonTestSpec):
210
+ def test_shouldnt_be_serialized_no_superfluous(mod_spec: ModuleJsonTestSpec) -> None:
211
211
  # everything in the list should be ignored for a reason
212
212
  names = set(mod_spec.get_all_names())
213
213
  missing_names = set(mod_spec.should_not_be_serialized).difference(names)
@@ -223,7 +223,7 @@ def test_shouldnt_be_serialized_no_superfluous(mod_spec: ModuleJsonTestSpec):
223
223
  # deprecation error in testing. It is cleaner to just turn it off than to assert
224
224
  # deprecation for each submodule.
225
225
  @mock.patch.dict(os.environ, clear='CIRQ_TESTING')
226
- def test_not_yet_serializable_no_superfluous(mod_spec: ModuleJsonTestSpec):
226
+ def test_not_yet_serializable_no_superfluous(mod_spec: ModuleJsonTestSpec) -> None:
227
227
  # everything in the list should be ignored for a reason
228
228
  names = set(mod_spec.get_all_names())
229
229
  missing_names = set(mod_spec.not_yet_serializable).difference(names)
@@ -233,7 +233,7 @@ def test_not_yet_serializable_no_superfluous(mod_spec: ModuleJsonTestSpec):
233
233
 
234
234
 
235
235
  @pytest.mark.parametrize('mod_spec', MODULE_TEST_SPECS, ids=repr)
236
- def test_mutually_exclusive_not_serialize_lists(mod_spec: ModuleJsonTestSpec):
236
+ def test_mutually_exclusive_not_serialize_lists(mod_spec: ModuleJsonTestSpec) -> None:
237
237
  common = set(mod_spec.should_not_be_serialized) & set(mod_spec.not_yet_serializable)
238
238
  assert len(common) == 0, (
239
239
  f"Defined in both {mod_spec.name} 'Not yet serializable' "
@@ -242,7 +242,7 @@ def test_mutually_exclusive_not_serialize_lists(mod_spec: ModuleJsonTestSpec):
242
242
 
243
243
 
244
244
  @pytest.mark.parametrize('mod_spec', MODULE_TEST_SPECS, ids=repr)
245
- def test_resolver_cache_vs_should_not_serialize(mod_spec: ModuleJsonTestSpec):
245
+ def test_resolver_cache_vs_should_not_serialize(mod_spec: ModuleJsonTestSpec) -> None:
246
246
  resolver_cache_types = set([n for (n, _) in mod_spec.get_resolver_cache_types()])
247
247
  common = set(mod_spec.should_not_be_serialized) & resolver_cache_types
248
248
 
@@ -254,7 +254,7 @@ def test_resolver_cache_vs_should_not_serialize(mod_spec: ModuleJsonTestSpec):
254
254
 
255
255
 
256
256
  @pytest.mark.parametrize('mod_spec', MODULE_TEST_SPECS, ids=repr)
257
- def test_resolver_cache_vs_not_yet_serializable(mod_spec: ModuleJsonTestSpec):
257
+ def test_resolver_cache_vs_not_yet_serializable(mod_spec: ModuleJsonTestSpec) -> None:
258
258
  resolver_cache_types = set([n for (n, _) in mod_spec.get_resolver_cache_types()])
259
259
  common = set(mod_spec.not_yet_serializable) & resolver_cache_types
260
260
 
@@ -267,14 +267,14 @@ def test_resolver_cache_vs_not_yet_serializable(mod_spec: ModuleJsonTestSpec):
267
267
  )
268
268
 
269
269
 
270
- def test_builtins():
270
+ def test_builtins() -> None:
271
271
  assert_json_roundtrip_works(True)
272
272
  assert_json_roundtrip_works(1)
273
273
  assert_json_roundtrip_works(1 + 2j)
274
274
  assert_json_roundtrip_works({'test': [123, 5.5], 'key2': 'asdf', '3': None, '0.0': []})
275
275
 
276
276
 
277
- def test_numpy():
277
+ def test_numpy() -> None:
278
278
  x = np.ones(1)[0]
279
279
 
280
280
  assert_json_roundtrip_works(np.bool_(True))
@@ -295,7 +295,7 @@ def test_numpy():
295
295
  assert_json_roundtrip_works(np.arange(3))
296
296
 
297
297
 
298
- def test_pandas():
298
+ def test_pandas() -> None:
299
299
  assert_json_roundtrip_works(
300
300
  pd.DataFrame(data=[[1, 2, 3], [4, 5, 6]], columns=['x', 'y', 'z'], index=[2, 5])
301
301
  )
@@ -320,7 +320,7 @@ def test_pandas():
320
320
  )
321
321
 
322
322
 
323
- def test_sympy():
323
+ def test_sympy() -> None:
324
324
  # Raw values.
325
325
  assert_json_roundtrip_works(sympy.Symbol('theta'))
326
326
  assert_json_roundtrip_works(sympy.Integer(5))
@@ -388,7 +388,7 @@ class SBKImpl(cirq.SerializableByKey):
388
388
  return cls(name, data_list, tuple(data_tuple), data_dict)
389
389
 
390
390
 
391
- def test_serializable_by_key():
391
+ def test_serializable_by_key() -> None:
392
392
  def custom_resolver(name):
393
393
  if name == 'SBKImpl':
394
394
  return SBKImpl
@@ -443,12 +443,12 @@ def _list_public_classes_for_tested_modules():
443
443
 
444
444
 
445
445
  @pytest.mark.parametrize('mod_spec,cirq_obj_name,cls', _list_public_classes_for_tested_modules())
446
- def test_json_test_data_coverage(mod_spec: ModuleJsonTestSpec, cirq_obj_name: str, cls):
446
+ def test_json_test_data_coverage(mod_spec: ModuleJsonTestSpec, cirq_obj_name: str, cls) -> None:
447
447
  if cirq_obj_name in mod_spec.tested_elsewhere:
448
448
  pytest.skip("Tested elsewhere.")
449
449
 
450
450
  if cirq_obj_name in mod_spec.not_yet_serializable:
451
- return pytest.xfail(reason="Not serializable (yet)")
451
+ pytest.xfail(reason="Not serializable (yet)")
452
452
 
453
453
  test_data_path = mod_spec.test_data_path
454
454
  rel_path = test_data_path.relative_to(REPO_ROOT)
@@ -529,12 +529,12 @@ class SerializableTypeObject:
529
529
 
530
530
 
531
531
  @pytest.mark.parametrize('mod_spec,cirq_obj_name,cls', _list_public_classes_for_tested_modules())
532
- def test_type_serialization(mod_spec: ModuleJsonTestSpec, cirq_obj_name: str, cls):
532
+ def test_type_serialization(mod_spec: ModuleJsonTestSpec, cirq_obj_name: str, cls) -> None:
533
533
  if cirq_obj_name in mod_spec.tested_elsewhere:
534
534
  pytest.skip("Tested elsewhere.")
535
535
 
536
536
  if cirq_obj_name in mod_spec.not_yet_serializable:
537
- return pytest.xfail(reason="Not serializable (yet)")
537
+ pytest.xfail(reason="Not serializable (yet)")
538
538
 
539
539
  if cls is None:
540
540
  pytest.skip(f'No serialization for None-mapped type: {cirq_obj_name}') # pragma: no cover
@@ -556,7 +556,7 @@ def test_type_serialization(mod_spec: ModuleJsonTestSpec, cirq_obj_name: str, cl
556
556
  assert_json_roundtrip_works(sto, resolvers=test_resolvers)
557
557
 
558
558
 
559
- def test_invalid_type_deserialize():
559
+ def test_invalid_type_deserialize() -> None:
560
560
  def custom_resolver(name):
561
561
  if name == 'SerializableTypeObject':
562
562
  return SerializableTypeObject
@@ -571,7 +571,7 @@ def test_invalid_type_deserialize():
571
571
  _ = cirq.read_json(json_text=factory_json, resolvers=test_resolvers)
572
572
 
573
573
 
574
- def test_to_from_strings():
574
+ def test_to_from_strings() -> None:
575
575
  x_json_text = """{
576
576
  "cirq_type": "_PauliX",
577
577
  "exponent": 1.0,
@@ -584,7 +584,7 @@ def test_to_from_strings():
584
584
  cirq.read_json(io.StringIO(), json_text=x_json_text)
585
585
 
586
586
 
587
- def test_to_from_json_gzip():
587
+ def test_to_from_json_gzip() -> None:
588
588
  a, b = cirq.LineQubit.range(2)
589
589
  test_circuit = cirq.Circuit(cirq.H(a), cirq.CX(a, b))
590
590
  gzip_data = cirq.to_json_gzip(test_circuit)
@@ -631,7 +631,7 @@ def assert_repr_and_json_test_data_agree(
631
631
  json_path: pathlib.Path,
632
632
  inward_only: bool,
633
633
  deprecation_deadline: str | None,
634
- ):
634
+ ) -> None:
635
635
  if not repr_path.exists() and not json_path.exists():
636
636
  return
637
637
 
@@ -701,7 +701,7 @@ def assert_repr_and_json_test_data_agree(
701
701
  'mod_spec, abs_path',
702
702
  [(m, abs_path) for m in MODULE_TEST_SPECS for abs_path in m.all_test_data_keys()],
703
703
  )
704
- def test_json_and_repr_data(mod_spec: ModuleJsonTestSpec, abs_path: str):
704
+ def test_json_and_repr_data(mod_spec: ModuleJsonTestSpec, abs_path: str) -> None:
705
705
  assert_repr_and_json_test_data_agree(
706
706
  mod_spec=mod_spec,
707
707
  repr_path=pathlib.Path(f'{abs_path}.repr'),
@@ -718,7 +718,7 @@ def test_json_and_repr_data(mod_spec: ModuleJsonTestSpec, abs_path: str):
718
718
  )
719
719
 
720
720
 
721
- def test_pathlib_paths(tmpdir):
721
+ def test_pathlib_paths(tmpdir) -> None:
722
722
  path = pathlib.Path(tmpdir) / 'op.json'
723
723
  cirq.to_json(cirq.X, path)
724
724
  assert cirq.read_json(path) == cirq.X
@@ -746,7 +746,7 @@ def test_dataclass_json_dict() -> None:
746
746
  assert_json_roundtrip_works(my_dc, resolvers=[custom_resolver, *cirq.DEFAULT_RESOLVERS])
747
747
 
748
748
 
749
- def test_numpy_values():
749
+ def test_numpy_values() -> None:
750
750
  assert (
751
751
  cirq.to_json({'value': np.array(1)})
752
752
  == """{
@@ -755,7 +755,7 @@ def test_numpy_values():
755
755
  )
756
756
 
757
757
 
758
- def test_basic_time_assertions():
758
+ def test_basic_time_assertions() -> None:
759
759
  naive_dt = datetime.datetime.now()
760
760
  utc_dt = naive_dt.astimezone(datetime.timezone.utc)
761
761
  assert naive_dt.timestamp() == utc_dt.timestamp()
@@ -768,7 +768,7 @@ def test_basic_time_assertions():
768
768
  assert naive_dt == re_naive, 'works, as long as you called fromtimestamp from the same timezone'
769
769
 
770
770
 
771
- def test_datetime():
771
+ def test_datetime() -> None:
772
772
  naive_dt = datetime.datetime.now()
773
773
 
774
774
  re_naive_dt = cirq.read_json(json_text=cirq.to_json(naive_dt))
@@ -793,7 +793,7 @@ class _TestAttrsClas:
793
793
  x: int
794
794
 
795
795
 
796
- def test_attrs_json_dict():
796
+ def test_attrs_json_dict() -> None:
797
797
  obj = _TestAttrsClas('test', x=123)
798
798
  js = json_serialization.attrs_json_dict(obj)
799
799
  assert js == {'name': 'test', 'x': 123}