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,1335 @@
1
+ # This code is part of Qiskit.
2
+ #
3
+ # (C) Copyright IBM 2017.
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
+ r"""
14
+ =============================================
15
+ Quantum circuit model (:mod:`qiskit.circuit`)
16
+ =============================================
17
+
18
+ .. currentmodule:: qiskit.circuit
19
+
20
+ The fundamental element of quantum computing is the *quantum circuit*. This is a computational
21
+ routine that can be run, one shot at a time, on a quantum processing unit (QPU). A circuit will act
22
+ on a predefined amount of quantum data (in Qiskit, we only directly support qubits) with unitary
23
+ operations (gates), measurements and resets. In addition, a quantum circuit can contain operations
24
+ on classical data, including real-time computations and control-flow constructs, which are executed
25
+ by the controllers of the QPU.
26
+
27
+ .. note::
28
+
29
+ You may wish to skip the introductory material and jump directly to:
30
+
31
+ * :ref:`the API overview of the whole circuit module <circuit-module-api>`
32
+ * :ref:`the detailed discussion about how circuits are represented <circuit-repr>`
33
+ * the core :class:`QuantumCircuit` class for how to build and query circuits
34
+ * :ref:`information on construction custom instructions <circuit-custom-gates>`
35
+ * :ref:`ways to work with circuit-level objects <circuit-working-with>`
36
+ * :ref:`discussion of Qiskit conventions for circuits, matrices and state labelling
37
+ <circuit-conventions>`
38
+
39
+ Circuits are at a low level of abstraction when building up quantum programs. They are the
40
+ construct that is used to build up to higher levels of abstraction, such as the :ref:`primitives of
41
+ quantum computation <qiskit-primitives>`, which accumulate data from many shots of quantum-circuit
42
+ execution, along with advanced error-mitigation techniques and measurement optimizations, into
43
+ well-typed classical data and error statistics.
44
+
45
+ In Qiskit, circuits can be defined in one of two regimes:
46
+
47
+ * an *abstract* circuit, which is defined in terms of *virtual qubits* and arbitrary high-level
48
+ operations, like encapsulated algorithms and user-defined gates.
49
+
50
+ * a *physical* circuit, which is defined in terms of the *hardware qubits* of one particular
51
+ backend, and contains only operations that this backend natively supports. You might also see
52
+ this concept referred to as an *ISA circuit*.
53
+
54
+ You convert from an abstract circuit to a physical circuit by using :ref:`Qiskit's transpilation
55
+ package <qiskit-transpiler>`, of which the top-level access point is :func:`.transpile`.
56
+
57
+ In Qiskit, a quantum circuit is represented by the :class:`QuantumCircuit` class. Below is an
58
+ example of a quantum circuit that makes a three-qubit Greenberger–Horne–Zeilinger (GHZ) state
59
+ defined as:
60
+
61
+ .. math::
62
+
63
+ |\psi\rangle = \left( |000\rangle + |111\rangle \right) / \sqrt{2}
64
+
65
+
66
+ .. plot::
67
+ :alt: Circuit diagram output by the previous code.
68
+ :include-source:
69
+
70
+ from qiskit import QuantumCircuit
71
+
72
+ # Create a circuit with a register of three qubits
73
+ circ = QuantumCircuit(3)
74
+ # H gate on qubit 0, putting this qubit in a superposition of |0> + |1>.
75
+ circ.h(0)
76
+ # A CX (CNOT) gate on control qubit 0 and target qubit 1 generating a Bell state.
77
+ circ.cx(0, 1)
78
+ # CX (CNOT) gate on control qubit 0 and target qubit 2 resulting in a GHZ state.
79
+ circ.cx(0, 2)
80
+ # Draw the circuit
81
+ circ.draw('mpl')
82
+
83
+
84
+ .. _circuit-definitions:
85
+
86
+ Circuit concepts and definitions
87
+ ================================
88
+
89
+ There is a lot of specialized terminology around quantum circuits. Much of this is common in
90
+ quantum-computing literature, while some is more specific to quantum software packages, and a small
91
+ amount specific to Qiskit. This is an alphabetical listing of some of the important concepts as a
92
+ quick reference, but does not go into detail of the foundational concepts. Consider using the `IBM
93
+ Quantum Learning platform <https://learning.quantum.ibm.com/>`_ if you want to start from the
94
+ beginning.
95
+
96
+ abstract circuit
97
+ A *circuit* defined in terms of abstract mathematical operations and *virtual qubits*. This is
98
+ typically how you think about quantum algorithms; an abstract circuit can be made up of
99
+ completely arbitrary unitary operations, measurements, and potentially *real-time classical
100
+ computation*, with no restrictions about which qubits can interact with each other.
101
+
102
+ You turn an abstract circuit into a *physical circuit* by using :ref:`Qiskit's transpilation
103
+ package <qiskit-transpiler>`.
104
+
105
+ ancilla qubit
106
+ An extra qubit that is used to help implement operations on other qubits, but whose final state
107
+ is not important for the program.
108
+
109
+ circuit
110
+ A computational routine the defines a single execution to be taken on a QPU. This can either be
111
+ an *abstract circuit* or a *physical circuit*.
112
+
113
+ clbit
114
+ A Qiskit-specific abbreviation meaning a single classical bit of data.
115
+
116
+ gate
117
+ A *unitary operation* on one or more qubits.
118
+
119
+ hardware qubit
120
+ The representation of a single qubit on a particular *QPU*. A hardware qubit has some physical
121
+ quantum-mechanical system backing it, such as superconducting circuits; unlike a *virtual
122
+ qubit*, it has particular coupling constraints and only certain gates can be applied to certain
123
+ groups of hardware qubits.
124
+
125
+ Qiskit does not distinguish *logical qubits* from any individual *physical qubits* when talking
126
+ about hardware qubits. A QPU may implement its hardware qubits as logical qubits, where each
127
+ hardware qubit comprises many physical qubits that are controlled and error-corrected opaquely
128
+ to Qiskit by the control electronics. More likely, for near-term applications, a QPU will be
129
+ directly exposing its physical qubits as the hardware qubits for Qiskit to reason about.
130
+
131
+ Both physical and logical qubits will have coupling constraints between them, only permit
132
+ certain quantum operations on them, and have scheduling concerns between them. Qiskit abstracts
133
+ these concerns together in the concept of hardware qubits. In the early days of quantum error
134
+ correction, particular backends may let you access their qubit resources either as high-level
135
+ logical qubits or as low-level physical qubits through Qiskit.
136
+
137
+ instruction set architecture (ISA)
138
+ The abstract model of which operations are available on which sets of *hardware qubits* on one
139
+ particular *QPU*. For example, one QPU may allow :math:`\sqrt X` and :math:`R_Z` operations on
140
+ all single hardware qubits, and :math:`CX` operations on certain pairs of hardware qubits.
141
+
142
+ logical qubit
143
+ A collection of several *physical qubits* that are controlled together by a QPU (from the user's
144
+ perspective) to apply real-time quantum error correction. A logical qubit is a type of
145
+ *hardware qubit* for Qiskit.
146
+
147
+ measurement
148
+ The act of extracting one classical bit of a data from a single qubit state. This is an
149
+ irreversible operation, and usually destroys entanglement and phase coherence between the target
150
+ qubit and the rest of the system.
151
+
152
+ physical circuit
153
+ A *circuit* defined in terms of *hardware qubits* and only the quantum operations available in a
154
+ particular *QPU's* *ISA*. Physical circuits are tied to one particular QPU architecture, and
155
+ will not run on other incompatible architectures. You may also hear this referred to as an *ISA
156
+ circuit*.
157
+
158
+ You typically get a physical circuit by using :ref:`Qiskit's transpilation routines
159
+ <qiskit-transpiler>` on an *abstract circuit* that you constructed.
160
+
161
+ physical qubit
162
+ A controllable two-level quantum system. This is literally one "physics" qubit, such as a
163
+ transmon or the electronic state of a trapped ion. A QPU may expose this directly as its
164
+ *hardware qubit*, or combine several physical qubits into a *logical qubit*.
165
+
166
+ quantum processing unit (QPU)
167
+ Analogous to a CPU in classical computing or a GPU in graphics processing, a QPU is the hardware
168
+ that runs quantum operations on quantum data. You can always expect a QPU that uses the
169
+ *circuit* model of computation to be able to perform some set of *gates*, and *measurement*
170
+ operations. Depending on the particular technology, they also may be able to run some real-time
171
+ classical computations as well, such as classical control flow and bitwise calculations on
172
+ classical data.
173
+
174
+ qubit
175
+ The basic unit of quantum information.
176
+
177
+ real-time classical computation
178
+ Any classical computation that can happen within the execution of a single shot of a *circuit*,
179
+ where the results of the classical computation can affect later execution of the circuit. The
180
+ amount of real-time classical computation available with particular *QPU*\ s will vary
181
+ significantly dependent on many factors, such as the controlling electronics and the qubit
182
+ technology in use. You should consult your hardware vendor's documentation for more information
183
+ on this.
184
+
185
+ unitary operation
186
+ A reversible operation on a quantum state. All quantum *gates* are unitary operations (by
187
+ definition).
188
+
189
+ virtual qubit
190
+ An abstract, mathematical *qubit* used to build an *abstract circuit*. Virtual qubits are how
191
+ one typically thinks about quantum algorithms at a high level; we assume that all quantum gates
192
+ are valid on all virtual qubits, and all virtual qubits are always connected to every other
193
+ virtual qubit.
194
+
195
+ When mapping to hardware, virtual qubits must be assigned to *hardware qubits*. This mapping
196
+ need not be one-to-one. Typically, one virtual qubit will need to be swapped from one hardware
197
+ qubit to another over the course of a circuit execution in order to satisfy coupling constraints
198
+ of the underlying QPU. It is not strictly necessary for all virtual qubits used in a circuit to
199
+ be mapped to a physical qubit at any given point in a *physical circuit*; it could be that a
200
+ virtual qubit is measured (collapsing its state) and then never used again, so a new virtual
201
+ qubit could take its place. Evaluating these conditions to map a virtual circuit to a physical
202
+ circuit is the job of :ref:`Qiskit's transpilation package <qiskit-transpiler>`.
203
+
204
+
205
+ .. _circuit-module-api:
206
+
207
+ API overview of qiskit.circuit
208
+ ==============================
209
+
210
+ All objects here are described in more detail, and in their greater context in the following
211
+ sections. This section provides an overview of the API elements documented here.
212
+
213
+ ..
214
+ TODO: actually write the "in-depth section on building circuits and cross-ref to it.
215
+
216
+ The principal class is :class:`.QuantumCircuit`, which has its own documentation page, including
217
+ an in-depth section on building circuits. Quantum data and the simplest classical data are
218
+ represented by "bits" and "registers":
219
+
220
+ * :class:`Bit`, an atom of data
221
+ * :class:`Qubit`
222
+ * :class:`Clbit`
223
+ * :class:`AncillaQubit`
224
+
225
+ * :class:`Register`, a collection of bits
226
+ * :class:`QuantumRegister`
227
+ * :class:`ClassicalRegister`
228
+ * :class:`AncillaRegister`
229
+
230
+ Within a circuit, each complete :class:`CircuitInstruction` is made up of an :class:`Operation`
231
+ (which might be an :class:`Instruction`, a :class:`Gate`, or some other subclass) and the qubit
232
+ and clbit operands. The core base classes here are:
233
+
234
+ * :class:`CircuitInstruction`, an operation and its operands
235
+ * :class:`InstructionSet`, a temporary handle to a slice of circuit data
236
+ * :class:`Operation`, any abstract mathematical object or hardware instruction
237
+ * :class:`AnnotatedOperation`, a subclass with applied abstract modifiers
238
+ * :class:`InverseModifier`
239
+ * :class:`ControlModifier`
240
+ * :class:`PowerModifier`
241
+
242
+ The most common concrete subclass of the minimal, abstract :class:`Operation` interface is the
243
+ :class:`Instruction`. While :class:`Operation` can include abstract mathematical objects,
244
+ an :class:`Instruction` is something that could conceivably run directly on hardware. This is in
245
+ turn subclassed by :class:`Gate` and :class:`ControlledGate` that further add unitarity and
246
+ controlled semantics on top:
247
+
248
+ * :class:`Instruction`, representing a hardware-based instruction
249
+ * :class:`Gate`, representing a hardware instruction that is unitary
250
+ * :class:`ControlledGate`, representing a gate with control structure.
251
+
252
+ Qiskit includes a large library of standard gates and circuits, which is documented in
253
+ :mod:`qiskit.circuit.library`. Many of these are declared as Python-object singletons. The
254
+ machinery for this is described in detail in :mod:`qiskit.circuit.singleton`, of which the main
255
+ classes are each a singleton form of the standard instruction–gate hierarchy:
256
+
257
+ * :class:`~singleton.SingletonInstruction`
258
+ * :class:`~singleton.SingletonGate`
259
+ * :class:`~singleton.SingletonControlledGate`
260
+
261
+ Some instructions are particularly special in that they affect the control flow or data flow of the
262
+ circuit. The top-level ones are:
263
+
264
+ * :class:`Barrier`, to mark parts of the circuit that should be optimized independently
265
+ * :class:`Delay`, to insert a real-time wait period
266
+ * :class:`Measure`, to measure a :class:`Qubit` into a :class:`Clbit`
267
+ * :class:`Reset`, to irreversibly reset a qubit to the :math:`\lvert0\rangle` state
268
+ * :class:`Store`, to write a real-time classical expression to a storage location
269
+ * :class:`ControlFlowOp`, which has specific subclasses:
270
+ * :class:`BreakLoopOp`, to break out of the nearest containing loop
271
+ * :class:`ContinueLoopOp`, to move immediately to the next iteration of the containing loop
272
+ * :class:`BoxOp`, a simple grouping of instructions
273
+ * :class:`ForLoopOp`, to loop over a fixed range of values
274
+ * :class:`IfElseOp`, to conditionally enter one of two subcircuits
275
+ * :class:`SwitchCaseOp`, to conditionally enter one of many subcircuits
276
+ * :class:`WhileLoopOp`, to repeat a subcircuit until a condition is falsified.
277
+
278
+ Certain instructions can be "annotated" with metadata, which is typically intended to be consumed by
279
+ a compiler pass either locally, or in later backend processing. Currently this is limited to
280
+ :class:`BoxOp`. These annotations are represented by custom subclasses of :class:`Annotation`, and
281
+ there is further discussion of the support infrastructure in :mod:`qiskit.circuit.annotation`.
282
+
283
+ :ref:`Circuits can include classical expressions that are evaluated in real time
284
+ <circuit-repr-real-time-classical>`, while the QPU is executing a single shot of the circuit. These
285
+ are primarily documented in the module documentation of :mod:`qiskit.circuit.classical`. You might
286
+ be particularly interested in the base classes (which are not exposed from the :mod:`qiskit.circuit`
287
+ root):
288
+
289
+ * :class:`~classical.expr.Var`, a typed classical storage location in a circuit
290
+ * :class:`~classical.expr.Expr`, a real-time-evaluated expression
291
+ * :class:`~classical.types.Type`, the classical type of an expression.
292
+
293
+ In addition to this real-time expression evaluation, which is limited by classical hardware
294
+ representations of data, Qiskit has the concept of "compile-time" parametrization, which is done in
295
+ abstract symbolic algebra. These are typically used to represent gate angles in high-level
296
+ algorithms that might want to perform numerical derivatives, but they are an older part of Qiskit
297
+ than the real-time evaluation, so are still used in some places to do general parametrization. The
298
+ main related classes are:
299
+
300
+ * :class:`Parameter`, the atom of compile-time expressions
301
+ * :class:`ParameterExpression`, a symbolic calculation on parameters
302
+ * :class:`ParameterVector`, a convenience collection of many :class:`Parameter`\ s
303
+ * :class:`ParameterVectorElement`, a subclass of :class:`Parameter` used by :class:`ParameterVector`
304
+
305
+ The :mod:`qiskit.circuit` module also exposes some calculation classes that work with circuits to
306
+ assist compilation workflows. These include:
307
+
308
+ * :class:`EquivalenceLibrary`, a database of decomposition relations between gates and circuits
309
+ * :data:`SessionEquivalenceLibrary`, a mutable instance of :class:`EquivalenceLibrary` which is used
310
+ by default by the compiler's :class:`.BasisTranslator`.
311
+
312
+ There are also utilities for generating random circuits:
313
+
314
+ * :func:`random.random_circuit`
315
+ * :func:`random.random_circuit_from_graph`
316
+ * :func:`random.random_clifford_circuit`
317
+
318
+ Finally, the circuit module has its own exception class, to indicate when things went wrong in
319
+ circuit-specific manners:
320
+
321
+ * :exc:`CircuitError`
322
+
323
+
324
+ .. _circuit-repr:
325
+
326
+ Representation of circuits in Qiskit
327
+ ====================================
328
+
329
+ The main user-facing class for representing circuits is :class:`QuantumCircuit`. This can be either
330
+ an abstract circuit or a physical circuit. There is much more information about the
331
+ :class:`QuantumCircuit` class itself and the multitude of available methods on it in its class
332
+ documentation.
333
+
334
+ Internally, a :class:`QuantumCircuit` contains the qubits, classical bits, compile-time parameters,
335
+ real-time variables, and other tracking information about the data it acts on and how it is
336
+ parametrized. It then contains a sequence of :class:`CircuitInstruction`\ s, which contain
337
+ the particular operation (gate, measurement, etc) and its operands (the qubits and classical bits).
338
+
339
+
340
+ Bits and registers
341
+ ------------------
342
+
343
+ Qubits and classical bits are represented by a shared base :class:`Bit` type, which is just intended
344
+ to be a "type tag"; the classes have no behavior other than being immutable objects:
345
+
346
+ .. autoclass:: Bit
347
+ .. autoclass:: Qubit
348
+ :show-inheritance:
349
+ :class-doc-from: class
350
+ .. autoclass:: Clbit
351
+ :show-inheritance:
352
+ :class-doc-from: class
353
+
354
+ Qubits and clbits are instantiated by users with no arguments, such as by ``Qubit()``. Bits compare
355
+ equal if they are the same Python object, or if they were both created by a register of the same
356
+ name and size, and they refer to the same index within that register. There is also a special type
357
+ tag for "ancilla" qubits, but this is little used in the current state
358
+ of Qiskit:
359
+
360
+ .. autoclass:: AncillaQubit
361
+ :show-inheritance:
362
+ :class-doc-from: class
363
+
364
+ A collection bits of the same type can be encapsulated in a register of the matching type. The base
365
+ functionality is in a base class that is not directly instantiated:
366
+
367
+ .. autoclass:: Register
368
+ :members:
369
+
370
+ Each of the defined bit subtypes has an associated register, which have the same constructor
371
+ signatures, methods and properties as the base class:
372
+
373
+ .. autoclass:: QuantumRegister
374
+ :show-inheritance:
375
+ :class-doc-from: class
376
+ .. autoclass:: ClassicalRegister
377
+ :show-inheritance:
378
+ :class-doc-from: class
379
+ .. autoclass:: AncillaRegister
380
+ :show-inheritance:
381
+ :class-doc-from: class
382
+
383
+ A common way to instantiate several bits at once is to create a register, such as by
384
+ ``QuantumRegister("my_qreg", 5)``. This has the advantage that you can give that collection of bits
385
+ a name, which will appear during circuit visualizations (:meth:`QuantumCircuit.draw`) and exports to
386
+ interchange languages (see :mod:`.qasm2` and :mod:`.qasm3`). You can also pass a name and a list of
387
+ pre-constructed bits, but this creates an "aliasing register", which are very poorly supported on
388
+ hardware.
389
+
390
+ Circuits track registers, but registers themselves impart almost no behavioral differences on
391
+ circuits. The only exception is that :class:`ClassicalRegister`\ s can be implicitly cast to
392
+ unsigned integers for use in conditional comparisons of :ref:`control flow operations
393
+ <circuit-control-flow-repr>`.
394
+
395
+ Classical registers and bits were the original way of representing classical data in Qiskit, and
396
+ remain the most supported currently. Longer term, the data model is moving towards a more complete
397
+ and strongly typed representation of a range of classical data (see
398
+ :ref:`circuit-repr-real-time-classical`), but you will still very commonly use classical bits in
399
+ current Qiskit.
400
+
401
+
402
+ Instruction contexts
403
+ --------------------
404
+
405
+ The scalar type of the :attr:`QuantumCircuit.data` sequence is the "instruction context" object,
406
+ :class:`CircuitInstruction`. This is essentially just a data class that contains a representation
407
+ of what is to be done (its :attr:`~CircuitInstruction.operation`), and the data it acts on (the
408
+ :attr:`~CircuitInstruction.qubits` and :attr:`~CircuitInstruction.clbits`).
409
+
410
+ .. autosummary::
411
+ :toctree: ../stubs/
412
+
413
+ CircuitInstruction
414
+
415
+ Programmatically, this class is actually implemented in Rust and is a constructed handle to internal
416
+ data within Rust space. Mutations to instances of this class will not be reflected in the circuit.
417
+ In general, you cannot mutate instruction contexts that are already in the circuit directly; the
418
+ :class:`QuantumCircuit` interface is designed for storing and building circuits, while the
419
+ :ref:`transpiler and its passes <qiskit-transpiler>`, and its intermediate :class:`.DAGCircuit`
420
+ representation, are where you should look for an interface to mutate circuits.
421
+
422
+ The :class:`QuantumCircuit` methods that add instructions to circuits (such as
423
+ :meth:`~QuantumCircuit.append`, and all the helper standard-gate methods) return an
424
+ :class:`InstructionSet`, which is a handle to several :class:`CircuitInstruction`\ s simultaneously.
425
+
426
+ .. autosummary::
427
+ :toctree: ../stubs/
428
+
429
+ InstructionSet
430
+
431
+ This :class:`InstructionSet` is now little used in Qiskit. It provides a very minimal set of
432
+ methods to perform post-append mutations on instructions (which *will* be propagated to the
433
+ circuit), but these are now discouraged and you should use the alternatives noted in those methods.
434
+
435
+
436
+ .. _circuit-operations-instructions:
437
+
438
+ Operations, instructions and gates
439
+ ----------------------------------
440
+
441
+ Within a :class:`CircuitInstruction`, the minimal interface that any operation must fulfill is
442
+ :class:`Operation`. This is a *very* high level view, and only usable for abstract circuits. The
443
+ main purpose of treating operations as :class:`Operation` is to allow arbitrary mathematical
444
+ objects (such as :class:`.quantum_info.Operator`) to be added to abstract circuits directly.
445
+
446
+ .. autosummary::
447
+ :toctree: ../stubs/
448
+
449
+ Operation
450
+
451
+ Most operations, including all operations on physical circuits, are instances of the more concretely
452
+ defined :class:`Instruction`. This represents any instruction that some QPU might be able to carry
453
+ out natively, such as :class:`Measure`. :class:`Instruction` need not be unitary (much as
454
+ :class:`Measure` isn't); an instruction is specifically unitary if it is a :class:`Gate`.
455
+
456
+ .. autosummary::
457
+ :toctree: ../stubs/
458
+
459
+ Instruction
460
+
461
+ :class:`Instruction`\ s can be near arbitrary, provided they only act on :class:`Qubit`\ s and
462
+ :class:`Clbit`\ s, and are parametrized by their :attr:`~Instruction.params`; they should not
463
+ attempt to "close over" outer circuit registers, or use hidden parameters inside themselves.
464
+ :class:`Instruction`\ s can be related to other circuits to provide a decompositions by using
465
+ their :attr:`Instruction.definition` attribute, which provides a local, one-off decomposition. This
466
+ can be in whatever basis set of operations is most convenient to you, as long as the definitions of
467
+ all contained gates have some topological order; that is, you cannot use a gate in a definition if
468
+ its own definition depends on the parent. If the :class:`Instruction` should be considered entirely
469
+ opaque to optimizers, its :attr:`~Instruction.definition` can be ``None``. See
470
+ :ref:`circuit-custom-gates` for more detail.
471
+
472
+ The :attr:`~Instruction.params` of an instruction can technically be arbitrary, but in general you
473
+ should attempt to stick to parametrizations in terms of real numbers, wherever possible. Qiskit
474
+ itself breaks this rule in many places, and you will find all sorts of unusual types in
475
+ :attr:`Instruction.params` fields, but these are an annoying source of bugs because they often imply
476
+ the need for type-aware special casing. If your instruction is parametrized in terms of angles, you
477
+ will be able to reliably use :ref:`compile-time parametrization in it
478
+ <circuit-compile-time-parameters>`, and it will integrate well with
479
+ :meth:`QuantumCircuit.assign_parameters`.
480
+
481
+ While :class:`Instruction` is not necessarily unitary, its subclass :class:`Gate` implies unitarity,
482
+ and adds :meth:`~Gate.to_matrix` and :meth:`~Gate.control` methods to all the methods inherited from
483
+ :class:`Instruction`.
484
+
485
+ .. autosummary::
486
+ :toctree: ../stubs/
487
+
488
+ Gate
489
+
490
+ :class:`Gate` inherits all the methods for :class:`Instruction` and all the same considerations
491
+ about its :attr:`~Instruction.params` and :attr:`~Instruction.definition` field, except of course
492
+ that :class:`Gate`\ s cannot act on any classical resources.
493
+
494
+ :class:`Gate` instances can (and should) have a base :attr:`~Instruction.definition`, but you can
495
+ also specify several different decompositions in different bases by using an
496
+ :class:`EquivalenceLibrary`.
497
+
498
+ Subclassing :class:`Gate`, Qiskit has a special :class:`ControlledGate` class as well. This class
499
+ is the base of many standard-library gates that are controlled (such as :class:`CXGate`), which is
500
+ where you are most likely to encounter it:
501
+
502
+ .. autosummary::
503
+ :toctree: ../stubs/
504
+
505
+ ControlledGate
506
+
507
+ Each of :class:`Instruction`, :class:`Gate` and :class:`ControlledGate` has a corresponding
508
+ singleton type, built using the machinery described in :mod:`qiskit.circuit.singleton`. The
509
+ module-level documentation contains full details, along with descriptions of
510
+ :class:`.SingletonInstruction`, :class:`.SingletonGate` and :class:`.SingletonControlledGate`. From
511
+ a user's perspective, little changes based on whether the base class is a singleton or not; the
512
+ intention always remains that you should call :meth:`~Instruction.to_mutable` first if you need to
513
+ get a safe-to-mutate owned copy of an instruction (you cannot assume that an arbitrary instruction
514
+ is mutable), and while direct :class:`type` inspection is discouraged, if you do need it, the
515
+ reliable way to find the "base" type of a potentially singleton instruction is to use
516
+ :attr:`~Instruction.base_class`.
517
+
518
+ :class:`ControlledGate` uses the same mechanisms as :ref:`subclassing gates <circuit-custom-gates>`
519
+ to define a fixed, lazy synthesis for itself. This is naturally not hardware-aware, and harder to
520
+ hook into the synthesis routines of the compiler, but works better as a concrete
521
+ :class:`Instruction` that could potentially be run natively on hardware. For cases where synthesis
522
+ and abstract optimization is more important, Qiskit offers a composable class called
523
+ :class:`AnnotatedOperation`, which tracks "gate modifiers" (of which :class:`ControlModifier` is
524
+ one) to apply to the inner :attr:`~AnnotatedOperation.base_op`.
525
+
526
+ .. autosummary::
527
+ :toctree: ../stubs/
528
+
529
+ AnnotatedOperation
530
+
531
+ The available modifiers for :class:`AnnotatedOperation` are:
532
+
533
+ .. autoclass:: InverseModifier
534
+ .. autoclass:: ControlModifier
535
+ .. autoclass:: PowerModifier
536
+
537
+ For information on how to create custom gates and instructions, including how to build one-off
538
+ objects, and re-usable parametric gates via subclassing, see :ref:`circuit-custom-gates` below.
539
+ The Qiskit circuit library in :mod:`qiskit.circuit.library` contains many predefined gates and
540
+ circuits for you to use.
541
+
542
+
543
+ Built-in special instructions
544
+ -----------------------------
545
+
546
+ Qiskit contains a few :class:`Instruction` classes that are in some ways "special". These typically
547
+ have special handling in circuit code, in the transpiler, or the models of hardware. These are all
548
+ generally instructions you might already be familiar with.
549
+
550
+ Measurements in Qiskit are of a single :class:`Qubit` into a single :class:`Clbit`. These are the
551
+ two that the instruction is applied to. Measurements are in the computational basis.
552
+
553
+ .. autoclass:: Measure(label=None)
554
+ :show-inheritance:
555
+
556
+ Related to measurements, there is a :class:`Reset` operation, which produces no classical data but
557
+ instructs hardware to return the qubit to the :math:`\lvert0\rangle` state. This is assumed to
558
+ happen incoherently and to collapse any entanglement.
559
+
560
+ .. autoclass:: Reset(label=None)
561
+ :show-inheritance:
562
+
563
+ Hardware can be instructed to apply a real-time idle period on a given qubit. A scheduled circuit
564
+ (see :mod:`qiskit.transpiler`) will include all the idle times on qubits explicitly in terms of this
565
+ :class:`Delay`.
566
+
567
+ .. autoclass:: Delay
568
+ :show-inheritance:
569
+
570
+ The :class:`Barrier` instruction can span an arbitrary number of qubits and clbits, and is a no-op
571
+ in hardware. During transpilation and optimization, however, it blocks any optimizations from
572
+ "crossing" the barrier; that is, in:
573
+
574
+ .. plot::
575
+ :include-source:
576
+ :nofigs:
577
+
578
+ from qiskit.circuit import QuantumCircuit
579
+
580
+ qc = QuantumCircuit(1)
581
+ qc.x(0)
582
+ qc.barrier()
583
+ qc.x(0)
584
+
585
+ it is forbidden for the optimizer to cancel out the two :math:`X` instructions.
586
+
587
+ .. autoclass:: Barrier
588
+ :show-inheritance:
589
+
590
+ The :class:`Store` instruction is particularly special, in that it allows writing the result of a
591
+ :ref:`real-time classical computation expression <circuit-repr-real-time-classical>` (an
592
+ :class:`.expr.Expr`) in a local classical variable (a :class:`.expr.Var`). It takes *neither*
593
+ :class:`Qubit` nor :class:`Clbit` operands, but has an explicit :attr:`~Store.lvalue` and
594
+ :attr:`~Store.rvalue`.
595
+
596
+ For example, to determine the parity of a bitstring ``cr`` and store it in another register ``creg``,
597
+ the :class:`Store` instruction can be used in the following way::
598
+
599
+ parity = expr.lift(cr[0])
600
+ for i in range(1,n):
601
+ parity = expr.bit_xor(cr[i], parity)
602
+ qc.store(creg[0], parity)
603
+
604
+
605
+
606
+ .. autoclass:: Store
607
+ :show-inheritance:
608
+ :members:
609
+ :no-inherited-members:
610
+
611
+
612
+ .. _circuit-repr-real-time-classical:
613
+
614
+ Real-time classical computation
615
+ -------------------------------
616
+
617
+ .. seealso::
618
+ :mod:`qiskit.circuit.classical`
619
+ Module-level documentation for how the variable-, expression- and type-systems work, the
620
+ objects used to represent them, and the classical operations available.
621
+
622
+ :ref:`circuit-real-time-methods`
623
+ The :class:`QuantumCircuit` methods for working with these variables in the context of a
624
+ single circuit.
625
+
626
+ Qiskit has rudimentary low-level support for representing real-time classical computations, which
627
+ happen during the QPU execution and affect the results. We are still relatively early into hardware
628
+ support for these concepts as well, so beware that you will need to work closely with your hardware
629
+ provider's documentation to get the best use out of any real-time classical computation.
630
+
631
+ These real-time calculations are represented by the expression and type system in
632
+ :mod:`qiskit.circuit.classical`. At a high level, all real-time expressions are represented by an
633
+ :class:`.Expr` node, which is part of an expression "tree" representation, which has a well-defined
634
+ :class:`~.classical.Type` associated with it at every level. See the module-level documentation for
635
+ much more detail on the internal representations of these classes.
636
+
637
+ The result of a real-time :class:`.Expr` can be used directly in certain places. Currently this is
638
+ limited to conditions of :class:`.IfElseOp` and :class:`.WhileLoopOp`, and the target of
639
+ :class:`.SwitchCaseOp`. The result can also be stored in a typed classical storage location, using
640
+ the :class:`.Store` instruction (or its :meth:`QuantumCircuit.store` constructor), backed by a
641
+ :class:`.expr.Var` node.
642
+
643
+ A circuit can contain manual classical storage locations, represented internally by the
644
+ :class:`~.expr.Var` node of the :class:`.Expr` tree. These have an attached classical type (like
645
+ any other expression). These can either be declared and initialized within each execution of the
646
+ circuit (:meth:`~QuantumCircuit.add_var`), or be inputs to the circuit
647
+ (:meth:`~QuantumCircuit.add_input`).
648
+
649
+ .. _circuit-compile-time-parameters:
650
+
651
+ Compile-time parametrization
652
+ ----------------------------
653
+
654
+ Various parametric :class:`Instruction` instances in Qiskit can be parametrized in ways that are
655
+ designed to be resolved at compile time. These are characterized by the use of the
656
+ :class:`Parameter` and :class:`ParameterExpression` classes.
657
+
658
+ .. autosummary::
659
+ :toctree: ../stubs/
660
+
661
+ Parameter
662
+ ParameterExpression
663
+
664
+ The main way that this differs from the :class:`expr.Var` variables used in real-time classical
665
+ computation is that :class:`ParameterExpression` is a symbolic representation of a mathematical
666
+ expression. The semantics of the expression are those of regular mathematics over the continuous
667
+ real numbers (and, in limited cases, over the complex numbers). In contrast, :class:`.Var` is a
668
+ handle to a variable stored on a classical computer, such as a floating-point value or an
669
+ fixed-width integer, which are always discrete.
670
+
671
+ In other words, you can expect :class:`ParameterExpression` to do symbolic simplifications that are
672
+ valid in mathematics, such as simplifying :math:`(x + y - x) / y \to 1`. Such a simplification is
673
+ not valid in floating-point arithmetic, and :class:`.expr.Expr` will not do this.
674
+
675
+ The "compile-time" part of these parameters means that you typically will want to "assign" values to
676
+ the parameters before sending the circuit for execution. These parameters can typically be used
677
+ anywhere that expects a mathematical angle (like a rotation gate's parameters), with the caveat that
678
+ hardware will usually require them to be assigned to a proper classically typed value before
679
+ execution. You can do this assignment using :meth:`QuantumCircuit.assign_parameters`.
680
+
681
+ You may want to use many parameters that are related to each other. To make this easier (and to
682
+ avoid you needing to come up with many names), you can use the convenience constructor
683
+ :class:`ParameterVector`. The elements of the vector are all valid :class:`Parameter` instances, of
684
+ a special subclass :class:`ParameterVectorElement`.
685
+
686
+ .. autosummary::
687
+ :toctree: ../stubs/
688
+
689
+ ParameterVector
690
+ ParameterVectorElement
691
+
692
+ .. _circuit-control-flow-repr:
693
+
694
+ Control flow in circuits
695
+ ------------------------
696
+
697
+ Within :class:`QuantumCircuit`, classical control flow is represented by specific
698
+ :class:`Instruction`\ s, which are subclasses of :class:`ControlFlowOp`.
699
+
700
+ .. autosummary::
701
+ :toctree: ../stubs/
702
+
703
+ ControlFlowOp
704
+
705
+ For convenience, there is a :class:`frozenset` instance containing the :attr:`.Instruction.name`
706
+ attributes of each of the control-flow operations.
707
+
708
+ .. data:: CONTROL_FLOW_OP_NAMES
709
+
710
+ Set of the instruction names of Qiskit's known control-flow operations.
711
+
712
+ The :func:`.get_control_flow_name_mapping` function allows to access the control-flow operation
713
+ classes associated to each name.
714
+
715
+ .. autofunction:: get_control_flow_name_mapping
716
+
717
+ These control-flow operations (:class:`IfElseOp`, :class:`WhileLoopOp`,
718
+ :class:`SwitchCaseOp` and :class:`ForLoopOp`) all have specific state that defines the branching
719
+ conditions and strategies, but contain all the different subcircuit blocks that might be entered in
720
+ their :attr:`~ControlFlowOp.blocks` property.
721
+
722
+ .. autosummary::
723
+ :toctree: ../stubs/
724
+
725
+ IfElseOp
726
+ WhileLoopOp
727
+ SwitchCaseOp
728
+ ForLoopOp
729
+
730
+ The :class:`.SwitchCaseOp` also understands a special value:
731
+
732
+ .. autodata:: CASE_DEFAULT
733
+
734
+ In addition to the block-structure control-flow operations, there are also two special instructions
735
+ that affect the flow of control when within loops. These correspond to typical uses of the
736
+ ``break`` and ``continue`` statements in classical programming languages.
737
+
738
+ .. autosummary::
739
+ :toctree: ../stubs/
740
+
741
+ BreakLoopOp
742
+ ContinueLoopOp
743
+
744
+ .. note::
745
+ The classes representations are documented here, but please note that manually constructing
746
+ these classes is a low-level operation that we do not expect users to need to do frequently.
747
+
748
+ Users should read :ref:`circuit-control-flow-methods` for the recommended workflows for building
749
+ control-flow-enabled circuits.
750
+
751
+ Since :class:`ControlFlowOp` subclasses are also :class:`Instruction` subclasses, this means that
752
+ the way they are stored in :class:`CircuitInstruction` instances has them "applied" to a sequence of
753
+ qubits and clbits in its :attr:`~CircuitInstruction.qubits` and :attr:`~CircuitInstruction.clbits`
754
+ attributes. This can lead to subtle data-coherence problems: the :class:`Qubit` and :class:`Clbit`
755
+ objects used inside the subcircuit blocks of the control-flow ops will not necessarily be identical
756
+ to the corresponding objects in the :class:`CircuitInstruction`. Any code that consumes
757
+ control-flow operations in Qiskit needs to be aware of this; within a subcircuit, you should treat
758
+ ``subcircuit.qubits[i]`` as if it were really ``outer_instruction.qubits[i]``, and so on. You can
759
+ generate an easy lookup table for this by doing::
760
+
761
+ cf_instruction: CircuitInstruction = ...
762
+ cf_operation: ControlFlowOp = cf_instruction.operation
763
+ for block in blocks:
764
+ # Mappings of "inner" qubits/clbits to the outer ones.
765
+ qubit_map = dict(zip(block.qubits, cf_instruction.qubits))
766
+ clbit_map = dict(zip(block.clbits, cf_instruction.clbits))
767
+
768
+ # ... do something with `block` ...
769
+
770
+ Remember that you will need to propagate this information if you recurse into subblocks of
771
+ control-flow operations.
772
+
773
+ ..
774
+ TODO: insert cross-ref to control-flow builder guide into below paragraph once written.
775
+
776
+ All the subcircuit blocks in a :class:`ControlFlowOp` are required to contain the same numbers of
777
+ :class:`Qubit`\ s and :class:`Clbit`\ s, referring to the same outer bits in the same order, such
778
+ that the :class:`zip` loop given in the code block above works. The inner-circuit :class:`Bit`
779
+ objects do not need to be literally the same objects. When using the control-flow builder interface
780
+ (which, it cannot be stressed enough, is *highly* recommended for users), the builders will arrange
781
+ that the inner bit objects *are* identical to the outer bit objects; the ``qubit_map`` in the code
782
+ block above will always be a mapping ``{x: x}``, but if you are consuming the blocks, you should be
783
+ prepared for the case that the mapping is required.
784
+
785
+ Any :class:`ClassicalRegister`\ s used in a control-flow subcircuit must also be present in all
786
+ containing blocks (*i.e.* any containing control-flow operations, and the outermost circuit), and
787
+ all blocks in the same :class:`ControlFlowOp` need to contain the same registers. Again, the
788
+ builder interface will arrange for this to be the case (or produce an eager error if they cannot).
789
+
790
+ When the low-level construction is being used the inner :class:`QuantumCircuit` blocks must
791
+ manually close over any outer-scope :ref:`real-time classical computation variables
792
+ <circuit-repr-real-time-classical>` that they use. This is marked by these being in the
793
+ :meth:`~QuantumCircuit.iter_captured_vars` iterator for that block. Libraries constructing these
794
+ blocks manually will need to track these captures when building control-flow circuit blocks and add
795
+ them to the block using :meth:`~QuantumCircuit.add_capture` (or the ``captures`` constructor
796
+ argument), but user code will typically use the control-flow builder interface, which handles this
797
+ automatically.
798
+
799
+ Consult :ref:`the control-flow construction documentation <circuit-control-flow-methods>` for more
800
+ information on how to build circuits with control flow.
801
+
802
+ Investigating commutation relations
803
+ -----------------------------------
804
+
805
+ If two operations in a circuit commute, we can swap the order in which they are applied.
806
+ This can allow for optimizations and simplifications, for example, if it allows to merge
807
+ or cancel gates:
808
+
809
+ .. code-block:: text
810
+
811
+ ┌─────────┐ ┌─────────┐ ┌─────────┐
812
+ q_0: ┤ Rz(0.5) ├──■──┤ Rz(1.2) ├──■── q_0: ┤ Rz(1.7) ├
813
+ └─────────┘┌─┴─┐└──┬───┬──┘┌─┴─┐ = └──┬───┬──┘
814
+ q_1: ───────────┤ X ├───┤ X ├───┤ X ├ q_1: ───┤ X ├───
815
+ └───┘ └───┘ └───┘ └───┘
816
+
817
+ Performing these optimizations are part of the transpiler, but the tools to investigate commutations
818
+ are available in the :class:`CommutationChecker`.
819
+
820
+ .. autosummary::
821
+ :toctree: ../stubs/
822
+
823
+ CommutationChecker
824
+
825
+
826
+ .. _circuit-custom-gates:
827
+
828
+ Creating custom instructions
829
+ ============================
830
+
831
+ If you wish to create simple one-off instructions or gates that will be added to a circuit, and the
832
+ blocks are just being used for visualization or grouping purposes, the easiest way to create a
833
+ custom instruction or gate is simply to build its definition as a :class:`QuantumCircuit`, and then
834
+ use its :meth:`~QuantumCircuit.to_instruction` or :meth:`~QuantumCircuit.to_gate` method as
835
+ appropriate. The results can be given directly to :meth:`QuantumCircuit.append` on the larger
836
+ circuit. These methods will create base :class:`Instruction` or :class:`Gate` instances whose
837
+ :attr:`~Instruction.definition` attribute is the circuit as supplied, meaning it will automatically
838
+ be accessible to the transpiler, and to other Qiskit functions that attempt to decompose circuits.
839
+
840
+ Note that standalone instructions and gates should act only on qubits and clbits; instructions that
841
+ need to use complex control-flow will need to be inlined onto the :class:`QuantumCircuit` using
842
+ :meth:`~QuantumCircuit.compose`.
843
+
844
+
845
+ Creating instruction subclasses
846
+ -------------------------------
847
+
848
+ The base classes :class:`Instruction`, :class:`Gate` and :class:`ControlledGate` are all designed to
849
+ be safe to subclass, and have hook points for subclasses to implement. If your custom gate is
850
+ parameterless and stateless, you may also want to derive from the corresponding singleton class in
851
+ :mod:`qiskit.circuit.singleton`, such as :class:`SingletonGate`. You should consult the
852
+ documentation in :mod:`qiskit.circuit.singleton` for additional methods and hook points for the
853
+ singleton machinery.
854
+
855
+ Subclasses should typically define a default constructor that calls the :class`super` constructor
856
+ with the correct arguments for your instruction. It is permissible to have extra state in the
857
+ class, but your subclasses will most reliably integrate with the rest of the Qiskit machinery if you
858
+ depend only on your :attr:`Instruction.params`, and these parameters are purely gate angles.
859
+
860
+ Subclasses of :class:`Instruction` (or one of its subclasses) should implement the private
861
+ :meth:`Instruction._define` method, which lazily populates the hidden ``_definition`` cache that
862
+ backs the public :attr:`~Instruction.definition` method.
863
+
864
+ .. automethod:: Instruction._define
865
+
866
+ In subclasses of :class:`ControlledGate`, the :meth:`~Instruction._define` method should implement
867
+ the decomposition only for the all-ones control state. The :attr:`ControlledGate.definition
868
+ <Instruction.definition>` machinery will modify this to handle the actual control state.
869
+
870
+ If the subclass is using the singleton machinery, beware that :meth:`~Instruction._define` will be
871
+ called eagerly immediately after the class-body statement has been executed, in order to produce the
872
+ definition object for the canonical singleton object. This means that your definition must only use
873
+ gates that are already defined; if you are writing a library with many singleton gates, you will
874
+ have to order your files and imports to ensure that this is possible.
875
+
876
+ Subclasses of :class:`Gate` will also likely wish to override `the Numpy array-protocol instance
877
+ method <https://numpy.org/devdocs/user/basics.interoperability.html#the-array-method>`__,
878
+ ``__array__``. This is used by :meth:`Gate.to_matrix`, and has the signature:
879
+
880
+ .. currentmodule:: None
881
+ .. py:method:: object.__array__(dtype=None, copy=None)
882
+
883
+ Return a Numpy array representing the gate. This can use the gate's
884
+ :attr:`~qiskit.circuit.Instruction.params` field, and may assume that these are numeric
885
+ values (assuming the subclass expects that) and not
886
+ :ref:`compile-time parameters <circuit-compile-time-parameters>`.
887
+
888
+ For greatest efficiency, the returned array should default to a dtype of :class:`complex`.
889
+ .. currentmodule:: qiskit.circuit
890
+
891
+ If your custom subclass has natural representations of its controlled or inverse forms, you may also
892
+ wish to override the :meth:`~Instruction.inverse` and :meth:`~Gate.control` methods.
893
+
894
+
895
+ As an example of defining a custom :math:`R_{xz}` gate; that is, a single-angle rotation about the
896
+ :math:`XZ` axis. This is essentially :class:`RZXGate`, if the qubits were the other way around, so
897
+ we will write our definition in terms of that. We are parametric, so cannot be a singleton, but we
898
+ are unitary, so should be a :class:`Gate`::
899
+
900
+ import math
901
+ import numpy as np
902
+ from qiskit.circuit import Gate, QuantumCircuit
903
+
904
+ class RXZGate(Gate):
905
+ def __init__(self, theta):
906
+ # Initialize with our name, number of qubits and parameters.
907
+ super().__init__("rxz", 2, [theta])
908
+
909
+ def _define(self):
910
+ # Our base definition is an RZXGate, applied "backwards".
911
+ defn = QuantumCircuit(2)
912
+ defn.rzx(1, 0)
913
+ self._definition = defn
914
+
915
+ def inverse(self, annotated = False):
916
+ # We have an efficient representation of our inverse,
917
+ # so we'll override this method.
918
+ return RXZGate(-self.params[0])
919
+
920
+ def power(self, exponent: float):
921
+ # Also we have an efficient representation of power.
922
+ return RXZGate(exponent * self.params[0])
923
+
924
+ def __array__(self, dtype=None, copy=None):
925
+ if copy is False:
926
+ raise ValueError("unable to avoid copy while creating an array as requested")
927
+ cos = math.cos(0.5 * self.params[0])
928
+ isin = 1j * math.sin(0.5 * self.params[0])
929
+ return np.array([
930
+ [cos, -isin, 0, 0],
931
+ [-isin, cos, 0, 0],
932
+ [0, 0, cos, isin],
933
+ [0, 0, isin, cos],
934
+ ], dtype=dtype)
935
+
936
+
937
+ In this example, we defined a base definition in terms of :class:`RZXGate`, but to enable faster
938
+ decompositions to a range of bases, we might want to add some more equivalences to
939
+ :data:`SessionEquivalenceLibrary`. Note that the :class:`.BasisTranslator` translation search will
940
+ search through all possible equivalences at all possible depths, so providing an equivalence in
941
+ terms of (say) :class:`.XGate` will automatically make decompositions in terms of :class:`.RXGate`
942
+ available as well.
943
+
944
+ Let us add an equivalence in terms of :math:`H`, :math:`CX` and :math:`R_z` for an arbitrary symbolic
945
+ parameter::
946
+
947
+ from qiskit.circuit import SessionEquivalenceLibrary, Parameter
948
+
949
+ theta = Parameter("theta")
950
+
951
+ equiv = QuantumCircuit(2)
952
+ equiv.h(0)
953
+ equiv.cx(1, 0)
954
+ equiv.rz(theta, 0)
955
+ equiv.cx(1, 0)
956
+ equiv.h(0)
957
+
958
+ SessionEquivalenceLibrary.add_equivalence(RZXGate(theta), equiv)
959
+
960
+ After this, for the duration of the Python interpreter session, translators like
961
+ :class:`.BasisTranslator` will find our new definition in their search.
962
+
963
+
964
+ .. _circuit-working-with:
965
+
966
+ Working with circuit-level objects
967
+ ==================================
968
+
969
+ .. _circuit-abstract-to-physical:
970
+
971
+ Converting abstract circuits to physical circuits
972
+ -------------------------------------------------
973
+
974
+ ..
975
+ Note that this is just a "jumping-off" section - this should just provide an overview of links
976
+ to where the real information is.
977
+
978
+ An abstract :class:`QuantumCircuit` cannot reliably be run on hardware. You might be able to use
979
+ some of the high-level simulators linked to in :ref:`circuit-simulation` to produce quick results
980
+ for small scale circuits, but to run utility-scale circuits, you will need to use real hardware,
981
+ which involves compiling to a physical circuit.
982
+
983
+ The high-level function to do this is :func:`.transpile`; it takes in an abstract circuit and a
984
+ hardware ``backend`` or ``target``, and returns a physical circuit. To get more access and control
985
+ over the stages of the passes that will be run, use :func:`.generate_preset_pass_manager` to build a
986
+ :class:`~.transpiler.StagedPassManager` first, which you can then modify.
987
+
988
+ The full transpilation and compilation machinery is described in detail in the
989
+ :mod:`qiskit.transpiler` module documentation, and detail on all the passes built into Qiskit is
990
+ available in :mod:`qiskit.transpiler.passes`.
991
+
992
+
993
+ .. _circuit-simulation:
994
+
995
+ Simulating circuits
996
+ -------------------
997
+
998
+ ..
999
+ Note that this is just a "jumping-off" section - this should just provide an overview of links
1000
+ to where the real information is.
1001
+
1002
+
1003
+ While not part of the :mod:`qiskit.circuit` interface, one of the most common needs is to get quick
1004
+ simulation results for :class:`QuantumCircuit` objects. This section provides a quick jumping-off
1005
+ point to other places in the documentation to find the relevant information.
1006
+
1007
+ For unitary circuits, you can simulate the effects on the :math:`\lvert0\dotsm0\rangle` state by
1008
+ passing the :class:`QuantumCircuit` directly to the :class:`~.quantum_info.Statevector` default
1009
+ constructor. You can similar get a unitary matrix representing the circuit as an operator by
1010
+ passing it to the :class:`~.quantum_info.Operator` default constructor. If you have a physical
1011
+ circuit, you may want to instead pass it to :meth:`.Operator.from_circuit` method to apply
1012
+ transformations from the :attr:`QuantumCircuit.layout` to map it back to the "abstract" qubit space.
1013
+
1014
+ For a more backend-like simulation experience, there are simulator-backed implementations of all the
1015
+ Qiskit hardware interfaces. In particular, you might be interested in:
1016
+
1017
+ * :class:`.BasicProvider` and the raw backends it can return to you.
1018
+ * :class:`.StatevectorSimulator` for a backend-like wrapper around :class:`.Statevector`
1019
+ * The :mod:`qiskit_aer` for full, high-performance simulation capabilities.
1020
+ * :class:`.StatevectorSampler` and :class:`.StatevectorEstimator` for simulator-backed reference
1021
+ implementations of the :ref:`Qiskit Primitives <qiskit-primitives>`.
1022
+
1023
+
1024
+ Defining equivalence relationships
1025
+ ----------------------------------
1026
+
1027
+ A common task in mapping abstract circuits to physical hardware and optimizing the result is to find
1028
+ equivalence relations that map a gate to a different basis set. Qiskit stores this information in a
1029
+ database class called :class:`EquivalenceLibrary`.
1030
+
1031
+ .. autosummary::
1032
+ :toctree: ../stubs/
1033
+
1034
+ EquivalenceLibrary
1035
+
1036
+ Qiskit ships with a large set of predefined equivalence relationships for all of its standard gates.
1037
+ This base library is called :data:`StandardEquivalenceLibrary`, and should be treated as immutable.
1038
+
1039
+ .. py:data:: StandardEquivalenceLibrary
1040
+
1041
+ A :class:`EquivalenceLibrary` that stores of all Qiskit's built-in standard gate relationships.
1042
+ You should not mutate this, but instead either create your own :class:`EquivalenceLibrary` using
1043
+ this one as its ``base``, or modify the global-state :data:`SessionEquivalenceLibrary`.
1044
+
1045
+ Qiskit also defines a shared global-state object, :data:`SessionEquivalenceLibrary`, which is the
1046
+ default equivalences used by various places in Qiskit, most notably the :class:`.BasisTranslator`
1047
+ transpiler pass. You should feel free to add your own equivalences to this using its
1048
+ :meth:`~EquivalenceLibrary.add_equivalence` method, and they will be automatically picked up by
1049
+ default instances of the :class:`.BasisTranslator`.
1050
+
1051
+ .. py:data:: SessionEquivalenceLibrary
1052
+
1053
+ The default instance of :class:`EquivalenceLibrary`, which will be used by most Qiskit objects
1054
+ if no library is manually specified. You can feel free to add equivalences to this using
1055
+ :meth:`~EquivalenceLibrary.add_equivalence`. It inherits all the built-in rules of
1056
+ :data:`StandardEquivalenceLibrary`.
1057
+
1058
+
1059
+ Apply Pauli twirling to a circuit
1060
+ ---------------------------------
1061
+
1062
+ There are two primary types of noise when executing quantum circuits. The first is stochastic,
1063
+ or incoherent, noise that is mainly due to the unwanted interaction between the quantum processor
1064
+ and the external environment in which it resides. The second is known as coherent error, and these
1065
+ errors arise due to imperfect control of a quantum system. This can be unwanted terms in a system
1066
+ Hamiltonian, i.e. incorrect unitary evolution, or errors from incorrect temporal control of the
1067
+ quantum system, which includes things like incorrect pulse-shapes for gates.
1068
+
1069
+ Pauli twirling is a quantum error suppression technique that uses randomization to shape coherent
1070
+ error into stochastic errors by combining the results from many random, but logically equivalent
1071
+ circuits, together. Qiskit provides a function to apply Pauli twirling to a given circuit for
1072
+ standard two qubit gates. For more details you can refer to the documentation of the function
1073
+ below:
1074
+
1075
+ .. autofunction:: qiskit.circuit.pauli_twirl_2q_gates
1076
+
1077
+
1078
+ Exceptions
1079
+ ==========
1080
+
1081
+ Almost all circuit functions and methods will raise a :exc:`CircuitError` when encountering an error
1082
+ that is particular to usage of Qiskit (as opposed to regular typing or indexing problems, which will
1083
+ typically raise the corresponding standard Python error).
1084
+
1085
+ .. autoexception:: CircuitError
1086
+
1087
+
1088
+ .. _circuit-conventions:
1089
+
1090
+ Circuit conventions
1091
+ ===================
1092
+
1093
+ When constructing circuits out of abstract objects and more concrete matrices, there are several
1094
+ possible conventions around bit-labelling, bit-ordering, and how the abstract tensor product is
1095
+ realized in concrete matrix algebra.
1096
+
1097
+ Qiskit's conventions are:
1098
+
1099
+ * in bitstring representations, bits are labelled with the right-most bit in the string called
1100
+ :math:`0` and the left-most bit in the string of :math:`n` bits called :math:`n - 1`.
1101
+
1102
+ * when using integers as bit-specifier indices in circuit-construction functions, the integer is
1103
+ treated as an index into :attr:`QuantumCircuit.qubits` (or :attr:`~QuantumCircuit.clbits`).
1104
+
1105
+ * when drawing circuits, we put the lowest-index bits on top.
1106
+
1107
+ * in statevector representations, we realize the abstract tensor product as the Kronecker product,
1108
+ and order the arguments to this such that the amplitude of computational-basis state
1109
+ :math:`\lvert x\rangle`, where :math:`x` is the bitstring interpreted as an integer, is at
1110
+ location ``statevector[x]``.
1111
+
1112
+ * when controlling a gate, the control qubit(s) is placed first in the argument list, *e.g.* in the
1113
+ call ``qc.cx(0, 1)``, qubit 0 will be the control and qubit 1 will be the target. Similarly, in
1114
+ the manual call ``qc.append(CXGate(), [0, 1])``, qubit 0 will be the control and qubit 1 will be
1115
+ the target.
1116
+
1117
+ Let us illustrate these conventions with some examples.
1118
+
1119
+ Bit labelling
1120
+ -------------
1121
+
1122
+ Take the circuit:
1123
+
1124
+ .. plot::
1125
+ :include-source:
1126
+ :nofigs:
1127
+ :context:
1128
+ :show-source-link: False
1129
+
1130
+ from qiskit import QuantumCircuit
1131
+
1132
+ qc = QuantumCircuit(5, 5)
1133
+ qc.x(0)
1134
+ qc.x(1)
1135
+ qc.x(4)
1136
+ qc.measure(range(5), range(5))
1137
+
1138
+ This flips the states of qubits 0, 1 and 4 from :math:`\lvert0\rangle` to :math:`\lvert1\rangle`,
1139
+ then measures all qubits :math:`n` into the corresponding clbit :math:`n` using the computational
1140
+ (:math:`Z`) basis. If simulated noiselessly, the bitstring output from this circuit will be
1141
+ :math:`10011` every time; qubits 0, 1, and 4 are flipped, and the "one" values in the bitstring are
1142
+ in the zeroth, first and fourth digits *from the right*.
1143
+
1144
+ In Qiskit, we would write the qubit state immediately before the measurement in ket-notation
1145
+ shorthand as :math:`\lvert10011\rangle`. Note that the ket label matches the classical bitstring,
1146
+ and has the numeric binary value of 19.
1147
+
1148
+ If we draw this circuit, we will see that Qiskit places the zeroth qubit on the top of the circuit
1149
+ drawing:
1150
+
1151
+ .. plot::
1152
+ :alt: Circuit diagram output by the previous code.
1153
+ :include-source:
1154
+ :context:
1155
+ :show-source-link: False
1156
+
1157
+ qc.draw("mpl")
1158
+
1159
+
1160
+ Matrix representations
1161
+ ----------------------
1162
+
1163
+ Statevectors are defined in the convention that for a two-level system, the relationship between
1164
+ abstract representation and matrix representation is such that
1165
+
1166
+ .. math::
1167
+
1168
+ \alpha\lvert0\rangle + \beta\lvert1\rangle
1169
+ \leftrightarrow \begin{pmatrix} \alpha \\ \beta \end{pmatrix}
1170
+
1171
+ where :math:`\alpha` and :math:`\beta` are complex numbers. We store the statevector as a 1D Numpy
1172
+ :class:`~numpy.ndarray` with data ``sv = [alpha, beta]``, *i.e.* ``sv[0] == alpha`` and ``sv[1] ==
1173
+ beta``; note that the indices into the statevector match the ket labels.
1174
+
1175
+ We construct `the tensor product of two qubit states
1176
+ <https://en.wikipedia.org/wiki/Tensor_product>`_ in matrix algebra using `the Kronecker product
1177
+ <https://en.wikipedia.org/wiki/Kronecker_product>`_, with qubit 0 on the right and qubit 1 on the
1178
+ left, such that the :math:`Z` basis state :math:`\lvert x\rangle` (where :math:`x` is the integer
1179
+ interpretation of the bitstring) has its non-zero term in the statevector ``sv`` at ``sv[x]``::
1180
+
1181
+ import numpy
1182
+ from qiskit import QuantumCircuit
1183
+ from qiskit.quantum_info import Statevector
1184
+
1185
+ state_0 = [1, 0] # defined representation of |0>
1186
+ state_1 = [0, 1] # defined representation of |1>
1187
+
1188
+ # Circuit that creates basis state |10011>, where
1189
+ # binary 10011 has the decimal value 19.
1190
+ qc = QuantumCircuit(5)
1191
+ qc.x(0)
1192
+ qc.x(1)
1193
+ qc.x(4)
1194
+ qiskit_sv = Statevector(qc)
1195
+
1196
+ # List index 'n' corresponds to qubit 'n'.
1197
+ individual_states = [
1198
+ state_1,
1199
+ state_1,
1200
+ state_0,
1201
+ state_0,
1202
+ state_1,
1203
+ ]
1204
+ # Start from a scalar.
1205
+ manual_sv = [1]
1206
+ for qubit_state in individual_states:
1207
+ # Each new qubit goes "on the left".
1208
+ manual_sv = numpy.kron(qubit_state, manual_sv)
1209
+
1210
+ # Now `qiskit_sv` and `manual_sv` are the same, and:
1211
+ assert manual_sv[19] == 1
1212
+ assert qiskit_sv[19] == 1
1213
+
1214
+ This feeds through to the matrix representation of operators, and joins with the conventions on bit
1215
+ orders for controlled operators. For example, the matrix form of :class:`.CXGate` is::
1216
+
1217
+ import numpy
1218
+ from qiskit.circuit.library import CXGate
1219
+
1220
+ numpy.array(CXGate())
1221
+
1222
+ .. math::
1223
+
1224
+ \operatorname{array}(CX) =
1225
+ \begin{pmatrix}
1226
+ 1 & 0 & 0 & 0 \\
1227
+ 0 & 0 & 0 & 1 \\
1228
+ 0 & 0 & 1 & 0 \\
1229
+ 0 & 1 & 0 & 0
1230
+ \end{pmatrix}
1231
+
1232
+ This might be different to other matrix representations you have seen for :math:`CX`, but recall
1233
+ that the choice of matrix representation is conventional, and this form matches Qiskit's conventions
1234
+ of *control qubits come first* and *the tensor product is represented such that there is a
1235
+ correspondence between the index of the "one amplitude" and the bitstring value of a state*.
1236
+
1237
+ In the case of multiple controls for a gate, such as for :class:`.CCXGate`, the ``ctrl_state``
1238
+ argument is interpreted as the bitstring value of the control qubits, using the same zero-based
1239
+ labelling conventions. For example, given that the default ``ctrl_state`` is the all-ones
1240
+ bitstring, we can see that the matrix form of :class:`.CCXGate` with ``ctrl_state = 1`` is the same
1241
+ as if we took the all-ones control-state :class:`.CCXGate`, but flipped the value of the higher
1242
+ indexed control qubit on entry and exist to the gate::
1243
+
1244
+ from qiskit import QuantumCircuit
1245
+ from qiskit.quantum_info import Operator
1246
+
1247
+ # Build the natural representation of `CCX` with the
1248
+ # control qubits being `[0, 1]`, relative to the
1249
+ # bitstring state "01", such that qubit 0 must be in |1>
1250
+ # and qubit 1 must be in |0>. The target qubit is 2.
1251
+ ccx_natural = QuantumCircuit(3)
1252
+ ccx_natural.ccx(0, 1, 2, ctrl_state=1)
1253
+
1254
+ # Build the same circuit in terms of the all-ones CCX.
1255
+ # Note that we flip _qubit 1_, because that's the one
1256
+ # that differs from the all-ones state.
1257
+ ccx_relative = QuantumCircuit(3)
1258
+ ccx_relative.x(1)
1259
+ ccx_relative.ccx(0, 1, 2)
1260
+ ccx_relative.x(1)
1261
+
1262
+ assert Operator(ccx_relative) == Operator(ccx_natural)
1263
+
1264
+ In both these cases, the matrix form of :class:`.CCXGate` in ``ctrl_state = 1`` is:
1265
+
1266
+ .. math::
1267
+
1268
+ \operatorname{array}\bigl(CCX(\text{ctrl\_state}=1)\bigr) =
1269
+ \begin{pmatrix}
1270
+ 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\
1271
+ 0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 \\
1272
+ 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 \\
1273
+ 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 \\
1274
+ 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 \\
1275
+ 0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 \\
1276
+ 0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 \\
1277
+ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1
1278
+ \end{pmatrix}
1279
+ """
1280
+
1281
+ from qiskit._accelerate.circuit import ( # pylint: disable=unused-import
1282
+ Bit,
1283
+ Qubit,
1284
+ AncillaQubit,
1285
+ Clbit,
1286
+ QuantumRegister,
1287
+ AncillaRegister,
1288
+ ClassicalRegister,
1289
+ Register,
1290
+ Duration,
1291
+ )
1292
+
1293
+ from .exceptions import CircuitError
1294
+ from . import _utils
1295
+ from .quantumcircuit import QuantumCircuit
1296
+ from .gate import Gate
1297
+
1298
+ # pylint: disable=cyclic-import
1299
+ from . import annotation
1300
+ from .annotation import Annotation
1301
+ from .controlledgate import ControlledGate
1302
+ from . import singleton
1303
+ from .instruction import Instruction
1304
+ from .instructionset import InstructionSet
1305
+ from .operation import Operation
1306
+ from .barrier import Barrier
1307
+ from .delay import Delay
1308
+ from .measure import Measure
1309
+ from .reset import Reset
1310
+ from .store import Store
1311
+ from .parameter import Parameter
1312
+ from .parametervector import ParameterVector, ParameterVectorElement
1313
+ from .parameterexpression import ParameterExpression
1314
+ from .quantumcircuitdata import CircuitInstruction
1315
+ from .equivalence import EquivalenceLibrary
1316
+ from . import library
1317
+ from .equivalence_library import StandardEquivalenceLibrary, SessionEquivalenceLibrary
1318
+ from .commutation_checker import CommutationChecker
1319
+
1320
+ from .controlflow import (
1321
+ ControlFlowOp,
1322
+ BoxOp,
1323
+ WhileLoopOp,
1324
+ ForLoopOp,
1325
+ IfElseOp,
1326
+ SwitchCaseOp,
1327
+ CASE_DEFAULT,
1328
+ BreakLoopOp,
1329
+ ContinueLoopOp,
1330
+ CONTROL_FLOW_OP_NAMES,
1331
+ get_control_flow_name_mapping,
1332
+ )
1333
+
1334
+ from .annotated_operation import AnnotatedOperation, InverseModifier, ControlModifier, PowerModifier
1335
+ from .twirling import pauli_twirl_2q_gates