cirq-core 1.7.0.dev20250924231107__py3-none-any.whl → 1.7.0.dev20251203004401__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.
Files changed (392) hide show
  1. cirq/__init__.py +1 -0
  2. cirq/_compat.py +3 -2
  3. cirq/_compat_test.py +16 -15
  4. cirq/_doc.py +4 -3
  5. cirq/_import.py +2 -1
  6. cirq/_version.py +1 -1
  7. cirq/_version_test.py +1 -1
  8. cirq/circuits/_bucket_priority_queue.py +2 -1
  9. cirq/circuits/circuit.py +7 -13
  10. cirq/circuits/circuit_operation.py +2 -1
  11. cirq/circuits/circuit_test.py +13 -12
  12. cirq/circuits/frozen_circuit.py +3 -2
  13. cirq/circuits/moment.py +3 -15
  14. cirq/circuits/optimization_pass.py +2 -1
  15. cirq/circuits/qasm_output.py +39 -10
  16. cirq/circuits/qasm_output_test.py +51 -2
  17. cirq/circuits/text_diagram_drawer.py +2 -1
  18. cirq/contrib/acquaintance/bipartite.py +2 -1
  19. cirq/contrib/acquaintance/devices.py +1 -1
  20. cirq/contrib/acquaintance/executor.py +4 -5
  21. cirq/contrib/acquaintance/executor_test.py +2 -1
  22. cirq/contrib/acquaintance/gates.py +2 -1
  23. cirq/contrib/acquaintance/gates_test.py +1 -1
  24. cirq/contrib/acquaintance/inspection_utils.py +2 -1
  25. cirq/contrib/acquaintance/mutation_utils.py +2 -1
  26. cirq/contrib/acquaintance/optimizers.py +2 -1
  27. cirq/contrib/acquaintance/permutation.py +2 -1
  28. cirq/contrib/acquaintance/permutation_test.py +1 -1
  29. cirq/contrib/acquaintance/shift.py +2 -1
  30. cirq/contrib/acquaintance/shift_swap_network.py +2 -1
  31. cirq/contrib/acquaintance/strategies/complete.py +3 -2
  32. cirq/contrib/acquaintance/strategies/cubic.py +2 -1
  33. cirq/contrib/acquaintance/strategies/quartic_paired.py +2 -1
  34. cirq/contrib/acquaintance/strategies/quartic_paired_test.py +1 -1
  35. cirq/contrib/acquaintance/testing.py +2 -1
  36. cirq/contrib/acquaintance/topological_sort.py +2 -1
  37. cirq/contrib/bayesian_network/bayesian_network_gate.py +3 -2
  38. cirq/contrib/circuitdag/circuit_dag.py +4 -2
  39. cirq/contrib/custom_simulators/custom_state_simulator.py +2 -1
  40. cirq/contrib/custom_simulators/custom_state_simulator_test.py +1 -1
  41. cirq/contrib/graph_device/graph_device.py +2 -1
  42. cirq/contrib/graph_device/graph_device_test.py +2 -1
  43. cirq/contrib/graph_device/hypergraph.py +2 -1
  44. cirq/contrib/graph_device/uniform_graph_device.py +2 -1
  45. cirq/contrib/json.py +14 -2
  46. cirq/contrib/json_test_data/BayesianNetworkGate.json +10 -0
  47. cirq/contrib/json_test_data/BayesianNetworkGate.repr +3 -0
  48. cirq/contrib/json_test_data/QuantumVolumeResult.json +169 -0
  49. cirq/contrib/json_test_data/QuantumVolumeResult.repr +22 -0
  50. cirq/contrib/json_test_data/SwapPermutationGate.json +3 -0
  51. cirq/contrib/json_test_data/SwapPermutationGate.repr +1 -0
  52. cirq/contrib/json_test_data/spec.py +0 -2
  53. cirq/contrib/noise_models/noise_models.py +2 -1
  54. cirq/contrib/paulistring/clifford_optimize.py +20 -2
  55. cirq/contrib/paulistring/optimize.py +1 -1
  56. cirq/contrib/paulistring/pauli_string_measurement_with_readout_mitigation.py +146 -35
  57. cirq/contrib/paulistring/pauli_string_measurement_with_readout_mitigation_test.py +74 -171
  58. cirq/contrib/paulistring/recombine.py +5 -2
  59. cirq/contrib/paulistring/separate.py +1 -1
  60. cirq/contrib/qasm_import/_parser.py +2 -1
  61. cirq/contrib/qasm_import/_parser_test.py +3 -3
  62. cirq/contrib/quantikz/__init__.py +21 -0
  63. cirq/contrib/quantikz/circuit_to_latex_quantikz.py +680 -0
  64. cirq/contrib/quantikz/circuit_to_latex_quantikz_test.py +253 -0
  65. cirq/contrib/quantikz/circuit_to_latex_render.py +424 -0
  66. cirq/contrib/quantikz/circuit_to_latex_render_test.py +44 -0
  67. cirq/contrib/quantum_volume/quantum_volume.py +2 -1
  68. cirq/contrib/quimb/density_matrix.py +1 -1
  69. cirq/contrib/quimb/grid_circuits.py +2 -1
  70. cirq/contrib/quimb/grid_circuits_test.py +1 -1
  71. cirq/contrib/quimb/mps_simulator.py +4 -3
  72. cirq/contrib/quimb/state_vector.py +2 -1
  73. cirq/contrib/quirk/export_to_quirk.py +2 -1
  74. cirq/contrib/quirk/linearize_circuit.py +1 -1
  75. cirq/contrib/quirk/quirk_gate.py +2 -1
  76. cirq/contrib/routing/device.py +1 -1
  77. cirq/contrib/routing/greedy.py +2 -1
  78. cirq/contrib/routing/initialization.py +2 -1
  79. cirq/contrib/routing/router.py +2 -1
  80. cirq/contrib/routing/swap_network.py +2 -1
  81. cirq/contrib/routing/utils.py +2 -1
  82. cirq/contrib/shuffle_circuits/shuffle_circuits_with_readout_benchmarking.py +7 -5
  83. cirq/contrib/shuffle_circuits/shuffle_circuits_with_readout_benchmarking_test.py +6 -6
  84. cirq/devices/device.py +2 -1
  85. cirq/devices/grid_device_metadata.py +2 -1
  86. cirq/devices/grid_qubit.py +7 -6
  87. cirq/devices/insertion_noise_model.py +2 -1
  88. cirq/devices/line_qubit.py +2 -1
  89. cirq/devices/named_topologies.py +2 -1
  90. cirq/devices/noise_model.py +2 -1
  91. cirq/devices/noise_model_test.py +1 -1
  92. cirq/devices/noise_properties.py +2 -1
  93. cirq/devices/superconducting_qubits_noise_properties_test.py +2 -1
  94. cirq/devices/thermal_noise_model.py +2 -1
  95. cirq/experiments/__init__.py +2 -0
  96. cirq/experiments/benchmarking/parallel_xeb.py +2 -1
  97. cirq/experiments/benchmarking/parallel_xeb_test.py +1 -1
  98. cirq/experiments/fidelity_estimation.py +2 -1
  99. cirq/experiments/fidelity_estimation_test.py +1 -1
  100. cirq/experiments/ghz_2d.py +150 -0
  101. cirq/experiments/ghz_2d_test.py +155 -0
  102. cirq/experiments/n_qubit_tomography.py +2 -1
  103. cirq/experiments/n_qubit_tomography_test.py +1 -1
  104. cirq/experiments/purity_estimation.py +1 -1
  105. cirq/experiments/qubit_characterizations.py +2 -1
  106. cirq/experiments/random_quantum_circuit_generation.py +2 -1
  107. cirq/experiments/random_quantum_circuit_generation_test.py +2 -1
  108. cirq/experiments/readout_confusion_matrix.py +2 -1
  109. cirq/experiments/readout_confusion_matrix_test.py +1 -1
  110. cirq/experiments/single_qubit_readout_calibration.py +2 -1
  111. cirq/experiments/single_qubit_readout_calibration_test.py +1 -1
  112. cirq/experiments/t1_decay_experiment.py +2 -1
  113. cirq/experiments/two_qubit_xeb.py +2 -1
  114. cirq/experiments/two_qubit_xeb_test.py +1 -1
  115. cirq/experiments/xeb_fitting.py +2 -1
  116. cirq/experiments/xeb_fitting_test.py +1 -1
  117. cirq/experiments/xeb_sampling.py +5 -3
  118. cirq/experiments/xeb_sampling_test.py +1 -1
  119. cirq/experiments/xeb_simulation.py +2 -1
  120. cirq/experiments/xeb_simulation_test.py +2 -1
  121. cirq/experiments/z_phase_calibration.py +2 -1
  122. cirq/experiments/z_phase_calibration_test.py +18 -3
  123. cirq/interop/quirk/cells/__init__.py +1 -2
  124. cirq/interop/quirk/cells/all_cells.py +2 -1
  125. cirq/interop/quirk/cells/arithmetic_cells.py +2 -1
  126. cirq/interop/quirk/cells/cell.py +2 -1
  127. cirq/interop/quirk/cells/composite_cell.py +2 -1
  128. cirq/interop/quirk/cells/composite_cell_test.py +1 -1
  129. cirq/interop/quirk/cells/control_cells.py +2 -1
  130. cirq/interop/quirk/cells/frequency_space_cells.py +1 -1
  131. cirq/interop/quirk/cells/ignored_cells.py +1 -1
  132. cirq/interop/quirk/cells/input_cells.py +2 -1
  133. cirq/interop/quirk/cells/input_rotation_cells.py +2 -1
  134. cirq/interop/quirk/cells/measurement_cells.py +2 -1
  135. cirq/interop/quirk/cells/parse.py +2 -11
  136. cirq/interop/quirk/cells/qubit_permutation_cells.py +2 -1
  137. cirq/interop/quirk/cells/scalar_cells.py +2 -1
  138. cirq/interop/quirk/cells/single_qubit_rotation_cells.py +2 -1
  139. cirq/interop/quirk/cells/swap_cell.py +2 -1
  140. cirq/interop/quirk/cells/unsupported_cells.py +1 -1
  141. cirq/interop/quirk/url_to_circuit.py +2 -1
  142. cirq/json_resolver_cache.py +0 -2
  143. cirq/linalg/decompositions.py +6 -2
  144. cirq/linalg/decompositions_test.py +1 -0
  145. cirq/linalg/diagonalize.py +1 -1
  146. cirq/linalg/predicates.py +2 -1
  147. cirq/linalg/tolerance.py +2 -1
  148. cirq/linalg/transformations.py +2 -1
  149. cirq/ops/arithmetic_operation.py +2 -1
  150. cirq/ops/arithmetic_operation_test.py +1 -1
  151. cirq/ops/boolean_hamiltonian.py +4 -3
  152. cirq/ops/classically_controlled_operation.py +3 -2
  153. cirq/ops/clifford_gate.py +2 -1
  154. cirq/ops/clifford_gate_test.py +1 -2
  155. cirq/ops/common_channels.py +2 -1
  156. cirq/ops/common_gates.py +2 -1
  157. cirq/ops/control_values.py +2 -1
  158. cirq/ops/controlled_gate.py +3 -2
  159. cirq/ops/controlled_gate_test.py +2 -1
  160. cirq/ops/controlled_operation.py +3 -2
  161. cirq/ops/controlled_operation_test.py +2 -1
  162. cirq/ops/dense_pauli_string.py +3 -13
  163. cirq/ops/diagonal_gate.py +3 -2
  164. cirq/ops/eigen_gate.py +9 -7
  165. cirq/ops/fourier_transform.py +3 -2
  166. cirq/ops/fourier_transform_test.py +2 -4
  167. cirq/ops/fsim_gate.py +3 -2
  168. cirq/ops/gate_operation.py +8 -12
  169. cirq/ops/gateset.py +22 -2
  170. cirq/ops/global_phase_op.py +3 -2
  171. cirq/ops/greedy_qubit_manager.py +2 -1
  172. cirq/ops/identity.py +2 -1
  173. cirq/ops/kraus_channel.py +2 -1
  174. cirq/ops/linear_combinations.py +8 -3
  175. cirq/ops/linear_combinations_test.py +23 -1
  176. cirq/ops/matrix_gates.py +2 -1
  177. cirq/ops/measure_util.py +2 -1
  178. cirq/ops/measurement_gate.py +2 -1
  179. cirq/ops/mixed_unitary_channel.py +2 -1
  180. cirq/ops/named_qubit.py +2 -2
  181. cirq/ops/op_tree.py +2 -1
  182. cirq/ops/parallel_gate.py +3 -2
  183. cirq/ops/parity_gates.py +2 -1
  184. cirq/ops/pauli_interaction_gate.py +2 -1
  185. cirq/ops/pauli_measurement_gate.py +2 -1
  186. cirq/ops/pauli_string.py +6 -12
  187. cirq/ops/pauli_string_phasor.py +3 -2
  188. cirq/ops/pauli_string_raw_types.py +2 -1
  189. cirq/ops/pauli_string_test.py +2 -2
  190. cirq/ops/pauli_sum_exponential.py +2 -1
  191. cirq/ops/permutation_gate.py +2 -1
  192. cirq/ops/phased_iswap_gate.py +3 -2
  193. cirq/ops/phased_x_gate.py +5 -4
  194. cirq/ops/phased_x_z_gate.py +12 -5
  195. cirq/ops/projector.py +2 -1
  196. cirq/ops/qubit_manager.py +2 -1
  197. cirq/ops/qubit_order.py +2 -1
  198. cirq/ops/qubit_order_or_list.py +1 -1
  199. cirq/ops/random_gate_channel.py +3 -2
  200. cirq/ops/raw_types.py +7 -15
  201. cirq/ops/raw_types_test.py +4 -3
  202. cirq/ops/state_preparation_channel.py +2 -1
  203. cirq/ops/three_qubit_gates.py +3 -2
  204. cirq/ops/two_qubit_diagonal_gate.py +3 -2
  205. cirq/ops/uniform_superposition_gate.py +2 -1
  206. cirq/ops/wait_gate.py +10 -4
  207. cirq/protocols/act_on_protocol.py +2 -1
  208. cirq/protocols/act_on_protocol_test.py +2 -1
  209. cirq/protocols/apply_channel_protocol.py +2 -1
  210. cirq/protocols/apply_mixture_protocol.py +2 -1
  211. cirq/protocols/apply_mixture_protocol_test.py +2 -1
  212. cirq/protocols/apply_unitary_protocol.py +2 -1
  213. cirq/protocols/apply_unitary_protocol_test.py +2 -0
  214. cirq/protocols/approximate_equality_protocol.py +2 -1
  215. cirq/protocols/circuit_diagram_info_protocol.py +2 -1
  216. cirq/protocols/decompose_protocol.py +2 -12
  217. cirq/protocols/has_stabilizer_effect_protocol.py +1 -1
  218. cirq/protocols/hash_from_pickle_test.py +2 -2
  219. cirq/protocols/inverse_protocol.py +2 -1
  220. cirq/protocols/json_serialization.py +2 -1
  221. cirq/protocols/kraus_protocol.py +4 -3
  222. cirq/protocols/kraus_protocol_test.py +2 -2
  223. cirq/protocols/measurement_key_protocol.py +2 -1
  224. cirq/protocols/mixture_protocol.py +2 -1
  225. cirq/protocols/pow_protocol.py +2 -1
  226. cirq/protocols/qasm.py +2 -1
  227. cirq/protocols/qid_shape_protocol.py +2 -1
  228. cirq/protocols/resolve_parameters.py +16 -14
  229. cirq/protocols/trace_distance_bound.py +2 -1
  230. cirq/protocols/unitary_protocol.py +21 -21
  231. cirq/qis/channels.py +1 -1
  232. cirq/qis/channels_test.py +1 -1
  233. cirq/qis/clifford_tableau.py +2 -1
  234. cirq/qis/entropy.py +2 -2
  235. cirq/qis/quantum_state_representation.py +2 -1
  236. cirq/qis/states.py +7 -2
  237. cirq/sim/classical_simulator.py +2 -1
  238. cirq/sim/clifford/clifford_simulator.py +2 -1
  239. cirq/sim/clifford/clifford_simulator_test.py +1 -1
  240. cirq/sim/clifford/clifford_tableau_simulation_state.py +2 -1
  241. cirq/sim/clifford/stabilizer_ch_form_simulation_state.py +2 -1
  242. cirq/sim/clifford/stabilizer_sampler.py +1 -1
  243. cirq/sim/clifford/stabilizer_simulation_state.py +2 -1
  244. cirq/sim/clifford/stabilizer_state_ch_form.py +3 -2
  245. cirq/sim/clifford/stabilizer_state_ch_form_test.py +0 -1
  246. cirq/sim/density_matrix_simulation_state.py +2 -1
  247. cirq/sim/density_matrix_simulator.py +2 -1
  248. cirq/sim/density_matrix_utils.py +2 -1
  249. cirq/sim/mux.py +2 -1
  250. cirq/sim/mux_test.py +0 -1
  251. cirq/sim/simulation_product_state.py +2 -1
  252. cirq/sim/simulation_product_state_test.py +2 -1
  253. cirq/sim/simulation_state.py +2 -1
  254. cirq/sim/simulation_state_base.py +2 -1
  255. cirq/sim/simulation_state_test.py +2 -1
  256. cirq/sim/simulation_utils.py +2 -1
  257. cirq/sim/simulator.py +2 -1
  258. cirq/sim/simulator_base.py +2 -1
  259. cirq/sim/simulator_base_test.py +2 -1
  260. cirq/sim/simulator_test.py +2 -1
  261. cirq/sim/sparse_simulator.py +2 -1
  262. cirq/sim/state_vector.py +2 -1
  263. cirq/sim/state_vector_simulation_state.py +2 -1
  264. cirq/sim/state_vector_simulator.py +2 -1
  265. cirq/sim/state_vector_test.py +1 -2
  266. cirq/study/__init__.py +1 -0
  267. cirq/study/flatten_expressions.py +2 -1
  268. cirq/study/resolver.py +31 -18
  269. cirq/study/resolver_test.py +1 -1
  270. cirq/study/result.py +2 -1
  271. cirq/study/sweepable.py +2 -1
  272. cirq/study/sweeps.py +26 -1
  273. cirq/study/sweeps_test.py +24 -0
  274. cirq/testing/_compat_test_data/__init__.py +3 -3
  275. cirq/testing/circuit_compare.py +2 -1
  276. cirq/testing/consistent_act_on_test.py +1 -1
  277. cirq/testing/consistent_controlled_gate_op.py +1 -1
  278. cirq/testing/consistent_controlled_gate_op_test.py +2 -1
  279. cirq/testing/consistent_protocols.py +2 -1
  280. cirq/testing/consistent_protocols_test.py +3 -3
  281. cirq/testing/consistent_qasm.py +2 -1
  282. cirq/testing/consistent_resolve_parameters.py +1 -1
  283. cirq/testing/consistent_unitary.py +1 -1
  284. cirq/testing/consistent_unitary_test.py +1 -1
  285. cirq/testing/deprecation.py +1 -1
  286. cirq/testing/devices.py +3 -2
  287. cirq/testing/equals_tester.py +4 -3
  288. cirq/testing/equivalent_basis_map.py +4 -2
  289. cirq/testing/json.py +3 -2
  290. cirq/testing/logs.py +1 -1
  291. cirq/testing/op_tree.py +1 -1
  292. cirq/testing/order_tester.py +2 -2
  293. cirq/testing/pytest_utils.py +2 -1
  294. cirq/testing/random_circuit.py +2 -1
  295. cirq/testing/random_circuit_test.py +2 -1
  296. cirq/testing/repr_pretty_tester.py +3 -3
  297. cirq/transformers/__init__.py +1 -0
  298. cirq/transformers/_connected_component.py +231 -0
  299. cirq/transformers/_connected_component_test.py +200 -0
  300. cirq/transformers/align_test.py +13 -13
  301. cirq/transformers/analytical_decompositions/clifford_decomposition.py +8 -7
  302. cirq/transformers/analytical_decompositions/clifford_decomposition_test.py +5 -5
  303. cirq/transformers/analytical_decompositions/controlled_gate_decomposition.py +11 -10
  304. cirq/transformers/analytical_decompositions/controlled_gate_decomposition_test.py +6 -6
  305. cirq/transformers/analytical_decompositions/cphase_to_fsim.py +3 -2
  306. cirq/transformers/analytical_decompositions/cphase_to_fsim_test.py +11 -10
  307. cirq/transformers/analytical_decompositions/quantum_shannon_decomposition.py +8 -7
  308. cirq/transformers/analytical_decompositions/quantum_shannon_decomposition_test.py +17 -20
  309. cirq/transformers/analytical_decompositions/single_qubit_decompositions_test.py +33 -27
  310. cirq/transformers/analytical_decompositions/single_to_two_qubit_isometry_test.py +1 -1
  311. cirq/transformers/analytical_decompositions/three_qubit_decomposition.py +1 -1
  312. cirq/transformers/analytical_decompositions/two_qubit_state_preparation_test.py +12 -11
  313. cirq/transformers/analytical_decompositions/two_qubit_to_cz.py +5 -2
  314. cirq/transformers/analytical_decompositions/two_qubit_to_cz_test.py +3 -3
  315. cirq/transformers/analytical_decompositions/two_qubit_to_fsim.py +2 -1
  316. cirq/transformers/analytical_decompositions/two_qubit_to_ms.py +2 -1
  317. cirq/transformers/analytical_decompositions/two_qubit_to_ms_test.py +2 -2
  318. cirq/transformers/analytical_decompositions/two_qubit_to_sqrt_iswap.py +2 -1
  319. cirq/transformers/analytical_decompositions/two_qubit_to_sqrt_iswap_test.py +32 -30
  320. cirq/transformers/drop_negligible_operations_test.py +7 -7
  321. cirq/transformers/dynamical_decoupling.py +185 -112
  322. cirq/transformers/dynamical_decoupling_test.py +195 -201
  323. cirq/transformers/eject_phased_paulis.py +2 -1
  324. cirq/transformers/eject_phased_paulis_test.py +3 -2
  325. cirq/transformers/eject_z.py +4 -3
  326. cirq/transformers/eject_z_test.py +23 -25
  327. cirq/transformers/expand_composite.py +3 -2
  328. cirq/transformers/expand_composite_test.py +14 -14
  329. cirq/transformers/gauge_compiling/__init__.py +8 -0
  330. cirq/transformers/gauge_compiling/gauge_compiling.py +3 -2
  331. cirq/transformers/gauge_compiling/gauge_compiling_test.py +14 -12
  332. cirq/transformers/gauge_compiling/gauge_compiling_test_utils.py +3 -3
  333. cirq/transformers/gauge_compiling/idle_moments_gauge.py +5 -2
  334. cirq/transformers/gauge_compiling/multi_moment_cphase_gauge.py +242 -0
  335. cirq/transformers/gauge_compiling/multi_moment_cphase_gauge_test.py +243 -0
  336. cirq/transformers/gauge_compiling/multi_moment_gauge_compiling.py +151 -0
  337. cirq/transformers/gauge_compiling/sqrt_cz_gauge.py +2 -1
  338. cirq/transformers/heuristic_decompositions/gate_tabulation_math_utils.py +1 -1
  339. cirq/transformers/heuristic_decompositions/gate_tabulation_math_utils_test.py +6 -6
  340. cirq/transformers/heuristic_decompositions/two_qubit_gate_tabulation.py +2 -1
  341. cirq/transformers/measurement_transformers.py +2 -1
  342. cirq/transformers/measurement_transformers_test.py +45 -39
  343. cirq/transformers/merge_k_qubit_gates.py +2 -1
  344. cirq/transformers/merge_k_qubit_gates_test.py +1 -1
  345. cirq/transformers/merge_single_qubit_gates.py +2 -1
  346. cirq/transformers/merge_single_qubit_gates_test.py +22 -22
  347. cirq/transformers/noise_adding_test.py +2 -2
  348. cirq/transformers/optimize_for_target_gateset.py +2 -1
  349. cirq/transformers/optimize_for_target_gateset_test.py +11 -9
  350. cirq/transformers/qubit_management_transformers_test.py +6 -2
  351. cirq/transformers/routing/mapping_manager.py +2 -1
  352. cirq/transformers/routing/route_circuit_cqc.py +2 -1
  353. cirq/transformers/stratify.py +2 -1
  354. cirq/transformers/symbolize.py +2 -1
  355. cirq/transformers/tag_transformers.py +2 -1
  356. cirq/transformers/target_gatesets/compilation_target_gateset.py +2 -1
  357. cirq/transformers/target_gatesets/cz_gateset.py +2 -1
  358. cirq/transformers/target_gatesets/cz_gateset_test.py +1 -1
  359. cirq/transformers/target_gatesets/sqrt_iswap_gateset.py +2 -1
  360. cirq/transformers/transformer_api.py +2 -1
  361. cirq/transformers/transformer_primitives.py +271 -145
  362. cirq/transformers/transformer_primitives_test.py +185 -1
  363. cirq/value/abc_alt.py +2 -1
  364. cirq/value/classical_data.py +2 -1
  365. cirq/value/condition.py +2 -1
  366. cirq/value/digits.py +9 -2
  367. cirq/value/duration.py +6 -5
  368. cirq/value/linear_dict.py +4 -9
  369. cirq/value/measurement_key.py +2 -1
  370. cirq/value/periodic_value.py +3 -2
  371. cirq/value/product_state.py +2 -1
  372. cirq/value/value_equality_attr.py +2 -1
  373. cirq/vis/density_matrix.py +1 -1
  374. cirq/vis/heatmap.py +2 -1
  375. cirq/vis/histogram.py +2 -1
  376. cirq/vis/state_histogram.py +2 -1
  377. cirq/work/collector.py +2 -1
  378. cirq/work/observable_grouping.py +2 -1
  379. cirq/work/observable_measurement.py +2 -1
  380. cirq/work/observable_measurement_data.py +2 -1
  381. cirq/work/observable_measurement_test.py +1 -1
  382. cirq/work/observable_readout_calibration.py +2 -1
  383. cirq/work/observable_readout_calibration_test.py +1 -1
  384. cirq/work/observable_settings.py +2 -1
  385. cirq/work/sampler.py +2 -1
  386. cirq/work/sampler_test.py +1 -1
  387. {cirq_core-1.7.0.dev20250924231107.dist-info → cirq_core-1.7.0.dev20251203004401.dist-info}/METADATA +4 -4
  388. {cirq_core-1.7.0.dev20250924231107.dist-info → cirq_core-1.7.0.dev20251203004401.dist-info}/RECORD +391 -374
  389. cirq/contrib/json_test.py +0 -33
  390. {cirq_core-1.7.0.dev20250924231107.dist-info → cirq_core-1.7.0.dev20251203004401.dist-info}/WHEEL +0 -0
  391. {cirq_core-1.7.0.dev20250924231107.dist-info → cirq_core-1.7.0.dev20251203004401.dist-info}/licenses/LICENSE +0 -0
  392. {cirq_core-1.7.0.dev20250924231107.dist-info → cirq_core-1.7.0.dev20251203004401.dist-info}/top_level.txt +0 -0
@@ -21,10 +21,11 @@ https://arxiv.org/abs/quant-ph/0406176
21
21
 
22
22
  from __future__ import annotations
23
23
 
24
- from typing import Callable, cast, Iterable, TYPE_CHECKING
24
+ from collections.abc import Callable, Iterable, Sequence
25
+ from typing import cast, TYPE_CHECKING
25
26
 
27
+ import attrs
26
28
  import numpy as np
27
- from attr import define
28
29
  from scipy.linalg import cossin
29
30
 
30
31
  from cirq import ops
@@ -40,14 +41,14 @@ if TYPE_CHECKING:
40
41
  import cirq
41
42
 
42
43
 
43
- @define
44
+ @attrs.define
44
45
  class _TwoQubitGate:
45
46
  location: int
46
47
  matrix: np.ndarray
47
48
 
48
49
 
49
50
  def quantum_shannon_decomposition(
50
- qubits: list[cirq.Qid], u: np.ndarray, atol: float = 1e-8
51
+ qubits: Sequence[cirq.Qid], u: np.ndarray, atol: float = 1e-8
51
52
  ) -> Iterable[cirq.Operation]:
52
53
  """Decomposes n-qubit unitary 1-q, 2-q and GlobalPhase gates, preserving global phase.
53
54
 
@@ -149,7 +150,7 @@ def quantum_shannon_decomposition(
149
150
  yield from cast(Iterable[ops.Operation], ops.flatten_op_tree(shannon_decomp))
150
151
 
151
152
 
152
- def _recursive_decomposition(qubits: list[cirq.Qid], u: np.ndarray) -> Iterable[cirq.Operation]:
153
+ def _recursive_decomposition(qubits: Sequence[cirq.Qid], u: np.ndarray) -> Iterable[cirq.Operation]:
153
154
  """Recursive step in the quantum shannon decomposition.
154
155
 
155
156
  Decomposes n-qubit unitary into generic 2-qubit gates, CNOT, CZ and 1-qubit gates.
@@ -270,7 +271,7 @@ def _single_qubit_decomposition(qubit: cirq.Qid, u: np.ndarray) -> Iterable[cirq
270
271
 
271
272
 
272
273
  def _msb_demuxer(
273
- demux_qubits: list[cirq.Qid], u1: np.ndarray, u2: np.ndarray
274
+ demux_qubits: Sequence[cirq.Qid], u1: np.ndarray, u2: np.ndarray
274
275
  ) -> Iterable[cirq.Operation]:
275
276
  """Demultiplexes a unitary matrix that is multiplexed in its most-significant-qubit.
276
277
 
@@ -336,7 +337,7 @@ def _nth_gray(n: int) -> int:
336
337
 
337
338
 
338
339
  def _multiplexed_cossin(
339
- cossin_qubits: list[cirq.Qid], angles: list[float], rot_func: Callable = ops.ry
340
+ cossin_qubits: Sequence[cirq.Qid], angles: list[float], rot_func: Callable = ops.ry
340
341
  ) -> Iterable[cirq.Operation]:
341
342
  """Performs a multiplexed rotation over all qubits in this unitary matrix,
342
343
 
@@ -31,9 +31,8 @@ from cirq.transformers.analytical_decompositions.quantum_shannon_decomposition i
31
31
  )
32
32
 
33
33
 
34
- @pytest.mark.xfail(reason='#6765')
35
34
  @pytest.mark.parametrize('n_qubits', list(range(1, 8)))
36
- def test_random_qsd_n_qubit(n_qubits):
35
+ def test_random_qsd_n_qubit(n_qubits) -> None:
37
36
  U = unitary_group.rvs(2**n_qubits)
38
37
  qubits = [cirq.NamedQubit(f'q{i}') for i in range(n_qubits)]
39
38
  circuit = cirq.Circuit(quantum_shannon_decomposition(qubits, U))
@@ -43,7 +42,7 @@ def test_random_qsd_n_qubit(n_qubits):
43
42
  assert all(cirq.num_qubits(op) <= 2 for op in circuit.all_operations())
44
43
 
45
44
 
46
- def test_qsd_n_qubit_errors():
45
+ def test_qsd_n_qubit_errors() -> None:
47
46
  qubits = [cirq.NamedQubit(f'q{i}') for i in range(3)]
48
47
  with pytest.raises(ValueError, match="shaped numpy array"):
49
48
  cirq.Circuit(quantum_shannon_decomposition(qubits, np.eye(9)))
@@ -51,7 +50,7 @@ def test_qsd_n_qubit_errors():
51
50
  cirq.Circuit(quantum_shannon_decomposition(qubits, np.ones((8, 8))))
52
51
 
53
52
 
54
- def test_recursive_decomposition_n_qubit_errors():
53
+ def test_recursive_decomposition_n_qubit_errors() -> None:
55
54
  qubits = [cirq.NamedQubit(f'q{i}') for i in range(3)]
56
55
  with pytest.raises(ValueError, match="shaped numpy array"):
57
56
  cirq.Circuit(_recursive_decomposition(qubits, np.eye(9)))
@@ -59,7 +58,7 @@ def test_recursive_decomposition_n_qubit_errors():
59
58
  cirq.Circuit(_recursive_decomposition(qubits, np.eye(2)))
60
59
 
61
60
 
62
- def test_random_single_qubit_decomposition():
61
+ def test_random_single_qubit_decomposition() -> None:
63
62
  U = unitary_group.rvs(2)
64
63
  qubit = cirq.NamedQubit('q0')
65
64
  circuit = cirq.Circuit(_single_qubit_decomposition(qubit, U))
@@ -69,7 +68,7 @@ def test_random_single_qubit_decomposition():
69
68
  assert all(cirq.num_qubits(op) <= 2 for op in circuit.all_operations())
70
69
 
71
70
 
72
- def test_msb_demuxer():
71
+ def test_msb_demuxer() -> None:
73
72
  U1 = unitary_group.rvs(4)
74
73
  U2 = unitary_group.rvs(4)
75
74
  U_full = np.kron([[1, 0], [0, 0]], U1) + np.kron([[0, 0], [0, 1]], U2)
@@ -81,13 +80,12 @@ def test_msb_demuxer():
81
80
  assert all(cirq.num_qubits(op) <= 2 for op in circuit.all_operations())
82
81
 
83
82
 
84
- def test_multiplexed_cossin():
83
+ def test_multiplexed_cossin() -> None:
85
84
  angle_1 = np.random.random_sample() * 2 * np.pi
86
85
  angle_2 = np.random.random_sample() * 2 * np.pi
87
86
  c1, s1 = np.cos(angle_1), np.sin(angle_1)
88
87
  c2, s2 = np.cos(angle_2), np.sin(angle_2)
89
- multiplexed_ry = [[c1, 0, -s1, 0], [0, c2, 0, -s2], [s1, 0, c1, 0], [0, s2, 0, c2]]
90
- multiplexed_ry = np.array(multiplexed_ry)
88
+ multiplexed_ry = np.asarray([[c1, 0, -s1, 0], [0, c2, 0, -s2], [s1, 0, c1, 0], [0, s2, 0, c2]])
91
89
  qubits = [cirq.NamedQubit(f'q{i}') for i in range(2)]
92
90
  circuit = cirq.Circuit(_multiplexed_cossin(qubits, [angle_1, angle_2]))
93
91
  # Add back the CZ gate removed by the A.1 optimization
@@ -126,11 +124,11 @@ def test_multiplexed_cossin():
126
124
  (15, 8),
127
125
  ],
128
126
  )
129
- def test_nth_gray(n, gray):
127
+ def test_nth_gray(n, gray) -> None:
130
128
  assert _nth_gray(n) == gray
131
129
 
132
130
 
133
- def test_ghz_circuit_decomposes():
131
+ def test_ghz_circuit_decomposes() -> None:
134
132
  # Test case from #6725
135
133
  ghz_circuit = cirq.Circuit(cirq.H(cirq.q(0)), cirq.CNOT(cirq.q(0), cirq.q(1)))
136
134
  ghz_unitary = cirq.unitary(ghz_circuit)
@@ -141,7 +139,7 @@ def test_ghz_circuit_decomposes():
141
139
  np.testing.assert_allclose(new_unitary, ghz_unitary, atol=1e-6)
142
140
 
143
141
 
144
- def test_qft_decomposes():
142
+ def test_qft_decomposes() -> None:
145
143
  # Test case from #6666
146
144
  qs = cirq.LineQubit.range(4)
147
145
  qft_circuit = cirq.Circuit(cirq.qft(*qs))
@@ -163,7 +161,7 @@ def test_qft_decomposes():
163
161
  (cirq.S, 1), # rz & ry
164
162
  ],
165
163
  )
166
- def test_cliffords(gate, num_ops):
164
+ def test_cliffords(gate, num_ops) -> None:
167
165
  desired_unitary = cirq.unitary(gate)
168
166
  shannon_circuit = cirq.Circuit(quantum_shannon_decomposition((cirq.q(0),), desired_unitary))
169
167
  new_unitary = cirq.unitary(shannon_circuit)
@@ -173,7 +171,7 @@ def test_cliffords(gate, num_ops):
173
171
 
174
172
 
175
173
  @pytest.mark.parametrize('gate', [cirq.X, cirq.Y, cirq.Z, cirq.H, cirq.S])
176
- def test_cliffords_with_global_phase(gate):
174
+ def test_cliffords_with_global_phase(gate) -> None:
177
175
  global_phase = np.exp(1j * np.random.choice(np.linspace(0.1, 2 * np.pi, 10)))
178
176
  desired_unitary = cirq.unitary(gate) * global_phase
179
177
  shannon_circuit = cirq.Circuit(quantum_shannon_decomposition((cirq.q(0),), desired_unitary))
@@ -181,7 +179,7 @@ def test_cliffords_with_global_phase(gate):
181
179
  np.testing.assert_allclose(new_unitary, desired_unitary)
182
180
 
183
181
 
184
- def test_global_phase():
182
+ def test_global_phase() -> None:
185
183
  global_phase = np.exp(1j * np.random.choice(np.linspace(0, 2 * np.pi, 10)))
186
184
  shannon_circuit = cirq.Circuit(
187
185
  quantum_shannon_decomposition((cirq.q(0),), np.eye(2) * global_phase)
@@ -191,7 +189,7 @@ def test_global_phase():
191
189
 
192
190
 
193
191
  @pytest.mark.parametrize('gate', [cirq.CZ, cirq.CNOT, cirq.XX, cirq.YY, cirq.ZZ])
194
- def test_two_qubit_gate(gate):
192
+ def test_two_qubit_gate(gate) -> None:
195
193
  global_phase = np.exp(1j * np.random.choice(np.linspace(0, 2 * np.pi, 10)))
196
194
  desired_unitary = cirq.unitary(gate) * global_phase
197
195
  shannon_circuit = cirq.Circuit(
@@ -202,7 +200,7 @@ def test_two_qubit_gate(gate):
202
200
 
203
201
 
204
202
  @pytest.mark.parametrize('gate', [cirq.CCNOT, cirq.qft(*cirq.LineQubit.range(3))])
205
- def test_three_qubit_gate(gate):
203
+ def test_three_qubit_gate(gate) -> None:
206
204
  global_phase = np.exp(1j * np.random.choice(np.linspace(0, 2 * np.pi, 10)))
207
205
  desired_unitary = cirq.unitary(gate) * global_phase
208
206
  shannon_circuit = cirq.Circuit(
@@ -212,8 +210,7 @@ def test_three_qubit_gate(gate):
212
210
  np.testing.assert_allclose(new_unitary, desired_unitary, atol=1e-6)
213
211
 
214
212
 
215
- @pytest.mark.xfail(reason='#6765')
216
- def test_qft5():
213
+ def test_qft5() -> None:
217
214
  global_phase = np.exp(1j * np.random.choice(np.linspace(0, 2 * np.pi, 10)))
218
215
  desired_unitary = cirq.unitary(cirq.qft(*cirq.LineQubit.range(5))) * global_phase
219
216
  shannon_circuit = cirq.Circuit(
@@ -223,7 +220,7 @@ def test_qft5():
223
220
  np.testing.assert_allclose(new_unitary, desired_unitary, atol=1e-6)
224
221
 
225
222
 
226
- def test_random_circuit_decomposition():
223
+ def test_random_circuit_decomposition() -> None:
227
224
  qubits = cirq.LineQubit.range(3)
228
225
  test_circuit = (
229
226
  random_two_qubit_circuit_with_czs(3, qubits[0], qubits[1])
@@ -15,7 +15,7 @@
15
15
  from __future__ import annotations
16
16
 
17
17
  import random
18
- from typing import Sequence
18
+ from collections.abc import Sequence
19
19
 
20
20
  import numpy as np
21
21
  import pytest
@@ -25,13 +25,13 @@ import cirq
25
25
 
26
26
 
27
27
  def assert_gates_implement_unitary(
28
- gates: Sequence[cirq.testing.SingleQubitGate], intended_effect: np.ndarray, atol: float
29
- ):
28
+ gates: Sequence[cirq.Gate], intended_effect: np.ndarray, atol: float
29
+ ) -> None:
30
30
  actual_effect = cirq.dot(*[cirq.unitary(g) for g in reversed(gates)])
31
31
  cirq.testing.assert_allclose_up_to_global_phase(actual_effect, intended_effect, atol=atol)
32
32
 
33
33
 
34
- def test_is_negligible_turn():
34
+ def test_is_negligible_turn() -> None:
35
35
  assert cirq.is_negligible_turn(0, 1e-5)
36
36
  assert cirq.is_negligible_turn(1e-6, 1e-5)
37
37
  assert cirq.is_negligible_turn(1, 1e-5)
@@ -57,37 +57,37 @@ def test_is_negligible_turn():
57
57
  assert not cirq.is_negligible_turn(sympy.Symbol('a') * 0 + 1.5 - 1e-6, 1e-5)
58
58
 
59
59
 
60
- def test_single_qubit_matrix_to_gates_known_x():
60
+ def test_single_qubit_matrix_to_gates_known_x() -> None:
61
61
  actual = cirq.single_qubit_matrix_to_gates(np.array([[0, 1], [1, 0]]), tolerance=0.01)
62
62
 
63
63
  assert cirq.approx_eq(actual, [cirq.X], atol=1e-9)
64
64
 
65
65
 
66
- def test_single_qubit_matrix_to_gates_known_y():
66
+ def test_single_qubit_matrix_to_gates_known_y() -> None:
67
67
  actual = cirq.single_qubit_matrix_to_gates(np.array([[0, -1j], [1j, 0]]), tolerance=0.01)
68
68
 
69
69
  assert cirq.approx_eq(actual, [cirq.Y], atol=1e-9)
70
70
 
71
71
 
72
- def test_single_qubit_matrix_to_gates_known_z():
72
+ def test_single_qubit_matrix_to_gates_known_z() -> None:
73
73
  actual = cirq.single_qubit_matrix_to_gates(np.array([[1, 0], [0, -1]]), tolerance=0.01)
74
74
 
75
75
  assert cirq.approx_eq(actual, [cirq.Z], atol=1e-9)
76
76
 
77
77
 
78
- def test_single_qubit_matrix_to_gates_known_s():
78
+ def test_single_qubit_matrix_to_gates_known_s() -> None:
79
79
  actual = cirq.single_qubit_matrix_to_gates(np.array([[1, 0], [0, 1j]]), tolerance=0.01)
80
80
 
81
81
  assert cirq.approx_eq(actual, [cirq.Z**0.5], atol=1e-9)
82
82
 
83
83
 
84
- def test_known_s_dag():
84
+ def test_known_s_dag() -> None:
85
85
  actual = cirq.single_qubit_matrix_to_gates(np.array([[1, 0], [0, -1j]]), tolerance=0.01)
86
86
 
87
87
  assert cirq.approx_eq(actual, [cirq.Z**-0.5], atol=1e-9)
88
88
 
89
89
 
90
- def test_known_h():
90
+ def test_known_h() -> None:
91
91
  actual = cirq.single_qubit_matrix_to_gates(
92
92
  np.array([[1, 1], [1, -1]]) * np.sqrt(0.5), tolerance=0.001
93
93
  )
@@ -109,7 +109,7 @@ def test_known_h():
109
109
  ]
110
110
  + [cirq.testing.random_unitary(2) for _ in range(10)],
111
111
  )
112
- def test_single_qubit_matrix_to_gates_cases(intended_effect):
112
+ def test_single_qubit_matrix_to_gates_cases(intended_effect) -> None:
113
113
  for atol in [1e-1, 1e-8]:
114
114
  gates = cirq.single_qubit_matrix_to_gates(intended_effect, tolerance=atol / 10)
115
115
  assert len(gates) <= 3
@@ -120,7 +120,7 @@ def test_single_qubit_matrix_to_gates_cases(intended_effect):
120
120
  @pytest.mark.parametrize(
121
121
  'pre_turns,post_turns', [(random.random(), random.random()) for _ in range(10)]
122
122
  )
123
- def test_single_qubit_matrix_to_gates_fuzz_half_turns_merge_z_gates(pre_turns, post_turns):
123
+ def test_single_qubit_matrix_to_gates_fuzz_half_turns_merge_z_gates(pre_turns, post_turns) -> None:
124
124
  intended_effect = cirq.dot(
125
125
  cirq.unitary(cirq.Z ** (2 * pre_turns)),
126
126
  cirq.unitary(cirq.X),
@@ -133,7 +133,7 @@ def test_single_qubit_matrix_to_gates_fuzz_half_turns_merge_z_gates(pre_turns, p
133
133
  assert_gates_implement_unitary(gates, intended_effect, atol=1e-6)
134
134
 
135
135
 
136
- def test_single_qubit_matrix_to_gates_tolerance_z():
136
+ def test_single_qubit_matrix_to_gates_tolerance_z() -> None:
137
137
  z = np.diag([1, np.exp(1j * 0.01)])
138
138
 
139
139
  optimized_away = cirq.single_qubit_matrix_to_gates(z, tolerance=0.1)
@@ -143,7 +143,7 @@ def test_single_qubit_matrix_to_gates_tolerance_z():
143
143
  assert len(kept) == 1
144
144
 
145
145
 
146
- def test_single_qubit_matrix_to_gates_tolerance_xy():
146
+ def test_single_qubit_matrix_to_gates_tolerance_xy() -> None:
147
147
  c, s = np.cos(0.01), np.sin(0.01)
148
148
  xy = np.array([[c, -s], [s, c]])
149
149
 
@@ -154,7 +154,7 @@ def test_single_qubit_matrix_to_gates_tolerance_xy():
154
154
  assert len(kept) == 1
155
155
 
156
156
 
157
- def test_single_qubit_matrix_to_gates_tolerance_half_turn_phasing():
157
+ def test_single_qubit_matrix_to_gates_tolerance_half_turn_phasing() -> None:
158
158
  a = np.pi / 2 + 0.01
159
159
  c, s = np.cos(a), np.sin(a)
160
160
  nearly_x = np.array([[c, -s], [s, c]])
@@ -189,13 +189,13 @@ def _random_unitary_with_close_eigenvalues():
189
189
  ]
190
190
  + [cirq.testing.random_unitary(2) for _ in range(10)],
191
191
  )
192
- def test_single_qubit_op_to_framed_phase_form_equivalent_on_known_and_random(mat):
192
+ def test_single_qubit_op_to_framed_phase_form_equivalent_on_known_and_random(mat) -> None:
193
193
  u, t, g = cirq.single_qubit_op_to_framed_phase_form(mat)
194
194
  z = np.diag([g, g * t])
195
195
  assert np.allclose(mat, np.conj(u.T).dot(z).dot(u))
196
196
 
197
197
 
198
- def test_single_qubit_matrix_to_phased_x_z_known():
198
+ def test_single_qubit_matrix_to_phased_x_z_known() -> None:
199
199
  actual = cirq.single_qubit_matrix_to_phased_x_z(np.array([[0, 1], [1, 0]]), atol=0.01)
200
200
  assert cirq.approx_eq(actual, [cirq.PhasedXPowGate(phase_exponent=1.0)], atol=1e-9)
201
201
 
@@ -223,7 +223,7 @@ def test_single_qubit_matrix_to_phased_x_z_known():
223
223
  'intended_effect',
224
224
  [np.array([[0, 1j], [1, 0]])] + [cirq.testing.random_unitary(2) for _ in range(10)],
225
225
  )
226
- def test_single_qubit_matrix_to_phased_x_z_cases(intended_effect):
226
+ def test_single_qubit_matrix_to_phased_x_z_cases(intended_effect) -> None:
227
227
  gates = cirq.single_qubit_matrix_to_phased_x_z(intended_effect, atol=1e-6)
228
228
  assert len(gates) <= 2
229
229
  assert_gates_implement_unitary(gates, intended_effect, atol=1e-5)
@@ -232,7 +232,9 @@ def test_single_qubit_matrix_to_phased_x_z_cases(intended_effect):
232
232
  @pytest.mark.parametrize(
233
233
  'pre_turns,post_turns', [(random.random(), random.random()) for _ in range(10)]
234
234
  )
235
- def test_single_qubit_matrix_to_phased_x_z_fuzz_half_turns_always_one_gate(pre_turns, post_turns):
235
+ def test_single_qubit_matrix_to_phased_x_z_fuzz_half_turns_always_one_gate(
236
+ pre_turns, post_turns
237
+ ) -> None:
236
238
  atol = 1e-6
237
239
  aggr_atol = atol * 10.0
238
240
 
@@ -248,7 +250,7 @@ def test_single_qubit_matrix_to_phased_x_z_fuzz_half_turns_always_one_gate(pre_t
248
250
  assert_gates_implement_unitary(gates, intended_effect, atol=aggr_atol)
249
251
 
250
252
 
251
- def test_single_qubit_matrix_to_phased_x_z_tolerance_z():
253
+ def test_single_qubit_matrix_to_phased_x_z_tolerance_z() -> None:
252
254
  z = np.diag([1, np.exp(1j * 0.01)])
253
255
 
254
256
  optimized_away = cirq.single_qubit_matrix_to_phased_x_z(z, atol=0.1)
@@ -258,7 +260,7 @@ def test_single_qubit_matrix_to_phased_x_z_tolerance_z():
258
260
  assert len(kept) == 1
259
261
 
260
262
 
261
- def test_single_qubit_matrix_to_phased_x_z_tolerance_xy():
263
+ def test_single_qubit_matrix_to_phased_x_z_tolerance_xy() -> None:
262
264
  c, s = np.cos(0.01), np.sin(0.01)
263
265
  xy = np.array([[c, -s], [s, c]])
264
266
 
@@ -269,7 +271,7 @@ def test_single_qubit_matrix_to_phased_x_z_tolerance_xy():
269
271
  assert len(kept) == 1
270
272
 
271
273
 
272
- def test_single_qubit_matrix_to_phased_x_z_tolerance_half_turn_phasing():
274
+ def test_single_qubit_matrix_to_phased_x_z_tolerance_half_turn_phasing() -> None:
273
275
  a = np.pi / 2 + 0.01
274
276
  c, s = np.cos(a), np.sin(a)
275
277
  nearly_x = np.array([[c, -s], [s, c]])
@@ -297,15 +299,16 @@ def test_single_qubit_matrix_to_phased_x_z_tolerance_half_turn_phasing():
297
299
  *[cirq.testing.random_unitary(2) for _ in range(10)],
298
300
  ],
299
301
  )
300
- def test_single_qubit_matrix_to_phxz_cases(intended_effect):
302
+ def test_single_qubit_matrix_to_phxz_cases(intended_effect) -> None:
301
303
  gate = cirq.single_qubit_matrix_to_phxz(intended_effect, atol=1e-6)
304
+ assert gate is not None
302
305
  assert_gates_implement_unitary([gate], intended_effect, atol=1e-5)
303
306
 
304
307
 
305
308
  @pytest.mark.parametrize(
306
309
  'pre_turns,post_turns', [(random.random(), random.random()) for _ in range(10)]
307
310
  )
308
- def test_single_qubit_matrix_to_phxz_fuzz_half_turns_always_one_gate(pre_turns, post_turns):
311
+ def test_single_qubit_matrix_to_phxz_fuzz_half_turns_always_one_gate(pre_turns, post_turns) -> None:
309
312
  atol = 1e-6
310
313
  aggr_atol = atol * 10.0
311
314
 
@@ -317,11 +320,12 @@ def test_single_qubit_matrix_to_phxz_fuzz_half_turns_always_one_gate(pre_turns,
317
320
 
318
321
  gate = cirq.single_qubit_matrix_to_phxz(intended_effect, atol=atol)
319
322
 
323
+ assert gate is not None
320
324
  assert gate.z_exponent == 0
321
325
  assert_gates_implement_unitary([gate], intended_effect, atol=aggr_atol)
322
326
 
323
327
 
324
- def test_single_qubit_matrix_to_phxz_tolerance_z():
328
+ def test_single_qubit_matrix_to_phxz_tolerance_z() -> None:
325
329
  z = np.diag([1, np.exp(1j * 0.01)])
326
330
 
327
331
  optimized_away = cirq.single_qubit_matrix_to_phxz(z, atol=0.1)
@@ -331,7 +335,7 @@ def test_single_qubit_matrix_to_phxz_tolerance_z():
331
335
  assert kept is not None
332
336
 
333
337
 
334
- def test_single_qubit_matrix_to_phxz_tolerance_xy():
338
+ def test_single_qubit_matrix_to_phxz_tolerance_xy() -> None:
335
339
  c, s = np.cos(0.01), np.sin(0.01)
336
340
  xy = np.array([[c, -s], [s, c]])
337
341
 
@@ -342,7 +346,7 @@ def test_single_qubit_matrix_to_phxz_tolerance_xy():
342
346
  assert kept is not None
343
347
 
344
348
 
345
- def test_single_qubit_matrix_to_phxz_tolerance_half_turn_phasing():
349
+ def test_single_qubit_matrix_to_phxz_tolerance_half_turn_phasing() -> None:
346
350
  a = np.pi / 2 + 0.01
347
351
  c, s = np.cos(a), np.sin(a)
348
352
  nearly_x = np.array([[c, -s], [s, c]])
@@ -351,7 +355,9 @@ def test_single_qubit_matrix_to_phxz_tolerance_half_turn_phasing():
351
355
  phased_nearly_x = z1.dot(nearly_x).dot(z2)
352
356
 
353
357
  optimized_away = cirq.single_qubit_matrix_to_phxz(phased_nearly_x, atol=0.1)
358
+ assert optimized_away is not None
354
359
  assert optimized_away.z_exponent == 0
355
360
 
356
361
  kept = cirq.single_qubit_matrix_to_phxz(phased_nearly_x, atol=0.0001)
362
+ assert kept is not None
357
363
  assert kept.z_exponent != 0
@@ -43,7 +43,7 @@ INVALID_INITIAL_STATES = [
43
43
  @pytest.mark.parametrize('allow_partial_czs', [True, False])
44
44
  def test_two_qubit_matrix_to_cz_isometry(
45
45
  initial_state, is_valid, unitary_matrix, allow_partial_czs
46
- ):
46
+ ) -> None:
47
47
  a, b, c = cirq.LineQubit.range(3)
48
48
  decomposed_ops = cirq.two_qubit_matrix_to_cz_isometry(
49
49
  a, b, unitary_matrix, allow_partial_czs=allow_partial_czs
@@ -16,7 +16,7 @@
16
16
 
17
17
  from __future__ import annotations
18
18
 
19
- from typing import Sequence
19
+ from collections.abc import Sequence
20
20
 
21
21
  import numpy as np
22
22
  import scipy.linalg
@@ -17,6 +17,7 @@
17
17
  from __future__ import annotations
18
18
 
19
19
  import copy
20
+ from collections.abc import Iterator
20
21
 
21
22
  import numpy as np
22
23
  import pytest
@@ -24,11 +25,11 @@ import pytest
24
25
  import cirq
25
26
 
26
27
 
27
- def random_state(seed: float):
28
+ def random_state(seed: float) -> np.ndarray:
28
29
  return cirq.testing.random_superposition(4, random_state=seed)
29
30
 
30
31
 
31
- def states_with_phases(st: np.ndarray):
32
+ def states_with_phases(st: np.ndarray) -> Iterator[np.ndarray]:
32
33
  """Returns several states similar to st with modified global phases."""
33
34
  st = np.array(st, dtype="complex64")
34
35
  yield st
@@ -61,10 +62,10 @@ STATES_TO_PREPARE = [
61
62
 
62
63
 
63
64
  @pytest.mark.parametrize("state", STATES_TO_PREPARE)
64
- def test_prepare_two_qubit_state_using_cz(state):
65
+ def test_prepare_two_qubit_state_using_cz(state) -> None:
65
66
  state = cirq.to_valid_state_vector(state, num_qubits=2)
66
- q = cirq.LineQubit.range(2)
67
- circuit = cirq.Circuit(cirq.prepare_two_qubit_state_using_cz(*q, state))
67
+ q0, q1 = cirq.LineQubit.range(2)
68
+ circuit = cirq.Circuit(cirq.prepare_two_qubit_state_using_cz(q0, q1, state))
68
69
  ops_cz = [*circuit.findall_operations(lambda op: op.gate == cirq.CZ)]
69
70
  ops_2q = [*circuit.findall_operations(lambda op: cirq.num_qubits(op) > 1)]
70
71
  assert ops_cz == ops_2q
@@ -76,11 +77,11 @@ def test_prepare_two_qubit_state_using_cz(state):
76
77
 
77
78
  @pytest.mark.parametrize("state", STATES_TO_PREPARE)
78
79
  @pytest.mark.parametrize("use_iswap_inv", [True, False])
79
- def test_prepare_two_qubit_state_using_iswap(state, use_iswap_inv):
80
+ def test_prepare_two_qubit_state_using_iswap(state, use_iswap_inv) -> None:
80
81
  state = cirq.to_valid_state_vector(state, num_qubits=2)
81
- q = cirq.LineQubit.range(2)
82
+ q0, q1 = cirq.LineQubit.range(2)
82
83
  circuit = cirq.Circuit(
83
- cirq.prepare_two_qubit_state_using_iswap(*q, state, use_iswap_inv=use_iswap_inv)
84
+ cirq.prepare_two_qubit_state_using_iswap(q0, q1, state, use_iswap_inv=use_iswap_inv)
84
85
  )
85
86
  iswap_gate = cirq.ISWAP_INV if use_iswap_inv else cirq.ISWAP
86
87
  ops_iswap = [*circuit.findall_operations(lambda op: op.gate == iswap_gate)]
@@ -94,12 +95,12 @@ def test_prepare_two_qubit_state_using_iswap(state, use_iswap_inv):
94
95
 
95
96
  @pytest.mark.parametrize("state", STATES_TO_PREPARE)
96
97
  @pytest.mark.parametrize("use_sqrt_iswap_inv", [True, False])
97
- def test_prepare_two_qubit_state_using_sqrt_iswap(state, use_sqrt_iswap_inv):
98
+ def test_prepare_two_qubit_state_using_sqrt_iswap(state, use_sqrt_iswap_inv) -> None:
98
99
  state = cirq.to_valid_state_vector(state, num_qubits=2)
99
- q = cirq.LineQubit.range(2)
100
+ q0, q1 = cirq.LineQubit.range(2)
100
101
  circuit = cirq.Circuit(
101
102
  cirq.prepare_two_qubit_state_using_sqrt_iswap(
102
- *q, state, use_sqrt_iswap_inv=use_sqrt_iswap_inv
103
+ q0, q1, state, use_sqrt_iswap_inv=use_sqrt_iswap_inv
103
104
  )
104
105
  )
105
106
  sqrt_iswap_gate = cirq.SQRT_ISWAP_INV if use_sqrt_iswap_inv else cirq.SQRT_ISWAP
@@ -16,7 +16,8 @@
16
16
 
17
17
  from __future__ import annotations
18
18
 
19
- from typing import cast, Iterable, Sequence, TYPE_CHECKING
19
+ from collections.abc import Iterable, Sequence
20
+ from typing import cast, TYPE_CHECKING
20
21
 
21
22
  import numpy as np
22
23
 
@@ -181,7 +182,9 @@ def _xx_yy_zz_interaction_via_full_czs(q0: cirq.Qid, q1: cirq.Qid, x: float, y:
181
182
  yield ops.H(q1)
182
183
 
183
184
 
184
- def cleanup_operations(operations: Sequence[ops.Operation], atol: float = 1e-8):
185
+ def cleanup_operations(
186
+ operations: Sequence[ops.Operation], atol: float = 1e-8
187
+ ) -> list[ops.Operation]:
185
188
  operations = _merge_single_qubit_gates(operations, atol=atol)
186
189
  circuit = circuits.Circuit(operations)
187
190
  circuit = eject_phased_paulis(circuit)
@@ -95,7 +95,7 @@ def _random_double_full_cz_effect():
95
95
  )
96
96
 
97
97
 
98
- def assert_cz_depth_below(operations, threshold, must_be_full):
98
+ def assert_cz_depth_below(operations, threshold, must_be_full) -> None:
99
99
  total_cz = 0
100
100
 
101
101
  for op in operations:
@@ -110,7 +110,7 @@ def assert_cz_depth_below(operations, threshold, must_be_full):
110
110
  assert total_cz <= threshold
111
111
 
112
112
 
113
- def assert_ops_implement_unitary(q0, q1, operations, intended_effect, atol=0.01):
113
+ def assert_ops_implement_unitary(q0, q1, operations, intended_effect, atol=0.01) -> None:
114
114
  actual_effect = _operations_to_matrix(operations, (q0, q1))
115
115
  assert cirq.allclose_up_to_global_phase(actual_effect, intended_effect, atol=atol)
116
116
 
@@ -273,7 +273,7 @@ def test_decompose_to_diagonal_and_circuit(v) -> None:
273
273
  )
274
274
  def test_decompose_to_diagonal_and_circuit_returns_circuit_with_expected_number_of_czs(
275
275
  mat, num_czs
276
- ):
276
+ ) -> None:
277
277
  b, c = cirq.LineQubit.range(2)
278
278
  _, ops = two_qubit_matrix_to_diagonal_and_cz_operations(b, c, mat, atol=1e-8)
279
279
  circuit = cirq.Circuit(ops)
@@ -16,7 +16,8 @@
16
16
 
17
17
  from __future__ import annotations
18
18
 
19
- from typing import Iterable, Iterator, Sequence, TYPE_CHECKING
19
+ from collections.abc import Iterable, Iterator, Sequence
20
+ from typing import TYPE_CHECKING
20
21
 
21
22
  import numpy as np
22
23
 
@@ -21,7 +21,8 @@ Gate compilation methods implemented here are following the paper below:
21
21
 
22
22
  from __future__ import annotations
23
23
 
24
- from typing import cast, Iterable, TYPE_CHECKING
24
+ from collections.abc import Iterable
25
+ from typing import cast, TYPE_CHECKING
25
26
 
26
27
  from cirq import linalg, ops, protocols
27
28
  from cirq.transformers.analytical_decompositions import single_qubit_decompositions, two_qubit_to_cz
@@ -60,12 +60,12 @@ def _random_double_MS_effect():
60
60
  )
61
61
 
62
62
 
63
- def assert_ops_implement_unitary(q0, q1, operations, intended_effect, atol=0.01):
63
+ def assert_ops_implement_unitary(q0, q1, operations, intended_effect, atol=0.01) -> None:
64
64
  actual_effect = _operations_to_matrix(operations, (q0, q1))
65
65
  assert cirq.allclose_up_to_global_phase(actual_effect, intended_effect, atol=atol)
66
66
 
67
67
 
68
- def assert_ms_depth_below(operations, threshold):
68
+ def assert_ms_depth_below(operations, threshold) -> None:
69
69
  total_ms = 0
70
70
 
71
71
  for op in operations:
@@ -22,7 +22,8 @@ References:
22
22
 
23
23
  from __future__ import annotations
24
24
 
25
- from typing import Sequence, TYPE_CHECKING
25
+ from collections.abc import Sequence
26
+ from typing import TYPE_CHECKING
26
27
 
27
28
  import numpy as np
28
29
  import sympy