qiskit 1.3.0__cp39-abi3-win_amd64.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 (836) hide show
  1. qiskit/VERSION.txt +1 -0
  2. qiskit/__init__.py +146 -0
  3. qiskit/_accelerate.pyd +0 -0
  4. qiskit/_numpy_compat.py +73 -0
  5. qiskit/assembler/__init__.py +42 -0
  6. qiskit/assembler/assemble_circuits.py +451 -0
  7. qiskit/assembler/assemble_schedules.py +367 -0
  8. qiskit/assembler/disassemble.py +310 -0
  9. qiskit/assembler/run_config.py +77 -0
  10. qiskit/circuit/__init__.py +1313 -0
  11. qiskit/circuit/_classical_resource_map.py +148 -0
  12. qiskit/circuit/_standard_gates_commutations.py +3849 -0
  13. qiskit/circuit/_utils.py +167 -0
  14. qiskit/circuit/add_control.py +274 -0
  15. qiskit/circuit/annotated_operation.py +279 -0
  16. qiskit/circuit/barrier.py +50 -0
  17. qiskit/circuit/bit.py +94 -0
  18. qiskit/circuit/classical/__init__.py +41 -0
  19. qiskit/circuit/classical/expr/__init__.py +238 -0
  20. qiskit/circuit/classical/expr/constructors.py +556 -0
  21. qiskit/circuit/classical/expr/expr.py +397 -0
  22. qiskit/circuit/classical/expr/visitors.py +300 -0
  23. qiskit/circuit/classical/types/__init__.py +109 -0
  24. qiskit/circuit/classical/types/ordering.py +222 -0
  25. qiskit/circuit/classical/types/types.py +117 -0
  26. qiskit/circuit/classicalfunction/__init__.py +140 -0
  27. qiskit/circuit/classicalfunction/boolean_expression.py +129 -0
  28. qiskit/circuit/classicalfunction/classical_element.py +54 -0
  29. qiskit/circuit/classicalfunction/classical_function_visitor.py +155 -0
  30. qiskit/circuit/classicalfunction/classicalfunction.py +173 -0
  31. qiskit/circuit/classicalfunction/exceptions.py +35 -0
  32. qiskit/circuit/classicalfunction/types.py +18 -0
  33. qiskit/circuit/classicalfunction/utils.py +91 -0
  34. qiskit/circuit/classicalregister.py +57 -0
  35. qiskit/circuit/commutation_checker.py +106 -0
  36. qiskit/circuit/commutation_library.py +20 -0
  37. qiskit/circuit/controlflow/__init__.py +28 -0
  38. qiskit/circuit/controlflow/_builder_utils.py +207 -0
  39. qiskit/circuit/controlflow/break_loop.py +56 -0
  40. qiskit/circuit/controlflow/builder.py +691 -0
  41. qiskit/circuit/controlflow/continue_loop.py +58 -0
  42. qiskit/circuit/controlflow/control_flow.py +84 -0
  43. qiskit/circuit/controlflow/for_loop.py +217 -0
  44. qiskit/circuit/controlflow/if_else.py +511 -0
  45. qiskit/circuit/controlflow/switch_case.py +417 -0
  46. qiskit/circuit/controlflow/while_loop.py +171 -0
  47. qiskit/circuit/controlledgate.py +274 -0
  48. qiskit/circuit/delay.py +123 -0
  49. qiskit/circuit/duration.py +95 -0
  50. qiskit/circuit/equivalence.py +94 -0
  51. qiskit/circuit/equivalence_library.py +18 -0
  52. qiskit/circuit/exceptions.py +19 -0
  53. qiskit/circuit/gate.py +263 -0
  54. qiskit/circuit/instruction.py +697 -0
  55. qiskit/circuit/instructionset.py +179 -0
  56. qiskit/circuit/library/__init__.py +668 -0
  57. qiskit/circuit/library/arithmetic/__init__.py +34 -0
  58. qiskit/circuit/library/arithmetic/adders/__init__.py +18 -0
  59. qiskit/circuit/library/arithmetic/adders/adder.py +210 -0
  60. qiskit/circuit/library/arithmetic/adders/cdkm_ripple_carry_adder.py +123 -0
  61. qiskit/circuit/library/arithmetic/adders/draper_qft_adder.py +129 -0
  62. qiskit/circuit/library/arithmetic/adders/vbe_ripple_carry_adder.py +95 -0
  63. qiskit/circuit/library/arithmetic/exact_reciprocal.py +88 -0
  64. qiskit/circuit/library/arithmetic/functional_pauli_rotations.py +114 -0
  65. qiskit/circuit/library/arithmetic/integer_comparator.py +243 -0
  66. qiskit/circuit/library/arithmetic/linear_amplitude_function.py +196 -0
  67. qiskit/circuit/library/arithmetic/linear_pauli_rotations.py +189 -0
  68. qiskit/circuit/library/arithmetic/multipliers/__init__.py +17 -0
  69. qiskit/circuit/library/arithmetic/multipliers/hrs_cumulative_multiplier.py +145 -0
  70. qiskit/circuit/library/arithmetic/multipliers/multiplier.py +192 -0
  71. qiskit/circuit/library/arithmetic/multipliers/rg_qft_multiplier.py +108 -0
  72. qiskit/circuit/library/arithmetic/piecewise_chebyshev.py +353 -0
  73. qiskit/circuit/library/arithmetic/piecewise_linear_pauli_rotations.py +277 -0
  74. qiskit/circuit/library/arithmetic/piecewise_polynomial_pauli_rotations.py +317 -0
  75. qiskit/circuit/library/arithmetic/polynomial_pauli_rotations.py +335 -0
  76. qiskit/circuit/library/arithmetic/quadratic_form.py +198 -0
  77. qiskit/circuit/library/arithmetic/weighted_adder.py +337 -0
  78. qiskit/circuit/library/basis_change/__init__.py +15 -0
  79. qiskit/circuit/library/basis_change/qft.py +313 -0
  80. qiskit/circuit/library/blueprintcircuit.py +280 -0
  81. qiskit/circuit/library/boolean_logic/__init__.py +18 -0
  82. qiskit/circuit/library/boolean_logic/inner_product.py +155 -0
  83. qiskit/circuit/library/boolean_logic/quantum_and.py +200 -0
  84. qiskit/circuit/library/boolean_logic/quantum_or.py +202 -0
  85. qiskit/circuit/library/boolean_logic/quantum_xor.py +165 -0
  86. qiskit/circuit/library/data_preparation/__init__.py +57 -0
  87. qiskit/circuit/library/data_preparation/_z_feature_map.py +115 -0
  88. qiskit/circuit/library/data_preparation/_zz_feature_map.py +150 -0
  89. qiskit/circuit/library/data_preparation/initializer.py +107 -0
  90. qiskit/circuit/library/data_preparation/pauli_feature_map.py +656 -0
  91. qiskit/circuit/library/data_preparation/state_preparation.py +336 -0
  92. qiskit/circuit/library/fourier_checking.py +158 -0
  93. qiskit/circuit/library/generalized_gates/__init__.py +30 -0
  94. qiskit/circuit/library/generalized_gates/diagonal.py +159 -0
  95. qiskit/circuit/library/generalized_gates/gms.py +174 -0
  96. qiskit/circuit/library/generalized_gates/gr.py +215 -0
  97. qiskit/circuit/library/generalized_gates/isometry.py +370 -0
  98. qiskit/circuit/library/generalized_gates/linear_function.py +318 -0
  99. qiskit/circuit/library/generalized_gates/mcg_up_to_diagonal.py +143 -0
  100. qiskit/circuit/library/generalized_gates/mcmt.py +316 -0
  101. qiskit/circuit/library/generalized_gates/pauli.py +85 -0
  102. qiskit/circuit/library/generalized_gates/permutation.py +194 -0
  103. qiskit/circuit/library/generalized_gates/rv.py +96 -0
  104. qiskit/circuit/library/generalized_gates/uc.py +213 -0
  105. qiskit/circuit/library/generalized_gates/uc_pauli_rot.py +164 -0
  106. qiskit/circuit/library/generalized_gates/ucrx.py +32 -0
  107. qiskit/circuit/library/generalized_gates/ucry.py +32 -0
  108. qiskit/circuit/library/generalized_gates/ucrz.py +32 -0
  109. qiskit/circuit/library/generalized_gates/unitary.py +215 -0
  110. qiskit/circuit/library/graph_state.py +169 -0
  111. qiskit/circuit/library/grover_operator.py +579 -0
  112. qiskit/circuit/library/hamiltonian_gate.py +142 -0
  113. qiskit/circuit/library/hidden_linear_function.py +161 -0
  114. qiskit/circuit/library/iqp.py +175 -0
  115. qiskit/circuit/library/n_local/__init__.py +45 -0
  116. qiskit/circuit/library/n_local/efficient_su2.py +277 -0
  117. qiskit/circuit/library/n_local/evolved_operator_ansatz.py +515 -0
  118. qiskit/circuit/library/n_local/excitation_preserving.py +297 -0
  119. qiskit/circuit/library/n_local/n_local.py +1472 -0
  120. qiskit/circuit/library/n_local/pauli_two_design.py +243 -0
  121. qiskit/circuit/library/n_local/qaoa_ansatz.py +366 -0
  122. qiskit/circuit/library/n_local/real_amplitudes.py +306 -0
  123. qiskit/circuit/library/n_local/two_local.py +289 -0
  124. qiskit/circuit/library/overlap.py +182 -0
  125. qiskit/circuit/library/pauli_evolution.py +186 -0
  126. qiskit/circuit/library/phase_estimation.py +175 -0
  127. qiskit/circuit/library/phase_oracle.py +153 -0
  128. qiskit/circuit/library/quantum_volume.py +167 -0
  129. qiskit/circuit/library/standard_gates/__init__.py +142 -0
  130. qiskit/circuit/library/standard_gates/dcx.py +78 -0
  131. qiskit/circuit/library/standard_gates/ecr.py +130 -0
  132. qiskit/circuit/library/standard_gates/equivalence_library.py +1800 -0
  133. qiskit/circuit/library/standard_gates/global_phase.py +85 -0
  134. qiskit/circuit/library/standard_gates/h.py +258 -0
  135. qiskit/circuit/library/standard_gates/i.py +76 -0
  136. qiskit/circuit/library/standard_gates/iswap.py +134 -0
  137. qiskit/circuit/library/standard_gates/multi_control_rotation_gates.py +405 -0
  138. qiskit/circuit/library/standard_gates/p.py +441 -0
  139. qiskit/circuit/library/standard_gates/r.py +117 -0
  140. qiskit/circuit/library/standard_gates/rx.py +303 -0
  141. qiskit/circuit/library/standard_gates/rxx.py +183 -0
  142. qiskit/circuit/library/standard_gates/ry.py +298 -0
  143. qiskit/circuit/library/standard_gates/ryy.py +183 -0
  144. qiskit/circuit/library/standard_gates/rz.py +319 -0
  145. qiskit/circuit/library/standard_gates/rzx.py +229 -0
  146. qiskit/circuit/library/standard_gates/rzz.py +196 -0
  147. qiskit/circuit/library/standard_gates/s.py +428 -0
  148. qiskit/circuit/library/standard_gates/swap.py +288 -0
  149. qiskit/circuit/library/standard_gates/sx.py +315 -0
  150. qiskit/circuit/library/standard_gates/t.py +179 -0
  151. qiskit/circuit/library/standard_gates/u.py +403 -0
  152. qiskit/circuit/library/standard_gates/u1.py +501 -0
  153. qiskit/circuit/library/standard_gates/u2.py +149 -0
  154. qiskit/circuit/library/standard_gates/u3.py +436 -0
  155. qiskit/circuit/library/standard_gates/x.py +1529 -0
  156. qiskit/circuit/library/standard_gates/xx_minus_yy.py +235 -0
  157. qiskit/circuit/library/standard_gates/xx_plus_yy.py +239 -0
  158. qiskit/circuit/library/standard_gates/y.py +262 -0
  159. qiskit/circuit/library/standard_gates/z.py +348 -0
  160. qiskit/circuit/library/templates/__init__.py +92 -0
  161. qiskit/circuit/library/templates/clifford/__init__.py +33 -0
  162. qiskit/circuit/library/templates/clifford/clifford_2_1.py +34 -0
  163. qiskit/circuit/library/templates/clifford/clifford_2_2.py +35 -0
  164. qiskit/circuit/library/templates/clifford/clifford_2_3.py +34 -0
  165. qiskit/circuit/library/templates/clifford/clifford_2_4.py +34 -0
  166. qiskit/circuit/library/templates/clifford/clifford_3_1.py +35 -0
  167. qiskit/circuit/library/templates/clifford/clifford_4_1.py +38 -0
  168. qiskit/circuit/library/templates/clifford/clifford_4_2.py +37 -0
  169. qiskit/circuit/library/templates/clifford/clifford_4_3.py +38 -0
  170. qiskit/circuit/library/templates/clifford/clifford_4_4.py +37 -0
  171. qiskit/circuit/library/templates/clifford/clifford_5_1.py +40 -0
  172. qiskit/circuit/library/templates/clifford/clifford_6_1.py +40 -0
  173. qiskit/circuit/library/templates/clifford/clifford_6_2.py +40 -0
  174. qiskit/circuit/library/templates/clifford/clifford_6_3.py +40 -0
  175. qiskit/circuit/library/templates/clifford/clifford_6_4.py +38 -0
  176. qiskit/circuit/library/templates/clifford/clifford_6_5.py +40 -0
  177. qiskit/circuit/library/templates/clifford/clifford_8_1.py +42 -0
  178. qiskit/circuit/library/templates/clifford/clifford_8_2.py +42 -0
  179. qiskit/circuit/library/templates/clifford/clifford_8_3.py +41 -0
  180. qiskit/circuit/library/templates/nct/__init__.py +67 -0
  181. qiskit/circuit/library/templates/nct/template_nct_2a_1.py +34 -0
  182. qiskit/circuit/library/templates/nct/template_nct_2a_2.py +35 -0
  183. qiskit/circuit/library/templates/nct/template_nct_2a_3.py +37 -0
  184. qiskit/circuit/library/templates/nct/template_nct_4a_1.py +43 -0
  185. qiskit/circuit/library/templates/nct/template_nct_4a_2.py +41 -0
  186. qiskit/circuit/library/templates/nct/template_nct_4a_3.py +39 -0
  187. qiskit/circuit/library/templates/nct/template_nct_4b_1.py +41 -0
  188. qiskit/circuit/library/templates/nct/template_nct_4b_2.py +39 -0
  189. qiskit/circuit/library/templates/nct/template_nct_5a_1.py +40 -0
  190. qiskit/circuit/library/templates/nct/template_nct_5a_2.py +40 -0
  191. qiskit/circuit/library/templates/nct/template_nct_5a_3.py +40 -0
  192. qiskit/circuit/library/templates/nct/template_nct_5a_4.py +39 -0
  193. qiskit/circuit/library/templates/nct/template_nct_6a_1.py +40 -0
  194. qiskit/circuit/library/templates/nct/template_nct_6a_2.py +41 -0
  195. qiskit/circuit/library/templates/nct/template_nct_6a_3.py +41 -0
  196. qiskit/circuit/library/templates/nct/template_nct_6a_4.py +41 -0
  197. qiskit/circuit/library/templates/nct/template_nct_6b_1.py +41 -0
  198. qiskit/circuit/library/templates/nct/template_nct_6b_2.py +41 -0
  199. qiskit/circuit/library/templates/nct/template_nct_6c_1.py +41 -0
  200. qiskit/circuit/library/templates/nct/template_nct_7a_1.py +43 -0
  201. qiskit/circuit/library/templates/nct/template_nct_7b_1.py +43 -0
  202. qiskit/circuit/library/templates/nct/template_nct_7c_1.py +43 -0
  203. qiskit/circuit/library/templates/nct/template_nct_7d_1.py +43 -0
  204. qiskit/circuit/library/templates/nct/template_nct_7e_1.py +43 -0
  205. qiskit/circuit/library/templates/nct/template_nct_9a_1.py +45 -0
  206. qiskit/circuit/library/templates/nct/template_nct_9c_1.py +43 -0
  207. qiskit/circuit/library/templates/nct/template_nct_9c_10.py +44 -0
  208. qiskit/circuit/library/templates/nct/template_nct_9c_11.py +44 -0
  209. qiskit/circuit/library/templates/nct/template_nct_9c_12.py +44 -0
  210. qiskit/circuit/library/templates/nct/template_nct_9c_2.py +44 -0
  211. qiskit/circuit/library/templates/nct/template_nct_9c_3.py +44 -0
  212. qiskit/circuit/library/templates/nct/template_nct_9c_4.py +44 -0
  213. qiskit/circuit/library/templates/nct/template_nct_9c_5.py +44 -0
  214. qiskit/circuit/library/templates/nct/template_nct_9c_6.py +44 -0
  215. qiskit/circuit/library/templates/nct/template_nct_9c_7.py +44 -0
  216. qiskit/circuit/library/templates/nct/template_nct_9c_8.py +44 -0
  217. qiskit/circuit/library/templates/nct/template_nct_9c_9.py +44 -0
  218. qiskit/circuit/library/templates/nct/template_nct_9d_1.py +43 -0
  219. qiskit/circuit/library/templates/nct/template_nct_9d_10.py +44 -0
  220. qiskit/circuit/library/templates/nct/template_nct_9d_2.py +44 -0
  221. qiskit/circuit/library/templates/nct/template_nct_9d_3.py +44 -0
  222. qiskit/circuit/library/templates/nct/template_nct_9d_4.py +44 -0
  223. qiskit/circuit/library/templates/nct/template_nct_9d_5.py +44 -0
  224. qiskit/circuit/library/templates/nct/template_nct_9d_6.py +44 -0
  225. qiskit/circuit/library/templates/nct/template_nct_9d_7.py +44 -0
  226. qiskit/circuit/library/templates/nct/template_nct_9d_8.py +44 -0
  227. qiskit/circuit/library/templates/nct/template_nct_9d_9.py +44 -0
  228. qiskit/circuit/library/templates/rzx/__init__.py +25 -0
  229. qiskit/circuit/library/templates/rzx/rzx_cy.py +47 -0
  230. qiskit/circuit/library/templates/rzx/rzx_xz.py +54 -0
  231. qiskit/circuit/library/templates/rzx/rzx_yz.py +45 -0
  232. qiskit/circuit/library/templates/rzx/rzx_zz1.py +69 -0
  233. qiskit/circuit/library/templates/rzx/rzx_zz2.py +59 -0
  234. qiskit/circuit/library/templates/rzx/rzx_zz3.py +59 -0
  235. qiskit/circuit/measure.py +44 -0
  236. qiskit/circuit/operation.py +67 -0
  237. qiskit/circuit/parameter.py +178 -0
  238. qiskit/circuit/parameterexpression.py +692 -0
  239. qiskit/circuit/parametertable.py +119 -0
  240. qiskit/circuit/parametervector.py +120 -0
  241. qiskit/circuit/quantumcircuit.py +6829 -0
  242. qiskit/circuit/quantumcircuitdata.py +136 -0
  243. qiskit/circuit/quantumregister.py +75 -0
  244. qiskit/circuit/random/__init__.py +15 -0
  245. qiskit/circuit/random/utils.py +358 -0
  246. qiskit/circuit/register.py +233 -0
  247. qiskit/circuit/reset.py +34 -0
  248. qiskit/circuit/singleton.py +606 -0
  249. qiskit/circuit/store.py +97 -0
  250. qiskit/circuit/tools/__init__.py +16 -0
  251. qiskit/circuit/tools/pi_check.py +190 -0
  252. qiskit/circuit/twirling.py +145 -0
  253. qiskit/compiler/__init__.py +33 -0
  254. qiskit/compiler/assembler.py +681 -0
  255. qiskit/compiler/scheduler.py +109 -0
  256. qiskit/compiler/sequencer.py +71 -0
  257. qiskit/compiler/transpiler.py +533 -0
  258. qiskit/converters/__init__.py +74 -0
  259. qiskit/converters/circuit_to_dag.py +78 -0
  260. qiskit/converters/circuit_to_dagdependency.py +51 -0
  261. qiskit/converters/circuit_to_dagdependency_v2.py +47 -0
  262. qiskit/converters/circuit_to_gate.py +107 -0
  263. qiskit/converters/circuit_to_instruction.py +155 -0
  264. qiskit/converters/dag_to_circuit.py +79 -0
  265. qiskit/converters/dag_to_dagdependency.py +55 -0
  266. qiskit/converters/dag_to_dagdependency_v2.py +44 -0
  267. qiskit/converters/dagdependency_to_circuit.py +46 -0
  268. qiskit/converters/dagdependency_to_dag.py +54 -0
  269. qiskit/dagcircuit/__init__.py +44 -0
  270. qiskit/dagcircuit/collect_blocks.py +391 -0
  271. qiskit/dagcircuit/dagcircuit.py +24 -0
  272. qiskit/dagcircuit/dagdependency.py +646 -0
  273. qiskit/dagcircuit/dagdependency_v2.py +641 -0
  274. qiskit/dagcircuit/dagdepnode.py +160 -0
  275. qiskit/dagcircuit/dagnode.py +176 -0
  276. qiskit/dagcircuit/exceptions.py +42 -0
  277. qiskit/exceptions.py +153 -0
  278. qiskit/passmanager/__init__.py +240 -0
  279. qiskit/passmanager/base_tasks.py +230 -0
  280. qiskit/passmanager/compilation_status.py +74 -0
  281. qiskit/passmanager/exceptions.py +19 -0
  282. qiskit/passmanager/flow_controllers.py +116 -0
  283. qiskit/passmanager/passmanager.py +333 -0
  284. qiskit/primitives/__init__.py +481 -0
  285. qiskit/primitives/backend_estimator.py +486 -0
  286. qiskit/primitives/backend_estimator_v2.py +434 -0
  287. qiskit/primitives/backend_sampler.py +222 -0
  288. qiskit/primitives/backend_sampler_v2.py +339 -0
  289. qiskit/primitives/base/__init__.py +20 -0
  290. qiskit/primitives/base/base_estimator.py +252 -0
  291. qiskit/primitives/base/base_primitive.py +45 -0
  292. qiskit/primitives/base/base_primitive_job.py +78 -0
  293. qiskit/primitives/base/base_result.py +65 -0
  294. qiskit/primitives/base/base_sampler.py +204 -0
  295. qiskit/primitives/base/estimator_result.py +46 -0
  296. qiskit/primitives/base/sampler_result.py +45 -0
  297. qiskit/primitives/base/validation.py +231 -0
  298. qiskit/primitives/containers/__init__.py +26 -0
  299. qiskit/primitives/containers/bindings_array.py +389 -0
  300. qiskit/primitives/containers/bit_array.py +741 -0
  301. qiskit/primitives/containers/data_bin.py +173 -0
  302. qiskit/primitives/containers/estimator_pub.py +222 -0
  303. qiskit/primitives/containers/object_array.py +94 -0
  304. qiskit/primitives/containers/observables_array.py +279 -0
  305. qiskit/primitives/containers/primitive_result.py +53 -0
  306. qiskit/primitives/containers/pub_result.py +51 -0
  307. qiskit/primitives/containers/sampler_pub.py +193 -0
  308. qiskit/primitives/containers/sampler_pub_result.py +74 -0
  309. qiskit/primitives/containers/shape.py +129 -0
  310. qiskit/primitives/estimator.py +172 -0
  311. qiskit/primitives/primitive_job.py +81 -0
  312. qiskit/primitives/sampler.py +162 -0
  313. qiskit/primitives/statevector_estimator.py +174 -0
  314. qiskit/primitives/statevector_sampler.py +292 -0
  315. qiskit/primitives/utils.py +247 -0
  316. qiskit/providers/__init__.py +803 -0
  317. qiskit/providers/backend.py +667 -0
  318. qiskit/providers/backend_compat.py +472 -0
  319. qiskit/providers/basic_provider/__init__.py +45 -0
  320. qiskit/providers/basic_provider/basic_provider.py +101 -0
  321. qiskit/providers/basic_provider/basic_provider_job.py +65 -0
  322. qiskit/providers/basic_provider/basic_provider_tools.py +218 -0
  323. qiskit/providers/basic_provider/basic_simulator.py +821 -0
  324. qiskit/providers/basic_provider/exceptions.py +30 -0
  325. qiskit/providers/exceptions.py +45 -0
  326. qiskit/providers/fake_provider/__init__.py +105 -0
  327. qiskit/providers/fake_provider/backends_v1/__init__.py +22 -0
  328. qiskit/providers/fake_provider/backends_v1/fake_127q_pulse/__init__.py +18 -0
  329. qiskit/providers/fake_provider/backends_v1/fake_127q_pulse/conf_washington.json +1 -0
  330. qiskit/providers/fake_provider/backends_v1/fake_127q_pulse/defs_washington.json +1 -0
  331. qiskit/providers/fake_provider/backends_v1/fake_127q_pulse/fake_127q_pulse_v1.py +37 -0
  332. qiskit/providers/fake_provider/backends_v1/fake_127q_pulse/props_washington.json +1 -0
  333. qiskit/providers/fake_provider/backends_v1/fake_20q/__init__.py +18 -0
  334. qiskit/providers/fake_provider/backends_v1/fake_20q/conf_singapore.json +1 -0
  335. qiskit/providers/fake_provider/backends_v1/fake_20q/fake_20q.py +43 -0
  336. qiskit/providers/fake_provider/backends_v1/fake_20q/props_singapore.json +1 -0
  337. qiskit/providers/fake_provider/backends_v1/fake_27q_pulse/__init__.py +18 -0
  338. qiskit/providers/fake_provider/backends_v1/fake_27q_pulse/conf_hanoi.json +1 -0
  339. qiskit/providers/fake_provider/backends_v1/fake_27q_pulse/defs_hanoi.json +1 -0
  340. qiskit/providers/fake_provider/backends_v1/fake_27q_pulse/fake_27q_pulse_v1.py +50 -0
  341. qiskit/providers/fake_provider/backends_v1/fake_27q_pulse/props_hanoi.json +1 -0
  342. qiskit/providers/fake_provider/backends_v1/fake_5q/__init__.py +18 -0
  343. qiskit/providers/fake_provider/backends_v1/fake_5q/conf_yorktown.json +1 -0
  344. qiskit/providers/fake_provider/backends_v1/fake_5q/fake_5q_v1.py +41 -0
  345. qiskit/providers/fake_provider/backends_v1/fake_5q/props_yorktown.json +1 -0
  346. qiskit/providers/fake_provider/backends_v1/fake_7q_pulse/__init__.py +18 -0
  347. qiskit/providers/fake_provider/backends_v1/fake_7q_pulse/conf_nairobi.json +1 -0
  348. qiskit/providers/fake_provider/backends_v1/fake_7q_pulse/defs_nairobi.json +1 -0
  349. qiskit/providers/fake_provider/backends_v1/fake_7q_pulse/fake_7q_pulse_v1.py +44 -0
  350. qiskit/providers/fake_provider/backends_v1/fake_7q_pulse/props_nairobi.json +1 -0
  351. qiskit/providers/fake_provider/fake_1q.py +91 -0
  352. qiskit/providers/fake_provider/fake_backend.py +165 -0
  353. qiskit/providers/fake_provider/fake_openpulse_2q.py +391 -0
  354. qiskit/providers/fake_provider/fake_openpulse_3q.py +340 -0
  355. qiskit/providers/fake_provider/fake_pulse_backend.py +49 -0
  356. qiskit/providers/fake_provider/fake_qasm_backend.py +77 -0
  357. qiskit/providers/fake_provider/generic_backend_v2.py +1035 -0
  358. qiskit/providers/fake_provider/utils/__init__.py +15 -0
  359. qiskit/providers/fake_provider/utils/backend_converter.py +150 -0
  360. qiskit/providers/fake_provider/utils/json_decoder.py +109 -0
  361. qiskit/providers/job.py +147 -0
  362. qiskit/providers/jobstatus.py +30 -0
  363. qiskit/providers/models/__init__.py +89 -0
  364. qiskit/providers/models/backendconfiguration.py +1040 -0
  365. qiskit/providers/models/backendproperties.py +517 -0
  366. qiskit/providers/models/backendstatus.py +94 -0
  367. qiskit/providers/models/jobstatus.py +66 -0
  368. qiskit/providers/models/pulsedefaults.py +305 -0
  369. qiskit/providers/options.py +273 -0
  370. qiskit/providers/provider.py +95 -0
  371. qiskit/providers/providerutils.py +110 -0
  372. qiskit/pulse/__init__.py +158 -0
  373. qiskit/pulse/builder.py +2254 -0
  374. qiskit/pulse/calibration_entries.py +381 -0
  375. qiskit/pulse/channels.py +227 -0
  376. qiskit/pulse/configuration.py +245 -0
  377. qiskit/pulse/exceptions.py +45 -0
  378. qiskit/pulse/filters.py +309 -0
  379. qiskit/pulse/instruction_schedule_map.py +424 -0
  380. qiskit/pulse/instructions/__init__.py +67 -0
  381. qiskit/pulse/instructions/acquire.py +150 -0
  382. qiskit/pulse/instructions/delay.py +71 -0
  383. qiskit/pulse/instructions/directives.py +154 -0
  384. qiskit/pulse/instructions/frequency.py +135 -0
  385. qiskit/pulse/instructions/instruction.py +270 -0
  386. qiskit/pulse/instructions/phase.py +152 -0
  387. qiskit/pulse/instructions/play.py +99 -0
  388. qiskit/pulse/instructions/reference.py +100 -0
  389. qiskit/pulse/instructions/snapshot.py +82 -0
  390. qiskit/pulse/library/__init__.py +97 -0
  391. qiskit/pulse/library/continuous.py +430 -0
  392. qiskit/pulse/library/pulse.py +148 -0
  393. qiskit/pulse/library/samplers/__init__.py +15 -0
  394. qiskit/pulse/library/samplers/decorators.py +295 -0
  395. qiskit/pulse/library/samplers/strategies.py +71 -0
  396. qiskit/pulse/library/symbolic_pulses.py +1988 -0
  397. qiskit/pulse/library/waveform.py +136 -0
  398. qiskit/pulse/macros.py +262 -0
  399. qiskit/pulse/parameter_manager.py +445 -0
  400. qiskit/pulse/parser.py +314 -0
  401. qiskit/pulse/reference_manager.py +58 -0
  402. qiskit/pulse/schedule.py +1854 -0
  403. qiskit/pulse/transforms/__init__.py +106 -0
  404. qiskit/pulse/transforms/alignments.py +406 -0
  405. qiskit/pulse/transforms/base_transforms.py +71 -0
  406. qiskit/pulse/transforms/canonicalization.py +498 -0
  407. qiskit/pulse/transforms/dag.py +122 -0
  408. qiskit/pulse/utils.py +149 -0
  409. qiskit/qasm/libs/dummy/stdgates.inc +75 -0
  410. qiskit/qasm/libs/qelib1.inc +266 -0
  411. qiskit/qasm/libs/stdgates.inc +82 -0
  412. qiskit/qasm2/__init__.py +654 -0
  413. qiskit/qasm2/exceptions.py +27 -0
  414. qiskit/qasm2/export.py +372 -0
  415. qiskit/qasm2/parse.py +452 -0
  416. qiskit/qasm3/__init__.py +367 -0
  417. qiskit/qasm3/ast.py +738 -0
  418. qiskit/qasm3/exceptions.py +27 -0
  419. qiskit/qasm3/experimental.py +70 -0
  420. qiskit/qasm3/exporter.py +1299 -0
  421. qiskit/qasm3/printer.py +577 -0
  422. qiskit/qobj/__init__.py +75 -0
  423. qiskit/qobj/common.py +81 -0
  424. qiskit/qobj/converters/__init__.py +18 -0
  425. qiskit/qobj/converters/lo_config.py +177 -0
  426. qiskit/qobj/converters/pulse_instruction.py +897 -0
  427. qiskit/qobj/pulse_qobj.py +709 -0
  428. qiskit/qobj/qasm_qobj.py +708 -0
  429. qiskit/qobj/utils.py +46 -0
  430. qiskit/qpy/__init__.py +1822 -0
  431. qiskit/qpy/binary_io/__init__.py +36 -0
  432. qiskit/qpy/binary_io/circuits.py +1475 -0
  433. qiskit/qpy/binary_io/schedules.py +635 -0
  434. qiskit/qpy/binary_io/value.py +1025 -0
  435. qiskit/qpy/common.py +350 -0
  436. qiskit/qpy/exceptions.py +53 -0
  437. qiskit/qpy/formats.py +401 -0
  438. qiskit/qpy/interface.py +377 -0
  439. qiskit/qpy/type_keys.py +572 -0
  440. qiskit/quantum_info/__init__.py +162 -0
  441. qiskit/quantum_info/analysis/__init__.py +17 -0
  442. qiskit/quantum_info/analysis/average.py +47 -0
  443. qiskit/quantum_info/analysis/distance.py +102 -0
  444. qiskit/quantum_info/analysis/make_observable.py +44 -0
  445. qiskit/quantum_info/analysis/z2_symmetries.py +484 -0
  446. qiskit/quantum_info/operators/__init__.py +28 -0
  447. qiskit/quantum_info/operators/base_operator.py +145 -0
  448. qiskit/quantum_info/operators/channel/__init__.py +29 -0
  449. qiskit/quantum_info/operators/channel/chi.py +191 -0
  450. qiskit/quantum_info/operators/channel/choi.py +218 -0
  451. qiskit/quantum_info/operators/channel/kraus.py +337 -0
  452. qiskit/quantum_info/operators/channel/ptm.py +204 -0
  453. qiskit/quantum_info/operators/channel/quantum_channel.py +348 -0
  454. qiskit/quantum_info/operators/channel/stinespring.py +296 -0
  455. qiskit/quantum_info/operators/channel/superop.py +377 -0
  456. qiskit/quantum_info/operators/channel/transformations.py +475 -0
  457. qiskit/quantum_info/operators/custom_iterator.py +48 -0
  458. qiskit/quantum_info/operators/dihedral/__init__.py +18 -0
  459. qiskit/quantum_info/operators/dihedral/dihedral.py +509 -0
  460. qiskit/quantum_info/operators/dihedral/dihedral_circuits.py +216 -0
  461. qiskit/quantum_info/operators/dihedral/polynomial.py +313 -0
  462. qiskit/quantum_info/operators/dihedral/random.py +64 -0
  463. qiskit/quantum_info/operators/linear_op.py +25 -0
  464. qiskit/quantum_info/operators/measures.py +418 -0
  465. qiskit/quantum_info/operators/mixins/__init__.py +52 -0
  466. qiskit/quantum_info/operators/mixins/adjoint.py +52 -0
  467. qiskit/quantum_info/operators/mixins/group.py +171 -0
  468. qiskit/quantum_info/operators/mixins/linear.py +84 -0
  469. qiskit/quantum_info/operators/mixins/multiply.py +62 -0
  470. qiskit/quantum_info/operators/mixins/tolerances.py +72 -0
  471. qiskit/quantum_info/operators/op_shape.py +525 -0
  472. qiskit/quantum_info/operators/operator.py +865 -0
  473. qiskit/quantum_info/operators/operator_utils.py +76 -0
  474. qiskit/quantum_info/operators/predicates.py +183 -0
  475. qiskit/quantum_info/operators/random.py +154 -0
  476. qiskit/quantum_info/operators/scalar_op.py +254 -0
  477. qiskit/quantum_info/operators/symplectic/__init__.py +23 -0
  478. qiskit/quantum_info/operators/symplectic/base_pauli.py +719 -0
  479. qiskit/quantum_info/operators/symplectic/clifford.py +1030 -0
  480. qiskit/quantum_info/operators/symplectic/clifford_circuits.py +558 -0
  481. qiskit/quantum_info/operators/symplectic/pauli.py +753 -0
  482. qiskit/quantum_info/operators/symplectic/pauli_list.py +1230 -0
  483. qiskit/quantum_info/operators/symplectic/pauli_utils.py +40 -0
  484. qiskit/quantum_info/operators/symplectic/random.py +117 -0
  485. qiskit/quantum_info/operators/symplectic/sparse_pauli_op.py +1196 -0
  486. qiskit/quantum_info/operators/utils/__init__.py +20 -0
  487. qiskit/quantum_info/operators/utils/anti_commutator.py +36 -0
  488. qiskit/quantum_info/operators/utils/commutator.py +36 -0
  489. qiskit/quantum_info/operators/utils/double_commutator.py +76 -0
  490. qiskit/quantum_info/quaternion.py +156 -0
  491. qiskit/quantum_info/random.py +26 -0
  492. qiskit/quantum_info/states/__init__.py +28 -0
  493. qiskit/quantum_info/states/densitymatrix.py +845 -0
  494. qiskit/quantum_info/states/measures.py +288 -0
  495. qiskit/quantum_info/states/quantum_state.py +503 -0
  496. qiskit/quantum_info/states/random.py +157 -0
  497. qiskit/quantum_info/states/stabilizerstate.py +773 -0
  498. qiskit/quantum_info/states/statevector.py +958 -0
  499. qiskit/quantum_info/states/utils.py +247 -0
  500. qiskit/result/__init__.py +73 -0
  501. qiskit/result/counts.py +189 -0
  502. qiskit/result/distributions/__init__.py +17 -0
  503. qiskit/result/distributions/probability.py +100 -0
  504. qiskit/result/distributions/quasi.py +154 -0
  505. qiskit/result/exceptions.py +40 -0
  506. qiskit/result/mitigation/__init__.py +13 -0
  507. qiskit/result/mitigation/base_readout_mitigator.py +79 -0
  508. qiskit/result/mitigation/correlated_readout_mitigator.py +277 -0
  509. qiskit/result/mitigation/local_readout_mitigator.py +328 -0
  510. qiskit/result/mitigation/utils.py +217 -0
  511. qiskit/result/models.py +234 -0
  512. qiskit/result/postprocess.py +239 -0
  513. qiskit/result/result.py +392 -0
  514. qiskit/result/sampled_expval.py +75 -0
  515. qiskit/result/utils.py +295 -0
  516. qiskit/scheduler/__init__.py +40 -0
  517. qiskit/scheduler/config.py +37 -0
  518. qiskit/scheduler/lowering.py +187 -0
  519. qiskit/scheduler/methods/__init__.py +15 -0
  520. qiskit/scheduler/methods/basic.py +140 -0
  521. qiskit/scheduler/schedule_circuit.py +69 -0
  522. qiskit/scheduler/sequence.py +104 -0
  523. qiskit/synthesis/__init__.py +220 -0
  524. qiskit/synthesis/arithmetic/__init__.py +16 -0
  525. qiskit/synthesis/arithmetic/adders/__init__.py +17 -0
  526. qiskit/synthesis/arithmetic/adders/cdkm_ripple_carry_adder.py +154 -0
  527. qiskit/synthesis/arithmetic/adders/draper_qft_adder.py +103 -0
  528. qiskit/synthesis/arithmetic/adders/vbe_ripple_carry_adder.py +161 -0
  529. qiskit/synthesis/arithmetic/multipliers/__init__.py +16 -0
  530. qiskit/synthesis/arithmetic/multipliers/hrs_cumulative_multiplier.py +102 -0
  531. qiskit/synthesis/arithmetic/multipliers/rg_qft_multiplier.py +99 -0
  532. qiskit/synthesis/clifford/__init__.py +19 -0
  533. qiskit/synthesis/clifford/clifford_decompose_ag.py +178 -0
  534. qiskit/synthesis/clifford/clifford_decompose_bm.py +46 -0
  535. qiskit/synthesis/clifford/clifford_decompose_full.py +64 -0
  536. qiskit/synthesis/clifford/clifford_decompose_greedy.py +58 -0
  537. qiskit/synthesis/clifford/clifford_decompose_layers.py +447 -0
  538. qiskit/synthesis/cnotdihedral/__init__.py +17 -0
  539. qiskit/synthesis/cnotdihedral/cnotdihedral_decompose_full.py +52 -0
  540. qiskit/synthesis/cnotdihedral/cnotdihedral_decompose_general.py +141 -0
  541. qiskit/synthesis/cnotdihedral/cnotdihedral_decompose_two_qubits.py +266 -0
  542. qiskit/synthesis/discrete_basis/__init__.py +16 -0
  543. qiskit/synthesis/discrete_basis/commutator_decompose.py +241 -0
  544. qiskit/synthesis/discrete_basis/gate_sequence.py +415 -0
  545. qiskit/synthesis/discrete_basis/generate_basis_approximations.py +163 -0
  546. qiskit/synthesis/discrete_basis/solovay_kitaev.py +217 -0
  547. qiskit/synthesis/evolution/__init__.py +21 -0
  548. qiskit/synthesis/evolution/evolution_synthesis.py +48 -0
  549. qiskit/synthesis/evolution/lie_trotter.py +117 -0
  550. qiskit/synthesis/evolution/matrix_synthesis.py +47 -0
  551. qiskit/synthesis/evolution/pauli_network.py +80 -0
  552. qiskit/synthesis/evolution/product_formula.py +311 -0
  553. qiskit/synthesis/evolution/qdrift.py +138 -0
  554. qiskit/synthesis/evolution/suzuki_trotter.py +215 -0
  555. qiskit/synthesis/linear/__init__.py +26 -0
  556. qiskit/synthesis/linear/cnot_synth.py +69 -0
  557. qiskit/synthesis/linear/linear_circuits_utils.py +128 -0
  558. qiskit/synthesis/linear/linear_depth_lnn.py +276 -0
  559. qiskit/synthesis/linear/linear_matrix_utils.py +27 -0
  560. qiskit/synthesis/linear_phase/__init__.py +17 -0
  561. qiskit/synthesis/linear_phase/cnot_phase_synth.py +206 -0
  562. qiskit/synthesis/linear_phase/cx_cz_depth_lnn.py +262 -0
  563. qiskit/synthesis/linear_phase/cz_depth_lnn.py +58 -0
  564. qiskit/synthesis/multi_controlled/__init__.py +24 -0
  565. qiskit/synthesis/multi_controlled/mcmt_vchain.py +52 -0
  566. qiskit/synthesis/multi_controlled/mcx_synthesis.py +356 -0
  567. qiskit/synthesis/one_qubit/__init__.py +15 -0
  568. qiskit/synthesis/one_qubit/one_qubit_decompose.py +288 -0
  569. qiskit/synthesis/permutation/__init__.py +18 -0
  570. qiskit/synthesis/permutation/permutation_full.py +78 -0
  571. qiskit/synthesis/permutation/permutation_lnn.py +54 -0
  572. qiskit/synthesis/permutation/permutation_reverse_lnn.py +93 -0
  573. qiskit/synthesis/permutation/permutation_utils.py +16 -0
  574. qiskit/synthesis/qft/__init__.py +16 -0
  575. qiskit/synthesis/qft/qft_decompose_full.py +97 -0
  576. qiskit/synthesis/qft/qft_decompose_lnn.py +79 -0
  577. qiskit/synthesis/stabilizer/__init__.py +16 -0
  578. qiskit/synthesis/stabilizer/stabilizer_circuit.py +149 -0
  579. qiskit/synthesis/stabilizer/stabilizer_decompose.py +194 -0
  580. qiskit/synthesis/two_qubit/__init__.py +19 -0
  581. qiskit/synthesis/two_qubit/local_invariance.py +63 -0
  582. qiskit/synthesis/two_qubit/two_qubit_decompose.py +700 -0
  583. qiskit/synthesis/two_qubit/xx_decompose/__init__.py +19 -0
  584. qiskit/synthesis/two_qubit/xx_decompose/circuits.py +300 -0
  585. qiskit/synthesis/two_qubit/xx_decompose/decomposer.py +324 -0
  586. qiskit/synthesis/two_qubit/xx_decompose/embodiments.py +163 -0
  587. qiskit/synthesis/two_qubit/xx_decompose/paths.py +412 -0
  588. qiskit/synthesis/two_qubit/xx_decompose/polytopes.py +262 -0
  589. qiskit/synthesis/two_qubit/xx_decompose/utilities.py +40 -0
  590. qiskit/synthesis/two_qubit/xx_decompose/weyl.py +133 -0
  591. qiskit/synthesis/unitary/__init__.py +13 -0
  592. qiskit/synthesis/unitary/aqc/__init__.py +177 -0
  593. qiskit/synthesis/unitary/aqc/approximate.py +116 -0
  594. qiskit/synthesis/unitary/aqc/aqc.py +175 -0
  595. qiskit/synthesis/unitary/aqc/cnot_structures.py +300 -0
  596. qiskit/synthesis/unitary/aqc/cnot_unit_circuit.py +103 -0
  597. qiskit/synthesis/unitary/aqc/cnot_unit_objective.py +299 -0
  598. qiskit/synthesis/unitary/aqc/elementary_operations.py +108 -0
  599. qiskit/synthesis/unitary/aqc/fast_gradient/__init__.py +164 -0
  600. qiskit/synthesis/unitary/aqc/fast_gradient/fast_grad_utils.py +237 -0
  601. qiskit/synthesis/unitary/aqc/fast_gradient/fast_gradient.py +226 -0
  602. qiskit/synthesis/unitary/aqc/fast_gradient/layer.py +370 -0
  603. qiskit/synthesis/unitary/aqc/fast_gradient/pmatrix.py +312 -0
  604. qiskit/synthesis/unitary/qsd.py +288 -0
  605. qiskit/transpiler/__init__.py +1290 -0
  606. qiskit/transpiler/basepasses.py +221 -0
  607. qiskit/transpiler/coupling.py +500 -0
  608. qiskit/transpiler/exceptions.py +59 -0
  609. qiskit/transpiler/instruction_durations.py +281 -0
  610. qiskit/transpiler/layout.py +737 -0
  611. qiskit/transpiler/passes/__init__.py +312 -0
  612. qiskit/transpiler/passes/analysis/__init__.py +23 -0
  613. qiskit/transpiler/passes/analysis/count_ops.py +30 -0
  614. qiskit/transpiler/passes/analysis/count_ops_longest_path.py +26 -0
  615. qiskit/transpiler/passes/analysis/dag_longest_path.py +24 -0
  616. qiskit/transpiler/passes/analysis/depth.py +33 -0
  617. qiskit/transpiler/passes/analysis/num_qubits.py +26 -0
  618. qiskit/transpiler/passes/analysis/num_tensor_factors.py +26 -0
  619. qiskit/transpiler/passes/analysis/resource_estimation.py +41 -0
  620. qiskit/transpiler/passes/analysis/size.py +36 -0
  621. qiskit/transpiler/passes/analysis/width.py +27 -0
  622. qiskit/transpiler/passes/basis/__init__.py +19 -0
  623. qiskit/transpiler/passes/basis/basis_translator.py +137 -0
  624. qiskit/transpiler/passes/basis/decompose.py +131 -0
  625. qiskit/transpiler/passes/basis/translate_parameterized.py +175 -0
  626. qiskit/transpiler/passes/basis/unroll_3q_or_more.py +88 -0
  627. qiskit/transpiler/passes/basis/unroll_custom_definitions.py +109 -0
  628. qiskit/transpiler/passes/calibration/__init__.py +17 -0
  629. qiskit/transpiler/passes/calibration/base_builder.py +79 -0
  630. qiskit/transpiler/passes/calibration/builders.py +20 -0
  631. qiskit/transpiler/passes/calibration/exceptions.py +22 -0
  632. qiskit/transpiler/passes/calibration/pulse_gate.py +100 -0
  633. qiskit/transpiler/passes/calibration/rx_builder.py +164 -0
  634. qiskit/transpiler/passes/calibration/rzx_builder.py +411 -0
  635. qiskit/transpiler/passes/calibration/rzx_templates.py +51 -0
  636. qiskit/transpiler/passes/layout/__init__.py +26 -0
  637. qiskit/transpiler/passes/layout/_csp_custom_solver.py +65 -0
  638. qiskit/transpiler/passes/layout/apply_layout.py +123 -0
  639. qiskit/transpiler/passes/layout/csp_layout.py +132 -0
  640. qiskit/transpiler/passes/layout/dense_layout.py +202 -0
  641. qiskit/transpiler/passes/layout/disjoint_utils.py +219 -0
  642. qiskit/transpiler/passes/layout/enlarge_with_ancilla.py +49 -0
  643. qiskit/transpiler/passes/layout/full_ancilla_allocation.py +117 -0
  644. qiskit/transpiler/passes/layout/layout_2q_distance.py +77 -0
  645. qiskit/transpiler/passes/layout/sabre_layout.py +487 -0
  646. qiskit/transpiler/passes/layout/sabre_pre_layout.py +225 -0
  647. qiskit/transpiler/passes/layout/set_layout.py +69 -0
  648. qiskit/transpiler/passes/layout/trivial_layout.py +66 -0
  649. qiskit/transpiler/passes/layout/vf2_layout.py +263 -0
  650. qiskit/transpiler/passes/layout/vf2_post_layout.py +419 -0
  651. qiskit/transpiler/passes/layout/vf2_utils.py +260 -0
  652. qiskit/transpiler/passes/optimization/__init__.py +43 -0
  653. qiskit/transpiler/passes/optimization/_gate_extension.py +80 -0
  654. qiskit/transpiler/passes/optimization/collect_1q_runs.py +31 -0
  655. qiskit/transpiler/passes/optimization/collect_2q_blocks.py +35 -0
  656. qiskit/transpiler/passes/optimization/collect_and_collapse.py +115 -0
  657. qiskit/transpiler/passes/optimization/collect_cliffords.py +104 -0
  658. qiskit/transpiler/passes/optimization/collect_linear_functions.py +80 -0
  659. qiskit/transpiler/passes/optimization/collect_multiqubit_blocks.py +227 -0
  660. qiskit/transpiler/passes/optimization/commutation_analysis.py +44 -0
  661. qiskit/transpiler/passes/optimization/commutative_cancellation.py +82 -0
  662. qiskit/transpiler/passes/optimization/commutative_inverse_cancellation.py +140 -0
  663. qiskit/transpiler/passes/optimization/consolidate_blocks.py +149 -0
  664. qiskit/transpiler/passes/optimization/cx_cancellation.py +65 -0
  665. qiskit/transpiler/passes/optimization/echo_rzx_weyl_decomposition.py +162 -0
  666. qiskit/transpiler/passes/optimization/elide_permutations.py +91 -0
  667. qiskit/transpiler/passes/optimization/hoare_opt.py +420 -0
  668. qiskit/transpiler/passes/optimization/inverse_cancellation.py +95 -0
  669. qiskit/transpiler/passes/optimization/normalize_rx_angle.py +149 -0
  670. qiskit/transpiler/passes/optimization/optimize_1q_commutation.py +268 -0
  671. qiskit/transpiler/passes/optimization/optimize_1q_decomposition.py +254 -0
  672. qiskit/transpiler/passes/optimization/optimize_1q_gates.py +384 -0
  673. qiskit/transpiler/passes/optimization/optimize_annotated.py +448 -0
  674. qiskit/transpiler/passes/optimization/optimize_cliffords.py +89 -0
  675. qiskit/transpiler/passes/optimization/optimize_swap_before_measure.py +71 -0
  676. qiskit/transpiler/passes/optimization/remove_diagonal_gates_before_measure.py +41 -0
  677. qiskit/transpiler/passes/optimization/remove_final_reset.py +37 -0
  678. qiskit/transpiler/passes/optimization/remove_identity_equiv.py +69 -0
  679. qiskit/transpiler/passes/optimization/remove_reset_in_zero_state.py +37 -0
  680. qiskit/transpiler/passes/optimization/reset_after_measure_simplification.py +47 -0
  681. qiskit/transpiler/passes/optimization/split_2q_unitaries.py +40 -0
  682. qiskit/transpiler/passes/optimization/template_matching/__init__.py +19 -0
  683. qiskit/transpiler/passes/optimization/template_matching/backward_match.py +749 -0
  684. qiskit/transpiler/passes/optimization/template_matching/forward_match.py +452 -0
  685. qiskit/transpiler/passes/optimization/template_matching/maximal_matches.py +77 -0
  686. qiskit/transpiler/passes/optimization/template_matching/template_matching.py +370 -0
  687. qiskit/transpiler/passes/optimization/template_matching/template_substitution.py +638 -0
  688. qiskit/transpiler/passes/optimization/template_optimization.py +158 -0
  689. qiskit/transpiler/passes/routing/__init__.py +22 -0
  690. qiskit/transpiler/passes/routing/algorithms/__init__.py +33 -0
  691. qiskit/transpiler/passes/routing/algorithms/token_swapper.py +105 -0
  692. qiskit/transpiler/passes/routing/algorithms/types.py +46 -0
  693. qiskit/transpiler/passes/routing/algorithms/util.py +103 -0
  694. qiskit/transpiler/passes/routing/basic_swap.py +166 -0
  695. qiskit/transpiler/passes/routing/commuting_2q_gate_routing/__init__.py +25 -0
  696. qiskit/transpiler/passes/routing/commuting_2q_gate_routing/commuting_2q_block.py +60 -0
  697. qiskit/transpiler/passes/routing/commuting_2q_gate_routing/commuting_2q_gate_router.py +395 -0
  698. qiskit/transpiler/passes/routing/commuting_2q_gate_routing/pauli_2q_evolution_commutation.py +145 -0
  699. qiskit/transpiler/passes/routing/commuting_2q_gate_routing/swap_strategy.py +306 -0
  700. qiskit/transpiler/passes/routing/layout_transformation.py +119 -0
  701. qiskit/transpiler/passes/routing/lookahead_swap.py +390 -0
  702. qiskit/transpiler/passes/routing/sabre_swap.py +447 -0
  703. qiskit/transpiler/passes/routing/star_prerouting.py +392 -0
  704. qiskit/transpiler/passes/routing/stochastic_swap.py +532 -0
  705. qiskit/transpiler/passes/routing/utils.py +35 -0
  706. qiskit/transpiler/passes/scheduling/__init__.py +27 -0
  707. qiskit/transpiler/passes/scheduling/alap.py +153 -0
  708. qiskit/transpiler/passes/scheduling/alignments/__init__.py +81 -0
  709. qiskit/transpiler/passes/scheduling/alignments/align_measures.py +255 -0
  710. qiskit/transpiler/passes/scheduling/alignments/check_durations.py +78 -0
  711. qiskit/transpiler/passes/scheduling/alignments/pulse_gate_validation.py +107 -0
  712. qiskit/transpiler/passes/scheduling/alignments/reschedule.py +250 -0
  713. qiskit/transpiler/passes/scheduling/asap.py +175 -0
  714. qiskit/transpiler/passes/scheduling/base_scheduler.py +310 -0
  715. qiskit/transpiler/passes/scheduling/dynamical_decoupling.py +312 -0
  716. qiskit/transpiler/passes/scheduling/padding/__init__.py +16 -0
  717. qiskit/transpiler/passes/scheduling/padding/base_padding.py +256 -0
  718. qiskit/transpiler/passes/scheduling/padding/dynamical_decoupling.py +452 -0
  719. qiskit/transpiler/passes/scheduling/padding/pad_delay.py +82 -0
  720. qiskit/transpiler/passes/scheduling/scheduling/__init__.py +17 -0
  721. qiskit/transpiler/passes/scheduling/scheduling/alap.py +127 -0
  722. qiskit/transpiler/passes/scheduling/scheduling/asap.py +131 -0
  723. qiskit/transpiler/passes/scheduling/scheduling/base_scheduler.py +94 -0
  724. qiskit/transpiler/passes/scheduling/scheduling/set_io_latency.py +64 -0
  725. qiskit/transpiler/passes/scheduling/time_unit_conversion.py +165 -0
  726. qiskit/transpiler/passes/synthesis/__init__.py +20 -0
  727. qiskit/transpiler/passes/synthesis/aqc_plugin.py +153 -0
  728. qiskit/transpiler/passes/synthesis/high_level_synthesis.py +854 -0
  729. qiskit/transpiler/passes/synthesis/hls_plugins.py +1559 -0
  730. qiskit/transpiler/passes/synthesis/linear_functions_synthesis.py +41 -0
  731. qiskit/transpiler/passes/synthesis/plugin.py +734 -0
  732. qiskit/transpiler/passes/synthesis/solovay_kitaev_synthesis.py +297 -0
  733. qiskit/transpiler/passes/synthesis/unitary_synthesis.py +1076 -0
  734. qiskit/transpiler/passes/utils/__init__.py +33 -0
  735. qiskit/transpiler/passes/utils/barrier_before_final_measurements.py +41 -0
  736. qiskit/transpiler/passes/utils/check_gate_direction.py +52 -0
  737. qiskit/transpiler/passes/utils/check_map.py +78 -0
  738. qiskit/transpiler/passes/utils/contains_instruction.py +45 -0
  739. qiskit/transpiler/passes/utils/control_flow.py +65 -0
  740. qiskit/transpiler/passes/utils/convert_conditions_to_if_ops.py +93 -0
  741. qiskit/transpiler/passes/utils/dag_fixed_point.py +36 -0
  742. qiskit/transpiler/passes/utils/error.py +69 -0
  743. qiskit/transpiler/passes/utils/filter_op_nodes.py +65 -0
  744. qiskit/transpiler/passes/utils/fixed_point.py +48 -0
  745. qiskit/transpiler/passes/utils/gate_direction.py +86 -0
  746. qiskit/transpiler/passes/utils/gates_basis.py +51 -0
  747. qiskit/transpiler/passes/utils/merge_adjacent_barriers.py +163 -0
  748. qiskit/transpiler/passes/utils/minimum_point.py +118 -0
  749. qiskit/transpiler/passes/utils/remove_barriers.py +49 -0
  750. qiskit/transpiler/passes/utils/remove_final_measurements.py +114 -0
  751. qiskit/transpiler/passes/utils/unroll_forloops.py +81 -0
  752. qiskit/transpiler/passmanager.py +490 -0
  753. qiskit/transpiler/passmanager_config.py +216 -0
  754. qiskit/transpiler/preset_passmanagers/__init__.py +73 -0
  755. qiskit/transpiler/preset_passmanagers/builtin_plugins.py +1045 -0
  756. qiskit/transpiler/preset_passmanagers/common.py +649 -0
  757. qiskit/transpiler/preset_passmanagers/generate_preset_pass_manager.py +626 -0
  758. qiskit/transpiler/preset_passmanagers/level0.py +113 -0
  759. qiskit/transpiler/preset_passmanagers/level1.py +120 -0
  760. qiskit/transpiler/preset_passmanagers/level2.py +119 -0
  761. qiskit/transpiler/preset_passmanagers/level3.py +119 -0
  762. qiskit/transpiler/preset_passmanagers/plugin.py +353 -0
  763. qiskit/transpiler/target.py +1319 -0
  764. qiskit/transpiler/timing_constraints.py +59 -0
  765. qiskit/user_config.py +262 -0
  766. qiskit/utils/__init__.py +89 -0
  767. qiskit/utils/classtools.py +146 -0
  768. qiskit/utils/deprecate_pulse.py +119 -0
  769. qiskit/utils/deprecation.py +490 -0
  770. qiskit/utils/lazy_tester.py +363 -0
  771. qiskit/utils/multiprocessing.py +56 -0
  772. qiskit/utils/optionals.py +347 -0
  773. qiskit/utils/parallel.py +191 -0
  774. qiskit/utils/units.py +143 -0
  775. qiskit/version.py +84 -0
  776. qiskit/visualization/__init__.py +288 -0
  777. qiskit/visualization/array.py +204 -0
  778. qiskit/visualization/bloch.py +778 -0
  779. qiskit/visualization/circuit/__init__.py +15 -0
  780. qiskit/visualization/circuit/_utils.py +675 -0
  781. qiskit/visualization/circuit/circuit_visualization.py +727 -0
  782. qiskit/visualization/circuit/latex.py +661 -0
  783. qiskit/visualization/circuit/matplotlib.py +2029 -0
  784. qiskit/visualization/circuit/qcstyle.py +278 -0
  785. qiskit/visualization/circuit/styles/__init__.py +13 -0
  786. qiskit/visualization/circuit/styles/bw.json +202 -0
  787. qiskit/visualization/circuit/styles/clifford.json +202 -0
  788. qiskit/visualization/circuit/styles/iqp-dark.json +214 -0
  789. qiskit/visualization/circuit/styles/iqp.json +214 -0
  790. qiskit/visualization/circuit/styles/textbook.json +202 -0
  791. qiskit/visualization/circuit/text.py +1844 -0
  792. qiskit/visualization/circuit_visualization.py +19 -0
  793. qiskit/visualization/counts_visualization.py +481 -0
  794. qiskit/visualization/dag_visualization.py +316 -0
  795. qiskit/visualization/exceptions.py +21 -0
  796. qiskit/visualization/gate_map.py +1485 -0
  797. qiskit/visualization/library.py +37 -0
  798. qiskit/visualization/pass_manager_visualization.py +308 -0
  799. qiskit/visualization/pulse_v2/__init__.py +21 -0
  800. qiskit/visualization/pulse_v2/core.py +901 -0
  801. qiskit/visualization/pulse_v2/device_info.py +173 -0
  802. qiskit/visualization/pulse_v2/drawings.py +253 -0
  803. qiskit/visualization/pulse_v2/events.py +254 -0
  804. qiskit/visualization/pulse_v2/generators/__init__.py +40 -0
  805. qiskit/visualization/pulse_v2/generators/barrier.py +76 -0
  806. qiskit/visualization/pulse_v2/generators/chart.py +208 -0
  807. qiskit/visualization/pulse_v2/generators/frame.py +436 -0
  808. qiskit/visualization/pulse_v2/generators/snapshot.py +133 -0
  809. qiskit/visualization/pulse_v2/generators/waveform.py +645 -0
  810. qiskit/visualization/pulse_v2/interface.py +458 -0
  811. qiskit/visualization/pulse_v2/layouts.py +387 -0
  812. qiskit/visualization/pulse_v2/plotters/__init__.py +17 -0
  813. qiskit/visualization/pulse_v2/plotters/base_plotter.py +53 -0
  814. qiskit/visualization/pulse_v2/plotters/matplotlib.py +201 -0
  815. qiskit/visualization/pulse_v2/stylesheet.py +312 -0
  816. qiskit/visualization/pulse_v2/types.py +242 -0
  817. qiskit/visualization/state_visualization.py +1518 -0
  818. qiskit/visualization/timeline/__init__.py +21 -0
  819. qiskit/visualization/timeline/core.py +480 -0
  820. qiskit/visualization/timeline/drawings.py +260 -0
  821. qiskit/visualization/timeline/generators.py +506 -0
  822. qiskit/visualization/timeline/interface.py +436 -0
  823. qiskit/visualization/timeline/layouts.py +115 -0
  824. qiskit/visualization/timeline/plotters/__init__.py +16 -0
  825. qiskit/visualization/timeline/plotters/base_plotter.py +58 -0
  826. qiskit/visualization/timeline/plotters/matplotlib.py +192 -0
  827. qiskit/visualization/timeline/stylesheet.py +301 -0
  828. qiskit/visualization/timeline/types.py +148 -0
  829. qiskit/visualization/transition_visualization.py +369 -0
  830. qiskit/visualization/utils.py +49 -0
  831. qiskit-1.3.0.dist-info/LICENSE.txt +203 -0
  832. qiskit-1.3.0.dist-info/METADATA +222 -0
  833. qiskit-1.3.0.dist-info/RECORD +836 -0
  834. qiskit-1.3.0.dist-info/WHEEL +5 -0
  835. qiskit-1.3.0.dist-info/entry_points.txt +76 -0
  836. qiskit-1.3.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,1313 @@
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
+ :include-source:
68
+
69
+ from qiskit import QuantumCircuit
70
+
71
+ # Create a circuit with a register of three qubits
72
+ circ = QuantumCircuit(3)
73
+ # H gate on qubit 0, putting this qubit in a superposition of |0> + |1>.
74
+ circ.h(0)
75
+ # A CX (CNOT) gate on control qubit 0 and target qubit 1 generating a Bell state.
76
+ circ.cx(0, 1)
77
+ # CX (CNOT) gate on control qubit 0 and target qubit 2 resulting in a GHZ state.
78
+ circ.cx(0, 2)
79
+ # Draw the circuit
80
+ circ.draw('mpl')
81
+
82
+
83
+ .. _circuit-definitions:
84
+
85
+ Circuit concepts and definitions
86
+ ================================
87
+
88
+ There is a lot of specialized terminology around quantum circuits. Much of this is common in
89
+ quantum-computing literature, while some is more specific to quantum software packages, and a small
90
+ amount specific to Qiskit. This is an alphabetical listing of some of the important concepts as a
91
+ quick reference, but does not go into detail of the foundational concepts. Consider using the `IBM
92
+ Quantum Learning platform <https://learning.quantum.ibm.com/>`_ if you want to start from the
93
+ beginning.
94
+
95
+ abstract circuit
96
+ A *circuit* defined in terms of abstract mathematical operations and *virtual qubits*. This is
97
+ typically how you think about quantum algorithms; an abstract circuit can be made up of
98
+ completely arbitrary unitary operations, measurements, and potentially *real-time classical
99
+ computation*, with no restrictions about which qubits can interact with each other.
100
+
101
+ You turn an abstract circuit into a *physical circuit* by using :ref:`Qiskit's transpilation
102
+ package <qiskit-transpiler>`.
103
+
104
+ ancilla qubit
105
+ An extra qubit that is used to help implement operations on other qubits, but whose final state
106
+ is not important for the program.
107
+
108
+ circuit
109
+ A computational routine the defines a single execution to be taken on a QPU. This can either be
110
+ an *abstract circuit* or a *physical circuit*.
111
+
112
+ clbit
113
+ A Qiskit-specific abbreviation meaning a single classical bit of data.
114
+
115
+ gate
116
+ A *unitary operation* on one or more qubits.
117
+
118
+ hardware qubit
119
+ The representation of a single qubit on a particular *QPU*. A hardware qubit has some physical
120
+ quantum-mechanical system backing it, such as superconducting circuits; unlike a *virtual
121
+ qubit*, it has particular coupling constraints and only certain gates can be applied to certain
122
+ groups of hardware qubits.
123
+
124
+ Qiskit does not distinguish *logical qubits* from any individual *physical qubits* when talking
125
+ about hardware qubits. A QPU may implement its hardware qubits as logical qubits, where each
126
+ hardware qubit comprises many physical qubits that are controlled and error-corrected opaquely
127
+ to Qiskit by the control electronics. More likely, for near-term applications, a QPU will be
128
+ directly exposing its physical qubits as the hardware qubits for Qiskit to reason about.
129
+
130
+ Both physical and logical qubits will have coupling constraints between them, only permit
131
+ certain quantum operations on them, and have scheduling concerns between them. Qiskit abstracts
132
+ these concerns together in the concept of hardware qubits. In the early days of quantum error
133
+ correction, particular backends may let you access their qubit resources either as high-level
134
+ logical qubits or as low-level physical qubits through Qiskit.
135
+
136
+ instruction set architecture (ISA)
137
+ The abstract model of which operations are available on which sets of *hardware qubits* on one
138
+ particular *QPU*. For example, one QPU may allow :math:`\sqrt X` and :math:`R_Z` operations on
139
+ all single hardware qubits, and :math:`CX` operations on certain pairs of hardware qubits.
140
+
141
+ logical qubit
142
+ A collection of several *physical qubits* that are controlled together by a QPU (from the user's
143
+ perspective) to apply real-time quantum error correction. A logical qubit is a type of
144
+ *hardware qubit* for Qiskit.
145
+
146
+ measurement
147
+ The act of extracting one classical bit of a data from a single qubit state. This is an
148
+ irreversible operation, and usually destroys entanglement and phase coherence between the target
149
+ qubit and the rest of the system.
150
+
151
+ physical circuit
152
+ A *circuit* defined in terms of *hardware qubits* and only the quantum operations available in a
153
+ particular *QPU's* *ISA*. Physical circuits are tied to one particular QPU architecture, and
154
+ will not run on other incompatible architectures. You may also hear this referred to as an *ISA
155
+ circuit*.
156
+
157
+ You typically get a physical circuit by using :ref:`Qiskit's transpilation routines
158
+ <qiskit-transpiler>` on an *abstract circuit* that you constructed.
159
+
160
+ physical qubit
161
+ A controllable two-level quantum system. This is literally one "physics" qubit, such as a
162
+ transmon or the electronic state of a trapped ion. A QPU may expose this directly as its
163
+ *hardware qubit*, or combine several physical qubits into a *logical qubit*.
164
+
165
+ quantum processing unit (QPU)
166
+ Analogous to a CPU in classical computing or a GPU in graphics processing, a QPU is the hardware
167
+ that runs quantum operations on quantum data. You can always expect a QPU that uses the
168
+ *circuit* model of computation to be able to perform some set of *gates*, and *measurement*
169
+ operations. Depending on the particular technology, they also may be able to run some real-time
170
+ classical computations as well, such as classical control flow and bitwise calculations on
171
+ classical data.
172
+
173
+ qubit
174
+ The basic unit of quantum information.
175
+
176
+ real-time classical computation
177
+ Any classical computation that can happen within the execution of a single shot of a *circuit*,
178
+ where the results of the classical computation can affect later execution of the circuit. The
179
+ amount of real-time classical computation available with particular *QPU*\ s will vary
180
+ significantly dependent on many factors, such as the controlling electronics and the qubit
181
+ technology in use. You should consult your hardware vendor's documentation for more information
182
+ on this.
183
+
184
+ unitary operation
185
+ A reversible operation on a quantum state. All quantum *gates* are unitary operations (by
186
+ definition).
187
+
188
+ virtual qubit
189
+ An abstract, mathematical *qubit* used to build an *abstract circuit*. Virtual qubits are how
190
+ one typically thinks about quantum algorithms at a high level; we assume that all quantum gates
191
+ are valid on all virtual qubits, and all virtual qubits are always connected to every other
192
+ virtual qubit.
193
+
194
+ When mapping to hardware, virtual qubits must be assigned to *hardware qubits*. This mapping
195
+ need not be one-to-one. Typically, one virtual qubit will need to be swapped from one hardware
196
+ qubit to another over the course of a circuit execution in order to satisfy coupling constraints
197
+ of the underlying QPU. It is not strictly necessary for all virtual qubits used in a circuit to
198
+ be mapped to a physical qubit at any given point in a *physical circuit*; it could be that a
199
+ virtual qubit is measured (collapsing its state) and then never used again, so a new virtual
200
+ qubit could take its place. Evaluating these conditions to map a virtual circuit to a physical
201
+ circuit is the job of :ref:`Qiskit's transpilation package <qiskit-transpiler>`.
202
+
203
+
204
+ .. _circuit-module-api:
205
+
206
+ API overview of qiskit.circuit
207
+ ==============================
208
+
209
+ All objects here are described in more detail, and in their greater context in the following
210
+ sections. This section provides an overview of the API elements documented here.
211
+
212
+ ..
213
+ TODO: actually write the "in-depth section on building circuits and cross-ref to it.
214
+
215
+ The principal class is :class:`.QuantumCircuit`, which has its own documentation page, including
216
+ an in-depth section on building circuits. Quantum data and the simplest classical data are
217
+ represented by "bits" and "registers":
218
+
219
+ * :class:`Bit`, an atom of data
220
+ * :class:`Qubit`
221
+ * :class:`Clbit`
222
+ * :class:`AncillaQubit`
223
+
224
+ * :class:`Register`, a collection of bits
225
+ * :class:`QuantumRegister`
226
+ * :class:`ClassicalRegister`
227
+ * :class:`AncillaRegister`
228
+
229
+ Within a circuit, each complete :class:`CircuitInstruction` is made up of an :class:`Operation`
230
+ (which might be an :class:`Instruction`, a :class:`Gate`, or some other subclass) and the qubit
231
+ and clbit operands. The core base classes here are:
232
+
233
+ * :class:`CircuitInstruction`, an operation and its operands
234
+ * :class:`InstructionSet`, a temporary handle to a slice of circuit data
235
+ * :class:`Operation`, any abstract mathematical object or hardware instruction
236
+ * :class:`AnnotatedOperation`, a subclass with applied abstract modifiers
237
+ * :class:`InverseModifier`
238
+ * :class:`ControlModifier`
239
+ * :class:`PowerModifier`
240
+
241
+ The most common concrete subclass of the minimal, abstract :class:`Operation` interface is the
242
+ :class:`Instruction`. While :class:`Operation` can include abstract mathematical objects,
243
+ an :class:`Instruction` is something that could conceivably run directly on hardware. This is in
244
+ turn subclassed by :class:`Gate` and :class:`ControlledGate` that further add unitarity and
245
+ controlled semantics on top:
246
+
247
+ * :class:`Instruction`, representing a hardware-based instruction
248
+ * :class:`Gate`, representing a hardware instruction that is unitary
249
+ * :class:`ControlledGate`, representing a gate with control structure.
250
+
251
+ Qiskit includes a large library of standard gates and circuits, which is documented in
252
+ :mod:`qiskit.circuit.library`. Many of these are declared as Python-object singletons. The
253
+ machinery for this is described in detail in :mod:`qiskit.circuit.singleton`, of which the main
254
+ classes are each a singleton form of the standard instruction–gate hierarchy:
255
+
256
+ * :class:`~singleton.SingletonInstruction`
257
+ * :class:`~singleton.SingletonGate`
258
+ * :class:`~singleton.SingletonControlledGate`
259
+
260
+ Some instructions are particularly special in that they affect the control flow or data flow of the
261
+ circuit. The top-level ones are:
262
+
263
+ * :class:`Barrier`, to mark parts of the circuit that should be optimized independently
264
+ * :class:`Delay`, to insert a real-time wait period
265
+ * :class:`Measure`, to measure a :class:`Qubit` into a :class:`Clbit`
266
+ * :class:`Reset`, to irreversibly reset a qubit to the :math:`\lvert0\rangle` state
267
+ * :class:`Store`, to write a real-time classical expression to a storage location
268
+ * :class:`ControlFlowOp`, which has specific subclasses:
269
+ * :class:`BreakLoopOp`, to break out of the nearest containing loop
270
+ * :class:`ContinueLoopOp`, to move immediately to the next iteration of the containing loop
271
+ * :class:`ForLoopOp`, to loop over a fixed range of values
272
+ * :class:`IfElseOp`, to conditionally enter one of two subcircuits
273
+ * :class:`SwitchCaseOp`, to conditionally enter one of many subcircuits
274
+ * :class:`WhileLoopOp`, to repeat a subcircuit until a condition is falsified.
275
+
276
+ :ref:`Circuits can include classical expressions that are evaluated in real time
277
+ <circuit-repr-real-time-classical>`, while the QPU is executing a single shot of the circuit. These
278
+ are primarily documented in the module documentation of :mod:`qiskit.circuit.classical`. You might
279
+ be particularly interested in the base classes (which are not exposed from the :mod:`qiskit.circuit`
280
+ root):
281
+
282
+ * :class:`~classical.expr.Var`, a typed classical storage location in a circuit
283
+ * :class:`~classical.expr.Expr`, a real-time-evaluated expression
284
+ * :class:`~classical.types.Type`, the classical type of an expression.
285
+
286
+ In addition to this real-time expression evaluation, which is limited by classical hardware
287
+ representations of data, Qiskit has the concept of "compile-time" parametrization, which is done in
288
+ abstract symbolic algebra. These are typically used to represent gate angles in high-level
289
+ algorithms that might want to perform numerical derivatives, but they are an older part of Qiskit
290
+ than the real-time evaluation, so are still used in some places to do general parametrization. The
291
+ main related classes are:
292
+
293
+ * :class:`Parameter`, the atom of compile-time expressions
294
+ * :class:`ParameterExpression`, a symbolic calculation on parameters
295
+ * :class:`ParameterVector`, a convenience collection of many :class:`Parameter`\ s
296
+
297
+ The :mod:`qiskit.circuit` module also exposes some calculation classes that work with circuits to
298
+ assist compilation workflows. These include:
299
+
300
+ * :class:`EquivalenceLibrary`, a database of decomposition relations between gates and circuits
301
+ * :data:`SessionEquivalenceLibrary`, a mutable instance of :class:`EquivalenceLibrary` which is used
302
+ by default by the compiler's :class:`.BasisTranslator`.
303
+
304
+ There is also a utility for generating random circuits:
305
+
306
+ * :func:`random.random_circuit`
307
+
308
+ Finally, the circuit module has its own exception class, to indicate when things went wrong in
309
+ circuit-specific manners:
310
+
311
+ * :exc:`CircuitError`
312
+
313
+
314
+ .. _circuit-repr:
315
+
316
+ Representation of circuits in Qiskit
317
+ ====================================
318
+
319
+ The main user-facing class for representing circuits is :class:`QuantumCircuit`. This can be either
320
+ an abstract circuit or a physical circuit. There is much more information about the
321
+ :class:`QuantumCircuit` class itself and the multitude of available methods on it in its class
322
+ documentation.
323
+
324
+ Internally, a :class:`QuantumCircuit` contains the qubits, classical bits, compile-time parameters,
325
+ real-time variables, and other tracking information about the data it acts on and how it is
326
+ parametrized. It then contains a sequence of :class:`CircuitInstruction`\ s, which contain
327
+ the particular operation (gate, measurement, etc) and its operands (the qubits and classical bits).
328
+
329
+
330
+ Bits and registers
331
+ ------------------
332
+
333
+ Qubits and classical bits are represented by a shared base :class:`Bit` type, which is just intended
334
+ to be a "type tag"; the classes have no behavior other than being immutable objects:
335
+
336
+ .. autoclass:: Bit
337
+ .. autoclass:: Qubit
338
+ :show-inheritance:
339
+ :class-doc-from: class
340
+ .. autoclass:: Clbit
341
+ :show-inheritance:
342
+ :class-doc-from: class
343
+
344
+ Qubits and clbits are instantiated by users with no arguments, such as by ``Qubit()``. Bits compare
345
+ equal if they are the same Python object, or if they were both created by a register of the same
346
+ name and size, and they refer to the same index within that register. There is also a special type
347
+ tag for "ancilla" qubits, but this is little used in the current state
348
+ of Qiskit:
349
+
350
+ .. autoclass:: AncillaQubit
351
+ :show-inheritance:
352
+ :class-doc-from: class
353
+
354
+ A collection bits of the same type can be encapsulated in a register of the matching type. The base
355
+ functionality is in a base class that is not directly instantiated:
356
+
357
+ .. autoclass:: Register
358
+ :members:
359
+
360
+ Each of the defined bit subtypes has an associated register, which have the same constructor
361
+ signatures, methods and properties as the base class:
362
+
363
+ .. autoclass:: QuantumRegister
364
+ :show-inheritance:
365
+ :class-doc-from: class
366
+ .. autoclass:: ClassicalRegister
367
+ :show-inheritance:
368
+ :class-doc-from: class
369
+ .. autoclass:: AncillaRegister
370
+ :show-inheritance:
371
+ :class-doc-from: class
372
+
373
+ A common way to instantiate several bits at once is to create a register, such as by
374
+ ``QuantumRegister("my_qreg", 5)``. This has the advantage that you can give that collection of bits
375
+ a name, which will appear during circuit visualizations (:meth:`QuantumCircuit.draw`) and exports to
376
+ interchange languages (see :mod:`.qasm2` and :mod:`.qasm3`). You can also pass a name and a list of
377
+ pre-constructed bits, but this creates an "aliasing register", which are very poorly supported on
378
+ hardware.
379
+
380
+ Circuits track registers, but registers themselves impart almost no behavioral differences on
381
+ circuits. The only exception is that :class:`ClassicalRegister`\ s can be implicitly cast to
382
+ unsigned integers for use in conditional comparisons of :ref:`control flow operations
383
+ <circuit-control-flow-repr>`.
384
+
385
+ Classical registers and bits were the original way of representing classical data in Qiskit, and
386
+ remain the most supported currently. Longer term, the data model is moving towards a more complete
387
+ and strongly typed representation of a range of classical data (see
388
+ :ref:`circuit-repr-real-time-classical`), but you will still very commonly use classical bits in
389
+ current Qiskit.
390
+
391
+
392
+ Instruction contexts
393
+ --------------------
394
+
395
+ The scalar type of the :attr:`QuantumCircuit.data` sequence is the "instruction context" object,
396
+ :class:`CircuitInstruction`. This is essentially just a data class that contains a representation
397
+ of what is to be done (its :attr:`~CircuitInstruction.operation`), and the data it acts on (the
398
+ :attr:`~CircuitInstruction.qubits` and :attr:`~CircuitInstruction.clbits`).
399
+
400
+ .. autosummary::
401
+ :toctree: ../stubs/
402
+
403
+ CircuitInstruction
404
+
405
+ Programmatically, this class is actually implemented in Rust and is a constructed handle to internal
406
+ data within Rust space. Mutations to instances of this class will not be reflected in the circuit.
407
+ In general, you cannot mutate instruction contexts that are already in the circuit directly; the
408
+ :class:`QuantumCircuit` interface is designed for storing and building circuits, while the
409
+ :ref:`transpiler and its passes <qiskit-transpiler>`, and its intermediate :class:`.DAGCircuit`
410
+ representation, are where you should look for an interface to mutate circuits.
411
+
412
+ The :class:`QuantumCircuit` methods that add instructions to circuits (such as
413
+ :meth:`~QuantumCircuit.append`, and all the helper standard-gate methods) return an
414
+ :class:`InstructionSet`, which is a handle to several :class:`CircuitInstruction`\ s simultaneously.
415
+
416
+ .. autosummary::
417
+ :toctree: ../stubs/
418
+
419
+ InstructionSet
420
+
421
+ This :class:`InstructionSet` is now little used in Qiskit. It provides a very minimal set of
422
+ methods to perform post-append mutations on instructions (which *will* be propagated to the
423
+ circuit), but these are now discouraged and you should use the alternatives noted in those methods.
424
+
425
+
426
+ .. _circuit-operations-instructions:
427
+
428
+ Operations, instructions and gates
429
+ ----------------------------------
430
+
431
+ Within a :class:`CircuitInstruction`, the minimal interface that any operation must fulfill is
432
+ :class:`Operation`. This is a *very* high level view, and only usable for abstract circuits. The
433
+ main purpose of treating operations as :class:`Operation` is to allow arbitrary mathematical
434
+ objects (such as :class:`.quantum_info.Operator`) to be added to abstract circuits directly.
435
+
436
+ .. autosummary::
437
+ :toctree: ../stubs/
438
+
439
+ Operation
440
+
441
+ Most operations, including all operations on physical circuits, are instances of the more concretely
442
+ defined :class:`Instruction`. This represents any instruction that some QPU might be able to carry
443
+ out natively, such as :class:`Measure`. :class:`Instruction` need not be unitary (much as
444
+ :class:`Measure` isn't); an instruction is specifically unitary if it is a :class:`Gate`.
445
+
446
+ .. autosummary::
447
+ :toctree: ../stubs/
448
+
449
+ Instruction
450
+
451
+ :class:`Instruction`\ s can be near arbitrary, provided they only act on :class:`Qubit`\ s and
452
+ :class:`Clbit`\ s, and are parametrized by their :attr:`~Instruction.params`; they should not
453
+ attempt to "close over" outer circuit registers, or use hidden parameters inside themselves.
454
+ :class:`Instruction`\ s can be related to other circuits to provide a decompositions by using
455
+ their :attr:`Instruction.definition` attribute, which provides a local, one-off decomposition. This
456
+ can be in whatever basis set of operations is most convenient to you, as long as the definitions of
457
+ all contained gates have some topological order; that is, you cannot use a gate in a definition if
458
+ its own definition depends on the parent. If the :class:`Instruction` should be considered entirely
459
+ opaque to optimizers, its :attr:`~Instruction.definition` can be ``None``. See
460
+ :ref:`circuit-custom-gates` for more detail.
461
+
462
+ The :attr:`~Instruction.params` of an instruction can technically be arbitrary, but in general you
463
+ should attempt to stick to parametrizations in terms of real numbers, wherever possible. Qiskit
464
+ itself breaks this rule in many places, and you will find all sorts of unusual types in
465
+ :attr:`Instruction.params` fields, but these are an annoying source of bugs because they often imply
466
+ the need for type-aware special casing. If your instruction is parametrized in terms of angles, you
467
+ will be able to reliably use :ref:`compile-time parametrization in it
468
+ <circuit-compile-time-parameters>`, and it will integrate well with
469
+ :meth:`QuantumCircuit.assign_parameters`.
470
+
471
+ While :class:`Instruction` is not necessarily unitary, its subclass :class:`Gate` implies unitarity,
472
+ and adds :meth:`~Gate.to_matrix` and :meth:`~Gate.control` methods to all the methods inherited from
473
+ :class:`Instruction`.
474
+
475
+ .. autosummary::
476
+ :toctree: ../stubs/
477
+
478
+ Gate
479
+
480
+ :class:`Gate` inherits all the methods for :class:`Instruction` and all the same considerations
481
+ about its :attr:`~Instruction.params` and :attr:`~Instruction.definition` field, except of course
482
+ that :class:`Gate`\ s cannot act on any classical resources.
483
+
484
+ :class:`Gate` instances can (and should) have a base :attr:`~Instruction.definition`, but you can
485
+ also specify several different decompositions in different bases by using an
486
+ :class:`EquivalenceLibrary`.
487
+
488
+ Subclassing :class:`Gate`, Qiskit has a special :class:`ControlledGate` class as well. This class
489
+ is the base of many standard-library gates that are controlled (such as :class:`CXGate`), which is
490
+ where you are most likely to encounter it:
491
+
492
+ .. autosummary::
493
+ :toctree: ../stubs/
494
+
495
+ ControlledGate
496
+
497
+ Each of :class:`Instruction`, :class:`Gate` and :class:`ControlledGate` has a corresponding
498
+ singleton type, built using the machinery described in :mod:`qiskit.circuit.singleton`. The
499
+ module-level documentation contains full details, along with descriptions of
500
+ :class:`.SingletonInstruction`, :class:`.SingletonGate` and :class:`.SingletonControlledGate`. From
501
+ a user's perspective, little changes based on whether the base class is a singleton or not; the
502
+ intention always remains that you should call :meth:`~Instruction.to_mutable` first if you need to
503
+ get a safe-to-mutate owned copy of an instruction (you cannot assume that an arbitrary instruction
504
+ is mutable), and while direct :class:`type` inspection is discouraged, if you do need it, the
505
+ reliable way to find the "base" type of a potentially singleton instruction is to use
506
+ :attr:`~Instruction.base_class`.
507
+
508
+ :class:`ControlledGate` uses the same mechanisms as :ref:`subclassing gates <circuit-custom-gates>`
509
+ to define a fixed, lazy synthesis for itself. This is naturally not hardware-aware, and harder to
510
+ hook into the synthesis routines of the compiler, but works better as a concrete
511
+ :class:`Instruction` that could potentially be run natively on hardware. For cases where synthesis
512
+ and abstract optimization is more important, Qiskit offers a composable class called
513
+ :class:`AnnotatedOperation`, which tracks "gate modifiers" (of which :class:`ControlModifier` is
514
+ one) to apply to the inner :attr:`~AnnotatedOperation.base_op`.
515
+
516
+ .. autosummary::
517
+ :toctree: ../stubs/
518
+
519
+ AnnotatedOperation
520
+
521
+ The available modifiers for :class:`AnnotatedOperation` are:
522
+
523
+ .. autoclass:: InverseModifier
524
+ .. autoclass:: ControlModifier
525
+ .. autoclass:: PowerModifier
526
+
527
+ For information on how to create custom gates and instructions, including how to build one-off
528
+ objects, and re-usable parametric gates via subclassing, see :ref:`circuit-custom-gates` below.
529
+ The Qiskit circuit library in :mod:`qiskit.circuit.library` contains many predefined gates and
530
+ circuits for you to use.
531
+
532
+
533
+ Built-in special instructions
534
+ -----------------------------
535
+
536
+ Qiskit contains a few :class:`Instruction` classes that are in some ways "special". These typically
537
+ have special handling in circuit code, in the transpiler, or the models of hardware. These are all
538
+ generally instructions you might already be familiar with.
539
+
540
+ Measurements in Qiskit are of a single :class:`Qubit` into a single :class:`Clbit`. These are the
541
+ two that the instruction is applied to. Measurements are in the computational basis.
542
+
543
+ .. autoclass:: Measure(label=None)
544
+ :show-inheritance:
545
+
546
+ Related to measurements, there is a :class:`Reset` operation, which produces no classical data but
547
+ instructs hardware to return the qubit to the :math:`\lvert0\rangle` state. This is assumed to
548
+ happen incoherently and to collapse any entanglement.
549
+
550
+ .. autoclass:: Reset(label=None)
551
+ :show-inheritance:
552
+
553
+ Hardware can be instructed to apply a real-time idle period on a given qubit. A scheduled circuit
554
+ (see :mod:`qiskit.transpiler`) will include all the idle times on qubits explicitly in terms of this
555
+ :class:`Delay`.
556
+
557
+ .. autoclass:: Delay
558
+ :show-inheritance:
559
+
560
+ The :class:`Barrier` instruction can span an arbitrary number of qubits and clbits, and is a no-op
561
+ in hardware. During transpilation and optimization, however, it blocks any optimizations from
562
+ "crossing" the barrier; that is, in::
563
+
564
+ from qiskit.circuit import QuantumCircuit
565
+
566
+ qc = QuantumCircuit(1)
567
+ qc.x(0)
568
+ qc.barrier()
569
+ qc.x(0)
570
+
571
+ it is forbidden for the optimizer to cancel out the two :math:`X` instructions.
572
+
573
+ .. autoclass:: Barrier
574
+ :show-inheritance:
575
+
576
+ The :class:`Store` instruction is particularly special, in that it allows writing the result of a
577
+ :ref:`real-time classical computation expression <circuit-repr-real-time-classical>` (an
578
+ :class:`.expr.Expr`) in a local classical variable (a :class:`.expr.Var`). It takes *neither*
579
+ :class:`Qubit` nor :class:`Clbit` operands, but has an explicit :attr:`~Store.lvalue` and
580
+ :attr:`~Store.rvalue`.
581
+
582
+ For example, to determine the parity of a bitstring ``cr`` and store it in another register ``creg``,
583
+ the :class:`Store` instruction can be used in the following way::
584
+
585
+ parity = expr.lift(cr[0])
586
+ for i in range(1,n):
587
+ parity = expr.bit_xor(cr[i], parity)
588
+ qc.store(creg[0], parity)
589
+
590
+
591
+
592
+ .. autoclass:: Store
593
+ :show-inheritance:
594
+ :members:
595
+ :no-inherited-members:
596
+
597
+
598
+ .. _circuit-repr-real-time-classical:
599
+
600
+ Real-time classical computation
601
+ -------------------------------
602
+
603
+ .. seealso::
604
+ :mod:`qiskit.circuit.classical`
605
+ Module-level documentation for how the variable-, expression- and type-systems work, the
606
+ objects used to represent them, and the classical operations available.
607
+
608
+ :ref:`circuit-real-time-methods`
609
+ The :class:`QuantumCircuit` methods for working with these variables in the context of a
610
+ single circuit.
611
+
612
+ Qiskit has rudimentary low-level support for representing real-time classical computations, which
613
+ happen during the QPU execution and affect the results. We are still relatively early into hardware
614
+ support for these concepts as well, so beware that you will need to work closely with your hardware
615
+ provider's documentation to get the best use out of any real-time classical computation.
616
+
617
+ These real-time calculations are represented by the expression and type system in
618
+ :mod:`qiskit.circuit.classical`. At a high level, all real-time expressions are represented by an
619
+ :class:`.Expr` node, which is part of an expression "tree" representation, which has a well-defined
620
+ :class:`~.classical.Type` associated with it at every level. See the module-level documentation for
621
+ much more detail on the internal representations of these classes.
622
+
623
+ The result of a real-time :class:`.Expr` can be used directly in certain places. Currently this is
624
+ limited to conditions of :class:`.IfElseOp` and :class:`.WhileLoopOp`, and the target of
625
+ :class:`.SwitchCaseOp`. The result can also be stored in a typed classical storage location, using
626
+ the :class:`.Store` instruction (or its :meth:`QuantumCircuit.store` constructor), backed by a
627
+ :class:`.expr.Var` node.
628
+
629
+ A circuit can contain manual classical storage locations, represented internally by the
630
+ :class:`~.expr.Var` node of the :class:`.Expr` tree. These have an attached classical type (like
631
+ any other expression). These can either be declared and initialized within each execution of the
632
+ circuit (:meth:`~QuantumCircuit.add_var`), or be inputs to the circuit
633
+ (:meth:`~QuantumCircuit.add_input`).
634
+
635
+ .. _circuit-compile-time-parameters:
636
+
637
+ Compile-time parametrization
638
+ ----------------------------
639
+
640
+ Various parametric :class:`Instruction` instances in Qiskit can be parametrized in ways that are
641
+ designed to be resolved at compile time. These are characterized by the use of the
642
+ :class:`Parameter` and :class:`ParameterExpression` classes.
643
+
644
+ .. autosummary::
645
+ :toctree: ../stubs/
646
+
647
+ Parameter
648
+ ParameterExpression
649
+
650
+ The main way that this differs from the :class:`expr.Var` variables used in real-time classical
651
+ computation is that :class:`ParameterExpression` is a symbolic representation of a mathematical
652
+ expression. The semantics of the expression are those of regular mathematics over the continuous
653
+ real numbers (and, in limited cases, over the complex numbers). In contrast, :class:`.Var` is a
654
+ handle to a variable stored on a classical computer, such as a floating-point value or an
655
+ fixed-width integer, which are always discrete.
656
+
657
+ In other words, you can expect :class:`ParameterExpression` to do symbolic simplifications that are
658
+ valid in mathematics, such as simplifying :math:`(x + y - x) / y \to 1`. Such a simplification is
659
+ not valid in floating-point arithmetic, and :class:`.expr.Expr` will not do this.
660
+
661
+ The "compile-time" part of these parameters means that you typically will want to "assign" values to
662
+ the parameters before sending the circuit for execution. These parameters can typically be used
663
+ anywhere that expects a mathematical angle (like a rotation gate's parameters), with the caveat that
664
+ hardware will usually require them to be assigned to a proper classically typed value before
665
+ execution. You can do this assignment using :meth:`QuantumCircuit.assign_parameters`.
666
+
667
+ You may want to use many parameters that are related to each other. To make this easier (and to
668
+ avoid you needing to come up with many names), you can use the convenience constructor
669
+ :class:`ParameterVector`. The elements of the vector are all valid :class:`Parameter` instances.
670
+
671
+ .. autosummary::
672
+ :toctree: ../stubs/
673
+
674
+ ParameterVector
675
+
676
+ .. _circuit-control-flow-repr:
677
+
678
+ Control flow in circuits
679
+ ------------------------
680
+
681
+ Within :class:`QuantumCircuit`, classical control flow is represented by specific
682
+ :class:`Instruction`\ s, which are subclasses of :class:`ControlFlowOp`.
683
+
684
+ .. autosummary::
685
+ :toctree: ../stubs/
686
+
687
+ ControlFlowOp
688
+
689
+ For convenience, there is a :class:`frozenset` instance containing the :attr:`.Instruction.name`
690
+ attributes of each of the control-flow operations.
691
+
692
+ .. data:: CONTROL_FLOW_OP_NAMES
693
+
694
+ Set of the instruction names of Qiskit's known control-flow operations.
695
+
696
+ These control-flow operations (:class:`IfElseOp`, :class:`WhileLoopOp`,
697
+ :class:`SwitchCaseOp` and :class:`ForLoopOp`) all have specific state that defines the branching
698
+ conditions and strategies, but contain all the different subcircuit blocks that might be entered in
699
+ their :attr:`~ControlFlowOp.blocks` property.
700
+
701
+ .. autosummary::
702
+ :toctree: ../stubs/
703
+
704
+ IfElseOp
705
+ WhileLoopOp
706
+ SwitchCaseOp
707
+ ForLoopOp
708
+
709
+ The :class:`.SwitchCaseOp` also understands a special value:
710
+
711
+ .. autodata:: CASE_DEFAULT
712
+
713
+ In addition to the block-structure control-flow operations, there are also two special instructions
714
+ that affect the flow of control when within loops. These correspond to typical uses of the
715
+ ``break`` and ``continue`` statements in classical programming languages.
716
+
717
+ .. autosummary::
718
+ :toctree: ../stubs/
719
+
720
+ BreakLoopOp
721
+ ContinueLoopOp
722
+
723
+ .. note::
724
+ The classes representations are documented here, but please note that manually constructing
725
+ these classes is a low-level operation that we do not expect users to need to do frequently.
726
+
727
+ Users should read :ref:`circuit-control-flow-methods` for the recommended workflows for building
728
+ control-flow-enabled circuits.
729
+
730
+ Since :class:`ControlFlowOp` subclasses are also :class:`Instruction` subclasses, this means that
731
+ the way they are stored in :class:`CircuitInstruction` instances has them "applied" to a sequence of
732
+ qubits and clbits in its :attr:`~CircuitInstruction.qubits` and :attr:`~CircuitInstruction.clbits`
733
+ attributes. This can lead to subtle data-coherence problems: the :class:`Qubit` and :class:`Clbit`
734
+ objects used inside the subcircuit blocks of the control-flow ops will not necessarily be identical
735
+ to the corresponding objects in the :class:`CircuitInstruction`. Any code that consumes
736
+ control-flow operations in Qiskit needs to be aware of this; within a subcircuit, you should treat
737
+ ``subcircuit.qubits[i]`` as if it were really ``outer_instruction.qubits[i]``, and so on. You can
738
+ generate an easy lookup table for this by doing::
739
+
740
+ cf_instruction: CircuitInstruction = ...
741
+ cf_operation: ControlFlowOp = cf_instruction.operation
742
+ for block in blocks:
743
+ # Mappings of "inner" qubits/clbits to the outer ones.
744
+ qubit_map = dict(zip(block.qubits, cf_instruction.qubits))
745
+ clbit_map = dict(zip(block.clbits, cf_instruction.clbits))
746
+
747
+ # ... do something with `block` ...
748
+
749
+ Remember that you will need to propagate this information if you recurse into subblocks of
750
+ control-flow operations.
751
+
752
+ ..
753
+ TODO: insert cross-ref to control-flow builder guide into below paragraph once written.
754
+
755
+ All the subcircuit blocks in a :class:`ControlFlowOp` are required to contain the same numbers of
756
+ :class:`Qubit`\ s and :class:`Clbit`\ s, referring to the same outer bits in the same order, such
757
+ that the :class:`zip` loop given in the code block above works. The inner-circuit :class:`Bit`
758
+ objects do not need to be literally the same objects. When using the control-flow builder interface
759
+ (which, it cannot be stressed enough, is *highly* recommended for users), the builders will arrange
760
+ that the inner bit objects *are* identical to the outer bit objects; the ``qubit_map`` in the code
761
+ block above will always be a mapping ``{x: x}``, but if you are consuming the blocks, you should be
762
+ prepared for the case that the mapping is required.
763
+
764
+ Any :class:`ClassicalRegister`\ s used in a control-flow subcircuit must also be present in all
765
+ containing blocks (*i.e.* any containing control-flow operations, and the outermost circuit), and
766
+ all blocks in the same :class:`ControlFlowOp` need to contain the same registers. Again, the
767
+ builder interface will arrange for this to be the case (or produce an eager error if they cannot).
768
+
769
+ When the low-level construction is being used the inner :class:`QuantumCircuit` blocks must
770
+ manually close over any outer-scope :ref:`real-time classical computation variables
771
+ <circuit-repr-real-time-classical>` that they use. This is marked by these being in the
772
+ :meth:`~QuantumCircuit.iter_captured_vars` iterator for that block. Libraries constructing these
773
+ blocks manually will need to track these captures when building control-flow circuit blocks and add
774
+ them to the block using :meth:`~QuantumCircuit.add_capture` (or the ``captures`` constructor
775
+ argument), but user code will typically use the control-flow builder interface, which handles this
776
+ automatically.
777
+
778
+ Consult :ref:`the control-flow construction documentation <circuit-control-flow-methods>` for more
779
+ information on how to build circuits with control flow.
780
+
781
+ Investigating commutation relations
782
+ -----------------------------------
783
+
784
+ If two operations in a circuit commute, we can swap the order in which they are applied.
785
+ This can allow for optimizations and simplifications, for example, if it allows to merge
786
+ or cancel gates:
787
+
788
+ .. code-block:: text
789
+
790
+ ┌─────────┐ ┌─────────┐ ┌─────────┐
791
+ q_0: ┤ Rz(0.5) ├──■──┤ Rz(1.2) ├──■── q_0: ┤ Rz(1.7) ├
792
+ └─────────┘┌─┴─┐└──┬───┬──┘┌─┴─┐ = └──┬───┬──┘
793
+ q_1: ───────────┤ X ├───┤ X ├───┤ X ├ q_1: ───┤ X ├───
794
+ └───┘ └───┘ └───┘ └───┘
795
+
796
+ Performing these optimizations are part of the transpiler, but the tools to investigate commutations
797
+ are available in the :class:`CommutationChecker`.
798
+
799
+ .. autosummary::
800
+ :toctree: ../stubs/
801
+
802
+ CommutationChecker
803
+
804
+
805
+ .. _circuit-custom-gates:
806
+
807
+ Creating custom instructions
808
+ ============================
809
+
810
+ If you wish to create simple one-off instructions or gates that will be added to a circuit, and the
811
+ blocks are just being used for visualization or grouping purposes, the easiest way to create a
812
+ custom instruction or gate is simply to build its definition as a :class:`QuantumCircuit`, and then
813
+ use its :meth:`~QuantumCircuit.to_instruction` or :meth:`~QuantumCircuit.to_gate` method as
814
+ appropriate. The results can be given directly to :meth:`QuantumCircuit.append` on the larger
815
+ circuit. These methods will create base :class:`Instruction` or :class:`Gate` instances whose
816
+ :attr:`~Instruction.definition` attribute is the circuit as supplied, meaning it will automatically
817
+ be accessible to the transpiler, and to other Qiskit functions that attempt to decompose circuits.
818
+
819
+ Note that standalone instructions and gates should act only on qubits and clbits; instructions that
820
+ need to use complex control-flow will need to be inlined onto the :class:`QuantumCircuit` using
821
+ :meth:`~QuantumCircuit.compose`.
822
+
823
+
824
+ Creating instruction subclasses
825
+ -------------------------------
826
+
827
+ The base classes :class:`Instruction`, :class:`Gate` and :class:`ControlledGate` are all designed to
828
+ be safe to subclass, and have hook points for subclasses to implement. If your custom gate is
829
+ parameterless and stateless, you may also want to derive from the corresponding singleton class in
830
+ :mod:`qiskit.circuit.singleton`, such as :class:`SingletonGate`. You should consult the
831
+ documentation in :mod:`qiskit.circuit.singleton` for additional methods and hook points for the
832
+ singleton machinery.
833
+
834
+ Subclasses should typically define a default constructor that calls the :class`super` constructor
835
+ with the correct arguments for your instruction. It is permissible to have extra state in the
836
+ class, but your subclasses will most reliably integrate with the rest of the Qiskit machinery if you
837
+ depend only on your :attr:`Instruction.params`, and these parameters are purely gate angles.
838
+
839
+ Subclasses of :class:`Instruction` (or one of its subclasses) should implement the private
840
+ :meth:`Instruction._define` method, which lazily populates the hidden ``_definition`` cache that
841
+ backs the public :attr:`~Instruction.definition` method.
842
+
843
+ .. automethod:: Instruction._define
844
+
845
+ In subclasses of :class:`ControlledGate`, the :meth:`~Instruction._define` method should implement
846
+ the decomposition only for the all-ones control state. The :attr:`ControlledGate.definition
847
+ <Instruction.definition>` machinery will modify this to handle the actual control state.
848
+
849
+ If the subclass is using the singleton machinery, beware that :meth:`~Instruction._define` will be
850
+ called eagerly immediately after the class-body statement has been executed, in order to produce the
851
+ definition object for the canonical singleton object. This means that your definition must only use
852
+ gates that are already defined; if you are writing a library with many singleton gates, you will
853
+ have to order your files and imports to ensure that this is possible.
854
+
855
+ Subclasses of :class:`Gate` will also likely wish to override `the Numpy array-protocol instance
856
+ method <https://numpy.org/devdocs/user/basics.interoperability.html#the-array-method>`__,
857
+ ``__array__``. This is used by :meth:`Gate.to_matrix`, and has the signature:
858
+
859
+ .. currentmodule:: None
860
+ .. py:method:: object.__array__(dtype=None, copy=None)
861
+
862
+ Return a Numpy array representing the gate. This can use the gate's
863
+ :attr:`~qiskit.circuit.Instruction.params` field, and may assume that these are numeric
864
+ values (assuming the subclass expects that) and not
865
+ :ref:`compile-time parameters <circuit-compile-time-parameters>`.
866
+
867
+ For greatest efficiency, the returned array should default to a dtype of :class:`complex`.
868
+ .. currentmodule:: qiskit.circuit
869
+
870
+ If your custom subclass has natural representations of its controlled or inverse forms, you may also
871
+ wish to override the :meth:`~Instruction.inverse` and :meth:`~Gate.control` methods.
872
+
873
+
874
+ As an example of defining a custom :math:`R_{xz}` gate; that is, a single-angle rotation about the
875
+ :math:`XZ` axis. This is essentially :class:`RZXGate`, if the qubits were the other way around, so
876
+ we will write our definition in terms of that. We are parametric, so cannot be a singleton, but we
877
+ are unitary, so should be a :class:`Gate`::
878
+
879
+ import math
880
+ import numpy as np
881
+ from qiskit.circuit import Gate, QuantumCircuit
882
+
883
+ class RXZGate(Gate):
884
+ def __init__(self, theta):
885
+ # Initialize with our name, number of qubits and parameters.
886
+ super().__init__("rxz", 2, [theta])
887
+
888
+ def _define(self):
889
+ # Our base definition is an RZXGate, applied "backwards".
890
+ defn = QuantumCircuit(2)
891
+ defn.rzx(1, 0)
892
+ self._definition = defn
893
+
894
+ def inverse(self, annotated = False):
895
+ # We have an efficient representation of our inverse,
896
+ # so we'll override this method.
897
+ return RXZGate(-self.params[0])
898
+
899
+ def power(self, exponent: float):
900
+ # Also we have an efficient representation of power.
901
+ return RXZGate(exponent * self.params[0])
902
+
903
+ def __array__(self, dtype=None, copy=None):
904
+ if copy is False:
905
+ raise ValueError("unable to avoid copy while creating an array as requested")
906
+ cos = math.cos(0.5 * self.params[0])
907
+ isin = 1j * math.sin(0.5 * self.params[0])
908
+ return np.array([
909
+ [cos, -isin, 0, 0],
910
+ [-isin, cos, 0, 0],
911
+ [0, 0, cos, isin],
912
+ [0, 0, isin, cos],
913
+ ], dtype=dtype)
914
+
915
+
916
+ In this example, we defined a base definition in terms of :class:`RZXGate`, but to enable faster
917
+ decompositions to a range of bases, we might want to add some more equivalences to
918
+ :data:`SessionEquivalenceLibrary`. Note that the :class:`.BasisTranslator` translation search will
919
+ search through all possible equivalences at all possible depths, so providing an equivalence in
920
+ terms of (say) :class:`.XGate` will automatically make decompositions in terms of :class:`.RXGate`
921
+ available as well.
922
+
923
+ Let us add an equivalence in terms of :math:`H`, :math:`CX` and :math:`R_z` for an arbitrary symbolic
924
+ parameter::
925
+
926
+ from qiskit.circuit import SessionEquivalenceLibrary, Parameter
927
+
928
+ theta = Parameter("theta")
929
+
930
+ equiv = QuantumCircuit(2)
931
+ equiv.h(0)
932
+ equiv.cx(1, 0)
933
+ equiv.rz(theta, 0)
934
+ equiv.cx(1, 0)
935
+ equiv.h(0)
936
+
937
+ SessionEquivalenceLibrary.add_equivalence(RZXGate(theta), equiv)
938
+
939
+ After this, for the duration of the Python interpreter session, translators like
940
+ :class:`.BasisTranslator` will find our new definition in their search.
941
+
942
+
943
+ .. _circuit-working-with:
944
+
945
+ Working with circuit-level objects
946
+ ==================================
947
+
948
+ .. _circuit-abstract-to-physical:
949
+
950
+ Converting abstract circuits to physical circuits
951
+ -------------------------------------------------
952
+
953
+ ..
954
+ Note that this is just a "jumping-off" section - this should just provide an overview of links
955
+ to where the real information is.
956
+
957
+ An abstract :class:`QuantumCircuit` cannot reliably be run on hardware. You might be able to use
958
+ some of the high-level simulators linked to in :ref:`circuit-simulation` to produce quick results
959
+ for small scale circuits, but to run utility-scale circuits, you will need to use real hardware,
960
+ which involves compiling to a physical circuit.
961
+
962
+ The high-level function to do this is :func:`.transpile`; it takes in an abstract circuit and a
963
+ hardware ``backend`` or ``target``, and returns a physical circuit. To get more access and control
964
+ over the stages of the passes that will be run, use :func:`.generate_preset_pass_manager` to build a
965
+ :class:`~.transpiler.StagedPassManager` first, which you can then modify.
966
+
967
+ The full transpilation and compilation machinery is described in detail in the
968
+ :mod:`qiskit.transpiler` module documentation, and detail on all the passes built into Qiskit is
969
+ available in :mod:`qiskit.transpiler.passes`.
970
+
971
+
972
+ .. _circuit-simulation:
973
+
974
+ Simulating circuits
975
+ -------------------
976
+
977
+ ..
978
+ Note that this is just a "jumping-off" section - this should just provide an overview of links
979
+ to where the real information is.
980
+
981
+
982
+ While not part of the :mod:`qiskit.circuit` interface, one of the most common needs is to get quick
983
+ simulation results for :class:`QuantumCircuit` objects. This section provides a quick jumping-off
984
+ point to other places in the documentation to find the relevant information.
985
+
986
+ For unitary circuits, you can simulate the effects on the :math:`\lvert0\dotsm0\rangle` state by
987
+ passing the :class:`QuantumCircuit` directly to the :class:`~.quantum_info.Statevector` default
988
+ constructor. You can similar get a unitary matrix representing the circuit as an operator by
989
+ passing it to the :class:`~.quantum_info.Operator` default constructor. If you have a physical
990
+ circuit, you may want to instead pass it to :meth:`.Operator.from_circuit` method to apply
991
+ transformations from the :attr:`QuantumCircuit.layout` to map it back to the "abstract" qubit space.
992
+
993
+ For a more backend-like simulation experience, there are simulator-backed implementations of all the
994
+ Qiskit hardware interfaces. In particular, you might be interested in:
995
+
996
+ * :class:`.BasicProvider` and the raw backends it can return to you.
997
+ * :class:`.StatevectorSimulator` for a backend-like wrapper around :class:`.Statevector`
998
+ * The :mod:`qiskit_aer` for full, high-performance simulation capabilities.
999
+ * :class:`.StatevectorSampler` and :class:`.StatevectorEstimator` for simulator-backed reference
1000
+ implementations of the :ref:`Qiskit Primitives <qiskit-primitives>`.
1001
+
1002
+
1003
+ Defining equivalence relationships
1004
+ ----------------------------------
1005
+
1006
+ A common task in mapping abstract circuits to physical hardware and optimizing the result is to find
1007
+ equivalence relations that map a gate to a different basis set. Qiskit stores this information in a
1008
+ database class called :class:`EquivalenceLibrary`.
1009
+
1010
+ .. autosummary::
1011
+ :toctree: ../stubs/
1012
+
1013
+ EquivalenceLibrary
1014
+
1015
+ Qiskit ships with a large set of predefined equivalence relationships for all of its standard gates.
1016
+ This base library is called :data:`StandardEquivalenceLibrary`, and should be treated as immutable.
1017
+
1018
+ .. py:data:: StandardEquivalenceLibrary
1019
+
1020
+ A :class:`EquivalenceLibrary` that stores of all Qiskit's built-in standard gate relationships.
1021
+ You should not mutate this, but instead either create your own :class:`EquivalenceLibrary` using
1022
+ this one as its ``base``, or modify the global-state :data:`SessionEquivalenceLibrary`.
1023
+
1024
+ Qiskit also defines a shared global-state object, :data:`SessionEquivalenceLibrary`, which is the
1025
+ default equivalences used by various places in Qiskit, most notably the :class:`.BasisTranslator`
1026
+ transpiler pass. You should feel free to add your own equivalences to this using its
1027
+ :meth:`~EquivalenceLibrary.add_equivalence` method, and they will be automatically picked up by
1028
+ default instances of the :class:`.BasisTranslator`.
1029
+
1030
+ .. py:data:: SessionEquivalenceLibrary
1031
+
1032
+ The default instance of :class:`EquivalenceLibrary`, which will be used by most Qiskit objects
1033
+ if no library is manually specified. You can feel free to add equivalences to this using
1034
+ :meth:`~EquivalenceLibrary.add_equivalence`. It inherits all the built-in rules of
1035
+ :data:`StandardEquivalenceLibrary`.
1036
+
1037
+
1038
+
1039
+ Generating random circuits
1040
+ --------------------------
1041
+
1042
+ ..
1043
+ If we expand these capabilities in the future, it's probably best to move it to its own
1044
+ module-level documentation page than to expand this "inline" module documentation.
1045
+
1046
+ .. currentmodule:: qiskit.circuit.random
1047
+ .. autofunction:: random_circuit
1048
+ .. currentmodule:: qiskit.circuit
1049
+
1050
+ Apply Pauli twirling to a circuit
1051
+ ---------------------------------
1052
+
1053
+ There are two primary types of noise when executing quantum circuits. The first is stochastic,
1054
+ or incoherent, noise that is mainly due to the unwanted interaction between the quantum processor
1055
+ and the external environment in which it resides. The second is known as coherent error, and these
1056
+ errors arise due to imperfect control of a quantum system. This can be unwanted terms in a system
1057
+ Hamiltonian, i.e. incorrect unitary evolution, or errors from incorrect temporal control of the
1058
+ quantum system, which includes things like incorrect pulse-shapes for gates.
1059
+
1060
+ Pauli twirling is a quantum error suppression technique that uses randomization to shape coherent
1061
+ error into stochastic errors by combining the results from many random, but logically equivalent
1062
+ circuits, together. Qiskit provides a function to apply Pauli twirling to a given circuit for
1063
+ standard two qubit gates. For more details you can refer to the documentation of the function
1064
+ below:
1065
+
1066
+ .. autofunction:: qiskit.circuit.pauli_twirl_2q_gates
1067
+
1068
+
1069
+ Exceptions
1070
+ ==========
1071
+
1072
+ Almost all circuit functions and methods will raise a :exc:`CircuitError` when encountering an error
1073
+ that is particular to usage of Qiskit (as opposed to regular typing or indexing problems, which will
1074
+ typically raise the corresponding standard Python error).
1075
+
1076
+ .. autoexception:: CircuitError
1077
+
1078
+
1079
+ .. _circuit-conventions:
1080
+
1081
+ Circuit conventions
1082
+ ===================
1083
+
1084
+ When constructing circuits out of abstract objects and more concrete matrices, there are several
1085
+ possible conventions around bit-labelling, bit-ordering, and how the abstract tensor product is
1086
+ realized in concrete matrix algebra.
1087
+
1088
+ Qiskit's conventions are:
1089
+
1090
+ * in bitstring representations, bits are labelled with the right-most bit in the string called
1091
+ :math:`0` and the left-most bit in the string of :math:`n` bits called :math:`n - 1`.
1092
+
1093
+ * when using integers as bit-specifier indices in circuit-construction functions, the integer is
1094
+ treated as an index into :attr:`QuantumCircuit.qubits` (or :attr:`~QuantumCircuit.clbits`).
1095
+
1096
+ * when drawing circuits, we put the lowest-index bits on top.
1097
+
1098
+ * in statevector representations, we realize the abstract tensor product as the Kronecker product,
1099
+ and order the arguments to this such that the amplitude of computational-basis state
1100
+ :math:`\lvert x\rangle`, where :math:`x` is the bitstring interpreted as an integer, is at
1101
+ location ``statevector[x]``.
1102
+
1103
+ * when controlling a gate, the control qubit(s) is placed first in the argument list, *e.g.* in the
1104
+ call ``qc.cx(0, 1)``, qubit 0 will be the control and qubit 1 will be the target. Similarly, in
1105
+ the manual call ``qc.append(CXGate(), [0, 1])``, qubit 0 will be the control and qubit 1 will be
1106
+ the target.
1107
+
1108
+ Let us illustrate these conventions with some examples.
1109
+
1110
+ Bit labelling
1111
+ -------------
1112
+
1113
+ Take the circuit:
1114
+
1115
+ .. plot::
1116
+ :include-source:
1117
+ :nofigs:
1118
+ :context:
1119
+ :show-source-link: False
1120
+
1121
+ from qiskit import QuantumCircuit
1122
+
1123
+ qc = QuantumCircuit(5, 5)
1124
+ qc.x(0)
1125
+ qc.x(1)
1126
+ qc.x(4)
1127
+ qc.measure(range(5), range(5))
1128
+
1129
+ This flips the states of qubits 0, 1 and 4 from :math:`\lvert0\rangle` to :math:`\lvert1\rangle`,
1130
+ then measures all qubits :math:`n` into the corresponding clbit :math:`n` using the computational
1131
+ (:math:`Z`) basis. If simulated noiselessly, the bitstring output from this circuit will be
1132
+ :math:`10011` every time; qubits 0, 1, and 4 are flipped, and the "one" values in the bitstring are
1133
+ in the zeroth, first and fourth digits *from the right*.
1134
+
1135
+ In Qiskit, we would write the qubit state immediately before the measurement in ket-notation
1136
+ shorthand as :math:`\lvert10011\rangle`. Note that the ket label matches the classical bitstring,
1137
+ and has the numeric binary value of 19.
1138
+
1139
+ If we draw this circuit, we will see that Qiskit places the zeroth qubit on the top of the circuit
1140
+ drawing:
1141
+
1142
+ .. plot::
1143
+ :include-source:
1144
+ :context:
1145
+ :show-source-link: False
1146
+
1147
+ qc.draw("mpl")
1148
+
1149
+
1150
+ Matrix representations
1151
+ ----------------------
1152
+
1153
+ Statevectors are defined in the convention that for a two-level system, the relationship between
1154
+ abstract representation and matrix representation is such that
1155
+
1156
+ .. math::
1157
+
1158
+ \alpha\lvert0\rangle + \beta\lvert1\rangle
1159
+ \leftrightarrow \begin{pmatrix} \alpha \\ \beta \end{pmatrix}
1160
+
1161
+ where :math:`\alpha` and :math:`\beta` are complex numbers. We store the statevector as a 1D Numpy
1162
+ :class:`~numpy.ndarray` with data ``sv = [alpha, beta]``, *i.e.* ``sv[0] == alpha`` and ``sv[1] ==
1163
+ beta``; note that the indices into the statevector match the ket labels.
1164
+
1165
+ We construct `the tensor product of two qubit states
1166
+ <https://en.wikipedia.org/wiki/Tensor_product>`_ in matrix algebra using `the Kronecker product
1167
+ <https://en.wikipedia.org/wiki/Kronecker_product>`_, with qubit 0 on the right and qubit 1 on the
1168
+ left, such that the :math:`Z` basis state :math:`\lvert x\rangle` (where :math:`x` is the integer
1169
+ interpretation of the bitstring) has its non-zero term in the statevector ``sv`` at ``sv[x]``::
1170
+
1171
+ import numpy
1172
+ from qiskit import QuantumCircuit
1173
+ from qiskit.quantum_info import Statevector
1174
+
1175
+ state_0 = [1, 0] # defined representation of |0>
1176
+ state_1 = [0, 1] # defined representation of |1>
1177
+
1178
+ # Circuit that creates basis state |10011>, where
1179
+ # binary 10011 has the decimal value 19.
1180
+ qc = QuantumCircuit(5)
1181
+ qc.x(0)
1182
+ qc.x(1)
1183
+ qc.x(4)
1184
+ qiskit_sv = Statevector(qc)
1185
+
1186
+ # List index 'n' corresponds to qubit 'n'.
1187
+ individual_states = [
1188
+ state_1,
1189
+ state_1,
1190
+ state_0,
1191
+ state_0,
1192
+ state_1,
1193
+ ]
1194
+ # Start from a scalar.
1195
+ manual_sv = [1]
1196
+ for qubit_state in individual_states:
1197
+ # Each new qubit goes "on the left".
1198
+ manual_sv = numpy.kron(qubit_state, manual_sv)
1199
+
1200
+ # Now `qiskit_sv` and `manual_sv` are the same, and:
1201
+ assert manual_sv[19] == 1
1202
+ assert qiskit_sv[19] == 1
1203
+
1204
+ This feeds through to the matrix representation of operators, and joins with the conventions on bit
1205
+ orders for controlled operators. For example, the matrix form of :class:`.CXGate` is::
1206
+
1207
+ import numpy
1208
+ from qiskit.circuit.library import CXGate
1209
+
1210
+ numpy.array(CXGate())
1211
+
1212
+ .. math::
1213
+
1214
+ \operatorname{array}(CX) =
1215
+ \begin{pmatrix}
1216
+ 1 & 0 & 0 & 0 \\
1217
+ 0 & 0 & 0 & 1 \\
1218
+ 0 & 0 & 1 & 0 \\
1219
+ 0 & 1 & 0 & 0
1220
+ \end{pmatrix}
1221
+
1222
+ This might be different to other matrix representations you have seen for :math:`CX`, but recall
1223
+ that the choice of matrix representation is conventional, and this form matches Qiskit's conventions
1224
+ of *control qubits come first* and *the tensor product is represented such that there is a
1225
+ correspondence between the index of the "one amplitude" and the bitstring value of a state*.
1226
+
1227
+ In the case of multiple controls for a gate, such as for :class:`.CCXGate`, the ``ctrl_state``
1228
+ argument is interpreted as the bitstring value of the control qubits, using the same zero-based
1229
+ labelling conventions. For example, given that the default ``ctrl_state`` is the all-ones
1230
+ bitstring, we can see that the matrix form of :class:`.CCXGate` with ``ctrl_state = 1`` is the same
1231
+ as if we took the all-ones control-state :class:`.CCXGate`, but flipped the value of the higher
1232
+ indexed control qubit on entry and exist to the gate::
1233
+
1234
+ from qiskit import QuantumCircuit
1235
+ from qiskit.quantum_info import Operator
1236
+
1237
+ # Build the natural representation of `CCX` with the
1238
+ # control qubits being `[0, 1]`, relative to the
1239
+ # bitstring state "01", such that qubit 0 must be in |1>
1240
+ # and qubit 1 must be in |0>. The target qubit is 2.
1241
+ ccx_natural = QuantumCircuit(3)
1242
+ ccx_natural.ccx(0, 1, 2, ctrl_state=1)
1243
+
1244
+ # Build the same circuit in terms of the all-ones CCX.
1245
+ # Note that we flip _qubit 1_, because that's the one
1246
+ # that differs from the all-ones state.
1247
+ ccx_relative = QuantumCircuit(3)
1248
+ ccx_relative.x(1)
1249
+ ccx_relative.ccx(0, 1, 2)
1250
+ ccx_relative.x(1)
1251
+
1252
+ assert Operator(ccx_relative) == Operator(ccx_natural)
1253
+
1254
+ In both these cases, the matrix form of :class:`.CCXGate` in ``ctrl_state = 1`` is:
1255
+
1256
+ .. math::
1257
+
1258
+ \operatorname{array}\bigl(CCX(\text{ctrl\_state}=1)\bigr) =
1259
+ \begin{pmatrix}
1260
+ 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\
1261
+ 0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 \\
1262
+ 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 \\
1263
+ 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 \\
1264
+ 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 \\
1265
+ 0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 \\
1266
+ 0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 \\
1267
+ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1
1268
+ \end{pmatrix}
1269
+ """
1270
+
1271
+ from .exceptions import CircuitError
1272
+ from . import _utils
1273
+ from .quantumcircuit import QuantumCircuit
1274
+ from .classicalregister import ClassicalRegister, Clbit
1275
+ from .quantumregister import QuantumRegister, Qubit, AncillaRegister, AncillaQubit
1276
+ from .gate import Gate
1277
+
1278
+ # pylint: disable=cyclic-import
1279
+ from .controlledgate import ControlledGate
1280
+ from . import singleton
1281
+ from .instruction import Instruction
1282
+ from .instructionset import InstructionSet
1283
+ from .operation import Operation
1284
+ from .barrier import Barrier
1285
+ from .delay import Delay
1286
+ from .measure import Measure
1287
+ from .reset import Reset
1288
+ from .store import Store
1289
+ from .parameter import Parameter
1290
+ from .parametervector import ParameterVector
1291
+ from .parameterexpression import ParameterExpression
1292
+ from .quantumcircuitdata import CircuitInstruction
1293
+ from .equivalence import EquivalenceLibrary
1294
+ from .bit import Bit
1295
+ from .register import Register
1296
+ from . import library
1297
+ from .equivalence_library import StandardEquivalenceLibrary, SessionEquivalenceLibrary
1298
+ from .commutation_checker import CommutationChecker
1299
+
1300
+ from .controlflow import (
1301
+ ControlFlowOp,
1302
+ WhileLoopOp,
1303
+ ForLoopOp,
1304
+ IfElseOp,
1305
+ SwitchCaseOp,
1306
+ CASE_DEFAULT,
1307
+ BreakLoopOp,
1308
+ ContinueLoopOp,
1309
+ CONTROL_FLOW_OP_NAMES,
1310
+ )
1311
+
1312
+ from .annotated_operation import AnnotatedOperation, InverseModifier, ControlModifier, PowerModifier
1313
+ from .twirling import pauli_twirl_2q_gates