cirq-core 1.6.0.dev20250520054601__py3-none-any.whl → 1.6.0.dev20250520183459__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 (290) hide show
  1. cirq/_compat.py +15 -17
  2. cirq/_compat_test.py +6 -9
  3. cirq/_doc.py +2 -2
  4. cirq/_import.py +6 -6
  5. cirq/_version.py +1 -1
  6. cirq/_version_test.py +1 -1
  7. cirq/circuits/_block_diagram_drawer.py +9 -10
  8. cirq/circuits/_box_drawing_character_data.py +6 -8
  9. cirq/circuits/_bucket_priority_queue.py +7 -7
  10. cirq/circuits/circuit.py +118 -125
  11. cirq/circuits/circuit_operation.py +38 -52
  12. cirq/circuits/circuit_test.py +4 -4
  13. cirq/circuits/frozen_circuit.py +13 -23
  14. cirq/circuits/moment.py +23 -29
  15. cirq/circuits/optimization_pass.py +4 -4
  16. cirq/circuits/optimization_pass_test.py +4 -6
  17. cirq/circuits/qasm_output.py +11 -11
  18. cirq/circuits/text_diagram_drawer.py +21 -36
  19. cirq/contrib/acquaintance/bipartite.py +5 -8
  20. cirq/contrib/acquaintance/executor.py +5 -5
  21. cirq/contrib/acquaintance/executor_test.py +3 -3
  22. cirq/contrib/acquaintance/gates.py +16 -26
  23. cirq/contrib/acquaintance/gates_test.py +3 -3
  24. cirq/contrib/acquaintance/mutation_utils.py +4 -4
  25. cirq/contrib/acquaintance/optimizers.py +4 -4
  26. cirq/contrib/acquaintance/permutation.py +15 -27
  27. cirq/contrib/acquaintance/shift.py +3 -3
  28. cirq/contrib/acquaintance/shift_swap_network.py +4 -4
  29. cirq/contrib/acquaintance/strategies/cubic.py +2 -2
  30. cirq/contrib/acquaintance/strategies/quartic_paired.py +6 -6
  31. cirq/contrib/bayesian_network/bayesian_network_gate.py +9 -10
  32. cirq/contrib/circuitdag/circuit_dag.py +2 -2
  33. cirq/contrib/custom_simulators/custom_state_simulator.py +3 -3
  34. cirq/contrib/custom_simulators/custom_state_simulator_test.py +4 -4
  35. cirq/contrib/graph_device/graph_device.py +5 -5
  36. cirq/contrib/graph_device/hypergraph.py +12 -12
  37. cirq/contrib/graph_device/uniform_graph_device.py +4 -4
  38. cirq/contrib/paulistring/clifford_optimize.py +2 -2
  39. cirq/contrib/paulistring/clifford_target_gateset.py +7 -7
  40. cirq/contrib/paulistring/pauli_string_measurement_with_readout_mitigation.py +31 -31
  41. cirq/contrib/paulistring/pauli_string_measurement_with_readout_mitigation_test.py +23 -23
  42. cirq/contrib/paulistring/recombine.py +3 -3
  43. cirq/contrib/paulistring/separate.py +2 -2
  44. cirq/contrib/qasm_import/_parser.py +20 -32
  45. cirq/contrib/qcircuit/qcircuit_diagram_info.py +3 -5
  46. cirq/contrib/quantum_volume/quantum_volume.py +24 -24
  47. cirq/contrib/quimb/density_matrix.py +12 -14
  48. cirq/contrib/quimb/mps_simulator.py +20 -20
  49. cirq/contrib/quimb/state_vector.py +6 -10
  50. cirq/contrib/quirk/export_to_quirk.py +3 -3
  51. cirq/contrib/quirk/quirk_gate.py +15 -15
  52. cirq/contrib/routing/device.py +3 -3
  53. cirq/contrib/routing/greedy.py +10 -21
  54. cirq/contrib/routing/initialization.py +2 -2
  55. cirq/contrib/routing/swap_network.py +3 -3
  56. cirq/contrib/routing/utils.py +2 -2
  57. cirq/contrib/shuffle_circuits/shuffle_circuits_with_readout_benchmarking.py +8 -8
  58. cirq/contrib/svg/svg.py +3 -3
  59. cirq/devices/grid_device_metadata.py +10 -10
  60. cirq/devices/grid_qubit.py +20 -20
  61. cirq/devices/insertion_noise_model.py +5 -5
  62. cirq/devices/line_qubit.py +13 -13
  63. cirq/devices/named_topologies.py +18 -29
  64. cirq/devices/noise_model.py +3 -3
  65. cirq/devices/noise_properties.py +2 -2
  66. cirq/devices/noise_properties_test.py +1 -3
  67. cirq/devices/noise_utils.py +7 -7
  68. cirq/devices/superconducting_qubits_noise_properties.py +21 -21
  69. cirq/devices/superconducting_qubits_noise_properties_test.py +5 -7
  70. cirq/devices/thermal_noise_model.py +14 -14
  71. cirq/devices/unconstrained_device.py +2 -2
  72. cirq/experiments/benchmarking/parallel_xeb.py +29 -31
  73. cirq/experiments/n_qubit_tomography.py +5 -7
  74. cirq/experiments/qubit_characterizations.py +29 -40
  75. cirq/experiments/qubit_characterizations_test.py +1 -1
  76. cirq/experiments/random_quantum_circuit_generation.py +19 -33
  77. cirq/experiments/random_quantum_circuit_generation_test.py +6 -6
  78. cirq/experiments/readout_confusion_matrix.py +14 -14
  79. cirq/experiments/single_qubit_readout_calibration.py +12 -12
  80. cirq/experiments/t2_decay_experiment.py +7 -7
  81. cirq/experiments/two_qubit_xeb.py +32 -32
  82. cirq/experiments/two_qubit_xeb_test.py +5 -5
  83. cirq/experiments/xeb_fitting.py +25 -25
  84. cirq/experiments/xeb_sampling.py +22 -33
  85. cirq/experiments/xeb_simulation.py +5 -5
  86. cirq/experiments/xeb_simulation_test.py +3 -3
  87. cirq/experiments/z_phase_calibration.py +19 -19
  88. cirq/interop/quirk/cells/arithmetic_cells.py +23 -36
  89. cirq/interop/quirk/cells/cell.py +9 -21
  90. cirq/interop/quirk/cells/composite_cell.py +7 -22
  91. cirq/interop/quirk/cells/control_cells.py +8 -8
  92. cirq/interop/quirk/cells/input_cells.py +4 -4
  93. cirq/interop/quirk/cells/input_rotation_cells.py +5 -5
  94. cirq/interop/quirk/cells/parse.py +20 -23
  95. cirq/interop/quirk/cells/qubit_permutation_cells.py +3 -3
  96. cirq/interop/quirk/cells/swap_cell.py +3 -3
  97. cirq/interop/quirk/cells/testing.py +5 -7
  98. cirq/interop/quirk/url_to_circuit.py +17 -33
  99. cirq/json_resolver_cache.py +6 -6
  100. cirq/linalg/decompositions.py +20 -31
  101. cirq/linalg/diagonalize.py +4 -4
  102. cirq/linalg/diagonalize_test.py +3 -4
  103. cirq/linalg/operator_spaces.py +5 -5
  104. cirq/linalg/predicates.py +7 -7
  105. cirq/linalg/transformations.py +20 -20
  106. cirq/ops/arithmetic_operation.py +13 -15
  107. cirq/ops/boolean_hamiltonian.py +17 -17
  108. cirq/ops/classically_controlled_operation.py +13 -25
  109. cirq/ops/clifford_gate.py +31 -35
  110. cirq/ops/clifford_gate_test.py +2 -3
  111. cirq/ops/common_channels.py +30 -32
  112. cirq/ops/common_gates.py +64 -74
  113. cirq/ops/control_values.py +12 -12
  114. cirq/ops/controlled_gate.py +15 -30
  115. cirq/ops/controlled_gate_test.py +5 -5
  116. cirq/ops/controlled_operation.py +12 -25
  117. cirq/ops/controlled_operation_test.py +5 -5
  118. cirq/ops/dense_pauli_string.py +23 -34
  119. cirq/ops/dense_pauli_string_test.py +1 -2
  120. cirq/ops/diagonal_gate.py +9 -20
  121. cirq/ops/diagonal_gate_test.py +1 -3
  122. cirq/ops/eigen_gate.py +11 -23
  123. cirq/ops/eigen_gate_test.py +6 -8
  124. cirq/ops/fourier_transform.py +5 -5
  125. cirq/ops/fsim_gate.py +14 -14
  126. cirq/ops/gate_operation.py +23 -44
  127. cirq/ops/gateset.py +23 -37
  128. cirq/ops/gateset_test.py +2 -2
  129. cirq/ops/global_phase_op.py +8 -10
  130. cirq/ops/greedy_qubit_manager.py +6 -6
  131. cirq/ops/identity.py +9 -9
  132. cirq/ops/kraus_channel.py +7 -7
  133. cirq/ops/linear_combinations.py +29 -48
  134. cirq/ops/matrix_gates.py +8 -8
  135. cirq/ops/measure_util.py +13 -14
  136. cirq/ops/measurement_gate.py +18 -29
  137. cirq/ops/mixed_unitary_channel.py +8 -8
  138. cirq/ops/named_qubit.py +10 -10
  139. cirq/ops/op_tree.py +7 -7
  140. cirq/ops/parallel_gate.py +5 -5
  141. cirq/ops/parity_gates.py +14 -14
  142. cirq/ops/pauli_gates.py +8 -10
  143. cirq/ops/pauli_interaction_gate.py +6 -6
  144. cirq/ops/pauli_measurement_gate.py +11 -23
  145. cirq/ops/pauli_string.py +35 -52
  146. cirq/ops/pauli_string_phasor.py +4 -14
  147. cirq/ops/pauli_string_raw_types.py +3 -3
  148. cirq/ops/pauli_sum_exponential.py +2 -2
  149. cirq/ops/permutation_gate.py +4 -4
  150. cirq/ops/phased_iswap_gate.py +9 -9
  151. cirq/ops/phased_x_gate.py +10 -10
  152. cirq/ops/phased_x_z_gate.py +11 -11
  153. cirq/ops/projector.py +6 -6
  154. cirq/ops/qubit_manager.py +6 -6
  155. cirq/ops/qubit_order.py +3 -3
  156. cirq/ops/random_gate_channel.py +4 -4
  157. cirq/ops/raw_types.py +48 -70
  158. cirq/ops/state_preparation_channel.py +3 -3
  159. cirq/ops/swap_gates.py +9 -9
  160. cirq/ops/tags.py +2 -4
  161. cirq/ops/three_qubit_gates.py +20 -38
  162. cirq/ops/two_qubit_diagonal_gate.py +5 -5
  163. cirq/ops/uniform_superposition_gate.py +2 -2
  164. cirq/ops/wait_gate.py +5 -5
  165. cirq/protocols/act_on_protocol_test.py +3 -3
  166. cirq/protocols/apply_channel_protocol.py +8 -14
  167. cirq/protocols/apply_mixture_protocol.py +14 -16
  168. cirq/protocols/apply_mixture_protocol_test.py +5 -6
  169. cirq/protocols/apply_unitary_protocol.py +17 -19
  170. cirq/protocols/circuit_diagram_info_protocol.py +19 -30
  171. cirq/protocols/decompose_protocol.py +30 -34
  172. cirq/protocols/inverse_protocol.py +7 -7
  173. cirq/protocols/json_serialization.py +32 -51
  174. cirq/protocols/json_serialization_test.py +9 -10
  175. cirq/protocols/kraus_protocol.py +4 -4
  176. cirq/protocols/kraus_protocol_test.py +3 -3
  177. cirq/protocols/measurement_key_protocol.py +11 -13
  178. cirq/protocols/mixture_protocol.py +4 -4
  179. cirq/protocols/qasm.py +11 -13
  180. cirq/protocols/qid_shape_protocol.py +6 -8
  181. cirq/qis/clifford_tableau.py +12 -12
  182. cirq/qis/measures.py +7 -7
  183. cirq/qis/quantum_state_representation.py +3 -3
  184. cirq/qis/states.py +51 -51
  185. cirq/sim/classical_simulator.py +10 -10
  186. cirq/sim/clifford/clifford_simulator.py +6 -6
  187. cirq/sim/clifford/clifford_tableau_simulation_state_test.py +1 -3
  188. cirq/sim/clifford/stabilizer_sampler.py +4 -4
  189. cirq/sim/clifford/stabilizer_state_ch_form.py +3 -3
  190. cirq/sim/density_matrix_simulation_state.py +15 -15
  191. cirq/sim/density_matrix_simulator.py +11 -11
  192. cirq/sim/density_matrix_utils.py +9 -9
  193. cirq/sim/mux.py +9 -9
  194. cirq/sim/simulation_product_state.py +9 -9
  195. cirq/sim/simulation_product_state_test.py +2 -2
  196. cirq/sim/simulation_state.py +14 -27
  197. cirq/sim/simulation_state_base.py +8 -24
  198. cirq/sim/simulation_utils.py +3 -4
  199. cirq/sim/simulator.py +28 -43
  200. cirq/sim/simulator_base.py +12 -25
  201. cirq/sim/simulator_base_test.py +6 -6
  202. cirq/sim/simulator_test.py +7 -7
  203. cirq/sim/sparse_simulator.py +8 -8
  204. cirq/sim/state_vector.py +8 -8
  205. cirq/sim/state_vector_simulation_state.py +17 -17
  206. cirq/sim/state_vector_simulator.py +4 -4
  207. cirq/study/flatten_expressions.py +12 -14
  208. cirq/study/resolver.py +9 -11
  209. cirq/study/result.py +11 -24
  210. cirq/study/sweepable.py +5 -5
  211. cirq/study/sweeps.py +27 -40
  212. cirq/testing/circuit_compare.py +5 -5
  213. cirq/testing/consistent_controlled_gate_op_test.py +7 -11
  214. cirq/testing/consistent_protocols.py +10 -10
  215. cirq/testing/consistent_protocols_test.py +7 -7
  216. cirq/testing/consistent_qasm.py +4 -4
  217. cirq/testing/consistent_qasm_test.py +2 -3
  218. cirq/testing/devices.py +4 -5
  219. cirq/testing/equals_tester.py +2 -2
  220. cirq/testing/equivalent_basis_map.py +4 -4
  221. cirq/testing/equivalent_repr_eval.py +3 -3
  222. cirq/testing/json.py +14 -14
  223. cirq/testing/logs.py +3 -3
  224. cirq/testing/no_identifier_qubit.py +2 -3
  225. cirq/testing/random_circuit.py +7 -7
  226. cirq/testing/random_circuit_test.py +3 -3
  227. cirq/transformers/analytical_decompositions/clifford_decomposition.py +16 -16
  228. cirq/transformers/analytical_decompositions/controlled_gate_decomposition.py +13 -13
  229. cirq/transformers/analytical_decompositions/cphase_to_fsim.py +5 -5
  230. cirq/transformers/analytical_decompositions/cphase_to_fsim_test.py +3 -3
  231. cirq/transformers/analytical_decompositions/pauli_string_decomposition.py +3 -3
  232. cirq/transformers/analytical_decompositions/quantum_shannon_decomposition.py +4 -4
  233. cirq/transformers/analytical_decompositions/single_qubit_decompositions.py +6 -7
  234. cirq/transformers/analytical_decompositions/single_to_two_qubit_isometry.py +2 -2
  235. cirq/transformers/analytical_decompositions/three_qubit_decomposition.py +7 -7
  236. cirq/transformers/analytical_decompositions/two_qubit_state_preparation.py +4 -4
  237. cirq/transformers/analytical_decompositions/two_qubit_to_cz.py +7 -7
  238. cirq/transformers/analytical_decompositions/two_qubit_to_fsim.py +11 -11
  239. cirq/transformers/analytical_decompositions/two_qubit_to_ms.py +5 -5
  240. cirq/transformers/analytical_decompositions/two_qubit_to_sqrt_iswap.py +14 -14
  241. cirq/transformers/dynamical_decoupling.py +13 -13
  242. cirq/transformers/dynamical_decoupling_test.py +4 -4
  243. cirq/transformers/eject_phased_paulis.py +16 -16
  244. cirq/transformers/eject_z.py +5 -7
  245. cirq/transformers/gauge_compiling/gauge_compiling.py +38 -38
  246. cirq/transformers/gauge_compiling/sqrt_cz_gauge.py +2 -2
  247. cirq/transformers/heuristic_decompositions/two_qubit_gate_tabulation.py +8 -8
  248. cirq/transformers/insertion_sort.py +5 -5
  249. cirq/transformers/measurement_transformers.py +14 -14
  250. cirq/transformers/merge_k_qubit_gates_test.py +1 -3
  251. cirq/transformers/merge_single_qubit_gates_test.py +1 -3
  252. cirq/transformers/qubit_management_transformers.py +5 -5
  253. cirq/transformers/routing/initial_mapper.py +4 -4
  254. cirq/transformers/routing/line_initial_mapper.py +9 -9
  255. cirq/transformers/routing/mapping_manager.py +7 -7
  256. cirq/transformers/routing/route_circuit_cqc.py +27 -27
  257. cirq/transformers/routing/visualize_routed_circuit.py +4 -4
  258. cirq/transformers/stratify.py +8 -8
  259. cirq/transformers/synchronize_terminal_measurements.py +6 -6
  260. cirq/transformers/target_gatesets/compilation_target_gateset.py +8 -8
  261. cirq/transformers/target_gatesets/compilation_target_gateset_test.py +2 -2
  262. cirq/transformers/target_gatesets/cz_gateset.py +4 -4
  263. cirq/transformers/target_gatesets/sqrt_iswap_gateset.py +5 -5
  264. cirq/transformers/transformer_api.py +11 -26
  265. cirq/transformers/transformer_primitives.py +24 -36
  266. cirq/transformers/transformer_primitives_test.py +3 -3
  267. cirq/value/classical_data.py +18 -18
  268. cirq/value/condition.py +8 -8
  269. cirq/value/digits.py +7 -7
  270. cirq/value/duration.py +12 -12
  271. cirq/value/linear_dict.py +8 -12
  272. cirq/value/linear_dict_test.py +2 -2
  273. cirq/value/measurement_key.py +8 -8
  274. cirq/value/product_state.py +9 -9
  275. cirq/value/value_equality_attr.py +4 -4
  276. cirq/vis/heatmap.py +23 -35
  277. cirq/work/collector.py +9 -17
  278. cirq/work/observable_grouping.py +4 -7
  279. cirq/work/observable_measurement.py +29 -41
  280. cirq/work/observable_measurement_data.py +14 -14
  281. cirq/work/observable_measurement_test.py +2 -2
  282. cirq/work/observable_settings.py +9 -10
  283. cirq/work/pauli_sum_collector.py +5 -5
  284. cirq/work/sampler.py +17 -17
  285. cirq/work/zeros_sampler.py +3 -3
  286. {cirq_core-1.6.0.dev20250520054601.dist-info → cirq_core-1.6.0.dev20250520183459.dist-info}/METADATA +1 -1
  287. {cirq_core-1.6.0.dev20250520054601.dist-info → cirq_core-1.6.0.dev20250520183459.dist-info}/RECORD +290 -290
  288. {cirq_core-1.6.0.dev20250520054601.dist-info → cirq_core-1.6.0.dev20250520183459.dist-info}/WHEEL +1 -1
  289. {cirq_core-1.6.0.dev20250520054601.dist-info → cirq_core-1.6.0.dev20250520183459.dist-info}/licenses/LICENSE +0 -0
  290. {cirq_core-1.6.0.dev20250520054601.dist-info → cirq_core-1.6.0.dev20250520183459.dist-info}/top_level.txt +0 -0
@@ -15,7 +15,7 @@
15
15
  from __future__ import annotations
16
16
 
17
17
  import itertools
18
- from typing import Any, Dict, Optional, Sequence, Type
18
+ from typing import Any, Sequence
19
19
 
20
20
  import numpy as np
21
21
  import sympy
@@ -49,11 +49,11 @@ def assert_implements_consistent_protocols(
49
49
  val: Any,
50
50
  *,
51
51
  exponents: Sequence[Any] = (0, 1, -1, 0.25, sympy.Symbol('s')),
52
- qubit_count: Optional[int] = None,
52
+ qubit_count: int | None = None,
53
53
  ignoring_global_phase: bool = False,
54
54
  setup_code: str = 'import cirq\nimport numpy as np\nimport sympy',
55
- global_vals: Optional[Dict[str, Any]] = None,
56
- local_vals: Optional[Dict[str, Any]] = None,
55
+ global_vals: dict[str, Any] | None = None,
56
+ local_vals: dict[str, Any] | None = None,
57
57
  ignore_decompose_to_default_gateset: bool = False,
58
58
  ) -> None:
59
59
  """Checks that a value is internally consistent and has a good __repr__."""
@@ -83,15 +83,15 @@ def assert_implements_consistent_protocols(
83
83
 
84
84
 
85
85
  def assert_eigengate_implements_consistent_protocols(
86
- eigen_gate_type: Type[ops.EigenGate],
86
+ eigen_gate_type: type[ops.EigenGate],
87
87
  *,
88
88
  exponents: Sequence[value.TParamVal] = (0, 1, -1, 0.25, sympy.Symbol('s')),
89
89
  global_shifts: Sequence[float] = (0, -0.5, 0.1),
90
- qubit_count: Optional[int] = None,
90
+ qubit_count: int | None = None,
91
91
  ignoring_global_phase: bool = False,
92
92
  setup_code: str = 'import cirq\nimport numpy as np\nimport sympy',
93
- global_vals: Optional[Dict[str, Any]] = None,
94
- local_vals: Optional[Dict[str, Any]] = None,
93
+ global_vals: dict[str, Any] | None = None,
94
+ local_vals: dict[str, Any] | None = None,
95
95
  ignore_decompose_to_default_gateset: bool = False,
96
96
  ) -> None:
97
97
  """Checks that an EigenGate subclass is internally consistent and has a
@@ -145,8 +145,8 @@ def _assert_meets_standards_helper(
145
145
  *,
146
146
  ignoring_global_phase: bool,
147
147
  setup_code: str,
148
- global_vals: Optional[Dict[str, Any]],
149
- local_vals: Optional[Dict[str, Any]],
148
+ global_vals: dict[str, Any] | None,
149
+ local_vals: dict[str, Any] | None,
150
150
  ignore_decompose_to_default_gateset: bool,
151
151
  ) -> None:
152
152
  __tracebackhide__ = True # pylint: disable=unused-variable
@@ -15,7 +15,7 @@
15
15
  from __future__ import annotations
16
16
 
17
17
  from types import NotImplementedType
18
- from typing import AbstractSet, List, Sequence, Tuple, Union
18
+ from typing import AbstractSet, Sequence
19
19
 
20
20
  import numpy as np
21
21
  import pytest
@@ -28,7 +28,7 @@ from cirq._compat import proper_repr
28
28
 
29
29
  class GoodGate(cirq.testing.SingleQubitGate):
30
30
  def __init__(
31
- self, *, phase_exponent: Union[float, sympy.Expr], exponent: Union[float, sympy.Expr] = 1.0
31
+ self, *, phase_exponent: float | sympy.Expr, exponent: float | sympy.Expr = 1.0
32
32
  ) -> None:
33
33
  self.phase_exponent = cirq.canonicalize_half_turns(phase_exponent)
34
34
  self.exponent = exponent
@@ -36,14 +36,14 @@ class GoodGate(cirq.testing.SingleQubitGate):
36
36
  def _has_unitary_(self):
37
37
  return not cirq.is_parameterized(self)
38
38
 
39
- def _unitary_(self) -> Union[np.ndarray, NotImplementedType]:
39
+ def _unitary_(self) -> np.ndarray | NotImplementedType:
40
40
  if cirq.is_parameterized(self):
41
41
  return NotImplemented
42
42
  z = cirq.unitary(cirq.Z**self.phase_exponent)
43
43
  x = cirq.unitary(cirq.X**self.exponent)
44
44
  return np.dot(np.dot(z, x), np.conj(z))
45
45
 
46
- def _apply_unitary_(self, args: cirq.ApplyUnitaryArgs) -> Union[np.ndarray, NotImplementedType]:
46
+ def _apply_unitary_(self, args: cirq.ApplyUnitaryArgs) -> np.ndarray | NotImplementedType:
47
47
  if self.exponent != 1 or cirq.is_parameterized(self):
48
48
  return NotImplemented
49
49
 
@@ -85,7 +85,7 @@ class GoodGate(cirq.testing.SingleQubitGate):
85
85
  exponent=self.exponent, phase_exponent=self.phase_exponent + phase_turns * 2
86
86
  )
87
87
 
88
- def __pow__(self, exponent: Union[float, sympy.Expr]) -> GoodGate:
88
+ def __pow__(self, exponent: float | sympy.Expr) -> GoodGate:
89
89
  new_exponent = cirq.mul(self.exponent, exponent, NotImplemented)
90
90
  if new_exponent is NotImplemented:
91
91
  return NotImplemented # pragma: no cover
@@ -129,7 +129,7 @@ class BadGateParameterNames(GoodGate):
129
129
 
130
130
 
131
131
  class BadGateApplyUnitaryToTensor(GoodGate):
132
- def _apply_unitary_(self, args: cirq.ApplyUnitaryArgs) -> Union[np.ndarray, NotImplementedType]:
132
+ def _apply_unitary_(self, args: cirq.ApplyUnitaryArgs) -> np.ndarray | NotImplementedType:
133
133
  if self.exponent != 1 or cirq.is_parameterized(self):
134
134
  return NotImplemented # pragma: no cover
135
135
 
@@ -178,7 +178,7 @@ class BadGateRepr(GoodGate):
178
178
 
179
179
 
180
180
  class GoodEigenGate(cirq.EigenGate, cirq.testing.SingleQubitGate):
181
- def _eigen_components(self) -> List[Tuple[float, np.ndarray]]:
181
+ def _eigen_components(self) -> list[tuple[float, np.ndarray]]:
182
182
  return [(0, np.diag([1, 0])), (1, np.diag([0, 1]))]
183
183
 
184
184
  def __repr__(self):
@@ -15,7 +15,7 @@
15
15
  from __future__ import annotations
16
16
 
17
17
  import warnings
18
- from typing import Any, List, Optional, Sequence
18
+ from typing import Any, Sequence
19
19
 
20
20
  import numpy as np
21
21
 
@@ -87,8 +87,8 @@ qreg q[{num_qubits}];
87
87
  qasm_unitary, unitary, rtol=1e-8, atol=1e-8
88
88
  )
89
89
  except Exception as ex:
90
- p_unitary: Optional[np.ndarray]
91
- p_qasm_unitary: Optional[np.ndarray]
90
+ p_unitary: np.ndarray | None
91
+ p_qasm_unitary: np.ndarray | None
92
92
  if qasm_unitary is not None:
93
93
  p_unitary, p_qasm_unitary = linalg.match_global_phase(unitary, qasm_unitary)
94
94
  else:
@@ -127,7 +127,7 @@ def _indent(*content: str) -> str:
127
127
  return ' ' + '\n'.join(content).replace('\n', '\n ')
128
128
 
129
129
 
130
- def _reorder_indices_of_matrix(matrix: np.ndarray, new_order: List[int]):
130
+ def _reorder_indices_of_matrix(matrix: np.ndarray, new_order: list[int]):
131
131
  num_qubits = matrix.shape[0].bit_length() - 1
132
132
  matrix = np.reshape(matrix, (2,) * 2 * num_qubits)
133
133
  all_indices = range(2 * num_qubits)
@@ -15,7 +15,6 @@
15
15
  from __future__ import annotations
16
16
 
17
17
  import warnings
18
- from typing import Tuple
19
18
 
20
19
  import numpy as np
21
20
  import pytest
@@ -43,13 +42,13 @@ class Fixed(cirq.Operation):
43
42
 
44
43
 
45
44
  class QuditGate(cirq.Gate):
46
- def _qid_shape_(self) -> Tuple[int, ...]:
45
+ def _qid_shape_(self) -> tuple[int, ...]:
47
46
  return (3, 3)
48
47
 
49
48
  def _unitary_(self):
50
49
  return np.eye(9)
51
50
 
52
- def _qasm_(self, args: cirq.QasmArgs, qubits: Tuple[cirq.Qid, ...]):
51
+ def _qasm_(self, args: cirq.QasmArgs, qubits: tuple[cirq.Qid, ...]):
53
52
  return NotImplemented
54
53
 
55
54
 
cirq/testing/devices.py CHANGED
@@ -13,10 +13,9 @@
13
13
  # limitations under the License.
14
14
 
15
15
  """Provides test devices that can validate circuits."""
16
-
17
16
  from __future__ import annotations
18
17
 
19
- from typing import AbstractSet, cast, Tuple
18
+ from typing import AbstractSet, cast
20
19
 
21
20
  from cirq import devices, ops
22
21
 
@@ -41,10 +40,10 @@ class ValidatingTestDevice(devices.Device):
41
40
  self,
42
41
  qubits: AbstractSet[ops.Qid],
43
42
  name: str = "ValidatingTestDevice",
44
- allowed_gates: Tuple[type, ...] = (ops.Gate,),
45
- allowed_qubit_types: Tuple[type, ...] = (devices.GridQubit,),
43
+ allowed_gates: tuple[type, ...] = (ops.Gate,),
44
+ allowed_qubit_types: tuple[type, ...] = (devices.GridQubit,),
46
45
  validate_locality: bool = False,
47
- auto_decompose_gates: Tuple[type, ...] = tuple(),
46
+ auto_decompose_gates: tuple[type, ...] = tuple(),
48
47
  ):
49
48
  self.allowed_qubit_types = allowed_qubit_types
50
49
  self.allowed_gates = allowed_gates
@@ -24,14 +24,14 @@ from __future__ import annotations
24
24
 
25
25
  import collections
26
26
  import itertools
27
- from typing import Any, Callable, List, Tuple, Union
27
+ from typing import Any, Callable
28
28
 
29
29
 
30
30
  class EqualsTester:
31
31
  """Tests equality against user-provided disjoint equivalence groups."""
32
32
 
33
33
  def __init__(self) -> None:
34
- self._groups: List[Tuple[Union[Any, _ClassUnknownToSubjects], ...]] = [
34
+ self._groups: list[tuple[Any | _ClassUnknownToSubjects, ...]] = [
35
35
  (_ClassUnknownToSubjects(),)
36
36
  ]
37
37
 
@@ -14,7 +14,7 @@
14
14
 
15
15
  from __future__ import annotations
16
16
 
17
- from typing import Dict, Optional, Sequence
17
+ from typing import Sequence
18
18
 
19
19
  import numpy as np
20
20
 
@@ -22,7 +22,7 @@ import cirq
22
22
  from cirq import circuits
23
23
 
24
24
 
25
- def assert_equivalent_computational_basis_map(maps: Dict[int, int], circuit: circuits.Circuit):
25
+ def assert_equivalent_computational_basis_map(maps: dict[int, int], circuit: circuits.Circuit):
26
26
  """Ensure equivalence of basis state mapping.
27
27
 
28
28
  Args:
@@ -49,7 +49,7 @@ def assert_equivalent_computational_basis_map(maps: Dict[int, int], circuit: cir
49
49
 
50
50
  def _sparse_computational_basis_map(
51
51
  inputs: Sequence[int], circuit: circuits.Circuit
52
- ) -> Dict[int, int]:
52
+ ) -> dict[int, int]:
53
53
  # Pick a unique amplitude for each computational basis input state.
54
54
  amps = [np.exp(1j * i / len(inputs)) / len(inputs) ** 0.5 for i in range(len(inputs))]
55
55
 
@@ -69,7 +69,7 @@ def _sparse_computational_basis_map(
69
69
  return actual_map
70
70
 
71
71
 
72
- def _bin_dec(x: Optional[int], num_bits: int) -> str:
72
+ def _bin_dec(x: int | None, num_bits: int) -> str:
73
73
  if x is None:
74
74
  return 'None'
75
75
  return f'0b{bin(x)[2:].zfill(num_bits)} ({x})'
@@ -14,7 +14,7 @@
14
14
 
15
15
  from __future__ import annotations
16
16
 
17
- from typing import Any, Dict, Optional
17
+ from typing import Any
18
18
 
19
19
 
20
20
  def assert_equivalent_repr(
@@ -23,8 +23,8 @@ def assert_equivalent_repr(
23
23
  setup_code: str = (
24
24
  'import cirq\nimport numpy as np\nimport sympy\nimport pandas as pd\nimport datetime\n'
25
25
  ),
26
- global_vals: Optional[Dict[str, Any]] = None,
27
- local_vals: Optional[Dict[str, Any]] = None,
26
+ global_vals: dict[str, Any] | None = None,
27
+ local_vals: dict[str, Any] | None = None,
28
28
  ) -> None:
29
29
  """Checks that eval(repr(v)) == v.
30
30
 
cirq/testing/json.py CHANGED
@@ -20,7 +20,7 @@ import io
20
20
  import pathlib
21
21
  from dataclasses import dataclass
22
22
  from types import ModuleType
23
- from typing import Dict, Iterator, List, Set, Tuple, Type, TYPE_CHECKING
23
+ from typing import Iterator, TYPE_CHECKING
24
24
 
25
25
  import numpy as np
26
26
  import pandas as pd
@@ -48,28 +48,28 @@ class ModuleJsonTestSpec:
48
48
  # for test failures, a better representation
49
49
  name: str
50
50
  # the packages that have the public classes to be checked for serialization
51
- packages: List[ModuleType]
51
+ packages: list[ModuleType]
52
52
  # the path for the folder containing the test files
53
53
  test_data_path: pathlib.Path
54
54
  # these public class names are planned to be serializable but not yet
55
- not_yet_serializable: List[str]
55
+ not_yet_serializable: list[str]
56
56
  # these public class names do not need to be serialized ever
57
- should_not_be_serialized: List[str]
57
+ should_not_be_serialized: list[str]
58
58
  # points to the resolver cache's dict for this module
59
- resolver_cache: Dict[str, ObjectFactory]
59
+ resolver_cache: dict[str, ObjectFactory]
60
60
  # {DeprecatedClass: deprecation_deadline} pairs to avoid deprecation errors
61
61
  # in serialization tests.
62
- deprecated: Dict[str, str]
62
+ deprecated: dict[str, str]
63
63
  # The unqualified public name is different from the cirq_type field of the json object,
64
64
  # usually due to namespacing.
65
- custom_class_name_to_cirq_type: Dict[str, str] = dataclasses.field(default_factory=dict)
65
+ custom_class_name_to_cirq_type: dict[str, str] = dataclasses.field(default_factory=dict)
66
66
  # Special cases where classes cannot be tested using the normal infrastructure.
67
- tested_elsewhere: List[str] = dataclasses.field(default_factory=list)
67
+ tested_elsewhere: list[str] = dataclasses.field(default_factory=list)
68
68
 
69
69
  def __repr__(self):
70
70
  return self.name
71
71
 
72
- def _get_all_public_classes(self) -> Iterator[Tuple[str, Type]]:
72
+ def _get_all_public_classes(self) -> Iterator[tuple[str, type]]:
73
73
  for module in self.packages:
74
74
  for name, obj in inspect.getmembers(module):
75
75
  if inspect.isfunction(obj) or inspect.ismodule(obj):
@@ -91,16 +91,16 @@ class ModuleJsonTestSpec:
91
91
  name = self.custom_class_name_to_cirq_type.get(name, name)
92
92
  yield name, obj
93
93
 
94
- def find_classes_that_should_serialize(self) -> Set[Tuple[str, Type]]:
95
- result: Set[Tuple[str, Type]] = set()
94
+ def find_classes_that_should_serialize(self) -> set[tuple[str, type]]:
95
+ result: set[tuple[str, type]] = set()
96
96
 
97
97
  result.update({(name, obj) for name, obj in self._get_all_public_classes()})
98
98
  result.update(self.get_resolver_cache_types())
99
99
 
100
100
  return result
101
101
 
102
- def get_resolver_cache_types(self) -> Set[Tuple[str, Type]]:
103
- result: Set[Tuple[str, Type]] = set()
102
+ def get_resolver_cache_types(self) -> set[tuple[str, type]]:
103
+ result: set[tuple[str, type]] = set()
104
104
  for k, v in self.resolver_cache.items():
105
105
  if isinstance(v, type):
106
106
  result.add((k, v))
@@ -117,7 +117,7 @@ class ModuleJsonTestSpec:
117
117
  for name, _ in self.get_resolver_cache_types():
118
118
  yield name
119
119
 
120
- def all_test_data_keys(self) -> List[str]:
120
+ def all_test_data_keys(self) -> list[str]:
121
121
  seen = set()
122
122
 
123
123
  for file in self.test_data_path.iterdir():
cirq/testing/logs.py CHANGED
@@ -18,17 +18,17 @@ from __future__ import annotations
18
18
 
19
19
  import contextlib
20
20
  import logging
21
- from typing import Iterator, List, Optional
21
+ from typing import Iterator
22
22
 
23
23
 
24
24
  @contextlib.contextmanager
25
25
  def assert_logs(
26
26
  *matches: str,
27
- count: Optional[int] = 1,
27
+ count: int | None = 1,
28
28
  min_level: int = logging.WARNING,
29
29
  max_level: int = logging.CRITICAL,
30
30
  capture_warnings: bool = True,
31
- ) -> Iterator[List[logging.LogRecord]]:
31
+ ) -> Iterator[list[logging.LogRecord]]:
32
32
  """A context manager for testing logging and warning events.
33
33
 
34
34
  To use this one wraps the code that is to be tested for log events within
@@ -11,10 +11,9 @@
11
11
  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
12
  # See the License for the specific language governing permissions and
13
13
  # limitations under the License.
14
-
15
14
  from __future__ import annotations
16
15
 
17
- from typing import Any, Dict
16
+ from typing import Any
18
17
 
19
18
  from cirq import protocols
20
19
  from cirq.ops import raw_types
@@ -38,5 +37,5 @@ class NoIdentifierQubit(raw_types.Qid):
38
37
  def __repr__(self) -> str:
39
38
  return 'cirq.testing.NoIdentifierQubit()'
40
39
 
41
- def _json_dict_(self) -> Dict[str, Any]:
40
+ def _json_dict_(self) -> dict[str, Any]:
42
41
  return protocols.obj_to_dict_helper(self, [])
@@ -14,7 +14,7 @@
14
14
 
15
15
  from __future__ import annotations
16
16
 
17
- from typing import Dict, List, Optional, Sequence, TYPE_CHECKING, Union
17
+ from typing import Sequence, TYPE_CHECKING
18
18
 
19
19
  from cirq import circuits, ops, value
20
20
  from cirq._doc import document
@@ -22,7 +22,7 @@ from cirq._doc import document
22
22
  if TYPE_CHECKING:
23
23
  import cirq
24
24
 
25
- DEFAULT_GATE_DOMAIN: Dict[ops.Gate, int] = {
25
+ DEFAULT_GATE_DOMAIN: dict[ops.Gate, int] = {
26
26
  ops.CNOT: 2, # type: ignore[has-type]
27
27
  ops.CZ: 2, # type: ignore[has-type]
28
28
  ops.H: 1, # type: ignore[has-type]
@@ -46,10 +46,10 @@ and Z gates.
46
46
 
47
47
 
48
48
  def random_circuit(
49
- qubits: Union[Sequence[cirq.Qid], int],
49
+ qubits: Sequence[cirq.Qid] | int,
50
50
  n_moments: int,
51
51
  op_density: float,
52
- gate_domain: Optional[Dict[ops.Gate, int]] = None,
52
+ gate_domain: dict[ops.Gate, int] | None = None,
53
53
  random_state: cirq.RANDOM_STATE_OR_SEED_LIKE = None,
54
54
  ) -> circuits.Circuit:
55
55
  """Generates a random circuit.
@@ -107,7 +107,7 @@ def random_circuit(
107
107
 
108
108
  prng = value.parse_random_state(random_state)
109
109
 
110
- moments: List[circuits.Moment] = []
110
+ moments: list[circuits.Moment] = []
111
111
  gate_arity_pairs = sorted(gate_domain.items(), key=repr)
112
112
  num_gates = len(gate_domain)
113
113
  for _ in range(n_moments):
@@ -126,8 +126,8 @@ def random_circuit(
126
126
 
127
127
  def random_two_qubit_circuit_with_czs(
128
128
  num_czs: int = 3,
129
- q0: Optional[cirq.Qid] = None,
130
- q1: Optional[cirq.Qid] = None,
129
+ q0: cirq.Qid | None = None,
130
+ q1: cirq.Qid | None = None,
131
131
  random_state: cirq.RANDOM_STATE_OR_SEED_LIKE = None,
132
132
  ) -> circuits.Circuit:
133
133
  """Creates a random two qubit circuit with the given number of CNOTs.
@@ -15,7 +15,7 @@
15
15
  from __future__ import annotations
16
16
 
17
17
  import random
18
- from typing import cast, Dict, Optional, Sequence, Union
18
+ from typing import cast, Sequence
19
19
 
20
20
  import numpy as np
21
21
  import pytest
@@ -75,10 +75,10 @@ def _cases_for_random_circuit():
75
75
  'n_qubits,n_moments,op_density,gate_domain,pass_qubits', _cases_for_random_circuit()
76
76
  )
77
77
  def test_random_circuit(
78
- n_qubits: Union[int, Sequence[cirq.Qid]],
78
+ n_qubits: int | Sequence[cirq.Qid],
79
79
  n_moments: int,
80
80
  op_density: float,
81
- gate_domain: Optional[Dict[cirq.Gate, int]],
81
+ gate_domain: dict[cirq.Gate, int] | None,
82
82
  pass_qubits: bool,
83
83
  ) -> None:
84
84
  qubit_set = cirq.LineQubit.range(n_qubits)
@@ -17,7 +17,7 @@
17
17
  from __future__ import annotations
18
18
 
19
19
  import functools
20
- from typing import List, TYPE_CHECKING
20
+ from typing import TYPE_CHECKING
21
21
 
22
22
  import numpy as np
23
23
 
@@ -30,8 +30,8 @@ if TYPE_CHECKING:
30
30
  def _X(
31
31
  q: int,
32
32
  args: sim.CliffordTableauSimulationState,
33
- operations: List[ops.Operation],
34
- qubits: List[cirq.Qid],
33
+ operations: list[ops.Operation],
34
+ qubits: list[cirq.Qid],
35
35
  ):
36
36
  protocols.act_on(ops.X, args, qubits=[qubits[q]], allow_decompose=False)
37
37
  operations.append(ops.X(qubits[q]))
@@ -40,8 +40,8 @@ def _X(
40
40
  def _Z(
41
41
  q: int,
42
42
  args: sim.CliffordTableauSimulationState,
43
- operations: List[ops.Operation],
44
- qubits: List[cirq.Qid],
43
+ operations: list[ops.Operation],
44
+ qubits: list[cirq.Qid],
45
45
  ):
46
46
  protocols.act_on(ops.Z, args, qubits=[qubits[q]], allow_decompose=False)
47
47
  operations.append(ops.Z(qubits[q]))
@@ -50,8 +50,8 @@ def _Z(
50
50
  def _Sdg(
51
51
  q: int,
52
52
  args: sim.CliffordTableauSimulationState,
53
- operations: List[ops.Operation],
54
- qubits: List[cirq.Qid],
53
+ operations: list[ops.Operation],
54
+ qubits: list[cirq.Qid],
55
55
  ):
56
56
  # Apply the tableau with S^\{dagger}
57
57
  protocols.act_on(ops.S**-1, args, qubits=[qubits[q]], allow_decompose=False)
@@ -61,8 +61,8 @@ def _Sdg(
61
61
  def _H(
62
62
  q: int,
63
63
  args: sim.CliffordTableauSimulationState,
64
- operations: List[ops.Operation],
65
- qubits: List[cirq.Qid],
64
+ operations: list[ops.Operation],
65
+ qubits: list[cirq.Qid],
66
66
  ):
67
67
  protocols.act_on(ops.H, args, qubits=[qubits[q]], allow_decompose=False)
68
68
  operations.append(ops.H(qubits[q]))
@@ -72,8 +72,8 @@ def _CNOT(
72
72
  q1: int,
73
73
  q2: int,
74
74
  args: sim.CliffordTableauSimulationState,
75
- operations: List[ops.Operation],
76
- qubits: List[cirq.Qid],
75
+ operations: list[ops.Operation],
76
+ qubits: list[cirq.Qid],
77
77
  ):
78
78
  protocols.act_on(ops.CNOT, args, qubits=[qubits[q1], qubits[q2]], allow_decompose=False)
79
79
  operations.append(ops.CNOT(qubits[q1], qubits[q2]))
@@ -83,16 +83,16 @@ def _SWAP(
83
83
  q1: int,
84
84
  q2: int,
85
85
  args: sim.CliffordTableauSimulationState,
86
- operations: List[ops.Operation],
87
- qubits: List[cirq.Qid],
86
+ operations: list[ops.Operation],
87
+ qubits: list[cirq.Qid],
88
88
  ):
89
89
  protocols.act_on(ops.SWAP, args, qubits=[qubits[q1], qubits[q2]], allow_decompose=False)
90
90
  operations.append(ops.SWAP(qubits[q1], qubits[q2]))
91
91
 
92
92
 
93
93
  def decompose_clifford_tableau_to_operations(
94
- qubits: List[cirq.Qid], clifford_tableau: qis.CliffordTableau
95
- ) -> List[ops.Operation]:
94
+ qubits: list[cirq.Qid], clifford_tableau: qis.CliffordTableau
95
+ ) -> list[ops.Operation]:
96
96
  """Decompose an n-qubit Clifford Tableau into a list of one/two qubit operations.
97
97
 
98
98
  The implementation is based on Theorem 8 in [1].
@@ -116,7 +116,7 @@ def decompose_clifford_tableau_to_operations(
116
116
  ), "The provided clifford_tableau must satisfy the symplectic property."
117
117
 
118
118
  t: qis.CliffordTableau = clifford_tableau.copy()
119
- operations: List[ops.Operation] = []
119
+ operations: list[ops.Operation] = []
120
120
  args = sim.CliffordTableauSimulationState(
121
121
  tableau=t, qubits=qubits, prng=np.random.RandomState()
122
122
  )
@@ -15,7 +15,7 @@
15
15
  from __future__ import annotations
16
16
 
17
17
  import itertools
18
- from typing import List, Tuple, TYPE_CHECKING
18
+ from typing import TYPE_CHECKING
19
19
 
20
20
  import numpy as np
21
21
 
@@ -40,7 +40,7 @@ def _flatten(x):
40
40
  return list(itertools.chain.from_iterable(x))
41
41
 
42
42
 
43
- def _decompose_abc(matrix: np.ndarray) -> Tuple[np.ndarray, np.ndarray, np.ndarray, float]:
43
+ def _decompose_abc(matrix: np.ndarray) -> tuple[np.ndarray, np.ndarray, np.ndarray, float]:
44
44
  """Decomposes 2x2 unitary matrix.
45
45
 
46
46
  Returns 2x2 special unitary matrices A, B, C and phase delta, such that:
@@ -74,7 +74,7 @@ def _decompose_abc(matrix: np.ndarray) -> Tuple[np.ndarray, np.ndarray, np.ndarr
74
74
 
75
75
  def _decompose_single_ctrl(
76
76
  matrix: np.ndarray, control: cirq.Qid, target: cirq.Qid
77
- ) -> List[cirq.Operation]:
77
+ ) -> list[cirq.Operation]:
78
78
  """Decomposes controlled gate with one control.
79
79
 
80
80
  See [1], chapter 5.1.
@@ -96,7 +96,7 @@ def _decompose_single_ctrl(
96
96
  return result
97
97
 
98
98
 
99
- def _ccnot_congruent(c0: cirq.Qid, c1: cirq.Qid, target: cirq.Qid) -> List[cirq.Operation]:
99
+ def _ccnot_congruent(c0: cirq.Qid, c1: cirq.Qid, target: cirq.Qid) -> list[cirq.Operation]:
100
100
  """Implements 3-qubit gate 'congruent' to CCNOT.
101
101
 
102
102
  Returns sequence of operations which is equivalent to applying
@@ -114,8 +114,8 @@ def _ccnot_congruent(c0: cirq.Qid, c1: cirq.Qid, target: cirq.Qid) -> List[cirq.
114
114
 
115
115
 
116
116
  def decompose_multi_controlled_x(
117
- controls: List[cirq.Qid], target: cirq.Qid, free_qubits: List[cirq.Qid]
118
- ) -> List[cirq.Operation]:
117
+ controls: list[cirq.Qid], target: cirq.Qid, free_qubits: list[cirq.Qid]
118
+ ) -> list[cirq.Operation]:
119
119
  """Implements action of multi-controlled Pauli X gate.
120
120
 
121
121
  Result is guaranteed to consist exclusively of 1-qubit, CNOT and CCNOT
@@ -167,8 +167,8 @@ def decompose_multi_controlled_x(
167
167
 
168
168
 
169
169
  def _decompose_su(
170
- matrix: np.ndarray, controls: List[cirq.Qid], target: cirq.Qid
171
- ) -> List[cirq.Operation]:
170
+ matrix: np.ndarray, controls: list[cirq.Qid], target: cirq.Qid
171
+ ) -> list[cirq.Operation]:
172
172
  """Decomposes controlled special unitary gate into elementary gates.
173
173
 
174
174
  Result has O(len(controls)) operations.
@@ -193,10 +193,10 @@ def _decompose_su(
193
193
  def _decompose_recursive(
194
194
  matrix: np.ndarray,
195
195
  power: float,
196
- controls: List[cirq.Qid],
196
+ controls: list[cirq.Qid],
197
197
  target: cirq.Qid,
198
- free_qubits: List[cirq.Qid],
199
- ) -> List[cirq.Operation]:
198
+ free_qubits: list[cirq.Qid],
199
+ ) -> list[cirq.Operation]:
200
200
  """Decomposes controlled unitary gate into elementary gates.
201
201
 
202
202
  Result has O(len(controls)^2) operations.
@@ -218,8 +218,8 @@ def _decompose_recursive(
218
218
 
219
219
 
220
220
  def decompose_multi_controlled_rotation(
221
- matrix: np.ndarray, controls: List[cirq.Qid], target: cirq.Qid
222
- ) -> List[cirq.Operation]:
221
+ matrix: np.ndarray, controls: list[cirq.Qid], target: cirq.Qid
222
+ ) -> list[cirq.Operation]:
223
223
  """Implements action of multi-controlled unitary gate.
224
224
 
225
225
  Returns a sequence of operations, which is equivalent to applying
@@ -14,7 +14,7 @@
14
14
 
15
15
  from __future__ import annotations
16
16
 
17
- from typing import Optional, Sequence, Tuple, TYPE_CHECKING
17
+ from typing import Sequence, TYPE_CHECKING
18
18
 
19
19
  import numpy as np
20
20
  import sympy
@@ -35,7 +35,7 @@ def _asinsin(x: float) -> float:
35
35
 
36
36
  def compute_cphase_exponents_for_fsim_decomposition(
37
37
  fsim_gate: cirq.FSimGate,
38
- ) -> Sequence[Tuple[float, float]]:
38
+ ) -> Sequence[tuple[float, float]]:
39
39
  """Returns intervals of CZPowGate exponents valid for FSim decomposition.
40
40
 
41
41
  Ideal intervals associated with the constraints are closed, but due to
@@ -58,8 +58,8 @@ def compute_cphase_exponents_for_fsim_decomposition(
58
58
  """
59
59
 
60
60
  def nonempty_intervals(
61
- intervals: Sequence[Tuple[float, float]],
62
- ) -> Sequence[Tuple[float, float]]:
61
+ intervals: Sequence[tuple[float, float]],
62
+ ) -> Sequence[tuple[float, float]]:
63
63
  return tuple((a, b) for a, b in intervals if a < b)
64
64
 
65
65
  # Each of the two FSimGate parameters sets a bound on phase angle.
@@ -98,7 +98,7 @@ def decompose_cphase_into_two_fsim(
98
98
  cphase_gate: cirq.CZPowGate,
99
99
  *,
100
100
  fsim_gate: cirq.FSimGate,
101
- qubits: Optional[Sequence[cirq.Qid]] = None,
101
+ qubits: Sequence[cirq.Qid] | None = None,
102
102
  atol: float = 1e-8,
103
103
  ) -> cirq.OP_TREE:
104
104
  """Decomposes CZPowGate into two FSimGates.