qiskit 1.3.0__cp39-abi3-win32.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
qiskit/qpy/__init__.py ADDED
@@ -0,0 +1,1822 @@
1
+ # This code is part of Qiskit.
2
+ #
3
+ # (C) Copyright IBM 2021, 2022.
4
+ #
5
+ # This code is licensed under the Apache License, Version 2.0. You may
6
+ # obtain a copy of this license in the LICENSE.txt file in the root directory
7
+ # of this source tree or at http://www.apache.org/licenses/LICENSE-2.0.
8
+ #
9
+ # Any modifications or derivative works of this code must retain this
10
+ # copyright notice, and modified files need to carry a notice indicating
11
+ # that they have been altered from the originals.
12
+
13
+ """
14
+ =====================================
15
+ QPY serialization (:mod:`qiskit.qpy`)
16
+ =====================================
17
+
18
+ .. currentmodule:: qiskit.qpy
19
+
20
+ QPY is a binary serialization format for :class:`~.QuantumCircuit` and
21
+ :class:`~.ScheduleBlock` objects that is designed to be cross-platform,
22
+ Python version agnostic, and backwards compatible moving forward. QPY should
23
+ be used if you need a mechanism to save or copy between systems a
24
+ :class:`~.QuantumCircuit` or :class:`~.ScheduleBlock` that preserves the full
25
+ Qiskit object structure (except for custom attributes defined outside of
26
+ Qiskit code). This differs from other serialization formats like
27
+ `OpenQASM <https://github.com/openqasm/openqasm>`__ (2.0 or 3.0) which has a
28
+ different abstraction model and can result in a loss of information contained
29
+ in the original circuit (or is unable to represent some aspects of the
30
+ Qiskit objects) or Python's `pickle <https://docs.python.org/3/library/pickle.html>`__
31
+ which will preserve the Qiskit object exactly but will only work for a single Qiskit
32
+ version (it is also
33
+ `potentially insecure <https://docs.python.org/3/library/pickle.html#module-pickle>`__).
34
+
35
+ Basic Usage
36
+ ===========
37
+
38
+ Using QPY is defined to be straightforward and mirror the user API of the
39
+ serializers in Python's standard library, ``pickle`` and ``json``. There are
40
+ 2 user facing functions: :func:`qiskit.qpy.dump` and
41
+ :func:`qiskit.qpy.load` which are used to dump QPY data
42
+ to a file object and load circuits from QPY data in a file object respectively.
43
+ For example::
44
+
45
+ from qiskit.circuit import QuantumCircuit
46
+ from qiskit import qpy
47
+
48
+ qc = QuantumCircuit(2, name='Bell', metadata={'test': True})
49
+ qc.h(0)
50
+ qc.cx(0, 1)
51
+ qc.measure_all()
52
+
53
+ with open('bell.qpy', 'wb') as fd:
54
+ qpy.dump(qc, fd)
55
+
56
+ with open('bell.qpy', 'rb') as fd:
57
+ new_qc = qpy.load(fd)[0]
58
+
59
+ The :func:`qiskit.qpy.dump` function also lets you
60
+ include multiple circuits in a single QPY file::
61
+
62
+ with open('twenty_bells.qpy', 'wb') as fd:
63
+ qpy.dump([qc] * 20, fd)
64
+
65
+ and then loading that file will return a list with all the circuits
66
+
67
+ with open('twenty_bells.qpy', 'rb') as fd:
68
+ twenty_new_bells = qpy.load(fd)
69
+
70
+ API documentation
71
+ =================
72
+
73
+ .. autofunction:: load
74
+ .. autofunction:: dump
75
+
76
+ These functions will raise a custom subclass of :exc:`.QiskitError` if they encounter problems
77
+ during serialization or deserialization.
78
+
79
+ .. autoexception:: QpyError
80
+
81
+ When a lower-than-maximum target QPY version is set for serialization, but the object to be
82
+ serialized contains features that cannot be represented in that format, a subclass of
83
+ :exc:`QpyError` is raised:
84
+
85
+ .. autoexception:: UnsupportedFeatureForVersion
86
+
87
+ Attributes:
88
+ QPY_VERSION (int): The current QPY format version as of this release. This
89
+ is the default value of the ``version`` keyword argument on
90
+ :func:`.qpy.dump` and also the upper bound for accepted values for
91
+ the same argument. This is also the upper bond on the versions supported
92
+ by :func:`.qpy.load`.
93
+
94
+ QPY_COMPATIBILITY_VERSION (int): The current minimum compatibility QPY
95
+ format version. This is the minimum version that :func:`.qpy.dump`
96
+ will accept for the ``version`` keyword argument. :func:`.qpy.load`
97
+ will be able to load all released format versions of QPY (up until
98
+ ``QPY_VERSION``).
99
+
100
+ .. _qpy_compatibility:
101
+
102
+ QPY Compatibility
103
+ =================
104
+
105
+ The QPY format is designed to be backwards compatible moving forward. This means
106
+ you should be able to load a QPY with any newer Qiskit version than the one
107
+ that generated it. However, loading a QPY file with an older Qiskit version is
108
+ not supported and may not work.
109
+
110
+ For example, if you generated a QPY file using qiskit-terra 0.18.1 you could
111
+ load that QPY file with qiskit-terra 0.19.0 and a hypothetical qiskit-terra
112
+ 0.29.0. However, loading that QPY file with 0.18.0 is not supported and may not
113
+ work.
114
+
115
+ If a feature being loaded is deprecated in the corresponding qiskit release, QPY will
116
+ raise a :exc:`~.QPYLoadingDeprecatedFeatureWarning` informing of the deprecation period
117
+ and how the feature will be internally handled.
118
+
119
+ .. autoexception:: QPYLoadingDeprecatedFeatureWarning
120
+
121
+ .. note::
122
+
123
+ With versions of Qiskit before 1.2.4, the ``use_symengine=True`` argument to :func:`.qpy.dump`
124
+ could cause problems with backwards compatibility if there were :class:`.ParameterExpression`
125
+ objects to serialize. In particular:
126
+
127
+ * When the loading version of Qiskit is 1.2.4 or greater, QPY files generated with any version
128
+ of Qiskit >= 0.46.0 can be loaded. If a version of Qiskit between 0.45.0 and 0.45.3 was used
129
+ to generate the files, and the non-default argument ``use_symengine=True`` was given to
130
+ :func:`.qpy.dump`, the file can only be read if the version of ``symengine`` used in the
131
+ generating environment was in the 0.11 or 0.13 series, but if the environment was created
132
+ during the support window of Qiskit 0.45, it is likely that ``symengine==0.9.2`` was used.
133
+
134
+ * When the loading version of Qiskit is between 0.46.0 and 1.2.2 inclusive, the file can only be
135
+ read if the installed version of ``symengine`` in the loading environment matches the version
136
+ used in the generating environment.
137
+
138
+ To recover a QPY file that fails with ``symengine`` version-related errors during a call to
139
+ :func:`.qpy.load`, first attempt to use Qiskit >= 1.2.4 to load the file. If this still fails,
140
+ it is likely because Qiskit 0.45.x was used to generate the file with ``use_symengine=True``.
141
+ In this case, use Qiskit 0.45.3 with ``symengine==0.9.2`` to load the file, and then re-export
142
+ it to QPY setting ``use_symengine=False``. The resulting file can then be loaded by any later
143
+ version of Qiskit.
144
+
145
+ QPY format version history
146
+ --------------------------
147
+
148
+ If you're planning to load a QPY file between different Qiskit versions knowing
149
+ which versions were available in a given release are useful. As the QPY is
150
+ backwards compatible but not forwards compatible you need to ensure a given
151
+ QPY format version was released in the release you're calling :func:`.load`
152
+ with. The following table lists the QPY versions that were supported in every
153
+ Qiskit (and qiskit-terra prior to Qiskit 1.0.0) release going back to the introduction
154
+ of QPY in qiskit-terra 0.18.0.
155
+
156
+ .. list-table:: QPY Format Version History
157
+ :header-rows: 1
158
+
159
+ * - Qiskit (qiskit-terra for < 1.0.0) version
160
+ - :func:`.dump` format(s) output versions
161
+ - :func:`.load` maximum supported version (older format versions can always be read)
162
+ * - 1.3.0
163
+ - 10, 11, 12, 13
164
+ - 13
165
+ * - 1.2.4
166
+ - 10, 11, 12
167
+ - 12
168
+ * - 1.2.3 (yanked)
169
+ - 10, 11, 12
170
+ - 12
171
+ * - 1.2.2
172
+ - 10, 11, 12
173
+ - 12
174
+ * - 1.2.1
175
+ - 10, 11, 12
176
+ - 12
177
+ * - 1.2.0
178
+ - 10, 11, 12
179
+ - 12
180
+ * - 1.1.0
181
+ - 10, 11, 12
182
+ - 12
183
+ * - 1.0.2
184
+ - 10, 11
185
+ - 11
186
+ * - 1.0.1
187
+ - 10, 11
188
+ - 11
189
+ * - 1.0.0
190
+ - 10, 11
191
+ - 11
192
+ * - 0.46.1
193
+ - 10
194
+ - 10
195
+ * - 0.45.3
196
+ - 10
197
+ - 10
198
+ * - 0.45.2
199
+ - 10
200
+ - 10
201
+ * - 0.45.1
202
+ - 10
203
+ - 10
204
+ * - 0.45.0
205
+ - 10
206
+ - 10
207
+ * - 0.25.3
208
+ - 9
209
+ - 9
210
+ * - 0.25.2
211
+ - 9
212
+ - 9
213
+ * - 0.25.1
214
+ - 9
215
+ - 9
216
+ * - 0.24.2
217
+ - 8
218
+ - 8
219
+ * - 0.24.1
220
+ - 7
221
+ - 7
222
+ * - 0.24.0
223
+ - 7
224
+ - 7
225
+ * - 0.23.3
226
+ - 6
227
+ - 6
228
+ * - 0.23.2
229
+ - 6
230
+ - 6
231
+ * - 0.23.1
232
+ - 6
233
+ - 6
234
+ * - 0.23.0
235
+ - 6
236
+ - 6
237
+ * - 0.22.4
238
+ - 5
239
+ - 5
240
+ * - 0.22.3
241
+ - 5
242
+ - 5
243
+ * - 0.22.2
244
+ - 5
245
+ - 5
246
+ * - 0.22.1
247
+ - 5
248
+ - 5
249
+ * - 0.22.0
250
+ - 5
251
+ - 5
252
+ * - 0.21.2
253
+ - 5
254
+ - 5
255
+ * - 0.21.1
256
+ - 5
257
+ - 5
258
+ * - 0.21.0
259
+ - 5
260
+ - 5
261
+ * - 0.20.2
262
+ - 4
263
+ - 4
264
+ * - 0.20.1
265
+ - 4
266
+ - 4
267
+ * - 0.20.0
268
+ - 4
269
+ - 4
270
+ * - 0.19.2
271
+ - 4
272
+ - 4
273
+ * - 0.19.1
274
+ - 3
275
+ - 3
276
+ * - 0.19.0
277
+ - 2
278
+ - 2
279
+ * - 0.18.3
280
+ - 1
281
+ - 1
282
+ * - 0.18.2
283
+ - 1
284
+ - 1
285
+ * - 0.18.1
286
+ - 1
287
+ - 1
288
+ * - 0.18.0
289
+ - 1
290
+ - 1
291
+
292
+ .. _qpy_format:
293
+
294
+ QPY Format
295
+ ==========
296
+
297
+ The QPY serialization format is a portable cross-platform binary
298
+ serialization format for :class:`~qiskit.circuit.QuantumCircuit` objects in Qiskit. The basic
299
+ file format is as follows:
300
+
301
+ A QPY file (or memory object) always starts with the following 6
302
+ byte UTF8 string: ``QISKIT`` which is immediately followed by the overall
303
+ file header. The contents of the file header as defined as a C struct are:
304
+
305
+ .. code-block:: c
306
+
307
+ struct {
308
+ uint8_t qpy_version;
309
+ uint8_t qiskit_major_version;
310
+ uint8_t qiskit_minor_version;
311
+ uint8_t qiskit_patch_version;
312
+ uint64_t num_circuits;
313
+ }
314
+
315
+
316
+ From V10 on, a new field is added to the file header struct to represent the
317
+ encoding scheme used for symbolic expressions:
318
+
319
+ .. code-block:: c
320
+
321
+ struct {
322
+ uint8_t qpy_version;
323
+ uint8_t qiskit_major_version;
324
+ uint8_t qiskit_minor_version;
325
+ uint8_t qiskit_patch_version;
326
+ uint64_t num_circuits;
327
+ char symbolic_encoding;
328
+ }
329
+
330
+ All values use network byte order [#f1]_ (big endian) for cross platform
331
+ compatibility.
332
+
333
+ The file header is immediately followed by the circuit payloads.
334
+ Each individual circuit is composed of the following parts:
335
+
336
+ ``HEADER | METADATA | REGISTERS | STANDALONE_VARS | CUSTOM_DEFINITIONS | INSTRUCTIONS``
337
+
338
+ The ``STANDALONE_VARS`` are new in QPY version 12; before that, there was no data between
339
+ ``REGISTERS`` and ``CUSTOM_DEFINITIONS``.
340
+
341
+ There is a circuit payload for each circuit (where the total number is dictated
342
+ by ``num_circuits`` in the file header). There is no padding between the
343
+ circuits in the data.
344
+
345
+ .. _qpy_version_13:
346
+
347
+ Version 13
348
+ ----------
349
+
350
+ Version 13 added a native Qiskit serialization representation for :class:`.ParameterExpression`.
351
+ Previous QPY versions relied on either ``sympy`` or ``symengine`` to serialize the underlying symbolic
352
+ expression. Starting in Version 13, QPY now represents the sequence of API calls used to create the
353
+ :class:`.ParameterExpression`.
354
+
355
+ The main change in the serialization format is in the :ref:`qpy_param_expr_v3` payload. The
356
+ ``expr_size`` bytes following the head now contain an array of ``PARAM_EXPR_ELEM_V13`` structs. The
357
+ intent is for this array to be read one struct at a time, where each struct describes one of the
358
+ calls to make to reconstruct the :class:`.ParameterExpression`.
359
+
360
+ PARAM_EXPR_ELEM_V13
361
+ ~~~~~~~~~~~~~~~~~~~
362
+
363
+ The struct format is defined as:
364
+
365
+ .. code-block:: c
366
+
367
+ struct {
368
+ unsigned char op_code;
369
+ char lhs_type;
370
+ char lhs[16];
371
+ char rhs_type;
372
+ char rhs[16];
373
+ } PARAM_EXPR_ELEM_V13;
374
+
375
+ The ``op_code`` field is used to define the operation added to the :class:`.ParameterExpression`.
376
+ The value can be:
377
+
378
+ .. list-table:: PARAM_EXPR_ELEM_V13 op code values
379
+ :header-rows: 1
380
+
381
+ * - ``op_code``
382
+ - :class:`.ParameterExpression` method
383
+ * - 0
384
+ - :meth:`~.ParameterExpression.__add__`
385
+ * - 1
386
+ - :meth:`~.ParameterExpression.__sub__`
387
+ * - 2
388
+ - :meth:`~.ParameterExpression.__mul__`
389
+ * - 3
390
+ - :meth:`~.ParameterExpression.__truediv__`
391
+ * - 4
392
+ - :meth:`~.ParameterExpression.__pow__`
393
+ * - 5
394
+ - :meth:`~.ParameterExpression.sin`
395
+ * - 6
396
+ - :meth:`~.ParameterExpression.cos`
397
+ * - 7
398
+ - :meth:`~.ParameterExpression.tan`
399
+ * - 8
400
+ - :meth:`~.ParameterExpression.arcsin`
401
+ * - 9
402
+ - :meth:`~.ParameterExpression.arccos`
403
+ * - 10
404
+ - :meth:`~.ParameterExpression.exp`
405
+ * - 11
406
+ - :meth:`~.ParameterExpression.log`
407
+ * - 12
408
+ - :meth:`~.ParameterExpression.sign`
409
+ * - 13
410
+ - :meth:`~.ParameterExpression.gradient`
411
+ * - 14
412
+ - :meth:`~.ParameterExpression.conjugate`
413
+ * - 15
414
+ - :meth:`~.ParameterExpression.subs`
415
+ * - 16
416
+ - :meth:`~.ParameterExpression.abs`
417
+ * - 17
418
+ - :meth:`~.ParameterExpression.arctan`
419
+ * - 255
420
+ - NULL
421
+
422
+ The ``NULL`` value of 255 is only used to fill the op code field for
423
+ entries that are not actual operations but indicate recursive definitions.
424
+ Then the ``lhs_type`` and ``rhs_type`` fields are used to describe
425
+ the operand types and can be one of the following UTF-8 encoded
426
+ characters:
427
+
428
+ .. list-table:: PARAM_EXPR_ELEM_V13 operand type values
429
+ :header-rows: 1
430
+
431
+ * - Value
432
+ - Type
433
+ * - ``n``
434
+ - ``None``
435
+ * - ``p``
436
+ - :class:`.Parameter`
437
+ * - ``f``
438
+ - ``float``
439
+ * - ``c``
440
+ - ``complex``
441
+ * - ``i``
442
+ - ``int``
443
+ * - ``s``
444
+ - Recursive :class:`.ParameterExpression` definition start
445
+ * - ``e``
446
+ - Recursive :class:`.ParameterExpression` definition stop
447
+ * - ``u``
448
+ - substitution
449
+
450
+ If the type value is ``f`` ,``c`` or ``i``, the corresponding ``lhs`` or `rhs``
451
+ field widths are 128 bits each. In the case of floats, the literal value is encoded as a double
452
+ with 0 padding, while complex numbers are encoded as real part followed by imaginary part,
453
+ taking up 64 bits each. For ``i`, the value is encoded as a 64 bit signed integer with 0 padding
454
+ for the full 128 bit width. ``n`` is used to represent a ``None`` and typically isn't directly used
455
+ as it indicates an argument that's not used. For ``p`` the data is the UUID for the
456
+ :class:`.Parameter` which can be looked up in the symbol map described in the
457
+ ``map_elements`` outer :ref:`qpy_param_expr_v3` payload. If the type value is
458
+ ``s`` this marks the start of a a new recursive section for a nested
459
+ :class:`.ParameterExpression`. For example, in the following snippet there is an inner ``expr``
460
+ contained in ``final_expr``, constituting a nested expression::
461
+
462
+ from qiskit.circuit import Parameter
463
+
464
+ x = Parameter("x")
465
+ y = Parameter("y")
466
+ z = Parameter("z")
467
+
468
+ expr = (x + y) / 2
469
+ final_expr = z**2 + expr
470
+
471
+ When ``s`` is encountered, this indicates that until an ``e` struct is reached, the next structs
472
+ are used for a recursive definition. For both
473
+ ``s`` and ``e`` types, the data values are not used, and always set to 0. The type value
474
+ of ``u`` is used to represent a substitution call. This is only used for ``lhs_type``
475
+ and is always paired with an ``rhs_type`` of ``n``. The data value is the size in bytes of
476
+ a :ref:`qpy_mapping` encoded mapping of :class:`.Parameter` names to their value for the
477
+ :meth:`~.ParameterExpression.subs` call. The mapping data is immediately following the
478
+ struct, and the next struct starts immediately after the mapping data.
479
+
480
+ .. _qpy_version_12:
481
+
482
+ Version 12
483
+ ----------
484
+
485
+ Version 12 adds support for:
486
+
487
+ * circuits containing memory-owning :class:`.expr.Var` variables.
488
+
489
+ Changes to HEADER
490
+ ~~~~~~~~~~~~~~~~~
491
+
492
+ The HEADER struct for an individual circuit has added three ``uint32_t`` counts of the input,
493
+ captured and locally declared variables in the circuit. The new form looks like:
494
+
495
+ .. code-block:: c
496
+
497
+ struct {
498
+ uint16_t name_size;
499
+ char global_phase_type;
500
+ uint16_t global_phase_size;
501
+ uint32_t num_qubits;
502
+ uint32_t num_clbits;
503
+ uint64_t metadata_size;
504
+ uint32_t num_registers;
505
+ uint64_t num_instructions;
506
+ uint32_t num_vars;
507
+ } HEADER_V12;
508
+
509
+ The ``HEADER_V12`` struct is followed immediately by the same name, global-phase, metadata
510
+ and register information as the V2 version of the header. Immediately following the registers is
511
+ ``num_vars`` instances of ``EXPR_VAR_STANDALONE`` that define the variables in this circuit. After
512
+ that, the data continues with custom definitions and instructions as in prior versions of QPY.
513
+
514
+
515
+ EXPR_VAR_DECLARATION
516
+ ~~~~~~~~~~~~~~~~~~~~
517
+
518
+ An ``EXPR_VAR_DECLARATION`` defines an :class:`.expr.Var` instance that is standalone; that is, it
519
+ represents a self-owned memory location rather than wrapping a :class:`.Clbit` or
520
+ :class:`.ClassicalRegister`. The payload is a C struct:
521
+
522
+ .. code-block:: c
523
+
524
+ struct {
525
+ char uuid_bytes[16];
526
+ char usage;
527
+ uint16_t name_size;
528
+ }
529
+
530
+ which is immediately followed by an ``EXPR_TYPE`` payload and then ``name_size`` bytes of UTF-8
531
+ encoding string data containing the name of the variable.
532
+
533
+ The ``char`` usage type code takes the following values:
534
+
535
+ ========= =========================================================================================
536
+ Type code Meaning
537
+ ========= =========================================================================================
538
+ ``I`` An ``input`` variable to the circuit.
539
+
540
+ ``C`` A ``capture`` variable to the circuit.
541
+
542
+ ``L`` A locally declared variable to the circuit.
543
+ ========= =========================================================================================
544
+
545
+
546
+ Changes to EXPR_VAR
547
+ ~~~~~~~~~~~~~~~~~~~
548
+
549
+ The EXPR_VAR variable has gained a new type code and payload, in addition to the pre-existing ones:
550
+
551
+ =========================== ========= ============================================================
552
+ Python class Type code Payload
553
+ =========================== ========= ============================================================
554
+ :class:`.UUID` ``U`` One ``uint32_t`` index of the variable into the series of
555
+ ``EXPR_VAR_STANDALONE`` variables that were written
556
+ immediately after the circuit header.
557
+ =========================== ========= ============================================================
558
+
559
+ Notably, this new type-code indexes into pre-defined variables from the circuit header, rather than
560
+ redefining the variable again in each location it is used.
561
+
562
+
563
+ Changes to EXPRESSION
564
+ ---------------------
565
+
566
+ The EXPRESSION type code has a new possible entry, ``i``, corresponding to :class:`.expr.Index`
567
+ nodes.
568
+
569
+ ====================== ========= ======================================================= ========
570
+ Qiskit class Type code Payload Children
571
+ ====================== ========= ======================================================= ========
572
+ :class:`~.expr.Index` ``i`` No additional payload. The children are the target 2
573
+ and the index, in that order.
574
+ ====================== ========= ======================================================= ========
575
+
576
+
577
+ .. _qpy_version_11:
578
+
579
+ Version 11
580
+ ----------
581
+
582
+ Version 11 is identical to Version 10 except for the following.
583
+ First, the names in the CUSTOM_INSTRUCTION blocks
584
+ have a suffix of the form ``"_{uuid_hex}"`` where ``uuid_hex`` is a uuid
585
+ hexadecimal string such as returned by :attr:`.UUID.hex`. For example:
586
+ ``"b3ecab5b4d6a4eb6bc2b2dbf18d83e1e"``.
587
+ Second, it adds support for :class:`.AnnotatedOperation`
588
+ objects. The base operation of an annotated operation is stored using the INSTRUCTION block,
589
+ and an additional ``type`` value ``'a'``is added to indicate that the custom instruction is an
590
+ annotated operation. The list of modifiers are stored as instruction parameters using INSTRUCTION_PARAM,
591
+ with an additional value ``'m'`` is added to indicate that the parameter is of type
592
+ :class:`~qiskit.circuit.annotated_operation.Modifier`. Each modifier is stored using the
593
+ MODIFIER struct.
594
+
595
+ .. _modifier_qpy:
596
+
597
+ MODIFIER
598
+ ~~~~~~~~
599
+
600
+ This represents :class:`~qiskit.circuit.annotated_operation.Modifier`
601
+
602
+ .. code-block:: c
603
+
604
+ struct {
605
+ char type;
606
+ uint32_t num_ctrl_qubits;
607
+ uint32_t ctrl_state;
608
+ double power;
609
+ }
610
+
611
+ This is sufficient to store different types of modifiers required for serializing objects
612
+ of type :class:`.AnnotatedOperation`.
613
+ The field ``type`` is either ``'i'``, ``'c'`` or ``'p'``, representing whether the modifier
614
+ is respectively an inverse modifier, a control modifier or a power modifier. In the second
615
+ case, the fields ``num_ctrl_qubits`` and ``ctrl_state`` specify the control logic of the base
616
+ operation, and in the third case the field ``power`` represents the power of the base operation.
617
+
618
+ .. _qpy_version_10:
619
+
620
+ Version 10
621
+ ----------
622
+
623
+ Version 10 adds support for:
624
+
625
+ * symengine-native serialization for objects of type :class:`~.ParameterExpression` as well as
626
+ symbolic expressions in Pulse schedule blocks.
627
+ * new fields in the :class:`~.TranspileLayout` class added in the Qiskit 0.45.0 release.
628
+
629
+ The symbolic_encoding field is added to the file header, and a new encoding type char
630
+ is introduced, mapped to each symbolic library as follows: ``p`` refers to sympy
631
+ encoding and ``e`` refers to symengine encoding.
632
+
633
+ Changes to FILE_HEADER
634
+ ~~~~~~~~~~~~~~~~~~~~~~
635
+
636
+ The contents of FILE_HEADER after V10 are defined as a C struct as:
637
+
638
+ .. code-block:: c
639
+
640
+ struct {
641
+ uint8_t qpy_version;
642
+ uint8_t qiskit_major_version;
643
+ uint8_t qiskit_minor_version;
644
+ uint8_t qiskit_patch_version;
645
+ uint64_t num_circuits;
646
+ char symbolic_encoding;
647
+ } FILE_HEADER_V10;
648
+
649
+ Changes to LAYOUT
650
+ ~~~~~~~~~~~~~~~~~
651
+
652
+ The ``LAYOUT`` struct is updated to have an additional ``input_qubit_count`` field.
653
+ With version 10 the ``LAYOUT`` struct is now:
654
+
655
+ .. code-block:: c
656
+
657
+ struct {
658
+ char exists;
659
+ int32_t initial_layout_size;
660
+ int32_t input_mapping_size;
661
+ int32_t final_layout_size;
662
+ uint32_t extra_registers;
663
+ int32_t input_qubit_count;
664
+ }
665
+
666
+ The rest of the layout data after the ``LAYOUT`` struct is represented as in previous versions. If
667
+ ``input qubit_count`` is < 0 that indicates that both ``_input_qubit_count``
668
+ and ``_output_qubit_list`` in the :class:`~.TranspileLayout` object are ``None``.
669
+
670
+ .. _qpy_version_9:
671
+
672
+ Version 9
673
+ ---------
674
+
675
+ Version 9 adds support for classical :class:`~.expr.Expr` nodes and their associated
676
+ :class:`~.types.Type`\\ s.
677
+
678
+
679
+ EXPRESSION
680
+ ~~~~~~~~~~
681
+
682
+ An :class:`~.expr.Expr` node is represented by a stream of variable-width data. A node itself is
683
+ represented by (in order in the byte stream):
684
+
685
+ #. a one-byte type code discriminator;
686
+ #. an EXPR_TYPE object;
687
+ #. a type-code-specific additional payload;
688
+ #. a type-code-specific number of child EXPRESSION payloads (the number of these is implied by the
689
+ type code and not explicitly stored).
690
+
691
+ Each of these are described in the following table:
692
+
693
+ ====================== ========= ======================================================= ========
694
+ Qiskit class Type code Payload Children
695
+ ====================== ========= ======================================================= ========
696
+ :class:`~.expr.Var` ``x`` One EXPR_VAR. 0
697
+
698
+ :class:`~.expr.Value` ``v`` One EXPR_VALUE. 0
699
+
700
+ :class:`~.expr.Cast` ``c`` One ``_Bool`` that corresponds to the value of 1
701
+ ``implicit``.
702
+
703
+ :class:`~.expr.Unary` ``u`` One ``uint8_t`` with the same numeric value as the 1
704
+ :class:`.Unary.Op`.
705
+
706
+ :class:`~.expr.Binary` ``b`` One ``uint8_t`` with the same numeric value as the 2
707
+ :class:`.Binary.Op`.
708
+ ====================== ========= ======================================================= ========
709
+
710
+
711
+ EXPR_TYPE
712
+ ~~~~~~~~~
713
+
714
+ A :class:`~.types.Type` is encoded by a single-byte ASCII ``char`` that encodes the kind of type,
715
+ followed by a payload that varies depending on the type. The defined codes are:
716
+
717
+ ====================== ========= =================================================================
718
+ Qiskit class Type code Payload
719
+ ====================== ========= =================================================================
720
+ :class:`~.types.Bool` ``b`` None.
721
+
722
+ :class:`~.types.Uint` ``u`` One ``uint32_t width``.
723
+ ====================== ========= =================================================================
724
+
725
+
726
+ EXPR_VAR
727
+ ~~~~~~~~
728
+
729
+ This represents a runtime variable of a :class:`~.expr.Var` node. These are a type code, followed
730
+ by a type-code-specific payload:
731
+
732
+ =========================== ========= ============================================================
733
+ Python class Type code Payload
734
+ =========================== ========= ============================================================
735
+ :class:`.Clbit` ``C`` One ``uint32_t index`` that is the index of the
736
+ :class:`.Clbit` in the containing circuit.
737
+
738
+ :class:`.ClassicalRegister` ``R`` One ``uint16_t reg_name_size``, followed by that many bytes
739
+ of UTF-8 string data of the register name.
740
+ =========================== ========= ============================================================
741
+
742
+
743
+ EXPR_VALUE
744
+ ~~~~~~~~~~
745
+
746
+ This represents a literal object in the classical type system, such as an integer. Currently there
747
+ are very few such literals. These are encoded as a type code, followed by a type-code-specific
748
+ payload.
749
+
750
+ =========== ========= ============================================================================
751
+ Python type Type code Payload
752
+ =========== ========= ============================================================================
753
+ ``bool`` ``b`` One ``_Bool value``.
754
+
755
+ ``int`` ``i`` One ``uint8_t num_bytes``, followed by the integer encoded into that many
756
+ many bytes (network order) in a two's complement representation.
757
+ =========== ========= ============================================================================
758
+
759
+
760
+
761
+ Changes to INSTRUCTION
762
+ ~~~~~~~~~~~~~~~~~~~~~~
763
+
764
+ To support the use of :class:`~.expr.Expr` nodes in the fields :attr:`.IfElseOp.condition`,
765
+ :attr:`.WhileLoopOp.condition` and :attr:`.SwitchCaseOp.target`, the INSTRUCTION struct is changed
766
+ in an ABI compatible-manner to :ref:`its previous definition <qpy_instruction_v5>`. The new struct
767
+ is the C struct:
768
+
769
+ .. code-block:: c
770
+
771
+ struct {
772
+ uint16_t name_size;
773
+ uint16_t label_size;
774
+ uint16_t num_parameters;
775
+ uint32_t num_qargs;
776
+ uint32_t num_cargs;
777
+ uint8_t conditional_key;
778
+ uint16_t conditional_reg_name_size;
779
+ int64_t conditional_value;
780
+ uint32_t num_ctrl_qubits;
781
+ uint32_t ctrl_state;
782
+ }
783
+
784
+ where the only change is that a ``uint8_t conditional_key`` entry has replaced ``_Bool
785
+ has_conditional``. This new ``conditional_key`` takes the following numeric values, with these
786
+ effects:
787
+
788
+ ===== =============================================================================================
789
+ Value Effects
790
+ ===== =============================================================================================
791
+ 0 The instruction has its ``.condition`` field set to ``None``. The
792
+ ``conditional_reg_name_size`` and ``conditional_value`` fields should be ignored.
793
+
794
+ 1 The instruction has its ``.condition`` field set to a 2-tuple of either a :class:`.Clbit`
795
+ or a :class:`.ClassicalRegister`, and a integer of value ``conditional_value``. The
796
+ INSTRUCTION payload, including its trailing data is parsed exactly as it would be in QPY
797
+ versions less than 8.
798
+
799
+ 2 The instruction has its ``.condition`` field set to a :class:`~.expr.Expr` node. The
800
+ ``conditional_reg_name_size`` and ``conditional_value`` fields should be ignored. The data
801
+ following the struct is followed (as in QPY versions less than 8) by ``name_size`` bytes of
802
+ UTF-8 string data for the class name and ``label_size`` bytes of UTF-8 string data for the
803
+ label (if any). Then, there is one INSTRUCTION_PARAM, which will contain an EXPRESSION. After
804
+ that, parsing continues with the INSTRUCTION_ARG structs, as in previous versions of QPY.
805
+ ===== =============================================================================================
806
+
807
+
808
+ Changes to INSTRUCTION_PARAM
809
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
810
+
811
+ A new type code ``x`` is added that defines an EXPRESSION parameter.
812
+
813
+
814
+ .. _qpy_version_8:
815
+
816
+ Version 8
817
+ ---------
818
+
819
+ Version 8 adds support for handling a :class:`~.TranspileLayout` stored in the
820
+ :attr:`.QuantumCircuit.layout` attribute. In version 8 immediately following the
821
+ calibrations block at the end of the circuit payload there is now the
822
+ ``LAYOUT`` struct. This struct outlines the size of the three attributes of a
823
+ :class:`~.TranspileLayout` class.
824
+
825
+ LAYOUT
826
+ ~~~~~~
827
+
828
+ .. code-block:: c
829
+
830
+ struct {
831
+ char exists;
832
+ int32_t initial_layout_size;
833
+ int32_t input_mapping_size;
834
+ int32_t final_layout_size;
835
+ uint32_t extra_registers;
836
+ }
837
+
838
+ If any of the signed values are ``-1`` this indicates the corresponding
839
+ attribute is ``None``.
840
+
841
+ Immediately following the ``LAYOUT`` struct there is a :ref:`qpy_registers` struct
842
+ for ``extra_registers`` (specifically the format introduced in :ref:`qpy_version_4`)
843
+ standalone register definitions that aren't present in the circuit. Then there
844
+ are ``initial_layout_size`` ``INITIAL_LAYOUT_BIT`` structs to define the
845
+ :attr:`.TranspileLayout.initial_layout` attribute.
846
+
847
+ INITIAL_LAYOUT_BIT
848
+ ~~~~~~~~~~~~~~~~~~
849
+
850
+ .. code-block:: c
851
+
852
+ struct {
853
+ int32_t index;
854
+ int32_t register_size;
855
+ }
856
+
857
+ Where a value of ``-1`` indicates ``None`` (as in no register is associated
858
+ with the bit). Following each ``INITIAL_LAYOUT_BIT`` struct is ``register_size``
859
+ bytes for a ``utf8`` encoded string for the register name.
860
+
861
+ Following the initial layout there is ``input_mapping_size`` array of
862
+ ``uint32_t`` integers representing the positions of the physical bit from the
863
+ initial layout. This enables constructing a list of virtual bits where the
864
+ array index is its input mapping position.
865
+
866
+ Finally, there is an array of ``final_layout_size`` ``uint32_t`` integers. Each
867
+ element is an index in the circuit's ``qubits`` attribute which enables building
868
+ a mapping from qubit starting position to the output position at the end of the
869
+ circuit.
870
+
871
+ .. _qpy_version_7:
872
+
873
+ Version 7
874
+ ---------
875
+
876
+ Version 7 adds support for :class:`.~Reference` instruction and serialization of
877
+ a :class:`.~ScheduleBlock` program while keeping its reference to subroutines::
878
+
879
+ from qiskit import pulse
880
+ from qiskit import qpy
881
+
882
+ with pulse.build() as schedule:
883
+ pulse.reference("cr45p", "q0", "q1")
884
+ pulse.reference("x", "q0")
885
+ pulse.reference("cr45p", "q0", "q1")
886
+
887
+ with open('template_ecr.qpy', 'wb') as fd:
888
+ qpy.dump(schedule, fd)
889
+
890
+ The conventional :ref:`qpy_schedule_block` data model is preserved, but in
891
+ version 7 it is immediately followed by an extra :ref:`qpy_mapping` utf8 bytes block
892
+ representing the data of the referenced subroutines.
893
+
894
+ New type key character is added to the :ref:`qpy_schedule_instructions` group
895
+ for the :class:`.~Reference` instruction.
896
+
897
+ - ``y``: :class:`~qiskit.pulse.instructions.Reference` instruction
898
+
899
+ New type key character is added to the :ref:`qpy_schedule_operands` group
900
+ for the operands of :class:`.~Reference` instruction,
901
+ which is a tuple of strings, e.g. ("cr45p", "q0", "q1").
902
+
903
+ - ``o``: string (operand string)
904
+
905
+ Note that this is the same encoding with the built-in Python string, however,
906
+ the standard value encoding in QPY uses ``s`` type character for string data,
907
+ which conflicts with the :class:`~qiskit.pulse.library.SymbolicPulse` in the scope of
908
+ pulse instruction operands. A special type character ``o`` is reserved for
909
+ the string data that appears in the pulse instruction operands.
910
+
911
+ In addition, version 7 adds two new type keys to the INSTRUCTION_PARM struct. ``"d"`` is followed
912
+ by no data and represents the literal value :data:`.CASE_DEFAULT` for switch-statement support.
913
+ ``"R"`` represents a :class:`.ClassicalRegister` or :class:`.Clbit`, and is followed by the same
914
+ format as the description of register or classical bit as used in the first element of :ref:`the
915
+ condition of an INSTRUCTION field <qpy_instructions>`.
916
+
917
+ .. _qpy_version_6:
918
+
919
+ Version 6
920
+ ---------
921
+
922
+ Version 6 adds support for :class:`.~ScalableSymbolicPulse`. These objects are saved and read
923
+ like `SymbolicPulse` objects, and the class name is added to the data to correctly handle
924
+ the class selection.
925
+
926
+ `SymbolicPulse` block now starts with SYMBOLIC_PULSE_V2 header:
927
+
928
+ .. code-block:: c
929
+
930
+ struct {
931
+ uint16_t class_name_size;
932
+ uint16_t type_size;
933
+ uint16_t envelope_size;
934
+ uint16_t constraints_size;
935
+ uint16_t valid_amp_conditions_size;
936
+ _bool amp_limited;
937
+ }
938
+
939
+ The only change compared to :ref:`qpy_version_5` is the addition of `class_name_size`. The header
940
+ is then immediately followed by ``class_name_size`` utf8 bytes with the name of the class. Currently,
941
+ either `SymbolicPulse` or `ScalableSymbolicPulse` are supported. The rest of the data is then
942
+ identical to :ref:`qpy_version_5`.
943
+
944
+ .. _qpy_version_5:
945
+
946
+ Version 5
947
+ ---------
948
+
949
+ Version 5 changes from :ref:`qpy_version_4` by adding support for :class:`.~ScheduleBlock`
950
+ and changing two payloads the INSTRUCTION metadata payload and the CUSTOM_INSTRUCTION block.
951
+ These now have new fields to better account for :class:`~.ControlledGate` objects in a circuit.
952
+ In addition, new payload MAP_ITEM is defined to implement the :ref:`qpy_mapping` block.
953
+
954
+ With the support of :class:`.~ScheduleBlock`, now :class:`~.QuantumCircuit` can be
955
+ serialized together with :attr:`~.QuantumCircuit.calibrations`, or
956
+ `Pulse Gates <https://docs.quantum.ibm.com/guides/pulse>`_.
957
+ In QPY version 5 and above, :ref:`qpy_circuit_calibrations` payload is
958
+ packed after the :ref:`qpy_instructions` block.
959
+
960
+ In QPY version 5 and above,
961
+
962
+ .. code-block:: c
963
+
964
+ struct {
965
+ char type;
966
+ }
967
+
968
+ immediately follows the file header block to represent the program type stored in the file.
969
+
970
+ - When ``type==c``, :class:`~.QuantumCircuit` payload follows
971
+ - When ``type==s``, :class:`~.ScheduleBlock` payload follows
972
+
973
+ .. note::
974
+
975
+ Different programs cannot be packed together in the same file.
976
+ You must create different files for different program types.
977
+ Multiple objects with the same type can be saved in a single file.
978
+
979
+ .. _qpy_schedule_block:
980
+
981
+ SCHEDULE_BLOCK
982
+ ~~~~~~~~~~~~~~
983
+
984
+ :class:`~.ScheduleBlock` is first supported in QPY Version 5. This allows
985
+ users to save pulse programs in the QPY binary format as follows:
986
+
987
+ .. code-block:: python
988
+
989
+ from qiskit import pulse, qpy
990
+
991
+ with pulse.build() as schedule:
992
+ pulse.play(pulse.Gaussian(160, 0.1, 40), pulse.DriveChannel(0))
993
+
994
+ with open('schedule.qpy', 'wb') as fd:
995
+ qpy.dump(qc, fd)
996
+
997
+ with open('schedule.qpy', 'rb') as fd:
998
+ new_qc = qpy.load(fd)[0]
999
+
1000
+ Note that circuit and schedule block are serialized and deserialized through
1001
+ the same QPY interface. Input data type is implicitly analyzed and
1002
+ no extra option is required to save the schedule block.
1003
+
1004
+ .. _qpy_schedule_block_header:
1005
+
1006
+ SCHEDULE_BLOCK_HEADER
1007
+ ~~~~~~~~~~~~~~~~~~~~~
1008
+
1009
+ :class:`~.ScheduleBlock` block starts with the following header:
1010
+
1011
+ .. code-block:: c
1012
+
1013
+ struct {
1014
+ uint16_t name_size;
1015
+ uint64_t metadata_size;
1016
+ uint16_t num_element;
1017
+ }
1018
+
1019
+ which is immediately followed by ``name_size`` utf8 bytes of schedule name and
1020
+ ``metadata_size`` utf8 bytes of the JSON serialized metadata dictionary
1021
+ attached to the schedule.
1022
+
1023
+ .. _qpy_schedule_alignments:
1024
+
1025
+ SCHEDULE_BLOCK_ALIGNMENTS
1026
+ ~~~~~~~~~~~~~~~~~~~~~~~~~
1027
+
1028
+ Then, alignment context of the schedule block starts with ``char``
1029
+ representing the supported context type followed by the :ref:`qpy_sequence` block representing
1030
+ the parameters associated with the alignment context :attr:`AlignmentKind._context_params`.
1031
+ The context type char is mapped to each alignment subclass as follows:
1032
+
1033
+ - ``l``: :class:`~.AlignLeft`
1034
+ - ``r``: :class:`~.AlignRight`
1035
+ - ``s``: :class:`~.AlignSequential`
1036
+ - ``e``: :class:`~.AlignEquispaced`
1037
+
1038
+ Note that :class:`~.AlignFunc` context is not supported because of the callback function
1039
+ stored in the context parameters.
1040
+
1041
+ .. _qpy_schedule_instructions:
1042
+
1043
+ SCHEDULE_BLOCK_INSTRUCTIONS
1044
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
1045
+
1046
+ This alignment block is further followed by ``num_element`` length of block elements which may
1047
+ consist of nested schedule blocks and schedule instructions.
1048
+ Each schedule instruction starts with ``char`` representing the instruction type
1049
+ followed by the :ref:`qpy_sequence` block representing the instruction
1050
+ :attr:`~qiskit.pulse.instructions.Instruction.operands`.
1051
+ Note that the data structure of pulse :class:`~qiskit.pulse.instructions.Instruction`
1052
+ is unified so that instance can be uniquely determined by the class and a tuple of operands.
1053
+ The mapping of type char to the instruction subclass is defined as follows:
1054
+
1055
+ - ``a``: :class:`~qiskit.pulse.instructions.Acquire` instruction
1056
+ - ``p``: :class:`~qiskit.pulse.instructions.Play` instruction
1057
+ - ``d``: :class:`~qiskit.pulse.instructions.Delay` instruction
1058
+ - ``f``: :class:`~qiskit.pulse.instructions.SetFrequency` instruction
1059
+ - ``g``: :class:`~qiskit.pulse.instructions.ShiftFrequency` instruction
1060
+ - ``q``: :class:`~qiskit.pulse.instructions.SetPhase` instruction
1061
+ - ``r``: :class:`~qiskit.pulse.instructions.ShiftPhase` instruction
1062
+ - ``b``: :class:`~qiskit.pulse.instructions.RelativeBarrier` instruction
1063
+ - ``t``: :class:`~qiskit.pulse.instructions.TimeBlockade` instruction
1064
+ - ``y``: :class:`~qiskit.pulse.instructions.Reference` instruction (new in version 0.7)
1065
+
1066
+ .. _qpy_schedule_operands:
1067
+
1068
+ SCHEDULE_BLOCK_OPERANDS
1069
+ ~~~~~~~~~~~~~~~~~~~~~~~
1070
+
1071
+ The operands of these instances can be serialized through the standard QPY value serialization
1072
+ mechanism, however there are special object types that only appear in the schedule operands.
1073
+ Since the operands are serialized as :ref:`qpy_sequence`, each element must be packed with the
1074
+ INSTRUCTION_PARAM pack struct, where each payload starts with a header block consists of
1075
+ the char ``type`` and uint64_t ``size``.
1076
+ Special objects start with the following type key:
1077
+
1078
+ - ``c``: :class:`~qiskit.pulse.channels.Channel`
1079
+ - ``w``: :class:`~qiskit.pulse.library.Waveform`
1080
+ - ``s``: :class:`~qiskit.pulse.library.SymbolicPulse`
1081
+ - ``o``: string (operand string, new in version 0.7)
1082
+
1083
+ .. _qpy_schedule_channel:
1084
+
1085
+ CHANNEL
1086
+ ~~~~~~~
1087
+
1088
+ Channel block starts with channel subtype ``char`` that maps an object data to
1089
+ :class:`~qiskit.pulse.channels.Channel` subclass. Mapping is defined as follows:
1090
+
1091
+ - ``d``: :class:`~qiskit.pulse.channels.DriveChannel`
1092
+ - ``c``: :class:`~qiskit.pulse.channels.ControlChannel`
1093
+ - ``m``: :class:`~qiskit.pulse.channels.MeasureChannel`
1094
+ - ``a``: :class:`~qiskit.pulse.channels.AcquireChannel`
1095
+ - ``e``: :class:`~qiskit.pulse.channels.MemorySlot`
1096
+ - ``r``: :class:`~qiskit.pulse.channels.RegisterSlot`
1097
+
1098
+ The key is immediately followed by the channel index serialized as the INSTRUCTION_PARAM.
1099
+
1100
+ .. _qpy_schedule_waveform:
1101
+
1102
+ Waveform
1103
+ ~~~~~~~~
1104
+
1105
+ Waveform block starts with WAVEFORM header:
1106
+
1107
+ .. code-block:: c
1108
+
1109
+ struct {
1110
+ double epsilon;
1111
+ uint32_t data_size;
1112
+ _bool amp_limited;
1113
+ }
1114
+
1115
+ which is followed by ``data_size`` bytes of complex ``ndarray`` binary generated by numpy.save_.
1116
+ This represents the complex IQ data points played on a quantum device.
1117
+ :attr:`~qiskit.pulse.library.Waveform.name` is saved after the samples in the
1118
+ INSTRUCTION_PARAM pack struct, which can be string or ``None``.
1119
+
1120
+ .. _numpy.save: https://numpy.org/doc/stable/reference/generated/numpy.save.html
1121
+
1122
+ .. _qpy_schedule_symbolic_pulse:
1123
+
1124
+ SymbolicPulse
1125
+ ~~~~~~~~~~~~~
1126
+
1127
+ SymbolicPulse block starts with SYMBOLIC_PULSE header:
1128
+
1129
+ .. code-block:: c
1130
+
1131
+ struct {
1132
+ uint16_t type_size;
1133
+ uint16_t envelope_size;
1134
+ uint16_t constraints_size;
1135
+ uint16_t valid_amp_conditions_size;
1136
+ _bool amp_limited;
1137
+ }
1138
+
1139
+ which is followed by ``type_size`` utf8 bytes of :attr:`.SymbolicPulse.pulse_type` string
1140
+ that represents a class of waveform, such as "Gaussian" or "GaussianSquare".
1141
+ Then, ``envelope_size``, ``constraints_size``, ``valid_amp_conditions_size`` utf8 bytes of
1142
+ serialized symbolic expressions are generated for :attr:`.SymbolicPulse.envelope`,
1143
+ :attr:`.SymbolicPulse.constraints`, and :attr:`.SymbolicPulse.valid_amp_conditions`, respectively.
1144
+ Since string representation of these expressions are usually lengthy,
1145
+ the expression binary is generated by the python zlib_ module with data compression.
1146
+
1147
+ To uniquely specify a pulse instance, we also need to store the associated parameters,
1148
+ which consist of ``duration`` and the rest of parameters as a dictionary.
1149
+ Dictionary parameters are first dumped in the :ref:`qpy_mapping` form, and then ``duration``
1150
+ is dumped with the INSTRUCTION_PARAM pack struct.
1151
+ Lastly, :attr:`~qiskit.pulse.library.SymbolicPulse.name` is saved also with the
1152
+ INSTRUCTION_PARAM pack struct, which can be string or ``None``.
1153
+
1154
+ .. _zlib: https://docs.python.org/3/library/zlib.html
1155
+
1156
+ .. _qpy_mapping:
1157
+
1158
+ MAPPING
1159
+ ~~~~~~~
1160
+
1161
+ The MAPPING is a representation for arbitrary mapping object. This is a fixed length
1162
+ :ref:`qpy_sequence` of key-value pair represented by the MAP_ITEM payload.
1163
+
1164
+ A MAP_ITEM starts with a header defined as:
1165
+
1166
+ .. code-block:: c
1167
+
1168
+ struct {
1169
+ uint16_t key_size;
1170
+ char type;
1171
+ uint16_t size;
1172
+ }
1173
+
1174
+ which is immediately followed by the ``key_size`` utf8 bytes representing
1175
+ the dictionary key in string and ``size`` utf8 bytes of arbitrary object data of
1176
+ QPY serializable ``type``.
1177
+
1178
+ .. _qpy_circuit_calibrations:
1179
+
1180
+ CIRCUIT_CALIBRATIONS
1181
+ ~~~~~~~~~~~~~~~~~~~~
1182
+
1183
+ The CIRCUIT_CALIBRATIONS block is a dictionary to define pulse calibrations of the custom
1184
+ instruction set. This block starts with the following CALIBRATION header:
1185
+
1186
+ .. code-block:: c
1187
+
1188
+ struct {
1189
+ uint16_t num_cals;
1190
+ }
1191
+
1192
+ which is followed by the ``num_cals`` length of calibration entries, each starts with
1193
+ the CALIBRATION_DEF header:
1194
+
1195
+ .. code-block:: c
1196
+
1197
+ struct {
1198
+ uint16_t name_size;
1199
+ uint16_t num_qubits;
1200
+ uint16_t num_params;
1201
+ char type;
1202
+ }
1203
+
1204
+ The calibration definition header is then followed by ``name_size`` utf8 bytes of
1205
+ the gate name, ``num_qubits`` length of integers representing a sequence of qubits,
1206
+ and ``num_params`` length of INSTRUCTION_PARAM payload for parameters
1207
+ associated to the custom instruction.
1208
+ The ``type`` indicates the class of pulse program which is either, in principle,
1209
+ :class:`~.ScheduleBlock` or :class:`~.Schedule`. As of QPY Version 5,
1210
+ only :class:`~.ScheduleBlock` payload is supported.
1211
+ Finally, :ref:`qpy_schedule_block` payload is packed for each CALIBRATION_DEF entry.
1212
+
1213
+ .. _qpy_instruction_v5:
1214
+
1215
+ INSTRUCTION
1216
+ ~~~~~~~~~~~
1217
+
1218
+ The INSTRUCTION block was modified to add two new fields ``num_ctrl_qubits`` and ``ctrl_state``
1219
+ which are used to model the :attr:`.ControlledGate.num_ctrl_qubits` and
1220
+ :attr:`.ControlledGate.ctrl_state` attributes. The new payload packed struct
1221
+ format is:
1222
+
1223
+ .. code-block:: c
1224
+
1225
+ struct {
1226
+ uint16_t name_size;
1227
+ uint16_t label_size;
1228
+ uint16_t num_parameters;
1229
+ uint32_t num_qargs;
1230
+ uint32_t num_cargs;
1231
+ _Bool has_conditional;
1232
+ uint16_t conditional_reg_name_size;
1233
+ int64_t conditional_value;
1234
+ uint32_t num_ctrl_qubits;
1235
+ uint32_t ctrl_state;
1236
+ }
1237
+
1238
+ The rest of the instruction payload is the same. You can refer to
1239
+ :ref:`qpy_instructions` for the details of the full payload.
1240
+
1241
+ CUSTOM_INSTRUCTION
1242
+ ~~~~~~~~~~~~~~~~~~
1243
+
1244
+ The CUSTOM_INSTRUCTION block in QPY version 5 adds a new field
1245
+ ``base_gate_size`` which is used to define the size of the
1246
+ :class:`qiskit.circuit.Instruction` object stored in the
1247
+ :attr:`.ControlledGate.base_gate` attribute for a custom
1248
+ :class:`~.ControlledGate` object. With this change the CUSTOM_INSTRUCTION
1249
+ metadata block becomes:
1250
+
1251
+ .. code-block:: c
1252
+
1253
+ struct {
1254
+ uint16_t name_size;
1255
+ char type;
1256
+ uint32_t num_qubits;
1257
+ uint32_t num_clbits;
1258
+ _Bool custom_definition;
1259
+ uint64_t size;
1260
+ uint32_t num_ctrl_qubits;
1261
+ uint32_t ctrl_state;
1262
+ uint64_t base_gate_size
1263
+ }
1264
+
1265
+ Immediately following the CUSTOM_INSTRUCTION struct is the utf8 encoded name
1266
+ of size ``name_size``.
1267
+
1268
+ If ``custom_definition`` is ``True`` that means that the immediately following
1269
+ ``size`` bytes contains a QPY circuit data which can be used for the custom
1270
+ definition of that gate. If ``custom_definition`` is ``False`` then the
1271
+ instruction can be considered opaque (ie no definition). The ``type`` field
1272
+ determines what type of object will get created with the custom definition.
1273
+ If it's ``'g'`` it will be a :class:`~qiskit.circuit.Gate` object, ``'i'``
1274
+ it will be a :class:`~qiskit.circuit.Instruction` object.
1275
+
1276
+ Following this the next ``base_gate_size`` bytes contain the ``INSTRUCTION``
1277
+ payload for the :attr:`.ControlledGate.base_gate`.
1278
+
1279
+ Additionally an addition value for ``type`` is added ``'c'`` which is used to
1280
+ indicate the custom instruction is a custom :class:`~.ControlledGate`.
1281
+
1282
+ .. _qpy_version_4:
1283
+
1284
+ Version 4
1285
+ ---------
1286
+
1287
+ Version 4 is identical to :ref:`qpy_version_3` except that it adds 2 new type strings
1288
+ to the INSTRUCTION_PARAM struct, ``z`` to represent ``None`` (which is encoded as
1289
+ no data), ``q`` to represent a :class:`.QuantumCircuit` (which is encoded as
1290
+ a QPY circuit), ``r`` to represent a ``range`` of integers (which is encoded as
1291
+ a :ref:`qpy_range_pack`), and ``t`` to represent a ``sequence`` (which is encoded as
1292
+ defined by :ref:`qpy_sequence`). Additionally, version 4 changes the type of register
1293
+ index mapping array from ``uint32_t`` to ``int64_t``. If the values of any of the
1294
+ array elements are negative they represent a register bit that is not present in the
1295
+ circuit.
1296
+
1297
+ The :ref:`qpy_registers` header format has also been updated to
1298
+
1299
+ .. code-block:: c
1300
+
1301
+ struct {
1302
+ char type;
1303
+ _Bool standalone;
1304
+ uint32_t size;
1305
+ uint16_t name_size;
1306
+ _bool in_circuit;
1307
+ }
1308
+
1309
+ which just adds the ``in_circuit`` field which represents whether the register is
1310
+ part of the circuit or not.
1311
+
1312
+ .. _qpy_range_pack:
1313
+
1314
+ RANGE
1315
+ ~~~~~
1316
+
1317
+ A RANGE is a representation of a ``range`` object. It is defined as:
1318
+
1319
+ .. code-block:: c
1320
+
1321
+ struct {
1322
+ int64_t start;
1323
+ int64_t stop;
1324
+ int64_t step;
1325
+ }
1326
+
1327
+ .. _qpy_sequence:
1328
+
1329
+ SEQUENCE
1330
+ ~~~~~~~~
1331
+
1332
+ A SEQUENCE is a representation of an arbitrary sequence object. As sequence are just fixed length
1333
+ containers of arbitrary python objects their QPY can't fully represent any sequence,
1334
+ but as long as the contents in a sequence are other QPY serializable types for
1335
+ the INSTRUCTION_PARAM payload the ``sequence`` object can be serialized.
1336
+
1337
+ A sequence instruction parameter starts with a header defined as:
1338
+
1339
+ .. code-block:: c
1340
+
1341
+ struct {
1342
+ uint64_t size;
1343
+ }
1344
+
1345
+ followed by ``size`` elements that are INSTRUCTION_PARAM payloads, where each of
1346
+ these define an element in the sequence. The sequence object will be typecasted
1347
+ into proper type, e.g. ``tuple``, afterwards.
1348
+
1349
+ .. _qpy_version_3:
1350
+
1351
+ Version 3
1352
+ ---------
1353
+
1354
+ Version 3 of the QPY format is identical to :ref:`qpy_version_2` except that it defines
1355
+ a struct format to represent a :class:`~qiskit.circuit.library.PauliEvolutionGate`
1356
+ natively in QPY. To accomplish this the :ref:`qpy_custom_definition` struct now supports
1357
+ a new type value ``'p'`` to represent a :class:`~qiskit.circuit.library.PauliEvolutionGate`.
1358
+ Enties in the custom instructions tables have unique name generated that start with the
1359
+ string ``"###PauliEvolutionGate_"`` followed by a uuid string. This gate name is reservered
1360
+ in QPY and if you have a custom :class:`~qiskit.circuit.Instruction` object with a definition
1361
+ set and that name prefix it will error. If it's of type ``'p'`` the data payload is defined
1362
+ as follows:
1363
+
1364
+ .. _pauli_evo_qpy:
1365
+
1366
+ PAULI_EVOLUTION
1367
+ ~~~~~~~~~~~~~~~
1368
+
1369
+ This represents the high level :class:`~qiskit.circuit.library.PauliEvolutionGate`
1370
+
1371
+ .. code-block:: c
1372
+
1373
+ struct {
1374
+ uint64_t operator_count;
1375
+ _Bool standalone_op;
1376
+ char time_type;
1377
+ uint64_t time_size;
1378
+ uint64_t synthesis_size;
1379
+ }
1380
+
1381
+ This is immediately followed by ``operator_count`` elements defined by the :ref:`qpy_pauli_sum_op`
1382
+ payload. Following that we have ``time_size`` bytes representing the ``time`` attribute. If
1383
+ ``standalone_op`` is ``True`` then there must only be a single operator. The
1384
+ encoding of these bytes is determined by the value of ``time_type``. Possible values of
1385
+ ``time_type`` are ``'f'``, ``'p'``, and ``'e'``. If ``time_type`` is ``'f'`` it's a double,
1386
+ ``'p'`` defines a :class:`~qiskit.circuit.Parameter` object which is represented by a
1387
+ :ref:`qpy_param_struct`, ``e`` defines a :class:`~qiskit.circuit.ParameterExpression` object
1388
+ (that's not a :class:`~qiskit.circuit.Parameter`) which is represented by a :ref:`qpy_param_expr`.
1389
+ Following that is ``synthesis_size`` bytes which is a utf8 encoded json payload representing
1390
+ the :class:`.EvolutionSynthesis` class used by the gate.
1391
+
1392
+ .. _qpy_pauli_sum_op:
1393
+
1394
+ SPARSE_PAULI_OP_LIST_ELEM
1395
+ ~~~~~~~~~~~~~~~~~~~~~~~~~
1396
+
1397
+ This represents an instance of :class:`.SparsePauliOp`.
1398
+
1399
+
1400
+ .. code-block:: c
1401
+
1402
+ struct {
1403
+ uint32_t pauli_op_size;
1404
+ }
1405
+
1406
+ which is immediately followed by ``pauli_op_size`` bytes which are .npy format [#f2]_
1407
+ data which represents the :class:`~qiskit.quantum_info.SparsePauliOp`.
1408
+
1409
+ Version 3 of the QPY format also defines a struct format to represent a
1410
+ :class:`~qiskit.circuit.ParameterVectorElement` as a distinct subclass from
1411
+ a :class:`~qiskit.circuit.Parameter`. This adds a new parameter type char ``'v'``
1412
+ to represent a :class:`~qiskit.circuit.ParameterVectorElement` which is now
1413
+ supported as a type string value for an INSTRUCTION_PARAM. The payload for these
1414
+ parameters are defined below as :ref:`qpy_param_vector`.
1415
+
1416
+ .. _qpy_param_vector:
1417
+
1418
+ PARAMETER_VECTOR_ELEMENT
1419
+ ~~~~~~~~~~~~~~~~~~~~~~~~
1420
+
1421
+ A PARAMETER_VECTOR_ELEMENT represents a :class:`~qiskit.circuit.ParameterVectorElement`
1422
+ object the data for a INSTRUCTION_PARAM. The contents of the PARAMETER_VECTOR_ELEMENT are
1423
+ defined as:
1424
+
1425
+ .. code-block:: c
1426
+
1427
+ struct {
1428
+ uint16_t vector_name_size;
1429
+ uint64_t vector_size;
1430
+ char uuid[16];
1431
+ uint64_t index;
1432
+ }
1433
+
1434
+ which is immediately followed by ``vector_name_size`` utf8 bytes representing
1435
+ the parameter's vector name.
1436
+
1437
+ .. _qpy_param_expr_v3:
1438
+
1439
+
1440
+ PARAMETER_EXPR
1441
+ ~~~~~~~~~~~~~~
1442
+
1443
+ Additionally, since QPY format version v3 distinguishes between a
1444
+ :class:`~qiskit.circuit.Parameter` and :class:`~qiskit.circuit.ParameterVectorElement`
1445
+ the payload for a :class:`~qiskit.circuit.ParameterExpression` needs to be updated
1446
+ to distinguish between the types. The following is the modified payload format
1447
+ which is mostly identical to the format in Version 1 and :ref:`qpy_version_2` but just
1448
+ modifies the ``map_elements`` struct to include a symbol type field.
1449
+
1450
+ A PARAMETER_EXPR represents a :class:`~qiskit.circuit.ParameterExpression`
1451
+ object that the data for an INSTRUCTION_PARAM. The contents of a PARAMETER_EXPR
1452
+ are defined as:
1453
+
1454
+ .. code-block:: c
1455
+
1456
+ struct {
1457
+ uint64_t map_elements;
1458
+ uint64_t expr_size;
1459
+ }
1460
+
1461
+ Immediately following the header is ``expr_size`` bytes of utf8 data containing
1462
+ the expression string, which is the sympy srepr of the expression for the
1463
+ parameter expression. Following that is a symbol map which contains
1464
+ ``map_elements`` elements with the format
1465
+
1466
+ .. code-block:: c
1467
+
1468
+ struct {
1469
+ char symbol_type;
1470
+ char type;
1471
+ uint64_t size;
1472
+ }
1473
+
1474
+ The ``symbol_type`` key determines the payload type of the symbol representation
1475
+ for the element. If it's ``p`` it represents a :class:`~qiskit.circuit.Parameter`
1476
+ and if it's ``v`` it represents a :class:`~qiskit.circuit.ParameterVectorElement`.
1477
+ The map element struct is immediately followed by the symbol map key payload, if
1478
+ ``symbol_type`` is ``p`` then it is followed immediately by a :ref:`qpy_param_struct`
1479
+ object (both the struct and utf8 name bytes) and if ``symbol_type`` is ``v``
1480
+ then the struct is imediately followed by :ref:`qpy_param_vector` (both the struct
1481
+ and utf8 name bytes). That is followed by ``size`` bytes for the
1482
+ data of the symbol. The data format is dependent on the value of ``type``. If
1483
+ ``type`` is ``p`` then it represents a :class:`~qiskit.circuit.Parameter` and
1484
+ size will be 0, the value will just be the same as the key. Similarly if the
1485
+ ``type`` is ``v`` then it represents a :class:`~qiskit.circuit.ParameterVectorElement`
1486
+ and size will be 0 as the value will just be the same as the key. If
1487
+ ``type`` is ``f`` then it represents a double precision float. If ``type`` is
1488
+ ``c`` it represents a double precision complex, which is represented by the
1489
+ :ref:`qpy_complex`. Finally, if type is ``i`` it represents an integer which is an
1490
+ ``int64_t``.
1491
+
1492
+ .. _qpy_version_2:
1493
+
1494
+ Version 2
1495
+ ---------
1496
+
1497
+ Version 2 of the QPY format is identical to version 1 except for the HEADER
1498
+ section is slightly different. You can refer to the :ref:`qpy_version_1` section
1499
+ for the details on the rest of the payload format.
1500
+
1501
+ HEADER
1502
+ ~~~~~~
1503
+
1504
+ The contents of HEADER are defined as a C struct are:
1505
+
1506
+ .. code-block:: c
1507
+
1508
+ struct {
1509
+ uint16_t name_size;
1510
+ char global_phase_type;
1511
+ uint16_t global_phase_size;
1512
+ uint32_t num_qubits;
1513
+ uint32_t num_clbits;
1514
+ uint64_t metadata_size;
1515
+ uint32_t num_registers;
1516
+ uint64_t num_instructions;
1517
+ }
1518
+
1519
+ This is immediately followed by ``name_size`` bytes of utf8 data for the name
1520
+ of the circuit. Following this is immediately ``global_phase_size`` bytes
1521
+ representing the global phase. The content of that data is dictated by the
1522
+ value of ``global_phase_type``. If it's ``'f'`` the data is a float and is the
1523
+ size of a ``double``. If it's ``'p'`` defines a :class:`~qiskit.circuit.Parameter`
1524
+ object which is represented by a PARAM struct (see below), ``e`` defines a
1525
+ :class:`~qiskit.circuit.ParameterExpression` object (that's not a
1526
+ :class:`~qiskit.circuit.Parameter`) which is represented by a PARAM_EXPR struct
1527
+ (see below).
1528
+
1529
+ .. _qpy_version_1:
1530
+
1531
+ Version 1
1532
+ ---------
1533
+
1534
+ HEADER
1535
+ ~~~~~~
1536
+
1537
+ The contents of HEADER as defined as a C struct are:
1538
+
1539
+ .. code-block:: c
1540
+
1541
+ struct {
1542
+ uint16_t name_size;
1543
+ double global_phase;
1544
+ uint32_t num_qubits;
1545
+ uint32_t num_clbits;
1546
+ uint64_t metadata_size;
1547
+ uint32_t num_registers;
1548
+ uint64_t num_instructions;
1549
+ }
1550
+
1551
+ This is immediately followed by ``name_size`` bytes of utf8 data for the name
1552
+ of the circuit.
1553
+
1554
+ METADATA
1555
+ ~~~~~~~~
1556
+
1557
+ The METADATA field is a UTF8 encoded JSON string. After reading the HEADER
1558
+ (which is a fixed size at the start of the QPY file) and the ``name`` string
1559
+ you then read the ``metadata_size`` number of bytes and parse the JSON to get
1560
+ the metadata for the circuit.
1561
+
1562
+ .. _qpy_registers:
1563
+
1564
+ REGISTERS
1565
+ ~~~~~~~~~
1566
+
1567
+ The contents of REGISTERS is a number of REGISTER object. If num_registers is
1568
+ > 0 then after reading METADATA you read that number of REGISTER structs defined
1569
+ as:
1570
+
1571
+ .. code-block:: c
1572
+
1573
+ struct {
1574
+ char type;
1575
+ _Bool standalone;
1576
+ uint32_t size;
1577
+ uint16_t name_size;
1578
+ }
1579
+
1580
+ ``type`` can be ``'q'`` or ``'c'``.
1581
+
1582
+ Immediately following the REGISTER struct is the utf8 encoded register name of
1583
+ size ``name_size``. After the ``name`` utf8 bytes there is then an array of
1584
+ int64_t values of size ``size`` that contains a map of the register's index to
1585
+ the circuit's qubit index. For example, array element 0's value is the index
1586
+ of the ``register[0]``'s position in the containing circuit's qubits list.
1587
+
1588
+ .. note::
1589
+
1590
+ Prior to QPY :ref:`qpy_version_4` the type of array elements was uint32_t. This was changed
1591
+ to enable negative values which represent bits in the array not present in the
1592
+ circuit
1593
+
1594
+
1595
+ The standalone boolean determines whether the register is constructed as a
1596
+ standalone register that was added to the circuit or was created from existing
1597
+ bits. A register is considered standalone if it has bits constructed solely
1598
+ as part of it, for example::
1599
+
1600
+ qr = QuantumRegister(2)
1601
+ qc = QuantumCircuit(qr)
1602
+
1603
+ the register ``qr`` would be a standalone register. While something like::
1604
+
1605
+ bits = [Qubit(), Qubit()]
1606
+ qr2 = QuantumRegister(bits=bits)
1607
+ qc = QuantumCircuit(qr2)
1608
+
1609
+ ``qr2`` would have ``standalone`` set to ``False``.
1610
+
1611
+
1612
+ .. _qpy_custom_definition:
1613
+
1614
+ CUSTOM_DEFINITIONS
1615
+ ~~~~~~~~~~~~~~~~~~
1616
+
1617
+ This section specifies custom definitions for any of the instructions in the circuit.
1618
+
1619
+ CUSTOM_DEFINITION_HEADER contents are defined as:
1620
+
1621
+ .. code-block:: c
1622
+
1623
+ struct {
1624
+ uint64_t size;
1625
+ }
1626
+
1627
+ If size is greater than 0 that means the circuit contains custom instruction(s).
1628
+ Each custom instruction is defined with a CUSTOM_INSTRUCTION block defined as:
1629
+
1630
+ .. code-block:: c
1631
+
1632
+ struct {
1633
+ uint16_t name_size;
1634
+ char type;
1635
+ uint32_t num_qubits;
1636
+ uint32_t num_clbits;
1637
+ _Bool custom_definition;
1638
+ uint64_t size;
1639
+ }
1640
+
1641
+ Immediately following the CUSTOM_INSTRUCTION struct is the utf8 encoded name
1642
+ of size ``name_size``.
1643
+
1644
+ If ``custom_definition`` is ``True`` that means that the immediately following
1645
+ ``size`` bytes contains a QPY circuit data which can be used for the custom
1646
+ definition of that gate. If ``custom_definition`` is ``False`` then the
1647
+ instruction can be considered opaque (ie no definition). The ``type`` field
1648
+ determines what type of object will get created with the custom definition.
1649
+ If it's ``'g'`` it will be a :class:`~qiskit.circuit.Gate` object, ``'i'``
1650
+ it will be a :class:`~qiskit.circuit.Instruction` object.
1651
+
1652
+ .. _qpy_instructions:
1653
+
1654
+ INSTRUCTIONS
1655
+ ~~~~~~~~~~~~
1656
+
1657
+ The contents of INSTRUCTIONS is a list of INSTRUCTION metadata objects
1658
+
1659
+ .. code-block:: c
1660
+
1661
+ struct {
1662
+ uint16_t name_size;
1663
+ uint16_t label_size;
1664
+ uint16_t num_parameters;
1665
+ uint32_t num_qargs;
1666
+ uint32_t num_cargs;
1667
+ _Bool has_conditional;
1668
+ uint16_t conditional_reg_name_size;
1669
+ int64_t conditional_value;
1670
+ }
1671
+
1672
+ This metadata object is immediately followed by ``name_size`` bytes of utf8 bytes
1673
+ for the ``name``. ``name`` here is the Qiskit class name for the Instruction
1674
+ class if it's defined in Qiskit. Otherwise it falls back to the custom
1675
+ instruction name. Following the ``name`` bytes there are ``label_size`` bytes of
1676
+ utf8 data for the label if one was set on the instruction. Following the label
1677
+ bytes if ``has_conditional`` is ``True`` then there are
1678
+ ``conditional_reg_name_size`` bytes of utf8 data for the name of the conditional
1679
+ register name. In case of single classical bit conditions the register name
1680
+ utf8 data will be prefixed with a null character "\\x00" and then a utf8 string
1681
+ integer representing the classical bit index in the circuit that the condition
1682
+ is on.
1683
+
1684
+ This is immediately followed by the INSTRUCTION_ARG structs for the list of
1685
+ arguments of that instruction. These are in the order of all quantum arguments
1686
+ (there are num_qargs of these) followed by all classical arguments (num_cargs
1687
+ of these).
1688
+
1689
+ The contents of each INSTRUCTION_ARG is:
1690
+
1691
+ .. code-block:: c
1692
+
1693
+ struct {
1694
+ char type;
1695
+ uint32_t index;
1696
+ }
1697
+
1698
+ ``type`` can be ``'q'`` or ``'c'``.
1699
+
1700
+ After all arguments for an instruction the parameters are specified with
1701
+ ``num_parameters`` INSTRUCTION_PARAM structs.
1702
+
1703
+ The contents of each INSTRUCTION_PARAM is:
1704
+
1705
+ .. code-block:: c
1706
+
1707
+ struct {
1708
+ char type;
1709
+ uint64_t size;
1710
+ }
1711
+
1712
+ After each INSTRUCTION_PARAM the next ``size`` bytes are the parameter's data.
1713
+ The ``type`` field can be ``'i'``, ``'f'``, ``'p'``, ``'e'``, ``'s'``, ``'c'``
1714
+ or ``'n'`` which dictate the format. For ``'i'`` it's an integer, ``'f'`` it's
1715
+ a double, ``'s'`` if it's a string (encoded as utf8), ``'c'`` is a complex and
1716
+ the data is represented by the struct format in the :ref:`qpy_param_expr` section.
1717
+ ``'p'`` defines a :class:`~qiskit.circuit.Parameter` object which is
1718
+ represented by a :ref:`qpy_param_struct` struct, ``e`` defines a
1719
+ :class:`~qiskit.circuit.ParameterExpression` object (that's not a
1720
+ :class:`~qiskit.circuit.Parameter`) which is represented by a :ref:`qpy_param_expr`
1721
+ struct (on QPY format :ref:`qpy_version_3` the format is tweak slightly see:
1722
+ :ref:`qpy_param_expr_v3`), ``'n'`` represents an object from numpy (either an
1723
+ ``ndarray`` or a numpy type) which means the data is .npy format [#f2]_ data,
1724
+ and in QPY :ref:`qpy_version_3` ``'v'`` represents a
1725
+ :class:`~qiskit.circuit.ParameterVectorElement` which is represented by a
1726
+ :ref:`qpy_param_vector` struct.
1727
+
1728
+ .. _qpy_param_struct:
1729
+
1730
+ PARAMETER
1731
+ ~~~~~~~~~
1732
+
1733
+ A PARAMETER represents a :class:`~qiskit.circuit.Parameter` object the data for
1734
+ a INSTRUCTION_PARAM. The contents of the PARAMETER are defined as:
1735
+
1736
+ .. code-block:: c
1737
+
1738
+ struct {
1739
+ uint16_t name_size;
1740
+ char uuid[16];
1741
+ }
1742
+
1743
+ which is immediately followed by ``name_size`` utf8 bytes representing the
1744
+ parameter name.
1745
+
1746
+ .. _qpy_param_expr:
1747
+
1748
+ PARAMETER_EXPR
1749
+ ~~~~~~~~~~~~~~
1750
+
1751
+ A PARAMETER_EXPR represents a :class:`~qiskit.circuit.ParameterExpression`
1752
+ object that the data for an INSTRUCTION_PARAM. The contents of a PARAMETER_EXPR
1753
+ are defined as:
1754
+
1755
+ The PARAMETER_EXPR data starts with a header:
1756
+
1757
+ .. code-block:: c
1758
+
1759
+ struct {
1760
+ uint64_t map_elements;
1761
+ uint64_t expr_size;
1762
+ }
1763
+
1764
+ Immediately following the header is ``expr_size`` bytes of utf8 data containing
1765
+ the expression string, which is the sympy srepr of the expression for the
1766
+ parameter expression. Follwing that is a symbol map which contains
1767
+ ``map_elements`` elements with the format
1768
+
1769
+ .. code-block:: c
1770
+
1771
+ struct {
1772
+ char type;
1773
+ uint64_t size;
1774
+ }
1775
+
1776
+ Which is followed immediately by ``PARAMETER`` object (both the struct and utf8
1777
+ name bytes) for the symbol map key. That is followed by ``size`` bytes for the
1778
+ data of the symbol. The data format is dependent on the value of ``type``. If
1779
+ ``type`` is ``p`` then it represents a :class:`~qiskit.circuit.Parameter` and
1780
+ size will be 0, the value will just be the same as the key. If
1781
+ ``type`` is ``f`` then it represents a double precision float. If ``type`` is
1782
+ ``c`` it represents a double precision complex, which is represented by :ref:`qpy_complex`.
1783
+ Finally, if type is ``i`` it represents an integer which is an ``int64_t``.
1784
+
1785
+ .. _qpy_complex:
1786
+
1787
+ COMPLEX
1788
+ ~~~~~~~
1789
+
1790
+ When representing a double precision complex value in QPY the following
1791
+ struct is used:
1792
+
1793
+
1794
+ .. code-block:: c
1795
+
1796
+ struct {
1797
+ double real;
1798
+ double imag;
1799
+ }
1800
+
1801
+ this matches the internal C representation of Python's complex type. [#f3]_
1802
+
1803
+ References
1804
+ ==========
1805
+
1806
+ .. [#f1] https://tools.ietf.org/html/rfc1700
1807
+ .. [#f2] https://numpy.org/doc/stable/reference/generated/numpy.lib.format.html
1808
+ .. [#f3] https://docs.python.org/3/c-api/complex.html#c.Py_complex
1809
+ """
1810
+
1811
+ from .exceptions import QpyError, UnsupportedFeatureForVersion, QPYLoadingDeprecatedFeatureWarning
1812
+ from .interface import dump, load
1813
+
1814
+ # For backward compatibility. Provide, Runtime, Experiment call these private functions.
1815
+ from .binary_io import (
1816
+ _write_instruction,
1817
+ _read_instruction,
1818
+ _write_parameter_expression,
1819
+ _read_parameter_expression,
1820
+ _read_parameter_expression_v3,
1821
+ )
1822
+ from .common import QPY_VERSION, QPY_COMPATIBILITY_VERSION