cirq-core 1.6.0.dev20250520054601__py3-none-any.whl → 1.6.0.dev20250520181654__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 (289) 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/measurement_key.py +8 -8
  273. cirq/value/product_state.py +9 -9
  274. cirq/value/value_equality_attr.py +4 -4
  275. cirq/vis/heatmap.py +23 -35
  276. cirq/work/collector.py +9 -17
  277. cirq/work/observable_grouping.py +4 -7
  278. cirq/work/observable_measurement.py +29 -41
  279. cirq/work/observable_measurement_data.py +14 -14
  280. cirq/work/observable_measurement_test.py +2 -2
  281. cirq/work/observable_settings.py +9 -10
  282. cirq/work/pauli_sum_collector.py +5 -5
  283. cirq/work/sampler.py +17 -17
  284. cirq/work/zeros_sampler.py +3 -3
  285. {cirq_core-1.6.0.dev20250520054601.dist-info → cirq_core-1.6.0.dev20250520181654.dist-info}/METADATA +1 -1
  286. {cirq_core-1.6.0.dev20250520054601.dist-info → cirq_core-1.6.0.dev20250520181654.dist-info}/RECORD +289 -289
  287. {cirq_core-1.6.0.dev20250520054601.dist-info → cirq_core-1.6.0.dev20250520181654.dist-info}/WHEEL +1 -1
  288. {cirq_core-1.6.0.dev20250520054601.dist-info → cirq_core-1.6.0.dev20250520181654.dist-info}/licenses/LICENSE +0 -0
  289. {cirq_core-1.6.0.dev20250520054601.dist-info → cirq_core-1.6.0.dev20250520181654.dist-info}/top_level.txt +0 -0
@@ -14,7 +14,7 @@
14
14
 
15
15
  from __future__ import annotations
16
16
 
17
- from typing import AbstractSet, Any, Dict, Union
17
+ from typing import AbstractSet, Any
18
18
 
19
19
  import numpy as np
20
20
  import sympy
@@ -54,7 +54,7 @@ class QuantumFourierTransformGate(raw_types.Gate):
54
54
  self._num_qubits = num_qubits
55
55
  self._without_reverse = without_reverse
56
56
 
57
- def _json_dict_(self) -> Dict[str, Any]:
57
+ def _json_dict_(self) -> dict[str, Any]:
58
58
  return {'num_qubits': self._num_qubits, 'without_reverse': self._without_reverse}
59
59
 
60
60
  def _value_equality_values_(self):
@@ -112,15 +112,15 @@ class PhaseGradientGate(raw_types.Gate):
112
112
  This gate makes up a portion of the quantum fourier transform.
113
113
  """
114
114
 
115
- def __init__(self, *, num_qubits: int, exponent: Union[float, sympy.Basic]):
115
+ def __init__(self, *, num_qubits: int, exponent: float | sympy.Basic):
116
116
  self._num_qubits = num_qubits
117
117
  self._exponent = exponent
118
118
 
119
119
  @property
120
- def exponent(self) -> Union[float, sympy.Basic]:
120
+ def exponent(self) -> float | sympy.Basic:
121
121
  return self._exponent
122
122
 
123
- def _json_dict_(self) -> Dict[str, Any]:
123
+ def _json_dict_(self) -> dict[str, Any]:
124
124
  return {'num_qubits': self._num_qubits, 'exponent': self.exponent}
125
125
 
126
126
  def _value_equality_values_(self):
cirq/ops/fsim_gate.py CHANGED
@@ -26,7 +26,7 @@ from __future__ import annotations
26
26
 
27
27
  import cmath
28
28
  import math
29
- from typing import AbstractSet, Any, Dict, Iterator, Optional, Tuple
29
+ from typing import AbstractSet, Any, Iterator
30
30
 
31
31
  import numpy as np
32
32
  import sympy
@@ -131,7 +131,7 @@ class FSimGate(gate_features.InterchangeableQubitsGate, raw_types.Gate):
131
131
  def _has_unitary_(self):
132
132
  return not self._is_parameterized_()
133
133
 
134
- def _unitary_(self) -> Optional[np.ndarray]:
134
+ def _unitary_(self) -> np.ndarray | None:
135
135
  if self._is_parameterized_():
136
136
  return None
137
137
  a = math.cos(self.theta)
@@ -171,7 +171,7 @@ class FSimGate(gate_features.InterchangeableQubitsGate, raw_types.Gate):
171
171
  protocols.resolve_parameters(self.phi, resolver, recursive),
172
172
  )
173
173
 
174
- def _apply_unitary_(self, args: cirq.ApplyUnitaryArgs) -> Optional[np.ndarray]:
174
+ def _apply_unitary_(self, args: cirq.ApplyUnitaryArgs) -> np.ndarray | None:
175
175
  if cirq.is_parameterized(self):
176
176
  return None
177
177
  if self.theta != 0:
@@ -196,7 +196,7 @@ class FSimGate(gate_features.InterchangeableQubitsGate, raw_types.Gate):
196
196
  yield yy(a, b)
197
197
  yield cirq.CZ(a, b) ** (-self.phi / np.pi)
198
198
 
199
- def _circuit_diagram_info_(self, args: cirq.CircuitDiagramInfoArgs) -> Tuple[str, ...]:
199
+ def _circuit_diagram_info_(self, args: cirq.CircuitDiagramInfoArgs) -> tuple[str, ...]:
200
200
  t = args.format_radians(self.theta)
201
201
  p = args.format_radians(self.phi)
202
202
  return f'FSim({t}, {p})', f'FSim({t}, {p})'
@@ -209,7 +209,7 @@ class FSimGate(gate_features.InterchangeableQubitsGate, raw_types.Gate):
209
209
  p = proper_repr(self.phi)
210
210
  return f'cirq.FSimGate(theta={t}, phi={p})'
211
211
 
212
- def _json_dict_(self) -> Dict[str, Any]:
212
+ def _json_dict_(self) -> dict[str, Any]:
213
213
  return protocols.obj_to_dict_helper(self, ['theta', 'phi'])
214
214
 
215
215
 
@@ -326,8 +326,8 @@ class PhasedFSimGate(gate_features.InterchangeableQubitsGate, raw_types.Gate):
326
326
  def from_fsim_rz(
327
327
  theta: cirq.TParamVal,
328
328
  phi: cirq.TParamVal,
329
- rz_angles_before: Tuple[cirq.TParamVal, cirq.TParamVal],
330
- rz_angles_after: Tuple[cirq.TParamVal, cirq.TParamVal],
329
+ rz_angles_before: tuple[cirq.TParamVal, cirq.TParamVal],
330
+ rz_angles_after: tuple[cirq.TParamVal, cirq.TParamVal],
331
331
  ) -> PhasedFSimGate:
332
332
  """Creates PhasedFSimGate using an alternate parametrization.
333
333
 
@@ -349,7 +349,7 @@ class PhasedFSimGate(gate_features.InterchangeableQubitsGate, raw_types.Gate):
349
349
  return PhasedFSimGate(theta, zeta, chi, gamma, phi)
350
350
 
351
351
  @staticmethod
352
- def from_matrix(u: np.ndarray) -> Optional[PhasedFSimGate]:
352
+ def from_matrix(u: np.ndarray) -> PhasedFSimGate | None:
353
353
  """Contruct a PhasedFSimGate from unitary.
354
354
 
355
355
  Args:
@@ -388,14 +388,14 @@ class PhasedFSimGate(gate_features.InterchangeableQubitsGate, raw_types.Gate):
388
388
  return None
389
389
 
390
390
  @property
391
- def rz_angles_before(self) -> Tuple[cirq.TParamVal, cirq.TParamVal]:
391
+ def rz_angles_before(self) -> tuple[cirq.TParamVal, cirq.TParamVal]:
392
392
  """Returns 2-tuple of phase angles applied to qubits before FSimGate."""
393
393
  b0 = (-self.gamma + self.zeta + self.chi) / 2.0
394
394
  b1 = (-self.gamma - self.zeta - self.chi) / 2.0
395
395
  return b0, b1
396
396
 
397
397
  @property
398
- def rz_angles_after(self) -> Tuple[cirq.TParamVal, cirq.TParamVal]:
398
+ def rz_angles_after(self) -> tuple[cirq.TParamVal, cirq.TParamVal]:
399
399
  """Returns 2-tuple of phase angles applied to qubits after FSimGate."""
400
400
  a0 = (-self.gamma + self.zeta - self.chi) / 2.0
401
401
  a1 = (-self.gamma - self.zeta + self.chi) / 2.0
@@ -434,7 +434,7 @@ class PhasedFSimGate(gate_features.InterchangeableQubitsGate, raw_types.Gate):
434
434
  def _has_unitary_(self):
435
435
  return not self._is_parameterized_()
436
436
 
437
- def _unitary_(self) -> Optional[np.ndarray]:
437
+ def _unitary_(self) -> np.ndarray | None:
438
438
  if self._is_parameterized_():
439
439
  return None
440
440
  a = math.cos(self.theta)
@@ -467,7 +467,7 @@ class PhasedFSimGate(gate_features.InterchangeableQubitsGate, raw_types.Gate):
467
467
  protocols.resolve_parameters(self.phi, resolver, recursive),
468
468
  )
469
469
 
470
- def _apply_unitary_(self, args: cirq.ApplyUnitaryArgs) -> Optional[np.ndarray]:
470
+ def _apply_unitary_(self, args: cirq.ApplyUnitaryArgs) -> np.ndarray | None:
471
471
  if cirq.is_parameterized(self):
472
472
  return None
473
473
  oi = args.subspace_index(0b01)
@@ -515,7 +515,7 @@ class PhasedFSimGate(gate_features.InterchangeableQubitsGate, raw_types.Gate):
515
515
  yield cirq.Z(q0) ** to_exponent(after[0])
516
516
  yield cirq.Z(q1) ** to_exponent(after[1])
517
517
 
518
- def _circuit_diagram_info_(self, args: cirq.CircuitDiagramInfoArgs) -> Tuple[str, ...]:
518
+ def _circuit_diagram_info_(self, args: cirq.CircuitDiagramInfoArgs) -> tuple[str, ...]:
519
519
  theta = args.format_radians(self.theta)
520
520
  zeta = args.format_radians(self.zeta)
521
521
  chi = args.format_radians(self.chi)
@@ -537,7 +537,7 @@ class PhasedFSimGate(gate_features.InterchangeableQubitsGate, raw_types.Gate):
537
537
  f'gamma={gamma}, phi={phi})'
538
538
  )
539
539
 
540
- def _json_dict_(self) -> Dict[str, Any]:
540
+ def _json_dict_(self) -> dict[str, Any]:
541
541
  return protocols.obj_to_dict_helper(self, ['theta', 'zeta', 'chi', 'gamma', 'phi'])
542
542
 
543
543
  def _num_qubits_(self) -> int:
@@ -19,22 +19,7 @@ from __future__ import annotations
19
19
  import re
20
20
  import warnings
21
21
  from types import NotImplementedType
22
- from typing import (
23
- AbstractSet,
24
- Any,
25
- cast,
26
- Collection,
27
- Dict,
28
- FrozenSet,
29
- List,
30
- Mapping,
31
- Optional,
32
- Sequence,
33
- Tuple,
34
- TYPE_CHECKING,
35
- TypeVar,
36
- Union,
37
- )
22
+ from typing import AbstractSet, Any, cast, Collection, Mapping, Sequence, TYPE_CHECKING, TypeVar
38
23
 
39
24
  from typing_extensions import Self
40
25
 
@@ -71,7 +56,7 @@ class GateOperation(raw_types.Operation):
71
56
  return self._gate
72
57
 
73
58
  @property
74
- def qubits(self) -> Tuple[cirq.Qid, ...]:
59
+ def qubits(self) -> tuple[cirq.Qid, ...]:
75
60
  """The qubits targeted by the operation."""
76
61
  return self._qubits
77
62
 
@@ -93,7 +78,7 @@ class GateOperation(raw_types.Operation):
93
78
  return self
94
79
  return new_gate.on(*self.qubits)
95
80
 
96
- def _with_key_path_(self, path: Tuple[str, ...]):
81
+ def _with_key_path_(self, path: tuple[str, ...]):
97
82
  new_gate = protocols.with_key_path(self.gate, path)
98
83
  if new_gate is NotImplemented:
99
84
  return NotImplemented
@@ -102,7 +87,7 @@ class GateOperation(raw_types.Operation):
102
87
  return self
103
88
  return new_gate.on(*self.qubits)
104
89
 
105
- def _with_key_path_prefix_(self, prefix: Tuple[str, ...]):
90
+ def _with_key_path_prefix_(self, prefix: tuple[str, ...]):
106
91
  new_gate = protocols.with_key_path_prefix(self.gate, prefix)
107
92
  if new_gate is NotImplemented:
108
93
  return NotImplemented
@@ -112,7 +97,7 @@ class GateOperation(raw_types.Operation):
112
97
  return new_gate.on(*self.qubits)
113
98
 
114
99
  def _with_rescoped_keys_(
115
- self, path: Tuple[str, ...], bindable_keys: FrozenSet[cirq.MeasurementKey]
100
+ self, path: tuple[str, ...], bindable_keys: frozenset[cirq.MeasurementKey]
116
101
  ):
117
102
  new_gate = protocols.with_rescoped_keys(self.gate, path, bindable_keys)
118
103
  if new_gate is self.gate:
@@ -140,15 +125,15 @@ class GateOperation(raw_types.Operation):
140
125
  qubits = ', '.join(str(e) for e in self.qubits)
141
126
  return f'{self.gate}({qubits})' if qubits else str(self.gate)
142
127
 
143
- def _json_dict_(self) -> Dict[str, Any]:
128
+ def _json_dict_(self) -> dict[str, Any]:
144
129
  return protocols.obj_to_dict_helper(self, ['gate', 'qubits'])
145
130
 
146
131
  def _group_interchangeable_qubits(
147
132
  self,
148
- ) -> Tuple[Union[cirq.Qid, Tuple[int, FrozenSet[cirq.Qid]]], ...]:
133
+ ) -> tuple[cirq.Qid | tuple[int, frozenset[cirq.Qid]], ...]:
149
134
  if not isinstance(self.gate, gate_features.InterchangeableQubitsGate):
150
135
  return self.qubits
151
- groups: Dict[int, List[cirq.Qid]] = {}
136
+ groups: dict[int, list[cirq.Qid]] = {}
152
137
  for i, q in enumerate(self.qubits):
153
138
  k = self.gate.qubit_index_to_equivalence_group_key(i)
154
139
  groups.setdefault(k, []).append(q)
@@ -167,7 +152,7 @@ class GateOperation(raw_types.Operation):
167
152
  return self._decompose_with_context_()
168
153
 
169
154
  def _decompose_with_context_(
170
- self, context: Optional[cirq.DecompositionContext] = None
155
+ self, context: cirq.DecompositionContext | None = None
171
156
  ) -> cirq.OP_TREE:
172
157
  return protocols.decompose_once_with_qubits(
173
158
  self.gate, self.qubits, NotImplemented, flatten=False, context=context
@@ -181,7 +166,7 @@ class GateOperation(raw_types.Operation):
181
166
 
182
167
  def _apply_unitary_(
183
168
  self, args: protocols.ApplyUnitaryArgs
184
- ) -> Union[np.ndarray, None, NotImplementedType]:
169
+ ) -> np.ndarray | None | NotImplementedType:
185
170
  getter = getattr(self.gate, '_apply_unitary_', None)
186
171
  if getter is not None:
187
172
  return getter(args)
@@ -193,15 +178,13 @@ class GateOperation(raw_types.Operation):
193
178
  return getter()
194
179
  return NotImplemented
195
180
 
196
- def _unitary_(self) -> Union[np.ndarray, NotImplementedType]:
181
+ def _unitary_(self) -> np.ndarray | NotImplementedType:
197
182
  getter = getattr(self.gate, '_unitary_', None)
198
183
  if getter is not None:
199
184
  return getter()
200
185
  return NotImplemented
201
186
 
202
- def _commutes_(
203
- self, other: Any, *, atol: float = 1e-8
204
- ) -> Union[bool, NotImplementedType, None]:
187
+ def _commutes_(self, other: Any, *, atol: float = 1e-8) -> bool | NotImplementedType | None:
205
188
  commutes = self.gate._commutes_on_qids_(self.qubits, other, atol=atol)
206
189
  if commutes is not NotImplemented:
207
190
  return commutes
@@ -214,7 +197,7 @@ class GateOperation(raw_types.Operation):
214
197
  return getter()
215
198
  return NotImplemented
216
199
 
217
- def _mixture_(self) -> Sequence[Tuple[float, Any]]:
200
+ def _mixture_(self) -> Sequence[tuple[float, Any]]:
218
201
  getter = getattr(self.gate, '_mixture_', None)
219
202
  if getter is not None:
220
203
  return getter()
@@ -222,7 +205,7 @@ class GateOperation(raw_types.Operation):
222
205
 
223
206
  def _apply_channel_(
224
207
  self, args: protocols.ApplyChannelArgs
225
- ) -> Union[np.ndarray, None, NotImplementedType]:
208
+ ) -> np.ndarray | None | NotImplementedType:
226
209
  getter = getattr(self.gate, '_apply_channel_', None)
227
210
  if getter is not None:
228
211
  return getter(args)
@@ -234,40 +217,38 @@ class GateOperation(raw_types.Operation):
234
217
  return getter()
235
218
  return NotImplemented
236
219
 
237
- def _kraus_(self) -> Union[Tuple[np.ndarray], NotImplementedType]:
220
+ def _kraus_(self) -> tuple[np.ndarray] | NotImplementedType:
238
221
  getter = getattr(self.gate, '_kraus_', None)
239
222
  if getter is not None:
240
223
  return getter()
241
224
  return NotImplemented
242
225
 
243
- def _is_measurement_(self) -> Optional[bool]:
226
+ def _is_measurement_(self) -> bool | None:
244
227
  getter = getattr(self.gate, '_is_measurement_', None)
245
228
  if getter is not None:
246
229
  return getter()
247
230
  # Let the protocol handle the fallback.
248
231
  return NotImplemented
249
232
 
250
- def _measurement_key_name_(self) -> Optional[str]:
233
+ def _measurement_key_name_(self) -> str | None:
251
234
  getter = getattr(self.gate, '_measurement_key_name_', None)
252
235
  if getter is not None:
253
236
  return getter()
254
237
  return NotImplemented
255
238
 
256
- def _measurement_key_names_(self) -> Union[FrozenSet[str], NotImplementedType, None]:
239
+ def _measurement_key_names_(self) -> frozenset[str] | NotImplementedType | None:
257
240
  getter = getattr(self.gate, '_measurement_key_names_', None)
258
241
  if getter is not None:
259
242
  return getter()
260
243
  return NotImplemented
261
244
 
262
- def _measurement_key_obj_(self) -> Optional[cirq.MeasurementKey]:
245
+ def _measurement_key_obj_(self) -> cirq.MeasurementKey | None:
263
246
  getter = getattr(self.gate, '_measurement_key_obj_', None)
264
247
  if getter is not None:
265
248
  return getter()
266
249
  return NotImplemented
267
250
 
268
- def _measurement_key_objs_(
269
- self,
270
- ) -> Union[FrozenSet[cirq.MeasurementKey], NotImplementedType, None]:
251
+ def _measurement_key_objs_(self) -> frozenset[cirq.MeasurementKey] | NotImplementedType | None:
271
252
  getter = getattr(self.gate, '_measurement_key_objs_', None)
272
253
  if getter is not None:
273
254
  return getter()
@@ -347,7 +328,7 @@ class GateOperation(raw_types.Operation):
347
328
  def __rmul__(self, other: Any) -> Any:
348
329
  return self.gate._rmul_with_qubits(self._qubits, other)
349
330
 
350
- def _qasm_(self, args: protocols.QasmArgs) -> Optional[str]:
331
+ def _qasm_(self, args: protocols.QasmArgs) -> str | None:
351
332
  if isinstance(self.gate, ops.GlobalPhaseGate):
352
333
  warnings.warn(
353
334
  "OpenQASM 2.0 does not support global phase."
@@ -360,7 +341,7 @@ class GateOperation(raw_types.Operation):
360
341
 
361
342
  def _equal_up_to_global_phase_(
362
343
  self, other: Any, atol: float = 1e-8
363
- ) -> Union[NotImplementedType, bool]:
344
+ ) -> NotImplementedType | bool:
364
345
  if not isinstance(other, type(self)):
365
346
  return NotImplemented
366
347
  if self._group_interchangeable_qubits() != other._group_interchangeable_qubits():
@@ -370,9 +351,7 @@ class GateOperation(raw_types.Operation):
370
351
  def controlled_by(
371
352
  self,
372
353
  *control_qubits: cirq.Qid,
373
- control_values: Optional[
374
- Union[cv.AbstractControlValues, Sequence[Union[int, Collection[int]]]]
375
- ] = None,
354
+ control_values: cv.AbstractControlValues | Sequence[int | Collection[int]] | None = None,
376
355
  ) -> cirq.Operation:
377
356
  if len(control_qubits) == 0:
378
357
  return self
cirq/ops/gateset.py CHANGED
@@ -16,20 +16,7 @@
16
16
 
17
17
  from __future__ import annotations
18
18
 
19
- from typing import (
20
- Any,
21
- Callable,
22
- cast,
23
- Dict,
24
- FrozenSet,
25
- Hashable,
26
- List,
27
- Optional,
28
- Sequence,
29
- Type,
30
- TYPE_CHECKING,
31
- Union,
32
- )
19
+ from typing import Any, Callable, cast, Hashable, Sequence, TYPE_CHECKING
33
20
 
34
21
  from cirq import protocols, value
35
22
  from cirq.ops import global_phase_op, op_tree, raw_types
@@ -39,8 +26,7 @@ if TYPE_CHECKING:
39
26
 
40
27
 
41
28
  def _gate_str(
42
- gate: Union[raw_types.Gate, Type[raw_types.Gate], cirq.GateFamily],
43
- gettr: Callable[[Any], str] = str,
29
+ gate: raw_types.Gate | type[raw_types.Gate] | cirq.GateFamily, gettr: Callable[[Any], str] = str
44
30
  ) -> str:
45
31
  return gettr(gate) if not isinstance(gate, type) else f'{gate.__module__}.{gate.__name__}'
46
32
 
@@ -114,10 +100,10 @@ class GateFamily:
114
100
 
115
101
  def __init__(
116
102
  self,
117
- gate: Union[Type[raw_types.Gate], raw_types.Gate],
103
+ gate: type[raw_types.Gate] | raw_types.Gate,
118
104
  *,
119
- name: Optional[str] = None,
120
- description: Optional[str] = None,
105
+ name: str | None = None,
106
+ description: str | None = None,
121
107
  ignore_global_phase: bool = True,
122
108
  tags_to_accept: Sequence[Hashable] = (),
123
109
  tags_to_ignore: Sequence[Hashable] = (),
@@ -166,7 +152,7 @@ class GateFamily:
166
152
  def _gate_str(self, gettr: Callable[[Any], str] = str) -> str:
167
153
  return _gate_str(self.gate, gettr)
168
154
 
169
- def _gate_json(self) -> Union[raw_types.Gate, str]:
155
+ def _gate_json(self) -> raw_types.Gate | str:
170
156
  return self.gate if not isinstance(self.gate, type) else protocols.json_cirq_type(self.gate)
171
157
 
172
158
  def _default_name(self) -> str:
@@ -188,7 +174,7 @@ class GateFamily:
188
174
  )
189
175
 
190
176
  @property
191
- def gate(self) -> Union[Type[raw_types.Gate], raw_types.Gate]:
177
+ def gate(self) -> type[raw_types.Gate] | raw_types.Gate:
192
178
  return self._gate
193
179
 
194
180
  @property
@@ -200,11 +186,11 @@ class GateFamily:
200
186
  return self._description
201
187
 
202
188
  @property
203
- def tags_to_accept(self) -> FrozenSet[Hashable]:
189
+ def tags_to_accept(self) -> frozenset[Hashable]:
204
190
  return self._tags_to_accept
205
191
 
206
192
  @property
207
- def tags_to_ignore(self) -> FrozenSet[Hashable]:
193
+ def tags_to_ignore(self) -> frozenset[Hashable]:
208
194
  return self._tags_to_ignore
209
195
 
210
196
  def _predicate(self, gate: raw_types.Gate) -> bool:
@@ -227,7 +213,7 @@ class GateFamily:
227
213
  )
228
214
  return isinstance(gate, self.gate)
229
215
 
230
- def __contains__(self, item: Union[raw_types.Gate, raw_types.Operation]) -> bool:
216
+ def __contains__(self, item: raw_types.Gate | raw_types.Operation) -> bool:
231
217
  if self._tags_to_accept and (
232
218
  not isinstance(item, raw_types.Operation) or self._tags_to_accept.isdisjoint(item.tags)
233
219
  ):
@@ -270,8 +256,8 @@ class GateFamily:
270
256
  self._tags_to_ignore,
271
257
  )
272
258
 
273
- def _json_dict_(self) -> Dict[str, Any]:
274
- d: Dict[str, Any] = {
259
+ def _json_dict_(self) -> dict[str, Any]:
260
+ d: dict[str, Any] = {
275
261
  'gate': self._gate_json(),
276
262
  'name': self.name,
277
263
  'description': self.description,
@@ -321,8 +307,8 @@ class Gateset:
321
307
 
322
308
  def __init__(
323
309
  self,
324
- *gates: Union[Type[raw_types.Gate], raw_types.Gate, GateFamily],
325
- name: Optional[str] = None,
310
+ *gates: type[raw_types.Gate] | raw_types.Gate | GateFamily,
311
+ name: str | None = None,
326
312
  unroll_circuit_op: bool = True,
327
313
  ) -> None:
328
314
  """Init Gateset.
@@ -346,10 +332,10 @@ class Gateset:
346
332
  """
347
333
  self._name = name
348
334
  self._unroll_circuit_op = unroll_circuit_op
349
- self._instance_gate_families: Dict[raw_types.Gate, GateFamily] = {}
350
- self._type_gate_families: Dict[Type[raw_types.Gate], GateFamily] = {}
335
+ self._instance_gate_families: dict[raw_types.Gate, GateFamily] = {}
336
+ self._type_gate_families: dict[type[raw_types.Gate], GateFamily] = {}
351
337
  self._gates_repr_str = ", ".join([_gate_str(g, repr) for g in gates])
352
- unique_gate_list: List[GateFamily] = list(
338
+ unique_gate_list: list[GateFamily] = list(
353
339
  dict.fromkeys(g if isinstance(g, GateFamily) else GateFamily(gate=g) for g in gates)
354
340
  )
355
341
 
@@ -363,15 +349,15 @@ class Gateset:
363
349
  self._gates = frozenset(unique_gate_list)
364
350
 
365
351
  @property
366
- def name(self) -> Optional[str]:
352
+ def name(self) -> str | None:
367
353
  return self._name
368
354
 
369
355
  @property
370
- def gates(self) -> FrozenSet[GateFamily]:
356
+ def gates(self) -> frozenset[GateFamily]:
371
357
  return self._gates
372
358
 
373
359
  def with_params(
374
- self, *, name: Optional[str] = None, unroll_circuit_op: Optional[bool] = None
360
+ self, *, name: str | None = None, unroll_circuit_op: bool | None = None
375
361
  ) -> Gateset:
376
362
  """Returns a copy of this Gateset with identical gates and new values for named arguments.
377
363
 
@@ -397,7 +383,7 @@ class Gateset:
397
383
  gates = self.gates
398
384
  return Gateset(*gates, name=name, unroll_circuit_op=cast(bool, unroll_circuit_op))
399
385
 
400
- def __contains__(self, item: Union[raw_types.Gate, raw_types.Operation]) -> bool:
386
+ def __contains__(self, item: raw_types.Gate | raw_types.Operation) -> bool:
401
387
  r"""Check for containment of a given Gate/Operation in this Gateset.
402
388
 
403
389
  Containment checks are handled as follows:
@@ -447,7 +433,7 @@ class Gateset:
447
433
 
448
434
  return any(item in gate_family for gate_family in self._gates)
449
435
 
450
- def validate(self, circuit_or_optree: Union[cirq.AbstractCircuit, op_tree.OP_TREE]) -> bool:
436
+ def validate(self, circuit_or_optree: cirq.AbstractCircuit | op_tree.OP_TREE) -> bool:
451
437
  """Validates gates forming `circuit_or_optree` should be contained in Gateset.
452
438
 
453
439
  Args:
@@ -512,7 +498,7 @@ class Gateset:
512
498
  header += self.name
513
499
  return f'{header}\n' + "\n\n".join([str(g) for g in self._unique_gate_list])
514
500
 
515
- def _json_dict_(self) -> Dict[str, Any]:
501
+ def _json_dict_(self) -> dict[str, Any]:
516
502
  return {
517
503
  'gates': self._unique_gate_list,
518
504
  'name': self.name,
cirq/ops/gateset_test.py CHANGED
@@ -15,7 +15,7 @@
15
15
  from __future__ import annotations
16
16
 
17
17
  import re
18
- from typing import cast, List, Tuple
18
+ from typing import cast
19
19
 
20
20
  import numpy as np
21
21
  import pytest
@@ -26,7 +26,7 @@ from cirq._compat import proper_repr
26
26
 
27
27
 
28
28
  class CustomXPowGate(cirq.EigenGate):
29
- def _eigen_components(self) -> List[Tuple[float, np.ndarray]]:
29
+ def _eigen_components(self) -> list[tuple[float, np.ndarray]]:
30
30
  return [(0, np.array([[0.5, 0.5], [0.5, 0.5]])), (1, np.array([[0.5, -0.5], [-0.5, 0.5]]))]
31
31
 
32
32
  def __str__(self) -> str:
@@ -16,7 +16,7 @@
16
16
  from __future__ import annotations
17
17
 
18
18
  from types import NotImplementedType
19
- from typing import AbstractSet, Any, cast, Collection, Dict, Optional, Sequence, Tuple, Union
19
+ from typing import AbstractSet, Any, cast, Collection, Sequence
20
20
 
21
21
  import numpy as np
22
22
  import sympy
@@ -50,12 +50,12 @@ class GlobalPhaseGate(raw_types.Gate):
50
50
  return GlobalPhaseGate(self.coefficient**power)
51
51
  return NotImplemented
52
52
 
53
- def _unitary_(self) -> Union[np.ndarray, NotImplementedType]:
53
+ def _unitary_(self) -> np.ndarray | NotImplementedType:
54
54
  if not self._has_unitary_():
55
55
  return NotImplemented
56
56
  return np.array([[self.coefficient]])
57
57
 
58
- def _apply_unitary_(self, args: cirq.ApplyUnitaryArgs) -> Union[np.ndarray, NotImplementedType]:
58
+ def _apply_unitary_(self, args: cirq.ApplyUnitaryArgs) -> np.ndarray | NotImplementedType:
59
59
  if not self._has_unitary_():
60
60
  return NotImplemented
61
61
  assert not cirq.is_parameterized(self)
@@ -74,10 +74,10 @@ class GlobalPhaseGate(raw_types.Gate):
74
74
  def _op_repr_(self, qubits: Sequence[cirq.Qid]) -> str:
75
75
  return f'cirq.global_phase_operation({proper_repr(self.coefficient)})'
76
76
 
77
- def _json_dict_(self) -> Dict[str, Any]:
77
+ def _json_dict_(self) -> dict[str, Any]:
78
78
  return protocols.obj_to_dict_helper(self, ['coefficient'])
79
79
 
80
- def _qid_shape_(self) -> Tuple[int, ...]:
80
+ def _qid_shape_(self) -> tuple[int, ...]:
81
81
  return tuple()
82
82
 
83
83
  def _is_parameterized_(self) -> bool:
@@ -94,11 +94,9 @@ class GlobalPhaseGate(raw_types.Gate):
94
94
 
95
95
  def controlled(
96
96
  self,
97
- num_controls: Optional[int] = None,
98
- control_values: Optional[
99
- Union[cv.AbstractControlValues, Sequence[Union[int, Collection[int]]]]
100
- ] = None,
101
- control_qid_shape: Optional[Tuple[int, ...]] = None,
97
+ num_controls: int | None = None,
98
+ control_values: cv.AbstractControlValues | Sequence[int | Collection[int]] | None = None,
99
+ control_qid_shape: tuple[int, ...] | None = None,
102
100
  ) -> raw_types.Gate:
103
101
  result = super().controlled(num_controls, control_values, control_qid_shape)
104
102
  if (
@@ -14,7 +14,7 @@
14
14
 
15
15
  from __future__ import annotations
16
16
 
17
- from typing import Iterable, List, Set, TYPE_CHECKING
17
+ from typing import Iterable, TYPE_CHECKING
18
18
 
19
19
  from cirq.ops import named_qubit, qid_util, qubit_manager
20
20
 
@@ -51,8 +51,8 @@ class GreedyQubitManager(qubit_manager.QubitManager):
51
51
  maximize_reuse: Flag to control a FIFO vs LIFO strategy, defaults to False (FIFO).
52
52
  """
53
53
  self._prefix = prefix
54
- self._used_qubits: Set[cirq.Qid] = set()
55
- self._free_qubits: List[cirq.Qid] = []
54
+ self._used_qubits: set[cirq.Qid] = set()
55
+ self._free_qubits: list[cirq.Qid] = []
56
56
  self._size = 0
57
57
  self.maximize_reuse = maximize_reuse
58
58
  self.resize(size)
@@ -63,13 +63,13 @@ class GreedyQubitManager(qubit_manager.QubitManager):
63
63
  def resize(self, new_size: int, dim: int = 2) -> None:
64
64
  if new_size <= self._size:
65
65
  return
66
- new_qubits: List[cirq.Qid] = [
66
+ new_qubits: list[cirq.Qid] = [
67
67
  self._allocate_qid(f'{self._prefix}_{s}', dim) for s in range(self._size, new_size)
68
68
  ]
69
69
  self._free_qubits = new_qubits + self._free_qubits
70
70
  self._size = new_size
71
71
 
72
- def qalloc(self, n: int, dim: int = 2) -> List[cirq.Qid]:
72
+ def qalloc(self, n: int, dim: int = 2) -> list[cirq.Qid]:
73
73
  if not n:
74
74
  return []
75
75
  self.resize(self._size + n - len(self._free_qubits), dim=dim)
@@ -84,5 +84,5 @@ class GreedyQubitManager(qubit_manager.QubitManager):
84
84
  self._used_qubits = self._used_qubits.difference(qs)
85
85
  self._free_qubits.extend(qs)
86
86
 
87
- def qborrow(self, n: int, dim: int = 2) -> List[cirq.Qid]:
87
+ def qborrow(self, n: int, dim: int = 2) -> list[cirq.Qid]:
88
88
  return self.qalloc(n, dim)