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
cirq/_compat.py CHANGED
@@ -28,7 +28,7 @@ import sys
28
28
  import traceback
29
29
  import warnings
30
30
  from types import ModuleType
31
- from typing import Any, Callable, Dict, Iterator, Optional, overload, Set, Tuple, Type, TypeVar
31
+ from typing import Any, Callable, Iterator, overload, TypeVar
32
32
 
33
33
  import numpy as np
34
34
  import pandas as pd
@@ -79,7 +79,7 @@ def cached_method(__func: TFunc) -> TFunc: ...
79
79
  def cached_method(*, maxsize: int = 128) -> Callable[[TFunc], TFunc]: ...
80
80
 
81
81
 
82
- def cached_method(method: Optional[TFunc] = None, *, maxsize: int = 128) -> Any:
82
+ def cached_method(method: TFunc | None = None, *, maxsize: int = 128) -> Any:
83
83
  """Decorator that adds a per-instance LRU cache for a method.
84
84
 
85
85
  Can be applied with or without parameters to customize the underlying cache:
@@ -195,7 +195,7 @@ def proper_repr(value: Any) -> str:
195
195
  f'\n)'
196
196
  )
197
197
 
198
- if isinstance(value, Dict):
198
+ if isinstance(value, dict):
199
199
  return '{' + ','.join(f"{proper_repr(k)}: {proper_repr(v)}" for k, v in value.items()) + '}'
200
200
 
201
201
  if hasattr(value, "__qualname__"):
@@ -288,7 +288,7 @@ def _validate_deadline(deadline: str):
288
288
 
289
289
 
290
290
  def deprecated(
291
- *, deadline: str, fix: str, name: Optional[str] = None
291
+ *, deadline: str, fix: str, name: str | None = None
292
292
  ) -> Callable[[Callable], Callable]:
293
293
  """Marks a function as deprecated.
294
294
 
@@ -329,9 +329,7 @@ def deprecated(
329
329
  return decorator
330
330
 
331
331
 
332
- def deprecated_class(
333
- *, deadline: str, fix: str, name: Optional[str] = None
334
- ) -> Callable[[Type], Type]:
332
+ def deprecated_class(*, deadline: str, fix: str, name: str | None = None) -> Callable[[type], type]:
335
333
  """Marks a class as deprecated.
336
334
 
337
335
  Args:
@@ -348,7 +346,7 @@ def deprecated_class(
348
346
 
349
347
  _validate_deadline(deadline)
350
348
 
351
- def decorator(clazz: Type) -> Type:
349
+ def decorator(clazz: type) -> type:
352
350
  clazz_new = clazz.__new__
353
351
 
354
352
  def patched_new(cls, *args, **kwargs):
@@ -378,12 +376,12 @@ def deprecated_parameter(
378
376
  *,
379
377
  deadline: str,
380
378
  fix: str,
381
- func_name: Optional[str] = None,
379
+ func_name: str | None = None,
382
380
  parameter_desc: str,
383
- match: Callable[[Tuple[Any, ...], Dict[str, Any]], bool],
384
- rewrite: Optional[
385
- Callable[[Tuple[Any, ...], Dict[str, Any]], Tuple[Tuple[Any, ...], Dict[str, Any]]]
386
- ] = None,
381
+ match: Callable[[tuple[Any, ...], dict[str, Any]], bool],
382
+ rewrite: (
383
+ Callable[[tuple[Any, ...], dict[str, Any]], tuple[tuple[Any, ...], dict[str, Any]]] | None
384
+ ) = None,
387
385
  ) -> Callable[[Callable], Callable]:
388
386
  """Marks a function parameter as deprecated.
389
387
 
@@ -447,7 +445,7 @@ def deprecated_parameter(
447
445
  return decorator
448
446
 
449
447
 
450
- def deprecate_attributes(module_name: str, deprecated_attributes: Dict[str, Tuple[str, str]]):
448
+ def deprecate_attributes(module_name: str, deprecated_attributes: dict[str, tuple[str, str]]):
451
449
  """Replace module with a wrapper that gives warnings for deprecated attributes.
452
450
 
453
451
  Args:
@@ -586,7 +584,7 @@ def _is_internal(filename: str) -> bool:
586
584
  return 'importlib' in filename and '_bootstrap' in filename
587
585
 
588
586
 
589
- _warned: Set[str] = set()
587
+ _warned: set[str] = set()
590
588
 
591
589
 
592
590
  def _called_from_test() -> bool:
@@ -635,7 +633,7 @@ class DeprecatedModuleFinder(importlib.abc.MetaPathFinder):
635
633
  new_module_name: str,
636
634
  old_module_name: str,
637
635
  deadline: str,
638
- broken_module_exception: Optional[BaseException],
636
+ broken_module_exception: BaseException | None,
639
637
  ):
640
638
  """An aliasing module finder that uses existing module finders to find a python
641
639
  module spec and intercept the execution of matching modules.
@@ -763,7 +761,7 @@ def _setup_deprecated_submodule_attribute(
763
761
  old_parent: str,
764
762
  old_child: str,
765
763
  deadline: str,
766
- new_module: Optional[ModuleType],
764
+ new_module: ModuleType | None,
767
765
  ):
768
766
  parent_module = sys.modules[old_parent]
769
767
  setattr(parent_module, old_child, new_module)
cirq/_compat_test.py CHANGED
@@ -27,7 +27,7 @@ import types
27
27
  import warnings
28
28
  from importlib.machinery import ModuleSpec
29
29
  from types import ModuleType
30
- from typing import Any, Callable, Dict, Optional, Tuple
30
+ from typing import Any, Callable
31
31
  from unittest import mock
32
32
 
33
33
  import duet
@@ -764,7 +764,6 @@ def test_metadata_search_path():
764
764
  def _test_metadata_search_path_inner(): # pragma: no cover
765
765
  # initialize the DeprecatedModuleFinders
766
766
  # pylint: disable=unused-import
767
- import cirq.testing._compat_test_data.module_a
768
767
 
769
768
  assert importlib.metadata.metadata('numpy')
770
769
 
@@ -882,8 +881,6 @@ def _test_new_module_is_top_level_inner():
882
881
  # imports a top level module that was also deprecated
883
882
  from freezegun import api
884
883
 
885
- import cirq.testing._compat_test_data
886
-
887
884
  assert api.real_time == time.time
888
885
 
889
886
 
@@ -925,7 +922,7 @@ def test_loader_create_module():
925
922
  fake_mod = ModuleType('hello')
926
923
 
927
924
  class CreateModuleLoader(importlib.abc.Loader):
928
- def create_module(self, spec: ModuleSpec) -> Optional[ModuleType]:
925
+ def create_module(self, spec: ModuleSpec) -> ModuleType | None:
929
926
  return fake_mod
930
927
 
931
928
  assert (
@@ -1017,16 +1014,16 @@ def test_block_overlapping_deprecation():
1017
1014
 
1018
1015
  class Bar:
1019
1016
  def __init__(self) -> None:
1020
- self.foo_calls: Dict[int, int] = collections.Counter()
1021
- self.bar_calls: Dict[int, int] = collections.Counter()
1017
+ self.foo_calls: dict[int, int] = collections.Counter()
1018
+ self.bar_calls: dict[int, int] = collections.Counter()
1022
1019
 
1023
1020
  @cached_method
1024
- def foo(self, n: int) -> Tuple[int, int]:
1021
+ def foo(self, n: int) -> tuple[int, int]:
1025
1022
  self.foo_calls[n] += 1
1026
1023
  return (id(self), n)
1027
1024
 
1028
1025
  @cached_method(maxsize=1)
1029
- def bar(self, n: int) -> Tuple[int, int]:
1026
+ def bar(self, n: int) -> tuple[int, int]:
1030
1027
  self.bar_calls[n] += 1
1031
1028
  return (id(self), 2 * n)
1032
1029
 
cirq/_doc.py CHANGED
@@ -15,9 +15,9 @@
15
15
 
16
16
  from __future__ import annotations
17
17
 
18
- from typing import Any, Dict
18
+ from typing import Any
19
19
 
20
- RECORDED_CONST_DOCS: Dict[int, str] = {}
20
+ RECORDED_CONST_DOCS: dict[int, str] = {}
21
21
 
22
22
 
23
23
  def document(value: Any, doc_string: str = ''):
cirq/_import.py CHANGED
@@ -21,7 +21,7 @@ from importlib import abc
21
21
  from importlib.abc import Loader
22
22
  from importlib.machinery import ModuleSpec
23
23
  from types import ModuleType
24
- from typing import Any, Callable, cast, List, Optional
24
+ from typing import Any, Callable, cast
25
25
 
26
26
 
27
27
  class InstrumentedFinder(abc.MetaPathFinder):
@@ -31,7 +31,7 @@ class InstrumentedFinder(abc.MetaPathFinder):
31
31
  self,
32
32
  finder: Any,
33
33
  module_name: str,
34
- wrap_module: Callable[[ModuleType], Optional[ModuleType]],
34
+ wrap_module: Callable[[ModuleType], ModuleType | None],
35
35
  after_exec: Callable[[ModuleType], None],
36
36
  ):
37
37
  """A module finder that uses an existing module finder to find a python
@@ -56,7 +56,7 @@ class InstrumentedFinder(abc.MetaPathFinder):
56
56
 
57
57
  self.finder = finder
58
58
  self.module_name = module_name
59
- self.match_components: List[str] = []
59
+ self.match_components: list[str] = []
60
60
  if self.module_name:
61
61
  self.match_components = self.module_name.split('.')
62
62
  self.wrap_module = wrap_module
@@ -82,7 +82,7 @@ class InstrumentedLoader(abc.Loader):
82
82
  def __init__(
83
83
  self,
84
84
  loader: Any,
85
- wrap_module: Callable[[ModuleType], Optional[ModuleType]],
85
+ wrap_module: Callable[[ModuleType], ModuleType | None],
86
86
  after_exec: Callable[[ModuleType], None],
87
87
  ):
88
88
  """A module loader that uses an existing module loader and intercepts
@@ -121,7 +121,7 @@ class InstrumentedLoader(abc.Loader):
121
121
  @contextmanager
122
122
  def wrap_module_executions(
123
123
  module_name: str,
124
- wrap_func: Callable[[ModuleType], Optional[ModuleType]],
124
+ wrap_func: Callable[[ModuleType], ModuleType | None],
125
125
  after_exec: Callable[[ModuleType], None] = lambda m: None,
126
126
  assert_meta_path_unchanged: bool = True,
127
127
  ):
@@ -157,7 +157,7 @@ def delay_import(module_name: str):
157
157
  delay = True
158
158
  execute_list = []
159
159
 
160
- def wrap_func(module: ModuleType) -> Optional[ModuleType]:
160
+ def wrap_func(module: ModuleType) -> ModuleType | None:
161
161
  if delay:
162
162
  execute_list.append(module)
163
163
  return None # Don't allow the module to be executed yet
cirq/_version.py CHANGED
@@ -28,4 +28,4 @@ if sys.version_info < (3, 11, 0): # pragma: no cover
28
28
  'of cirq (e.g. "python -m pip install cirq==1.5.0")'
29
29
  )
30
30
 
31
- __version__ = "1.6.0.dev20250520054601"
31
+ __version__ = "1.6.0.dev20250520181654"
cirq/_version_test.py CHANGED
@@ -3,4 +3,4 @@ import cirq
3
3
 
4
4
 
5
5
  def test_version() -> None:
6
- assert cirq.__version__ == "1.6.0.dev20250520054601"
6
+ assert cirq.__version__ == "1.6.0.dev20250520181654"
@@ -15,7 +15,6 @@
15
15
  from __future__ import annotations
16
16
 
17
17
  import collections
18
- from typing import Dict, List, Optional, Tuple
19
18
 
20
19
  from cirq.circuits._box_drawing_character_data import box_draw_character, BoxDrawCharacterSet
21
20
 
@@ -57,7 +56,7 @@ class Block:
57
56
  left: bool = False,
58
57
  right: bool = False,
59
58
  bottom: bool = False,
60
- crossing_char: Optional[str] = None,
59
+ crossing_char: str | None = None,
61
60
  ):
62
61
  """Draws lines in the box using the given character set.
63
62
 
@@ -107,7 +106,7 @@ class Block:
107
106
 
108
107
  self._prev_curve_grid_chars = grid_characters
109
108
 
110
- def render(self, width: int, height: int) -> List[str]:
109
+ def render(self, width: int, height: int) -> list[str]:
111
110
  """Returns a list of text lines representing the block's contents.
112
111
 
113
112
  Args:
@@ -159,9 +158,9 @@ class BlockDiagramDrawer:
159
158
  """Aligns text and curve data placed onto an abstract 2d grid of blocks."""
160
159
 
161
160
  def __init__(self) -> None:
162
- self._blocks: Dict[Tuple[int, int], Block] = collections.defaultdict(Block)
163
- self._min_widths: Dict[int, int] = collections.defaultdict(lambda: 0)
164
- self._min_heights: Dict[int, int] = collections.defaultdict(lambda: 0)
161
+ self._blocks: dict[tuple[int, int], Block] = collections.defaultdict(Block)
162
+ self._min_widths: dict[int, int] = collections.defaultdict(lambda: 0)
163
+ self._min_heights: dict[int, int] = collections.defaultdict(lambda: 0)
165
164
 
166
165
  # Populate the origin.
167
166
  _ = self._blocks[(0, 0)]
@@ -189,8 +188,8 @@ class BlockDiagramDrawer:
189
188
  def render(
190
189
  self,
191
190
  *,
192
- block_span_x: Optional[int] = None,
193
- block_span_y: Optional[int] = None,
191
+ block_span_x: int | None = None,
192
+ block_span_y: int | None = None,
194
193
  min_block_width: int = 0,
195
194
  min_block_height: int = 0,
196
195
  ) -> str:
@@ -252,10 +251,10 @@ class BlockDiagramDrawer:
252
251
  }
253
252
 
254
253
  # Paste together all of the rows of rendered block content.
255
- out_lines: List[str] = []
254
+ out_lines: list[str] = []
256
255
  for y in range(block_span_y):
257
256
  for by in range(heights[y]):
258
- out_line_chunks: List[str] = []
257
+ out_line_chunks: list[str] = []
259
258
  for x in range(block_span_x):
260
259
  out_line_chunks.extend(block_renders[x, y][by])
261
260
  out_lines.append(''.join(out_line_chunks).rstrip())
@@ -16,7 +16,7 @@
16
16
 
17
17
  from __future__ import annotations
18
18
 
19
- from typing import List, NamedTuple, Optional
19
+ from typing import NamedTuple
20
20
 
21
21
  _BoxDrawCharacterSet = NamedTuple(
22
22
  '_BoxDrawCharacterSet',
@@ -43,7 +43,7 @@ _BoxDrawCharacterSet = NamedTuple(
43
43
  class BoxDrawCharacterSet(_BoxDrawCharacterSet):
44
44
  def char(
45
45
  self, top: bool = False, bottom: bool = False, left: bool = False, right: bool = False
46
- ) -> Optional[str]:
46
+ ) -> str | None:
47
47
  parts = []
48
48
  if top:
49
49
  parts.append('top')
@@ -118,10 +118,8 @@ _MixedBoxDrawCharacterSet = NamedTuple(
118
118
 
119
119
 
120
120
  class MixedBoxDrawCharacterSet(_MixedBoxDrawCharacterSet):
121
- def char(
122
- self, *, top: int = 0, bottom: int = 0, left: int = 0, right: int = 0
123
- ) -> Optional[str]:
124
- def parts_with(val: int) -> List[str]:
121
+ def char(self, *, top: int = 0, bottom: int = 0, left: int = 0, right: int = 0) -> str | None:
122
+ def parts_with(val: int) -> list[str]:
125
123
  parts = []
126
124
  if top == val:
127
125
  parts.append('top')
@@ -340,14 +338,14 @@ NORMAL_THEN_DOUBLED_MIXED_BOX_CHARS = MixedBoxDrawCharacterSet(
340
338
 
341
339
 
342
340
  def box_draw_character(
343
- first: Optional[BoxDrawCharacterSet],
341
+ first: BoxDrawCharacterSet | None,
344
342
  second: BoxDrawCharacterSet,
345
343
  *,
346
344
  top: int = 0,
347
345
  bottom: int = 0,
348
346
  left: int = 0,
349
347
  right: int = 0,
350
- ) -> Optional[str]:
348
+ ) -> str | None:
351
349
  """Finds a box drawing character based on its connectivity.
352
350
 
353
351
  For example:
@@ -14,7 +14,7 @@
14
14
 
15
15
  from __future__ import annotations
16
16
 
17
- from typing import Any, Generic, Iterable, Iterator, List, Optional, Set, Tuple, TypeVar
17
+ from typing import Any, Generic, Iterable, Iterator, TypeVar
18
18
 
19
19
  TItem = TypeVar('TItem')
20
20
 
@@ -39,7 +39,7 @@ class BucketPriorityQueue(Generic[TItem]):
39
39
  """
40
40
 
41
41
  def __init__(
42
- self, entries: Iterable[Tuple[int, TItem]] = (), *, drop_duplicate_entries: bool = False
42
+ self, entries: Iterable[tuple[int, TItem]] = (), *, drop_duplicate_entries: bool = False
43
43
  ):
44
44
  """Initializes a new priority queue.
45
45
 
@@ -50,10 +50,10 @@ class BucketPriorityQueue(Generic[TItem]):
50
50
  in the priority queue. Note that duplicates of an item may still
51
51
  be enqueued, as long as they have different priorities.
52
52
  """
53
- self._buckets: List[List[TItem]] = []
53
+ self._buckets: list[list[TItem]] = []
54
54
  self._offset = 0
55
55
  self._len = 0
56
- self._drop_set: Optional[Set[Tuple[int, TItem]]] = set() if drop_duplicate_entries else None
56
+ self._drop_set: set[tuple[int, TItem]] | None = set() if drop_duplicate_entries else None
57
57
 
58
58
  for p, e in entries:
59
59
  self.enqueue(p, e)
@@ -70,7 +70,7 @@ class BucketPriorityQueue(Generic[TItem]):
70
70
  """Returns how many items are in the priority queue."""
71
71
  return self._len
72
72
 
73
- def __iter__(self) -> Iterator[Tuple[int, TItem]]:
73
+ def __iter__(self) -> Iterator[tuple[int, TItem]]:
74
74
  """Iterates the (priority, item) entries in the queue."""
75
75
  for i, bucket in enumerate(self._buckets):
76
76
  for item in bucket:
@@ -122,7 +122,7 @@ class BucketPriorityQueue(Generic[TItem]):
122
122
  self._len += 1
123
123
  return True
124
124
 
125
- def dequeue(self) -> Tuple[int, TItem]:
125
+ def dequeue(self) -> tuple[int, TItem]:
126
126
  """Removes and returns an item from the priority queue.
127
127
 
128
128
  Returns:
@@ -180,6 +180,6 @@ class BucketPriorityQueue(Generic[TItem]):
180
180
  return not self == other
181
181
 
182
182
 
183
- def _indent(lines: List[Any]) -> str:
183
+ def _indent(lines: list[Any]) -> str:
184
184
  paragraph = ''.join('\n' + str(line) for line in lines)
185
185
  return paragraph.replace('\n', '\n ')