qiskit 2.1.0rc1__cp39-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.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 (699) hide show
  1. qiskit/VERSION.txt +1 -0
  2. qiskit/__init__.py +159 -0
  3. qiskit/_accelerate.abi3.so +0 -0
  4. qiskit/_numpy_compat.py +73 -0
  5. qiskit/circuit/__init__.py +1335 -0
  6. qiskit/circuit/_add_control.py +338 -0
  7. qiskit/circuit/_classical_resource_map.py +154 -0
  8. qiskit/circuit/_standard_gates_commutations.py +3849 -0
  9. qiskit/circuit/_utils.py +167 -0
  10. qiskit/circuit/annotated_operation.py +279 -0
  11. qiskit/circuit/annotation.py +404 -0
  12. qiskit/circuit/barrier.py +46 -0
  13. qiskit/circuit/classical/__init__.py +41 -0
  14. qiskit/circuit/classical/expr/__init__.py +266 -0
  15. qiskit/circuit/classical/expr/constructors.py +764 -0
  16. qiskit/circuit/classical/expr/expr.py +156 -0
  17. qiskit/circuit/classical/expr/visitors.py +381 -0
  18. qiskit/circuit/classical/types/__init__.py +113 -0
  19. qiskit/circuit/classical/types/ordering.py +229 -0
  20. qiskit/circuit/classical/types/types.py +30 -0
  21. qiskit/circuit/commutation_checker.py +133 -0
  22. qiskit/circuit/commutation_library.py +20 -0
  23. qiskit/circuit/controlflow/__init__.py +59 -0
  24. qiskit/circuit/controlflow/_builder_utils.py +211 -0
  25. qiskit/circuit/controlflow/box.py +188 -0
  26. qiskit/circuit/controlflow/break_loop.py +56 -0
  27. qiskit/circuit/controlflow/builder.py +791 -0
  28. qiskit/circuit/controlflow/continue_loop.py +56 -0
  29. qiskit/circuit/controlflow/control_flow.py +94 -0
  30. qiskit/circuit/controlflow/for_loop.py +218 -0
  31. qiskit/circuit/controlflow/if_else.py +498 -0
  32. qiskit/circuit/controlflow/switch_case.py +411 -0
  33. qiskit/circuit/controlflow/while_loop.py +166 -0
  34. qiskit/circuit/controlledgate.py +274 -0
  35. qiskit/circuit/delay.py +159 -0
  36. qiskit/circuit/duration.py +80 -0
  37. qiskit/circuit/equivalence.py +94 -0
  38. qiskit/circuit/equivalence_library.py +18 -0
  39. qiskit/circuit/exceptions.py +19 -0
  40. qiskit/circuit/gate.py +261 -0
  41. qiskit/circuit/instruction.py +564 -0
  42. qiskit/circuit/instructionset.py +132 -0
  43. qiskit/circuit/library/__init__.py +984 -0
  44. qiskit/circuit/library/arithmetic/__init__.py +40 -0
  45. qiskit/circuit/library/arithmetic/adders/__init__.py +18 -0
  46. qiskit/circuit/library/arithmetic/adders/adder.py +235 -0
  47. qiskit/circuit/library/arithmetic/adders/cdkm_ripple_carry_adder.py +123 -0
  48. qiskit/circuit/library/arithmetic/adders/draper_qft_adder.py +129 -0
  49. qiskit/circuit/library/arithmetic/adders/vbe_ripple_carry_adder.py +95 -0
  50. qiskit/circuit/library/arithmetic/exact_reciprocal.py +131 -0
  51. qiskit/circuit/library/arithmetic/functional_pauli_rotations.py +114 -0
  52. qiskit/circuit/library/arithmetic/integer_comparator.py +200 -0
  53. qiskit/circuit/library/arithmetic/linear_amplitude_function.py +363 -0
  54. qiskit/circuit/library/arithmetic/linear_pauli_rotations.py +243 -0
  55. qiskit/circuit/library/arithmetic/multipliers/__init__.py +17 -0
  56. qiskit/circuit/library/arithmetic/multipliers/hrs_cumulative_multiplier.py +145 -0
  57. qiskit/circuit/library/arithmetic/multipliers/multiplier.py +201 -0
  58. qiskit/circuit/library/arithmetic/multipliers/rg_qft_multiplier.py +108 -0
  59. qiskit/circuit/library/arithmetic/piecewise_chebyshev.py +506 -0
  60. qiskit/circuit/library/arithmetic/piecewise_linear_pauli_rotations.py +395 -0
  61. qiskit/circuit/library/arithmetic/piecewise_polynomial_pauli_rotations.py +501 -0
  62. qiskit/circuit/library/arithmetic/polynomial_pauli_rotations.py +389 -0
  63. qiskit/circuit/library/arithmetic/quadratic_form.py +370 -0
  64. qiskit/circuit/library/arithmetic/weighted_adder.py +428 -0
  65. qiskit/circuit/library/basis_change/__init__.py +15 -0
  66. qiskit/circuit/library/basis_change/qft.py +316 -0
  67. qiskit/circuit/library/bit_flip_oracle.py +130 -0
  68. qiskit/circuit/library/blueprintcircuit.py +322 -0
  69. qiskit/circuit/library/boolean_logic/__init__.py +18 -0
  70. qiskit/circuit/library/boolean_logic/inner_product.py +157 -0
  71. qiskit/circuit/library/boolean_logic/quantum_and.py +204 -0
  72. qiskit/circuit/library/boolean_logic/quantum_or.py +206 -0
  73. qiskit/circuit/library/boolean_logic/quantum_xor.py +167 -0
  74. qiskit/circuit/library/data_preparation/__init__.py +57 -0
  75. qiskit/circuit/library/data_preparation/_z_feature_map.py +115 -0
  76. qiskit/circuit/library/data_preparation/_zz_feature_map.py +150 -0
  77. qiskit/circuit/library/data_preparation/initializer.py +107 -0
  78. qiskit/circuit/library/data_preparation/pauli_feature_map.py +656 -0
  79. qiskit/circuit/library/data_preparation/state_preparation.py +336 -0
  80. qiskit/circuit/library/fourier_checking.py +160 -0
  81. qiskit/circuit/library/generalized_gates/__init__.py +30 -0
  82. qiskit/circuit/library/generalized_gates/diagonal.py +163 -0
  83. qiskit/circuit/library/generalized_gates/gms.py +179 -0
  84. qiskit/circuit/library/generalized_gates/gr.py +219 -0
  85. qiskit/circuit/library/generalized_gates/isometry.py +370 -0
  86. qiskit/circuit/library/generalized_gates/linear_function.py +318 -0
  87. qiskit/circuit/library/generalized_gates/mcg_up_to_diagonal.py +143 -0
  88. qiskit/circuit/library/generalized_gates/mcmt.py +316 -0
  89. qiskit/circuit/library/generalized_gates/pauli.py +84 -0
  90. qiskit/circuit/library/generalized_gates/permutation.py +202 -0
  91. qiskit/circuit/library/generalized_gates/rv.py +96 -0
  92. qiskit/circuit/library/generalized_gates/uc.py +303 -0
  93. qiskit/circuit/library/generalized_gates/uc_pauli_rot.py +164 -0
  94. qiskit/circuit/library/generalized_gates/ucrx.py +32 -0
  95. qiskit/circuit/library/generalized_gates/ucry.py +32 -0
  96. qiskit/circuit/library/generalized_gates/ucrz.py +32 -0
  97. qiskit/circuit/library/generalized_gates/unitary.py +236 -0
  98. qiskit/circuit/library/graph_state.py +172 -0
  99. qiskit/circuit/library/grover_operator.py +583 -0
  100. qiskit/circuit/library/hamiltonian_gate.py +142 -0
  101. qiskit/circuit/library/hidden_linear_function.py +163 -0
  102. qiskit/circuit/library/iqp.py +180 -0
  103. qiskit/circuit/library/n_local/__init__.py +45 -0
  104. qiskit/circuit/library/n_local/efficient_su2.py +282 -0
  105. qiskit/circuit/library/n_local/evolved_operator_ansatz.py +520 -0
  106. qiskit/circuit/library/n_local/excitation_preserving.py +301 -0
  107. qiskit/circuit/library/n_local/n_local.py +1478 -0
  108. qiskit/circuit/library/n_local/pauli_two_design.py +246 -0
  109. qiskit/circuit/library/n_local/qaoa_ansatz.py +367 -0
  110. qiskit/circuit/library/n_local/real_amplitudes.py +312 -0
  111. qiskit/circuit/library/n_local/two_local.py +289 -0
  112. qiskit/circuit/library/overlap.py +183 -0
  113. qiskit/circuit/library/pauli_evolution.py +202 -0
  114. qiskit/circuit/library/phase_estimation.py +177 -0
  115. qiskit/circuit/library/phase_oracle.py +239 -0
  116. qiskit/circuit/library/quantum_volume.py +179 -0
  117. qiskit/circuit/library/standard_gates/__init__.py +141 -0
  118. qiskit/circuit/library/standard_gates/dcx.py +76 -0
  119. qiskit/circuit/library/standard_gates/ecr.py +126 -0
  120. qiskit/circuit/library/standard_gates/equivalence_library.py +1936 -0
  121. qiskit/circuit/library/standard_gates/global_phase.py +83 -0
  122. qiskit/circuit/library/standard_gates/h.py +230 -0
  123. qiskit/circuit/library/standard_gates/i.py +76 -0
  124. qiskit/circuit/library/standard_gates/iswap.py +115 -0
  125. qiskit/circuit/library/standard_gates/p.py +415 -0
  126. qiskit/circuit/library/standard_gates/r.py +108 -0
  127. qiskit/circuit/library/standard_gates/rx.py +269 -0
  128. qiskit/circuit/library/standard_gates/rxx.py +165 -0
  129. qiskit/circuit/library/standard_gates/ry.py +268 -0
  130. qiskit/circuit/library/standard_gates/ryy.py +165 -0
  131. qiskit/circuit/library/standard_gates/rz.py +290 -0
  132. qiskit/circuit/library/standard_gates/rzx.py +211 -0
  133. qiskit/circuit/library/standard_gates/rzz.py +181 -0
  134. qiskit/circuit/library/standard_gates/s.py +424 -0
  135. qiskit/circuit/library/standard_gates/swap.py +268 -0
  136. qiskit/circuit/library/standard_gates/sx.py +303 -0
  137. qiskit/circuit/library/standard_gates/t.py +169 -0
  138. qiskit/circuit/library/standard_gates/u.py +379 -0
  139. qiskit/circuit/library/standard_gates/u1.py +466 -0
  140. qiskit/circuit/library/standard_gates/u2.py +145 -0
  141. qiskit/circuit/library/standard_gates/u3.py +412 -0
  142. qiskit/circuit/library/standard_gates/x.py +1335 -0
  143. qiskit/circuit/library/standard_gates/xx_minus_yy.py +164 -0
  144. qiskit/circuit/library/standard_gates/xx_plus_yy.py +197 -0
  145. qiskit/circuit/library/standard_gates/y.py +253 -0
  146. qiskit/circuit/library/standard_gates/z.py +331 -0
  147. qiskit/circuit/library/templates/__init__.py +92 -0
  148. qiskit/circuit/library/templates/clifford/__init__.py +33 -0
  149. qiskit/circuit/library/templates/clifford/clifford_2_1.py +34 -0
  150. qiskit/circuit/library/templates/clifford/clifford_2_2.py +35 -0
  151. qiskit/circuit/library/templates/clifford/clifford_2_3.py +34 -0
  152. qiskit/circuit/library/templates/clifford/clifford_2_4.py +34 -0
  153. qiskit/circuit/library/templates/clifford/clifford_3_1.py +35 -0
  154. qiskit/circuit/library/templates/clifford/clifford_4_1.py +38 -0
  155. qiskit/circuit/library/templates/clifford/clifford_4_2.py +37 -0
  156. qiskit/circuit/library/templates/clifford/clifford_4_3.py +38 -0
  157. qiskit/circuit/library/templates/clifford/clifford_4_4.py +37 -0
  158. qiskit/circuit/library/templates/clifford/clifford_5_1.py +40 -0
  159. qiskit/circuit/library/templates/clifford/clifford_6_1.py +40 -0
  160. qiskit/circuit/library/templates/clifford/clifford_6_2.py +40 -0
  161. qiskit/circuit/library/templates/clifford/clifford_6_3.py +40 -0
  162. qiskit/circuit/library/templates/clifford/clifford_6_4.py +38 -0
  163. qiskit/circuit/library/templates/clifford/clifford_6_5.py +40 -0
  164. qiskit/circuit/library/templates/clifford/clifford_8_1.py +42 -0
  165. qiskit/circuit/library/templates/clifford/clifford_8_2.py +42 -0
  166. qiskit/circuit/library/templates/clifford/clifford_8_3.py +41 -0
  167. qiskit/circuit/library/templates/nct/__init__.py +67 -0
  168. qiskit/circuit/library/templates/nct/template_nct_2a_1.py +34 -0
  169. qiskit/circuit/library/templates/nct/template_nct_2a_2.py +35 -0
  170. qiskit/circuit/library/templates/nct/template_nct_2a_3.py +37 -0
  171. qiskit/circuit/library/templates/nct/template_nct_4a_1.py +43 -0
  172. qiskit/circuit/library/templates/nct/template_nct_4a_2.py +41 -0
  173. qiskit/circuit/library/templates/nct/template_nct_4a_3.py +39 -0
  174. qiskit/circuit/library/templates/nct/template_nct_4b_1.py +41 -0
  175. qiskit/circuit/library/templates/nct/template_nct_4b_2.py +39 -0
  176. qiskit/circuit/library/templates/nct/template_nct_5a_1.py +40 -0
  177. qiskit/circuit/library/templates/nct/template_nct_5a_2.py +40 -0
  178. qiskit/circuit/library/templates/nct/template_nct_5a_3.py +40 -0
  179. qiskit/circuit/library/templates/nct/template_nct_5a_4.py +39 -0
  180. qiskit/circuit/library/templates/nct/template_nct_6a_1.py +40 -0
  181. qiskit/circuit/library/templates/nct/template_nct_6a_2.py +41 -0
  182. qiskit/circuit/library/templates/nct/template_nct_6a_3.py +41 -0
  183. qiskit/circuit/library/templates/nct/template_nct_6a_4.py +41 -0
  184. qiskit/circuit/library/templates/nct/template_nct_6b_1.py +41 -0
  185. qiskit/circuit/library/templates/nct/template_nct_6b_2.py +41 -0
  186. qiskit/circuit/library/templates/nct/template_nct_6c_1.py +41 -0
  187. qiskit/circuit/library/templates/nct/template_nct_7a_1.py +43 -0
  188. qiskit/circuit/library/templates/nct/template_nct_7b_1.py +43 -0
  189. qiskit/circuit/library/templates/nct/template_nct_7c_1.py +43 -0
  190. qiskit/circuit/library/templates/nct/template_nct_7d_1.py +43 -0
  191. qiskit/circuit/library/templates/nct/template_nct_7e_1.py +43 -0
  192. qiskit/circuit/library/templates/nct/template_nct_9a_1.py +45 -0
  193. qiskit/circuit/library/templates/nct/template_nct_9c_1.py +43 -0
  194. qiskit/circuit/library/templates/nct/template_nct_9c_10.py +44 -0
  195. qiskit/circuit/library/templates/nct/template_nct_9c_11.py +44 -0
  196. qiskit/circuit/library/templates/nct/template_nct_9c_12.py +44 -0
  197. qiskit/circuit/library/templates/nct/template_nct_9c_2.py +44 -0
  198. qiskit/circuit/library/templates/nct/template_nct_9c_3.py +44 -0
  199. qiskit/circuit/library/templates/nct/template_nct_9c_4.py +44 -0
  200. qiskit/circuit/library/templates/nct/template_nct_9c_5.py +44 -0
  201. qiskit/circuit/library/templates/nct/template_nct_9c_6.py +44 -0
  202. qiskit/circuit/library/templates/nct/template_nct_9c_7.py +44 -0
  203. qiskit/circuit/library/templates/nct/template_nct_9c_8.py +44 -0
  204. qiskit/circuit/library/templates/nct/template_nct_9c_9.py +44 -0
  205. qiskit/circuit/library/templates/nct/template_nct_9d_1.py +43 -0
  206. qiskit/circuit/library/templates/nct/template_nct_9d_10.py +44 -0
  207. qiskit/circuit/library/templates/nct/template_nct_9d_2.py +44 -0
  208. qiskit/circuit/library/templates/nct/template_nct_9d_3.py +44 -0
  209. qiskit/circuit/library/templates/nct/template_nct_9d_4.py +44 -0
  210. qiskit/circuit/library/templates/nct/template_nct_9d_5.py +44 -0
  211. qiskit/circuit/library/templates/nct/template_nct_9d_6.py +44 -0
  212. qiskit/circuit/library/templates/nct/template_nct_9d_7.py +44 -0
  213. qiskit/circuit/library/templates/nct/template_nct_9d_8.py +44 -0
  214. qiskit/circuit/library/templates/nct/template_nct_9d_9.py +44 -0
  215. qiskit/circuit/library/templates/rzx/__init__.py +25 -0
  216. qiskit/circuit/library/templates/rzx/rzx_cy.py +47 -0
  217. qiskit/circuit/library/templates/rzx/rzx_xz.py +54 -0
  218. qiskit/circuit/library/templates/rzx/rzx_yz.py +45 -0
  219. qiskit/circuit/library/templates/rzx/rzx_zz1.py +69 -0
  220. qiskit/circuit/library/templates/rzx/rzx_zz2.py +59 -0
  221. qiskit/circuit/library/templates/rzx/rzx_zz3.py +59 -0
  222. qiskit/circuit/measure.py +53 -0
  223. qiskit/circuit/operation.py +68 -0
  224. qiskit/circuit/parameter.py +188 -0
  225. qiskit/circuit/parameterexpression.py +737 -0
  226. qiskit/circuit/parametertable.py +119 -0
  227. qiskit/circuit/parametervector.py +140 -0
  228. qiskit/circuit/quantumcircuit.py +7610 -0
  229. qiskit/circuit/quantumcircuitdata.py +137 -0
  230. qiskit/circuit/random/__init__.py +50 -0
  231. qiskit/circuit/random/utils.py +755 -0
  232. qiskit/circuit/reset.py +37 -0
  233. qiskit/circuit/singleton.py +600 -0
  234. qiskit/circuit/store.py +89 -0
  235. qiskit/circuit/tools/__init__.py +16 -0
  236. qiskit/circuit/tools/pi_check.py +185 -0
  237. qiskit/circuit/twirling.py +145 -0
  238. qiskit/compiler/__init__.py +27 -0
  239. qiskit/compiler/transpiler.py +375 -0
  240. qiskit/converters/__init__.py +74 -0
  241. qiskit/converters/circuit_to_dag.py +80 -0
  242. qiskit/converters/circuit_to_dagdependency.py +49 -0
  243. qiskit/converters/circuit_to_dagdependency_v2.py +46 -0
  244. qiskit/converters/circuit_to_gate.py +107 -0
  245. qiskit/converters/circuit_to_instruction.py +142 -0
  246. qiskit/converters/dag_to_circuit.py +79 -0
  247. qiskit/converters/dag_to_dagdependency.py +54 -0
  248. qiskit/converters/dag_to_dagdependency_v2.py +43 -0
  249. qiskit/converters/dagdependency_to_circuit.py +40 -0
  250. qiskit/converters/dagdependency_to_dag.py +48 -0
  251. qiskit/dagcircuit/__init__.py +44 -0
  252. qiskit/dagcircuit/collect_blocks.py +403 -0
  253. qiskit/dagcircuit/dagcircuit.py +24 -0
  254. qiskit/dagcircuit/dagdependency.py +612 -0
  255. qiskit/dagcircuit/dagdependency_v2.py +566 -0
  256. qiskit/dagcircuit/dagdepnode.py +160 -0
  257. qiskit/dagcircuit/dagnode.py +193 -0
  258. qiskit/dagcircuit/exceptions.py +42 -0
  259. qiskit/exceptions.py +153 -0
  260. qiskit/passmanager/__init__.py +258 -0
  261. qiskit/passmanager/base_tasks.py +230 -0
  262. qiskit/passmanager/compilation_status.py +74 -0
  263. qiskit/passmanager/exceptions.py +19 -0
  264. qiskit/passmanager/flow_controllers.py +116 -0
  265. qiskit/passmanager/passmanager.py +353 -0
  266. qiskit/primitives/__init__.py +490 -0
  267. qiskit/primitives/backend_estimator_v2.py +530 -0
  268. qiskit/primitives/backend_sampler_v2.py +339 -0
  269. qiskit/primitives/base/__init__.py +20 -0
  270. qiskit/primitives/base/base_estimator.py +247 -0
  271. qiskit/primitives/base/base_primitive_job.py +78 -0
  272. qiskit/primitives/base/base_primitive_v1.py +45 -0
  273. qiskit/primitives/base/base_result_v1.py +65 -0
  274. qiskit/primitives/base/base_sampler.py +196 -0
  275. qiskit/primitives/base/estimator_result_v1.py +46 -0
  276. qiskit/primitives/base/sampler_result_v1.py +45 -0
  277. qiskit/primitives/base/validation_v1.py +250 -0
  278. qiskit/primitives/containers/__init__.py +26 -0
  279. qiskit/primitives/containers/bindings_array.py +391 -0
  280. qiskit/primitives/containers/bit_array.py +764 -0
  281. qiskit/primitives/containers/data_bin.py +172 -0
  282. qiskit/primitives/containers/estimator_pub.py +222 -0
  283. qiskit/primitives/containers/object_array.py +94 -0
  284. qiskit/primitives/containers/observables_array.py +380 -0
  285. qiskit/primitives/containers/primitive_result.py +53 -0
  286. qiskit/primitives/containers/pub_result.py +51 -0
  287. qiskit/primitives/containers/sampler_pub.py +193 -0
  288. qiskit/primitives/containers/sampler_pub_result.py +74 -0
  289. qiskit/primitives/containers/shape.py +129 -0
  290. qiskit/primitives/primitive_job.py +100 -0
  291. qiskit/primitives/statevector_estimator.py +175 -0
  292. qiskit/primitives/statevector_sampler.py +290 -0
  293. qiskit/primitives/utils.py +72 -0
  294. qiskit/providers/__init__.py +677 -0
  295. qiskit/providers/backend.py +364 -0
  296. qiskit/providers/basic_provider/__init__.py +47 -0
  297. qiskit/providers/basic_provider/basic_provider.py +121 -0
  298. qiskit/providers/basic_provider/basic_provider_job.py +65 -0
  299. qiskit/providers/basic_provider/basic_provider_tools.py +218 -0
  300. qiskit/providers/basic_provider/basic_simulator.py +693 -0
  301. qiskit/providers/basic_provider/exceptions.py +30 -0
  302. qiskit/providers/exceptions.py +33 -0
  303. qiskit/providers/fake_provider/__init__.py +69 -0
  304. qiskit/providers/fake_provider/generic_backend_v2.py +376 -0
  305. qiskit/providers/fake_provider/utils/__init__.py +15 -0
  306. qiskit/providers/job.py +147 -0
  307. qiskit/providers/jobstatus.py +30 -0
  308. qiskit/providers/options.py +273 -0
  309. qiskit/providers/providerutils.py +110 -0
  310. qiskit/qasm/libs/dummy/stdgates.inc +75 -0
  311. qiskit/qasm/libs/qelib1.inc +266 -0
  312. qiskit/qasm/libs/stdgates.inc +82 -0
  313. qiskit/qasm2/__init__.py +669 -0
  314. qiskit/qasm2/exceptions.py +27 -0
  315. qiskit/qasm2/export.py +364 -0
  316. qiskit/qasm2/parse.py +438 -0
  317. qiskit/qasm3/__init__.py +466 -0
  318. qiskit/qasm3/ast.py +796 -0
  319. qiskit/qasm3/exceptions.py +27 -0
  320. qiskit/qasm3/experimental.py +70 -0
  321. qiskit/qasm3/exporter.py +1363 -0
  322. qiskit/qasm3/printer.py +620 -0
  323. qiskit/qpy/__init__.py +2141 -0
  324. qiskit/qpy/binary_io/__init__.py +35 -0
  325. qiskit/qpy/binary_io/circuits.py +1687 -0
  326. qiskit/qpy/binary_io/parse_sympy_repr.py +126 -0
  327. qiskit/qpy/binary_io/schedules.py +288 -0
  328. qiskit/qpy/binary_io/value.py +1183 -0
  329. qiskit/qpy/common.py +361 -0
  330. qiskit/qpy/exceptions.py +53 -0
  331. qiskit/qpy/formats.py +458 -0
  332. qiskit/qpy/interface.py +384 -0
  333. qiskit/qpy/type_keys.py +415 -0
  334. qiskit/quantum_info/__init__.py +172 -0
  335. qiskit/quantum_info/analysis/__init__.py +17 -0
  336. qiskit/quantum_info/analysis/average.py +47 -0
  337. qiskit/quantum_info/analysis/distance.py +104 -0
  338. qiskit/quantum_info/analysis/make_observable.py +44 -0
  339. qiskit/quantum_info/analysis/z2_symmetries.py +484 -0
  340. qiskit/quantum_info/operators/__init__.py +29 -0
  341. qiskit/quantum_info/operators/base_operator.py +145 -0
  342. qiskit/quantum_info/operators/channel/__init__.py +29 -0
  343. qiskit/quantum_info/operators/channel/chi.py +191 -0
  344. qiskit/quantum_info/operators/channel/choi.py +218 -0
  345. qiskit/quantum_info/operators/channel/kraus.py +337 -0
  346. qiskit/quantum_info/operators/channel/ptm.py +204 -0
  347. qiskit/quantum_info/operators/channel/quantum_channel.py +348 -0
  348. qiskit/quantum_info/operators/channel/stinespring.py +296 -0
  349. qiskit/quantum_info/operators/channel/superop.py +373 -0
  350. qiskit/quantum_info/operators/channel/transformations.py +490 -0
  351. qiskit/quantum_info/operators/custom_iterator.py +48 -0
  352. qiskit/quantum_info/operators/dihedral/__init__.py +18 -0
  353. qiskit/quantum_info/operators/dihedral/dihedral.py +511 -0
  354. qiskit/quantum_info/operators/dihedral/dihedral_circuits.py +216 -0
  355. qiskit/quantum_info/operators/dihedral/polynomial.py +313 -0
  356. qiskit/quantum_info/operators/dihedral/random.py +64 -0
  357. qiskit/quantum_info/operators/linear_op.py +25 -0
  358. qiskit/quantum_info/operators/measures.py +418 -0
  359. qiskit/quantum_info/operators/mixins/__init__.py +52 -0
  360. qiskit/quantum_info/operators/mixins/adjoint.py +52 -0
  361. qiskit/quantum_info/operators/mixins/group.py +171 -0
  362. qiskit/quantum_info/operators/mixins/linear.py +84 -0
  363. qiskit/quantum_info/operators/mixins/multiply.py +62 -0
  364. qiskit/quantum_info/operators/mixins/tolerances.py +72 -0
  365. qiskit/quantum_info/operators/op_shape.py +525 -0
  366. qiskit/quantum_info/operators/operator.py +869 -0
  367. qiskit/quantum_info/operators/operator_utils.py +76 -0
  368. qiskit/quantum_info/operators/predicates.py +183 -0
  369. qiskit/quantum_info/operators/random.py +154 -0
  370. qiskit/quantum_info/operators/scalar_op.py +254 -0
  371. qiskit/quantum_info/operators/symplectic/__init__.py +24 -0
  372. qiskit/quantum_info/operators/symplectic/base_pauli.py +719 -0
  373. qiskit/quantum_info/operators/symplectic/clifford.py +1032 -0
  374. qiskit/quantum_info/operators/symplectic/clifford_circuits.py +584 -0
  375. qiskit/quantum_info/operators/symplectic/pauli.py +755 -0
  376. qiskit/quantum_info/operators/symplectic/pauli_list.py +1242 -0
  377. qiskit/quantum_info/operators/symplectic/pauli_utils.py +40 -0
  378. qiskit/quantum_info/operators/symplectic/random.py +117 -0
  379. qiskit/quantum_info/operators/symplectic/sparse_pauli_op.py +1239 -0
  380. qiskit/quantum_info/operators/utils/__init__.py +20 -0
  381. qiskit/quantum_info/operators/utils/anti_commutator.py +36 -0
  382. qiskit/quantum_info/operators/utils/commutator.py +36 -0
  383. qiskit/quantum_info/operators/utils/double_commutator.py +76 -0
  384. qiskit/quantum_info/quaternion.py +156 -0
  385. qiskit/quantum_info/random.py +26 -0
  386. qiskit/quantum_info/states/__init__.py +28 -0
  387. qiskit/quantum_info/states/densitymatrix.py +857 -0
  388. qiskit/quantum_info/states/measures.py +288 -0
  389. qiskit/quantum_info/states/quantum_state.py +503 -0
  390. qiskit/quantum_info/states/random.py +157 -0
  391. qiskit/quantum_info/states/stabilizerstate.py +805 -0
  392. qiskit/quantum_info/states/statevector.py +977 -0
  393. qiskit/quantum_info/states/utils.py +247 -0
  394. qiskit/result/__init__.py +61 -0
  395. qiskit/result/counts.py +189 -0
  396. qiskit/result/distributions/__init__.py +17 -0
  397. qiskit/result/distributions/probability.py +100 -0
  398. qiskit/result/distributions/quasi.py +154 -0
  399. qiskit/result/exceptions.py +40 -0
  400. qiskit/result/models.py +241 -0
  401. qiskit/result/postprocess.py +239 -0
  402. qiskit/result/result.py +385 -0
  403. qiskit/result/sampled_expval.py +76 -0
  404. qiskit/result/utils.py +294 -0
  405. qiskit/synthesis/__init__.py +250 -0
  406. qiskit/synthesis/arithmetic/__init__.py +18 -0
  407. qiskit/synthesis/arithmetic/adders/__init__.py +18 -0
  408. qiskit/synthesis/arithmetic/adders/cdkm_ripple_carry_adder.py +154 -0
  409. qiskit/synthesis/arithmetic/adders/draper_qft_adder.py +107 -0
  410. qiskit/synthesis/arithmetic/adders/rv_ripple_carry_adder.py +156 -0
  411. qiskit/synthesis/arithmetic/adders/vbe_ripple_carry_adder.py +161 -0
  412. qiskit/synthesis/arithmetic/comparators/__init__.py +16 -0
  413. qiskit/synthesis/arithmetic/comparators/compare_2s.py +112 -0
  414. qiskit/synthesis/arithmetic/comparators/compare_greedy.py +66 -0
  415. qiskit/synthesis/arithmetic/multipliers/__init__.py +16 -0
  416. qiskit/synthesis/arithmetic/multipliers/hrs_cumulative_multiplier.py +103 -0
  417. qiskit/synthesis/arithmetic/multipliers/rg_qft_multiplier.py +100 -0
  418. qiskit/synthesis/arithmetic/weighted_sum.py +155 -0
  419. qiskit/synthesis/boolean/__init__.py +13 -0
  420. qiskit/synthesis/boolean/boolean_expression.py +231 -0
  421. qiskit/synthesis/boolean/boolean_expression_synth.py +124 -0
  422. qiskit/synthesis/boolean/boolean_expression_visitor.py +96 -0
  423. qiskit/synthesis/clifford/__init__.py +19 -0
  424. qiskit/synthesis/clifford/clifford_decompose_ag.py +178 -0
  425. qiskit/synthesis/clifford/clifford_decompose_bm.py +46 -0
  426. qiskit/synthesis/clifford/clifford_decompose_full.py +64 -0
  427. qiskit/synthesis/clifford/clifford_decompose_greedy.py +58 -0
  428. qiskit/synthesis/clifford/clifford_decompose_layers.py +447 -0
  429. qiskit/synthesis/cnotdihedral/__init__.py +17 -0
  430. qiskit/synthesis/cnotdihedral/cnotdihedral_decompose_full.py +52 -0
  431. qiskit/synthesis/cnotdihedral/cnotdihedral_decompose_general.py +141 -0
  432. qiskit/synthesis/cnotdihedral/cnotdihedral_decompose_two_qubits.py +266 -0
  433. qiskit/synthesis/discrete_basis/__init__.py +16 -0
  434. qiskit/synthesis/discrete_basis/generate_basis_approximations.py +53 -0
  435. qiskit/synthesis/discrete_basis/solovay_kitaev.py +280 -0
  436. qiskit/synthesis/evolution/__init__.py +21 -0
  437. qiskit/synthesis/evolution/evolution_synthesis.py +48 -0
  438. qiskit/synthesis/evolution/lie_trotter.py +123 -0
  439. qiskit/synthesis/evolution/matrix_synthesis.py +47 -0
  440. qiskit/synthesis/evolution/pauli_network.py +80 -0
  441. qiskit/synthesis/evolution/product_formula.py +316 -0
  442. qiskit/synthesis/evolution/qdrift.py +133 -0
  443. qiskit/synthesis/evolution/suzuki_trotter.py +227 -0
  444. qiskit/synthesis/linear/__init__.py +26 -0
  445. qiskit/synthesis/linear/cnot_synth.py +69 -0
  446. qiskit/synthesis/linear/linear_circuits_utils.py +128 -0
  447. qiskit/synthesis/linear/linear_depth_lnn.py +61 -0
  448. qiskit/synthesis/linear/linear_matrix_utils.py +27 -0
  449. qiskit/synthesis/linear_phase/__init__.py +17 -0
  450. qiskit/synthesis/linear_phase/cnot_phase_synth.py +206 -0
  451. qiskit/synthesis/linear_phase/cx_cz_depth_lnn.py +61 -0
  452. qiskit/synthesis/linear_phase/cz_depth_lnn.py +58 -0
  453. qiskit/synthesis/multi_controlled/__init__.py +29 -0
  454. qiskit/synthesis/multi_controlled/mcmt_vchain.py +52 -0
  455. qiskit/synthesis/multi_controlled/mcx_synthesis.py +583 -0
  456. qiskit/synthesis/multi_controlled/multi_control_rotation_gates.py +205 -0
  457. qiskit/synthesis/one_qubit/__init__.py +15 -0
  458. qiskit/synthesis/one_qubit/one_qubit_decompose.py +288 -0
  459. qiskit/synthesis/permutation/__init__.py +18 -0
  460. qiskit/synthesis/permutation/permutation_full.py +78 -0
  461. qiskit/synthesis/permutation/permutation_lnn.py +54 -0
  462. qiskit/synthesis/permutation/permutation_reverse_lnn.py +93 -0
  463. qiskit/synthesis/permutation/permutation_utils.py +16 -0
  464. qiskit/synthesis/qft/__init__.py +16 -0
  465. qiskit/synthesis/qft/qft_decompose_full.py +97 -0
  466. qiskit/synthesis/qft/qft_decompose_lnn.py +61 -0
  467. qiskit/synthesis/stabilizer/__init__.py +16 -0
  468. qiskit/synthesis/stabilizer/stabilizer_circuit.py +149 -0
  469. qiskit/synthesis/stabilizer/stabilizer_decompose.py +194 -0
  470. qiskit/synthesis/two_qubit/__init__.py +20 -0
  471. qiskit/synthesis/two_qubit/local_invariance.py +63 -0
  472. qiskit/synthesis/two_qubit/two_qubit_decompose.py +583 -0
  473. qiskit/synthesis/two_qubit/xx_decompose/__init__.py +19 -0
  474. qiskit/synthesis/two_qubit/xx_decompose/circuits.py +300 -0
  475. qiskit/synthesis/two_qubit/xx_decompose/decomposer.py +324 -0
  476. qiskit/synthesis/two_qubit/xx_decompose/embodiments.py +163 -0
  477. qiskit/synthesis/two_qubit/xx_decompose/paths.py +412 -0
  478. qiskit/synthesis/two_qubit/xx_decompose/polytopes.py +262 -0
  479. qiskit/synthesis/two_qubit/xx_decompose/utilities.py +40 -0
  480. qiskit/synthesis/two_qubit/xx_decompose/weyl.py +133 -0
  481. qiskit/synthesis/unitary/__init__.py +13 -0
  482. qiskit/synthesis/unitary/aqc/__init__.py +177 -0
  483. qiskit/synthesis/unitary/aqc/approximate.py +116 -0
  484. qiskit/synthesis/unitary/aqc/aqc.py +175 -0
  485. qiskit/synthesis/unitary/aqc/cnot_structures.py +300 -0
  486. qiskit/synthesis/unitary/aqc/cnot_unit_circuit.py +103 -0
  487. qiskit/synthesis/unitary/aqc/cnot_unit_objective.py +299 -0
  488. qiskit/synthesis/unitary/aqc/elementary_operations.py +108 -0
  489. qiskit/synthesis/unitary/aqc/fast_gradient/__init__.py +164 -0
  490. qiskit/synthesis/unitary/aqc/fast_gradient/fast_grad_utils.py +237 -0
  491. qiskit/synthesis/unitary/aqc/fast_gradient/fast_gradient.py +226 -0
  492. qiskit/synthesis/unitary/aqc/fast_gradient/layer.py +370 -0
  493. qiskit/synthesis/unitary/aqc/fast_gradient/pmatrix.py +312 -0
  494. qiskit/synthesis/unitary/qsd.py +359 -0
  495. qiskit/transpiler/__init__.py +1352 -0
  496. qiskit/transpiler/basepasses.py +190 -0
  497. qiskit/transpiler/coupling.py +500 -0
  498. qiskit/transpiler/exceptions.py +59 -0
  499. qiskit/transpiler/instruction_durations.py +263 -0
  500. qiskit/transpiler/layout.py +740 -0
  501. qiskit/transpiler/passes/__init__.py +278 -0
  502. qiskit/transpiler/passes/analysis/__init__.py +23 -0
  503. qiskit/transpiler/passes/analysis/count_ops.py +30 -0
  504. qiskit/transpiler/passes/analysis/count_ops_longest_path.py +26 -0
  505. qiskit/transpiler/passes/analysis/dag_longest_path.py +24 -0
  506. qiskit/transpiler/passes/analysis/depth.py +33 -0
  507. qiskit/transpiler/passes/analysis/num_qubits.py +26 -0
  508. qiskit/transpiler/passes/analysis/num_tensor_factors.py +26 -0
  509. qiskit/transpiler/passes/analysis/resource_estimation.py +41 -0
  510. qiskit/transpiler/passes/analysis/size.py +36 -0
  511. qiskit/transpiler/passes/analysis/width.py +27 -0
  512. qiskit/transpiler/passes/basis/__init__.py +19 -0
  513. qiskit/transpiler/passes/basis/basis_translator.py +138 -0
  514. qiskit/transpiler/passes/basis/decompose.py +137 -0
  515. qiskit/transpiler/passes/basis/translate_parameterized.py +175 -0
  516. qiskit/transpiler/passes/basis/unroll_3q_or_more.py +84 -0
  517. qiskit/transpiler/passes/basis/unroll_custom_definitions.py +110 -0
  518. qiskit/transpiler/passes/layout/__init__.py +26 -0
  519. qiskit/transpiler/passes/layout/_csp_custom_solver.py +65 -0
  520. qiskit/transpiler/passes/layout/apply_layout.py +128 -0
  521. qiskit/transpiler/passes/layout/csp_layout.py +132 -0
  522. qiskit/transpiler/passes/layout/dense_layout.py +197 -0
  523. qiskit/transpiler/passes/layout/disjoint_utils.py +54 -0
  524. qiskit/transpiler/passes/layout/enlarge_with_ancilla.py +49 -0
  525. qiskit/transpiler/passes/layout/full_ancilla_allocation.py +116 -0
  526. qiskit/transpiler/passes/layout/layout_2q_distance.py +77 -0
  527. qiskit/transpiler/passes/layout/sabre_layout.py +525 -0
  528. qiskit/transpiler/passes/layout/sabre_pre_layout.py +225 -0
  529. qiskit/transpiler/passes/layout/set_layout.py +69 -0
  530. qiskit/transpiler/passes/layout/trivial_layout.py +66 -0
  531. qiskit/transpiler/passes/layout/vf2_layout.py +292 -0
  532. qiskit/transpiler/passes/layout/vf2_post_layout.py +376 -0
  533. qiskit/transpiler/passes/layout/vf2_utils.py +245 -0
  534. qiskit/transpiler/passes/optimization/__init__.py +42 -0
  535. qiskit/transpiler/passes/optimization/_gate_extension.py +80 -0
  536. qiskit/transpiler/passes/optimization/collect_1q_runs.py +31 -0
  537. qiskit/transpiler/passes/optimization/collect_2q_blocks.py +35 -0
  538. qiskit/transpiler/passes/optimization/collect_and_collapse.py +117 -0
  539. qiskit/transpiler/passes/optimization/collect_cliffords.py +109 -0
  540. qiskit/transpiler/passes/optimization/collect_linear_functions.py +85 -0
  541. qiskit/transpiler/passes/optimization/collect_multiqubit_blocks.py +242 -0
  542. qiskit/transpiler/passes/optimization/commutation_analysis.py +44 -0
  543. qiskit/transpiler/passes/optimization/commutative_cancellation.py +82 -0
  544. qiskit/transpiler/passes/optimization/commutative_inverse_cancellation.py +140 -0
  545. qiskit/transpiler/passes/optimization/consolidate_blocks.py +176 -0
  546. qiskit/transpiler/passes/optimization/contract_idle_wires_in_control_flow.py +104 -0
  547. qiskit/transpiler/passes/optimization/elide_permutations.py +91 -0
  548. qiskit/transpiler/passes/optimization/hoare_opt.py +420 -0
  549. qiskit/transpiler/passes/optimization/inverse_cancellation.py +95 -0
  550. qiskit/transpiler/passes/optimization/light_cone.py +135 -0
  551. qiskit/transpiler/passes/optimization/optimize_1q_commutation.py +267 -0
  552. qiskit/transpiler/passes/optimization/optimize_1q_decomposition.py +251 -0
  553. qiskit/transpiler/passes/optimization/optimize_1q_gates.py +384 -0
  554. qiskit/transpiler/passes/optimization/optimize_annotated.py +449 -0
  555. qiskit/transpiler/passes/optimization/optimize_clifford_t.py +68 -0
  556. qiskit/transpiler/passes/optimization/optimize_cliffords.py +89 -0
  557. qiskit/transpiler/passes/optimization/optimize_swap_before_measure.py +71 -0
  558. qiskit/transpiler/passes/optimization/remove_diagonal_gates_before_measure.py +41 -0
  559. qiskit/transpiler/passes/optimization/remove_final_reset.py +37 -0
  560. qiskit/transpiler/passes/optimization/remove_identity_equiv.py +70 -0
  561. qiskit/transpiler/passes/optimization/remove_reset_in_zero_state.py +37 -0
  562. qiskit/transpiler/passes/optimization/reset_after_measure_simplification.py +50 -0
  563. qiskit/transpiler/passes/optimization/split_2q_unitaries.py +63 -0
  564. qiskit/transpiler/passes/optimization/template_matching/__init__.py +19 -0
  565. qiskit/transpiler/passes/optimization/template_matching/backward_match.py +749 -0
  566. qiskit/transpiler/passes/optimization/template_matching/forward_match.py +452 -0
  567. qiskit/transpiler/passes/optimization/template_matching/maximal_matches.py +77 -0
  568. qiskit/transpiler/passes/optimization/template_matching/template_matching.py +370 -0
  569. qiskit/transpiler/passes/optimization/template_matching/template_substitution.py +633 -0
  570. qiskit/transpiler/passes/optimization/template_optimization.py +158 -0
  571. qiskit/transpiler/passes/routing/__init__.py +21 -0
  572. qiskit/transpiler/passes/routing/algorithms/__init__.py +33 -0
  573. qiskit/transpiler/passes/routing/algorithms/token_swapper.py +105 -0
  574. qiskit/transpiler/passes/routing/algorithms/types.py +46 -0
  575. qiskit/transpiler/passes/routing/algorithms/util.py +103 -0
  576. qiskit/transpiler/passes/routing/basic_swap.py +166 -0
  577. qiskit/transpiler/passes/routing/commuting_2q_gate_routing/__init__.py +25 -0
  578. qiskit/transpiler/passes/routing/commuting_2q_gate_routing/commuting_2q_block.py +60 -0
  579. qiskit/transpiler/passes/routing/commuting_2q_gate_routing/commuting_2q_gate_router.py +397 -0
  580. qiskit/transpiler/passes/routing/commuting_2q_gate_routing/pauli_2q_evolution_commutation.py +145 -0
  581. qiskit/transpiler/passes/routing/commuting_2q_gate_routing/swap_strategy.py +306 -0
  582. qiskit/transpiler/passes/routing/layout_transformation.py +119 -0
  583. qiskit/transpiler/passes/routing/lookahead_swap.py +390 -0
  584. qiskit/transpiler/passes/routing/sabre_swap.py +465 -0
  585. qiskit/transpiler/passes/routing/star_prerouting.py +433 -0
  586. qiskit/transpiler/passes/routing/utils.py +35 -0
  587. qiskit/transpiler/passes/scheduling/__init__.py +21 -0
  588. qiskit/transpiler/passes/scheduling/alignments/__init__.py +79 -0
  589. qiskit/transpiler/passes/scheduling/alignments/check_durations.py +70 -0
  590. qiskit/transpiler/passes/scheduling/alignments/reschedule.py +251 -0
  591. qiskit/transpiler/passes/scheduling/padding/__init__.py +17 -0
  592. qiskit/transpiler/passes/scheduling/padding/base_padding.py +284 -0
  593. qiskit/transpiler/passes/scheduling/padding/context_aware_dynamical_decoupling.py +876 -0
  594. qiskit/transpiler/passes/scheduling/padding/dynamical_decoupling.py +415 -0
  595. qiskit/transpiler/passes/scheduling/padding/pad_delay.py +90 -0
  596. qiskit/transpiler/passes/scheduling/scheduling/__init__.py +17 -0
  597. qiskit/transpiler/passes/scheduling/scheduling/alap.py +93 -0
  598. qiskit/transpiler/passes/scheduling/scheduling/asap.py +100 -0
  599. qiskit/transpiler/passes/scheduling/scheduling/base_scheduler.py +88 -0
  600. qiskit/transpiler/passes/scheduling/scheduling/set_io_latency.py +64 -0
  601. qiskit/transpiler/passes/scheduling/time_unit_conversion.py +237 -0
  602. qiskit/transpiler/passes/synthesis/__init__.py +21 -0
  603. qiskit/transpiler/passes/synthesis/aqc_plugin.py +153 -0
  604. qiskit/transpiler/passes/synthesis/clifford_unitary_synth_plugin.py +123 -0
  605. qiskit/transpiler/passes/synthesis/default_unitary_synth_plugin.py +653 -0
  606. qiskit/transpiler/passes/synthesis/high_level_synthesis.py +429 -0
  607. qiskit/transpiler/passes/synthesis/hls_plugins.py +2338 -0
  608. qiskit/transpiler/passes/synthesis/linear_functions_synthesis.py +41 -0
  609. qiskit/transpiler/passes/synthesis/plugin.py +738 -0
  610. qiskit/transpiler/passes/synthesis/solovay_kitaev_synthesis.py +318 -0
  611. qiskit/transpiler/passes/synthesis/unitary_synthesis.py +425 -0
  612. qiskit/transpiler/passes/utils/__init__.py +32 -0
  613. qiskit/transpiler/passes/utils/barrier_before_final_measurements.py +41 -0
  614. qiskit/transpiler/passes/utils/check_gate_direction.py +60 -0
  615. qiskit/transpiler/passes/utils/check_map.py +78 -0
  616. qiskit/transpiler/passes/utils/contains_instruction.py +45 -0
  617. qiskit/transpiler/passes/utils/control_flow.py +61 -0
  618. qiskit/transpiler/passes/utils/dag_fixed_point.py +36 -0
  619. qiskit/transpiler/passes/utils/error.py +69 -0
  620. qiskit/transpiler/passes/utils/filter_op_nodes.py +66 -0
  621. qiskit/transpiler/passes/utils/fixed_point.py +48 -0
  622. qiskit/transpiler/passes/utils/gate_direction.py +93 -0
  623. qiskit/transpiler/passes/utils/gates_basis.py +51 -0
  624. qiskit/transpiler/passes/utils/merge_adjacent_barriers.py +163 -0
  625. qiskit/transpiler/passes/utils/minimum_point.py +118 -0
  626. qiskit/transpiler/passes/utils/remove_barriers.py +50 -0
  627. qiskit/transpiler/passes/utils/remove_final_measurements.py +121 -0
  628. qiskit/transpiler/passes/utils/unroll_forloops.py +81 -0
  629. qiskit/transpiler/passmanager.py +503 -0
  630. qiskit/transpiler/passmanager_config.py +154 -0
  631. qiskit/transpiler/preset_passmanagers/__init__.py +93 -0
  632. qiskit/transpiler/preset_passmanagers/builtin_plugins.py +1114 -0
  633. qiskit/transpiler/preset_passmanagers/common.py +773 -0
  634. qiskit/transpiler/preset_passmanagers/generate_preset_pass_manager.py +443 -0
  635. qiskit/transpiler/preset_passmanagers/level0.py +104 -0
  636. qiskit/transpiler/preset_passmanagers/level1.py +108 -0
  637. qiskit/transpiler/preset_passmanagers/level2.py +109 -0
  638. qiskit/transpiler/preset_passmanagers/level3.py +110 -0
  639. qiskit/transpiler/preset_passmanagers/plugin.py +346 -0
  640. qiskit/transpiler/target.py +905 -0
  641. qiskit/transpiler/timing_constraints.py +59 -0
  642. qiskit/user_config.py +266 -0
  643. qiskit/utils/__init__.py +90 -0
  644. qiskit/utils/classtools.py +146 -0
  645. qiskit/utils/deprecation.py +382 -0
  646. qiskit/utils/lazy_tester.py +363 -0
  647. qiskit/utils/optionals.py +355 -0
  648. qiskit/utils/parallel.py +318 -0
  649. qiskit/utils/units.py +146 -0
  650. qiskit/version.py +84 -0
  651. qiskit/visualization/__init__.py +290 -0
  652. qiskit/visualization/array.py +207 -0
  653. qiskit/visualization/bloch.py +778 -0
  654. qiskit/visualization/circuit/__init__.py +15 -0
  655. qiskit/visualization/circuit/_utils.py +677 -0
  656. qiskit/visualization/circuit/circuit_visualization.py +735 -0
  657. qiskit/visualization/circuit/latex.py +668 -0
  658. qiskit/visualization/circuit/matplotlib.py +2041 -0
  659. qiskit/visualization/circuit/qcstyle.py +130 -0
  660. qiskit/visualization/circuit/styles/__init__.py +13 -0
  661. qiskit/visualization/circuit/styles/bw.json +202 -0
  662. qiskit/visualization/circuit/styles/clifford.json +202 -0
  663. qiskit/visualization/circuit/styles/iqp-dark.json +214 -0
  664. qiskit/visualization/circuit/styles/iqp.json +214 -0
  665. qiskit/visualization/circuit/styles/textbook.json +202 -0
  666. qiskit/visualization/circuit/text.py +1849 -0
  667. qiskit/visualization/circuit_visualization.py +19 -0
  668. qiskit/visualization/counts_visualization.py +487 -0
  669. qiskit/visualization/dag/__init__.py +13 -0
  670. qiskit/visualization/dag/dagstyle.py +103 -0
  671. qiskit/visualization/dag/styles/__init__.py +13 -0
  672. qiskit/visualization/dag/styles/color.json +10 -0
  673. qiskit/visualization/dag/styles/plain.json +5 -0
  674. qiskit/visualization/dag_visualization.py +389 -0
  675. qiskit/visualization/exceptions.py +21 -0
  676. qiskit/visualization/gate_map.py +1424 -0
  677. qiskit/visualization/library.py +40 -0
  678. qiskit/visualization/pass_manager_visualization.py +312 -0
  679. qiskit/visualization/state_visualization.py +1546 -0
  680. qiskit/visualization/style.py +223 -0
  681. qiskit/visualization/timeline/__init__.py +21 -0
  682. qiskit/visualization/timeline/core.py +495 -0
  683. qiskit/visualization/timeline/drawings.py +260 -0
  684. qiskit/visualization/timeline/generators.py +506 -0
  685. qiskit/visualization/timeline/interface.py +444 -0
  686. qiskit/visualization/timeline/layouts.py +115 -0
  687. qiskit/visualization/timeline/plotters/__init__.py +16 -0
  688. qiskit/visualization/timeline/plotters/base_plotter.py +58 -0
  689. qiskit/visualization/timeline/plotters/matplotlib.py +195 -0
  690. qiskit/visualization/timeline/stylesheet.py +301 -0
  691. qiskit/visualization/timeline/types.py +148 -0
  692. qiskit/visualization/transition_visualization.py +369 -0
  693. qiskit/visualization/utils.py +49 -0
  694. qiskit-2.1.0rc1.dist-info/METADATA +221 -0
  695. qiskit-2.1.0rc1.dist-info/RECORD +699 -0
  696. qiskit-2.1.0rc1.dist-info/WHEEL +6 -0
  697. qiskit-2.1.0rc1.dist-info/entry_points.txt +88 -0
  698. qiskit-2.1.0rc1.dist-info/licenses/LICENSE.txt +203 -0
  699. qiskit-2.1.0rc1.dist-info/top_level.txt +1 -0
@@ -0,0 +1,1352 @@
1
+ # This code is part of Qiskit.
2
+ #
3
+ # (C) Copyright IBM 2017, 2018.
4
+ #
5
+ # This code is licensed under the Apache License, Version 2.0. You may
6
+ # obtain a copy of this license in the LICENSE.txt file in the root directory
7
+ # of this source tree or at http://www.apache.org/licenses/LICENSE-2.0.
8
+ #
9
+ # Any modifications or derivative works of this code must retain this
10
+ # copyright notice, and modified files need to carry a notice indicating
11
+ # that they have been altered from the originals.
12
+
13
+ """
14
+ =====================================
15
+ Transpiler (:mod:`qiskit.transpiler`)
16
+ =====================================
17
+
18
+ .. currentmodule:: qiskit.transpiler
19
+
20
+ Overview
21
+ ========
22
+
23
+ Transpilation is the process of rewriting a given input circuit to match
24
+ the topology of a specific quantum device, and/or to optimize the circuit
25
+ for execution on present day noisy quantum systems.
26
+
27
+ Most circuits must undergo a series of transformations that make them compatible with
28
+ a given target device, and optimize them to reduce the effects of noise on the
29
+ resulting outcomes. Rewriting quantum circuits to match hardware constraints and
30
+ optimizing for performance can be far from trivial. The flow of logic in the rewriting
31
+ tool chain need not be linear, and can often have iterative sub-loops, conditional
32
+ branches, and other complex behaviors. That being said, the standard
33
+ compilation flow follows the structure given below:
34
+
35
+ .. image:: /source_images/transpiling_core_steps.png
36
+ :alt: The transpilation process takes the input circuit, applies the transpilation \
37
+ passes, then produces the output circuit.
38
+
39
+ Qiskit uses the graph-based :class:`.DAGCircuit` intermediate representation (IR) of a circuit
40
+ throughout the transpiler stack, rather than the tree-based :class:`.QuantumCircuit`. A transpiler
41
+ pipeline is a :class:`.PassManager` object, whose :meth:`.PassManager.run` method takes in a
42
+ :class:`.QuantumCircuit` and converts it to a :class:`.DAGCircuit`, then subjects the IR to a
43
+ sequence of *passes*, finally returning a :class:`.QuantumCircuit` back. A pass is either an
44
+ :class:`.AnalysisPass`, which calculates and stores properties about the circuit in the
45
+ stateful :class:`.PropertySet`, or a :class:`.TransformationPass`, which modifies the IR
46
+ to achieve a particular singular goal. You can think of a pipeline as being split into
47
+ "stages", where each stage is responsible for one high-level transformation.
48
+
49
+ Qiskit exposes a default transpilation pipeline builder using the function
50
+ :func:`.generate_preset_pass_manager`. This returns a properly configured pipeline for complete
51
+ transpilation, at a chosen ``optimization_level`` (between 0 and 3, inclusive). Unless you are
52
+ looking for something highly specialized, this is almost certainly the entry point you want. A
53
+ sample transpilation looks like::
54
+
55
+ from qiskit.circuit import QuantumCircuit
56
+ from qiskit.transpiler import generate_preset_pass_manager
57
+ from qiskit_ibm_runtime import QiskitRuntimeService
58
+
59
+ # Any abstract circuit you want:
60
+ abstract = QuantumCircuit(2)
61
+ abstract.h(0)
62
+ abstract.cx(0, 1)
63
+
64
+ # Any method you like to retrieve the backend you want to run on:
65
+ backend = QiskitRuntimeService().backend("some-backend")
66
+
67
+ # Create the pass manager for the transpilation ...
68
+ pm = generate_preset_pass_manager(backend=backend)
69
+ # ... and use it (as many times as you like).
70
+ physical = pm.run(abstract)
71
+
72
+ For most use cases, this is all you need.
73
+ All of Qiskit's transpiler infrastructure is highly extensible and configurable, however.
74
+ The rest of this page details how to harness the low-level capabilities of the transpiler stack.
75
+
76
+ .. _transpiler-preset:
77
+
78
+ Preset pass managers
79
+ ====================
80
+
81
+ The function :func:`.generate_preset_pass_manager` creates the "preset pass managers".
82
+ These are all instances of :class:`.PassManager`, so are used by passing a :class:`.QuantumCircuit`
83
+ to the :meth:`.PassManager.run` method. More specifically, the preset pass managers are instances
84
+ of :class:`.StagedPassManager`, which allows greater configuration of the individual stages of a
85
+ transpilation, including pre- and post-stage hooks.
86
+
87
+ A preset pass manager has up to six named stages. These are summarized, in order of execution,
88
+ below, with more in-depth information in the following subsections.
89
+
90
+ ``init``
91
+ Abstract-circuit optimizations, and reduction of multi-qubit operations to one- and two-qubit
92
+ operations. See :ref:`transpiler-preset-stage-init` for more details.
93
+
94
+ ``layout``
95
+ Choose an initial mapping of virtual qubits to physical qubits, including expansion of the
96
+ circuit to contain explicit ancillas. This stage sometimes subsumes ``routing``. See
97
+ :ref:`transpiler-preset-stage-layout` for more details.
98
+
99
+ ``routing``
100
+ Insert gates into the circuit to ensure it matches the connectivity constraints of the
101
+ :class:`.Target`. The inserted gates need not match the target ISA yet, so are often just
102
+ ``swap`` instructions. This stage is sometimes omitted, when the ``layout`` stage handles its
103
+ job. See :ref:`transpiler-preset-stage-routing` for more details.
104
+
105
+ ``translation``
106
+ Convert all gates in the circuit to ones matching the ISA of the :class:`Target`. See
107
+ :ref:`transpiler-preset-stage-translation` for more details.
108
+
109
+ ``optimization``
110
+ Low-level, hardware-aware optimizations. Unlike the abstract optimizations of the ``init``
111
+ stage, this stage acts on a physical circuit. See :ref:`transpiler-preset-stage-optimization`
112
+ for more details.
113
+
114
+ ``scheduling``
115
+ Insert :class:`~.circuit.Delay` instructions to make the wall-clock timing of a circuit
116
+ explicit. This may also include hardware-aware online error reduction techniques such as
117
+ dynamical decoupling, which are dependent on knowing wall-clock timings. See
118
+ :ref:`transpiler-preset-stage-scheduling` for more details.
119
+
120
+ The preset transpiler pipelines can also be configured at a high level by setting an
121
+ ``optimization_level``. This is an integer from 0 to 3, inclusive, indicating the relative effort to
122
+ exert in attempting to optimize the circuit for the hardware. Level 0 disables all unnecessary
123
+ optimizations; only transformations needed to make the circuit runnable are used. On
124
+ the other end, level 3 enables a full range of optimization techniques, some of which can be very
125
+ expensive in compilation time. Similar to classical compilers, optimization level 3 is not always
126
+ guaranteed to produce the best results. Qiskit defaults to optimization level 2, as a trade-off
127
+ between compilation time and the expected amount of optimization.
128
+
129
+ The optimization level affects which implementations are used for a given stage by default, though
130
+ this can be overridden by passing explicit ``<stage>_method="<choice>"`` arguments to
131
+ :func:`.generate_preset_pass_manager`.
132
+
133
+ .. note::
134
+
135
+ The preset pass managers almost always include stochastic, heuristic-based passes. If you need
136
+ to ensure reproducibility of a compilation, pass a known integer to the ``seed_transpiler``
137
+ argument to the generator functions.
138
+
139
+ This stochasticity arises because many of the problems the transpiler must solve are known to be
140
+ non-polynomial in complexity, but transpilation must complete in a workable amount of time.
141
+
142
+ Choosing preset stage implementations
143
+ -------------------------------------
144
+
145
+ Qiskit includes several implementations of the above stages, and more can be installed as
146
+ separate "plugins". To control which implementation of a stage is used, pass its name to the
147
+ ``<stage>_method`` keyword argument of the two functions, such as
148
+ ``translation_method="translator"``. To read more about implementing such external plugins for a
149
+ stage, see :mod:`qiskit.transpiler.preset_passmanagers.plugin`.
150
+
151
+ For example, to generate a preset pass manager at optimization level 1 that explicitly uses the
152
+ ``trivial`` method for layout with the ``sabre`` method for routing, we would do:
153
+
154
+ .. plot::
155
+ :include-source:
156
+ :nofigs:
157
+
158
+ from qiskit.transpiler import generate_preset_pass_manager
159
+ from qiskit.providers.fake_provider import GenericBackendV2
160
+
161
+ # Whatever backend you like:
162
+ backend = GenericBackendV2(num_qubits=5)
163
+
164
+ pass_manager = generate_preset_pass_manager(
165
+ optimization_level=1,
166
+ backend=backend,
167
+ layout_method="trivial",
168
+ routing_method="sabre",
169
+ )
170
+
171
+ .. note::
172
+
173
+ The built-in set of available plugins for each stage is part of Qiskit's public API, and subject
174
+ to all the stability guarantees. This includes the high-level logical effects of that method
175
+ (for example, ``routing_method="sabre"`` will always use a Sabre-derived algorithm). The exact
176
+ internal construction of the :class:`.PassManager` representing the stage is not, however; the
177
+ order of passes might change between minor versions, or new passes might be introduced.
178
+
179
+ For any stage that has one, the method named ``"default"`` is the most subject to change.
180
+ Qiskit typically only makes complete algorithmic changes in the default method across a
181
+ major-version boundary, but it might rebalance heuristics and add new passes to default
182
+ methods between minor versions.
183
+
184
+ Since the output of :func:`.generate_preset_pass_manager` is a :class:`.StagedPassManager`, you can
185
+ also modify the pass manager after its creation to provide an entirely custom stage implementation.
186
+ For example, if you wanted to run a custom scheduling stage using dynamical decoupling (using the
187
+ :class:`~.PadDynamicalDecoupling` pass) and also add initial logical optimization prior to routing,
188
+ you would do something like the following (building off the previous example):
189
+
190
+ .. plot::
191
+ :include-source:
192
+ :nofigs:
193
+
194
+ import numpy as np
195
+ from qiskit.providers.fake_provider import GenericBackendV2
196
+ from qiskit.circuit import library as lib
197
+ from qiskit.transpiler import PassManager, generate_preset_pass_manager
198
+ from qiskit.transpiler.passes import (
199
+ ALAPScheduleAnalysis,
200
+ InverseCancellation,
201
+ PadDynamicalDecoupling,
202
+ )
203
+
204
+ backend = GenericBackendV2(num_qubits=5)
205
+ dd_sequence = [lib.XGate(), lib.XGate()]
206
+ scheduling_pm = PassManager(
207
+ [
208
+ ALAPScheduleAnalysis(target=backend.target),
209
+ PadDynamicalDecoupling(target=backend.target, dd_sequence=dd_sequence),
210
+ ]
211
+ )
212
+ inverse_gate_list = [
213
+ lib.CXGate(),
214
+ lib.HGate(),
215
+ (lib.RXGate(np.pi / 4), lib.RXGate(-np.pi / 4)),
216
+ (lib.PhaseGate(np.pi / 4), lib.PhaseGate(-np.pi / 4)),
217
+ (lib.TGate(), lib.TdgGate()),
218
+ ]
219
+ logical_opt = PassManager([InverseCancellation(inverse_gate_list)])
220
+
221
+ pass_manager = generate_preset_pass_manager(optimization_level=0)
222
+ # Add pre-layout stage to run extra logical optimization
223
+ pass_manager.pre_layout = logical_opt
224
+ # Set scheduling stage to custom pass manager
225
+ pass_manager.scheduling = scheduling_pm
226
+
227
+ Now, when the staged pass manager is run via the :meth:`~.StagedPassManager.run` method,
228
+ the ``logical_opt`` pass manager will be called before the ``layout`` stage, and the
229
+ ``scheduling_pm`` pass manager will be used for the ``scheduling`` stage instead of the default.
230
+
231
+ If you are constructing custom stages for the preset pass managers, you may find some of the
232
+ low-level helper functions in :mod:`qiskit.transpiler.preset_passmanagers` useful.
233
+
234
+ .. _transpiler-preset-stage-init:
235
+
236
+ Initialization stage
237
+ --------------------
238
+
239
+ .. seealso::
240
+ `Init stage explanation <https://quantum.cloud.ibm.com/docs/guides/transpiler-stages#init-stage>`__
241
+ Higher-level user-facing explanation of the init stage in the IBM Quantum guide.
242
+
243
+ The ``init`` stage is responsible for high-level, logical optimizations on abstract circuits, and
244
+ for lowering multi-qubit (3+) operations down to a series of one- and two-qubit operations. As this is
245
+ the first stage run, its input is a fully abstract circuit. The ``init`` stage must be able to
246
+ handle custom user-defined gates, and all the high-level abstract circuit-description objects, such
247
+ as :class:`.AnnotatedOperation`.
248
+
249
+ The output of the ``init`` stage is an abstract circuit that contains only one- and two-qubit
250
+ operations.
251
+
252
+ When writing :ref:`stage plugins <transpiler-preset-stage-plugins>`, the entry point for ``init`` is
253
+ ``qiskit.transpiler.init``. The built-in plugins are:
254
+
255
+ .. list-table::
256
+ :header-rows: 1
257
+
258
+ * - Method
259
+ - Summary
260
+
261
+ * - :ref:`default <transpiler-preset-stage-init-default>`
262
+ - Built-in unrolling of multi-qubit operations and abstract optimizations.
263
+
264
+
265
+ .. _transpiler-preset-stage-init-default:
266
+
267
+ Built-in ``default`` plugin
268
+ ...........................
269
+
270
+ At optimization level 0, no abstract optimization is done. The default plugin simply "unrolls"
271
+ operations with more than three qubits by accessing their hierarchical
272
+ :class:`~.circuit.Instruction.definition` fields.
273
+
274
+ At optimization levels 1 and above, the default plugin also does simple cancellation of adjacent
275
+ inverse gates, such as two back-to-back ``cx`` gates.
276
+
277
+ At optimization levels 2 and 3, the default plugin enables a much wider range of abstract
278
+ optimizations. This includes:
279
+
280
+ * "Virtual permutation elision" (see :class:`.ElidePermutations`), where explicit
281
+ permutation-inducing operations are removed and instead effected as remapping of virtual qubits.
282
+ * Analysis of the commutation structure of the IR to find pairs of gates that can be canceled out.
283
+ * Numerical splitting of two-qubit operations that can be expressed as a series of separable
284
+ one-qubit operations.
285
+ * Removal of imperceivable operations, such as tiny-angle Pauli rotations and diagonal operations
286
+ immediately preceding measurements.
287
+
288
+ .. _transpiler-preset-stage-layout:
289
+
290
+ Layout stage
291
+ ------------
292
+
293
+ .. seealso::
294
+ `Layout stage explanation`__
295
+ Higher-level user-facing explanation of the layout stage in the IBM Quantum guide.
296
+
297
+ __ https://quantum.cloud.ibm.com/docs/guides/transpiler-stages#layout-stage
298
+
299
+ The layout stage is responsible for making an initial mapping between the virtual qubits of the
300
+ input circuit, and the hardware qubits of the target. This includes expanding the input circuit
301
+ with explicit ancillas so it has as many qubits as the target has, and rewriting all operations in
302
+ terms of hardware qubits. You may also see this problem called the "placement" problem in other
303
+ toolkits or literature.
304
+
305
+ The layout stage must set the properties ``layout`` and ``original_qubit_indices`` in the pipeline's
306
+ :class:`.PropertySet`.
307
+
308
+ .. note::
309
+
310
+ All built-in plugins for the layout stage will give priority to an explicit layout selected
311
+ using the ``initial_layout`` argument to :func:`.generate_preset_pass_manager` or
312
+ :func:`.transpile`.
313
+
314
+ At any given point in a circuit, we can identify a mapping between currently active "virtual" qubits
315
+ of the input circuit to hardware qubits of the backend. A hardware qubit can only ever represent a
316
+ single virtual qubit at a given point, but the mapping might vary over the course of the circuit.
317
+ In principle, some virtual qubits might not be mapped at all points in the circuit
318
+ execution, if the lifetime of a virtual qubit state can be shortened, though Qiskit's built-in
319
+ pipelines do not use this currently.
320
+
321
+ .. image:: /source_images/mapping.png
322
+ :alt: Illustration of how virtual qubits from an input circuit could be mapped to hardware
323
+ qubits on a backend device's connectivity map.
324
+
325
+ The layout stage is not responsible for ensuring that the connectivity of the target
326
+ is respected all the way through the circuit, nor that all operations are valid for direct execution
327
+ on the target; these are the responsibilities of the :ref:`routing
328
+ <transpiler-preset-stage-routing>` and :ref:`translation <transpiler-preset-stage-translation>`
329
+ stages, respectively.
330
+
331
+ The choice of initial layout is one of the most important factors that affects the quality of the
332
+ output circuit. The layout stage is often the most computationally expensive stage in the default
333
+ pipelines; the default plugin for layout even tries several different algorithms (described in more
334
+ detail in :ref:`transpiler-preset-stage-layout-default`).
335
+
336
+ The ideal situation for the layout stage is to find a "perfect" layout, where all operations
337
+ respect the connectivity constraints of the :class:`.Target` such that the routing stage
338
+ is not required. This is typically not possible for arbitrary input circuits, but when it is, the
339
+ :class:`.VF2Layout` pass can be used to find a valid initial layout. If multiple perfect layouts
340
+ are found, a scoring heuristic based on estimated error rates is used to decide which one to use.
341
+
342
+ In all built-in plugins, passing the :func:`.generate_preset_pass_manager` argument
343
+ ``initial_layout`` causes the given layout to be used verbatim, skipping the individual "choosing"
344
+ logic. All built-in plugins also handle embedding the circuit into the full width of the device,
345
+ including assigning ancillas.
346
+
347
+ If you write your own layout plugin, you might find :func:`.generate_embed_passmanager` useful for
348
+ automating the "embedding" stage of the layout application.
349
+
350
+ When writing :ref:`stage plugins <transpiler-preset-stage-plugins>`, the entry point for ``layout``
351
+ is ``qiskit.transpiler.layout``. The built-in plugins are:
352
+
353
+ .. list-table::
354
+ :header-rows: 1
355
+
356
+ * - Method
357
+ - Summary
358
+
359
+ * - :ref:`default <transpiler-preset-stage-layout-default>`
360
+ - At the highest optimization levels, attempts to find a perfect layout, then tries a
361
+ Sabre-based layout-and-routing combined pass.
362
+
363
+ * - :ref:`dense <transpiler-preset-stage-layout-dense>`
364
+ - Finds the densest subgraph (in terms of qubit link degrees) of the backend to use as the
365
+ initial qubits.
366
+
367
+ * - :ref:`trivial <transpiler-preset-stage-layout-trivial>`
368
+ - Maps virtual qubit 0 to physical qubit 0, and so on.
369
+
370
+ * - :ref:`sabre <transpiler-preset-stage-layout-sabre>`
371
+ - Uses `Qiskit's enhanced Sabre layout algorithm <sabre-lightsabre-paper_>`_.
372
+
373
+ At all optimization levels, the default layout method is ``default``, though the structure of this
374
+ stage changes dramatically based on the level.
375
+
376
+ .. _transpiler-preset-stage-layout-default:
377
+
378
+ Built-in ``default`` plugin
379
+ ...........................
380
+
381
+ An amalgamation of several different layout techniques.
382
+
383
+ At optimization level 0, the trivial layout is chosen.
384
+
385
+ At optimization levels above 0, there is a two-step process:
386
+
387
+ #. First, use :class:`.VF2Layout` to attempt to find a "perfect" layout. The maximum number of
388
+ calls to the isomorphism evaluator increases with the optimization level. For huge, complex
389
+ targets, we are not guaranteed to find perfect layouts even if they exist, but the chance
390
+ increases with the optimization level.
391
+
392
+ #. If no perfect layout can be found, use :class:`.SabreLayout` to choose an initial layout, with
393
+ the numbers of initial layout trials, swap-map trials, and forwards–backwards iterations
394
+ increasing with the optimization level.
395
+
396
+ In addition, optimization level 1 also tries the trivial layout before the VF2-based version,
397
+ for historical backwards compatibility.
398
+
399
+
400
+ .. _transpiler-preset-stage-layout-dense:
401
+
402
+ Built-in ``dense`` plugin
403
+ .........................
404
+
405
+ Uses the :class:`.DenseLayout` pass to choose the layout. This pass finds the densest connected
406
+ subgraph of the complete target connectivity graph, where "densest" means that hardware qubits with
407
+ the greatest number of available connections are preferred. The virtual-to-hardware mapping is
408
+ completed by assigning the highest-degree virtual qubits to the highest-degree hardware qubits.
409
+
410
+ This is a relatively cheap heuristic for choosing an initial layout, but typically has far worse
411
+ output quality than Sabre-based methods. The :ref:`default layout plugin
412
+ <transpiler-preset-stage-layout-default>` uses the initial mapping selected by :class:`.DenseLayout`
413
+ as one of its initial layouts to seed the Sabre algorithm.
414
+
415
+ .. _transpiler-preset-stage-layout-trivial:
416
+
417
+ Built-in ``trivial`` plugin
418
+ ...........................
419
+
420
+ Uses the :class:`.TrivialLayout` pass to choose the layout. This is the simplest assignment, where
421
+ each virtual qubit is assigned to the hardware qubit with the same index, so virtual qubit 0 is
422
+ mapped to hardware qubit 0, and so on.
423
+
424
+ This method is most useful for hardware-characterization experiments, where the incoming "abstract"
425
+ circuit is already full-width on the device, its operations correspond to physical operations, and
426
+ the transpiler is just being invoked to formalize the creation of a physical
427
+ :class:`.QuantumCircuit`.
428
+
429
+
430
+ .. _transpiler-preset-stage-layout-sabre:
431
+
432
+ Built-in ``sabre`` plugin
433
+ .........................
434
+
435
+ Uses the :class:`.SabreLayout` to choose an initial layout, using Qiskit's modified :ref:`Sabre
436
+ routing algorithm <transpiler-preset-stage-routing-sabre>` as the subroutine to swap-map the
437
+ candidate circuit both forwards and backwards.
438
+
439
+ Summarily, the layout component of `the original Sabre algorithm <sabre-original-paper_>`_
440
+ chooses an initial layout arbitrarily, then tries to "improve" it by running routing on the circuit,
441
+ reversing the circuit, and running routing on the reversed circuit with the previous "final"
442
+ virtual-to-hardware assignment as the initial state. The configured optimization level decides how
443
+ many iterations of this to-and-fro to do, and how many different random initial layouts to try.
444
+
445
+ The principal difference to the :ref:`default stage <transpiler-preset-stage-layout-default>` at
446
+ optimization levels other than 0 is that this plugin *only* runs the Sabre-based algorithm. It
447
+ does not attempt to find a perfect layout, nor attempt the trivial layout.
448
+
449
+
450
+
451
+ .. _transpiler-preset-stage-routing:
452
+
453
+ Routing stage
454
+ -------------
455
+
456
+ .. seealso::
457
+ `Routing stage explanation`__
458
+ Higher-level user-facing explanation of the routing stage in the IBM Quantum guide.
459
+
460
+ __ https://quantum.cloud.ibm.com/docs/guides/transpiler-stages#routing-stage
461
+
462
+ The routing stage ensures that the virtual connectivity graph of the circuit is compatible with the
463
+ hardware connectivity graph of the target. In simpler terms, the routing stage makes sure that all
464
+ two-qubit gates in the circuit are mapped to hardware qubits that have a defined two-qubit operation
465
+ in the target ISA. You may also see this problem referred to as the "mapping" or "swap-mapping"
466
+ problem in other toolkits or literature.
467
+
468
+ Routing algorithms typically do this by inserting ``swap`` gates into the circuit, and modifying the
469
+ virtual-to-hardware mapping of qubits over the course of the circuit execution.
470
+
471
+ The routing stage does not need to ensure that all the gates in the circuit are valid for the target
472
+ ISA. For example, a routing plugin can leave literal ``swap`` gates in the circuit, even if the
473
+ :class:`.Target` does not contain :class:`.SwapGate`. However, there must be at least one two-qubit
474
+ gate defined in the :class:`.Target` for any pair of hardware qubits that has a gate applied in the
475
+ circuit.
476
+
477
+ The routing stage must set the ``final_layout`` and ``virtual_permutation_layout`` properties in
478
+ the :class:`.PropertySet` if routing has taken place.
479
+
480
+ All of Qiskit's built-in routing stages will additionally run the :class:`.VF2PostLayout` pass after
481
+ routing. This might reassign the initial layout, if lower-error qubits can be found. This
482
+ pass is very similar to the :class:`.VF2Layout` class that :ref:`the default layout plugin
483
+ <transpiler-preset-stage-layout-default>` uses, except in :class:`.VF2PostLayout` we can guarantee
484
+ that there is at least one isomorphic induced subgraph of the target topology that matches the
485
+ circuit topology.
486
+
487
+ .. note::
488
+
489
+ Qiskit's built-in routing plugins all generally assume that all pairs of qubits with a
490
+ defined two-qubit link have a *universal* set of gates defined for those two qubits. Hardware
491
+ does not necessarily need to respect this (for example, if the only defined two-qubit gate is
492
+ ``swap``, then entangling operations like ``cx`` cannot be realized), but Qiskit does not yet
493
+ consider this possibility.
494
+
495
+ .. note::
496
+
497
+ Finding the minimal number of swaps to insert is known to be a non-polynomial problem. This
498
+ means it is prohibitively expensive to attempt, so many of Qiskit's built-in algorithms are
499
+ stochastic, and you may see large variations between different compilations. If you need
500
+ reproducibility, be sure to set the ``seed_transpiler`` argument of
501
+ :func:`.generate_preset_pass_manager` or :func:`.transpile`.
502
+
503
+ When writing :ref:`stage plugins <transpiler-preset-stage-plugins>`, the entry point for ``routing``
504
+ is ``qiskit.transpiler.routing``. The built-in plugins are:
505
+
506
+ .. list-table::
507
+ :header-rows: 1
508
+
509
+ * - Method
510
+ - Summary
511
+
512
+ * - :ref:`default <transpiler-preset-stage-routing-default>`
513
+ - Use a Qiskit-chosen default routing method.
514
+
515
+ * - :ref:`sabre <transpiler-preset-stage-routing-sabre>`
516
+ - Default. Uses `Qiskit's modified Sabre routing algorithm <sabre-lightsabre-paper_>`_ to
517
+ swap map.
518
+
519
+ * - :ref:`none <transpiler-preset-stage-routing-none>`
520
+ - Disable routing. Raises an error if routing is required.
521
+
522
+ * - :ref:`basic <transpiler-preset-stage-routing-basic>`
523
+ - Greedy swap insertion to route a single operation at a time.
524
+
525
+ * - :ref:`lookahead <transpiler-preset-stage-routing-lookahead>`
526
+ - Breadth-first search with heuristic pruning to find swaps that make gates executable.
527
+
528
+ .. _transpiler-preset-stage-routing-default:
529
+
530
+ Built-in ``default`` plugin
531
+ ...........................
532
+
533
+ Use a Qiskit-chosen default method for routing. As of Qiskit 2.0, the chosen algorithm is the same
534
+ as :ref:`transpiler-preset-stage-routing-sabre`, though in practice, usually the :ref:`built-in
535
+ default layout-stage plugin <transpiler-preset-stage-layout-default>` will run the Sabre-based
536
+ routing algorithm, and the routing stage will only be used to run :class:`.VF2PostLayout`.
537
+
538
+ .. _transpiler-preset-stage-routing-none:
539
+
540
+ Built-in ``none`` plugin
541
+ ........................
542
+
543
+ A dummy plugin used to disable routing entirely. This can occasionally be useful for
544
+ hardware-configuration experiments, or in certain special cases of partial compilation.
545
+
546
+ .. _transpiler-preset-stage-routing-basic:
547
+
548
+ Built-in ``basic`` plugin
549
+ .........................
550
+
551
+ Uses the :class:`.BasisSwap` greedy swap-insertion algorithm. This is conceptually very simple; for
552
+ each operation in topological order, insert the shortest-path swaps needed to make the connection
553
+ executable on the device.
554
+
555
+ The optimization level only affects the amount of work the :class:`.VF2PostLayout` step does to
556
+ attempt to improve the initial layout after routing.
557
+
558
+ This method typically has poor output quality.
559
+
560
+ .. _transpiler-preset-stage-routing-lookahead:
561
+
562
+ Built-in ``lookahead`` plugin
563
+ .............................
564
+
565
+ Uses the :class:`.LookaheadSwap` algorithm to route. This is essentially a breadth-first search
566
+ at producing a swap network, where the tree being explored is pruned down to a small number of
567
+ candidate swaps at each depth.
568
+
569
+ This algorithm is similar to the ``basic`` heuristic of :ref:`the "sabre" plugin
570
+ <transpiler-preset-stage-routing-sabre>`, except it considers the following effects of each swap to
571
+ a small depth as well.
572
+
573
+ The optimization level affects the search depth, the amount of per-depth pruning, and amount of work
574
+ done by :class:`.VF2PostLayout` to post-optimize the initial layout.
575
+
576
+ In practice, :ref:`the "sabre" plugin <transpiler-preset-stage-routing-sabre>` runs several orders
577
+ of magnitude faster, and produces better output.
578
+
579
+ .. _transpiler-preset-stage-routing-sabre:
580
+
581
+ Built-in ``sabre`` plugin
582
+ .........................
583
+
584
+ Uses the :class:`.SabreSwap` algorithm to route. This uses `Qiskit's enhanced version
585
+ <sabre-lightsabre-paper_>`_ of `the original Sabre routing algorithm <sabre-original-paper_>`_.
586
+
587
+ This routing algorithm runs with threaded parallelism to consider several different possibilities
588
+ for routing, choosing the one that minimizes the number of inserted swaps.
589
+
590
+ The optimization level affects how many different stochastic seeds are attempted for the full
591
+ routing, and the amount of work done by :class:`.VF2PostLayout` to post-optimize the initial layout.
592
+
593
+ This is almost invariably the best-performing built-in plugin, and the one Qiskit uses by default in
594
+ all cases where routing is necessary.
595
+
596
+ .. _transpiler-preset-stage-translation:
597
+
598
+ Translation stage
599
+ -----------------
600
+
601
+ .. seealso::
602
+ `Translation stage explanation`__
603
+ Higher-level user-facing explanation of the translation stage in the IBM Quantum guide.
604
+
605
+ .. __: https://quantum.cloud.ibm.com/docs/guides/transpiler-stages#translation-stage
606
+
607
+ The translation stage is responsible for rewriting all gates in the circuit into ones that are
608
+ supported by the target ISA. For example, if a ``cx`` is requested on hardware qubits 0 and 1, but
609
+ the ISA only contains a ``cz`` operation on those qubits, the translation stage must find a way of
610
+ representing the ``cx`` gate using the ``cz`` and available one-qubit gates.
611
+
612
+ The translation stage is called before entering the optimization stage. Optimization plugins
613
+ (including Qiskit's built-in plugins) may also use the translation stage as a "fixup" stage after
614
+ the optimization loop, if the optimization loop returns a circuit that includes non-ISA gates. This
615
+ latter situation is fairly common; the optimization loop may only be concerned with minimizing
616
+ properties like "number of two-qubit gates", and will leave its output in terms of locally
617
+ equivalent gates, which the translation stage can easily rewrite without affecting the target
618
+ optimization properties. This allows easier separation of concerns between the two stages. Some
619
+ optimization plugins may be stricter in their output, and so this follow-up to the translation stage
620
+ may no longer be necessary.
621
+
622
+ When writing :ref:`stage plugins <transpiler-preset-stage-plugins>`, the entry point for
623
+ ``translation`` is ``qiskit.transpiler.translation``. The built-in plugins are:
624
+
625
+ .. list-table::
626
+ :header-rows: 1
627
+
628
+ * - Method
629
+ - Summary
630
+
631
+ * - :ref:`default <transpiler-preset-stage-translation-translator>`
632
+ - Use a Qiskit-chosen default translation method.
633
+
634
+ * - :ref:`translator <transpiler-preset-stage-translation-translator>`
635
+ - Symbolic translation of gates to the target basis using known equivalences.
636
+
637
+ * - :ref:`synthesis <transpiler-preset-stage-translation-synthesis>`
638
+ - Collect each run of one- and two-qubit gates into a matrix representation, and resynthesize
639
+ from there.
640
+
641
+ .. _transpiler-preset-stage-translation-default:
642
+
643
+ Built-in ``default`` plugin
644
+ ...........................
645
+
646
+ Use a Qiskit-chosen default method for translation. As of Qiskit 2.0, this is the same as
647
+ :ref:`transpiler-preset-stage-translation-translator`, but the chosen algorithm might change during
648
+ the 2.x series, either for all targets, or only for certain classes of target.
649
+
650
+ .. _transpiler-preset-stage-translation-synthesis:
651
+
652
+ Built-in ``synthesis`` plugin
653
+ .............................
654
+
655
+ Collect runs of gates on the same qubits into matrix form, and then resynthesize using the
656
+ :class:`.UnitarySynthesis` pass (with the configured ``unitary_synthesis_method``). This is, in
657
+ large part, similar to the optimization loop itself at high optimization levels.
658
+
659
+ The collection into matrices is typically more expensive than matrix-free translations, but in
660
+ principle the quality of the translations can be better. In practice, this requires a synthesis
661
+ algorithm tailored to the target ISA, which makes this method less general than other methods. It
662
+ can produce higher-quality results when targeting simple ISAs that match the synthesis routines
663
+ already in Qiskit.
664
+
665
+ If this method is used, you might not need the optimization loop.
666
+
667
+ The optimization level has no effect on this plugin.
668
+
669
+
670
+ .. _transpiler-preset-stage-translation-translator:
671
+
672
+ Built-in ``translator`` plugin
673
+ ..............................
674
+
675
+ Uses the :class:`.BasisTranslator` algorithm to symbolically translate gates into the target basis.
676
+ At a high level, this starts from the set of gates requested by the circuit, and uses rules from a
677
+ given :class:`.EquivalenceLibrary` (typically the :data:`.SessionEquivalenceLibrary`) to move
678
+ towards the ISA.
679
+
680
+ For a Clifford+T basis set, the single-qubit rotation gates are approximated using the
681
+ :class:`.SolovayKitaevDecomposition` algorithm.
682
+
683
+ This is the default translation method.
684
+
685
+ The optimization level has no effect on this plugin.
686
+
687
+
688
+ .. _transpiler-preset-stage-optimization:
689
+
690
+ Optimization stage
691
+ ------------------
692
+
693
+ .. seealso::
694
+ `Optimization stage explanation`__
695
+ Higher-level user-facing explanation of the optimization stage in the IBM Quantum guide.
696
+
697
+ .. __: https://quantum.cloud.ibm.com/docs/guides/transpiler-stages#optimization-stage
698
+
699
+ The optimization stage is for low-level hardware-aware optimizations. Unlike :ref:`the init stage
700
+ <transpiler-preset-stage-init>`, the input to this stage is a circuit that is already
701
+ ISA-compatible, so a low-level optimization plugin can be tailored for a particular ISA.
702
+
703
+ There are very few requirements on an optimization plugin, other than it takes in ISA-supported
704
+ circuits, and returns ISA-supported circuits. An optimization plugin will often contain a loop,
705
+ such as the :class:`.DoWhileController`, and might include the configured translation stage
706
+ as a fix-up pipeline.
707
+
708
+ Qiskit's built-in optimization plugins are general, and apply well to most real-world ISAs for
709
+ non-error-corrected devices. The built-in plugins are less well-suited to ISAs that have no
710
+ continuously parametrized single-qubit gate.
711
+
712
+ When writing :ref:`stage plugins <transpiler-preset-stage-plugins>`, the entry point for
713
+ ``optimization`` is ``qiskit.transpiler.optimization``. The built-in plugins are:
714
+
715
+ .. list-table::
716
+ :header-rows: 1
717
+
718
+ * - Method
719
+ - Summary
720
+
721
+ * - :ref:`default <transpiler-preset-stage-optimization-default>`
722
+ - A default set of optimization passes. This varies significantly between optimization
723
+ levels.
724
+
725
+ .. _transpiler-preset-stage-optimization-default:
726
+
727
+ Built-in ``default`` plugin
728
+ ...........................
729
+
730
+ This varies significantly depending on the optimization level and whether the basis set is of the
731
+ form Clifford+T.
732
+
733
+ The specifics of this pipeline are subject to change between Qiskit versions. The broad principles
734
+ are described below. First, consider the more common case that the basis set is not of the form
735
+ Clifford+T.
736
+
737
+ At optimization level 0, the stage is empty.
738
+
739
+ At optimization level 1, the stage does matrix-based resynthesis of runs of single-qubit gates, and
740
+ very simple symbolic inverse cancellation of two-qubit gates, if they appear consecutively. This
741
+ runs in a loop until the size and depth of the circuit are fixed.
742
+
743
+ At optimization level 2, in addition the optimizations of level 1, the loop contains commutation
744
+ analysis of sets of gates to widen the range of gates that can be considered for cancellation.
745
+ Before the loop, runs of both one- and two-qubit gates undergo a single matrix-based resynthesis.
746
+
747
+ At optimization level 3, the two-qubit matrix-based resynthesis runs inside the optimization loop.
748
+ The optimization loop condition also tries multiple runs and chooses the minimum point in the case
749
+ of fluctuating output; this is necessary because matrix-based resynthesis is relatively unstable in
750
+ terms of concrete gates.
751
+
752
+ For a Clifford+T basis set, two-qubit matrix based resynthesis is not applied.
753
+
754
+ Optimization level 3 is typically very expensive for large circuits.
755
+
756
+
757
+ .. _transpiler-preset-stage-scheduling:
758
+
759
+ Scheduling stage
760
+ ----------------
761
+
762
+ .. seealso::
763
+ :ref:`transpiler-scheduling-description`
764
+ A guide-level explanation of scheduling concepts.
765
+
766
+ The scheduling stage, if requested, is responsible for inserting explicit :class:`~.circuit.Delay`
767
+ instructions to make idle periods of qubits explicit. Plugins may optionally choose to do
768
+ walltime-sensitive transformations, such as inserting dynamical decoupling sequences.
769
+
770
+ The input to the scheduling stage is an ISA-compatible circuit. The output of the scheduling stage
771
+ must also be an ISA-compatible circuit, with explicit :class:`~.circuit.Delay` instructions that
772
+ satisfy the hardware's timing information, if appropriate.
773
+
774
+ The scheduling stage should set the ``node_start_time`` property in the pipeline's
775
+ :class:`.PropertySet`.
776
+
777
+ When writing :ref:`stage plugins <transpiler-preset-stage-plugins>`, the entry point for
778
+ ``scheduling`` is ``qiskit.transpiler.scheduling``. The built-in plugins are:
779
+
780
+ .. list-table::
781
+ :header-rows: 1
782
+
783
+ * - Method
784
+ - Summary
785
+
786
+ * - :ref:`default <transpiler-preset-stage-scheduling-default>`
787
+ - Attempt to satisfy timing alignment constraints without otherwise scheduling.
788
+
789
+ * - :ref:`alap <transpiler-preset-stage-scheduling-alap>`
790
+ - Schedule the circuit, preferring operations to be as late as possible.
791
+
792
+ * - :ref:`asap <transpiler-preset-stage-scheduling-asap>`
793
+ - Schedule the circuit, preferring operations to be as soon as possible.
794
+
795
+ .. _transpiler-preset-stage-scheduling-default:
796
+
797
+ Built-in ``default`` plugin
798
+ ...........................
799
+
800
+ Do nothing, unless the circuit already contains instructions with explicit timings. If there are
801
+ explicitly timed operations in the circuit, insert additional padding to ensure that these timings
802
+ satisfy the alignment and other hardware constraints.
803
+
804
+ .. _transpiler-preset-stage-scheduling-alap:
805
+
806
+ Builtin ``alap`` plugin
807
+ .......................
808
+
809
+ Explicitly schedule all operations using an "as late as possible" strategy. This uses the
810
+ :class:`.ALAPScheduleAnalysis` algorithm to decide where to place gates.
811
+
812
+ .. _transpiler-preset-stage-scheduling-asap:
813
+
814
+ Builtin ``asap`` plugin
815
+ .......................
816
+
817
+ Explicitly schedule all operations using an "as soon as possible" strategy. This uses the
818
+ :class:`.ASAPScheduleAnalysis` algorithm to decide where to place gates.
819
+
820
+
821
+ Custom pass managers
822
+ ====================
823
+
824
+ In addition to modifying preset pass managers, it is also possible to construct a pass
825
+ manager to build an entirely custom pipeline for transforming input
826
+ circuits. You can use the :class:`~.StagedPassManager` class directly to do
827
+ this. You can define arbitrary stage names and populate them with a :class:`~.PassManager`
828
+ instance. For example, the following code creates a new :class:`~.StagedPassManager`
829
+ that has two stages, ``init`` and ``translation``.
830
+
831
+ .. plot::
832
+ :include-source:
833
+ :nofigs:
834
+
835
+ from qiskit.transpiler.passes import (
836
+ UnitarySynthesis,
837
+ Collect2qBlocks,
838
+ ConsolidateBlocks,
839
+ UnitarySynthesis,
840
+ Unroll3qOrMore,
841
+ )
842
+ from qiskit.transpiler import PassManager, StagedPassManager
843
+
844
+ basis_gates = ["rx", "ry", "rxx"]
845
+ init = PassManager([UnitarySynthesis(basis_gates, min_qubits=3), Unroll3qOrMore()])
846
+ translate = PassManager(
847
+ [
848
+ Collect2qBlocks(),
849
+ ConsolidateBlocks(basis_gates=basis_gates),
850
+ UnitarySynthesis(basis_gates),
851
+ ]
852
+ )
853
+
854
+ staged_pm = StagedPassManager(
855
+ stages=["init", "translation"], init=init, translation=translate
856
+ )
857
+
858
+ There is no limit on the number of stages you can put in a :class:`~.StagedPassManager`. The stages
859
+ do not need to correspond to the stages used by Qiskit's preset pipelines.
860
+
861
+ The :ref:`stage_generators` may be useful for the construction of custom :class:`~.StagedPassManager`
862
+ instances. They generate pass managers which provide common functionality used in many stages. For
863
+ example, :func:`~.generate_embed_passmanager` generates a :class:`~.PassManager` to "embed" a
864
+ selected initial :class:`~.Layout` from a layout pass to the specified target device.
865
+
866
+ Representing Quantum Computers
867
+ ==============================
868
+
869
+ To be able to compile a :class:`~.QuantumCircuit` for a specific backend, the transpiler needs a
870
+ specialized representation of that backend, including its constraints, instruction set, qubit
871
+ properties, and more, to be able to compile and optimize effectively. While the
872
+ :class:`~.BackendV2` class defines an interface for querying and interacting
873
+ with backends, its scope is larger than just the transpiler's needs including
874
+ managing job submission and potentially interfacing with remote services.
875
+ The specific information needed by the transpiler is described by the
876
+ :class:`~.Target` class
877
+
878
+ For example, to construct a simple :class:`~.Target` object, one can iteratively add
879
+ descriptions of the instructions it supports:
880
+
881
+ .. plot::
882
+ :include-source:
883
+ :nofigs:
884
+
885
+ from qiskit.circuit import Parameter, Measure
886
+ from qiskit.transpiler import Target, InstructionProperties
887
+ from qiskit.circuit.library import UGate, RZGate, RXGate, RYGate, CXGate, CZGate
888
+
889
+ target = Target(num_qubits=3)
890
+ target.add_instruction(CXGate(), {(0, 1): InstructionProperties(error=.0001, duration=5e-7)})
891
+ target.add_instruction(
892
+ UGate(Parameter('theta'), Parameter('phi'), Parameter('lam')),
893
+ {
894
+ (0,): InstructionProperties(error=.00001, duration=5e-8),
895
+ (1,): InstructionProperties(error=.00002, duration=6e-8)
896
+ }
897
+ )
898
+ target.add_instruction(
899
+ RZGate(Parameter('theta')),
900
+ {
901
+ (1,): InstructionProperties(error=.00001, duration=5e-8),
902
+ (2,): InstructionProperties(error=.00002, duration=6e-8)
903
+ }
904
+ )
905
+ target.add_instruction(
906
+ RYGate(Parameter('theta')),
907
+ {
908
+ (1,): InstructionProperties(error=.00001, duration=5e-8),
909
+ (2,): InstructionProperties(error=.00002, duration=6e-8)
910
+ }
911
+ )
912
+ target.add_instruction(
913
+ RXGate(Parameter('theta')),
914
+ {
915
+ (1,): InstructionProperties(error=.00001, duration=5e-8),
916
+ (2,): InstructionProperties(error=.00002, duration=6e-8)
917
+ }
918
+ )
919
+ target.add_instruction(
920
+ CZGate(),
921
+ {
922
+ (1, 2): InstructionProperties(error=.0001, duration=5e-7),
923
+ (2, 0): InstructionProperties(error=.0001, duration=5e-7)
924
+ }
925
+ )
926
+ target.add_instruction(
927
+ Measure(),
928
+ {
929
+ (0,): InstructionProperties(error=.001, duration=5e-5),
930
+ (1,): InstructionProperties(error=.002, duration=6e-5),
931
+ (2,): InstructionProperties(error=.2, duration=5e-7)
932
+ }
933
+ )
934
+ print(target)
935
+
936
+ .. code-block:: text
937
+
938
+ Target
939
+ Number of qubits: 3
940
+ Instructions:
941
+ cx
942
+ (0, 1):
943
+ Duration: 5e-07 sec.
944
+ Error Rate: 0.0001
945
+ u
946
+ (0,):
947
+ Duration: 5e-08 sec.
948
+ Error Rate: 1e-05
949
+ (1,):
950
+ Duration: 6e-08 sec.
951
+ Error Rate: 2e-05
952
+ rz
953
+ (1,):
954
+ Duration: 5e-08 sec.
955
+ Error Rate: 1e-05
956
+ (2,):
957
+ Duration: 6e-08 sec.
958
+ Error Rate: 2e-05
959
+ ry
960
+ (1,):
961
+ Duration: 5e-08 sec.
962
+ Error Rate: 1e-05
963
+ (2,):
964
+ Duration: 6e-08 sec.
965
+ Error Rate: 2e-05
966
+ rx
967
+ (1,):
968
+ Duration: 5e-08 sec.
969
+ Error Rate: 1e-05
970
+ (2,):
971
+ Duration: 6e-08 sec.
972
+ Error Rate: 2e-05
973
+ cz
974
+ (1, 2):
975
+ Duration: 5e-07 sec.
976
+ Error Rate: 0.0001
977
+ (2, 0):
978
+ Duration: 5e-07 sec.
979
+ Error Rate: 0.0001
980
+ measure
981
+ (0,):
982
+ Duration: 5e-05 sec.
983
+ Error Rate: 0.001
984
+ (1,):
985
+ Duration: 6e-05 sec.
986
+ Error Rate: 0.002
987
+ (2,):
988
+ Duration: 5e-07 sec.
989
+ Error Rate: 0.2
990
+
991
+ This :class:`~.Target` represents a 3 qubit backend that supports :class:`~.CXGate` between qubits
992
+ 0 and 1, :class:`~.UGate` on qubits 0 and 1, :class:`~.RZGate`, :class:`~.RXGate`,
993
+ and :class:`~.RYGate` on qubits 1 and 2, :class:`~.CZGate` between qubits 1 and 2, and qubits
994
+ 2 and 0, and :class:`~.Measure` on all qubits.
995
+
996
+ There are also specific data structures to represent a specific subset of information from the
997
+ :class:`~.Target`. For example, the :class:`~.CouplingMap` class is used to solely represent the
998
+ connectivity constraints of a backend as a directed graph. A coupling map can be generated from
999
+ a :class:`~.Target` using the :meth:`.Target.build_coupling_map` method. These data structures
1000
+ typically pre-date the :class:`~.Target` class but are still used by some transpiler passes that do
1001
+ not work natively with a :class:`~.Target` instance yet or when dealing with backends that aren't
1002
+ using the latest :class:`~.BackendV2` interface.
1003
+
1004
+ For example, if we wanted to visualize the :class:`~.CouplingMap` for the
1005
+ example 3 qubit :class:`~.Target` above:
1006
+
1007
+ .. plot::
1008
+ :include-source:
1009
+ :alt: Output from the previous code.
1010
+
1011
+ from qiskit.circuit import Parameter, Measure
1012
+ from qiskit.transpiler import Target, InstructionProperties
1013
+ from qiskit.circuit.library import UGate, RZGate, RXGate, RYGate, CXGate, CZGate
1014
+
1015
+ target = Target(num_qubits=3)
1016
+ target.add_instruction(CXGate(), {(0, 1): InstructionProperties(error=.0001, duration=5e-7)})
1017
+ target.add_instruction(
1018
+ UGate(Parameter('theta'), Parameter('phi'), Parameter('lam')),
1019
+ {
1020
+ (0,): InstructionProperties(error=.00001, duration=5e-8),
1021
+ (1,): InstructionProperties(error=.00002, duration=6e-8)
1022
+ }
1023
+ )
1024
+ target.add_instruction(
1025
+ RZGate(Parameter('theta')),
1026
+ {
1027
+ (1,): InstructionProperties(error=.00001, duration=5e-8),
1028
+ (2,): InstructionProperties(error=.00002, duration=6e-8)
1029
+ }
1030
+ )
1031
+ target.add_instruction(
1032
+ RYGate(Parameter('theta')),
1033
+ {
1034
+ (1,): InstructionProperties(error=.00001, duration=5e-8),
1035
+ (2,): InstructionProperties(error=.00002, duration=6e-8)
1036
+ }
1037
+ )
1038
+ target.add_instruction(
1039
+ RXGate(Parameter('theta')),
1040
+ {
1041
+ (1,): InstructionProperties(error=.00001, duration=5e-8),
1042
+ (2,): InstructionProperties(error=.00002, duration=6e-8)
1043
+ }
1044
+ )
1045
+ target.add_instruction(
1046
+ CZGate(),
1047
+ {
1048
+ (1, 2): InstructionProperties(error=.0001, duration=5e-7),
1049
+ (2, 0): InstructionProperties(error=.0001, duration=5e-7)
1050
+ }
1051
+ )
1052
+ target.add_instruction(
1053
+ Measure(),
1054
+ {
1055
+ (0,): InstructionProperties(error=.001, duration=5e-5),
1056
+ (1,): InstructionProperties(error=.002, duration=6e-5),
1057
+ (2,): InstructionProperties(error=.2, duration=5e-7)
1058
+ }
1059
+ )
1060
+
1061
+ target.build_coupling_map().draw()
1062
+
1063
+ This shows the global connectivity of the :class:`~.Target` which is the
1064
+ combination of the supported qubits for :class:`~.CXGate` and :class:`~.CZGate`. To
1065
+ see the individual connectivity, you can pass the operation name to
1066
+ :meth:`.CouplingMap.build_coupling_map`:
1067
+
1068
+ .. plot::
1069
+ :alt: Output from the previous code.
1070
+ :include-source:
1071
+
1072
+ from qiskit.circuit import Parameter, Measure
1073
+ from qiskit.transpiler import Target, InstructionProperties
1074
+ from qiskit.circuit.library import UGate, RZGate, RXGate, RYGate, CXGate, CZGate
1075
+
1076
+ target = Target(num_qubits=3)
1077
+ target.add_instruction(CXGate(), {(0, 1): InstructionProperties(error=.0001, duration=5e-7)})
1078
+ target.add_instruction(
1079
+ UGate(Parameter('theta'), Parameter('phi'), Parameter('lam')),
1080
+ {
1081
+ (0,): InstructionProperties(error=.00001, duration=5e-8),
1082
+ (1,): InstructionProperties(error=.00002, duration=6e-8)
1083
+ }
1084
+ )
1085
+ target.add_instruction(
1086
+ RZGate(Parameter('theta')),
1087
+ {
1088
+ (1,): InstructionProperties(error=.00001, duration=5e-8),
1089
+ (2,): InstructionProperties(error=.00002, duration=6e-8)
1090
+ }
1091
+ )
1092
+ target.add_instruction(
1093
+ RYGate(Parameter('theta')),
1094
+ {
1095
+ (1,): InstructionProperties(error=.00001, duration=5e-8),
1096
+ (2,): InstructionProperties(error=.00002, duration=6e-8)
1097
+ }
1098
+ )
1099
+ target.add_instruction(
1100
+ RXGate(Parameter('theta')),
1101
+ {
1102
+ (1,): InstructionProperties(error=.00001, duration=5e-8),
1103
+ (2,): InstructionProperties(error=.00002, duration=6e-8)
1104
+ }
1105
+ )
1106
+ target.add_instruction(
1107
+ CZGate(),
1108
+ {
1109
+ (1, 2): InstructionProperties(error=.0001, duration=5e-7),
1110
+ (2, 0): InstructionProperties(error=.0001, duration=5e-7)
1111
+ }
1112
+ )
1113
+ target.add_instruction(
1114
+ Measure(),
1115
+ {
1116
+ (0,): InstructionProperties(error=.001, duration=5e-5),
1117
+ (1,): InstructionProperties(error=.002, duration=6e-5),
1118
+ (2,): InstructionProperties(error=.2, duration=5e-7)
1119
+ }
1120
+ )
1121
+
1122
+ target.build_coupling_map('cx').draw()
1123
+
1124
+ .. plot::
1125
+ :alt: Output from the previous code.
1126
+ :include-source:
1127
+
1128
+ from qiskit.circuit import Parameter, Measure
1129
+ from qiskit.transpiler import Target, InstructionProperties
1130
+ from qiskit.circuit.library import UGate, RZGate, RXGate, RYGate, CXGate, CZGate
1131
+
1132
+ target = Target(num_qubits=3)
1133
+ target.add_instruction(CXGate(), {(0, 1): InstructionProperties(error=.0001, duration=5e-7)})
1134
+ target.add_instruction(
1135
+ UGate(Parameter('theta'), Parameter('phi'), Parameter('lam')),
1136
+ {
1137
+ (0,): InstructionProperties(error=.00001, duration=5e-8),
1138
+ (1,): InstructionProperties(error=.00002, duration=6e-8)
1139
+ }
1140
+ )
1141
+ target.add_instruction(
1142
+ RZGate(Parameter('theta')),
1143
+ {
1144
+ (1,): InstructionProperties(error=.00001, duration=5e-8),
1145
+ (2,): InstructionProperties(error=.00002, duration=6e-8)
1146
+ }
1147
+ )
1148
+ target.add_instruction(
1149
+ RYGate(Parameter('theta')),
1150
+ {
1151
+ (1,): InstructionProperties(error=.00001, duration=5e-8),
1152
+ (2,): InstructionProperties(error=.00002, duration=6e-8)
1153
+ }
1154
+ )
1155
+ target.add_instruction(
1156
+ RXGate(Parameter('theta')),
1157
+ {
1158
+ (1,): InstructionProperties(error=.00001, duration=5e-8),
1159
+ (2,): InstructionProperties(error=.00002, duration=6e-8)
1160
+ }
1161
+ )
1162
+ target.add_instruction(
1163
+ CZGate(),
1164
+ {
1165
+ (1, 2): InstructionProperties(error=.0001, duration=5e-7),
1166
+ (2, 0): InstructionProperties(error=.0001, duration=5e-7)
1167
+ }
1168
+ )
1169
+ target.add_instruction(
1170
+ Measure(),
1171
+ {
1172
+ (0,): InstructionProperties(error=.001, duration=5e-5),
1173
+ (1,): InstructionProperties(error=.002, duration=6e-5),
1174
+ (2,): InstructionProperties(error=.2, duration=5e-7)
1175
+ }
1176
+ )
1177
+
1178
+ target.build_coupling_map('cz').draw()
1179
+
1180
+
1181
+ .. _transpiler-scheduling-description:
1182
+
1183
+ Scheduling of circuits
1184
+ ======================
1185
+
1186
+ ..
1187
+ This section is still here because the content hasn't fully migrated to other places yet, unlike
1188
+ other discussions of the components of quantum compilation.
1189
+
1190
+ .. seealso::
1191
+ :ref:`transpiler-preset-stage-scheduling`
1192
+ How to configure the scheduling stages of the preset pass managers.
1193
+
1194
+ After the circuit has been translated to the target basis, mapped to the device, and optimized,
1195
+ a scheduling phase can be applied to optionally account for all the idle time in the circuit.
1196
+ At a high level, the scheduling can be thought of as inserting delays into the circuit to account
1197
+ for idle time on the qubits between the execution of instructions. For example, if we start with a
1198
+ circuit such as:
1199
+
1200
+ .. plot::
1201
+ :alt: Diagram illustrating the previously described circuit.
1202
+
1203
+ from qiskit import QuantumCircuit
1204
+
1205
+ ghz = QuantumCircuit(5)
1206
+ ghz.h(0)
1207
+ ghz.cx(0,range(1,5))
1208
+ ghz.draw(output='mpl')
1209
+
1210
+ we can then call :func:`~.transpile` on it with ``scheduling_method`` set:
1211
+
1212
+ .. plot::
1213
+ :alt: Circuit diagram output by the previous code.
1214
+ :include-source:
1215
+
1216
+ from qiskit import QuantumCircuit, transpile
1217
+ from qiskit.providers.fake_provider import GenericBackendV2
1218
+
1219
+ backend = GenericBackendV2(5)
1220
+
1221
+ ghz = QuantumCircuit(5)
1222
+ ghz.h(0)
1223
+ ghz.cx(0,range(1,5))
1224
+
1225
+ circ = transpile(ghz, backend, scheduling_method="asap")
1226
+ circ.draw(output='mpl')
1227
+
1228
+ You can see here that the transpiler inserted :class:`~qiskit.circuit.Delay` instructions to
1229
+ account for idle time on each qubit. To get a better idea of the timing of the circuit we can
1230
+ also look at it with the :func:`.timeline.draw` function:
1231
+
1232
+ .. plot::
1233
+ :alt: Output from circuit timeline drawer.
1234
+
1235
+ from qiskit.visualization.timeline import draw as timeline_draw
1236
+
1237
+ from qiskit import QuantumCircuit, transpile
1238
+ from qiskit.providers.fake_provider import GenericBackendV2
1239
+
1240
+ backend = GenericBackendV2(5)
1241
+
1242
+ ghz = QuantumCircuit(5)
1243
+ ghz.h(0)
1244
+ ghz.cx(0,range(1,5))
1245
+
1246
+ circ = transpile(ghz, backend, scheduling_method="asap")
1247
+
1248
+ timeline_draw(circ, target=backend.target)
1249
+
1250
+ The scheduling of a circuit involves two parts: analysis and constraint mapping, followed by a
1251
+ padding pass. The first part requires running a scheduling analysis pass such as
1252
+ :class:`~.ALAPSchedulingAnalysis` or :class:`~.ASAPSchedulingAnalysis` which analyzes the circuit
1253
+ and records the start time of each instruction in the circuit using a scheduling algorithm ("as late
1254
+ as possible" for :class:`~.ALAPSchedulingAnalysis` and "as soon as possible" for
1255
+ :class:`~.ASAPSchedulingAnalysis`) in the property set. Once the circuit has an initial scheduling,
1256
+ additional passes can be run to account for any timing constraints on the target backend, such
1257
+ as alignment constraints. This is typically done with the
1258
+ :class:`~.ConstrainedReschedule` pass which will adjust the scheduling
1259
+ set in the property set to the constraints of the target backend. Once all
1260
+ the scheduling and adjustments/rescheduling are finished, a padding pass,
1261
+ such as :class:`~.PadDelay` or :class:`~.PadDynamicalDecoupling` is run
1262
+ to insert the instructions into the circuit, which completes the scheduling.
1263
+
1264
+ Transpiler API
1265
+ ==============
1266
+
1267
+ Hardware description
1268
+ --------------------
1269
+
1270
+ .. autosummary::
1271
+ :toctree: ../stubs/
1272
+
1273
+ Target
1274
+ InstructionProperties
1275
+
1276
+ Pass Manager Definition
1277
+ -----------------------
1278
+
1279
+ .. autosummary::
1280
+ :toctree: ../stubs/
1281
+
1282
+ StagedPassManager
1283
+ PassManager
1284
+ PassManagerConfig
1285
+ generate_preset_pass_manager
1286
+
1287
+ Layout and Topology
1288
+ -------------------
1289
+
1290
+ .. autosummary::
1291
+ :toctree: ../stubs/
1292
+
1293
+ Layout
1294
+ CouplingMap
1295
+ TranspileLayout
1296
+
1297
+ Scheduling
1298
+ ----------
1299
+
1300
+ .. autosummary::
1301
+ :toctree: ../stubs/
1302
+
1303
+ InstructionDurations
1304
+
1305
+ Abstract Passes
1306
+ ---------------
1307
+
1308
+ .. autosummary::
1309
+ :toctree: ../stubs/
1310
+
1311
+ TransformationPass
1312
+ AnalysisPass
1313
+
1314
+ Exceptions
1315
+ ----------
1316
+
1317
+ .. autoexception:: TranspilerError
1318
+ .. autoexception:: TranspilerAccessError
1319
+ .. autoexception:: CouplingError
1320
+ .. autoexception:: LayoutError
1321
+ .. autoexception:: CircuitTooWideForTarget
1322
+ .. autoexception:: InvalidLayoutError
1323
+
1324
+ .. _sabre-original-paper: https://arxiv.org/abs/1809.02573
1325
+ .. _sabre-lightsabre-paper: https://arxiv.org/abs/2409.08368
1326
+ """
1327
+
1328
+ # For backward compatibility
1329
+ from qiskit.passmanager import (
1330
+ ConditionalController,
1331
+ DoWhileController,
1332
+ )
1333
+ from qiskit.passmanager.compilation_status import PropertySet
1334
+
1335
+ from .passmanager import PassManager, StagedPassManager
1336
+ from .passmanager_config import PassManagerConfig
1337
+ from .exceptions import (
1338
+ TranspilerError,
1339
+ TranspilerAccessError,
1340
+ CouplingError,
1341
+ LayoutError,
1342
+ CircuitTooWideForTarget,
1343
+ InvalidLayoutError,
1344
+ )
1345
+ from .basepasses import AnalysisPass, TransformationPass
1346
+ from .coupling import CouplingMap
1347
+ from .layout import Layout, TranspileLayout
1348
+ from .instruction_durations import InstructionDurations
1349
+ from .preset_passmanagers import generate_preset_pass_manager
1350
+ from .target import Target
1351
+ from .target import InstructionProperties
1352
+ from .target import QubitProperties