qiskit 1.3.0b1__cp39-abi3-macosx_10_9_x86_64.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 (825) hide show
  1. qiskit/VERSION.txt +1 -0
  2. qiskit/__init__.py +127 -0
  3. qiskit/_accelerate.abi3.so +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 +365 -0
  8. qiskit/assembler/disassemble.py +310 -0
  9. qiskit/assembler/run_config.py +77 -0
  10. qiskit/circuit/__init__.py +1270 -0
  11. qiskit/circuit/_classical_resource_map.py +148 -0
  12. qiskit/circuit/_standard_gates_commutations.py +3264 -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 +48 -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 +503 -0
  45. qiskit/circuit/controlflow/switch_case.py +417 -0
  46. qiskit/circuit/controlflow/while_loop.py +163 -0
  47. qiskit/circuit/controlledgate.py +274 -0
  48. qiskit/circuit/delay.py +106 -0
  49. qiskit/circuit/duration.py +95 -0
  50. qiskit/circuit/equivalence.py +295 -0
  51. qiskit/circuit/equivalence_library.py +18 -0
  52. qiskit/circuit/exceptions.py +19 -0
  53. qiskit/circuit/gate.py +261 -0
  54. qiskit/circuit/instruction.py +676 -0
  55. qiskit/circuit/instructionset.py +177 -0
  56. qiskit/circuit/library/__init__.py +572 -0
  57. qiskit/circuit/library/arithmetic/__init__.py +27 -0
  58. qiskit/circuit/library/arithmetic/adders/__init__.py +17 -0
  59. qiskit/circuit/library/arithmetic/adders/adder.py +58 -0
  60. qiskit/circuit/library/arithmetic/adders/cdkm_ripple_carry_adder.py +159 -0
  61. qiskit/circuit/library/arithmetic/adders/draper_qft_adder.py +116 -0
  62. qiskit/circuit/library/arithmetic/adders/vbe_ripple_carry_adder.py +165 -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 +16 -0
  69. qiskit/circuit/library/arithmetic/multipliers/hrs_cumulative_multiplier.py +138 -0
  70. qiskit/circuit/library/arithmetic/multipliers/multiplier.py +101 -0
  71. qiskit/circuit/library/arithmetic/multipliers/rg_qft_multiplier.py +101 -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 +331 -0
  80. qiskit/circuit/library/blueprintcircuit.py +216 -0
  81. qiskit/circuit/library/boolean_logic/__init__.py +18 -0
  82. qiskit/circuit/library/boolean_logic/inner_product.py +78 -0
  83. qiskit/circuit/library/boolean_logic/quantum_and.py +97 -0
  84. qiskit/circuit/library/boolean_logic/quantum_or.py +98 -0
  85. qiskit/circuit/library/boolean_logic/quantum_xor.py +71 -0
  86. qiskit/circuit/library/data_preparation/__init__.py +54 -0
  87. qiskit/circuit/library/data_preparation/initializer.py +107 -0
  88. qiskit/circuit/library/data_preparation/pauli_feature_map.py +343 -0
  89. qiskit/circuit/library/data_preparation/state_preparation.py +336 -0
  90. qiskit/circuit/library/data_preparation/z_feature_map.py +104 -0
  91. qiskit/circuit/library/data_preparation/zz_feature_map.py +118 -0
  92. qiskit/circuit/library/fourier_checking.py +97 -0
  93. qiskit/circuit/library/generalized_gates/__init__.py +30 -0
  94. qiskit/circuit/library/generalized_gates/diagonal.py +165 -0
  95. qiskit/circuit/library/generalized_gates/gms.py +121 -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 +312 -0
  99. qiskit/circuit/library/generalized_gates/mcg_up_to_diagonal.py +143 -0
  100. qiskit/circuit/library/generalized_gates/mcmt.py +256 -0
  101. qiskit/circuit/library/generalized_gates/pauli.py +85 -0
  102. qiskit/circuit/library/generalized_gates/permutation.py +192 -0
  103. qiskit/circuit/library/generalized_gates/rv.py +97 -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 +86 -0
  111. qiskit/circuit/library/grover_operator.py +311 -0
  112. qiskit/circuit/library/hamiltonian_gate.py +142 -0
  113. qiskit/circuit/library/hidden_linear_function.py +98 -0
  114. qiskit/circuit/library/iqp.py +96 -0
  115. qiskit/circuit/library/n_local/__init__.py +33 -0
  116. qiskit/circuit/library/n_local/efficient_su2.py +164 -0
  117. qiskit/circuit/library/n_local/evolved_operator_ansatz.py +256 -0
  118. qiskit/circuit/library/n_local/excitation_preserving.py +173 -0
  119. qiskit/circuit/library/n_local/n_local.py +1071 -0
  120. qiskit/circuit/library/n_local/pauli_two_design.py +141 -0
  121. qiskit/circuit/library/n_local/qaoa_ansatz.py +287 -0
  122. qiskit/circuit/library/n_local/real_amplitudes.py +186 -0
  123. qiskit/circuit/library/n_local/two_local.py +282 -0
  124. qiskit/circuit/library/overlap.py +117 -0
  125. qiskit/circuit/library/pauli_evolution.py +184 -0
  126. qiskit/circuit/library/phase_estimation.py +99 -0
  127. qiskit/circuit/library/phase_oracle.py +153 -0
  128. qiskit/circuit/library/quantum_volume.py +115 -0
  129. qiskit/circuit/library/standard_gates/__init__.py +123 -0
  130. qiskit/circuit/library/standard_gates/dcx.py +77 -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 +257 -0
  135. qiskit/circuit/library/standard_gates/i.py +75 -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 +433 -0
  139. qiskit/circuit/library/standard_gates/r.py +117 -0
  140. qiskit/circuit/library/standard_gates/rx.py +302 -0
  141. qiskit/circuit/library/standard_gates/rxx.py +183 -0
  142. qiskit/circuit/library/standard_gates/ry.py +297 -0
  143. qiskit/circuit/library/standard_gates/ryy.py +183 -0
  144. qiskit/circuit/library/standard_gates/rz.py +318 -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 +314 -0
  150. qiskit/circuit/library/standard_gates/t.py +179 -0
  151. qiskit/circuit/library/standard_gates/u.py +395 -0
  152. qiskit/circuit/library/standard_gates/u1.py +451 -0
  153. qiskit/circuit/library/standard_gates/u2.py +146 -0
  154. qiskit/circuit/library/standard_gates/u3.py +408 -0
  155. qiskit/circuit/library/standard_gates/x.py +1527 -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 +261 -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 +33 -0
  163. qiskit/circuit/library/templates/clifford/clifford_2_2.py +34 -0
  164. qiskit/circuit/library/templates/clifford/clifford_2_3.py +32 -0
  165. qiskit/circuit/library/templates/clifford/clifford_2_4.py +33 -0
  166. qiskit/circuit/library/templates/clifford/clifford_3_1.py +34 -0
  167. qiskit/circuit/library/templates/clifford/clifford_4_1.py +37 -0
  168. qiskit/circuit/library/templates/clifford/clifford_4_2.py +36 -0
  169. qiskit/circuit/library/templates/clifford/clifford_4_3.py +37 -0
  170. qiskit/circuit/library/templates/clifford/clifford_4_4.py +36 -0
  171. qiskit/circuit/library/templates/clifford/clifford_5_1.py +39 -0
  172. qiskit/circuit/library/templates/clifford/clifford_6_1.py +39 -0
  173. qiskit/circuit/library/templates/clifford/clifford_6_2.py +39 -0
  174. qiskit/circuit/library/templates/clifford/clifford_6_3.py +39 -0
  175. qiskit/circuit/library/templates/clifford/clifford_6_4.py +37 -0
  176. qiskit/circuit/library/templates/clifford/clifford_6_5.py +39 -0
  177. qiskit/circuit/library/templates/clifford/clifford_8_1.py +41 -0
  178. qiskit/circuit/library/templates/clifford/clifford_8_2.py +41 -0
  179. qiskit/circuit/library/templates/clifford/clifford_8_3.py +40 -0
  180. qiskit/circuit/library/templates/nct/__init__.py +67 -0
  181. qiskit/circuit/library/templates/nct/template_nct_2a_1.py +32 -0
  182. qiskit/circuit/library/templates/nct/template_nct_2a_2.py +33 -0
  183. qiskit/circuit/library/templates/nct/template_nct_2a_3.py +35 -0
  184. qiskit/circuit/library/templates/nct/template_nct_4a_1.py +41 -0
  185. qiskit/circuit/library/templates/nct/template_nct_4a_2.py +39 -0
  186. qiskit/circuit/library/templates/nct/template_nct_4a_3.py +37 -0
  187. qiskit/circuit/library/templates/nct/template_nct_4b_1.py +39 -0
  188. qiskit/circuit/library/templates/nct/template_nct_4b_2.py +37 -0
  189. qiskit/circuit/library/templates/nct/template_nct_5a_1.py +38 -0
  190. qiskit/circuit/library/templates/nct/template_nct_5a_2.py +38 -0
  191. qiskit/circuit/library/templates/nct/template_nct_5a_3.py +38 -0
  192. qiskit/circuit/library/templates/nct/template_nct_5a_4.py +37 -0
  193. qiskit/circuit/library/templates/nct/template_nct_6a_1.py +38 -0
  194. qiskit/circuit/library/templates/nct/template_nct_6a_2.py +39 -0
  195. qiskit/circuit/library/templates/nct/template_nct_6a_3.py +39 -0
  196. qiskit/circuit/library/templates/nct/template_nct_6a_4.py +39 -0
  197. qiskit/circuit/library/templates/nct/template_nct_6b_1.py +39 -0
  198. qiskit/circuit/library/templates/nct/template_nct_6b_2.py +39 -0
  199. qiskit/circuit/library/templates/nct/template_nct_6c_1.py +39 -0
  200. qiskit/circuit/library/templates/nct/template_nct_7a_1.py +41 -0
  201. qiskit/circuit/library/templates/nct/template_nct_7b_1.py +41 -0
  202. qiskit/circuit/library/templates/nct/template_nct_7c_1.py +41 -0
  203. qiskit/circuit/library/templates/nct/template_nct_7d_1.py +41 -0
  204. qiskit/circuit/library/templates/nct/template_nct_7e_1.py +41 -0
  205. qiskit/circuit/library/templates/nct/template_nct_9a_1.py +43 -0
  206. qiskit/circuit/library/templates/nct/template_nct_9c_1.py +41 -0
  207. qiskit/circuit/library/templates/nct/template_nct_9c_10.py +42 -0
  208. qiskit/circuit/library/templates/nct/template_nct_9c_11.py +42 -0
  209. qiskit/circuit/library/templates/nct/template_nct_9c_12.py +42 -0
  210. qiskit/circuit/library/templates/nct/template_nct_9c_2.py +42 -0
  211. qiskit/circuit/library/templates/nct/template_nct_9c_3.py +42 -0
  212. qiskit/circuit/library/templates/nct/template_nct_9c_4.py +42 -0
  213. qiskit/circuit/library/templates/nct/template_nct_9c_5.py +42 -0
  214. qiskit/circuit/library/templates/nct/template_nct_9c_6.py +42 -0
  215. qiskit/circuit/library/templates/nct/template_nct_9c_7.py +42 -0
  216. qiskit/circuit/library/templates/nct/template_nct_9c_8.py +42 -0
  217. qiskit/circuit/library/templates/nct/template_nct_9c_9.py +42 -0
  218. qiskit/circuit/library/templates/nct/template_nct_9d_1.py +41 -0
  219. qiskit/circuit/library/templates/nct/template_nct_9d_10.py +42 -0
  220. qiskit/circuit/library/templates/nct/template_nct_9d_2.py +42 -0
  221. qiskit/circuit/library/templates/nct/template_nct_9d_3.py +42 -0
  222. qiskit/circuit/library/templates/nct/template_nct_9d_4.py +42 -0
  223. qiskit/circuit/library/templates/nct/template_nct_9d_5.py +42 -0
  224. qiskit/circuit/library/templates/nct/template_nct_9d_6.py +42 -0
  225. qiskit/circuit/library/templates/nct/template_nct_9d_7.py +42 -0
  226. qiskit/circuit/library/templates/nct/template_nct_9d_8.py +42 -0
  227. qiskit/circuit/library/templates/nct/template_nct_9d_9.py +42 -0
  228. qiskit/circuit/library/templates/rzx/__init__.py +25 -0
  229. qiskit/circuit/library/templates/rzx/rzx_cy.py +46 -0
  230. qiskit/circuit/library/templates/rzx/rzx_xz.py +53 -0
  231. qiskit/circuit/library/templates/rzx/rzx_yz.py +43 -0
  232. qiskit/circuit/library/templates/rzx/rzx_zz1.py +67 -0
  233. qiskit/circuit/library/templates/rzx/rzx_zz2.py +58 -0
  234. qiskit/circuit/library/templates/rzx/rzx_zz3.py +57 -0
  235. qiskit/circuit/measure.py +44 -0
  236. qiskit/circuit/operation.py +67 -0
  237. qiskit/circuit/parameter.py +174 -0
  238. qiskit/circuit/parameterexpression.py +559 -0
  239. qiskit/circuit/parametertable.py +119 -0
  240. qiskit/circuit/parametervector.py +120 -0
  241. qiskit/circuit/quantumcircuit.py +6793 -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 +604 -0
  249. qiskit/circuit/store.py +95 -0
  250. qiskit/circuit/tools/__init__.py +16 -0
  251. qiskit/circuit/tools/pi_check.py +190 -0
  252. qiskit/compiler/__init__.py +33 -0
  253. qiskit/compiler/assembler.py +668 -0
  254. qiskit/compiler/scheduler.py +107 -0
  255. qiskit/compiler/sequencer.py +69 -0
  256. qiskit/compiler/transpiler.py +478 -0
  257. qiskit/converters/__init__.py +74 -0
  258. qiskit/converters/circuit_to_dag.py +78 -0
  259. qiskit/converters/circuit_to_dagdependency.py +51 -0
  260. qiskit/converters/circuit_to_dagdependency_v2.py +47 -0
  261. qiskit/converters/circuit_to_gate.py +107 -0
  262. qiskit/converters/circuit_to_instruction.py +155 -0
  263. qiskit/converters/dag_to_circuit.py +77 -0
  264. qiskit/converters/dag_to_dagdependency.py +55 -0
  265. qiskit/converters/dag_to_dagdependency_v2.py +44 -0
  266. qiskit/converters/dagdependency_to_circuit.py +42 -0
  267. qiskit/converters/dagdependency_to_dag.py +49 -0
  268. qiskit/dagcircuit/__init__.py +44 -0
  269. qiskit/dagcircuit/collect_blocks.py +391 -0
  270. qiskit/dagcircuit/dagcircuit.py +24 -0
  271. qiskit/dagcircuit/dagdependency.py +633 -0
  272. qiskit/dagcircuit/dagdependency_v2.py +641 -0
  273. qiskit/dagcircuit/dagdepnode.py +160 -0
  274. qiskit/dagcircuit/dagnode.py +176 -0
  275. qiskit/dagcircuit/exceptions.py +42 -0
  276. qiskit/exceptions.py +153 -0
  277. qiskit/passmanager/__init__.py +240 -0
  278. qiskit/passmanager/base_tasks.py +230 -0
  279. qiskit/passmanager/compilation_status.py +74 -0
  280. qiskit/passmanager/exceptions.py +19 -0
  281. qiskit/passmanager/flow_controllers.py +116 -0
  282. qiskit/passmanager/passmanager.py +333 -0
  283. qiskit/primitives/__init__.py +481 -0
  284. qiskit/primitives/backend_estimator.py +483 -0
  285. qiskit/primitives/backend_estimator_v2.py +434 -0
  286. qiskit/primitives/backend_sampler.py +222 -0
  287. qiskit/primitives/backend_sampler_v2.py +296 -0
  288. qiskit/primitives/base/__init__.py +20 -0
  289. qiskit/primitives/base/base_estimator.py +252 -0
  290. qiskit/primitives/base/base_primitive.py +45 -0
  291. qiskit/primitives/base/base_primitive_job.py +78 -0
  292. qiskit/primitives/base/base_result.py +65 -0
  293. qiskit/primitives/base/base_sampler.py +204 -0
  294. qiskit/primitives/base/estimator_result.py +46 -0
  295. qiskit/primitives/base/sampler_result.py +45 -0
  296. qiskit/primitives/base/validation.py +231 -0
  297. qiskit/primitives/containers/__init__.py +26 -0
  298. qiskit/primitives/containers/bindings_array.py +389 -0
  299. qiskit/primitives/containers/bit_array.py +741 -0
  300. qiskit/primitives/containers/data_bin.py +165 -0
  301. qiskit/primitives/containers/estimator_pub.py +222 -0
  302. qiskit/primitives/containers/object_array.py +94 -0
  303. qiskit/primitives/containers/observables_array.py +279 -0
  304. qiskit/primitives/containers/primitive_result.py +53 -0
  305. qiskit/primitives/containers/pub_result.py +51 -0
  306. qiskit/primitives/containers/sampler_pub.py +193 -0
  307. qiskit/primitives/containers/sampler_pub_result.py +74 -0
  308. qiskit/primitives/containers/shape.py +129 -0
  309. qiskit/primitives/estimator.py +172 -0
  310. qiskit/primitives/primitive_job.py +81 -0
  311. qiskit/primitives/sampler.py +162 -0
  312. qiskit/primitives/statevector_estimator.py +174 -0
  313. qiskit/primitives/statevector_sampler.py +292 -0
  314. qiskit/primitives/utils.py +247 -0
  315. qiskit/providers/__init__.py +803 -0
  316. qiskit/providers/backend.py +656 -0
  317. qiskit/providers/backend_compat.py +452 -0
  318. qiskit/providers/basic_provider/__init__.py +45 -0
  319. qiskit/providers/basic_provider/basic_provider.py +101 -0
  320. qiskit/providers/basic_provider/basic_provider_job.py +65 -0
  321. qiskit/providers/basic_provider/basic_provider_tools.py +218 -0
  322. qiskit/providers/basic_provider/basic_simulator.py +811 -0
  323. qiskit/providers/basic_provider/exceptions.py +30 -0
  324. qiskit/providers/exceptions.py +45 -0
  325. qiskit/providers/fake_provider/__init__.py +105 -0
  326. qiskit/providers/fake_provider/backends_v1/__init__.py +22 -0
  327. qiskit/providers/fake_provider/backends_v1/fake_127q_pulse/__init__.py +18 -0
  328. qiskit/providers/fake_provider/backends_v1/fake_127q_pulse/conf_washington.json +1 -0
  329. qiskit/providers/fake_provider/backends_v1/fake_127q_pulse/defs_washington.json +1 -0
  330. qiskit/providers/fake_provider/backends_v1/fake_127q_pulse/fake_127q_pulse_v1.py +37 -0
  331. qiskit/providers/fake_provider/backends_v1/fake_127q_pulse/props_washington.json +1 -0
  332. qiskit/providers/fake_provider/backends_v1/fake_20q/__init__.py +18 -0
  333. qiskit/providers/fake_provider/backends_v1/fake_20q/conf_singapore.json +1 -0
  334. qiskit/providers/fake_provider/backends_v1/fake_20q/fake_20q.py +43 -0
  335. qiskit/providers/fake_provider/backends_v1/fake_20q/props_singapore.json +1 -0
  336. qiskit/providers/fake_provider/backends_v1/fake_27q_pulse/__init__.py +18 -0
  337. qiskit/providers/fake_provider/backends_v1/fake_27q_pulse/conf_hanoi.json +1 -0
  338. qiskit/providers/fake_provider/backends_v1/fake_27q_pulse/defs_hanoi.json +1 -0
  339. qiskit/providers/fake_provider/backends_v1/fake_27q_pulse/fake_27q_pulse_v1.py +50 -0
  340. qiskit/providers/fake_provider/backends_v1/fake_27q_pulse/props_hanoi.json +1 -0
  341. qiskit/providers/fake_provider/backends_v1/fake_5q/__init__.py +18 -0
  342. qiskit/providers/fake_provider/backends_v1/fake_5q/conf_yorktown.json +1 -0
  343. qiskit/providers/fake_provider/backends_v1/fake_5q/fake_5q_v1.py +41 -0
  344. qiskit/providers/fake_provider/backends_v1/fake_5q/props_yorktown.json +1 -0
  345. qiskit/providers/fake_provider/backends_v1/fake_7q_pulse/__init__.py +18 -0
  346. qiskit/providers/fake_provider/backends_v1/fake_7q_pulse/conf_nairobi.json +1 -0
  347. qiskit/providers/fake_provider/backends_v1/fake_7q_pulse/defs_nairobi.json +1 -0
  348. qiskit/providers/fake_provider/backends_v1/fake_7q_pulse/fake_7q_pulse_v1.py +44 -0
  349. qiskit/providers/fake_provider/backends_v1/fake_7q_pulse/props_nairobi.json +1 -0
  350. qiskit/providers/fake_provider/fake_1q.py +91 -0
  351. qiskit/providers/fake_provider/fake_backend.py +165 -0
  352. qiskit/providers/fake_provider/fake_openpulse_2q.py +391 -0
  353. qiskit/providers/fake_provider/fake_openpulse_3q.py +340 -0
  354. qiskit/providers/fake_provider/fake_pulse_backend.py +44 -0
  355. qiskit/providers/fake_provider/fake_qasm_backend.py +77 -0
  356. qiskit/providers/fake_provider/generic_backend_v2.py +1019 -0
  357. qiskit/providers/fake_provider/utils/__init__.py +15 -0
  358. qiskit/providers/fake_provider/utils/backend_converter.py +150 -0
  359. qiskit/providers/fake_provider/utils/json_decoder.py +109 -0
  360. qiskit/providers/job.py +147 -0
  361. qiskit/providers/jobstatus.py +30 -0
  362. qiskit/providers/models/__init__.py +89 -0
  363. qiskit/providers/models/backendconfiguration.py +1040 -0
  364. qiskit/providers/models/backendproperties.py +517 -0
  365. qiskit/providers/models/backendstatus.py +94 -0
  366. qiskit/providers/models/jobstatus.py +66 -0
  367. qiskit/providers/models/pulsedefaults.py +303 -0
  368. qiskit/providers/options.py +273 -0
  369. qiskit/providers/provider.py +95 -0
  370. qiskit/providers/providerutils.py +110 -0
  371. qiskit/pulse/__init__.py +158 -0
  372. qiskit/pulse/builder.py +2213 -0
  373. qiskit/pulse/calibration_entries.py +378 -0
  374. qiskit/pulse/channels.py +225 -0
  375. qiskit/pulse/configuration.py +245 -0
  376. qiskit/pulse/exceptions.py +43 -0
  377. qiskit/pulse/filters.py +309 -0
  378. qiskit/pulse/instruction_schedule_map.py +409 -0
  379. qiskit/pulse/instructions/__init__.py +67 -0
  380. qiskit/pulse/instructions/acquire.py +148 -0
  381. qiskit/pulse/instructions/delay.py +69 -0
  382. qiskit/pulse/instructions/directives.py +146 -0
  383. qiskit/pulse/instructions/frequency.py +132 -0
  384. qiskit/pulse/instructions/instruction.py +268 -0
  385. qiskit/pulse/instructions/phase.py +149 -0
  386. qiskit/pulse/instructions/play.py +97 -0
  387. qiskit/pulse/instructions/reference.py +98 -0
  388. qiskit/pulse/instructions/snapshot.py +80 -0
  389. qiskit/pulse/library/__init__.py +97 -0
  390. qiskit/pulse/library/continuous.py +430 -0
  391. qiskit/pulse/library/pulse.py +146 -0
  392. qiskit/pulse/library/samplers/__init__.py +15 -0
  393. qiskit/pulse/library/samplers/decorators.py +295 -0
  394. qiskit/pulse/library/samplers/strategies.py +71 -0
  395. qiskit/pulse/library/symbolic_pulses.py +1960 -0
  396. qiskit/pulse/library/waveform.py +134 -0
  397. qiskit/pulse/macros.py +262 -0
  398. qiskit/pulse/parameter_manager.py +445 -0
  399. qiskit/pulse/parser.py +314 -0
  400. qiskit/pulse/reference_manager.py +58 -0
  401. qiskit/pulse/schedule.py +1855 -0
  402. qiskit/pulse/transforms/__init__.py +106 -0
  403. qiskit/pulse/transforms/alignments.py +404 -0
  404. qiskit/pulse/transforms/base_transforms.py +71 -0
  405. qiskit/pulse/transforms/canonicalization.py +498 -0
  406. qiskit/pulse/transforms/dag.py +115 -0
  407. qiskit/pulse/utils.py +149 -0
  408. qiskit/qasm/libs/dummy/stdgates.inc +75 -0
  409. qiskit/qasm/libs/qelib1.inc +266 -0
  410. qiskit/qasm/libs/stdgates.inc +82 -0
  411. qiskit/qasm2/__init__.py +654 -0
  412. qiskit/qasm2/exceptions.py +27 -0
  413. qiskit/qasm2/export.py +370 -0
  414. qiskit/qasm2/parse.py +408 -0
  415. qiskit/qasm3/__init__.py +366 -0
  416. qiskit/qasm3/ast.py +630 -0
  417. qiskit/qasm3/exceptions.py +27 -0
  418. qiskit/qasm3/experimental.py +70 -0
  419. qiskit/qasm3/exporter.py +1273 -0
  420. qiskit/qasm3/printer.py +577 -0
  421. qiskit/qobj/__init__.py +75 -0
  422. qiskit/qobj/common.py +81 -0
  423. qiskit/qobj/converters/__init__.py +18 -0
  424. qiskit/qobj/converters/lo_config.py +177 -0
  425. qiskit/qobj/converters/pulse_instruction.py +895 -0
  426. qiskit/qobj/pulse_qobj.py +709 -0
  427. qiskit/qobj/qasm_qobj.py +708 -0
  428. qiskit/qobj/utils.py +46 -0
  429. qiskit/qpy/__init__.py +1641 -0
  430. qiskit/qpy/binary_io/__init__.py +36 -0
  431. qiskit/qpy/binary_io/circuits.py +1460 -0
  432. qiskit/qpy/binary_io/schedules.py +636 -0
  433. qiskit/qpy/binary_io/value.py +728 -0
  434. qiskit/qpy/common.py +306 -0
  435. qiskit/qpy/exceptions.py +53 -0
  436. qiskit/qpy/formats.py +394 -0
  437. qiskit/qpy/interface.py +341 -0
  438. qiskit/qpy/type_keys.py +572 -0
  439. qiskit/quantum_info/__init__.py +158 -0
  440. qiskit/quantum_info/analysis/__init__.py +17 -0
  441. qiskit/quantum_info/analysis/average.py +47 -0
  442. qiskit/quantum_info/analysis/distance.py +102 -0
  443. qiskit/quantum_info/analysis/make_observable.py +44 -0
  444. qiskit/quantum_info/analysis/z2_symmetries.py +484 -0
  445. qiskit/quantum_info/operators/__init__.py +28 -0
  446. qiskit/quantum_info/operators/base_operator.py +145 -0
  447. qiskit/quantum_info/operators/channel/__init__.py +29 -0
  448. qiskit/quantum_info/operators/channel/chi.py +191 -0
  449. qiskit/quantum_info/operators/channel/choi.py +218 -0
  450. qiskit/quantum_info/operators/channel/kraus.py +337 -0
  451. qiskit/quantum_info/operators/channel/ptm.py +204 -0
  452. qiskit/quantum_info/operators/channel/quantum_channel.py +348 -0
  453. qiskit/quantum_info/operators/channel/stinespring.py +296 -0
  454. qiskit/quantum_info/operators/channel/superop.py +377 -0
  455. qiskit/quantum_info/operators/channel/transformations.py +468 -0
  456. qiskit/quantum_info/operators/custom_iterator.py +48 -0
  457. qiskit/quantum_info/operators/dihedral/__init__.py +18 -0
  458. qiskit/quantum_info/operators/dihedral/dihedral.py +509 -0
  459. qiskit/quantum_info/operators/dihedral/dihedral_circuits.py +216 -0
  460. qiskit/quantum_info/operators/dihedral/polynomial.py +313 -0
  461. qiskit/quantum_info/operators/dihedral/random.py +64 -0
  462. qiskit/quantum_info/operators/linear_op.py +25 -0
  463. qiskit/quantum_info/operators/measures.py +418 -0
  464. qiskit/quantum_info/operators/mixins/__init__.py +52 -0
  465. qiskit/quantum_info/operators/mixins/adjoint.py +52 -0
  466. qiskit/quantum_info/operators/mixins/group.py +171 -0
  467. qiskit/quantum_info/operators/mixins/linear.py +84 -0
  468. qiskit/quantum_info/operators/mixins/multiply.py +62 -0
  469. qiskit/quantum_info/operators/mixins/tolerances.py +72 -0
  470. qiskit/quantum_info/operators/op_shape.py +525 -0
  471. qiskit/quantum_info/operators/operator.py +819 -0
  472. qiskit/quantum_info/operators/operator_utils.py +76 -0
  473. qiskit/quantum_info/operators/predicates.py +183 -0
  474. qiskit/quantum_info/operators/random.py +154 -0
  475. qiskit/quantum_info/operators/scalar_op.py +254 -0
  476. qiskit/quantum_info/operators/symplectic/__init__.py +23 -0
  477. qiskit/quantum_info/operators/symplectic/base_pauli.py +727 -0
  478. qiskit/quantum_info/operators/symplectic/clifford.py +1030 -0
  479. qiskit/quantum_info/operators/symplectic/clifford_circuits.py +558 -0
  480. qiskit/quantum_info/operators/symplectic/pauli.py +751 -0
  481. qiskit/quantum_info/operators/symplectic/pauli_list.py +1230 -0
  482. qiskit/quantum_info/operators/symplectic/pauli_utils.py +40 -0
  483. qiskit/quantum_info/operators/symplectic/random.py +117 -0
  484. qiskit/quantum_info/operators/symplectic/sparse_pauli_op.py +1175 -0
  485. qiskit/quantum_info/operators/utils/__init__.py +20 -0
  486. qiskit/quantum_info/operators/utils/anti_commutator.py +36 -0
  487. qiskit/quantum_info/operators/utils/commutator.py +36 -0
  488. qiskit/quantum_info/operators/utils/double_commutator.py +76 -0
  489. qiskit/quantum_info/quaternion.py +156 -0
  490. qiskit/quantum_info/random.py +26 -0
  491. qiskit/quantum_info/states/__init__.py +28 -0
  492. qiskit/quantum_info/states/densitymatrix.py +845 -0
  493. qiskit/quantum_info/states/measures.py +288 -0
  494. qiskit/quantum_info/states/quantum_state.py +503 -0
  495. qiskit/quantum_info/states/random.py +157 -0
  496. qiskit/quantum_info/states/stabilizerstate.py +773 -0
  497. qiskit/quantum_info/states/statevector.py +958 -0
  498. qiskit/quantum_info/states/utils.py +247 -0
  499. qiskit/result/__init__.py +73 -0
  500. qiskit/result/counts.py +189 -0
  501. qiskit/result/distributions/__init__.py +17 -0
  502. qiskit/result/distributions/probability.py +100 -0
  503. qiskit/result/distributions/quasi.py +154 -0
  504. qiskit/result/exceptions.py +40 -0
  505. qiskit/result/mitigation/__init__.py +13 -0
  506. qiskit/result/mitigation/base_readout_mitigator.py +79 -0
  507. qiskit/result/mitigation/correlated_readout_mitigator.py +269 -0
  508. qiskit/result/mitigation/local_readout_mitigator.py +320 -0
  509. qiskit/result/mitigation/utils.py +160 -0
  510. qiskit/result/models.py +234 -0
  511. qiskit/result/postprocess.py +239 -0
  512. qiskit/result/result.py +392 -0
  513. qiskit/result/sampled_expval.py +75 -0
  514. qiskit/result/utils.py +295 -0
  515. qiskit/scheduler/__init__.py +40 -0
  516. qiskit/scheduler/config.py +35 -0
  517. qiskit/scheduler/lowering.py +187 -0
  518. qiskit/scheduler/methods/__init__.py +15 -0
  519. qiskit/scheduler/methods/basic.py +137 -0
  520. qiskit/scheduler/schedule_circuit.py +67 -0
  521. qiskit/scheduler/sequence.py +102 -0
  522. qiskit/synthesis/__init__.py +195 -0
  523. qiskit/synthesis/clifford/__init__.py +19 -0
  524. qiskit/synthesis/clifford/clifford_decompose_ag.py +178 -0
  525. qiskit/synthesis/clifford/clifford_decompose_bm.py +47 -0
  526. qiskit/synthesis/clifford/clifford_decompose_full.py +64 -0
  527. qiskit/synthesis/clifford/clifford_decompose_greedy.py +57 -0
  528. qiskit/synthesis/clifford/clifford_decompose_layers.py +446 -0
  529. qiskit/synthesis/cnotdihedral/__init__.py +17 -0
  530. qiskit/synthesis/cnotdihedral/cnotdihedral_decompose_full.py +52 -0
  531. qiskit/synthesis/cnotdihedral/cnotdihedral_decompose_general.py +141 -0
  532. qiskit/synthesis/cnotdihedral/cnotdihedral_decompose_two_qubits.py +266 -0
  533. qiskit/synthesis/discrete_basis/__init__.py +16 -0
  534. qiskit/synthesis/discrete_basis/commutator_decompose.py +241 -0
  535. qiskit/synthesis/discrete_basis/gate_sequence.py +415 -0
  536. qiskit/synthesis/discrete_basis/generate_basis_approximations.py +163 -0
  537. qiskit/synthesis/discrete_basis/solovay_kitaev.py +217 -0
  538. qiskit/synthesis/evolution/__init__.py +20 -0
  539. qiskit/synthesis/evolution/evolution_synthesis.py +48 -0
  540. qiskit/synthesis/evolution/lie_trotter.py +143 -0
  541. qiskit/synthesis/evolution/matrix_synthesis.py +47 -0
  542. qiskit/synthesis/evolution/product_formula.py +384 -0
  543. qiskit/synthesis/evolution/qdrift.py +131 -0
  544. qiskit/synthesis/evolution/suzuki_trotter.py +155 -0
  545. qiskit/synthesis/linear/__init__.py +26 -0
  546. qiskit/synthesis/linear/cnot_synth.py +69 -0
  547. qiskit/synthesis/linear/linear_circuits_utils.py +128 -0
  548. qiskit/synthesis/linear/linear_depth_lnn.py +276 -0
  549. qiskit/synthesis/linear/linear_matrix_utils.py +27 -0
  550. qiskit/synthesis/linear_phase/__init__.py +17 -0
  551. qiskit/synthesis/linear_phase/cnot_phase_synth.py +206 -0
  552. qiskit/synthesis/linear_phase/cx_cz_depth_lnn.py +262 -0
  553. qiskit/synthesis/linear_phase/cz_depth_lnn.py +58 -0
  554. qiskit/synthesis/multi_controlled/__init__.py +23 -0
  555. qiskit/synthesis/multi_controlled/mcx_synthesis.py +356 -0
  556. qiskit/synthesis/one_qubit/__init__.py +15 -0
  557. qiskit/synthesis/one_qubit/one_qubit_decompose.py +288 -0
  558. qiskit/synthesis/permutation/__init__.py +18 -0
  559. qiskit/synthesis/permutation/permutation_full.py +78 -0
  560. qiskit/synthesis/permutation/permutation_lnn.py +54 -0
  561. qiskit/synthesis/permutation/permutation_reverse_lnn.py +93 -0
  562. qiskit/synthesis/permutation/permutation_utils.py +16 -0
  563. qiskit/synthesis/qft/__init__.py +16 -0
  564. qiskit/synthesis/qft/qft_decompose_full.py +79 -0
  565. qiskit/synthesis/qft/qft_decompose_lnn.py +78 -0
  566. qiskit/synthesis/stabilizer/__init__.py +16 -0
  567. qiskit/synthesis/stabilizer/stabilizer_circuit.py +149 -0
  568. qiskit/synthesis/stabilizer/stabilizer_decompose.py +193 -0
  569. qiskit/synthesis/two_qubit/__init__.py +19 -0
  570. qiskit/synthesis/two_qubit/local_invariance.py +63 -0
  571. qiskit/synthesis/two_qubit/two_qubit_decompose.py +759 -0
  572. qiskit/synthesis/two_qubit/weyl.py +97 -0
  573. qiskit/synthesis/two_qubit/xx_decompose/__init__.py +19 -0
  574. qiskit/synthesis/two_qubit/xx_decompose/circuits.py +300 -0
  575. qiskit/synthesis/two_qubit/xx_decompose/decomposer.py +324 -0
  576. qiskit/synthesis/two_qubit/xx_decompose/embodiments.py +163 -0
  577. qiskit/synthesis/two_qubit/xx_decompose/paths.py +412 -0
  578. qiskit/synthesis/two_qubit/xx_decompose/polytopes.py +262 -0
  579. qiskit/synthesis/two_qubit/xx_decompose/utilities.py +40 -0
  580. qiskit/synthesis/two_qubit/xx_decompose/weyl.py +133 -0
  581. qiskit/synthesis/unitary/__init__.py +13 -0
  582. qiskit/synthesis/unitary/aqc/__init__.py +177 -0
  583. qiskit/synthesis/unitary/aqc/approximate.py +116 -0
  584. qiskit/synthesis/unitary/aqc/aqc.py +175 -0
  585. qiskit/synthesis/unitary/aqc/cnot_structures.py +300 -0
  586. qiskit/synthesis/unitary/aqc/cnot_unit_circuit.py +103 -0
  587. qiskit/synthesis/unitary/aqc/cnot_unit_objective.py +299 -0
  588. qiskit/synthesis/unitary/aqc/elementary_operations.py +108 -0
  589. qiskit/synthesis/unitary/aqc/fast_gradient/__init__.py +164 -0
  590. qiskit/synthesis/unitary/aqc/fast_gradient/fast_grad_utils.py +237 -0
  591. qiskit/synthesis/unitary/aqc/fast_gradient/fast_gradient.py +226 -0
  592. qiskit/synthesis/unitary/aqc/fast_gradient/layer.py +370 -0
  593. qiskit/synthesis/unitary/aqc/fast_gradient/pmatrix.py +312 -0
  594. qiskit/synthesis/unitary/qsd.py +288 -0
  595. qiskit/transpiler/__init__.py +1283 -0
  596. qiskit/transpiler/basepasses.py +221 -0
  597. qiskit/transpiler/coupling.py +500 -0
  598. qiskit/transpiler/exceptions.py +59 -0
  599. qiskit/transpiler/instruction_durations.py +281 -0
  600. qiskit/transpiler/layout.py +737 -0
  601. qiskit/transpiler/passes/__init__.py +310 -0
  602. qiskit/transpiler/passes/analysis/__init__.py +23 -0
  603. qiskit/transpiler/passes/analysis/count_ops.py +30 -0
  604. qiskit/transpiler/passes/analysis/count_ops_longest_path.py +26 -0
  605. qiskit/transpiler/passes/analysis/dag_longest_path.py +24 -0
  606. qiskit/transpiler/passes/analysis/depth.py +33 -0
  607. qiskit/transpiler/passes/analysis/num_qubits.py +26 -0
  608. qiskit/transpiler/passes/analysis/num_tensor_factors.py +26 -0
  609. qiskit/transpiler/passes/analysis/resource_estimation.py +41 -0
  610. qiskit/transpiler/passes/analysis/size.py +36 -0
  611. qiskit/transpiler/passes/analysis/width.py +27 -0
  612. qiskit/transpiler/passes/basis/__init__.py +19 -0
  613. qiskit/transpiler/passes/basis/basis_translator.py +693 -0
  614. qiskit/transpiler/passes/basis/decompose.py +98 -0
  615. qiskit/transpiler/passes/basis/translate_parameterized.py +175 -0
  616. qiskit/transpiler/passes/basis/unroll_3q_or_more.py +88 -0
  617. qiskit/transpiler/passes/basis/unroll_custom_definitions.py +109 -0
  618. qiskit/transpiler/passes/calibration/__init__.py +17 -0
  619. qiskit/transpiler/passes/calibration/base_builder.py +79 -0
  620. qiskit/transpiler/passes/calibration/builders.py +20 -0
  621. qiskit/transpiler/passes/calibration/exceptions.py +22 -0
  622. qiskit/transpiler/passes/calibration/pulse_gate.py +98 -0
  623. qiskit/transpiler/passes/calibration/rx_builder.py +160 -0
  624. qiskit/transpiler/passes/calibration/rzx_builder.py +395 -0
  625. qiskit/transpiler/passes/calibration/rzx_templates.py +51 -0
  626. qiskit/transpiler/passes/layout/__init__.py +26 -0
  627. qiskit/transpiler/passes/layout/_csp_custom_solver.py +65 -0
  628. qiskit/transpiler/passes/layout/apply_layout.py +123 -0
  629. qiskit/transpiler/passes/layout/csp_layout.py +132 -0
  630. qiskit/transpiler/passes/layout/dense_layout.py +202 -0
  631. qiskit/transpiler/passes/layout/disjoint_utils.py +217 -0
  632. qiskit/transpiler/passes/layout/enlarge_with_ancilla.py +49 -0
  633. qiskit/transpiler/passes/layout/full_ancilla_allocation.py +117 -0
  634. qiskit/transpiler/passes/layout/layout_2q_distance.py +77 -0
  635. qiskit/transpiler/passes/layout/sabre_layout.py +482 -0
  636. qiskit/transpiler/passes/layout/sabre_pre_layout.py +220 -0
  637. qiskit/transpiler/passes/layout/set_layout.py +69 -0
  638. qiskit/transpiler/passes/layout/trivial_layout.py +66 -0
  639. qiskit/transpiler/passes/layout/vf2_layout.py +263 -0
  640. qiskit/transpiler/passes/layout/vf2_post_layout.py +419 -0
  641. qiskit/transpiler/passes/layout/vf2_utils.py +260 -0
  642. qiskit/transpiler/passes/optimization/__init__.py +42 -0
  643. qiskit/transpiler/passes/optimization/_gate_extension.py +80 -0
  644. qiskit/transpiler/passes/optimization/collect_1q_runs.py +31 -0
  645. qiskit/transpiler/passes/optimization/collect_2q_blocks.py +35 -0
  646. qiskit/transpiler/passes/optimization/collect_and_collapse.py +115 -0
  647. qiskit/transpiler/passes/optimization/collect_cliffords.py +88 -0
  648. qiskit/transpiler/passes/optimization/collect_linear_functions.py +80 -0
  649. qiskit/transpiler/passes/optimization/collect_multiqubit_blocks.py +227 -0
  650. qiskit/transpiler/passes/optimization/commutation_analysis.py +44 -0
  651. qiskit/transpiler/passes/optimization/commutative_cancellation.py +82 -0
  652. qiskit/transpiler/passes/optimization/commutative_inverse_cancellation.py +140 -0
  653. qiskit/transpiler/passes/optimization/consolidate_blocks.py +232 -0
  654. qiskit/transpiler/passes/optimization/cx_cancellation.py +65 -0
  655. qiskit/transpiler/passes/optimization/echo_rzx_weyl_decomposition.py +160 -0
  656. qiskit/transpiler/passes/optimization/elide_permutations.py +114 -0
  657. qiskit/transpiler/passes/optimization/hoare_opt.py +420 -0
  658. qiskit/transpiler/passes/optimization/inverse_cancellation.py +93 -0
  659. qiskit/transpiler/passes/optimization/normalize_rx_angle.py +149 -0
  660. qiskit/transpiler/passes/optimization/optimize_1q_commutation.py +268 -0
  661. qiskit/transpiler/passes/optimization/optimize_1q_decomposition.py +260 -0
  662. qiskit/transpiler/passes/optimization/optimize_1q_gates.py +384 -0
  663. qiskit/transpiler/passes/optimization/optimize_annotated.py +448 -0
  664. qiskit/transpiler/passes/optimization/optimize_cliffords.py +89 -0
  665. qiskit/transpiler/passes/optimization/optimize_swap_before_measure.py +71 -0
  666. qiskit/transpiler/passes/optimization/remove_diagonal_gates_before_measure.py +41 -0
  667. qiskit/transpiler/passes/optimization/remove_final_reset.py +37 -0
  668. qiskit/transpiler/passes/optimization/remove_reset_in_zero_state.py +37 -0
  669. qiskit/transpiler/passes/optimization/reset_after_measure_simplification.py +47 -0
  670. qiskit/transpiler/passes/optimization/split_2q_unitaries.py +40 -0
  671. qiskit/transpiler/passes/optimization/template_matching/__init__.py +19 -0
  672. qiskit/transpiler/passes/optimization/template_matching/backward_match.py +749 -0
  673. qiskit/transpiler/passes/optimization/template_matching/forward_match.py +452 -0
  674. qiskit/transpiler/passes/optimization/template_matching/maximal_matches.py +77 -0
  675. qiskit/transpiler/passes/optimization/template_matching/template_matching.py +370 -0
  676. qiskit/transpiler/passes/optimization/template_matching/template_substitution.py +638 -0
  677. qiskit/transpiler/passes/optimization/template_optimization.py +158 -0
  678. qiskit/transpiler/passes/routing/__init__.py +22 -0
  679. qiskit/transpiler/passes/routing/algorithms/__init__.py +33 -0
  680. qiskit/transpiler/passes/routing/algorithms/token_swapper.py +105 -0
  681. qiskit/transpiler/passes/routing/algorithms/types.py +46 -0
  682. qiskit/transpiler/passes/routing/algorithms/util.py +103 -0
  683. qiskit/transpiler/passes/routing/basic_swap.py +166 -0
  684. qiskit/transpiler/passes/routing/commuting_2q_gate_routing/__init__.py +25 -0
  685. qiskit/transpiler/passes/routing/commuting_2q_gate_routing/commuting_2q_block.py +60 -0
  686. qiskit/transpiler/passes/routing/commuting_2q_gate_routing/commuting_2q_gate_router.py +395 -0
  687. qiskit/transpiler/passes/routing/commuting_2q_gate_routing/pauli_2q_evolution_commutation.py +145 -0
  688. qiskit/transpiler/passes/routing/commuting_2q_gate_routing/swap_strategy.py +306 -0
  689. qiskit/transpiler/passes/routing/layout_transformation.py +119 -0
  690. qiskit/transpiler/passes/routing/lookahead_swap.py +390 -0
  691. qiskit/transpiler/passes/routing/sabre_swap.py +443 -0
  692. qiskit/transpiler/passes/routing/star_prerouting.py +392 -0
  693. qiskit/transpiler/passes/routing/stochastic_swap.py +532 -0
  694. qiskit/transpiler/passes/routing/utils.py +35 -0
  695. qiskit/transpiler/passes/scheduling/__init__.py +27 -0
  696. qiskit/transpiler/passes/scheduling/alap.py +153 -0
  697. qiskit/transpiler/passes/scheduling/alignments/__init__.py +81 -0
  698. qiskit/transpiler/passes/scheduling/alignments/align_measures.py +255 -0
  699. qiskit/transpiler/passes/scheduling/alignments/check_durations.py +78 -0
  700. qiskit/transpiler/passes/scheduling/alignments/pulse_gate_validation.py +105 -0
  701. qiskit/transpiler/passes/scheduling/alignments/reschedule.py +250 -0
  702. qiskit/transpiler/passes/scheduling/asap.py +175 -0
  703. qiskit/transpiler/passes/scheduling/base_scheduler.py +308 -0
  704. qiskit/transpiler/passes/scheduling/dynamical_decoupling.py +307 -0
  705. qiskit/transpiler/passes/scheduling/padding/__init__.py +16 -0
  706. qiskit/transpiler/passes/scheduling/padding/base_padding.py +256 -0
  707. qiskit/transpiler/passes/scheduling/padding/dynamical_decoupling.py +441 -0
  708. qiskit/transpiler/passes/scheduling/padding/pad_delay.py +79 -0
  709. qiskit/transpiler/passes/scheduling/scheduling/__init__.py +17 -0
  710. qiskit/transpiler/passes/scheduling/scheduling/alap.py +127 -0
  711. qiskit/transpiler/passes/scheduling/scheduling/asap.py +131 -0
  712. qiskit/transpiler/passes/scheduling/scheduling/base_scheduler.py +90 -0
  713. qiskit/transpiler/passes/scheduling/scheduling/set_io_latency.py +64 -0
  714. qiskit/transpiler/passes/scheduling/time_unit_conversion.py +160 -0
  715. qiskit/transpiler/passes/synthesis/__init__.py +20 -0
  716. qiskit/transpiler/passes/synthesis/aqc_plugin.py +153 -0
  717. qiskit/transpiler/passes/synthesis/high_level_synthesis.py +691 -0
  718. qiskit/transpiler/passes/synthesis/hls_plugins.py +928 -0
  719. qiskit/transpiler/passes/synthesis/linear_functions_synthesis.py +41 -0
  720. qiskit/transpiler/passes/synthesis/plugin.py +734 -0
  721. qiskit/transpiler/passes/synthesis/qubit_tracker.py +132 -0
  722. qiskit/transpiler/passes/synthesis/solovay_kitaev_synthesis.py +297 -0
  723. qiskit/transpiler/passes/synthesis/unitary_synthesis.py +1055 -0
  724. qiskit/transpiler/passes/utils/__init__.py +33 -0
  725. qiskit/transpiler/passes/utils/barrier_before_final_measurements.py +95 -0
  726. qiskit/transpiler/passes/utils/check_gate_direction.py +52 -0
  727. qiskit/transpiler/passes/utils/check_map.py +78 -0
  728. qiskit/transpiler/passes/utils/contains_instruction.py +45 -0
  729. qiskit/transpiler/passes/utils/control_flow.py +65 -0
  730. qiskit/transpiler/passes/utils/convert_conditions_to_if_ops.py +88 -0
  731. qiskit/transpiler/passes/utils/dag_fixed_point.py +36 -0
  732. qiskit/transpiler/passes/utils/error.py +69 -0
  733. qiskit/transpiler/passes/utils/filter_op_nodes.py +65 -0
  734. qiskit/transpiler/passes/utils/fixed_point.py +48 -0
  735. qiskit/transpiler/passes/utils/gate_direction.py +349 -0
  736. qiskit/transpiler/passes/utils/gates_basis.py +74 -0
  737. qiskit/transpiler/passes/utils/merge_adjacent_barriers.py +162 -0
  738. qiskit/transpiler/passes/utils/minimum_point.py +118 -0
  739. qiskit/transpiler/passes/utils/remove_barriers.py +49 -0
  740. qiskit/transpiler/passes/utils/remove_final_measurements.py +114 -0
  741. qiskit/transpiler/passes/utils/unroll_forloops.py +81 -0
  742. qiskit/transpiler/passmanager.py +490 -0
  743. qiskit/transpiler/passmanager_config.py +198 -0
  744. qiskit/transpiler/preset_passmanagers/__init__.py +73 -0
  745. qiskit/transpiler/preset_passmanagers/builtin_plugins.py +1019 -0
  746. qiskit/transpiler/preset_passmanagers/common.py +647 -0
  747. qiskit/transpiler/preset_passmanagers/generate_preset_pass_manager.py +543 -0
  748. qiskit/transpiler/preset_passmanagers/level0.py +113 -0
  749. qiskit/transpiler/preset_passmanagers/level1.py +120 -0
  750. qiskit/transpiler/preset_passmanagers/level2.py +119 -0
  751. qiskit/transpiler/preset_passmanagers/level3.py +119 -0
  752. qiskit/transpiler/preset_passmanagers/plugin.py +353 -0
  753. qiskit/transpiler/target.py +1261 -0
  754. qiskit/transpiler/timing_constraints.py +59 -0
  755. qiskit/user_config.py +262 -0
  756. qiskit/utils/__init__.py +89 -0
  757. qiskit/utils/classtools.py +146 -0
  758. qiskit/utils/deprecation.py +490 -0
  759. qiskit/utils/lazy_tester.py +363 -0
  760. qiskit/utils/multiprocessing.py +56 -0
  761. qiskit/utils/optionals.py +347 -0
  762. qiskit/utils/parallel.py +191 -0
  763. qiskit/utils/units.py +143 -0
  764. qiskit/version.py +84 -0
  765. qiskit/visualization/__init__.py +288 -0
  766. qiskit/visualization/array.py +204 -0
  767. qiskit/visualization/bloch.py +778 -0
  768. qiskit/visualization/circuit/__init__.py +15 -0
  769. qiskit/visualization/circuit/_utils.py +675 -0
  770. qiskit/visualization/circuit/circuit_visualization.py +726 -0
  771. qiskit/visualization/circuit/latex.py +661 -0
  772. qiskit/visualization/circuit/matplotlib.py +2029 -0
  773. qiskit/visualization/circuit/qcstyle.py +278 -0
  774. qiskit/visualization/circuit/styles/__init__.py +13 -0
  775. qiskit/visualization/circuit/styles/bw.json +202 -0
  776. qiskit/visualization/circuit/styles/clifford.json +202 -0
  777. qiskit/visualization/circuit/styles/iqp-dark.json +214 -0
  778. qiskit/visualization/circuit/styles/iqp.json +214 -0
  779. qiskit/visualization/circuit/styles/textbook.json +202 -0
  780. qiskit/visualization/circuit/text.py +1844 -0
  781. qiskit/visualization/circuit_visualization.py +19 -0
  782. qiskit/visualization/counts_visualization.py +481 -0
  783. qiskit/visualization/dag_visualization.py +316 -0
  784. qiskit/visualization/exceptions.py +21 -0
  785. qiskit/visualization/gate_map.py +1485 -0
  786. qiskit/visualization/library.py +37 -0
  787. qiskit/visualization/pass_manager_visualization.py +319 -0
  788. qiskit/visualization/pulse_v2/__init__.py +21 -0
  789. qiskit/visualization/pulse_v2/core.py +901 -0
  790. qiskit/visualization/pulse_v2/device_info.py +173 -0
  791. qiskit/visualization/pulse_v2/drawings.py +253 -0
  792. qiskit/visualization/pulse_v2/events.py +254 -0
  793. qiskit/visualization/pulse_v2/generators/__init__.py +40 -0
  794. qiskit/visualization/pulse_v2/generators/barrier.py +76 -0
  795. qiskit/visualization/pulse_v2/generators/chart.py +208 -0
  796. qiskit/visualization/pulse_v2/generators/frame.py +436 -0
  797. qiskit/visualization/pulse_v2/generators/snapshot.py +133 -0
  798. qiskit/visualization/pulse_v2/generators/waveform.py +645 -0
  799. qiskit/visualization/pulse_v2/interface.py +456 -0
  800. qiskit/visualization/pulse_v2/layouts.py +387 -0
  801. qiskit/visualization/pulse_v2/plotters/__init__.py +17 -0
  802. qiskit/visualization/pulse_v2/plotters/base_plotter.py +53 -0
  803. qiskit/visualization/pulse_v2/plotters/matplotlib.py +201 -0
  804. qiskit/visualization/pulse_v2/stylesheet.py +312 -0
  805. qiskit/visualization/pulse_v2/types.py +242 -0
  806. qiskit/visualization/state_visualization.py +1518 -0
  807. qiskit/visualization/timeline/__init__.py +21 -0
  808. qiskit/visualization/timeline/core.py +457 -0
  809. qiskit/visualization/timeline/drawings.py +260 -0
  810. qiskit/visualization/timeline/generators.py +506 -0
  811. qiskit/visualization/timeline/interface.py +424 -0
  812. qiskit/visualization/timeline/layouts.py +115 -0
  813. qiskit/visualization/timeline/plotters/__init__.py +16 -0
  814. qiskit/visualization/timeline/plotters/base_plotter.py +58 -0
  815. qiskit/visualization/timeline/plotters/matplotlib.py +192 -0
  816. qiskit/visualization/timeline/stylesheet.py +301 -0
  817. qiskit/visualization/timeline/types.py +148 -0
  818. qiskit/visualization/transition_visualization.py +369 -0
  819. qiskit/visualization/utils.py +49 -0
  820. qiskit-1.3.0b1.dist-info/LICENSE.txt +203 -0
  821. qiskit-1.3.0b1.dist-info/METADATA +221 -0
  822. qiskit-1.3.0b1.dist-info/RECORD +825 -0
  823. qiskit-1.3.0b1.dist-info/WHEEL +5 -0
  824. qiskit-1.3.0b1.dist-info/entry_points.txt +57 -0
  825. qiskit-1.3.0b1.dist-info/top_level.txt +1 -0
qiskit/qpy/__init__.py ADDED
@@ -0,0 +1,1641 @@
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
+
103
+ The QPY format is designed to be backwards compatible moving forward. This means
104
+ you should be able to load a QPY with any newer Qiskit version than the one
105
+ that generated it. However, loading a QPY file with an older Qiskit version is
106
+ not supported and may not work.
107
+
108
+ For example, if you generated a QPY file using qiskit-terra 0.18.1 you could
109
+ load that QPY file with qiskit-terra 0.19.0 and a hypothetical qiskit-terra
110
+ 0.29.0. However, loading that QPY file with 0.18.0 is not supported and may not
111
+ work.
112
+
113
+ If a feature being loaded is deprecated in the corresponding qiskit release, QPY will
114
+ raise a :exc:`~.QPYLoadingDeprecatedFeatureWarning` informing of the deprecation period
115
+ and how the feature will be internally handled.
116
+
117
+ .. autoexception:: QPYLoadingDeprecatedFeatureWarning
118
+
119
+ QPY format version history
120
+ --------------------------
121
+
122
+ If you're planning to load a QPY file between different Qiskit versions knowing
123
+ which versions were available in a given release are useful. As the QPY is
124
+ backwards compatible but not forwards compatible you need to ensure a given
125
+ QPY format version was released in the release you're calling :func:`.load`
126
+ with. The following table lists the QPY versions that were supported in every
127
+ Qiskit (and qiskit-terra prior to Qiskit 1.0.0) release going back to the introduction
128
+ of QPY in qiskit-terra 0.18.0.
129
+
130
+ .. list-table:: QPY Format Version History
131
+ :header-rows: 1
132
+
133
+ * - Qiskit (qiskit-terra for < 1.0.0) version
134
+ - :func:`.dump` format(s) output versions
135
+ - :func:`.load` maximum supported version (older format versions can always be read)
136
+ * - 1.1.0
137
+ - 10, 11, 12
138
+ - 12
139
+ * - 1.0.2
140
+ - 10, 11
141
+ - 11
142
+ * - 1.0.1
143
+ - 10, 11
144
+ - 11
145
+ * - 1.0.0
146
+ - 10, 11
147
+ - 11
148
+ * - 0.46.1
149
+ - 10
150
+ - 10
151
+ * - 0.45.3
152
+ - 10
153
+ - 10
154
+ * - 0.45.2
155
+ - 10
156
+ - 10
157
+ * - 0.45.1
158
+ - 10
159
+ - 10
160
+ * - 0.45.0
161
+ - 10
162
+ - 10
163
+ * - 0.25.3
164
+ - 9
165
+ - 9
166
+ * - 0.25.2
167
+ - 9
168
+ - 9
169
+ * - 0.25.1
170
+ - 9
171
+ - 9
172
+ * - 0.24.2
173
+ - 8
174
+ - 8
175
+ * - 0.24.1
176
+ - 7
177
+ - 7
178
+ * - 0.24.0
179
+ - 7
180
+ - 7
181
+ * - 0.23.3
182
+ - 6
183
+ - 6
184
+ * - 0.23.2
185
+ - 6
186
+ - 6
187
+ * - 0.23.1
188
+ - 6
189
+ - 6
190
+ * - 0.23.0
191
+ - 6
192
+ - 6
193
+ * - 0.22.4
194
+ - 5
195
+ - 5
196
+ * - 0.22.3
197
+ - 5
198
+ - 5
199
+ * - 0.22.2
200
+ - 5
201
+ - 5
202
+ * - 0.22.1
203
+ - 5
204
+ - 5
205
+ * - 0.22.0
206
+ - 5
207
+ - 5
208
+ * - 0.21.2
209
+ - 5
210
+ - 5
211
+ * - 0.21.1
212
+ - 5
213
+ - 5
214
+ * - 0.21.0
215
+ - 5
216
+ - 5
217
+ * - 0.20.2
218
+ - 4
219
+ - 4
220
+ * - 0.20.1
221
+ - 4
222
+ - 4
223
+ * - 0.20.0
224
+ - 4
225
+ - 4
226
+ * - 0.19.2
227
+ - 4
228
+ - 4
229
+ * - 0.19.1
230
+ - 3
231
+ - 3
232
+ * - 0.19.0
233
+ - 2
234
+ - 2
235
+ * - 0.18.3
236
+ - 1
237
+ - 1
238
+ * - 0.18.2
239
+ - 1
240
+ - 1
241
+ * - 0.18.1
242
+ - 1
243
+ - 1
244
+ * - 0.18.0
245
+ - 1
246
+ - 1
247
+
248
+ .. _qpy_format:
249
+
250
+ QPY Format
251
+ ==========
252
+
253
+ The QPY serialization format is a portable cross-platform binary
254
+ serialization format for :class:`~qiskit.circuit.QuantumCircuit` objects in Qiskit. The basic
255
+ file format is as follows:
256
+
257
+ A QPY file (or memory object) always starts with the following 6
258
+ byte UTF8 string: ``QISKIT`` which is immediately followed by the overall
259
+ file header. The contents of the file header as defined as a C struct are:
260
+
261
+ .. code-block:: c
262
+
263
+ struct {
264
+ uint8_t qpy_version;
265
+ uint8_t qiskit_major_version;
266
+ uint8_t qiskit_minor_version;
267
+ uint8_t qiskit_patch_version;
268
+ uint64_t num_circuits;
269
+ }
270
+
271
+
272
+ From V10 on, a new field is added to the file header struct to represent the
273
+ encoding scheme used for symbolic expressions:
274
+
275
+ .. code-block:: c
276
+
277
+ struct {
278
+ uint8_t qpy_version;
279
+ uint8_t qiskit_major_version;
280
+ uint8_t qiskit_minor_version;
281
+ uint8_t qiskit_patch_version;
282
+ uint64_t num_circuits;
283
+ char symbolic_encoding;
284
+ }
285
+
286
+ All values use network byte order [#f1]_ (big endian) for cross platform
287
+ compatibility.
288
+
289
+ The file header is immediately followed by the circuit payloads.
290
+ Each individual circuit is composed of the following parts:
291
+
292
+ ``HEADER | METADATA | REGISTERS | STANDALONE_VARS | CUSTOM_DEFINITIONS | INSTRUCTIONS``
293
+
294
+ The ``STANDALONE_VARS`` are new in QPY version 12; before that, there was no data between
295
+ ``REGISTERS`` and ``CUSTOM_DEFINITIONS``.
296
+
297
+ There is a circuit payload for each circuit (where the total number is dictated
298
+ by ``num_circuits`` in the file header). There is no padding between the
299
+ circuits in the data.
300
+
301
+ .. _qpy_version_12:
302
+
303
+ Version 12
304
+ ----------
305
+
306
+ Version 12 adds support for:
307
+
308
+ * circuits containing memory-owning :class:`.expr.Var` variables.
309
+
310
+ Changes to HEADER
311
+ ~~~~~~~~~~~~~~~~~
312
+
313
+ The HEADER struct for an individual circuit has added three ``uint32_t`` counts of the input,
314
+ captured and locally declared variables in the circuit. The new form looks like:
315
+
316
+ .. code-block:: c
317
+
318
+ struct {
319
+ uint16_t name_size;
320
+ char global_phase_type;
321
+ uint16_t global_phase_size;
322
+ uint32_t num_qubits;
323
+ uint32_t num_clbits;
324
+ uint64_t metadata_size;
325
+ uint32_t num_registers;
326
+ uint64_t num_instructions;
327
+ uint32_t num_vars;
328
+ } HEADER_V12;
329
+
330
+ The ``HEADER_V12`` struct is followed immediately by the same name, global-phase, metadata
331
+ and register information as the V2 version of the header. Immediately following the registers is
332
+ ``num_vars`` instances of ``EXPR_VAR_STANDALONE`` that define the variables in this circuit. After
333
+ that, the data continues with custom definitions and instructions as in prior versions of QPY.
334
+
335
+
336
+ EXPR_VAR_DECLARATION
337
+ ~~~~~~~~~~~~~~~~~~~~
338
+
339
+ An ``EXPR_VAR_DECLARATION`` defines an :class:`.expr.Var` instance that is standalone; that is, it
340
+ represents a self-owned memory location rather than wrapping a :class:`.Clbit` or
341
+ :class:`.ClassicalRegister`. The payload is a C struct:
342
+
343
+ .. code-block:: c
344
+
345
+ struct {
346
+ char uuid_bytes[16];
347
+ char usage;
348
+ uint16_t name_size;
349
+ }
350
+
351
+ which is immediately followed by an ``EXPR_TYPE`` payload and then ``name_size`` bytes of UTF-8
352
+ encoding string data containing the name of the variable.
353
+
354
+ The ``char`` usage type code takes the following values:
355
+
356
+ ========= =========================================================================================
357
+ Type code Meaning
358
+ ========= =========================================================================================
359
+ ``I`` An ``input`` variable to the circuit.
360
+
361
+ ``C`` A ``capture`` variable to the circuit.
362
+
363
+ ``L`` A locally declared variable to the circuit.
364
+ ========= =========================================================================================
365
+
366
+
367
+ Changes to EXPR_VAR
368
+ ~~~~~~~~~~~~~~~~~~~
369
+
370
+ The EXPR_VAR variable has gained a new type code and payload, in addition to the pre-existing ones:
371
+
372
+ =========================== ========= ============================================================
373
+ Python class Type code Payload
374
+ =========================== ========= ============================================================
375
+ :class:`.UUID` ``U`` One ``uint32_t`` index of the variable into the series of
376
+ ``EXPR_VAR_STANDALONE`` variables that were written
377
+ immediately after the circuit header.
378
+ =========================== ========= ============================================================
379
+
380
+ Notably, this new type-code indexes into pre-defined variables from the circuit header, rather than
381
+ redefining the variable again in each location it is used.
382
+
383
+
384
+ Changes to EXPRESSION
385
+ ---------------------
386
+
387
+ The EXPRESSION type code has a new possible entry, ``i``, corresponding to :class:`.expr.Index`
388
+ nodes.
389
+
390
+ ====================== ========= ======================================================= ========
391
+ Qiskit class Type code Payload Children
392
+ ====================== ========= ======================================================= ========
393
+ :class:`~.expr.Index` ``i`` No additional payload. The children are the target 2
394
+ and the index, in that order.
395
+ ====================== ========= ======================================================= ========
396
+
397
+
398
+ .. _qpy_version_11:
399
+
400
+ Version 11
401
+ ----------
402
+
403
+ Version 11 is identical to Version 10 except for the following.
404
+ First, the names in the CUSTOM_INSTRUCTION blocks
405
+ have a suffix of the form ``"_{uuid_hex}"`` where ``uuid_hex`` is a uuid
406
+ hexadecimal string such as returned by :attr:`.UUID.hex`. For example:
407
+ ``"b3ecab5b4d6a4eb6bc2b2dbf18d83e1e"``.
408
+ Second, it adds support for :class:`.AnnotatedOperation`
409
+ objects. The base operation of an annotated operation is stored using the INSTRUCTION block,
410
+ and an additional ``type`` value ``'a'``is added to indicate that the custom instruction is an
411
+ annotated operation. The list of modifiers are stored as instruction parameters using INSTRUCTION_PARAM,
412
+ with an additional value ``'m'`` is added to indicate that the parameter is of type
413
+ :class:`~qiskit.circuit.annotated_operation.Modifier`. Each modifier is stored using the
414
+ MODIFIER struct.
415
+
416
+ .. _modifier_qpy:
417
+
418
+ MODIFIER
419
+ ~~~~~~~~
420
+
421
+ This represents :class:`~qiskit.circuit.annotated_operation.Modifier`
422
+
423
+ .. code-block:: c
424
+
425
+ struct {
426
+ char type;
427
+ uint32_t num_ctrl_qubits;
428
+ uint32_t ctrl_state;
429
+ double power;
430
+ }
431
+
432
+ This is sufficient to store different types of modifiers required for serializing objects
433
+ of type :class:`.AnnotatedOperation`.
434
+ The field ``type`` is either ``'i'``, ``'c'`` or ``'p'``, representing whether the modifier
435
+ is respectively an inverse modifier, a control modifier or a power modifier. In the second
436
+ case, the fields ``num_ctrl_qubits`` and ``ctrl_state`` specify the control logic of the base
437
+ operation, and in the third case the field ``power`` represents the power of the base operation.
438
+
439
+ .. _qpy_version_10:
440
+
441
+ Version 10
442
+ ----------
443
+
444
+ Version 10 adds support for:
445
+
446
+ * symengine-native serialization for objects of type :class:`~.ParameterExpression` as well as
447
+ symbolic expressions in Pulse schedule blocks.
448
+ * new fields in the :class:`~.TranspileLayout` class added in the Qiskit 0.45.0 release.
449
+
450
+ The symbolic_encoding field is added to the file header, and a new encoding type char
451
+ is introduced, mapped to each symbolic library as follows: ``p`` refers to sympy
452
+ encoding and ``e`` refers to symengine encoding.
453
+
454
+ Changes to FILE_HEADER
455
+ ~~~~~~~~~~~~~~~~~~~~~~
456
+
457
+ The contents of FILE_HEADER after V10 are defined as a C struct as:
458
+
459
+ .. code-block:: c
460
+
461
+ struct {
462
+ uint8_t qpy_version;
463
+ uint8_t qiskit_major_version;
464
+ uint8_t qiskit_minor_version;
465
+ uint8_t qiskit_patch_version;
466
+ uint64_t num_circuits;
467
+ char symbolic_encoding;
468
+ } FILE_HEADER_V10;
469
+
470
+ Changes to LAYOUT
471
+ ~~~~~~~~~~~~~~~~~
472
+
473
+ The ``LAYOUT`` struct is updated to have an additional ``input_qubit_count`` field.
474
+ With version 10 the ``LAYOUT`` struct is now:
475
+
476
+ .. code-block:: c
477
+
478
+ struct {
479
+ char exists;
480
+ int32_t initial_layout_size;
481
+ int32_t input_mapping_size;
482
+ int32_t final_layout_size;
483
+ uint32_t extra_registers;
484
+ int32_t input_qubit_count;
485
+ }
486
+
487
+ The rest of the layout data after the ``LAYOUT`` struct is represented as in previous versions. If
488
+ ``input qubit_count`` is < 0 that indicates that both ``_input_qubit_count``
489
+ and ``_output_qubit_list`` in the :class:`~.TranspileLayout` object are ``None``.
490
+
491
+ .. _qpy_version_9:
492
+
493
+ Version 9
494
+ ---------
495
+
496
+ Version 9 adds support for classical :class:`~.expr.Expr` nodes and their associated
497
+ :class:`~.types.Type`\\ s.
498
+
499
+
500
+ EXPRESSION
501
+ ~~~~~~~~~~
502
+
503
+ An :class:`~.expr.Expr` node is represented by a stream of variable-width data. A node itself is
504
+ represented by (in order in the byte stream):
505
+
506
+ #. a one-byte type code discriminator;
507
+ #. an EXPR_TYPE object;
508
+ #. a type-code-specific additional payload;
509
+ #. a type-code-specific number of child EXPRESSION payloads (the number of these is implied by the
510
+ type code and not explicitly stored).
511
+
512
+ Each of these are described in the following table:
513
+
514
+ ====================== ========= ======================================================= ========
515
+ Qiskit class Type code Payload Children
516
+ ====================== ========= ======================================================= ========
517
+ :class:`~.expr.Var` ``x`` One EXPR_VAR. 0
518
+
519
+ :class:`~.expr.Value` ``v`` One EXPR_VALUE. 0
520
+
521
+ :class:`~.expr.Cast` ``c`` One ``_Bool`` that corresponds to the value of 1
522
+ ``implicit``.
523
+
524
+ :class:`~.expr.Unary` ``u`` One ``uint8_t`` with the same numeric value as the 1
525
+ :class:`.Unary.Op`.
526
+
527
+ :class:`~.expr.Binary` ``b`` One ``uint8_t`` with the same numeric value as the 2
528
+ :class:`.Binary.Op`.
529
+ ====================== ========= ======================================================= ========
530
+
531
+
532
+ EXPR_TYPE
533
+ ~~~~~~~~~
534
+
535
+ A :class:`~.types.Type` is encoded by a single-byte ASCII ``char`` that encodes the kind of type,
536
+ followed by a payload that varies depending on the type. The defined codes are:
537
+
538
+ ====================== ========= =================================================================
539
+ Qiskit class Type code Payload
540
+ ====================== ========= =================================================================
541
+ :class:`~.types.Bool` ``b`` None.
542
+
543
+ :class:`~.types.Uint` ``u`` One ``uint32_t width``.
544
+ ====================== ========= =================================================================
545
+
546
+
547
+ EXPR_VAR
548
+ ~~~~~~~~
549
+
550
+ This represents a runtime variable of a :class:`~.expr.Var` node. These are a type code, followed
551
+ by a type-code-specific payload:
552
+
553
+ =========================== ========= ============================================================
554
+ Python class Type code Payload
555
+ =========================== ========= ============================================================
556
+ :class:`.Clbit` ``C`` One ``uint32_t index`` that is the index of the
557
+ :class:`.Clbit` in the containing circuit.
558
+
559
+ :class:`.ClassicalRegister` ``R`` One ``uint16_t reg_name_size``, followed by that many bytes
560
+ of UTF-8 string data of the register name.
561
+ =========================== ========= ============================================================
562
+
563
+
564
+ EXPR_VALUE
565
+ ~~~~~~~~~~
566
+
567
+ This represents a literal object in the classical type system, such as an integer. Currently there
568
+ are very few such literals. These are encoded as a type code, followed by a type-code-specific
569
+ payload.
570
+
571
+ =========== ========= ============================================================================
572
+ Python type Type code Payload
573
+ =========== ========= ============================================================================
574
+ ``bool`` ``b`` One ``_Bool value``.
575
+
576
+ ``int`` ``i`` One ``uint8_t num_bytes``, followed by the integer encoded into that many
577
+ many bytes (network order) in a two's complement representation.
578
+ =========== ========= ============================================================================
579
+
580
+
581
+
582
+ Changes to INSTRUCTION
583
+ ~~~~~~~~~~~~~~~~~~~~~~
584
+
585
+ To support the use of :class:`~.expr.Expr` nodes in the fields :attr:`.IfElseOp.condition`,
586
+ :attr:`.WhileLoopOp.condition` and :attr:`.SwitchCaseOp.target`, the INSTRUCTION struct is changed
587
+ in an ABI compatible-manner to :ref:`its previous definition <qpy_instruction_v5>`. The new struct
588
+ is the C struct:
589
+
590
+ .. code-block:: c
591
+
592
+ struct {
593
+ uint16_t name_size;
594
+ uint16_t label_size;
595
+ uint16_t num_parameters;
596
+ uint32_t num_qargs;
597
+ uint32_t num_cargs;
598
+ uint8_t conditional_key;
599
+ uint16_t conditional_reg_name_size;
600
+ int64_t conditional_value;
601
+ uint32_t num_ctrl_qubits;
602
+ uint32_t ctrl_state;
603
+ }
604
+
605
+ where the only change is that a ``uint8_t conditional_key`` entry has replaced ``_Bool
606
+ has_conditional``. This new ``conditional_key`` takes the following numeric values, with these
607
+ effects:
608
+
609
+ ===== =============================================================================================
610
+ Value Effects
611
+ ===== =============================================================================================
612
+ 0 The instruction has its ``.condition`` field set to ``None``. The
613
+ ``conditional_reg_name_size`` and ``conditional_value`` fields should be ignored.
614
+
615
+ 1 The instruction has its ``.condition`` field set to a 2-tuple of either a :class:`.Clbit`
616
+ or a :class:`.ClassicalRegister`, and a integer of value ``conditional_value``. The
617
+ INSTRUCTION payload, including its trailing data is parsed exactly as it would be in QPY
618
+ versions less than 8.
619
+
620
+ 2 The instruction has its ``.condition`` field set to a :class:`~.expr.Expr` node. The
621
+ ``conditional_reg_name_size`` and ``conditional_value`` fields should be ignored. The data
622
+ following the struct is followed (as in QPY versions less than 8) by ``name_size`` bytes of
623
+ UTF-8 string data for the class name and ``label_size`` bytes of UTF-8 string data for the
624
+ label (if any). Then, there is one INSTRUCTION_PARAM, which will contain an EXPRESSION. After
625
+ that, parsing continues with the INSTRUCTION_ARG structs, as in previous versions of QPY.
626
+ ===== =============================================================================================
627
+
628
+
629
+ Changes to INSTRUCTION_PARAM
630
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
631
+
632
+ A new type code ``x`` is added that defines an EXPRESSION parameter.
633
+
634
+
635
+ .. _qpy_version_8:
636
+
637
+ Version 8
638
+ ---------
639
+
640
+ Version 8 adds support for handling a :class:`~.TranspileLayout` stored in the
641
+ :attr:`.QuantumCircuit.layout` attribute. In version 8 immediately following the
642
+ calibrations block at the end of the circuit payload there is now the
643
+ ``LAYOUT`` struct. This struct outlines the size of the three attributes of a
644
+ :class:`~.TranspileLayout` class.
645
+
646
+ LAYOUT
647
+ ~~~~~~
648
+
649
+ .. code-block:: c
650
+
651
+ struct {
652
+ char exists;
653
+ int32_t initial_layout_size;
654
+ int32_t input_mapping_size;
655
+ int32_t final_layout_size;
656
+ uint32_t extra_registers;
657
+ }
658
+
659
+ If any of the signed values are ``-1`` this indicates the corresponding
660
+ attribute is ``None``.
661
+
662
+ Immediately following the ``LAYOUT`` struct there is a :ref:`qpy_registers` struct
663
+ for ``extra_registers`` (specifically the format introduced in :ref:`qpy_version_4`)
664
+ standalone register definitions that aren't present in the circuit. Then there
665
+ are ``initial_layout_size`` ``INITIAL_LAYOUT_BIT`` structs to define the
666
+ :attr:`.TranspileLayout.initial_layout` attribute.
667
+
668
+ INITIAL_LAYOUT_BIT
669
+ ~~~~~~~~~~~~~~~~~~
670
+
671
+ .. code-block:: c
672
+
673
+ struct {
674
+ int32_t index;
675
+ int32_t register_size;
676
+ }
677
+
678
+ Where a value of ``-1`` indicates ``None`` (as in no register is associated
679
+ with the bit). Following each ``INITIAL_LAYOUT_BIT`` struct is ``register_size``
680
+ bytes for a ``utf8`` encoded string for the register name.
681
+
682
+ Following the initial layout there is ``input_mapping_size`` array of
683
+ ``uint32_t`` integers representing the positions of the physical bit from the
684
+ initial layout. This enables constructing a list of virtual bits where the
685
+ array index is its input mapping position.
686
+
687
+ Finally, there is an array of ``final_layout_size`` ``uint32_t`` integers. Each
688
+ element is an index in the circuit's ``qubits`` attribute which enables building
689
+ a mapping from qubit starting position to the output position at the end of the
690
+ circuit.
691
+
692
+ .. _qpy_version_7:
693
+
694
+ Version 7
695
+ ---------
696
+
697
+ Version 7 adds support for :class:`.~Reference` instruction and serialization of
698
+ a :class:`.~ScheduleBlock` program while keeping its reference to subroutines::
699
+
700
+ from qiskit import pulse
701
+ from qiskit import qpy
702
+
703
+ with pulse.build() as schedule:
704
+ pulse.reference("cr45p", "q0", "q1")
705
+ pulse.reference("x", "q0")
706
+ pulse.reference("cr45p", "q0", "q1")
707
+
708
+ with open('template_ecr.qpy', 'wb') as fd:
709
+ qpy.dump(schedule, fd)
710
+
711
+ The conventional :ref:`qpy_schedule_block` data model is preserved, but in
712
+ version 7 it is immediately followed by an extra :ref:`qpy_mapping` utf8 bytes block
713
+ representing the data of the referenced subroutines.
714
+
715
+ New type key character is added to the :ref:`qpy_schedule_instructions` group
716
+ for the :class:`.~Reference` instruction.
717
+
718
+ - ``y``: :class:`~qiskit.pulse.instructions.Reference` instruction
719
+
720
+ New type key character is added to the :ref:`qpy_schedule_operands` group
721
+ for the operands of :class:`.~Reference` instruction,
722
+ which is a tuple of strings, e.g. ("cr45p", "q0", "q1").
723
+
724
+ - ``o``: string (operand string)
725
+
726
+ Note that this is the same encoding with the built-in Python string, however,
727
+ the standard value encoding in QPY uses ``s`` type character for string data,
728
+ which conflicts with the :class:`~qiskit.pulse.library.SymbolicPulse` in the scope of
729
+ pulse instruction operands. A special type character ``o`` is reserved for
730
+ the string data that appears in the pulse instruction operands.
731
+
732
+ In addition, version 7 adds two new type keys to the INSTRUCTION_PARM struct. ``"d"`` is followed
733
+ by no data and represents the literal value :data:`.CASE_DEFAULT` for switch-statement support.
734
+ ``"R"`` represents a :class:`.ClassicalRegister` or :class:`.Clbit`, and is followed by the same
735
+ format as the description of register or classical bit as used in the first element of :ref:`the
736
+ condition of an INSTRUCTION field <qpy_instructions>`.
737
+
738
+ .. _qpy_version_6:
739
+
740
+ Version 6
741
+ ---------
742
+
743
+ Version 6 adds support for :class:`.~ScalableSymbolicPulse`. These objects are saved and read
744
+ like `SymbolicPulse` objects, and the class name is added to the data to correctly handle
745
+ the class selection.
746
+
747
+ `SymbolicPulse` block now starts with SYMBOLIC_PULSE_V2 header:
748
+
749
+ .. code-block:: c
750
+
751
+ struct {
752
+ uint16_t class_name_size;
753
+ uint16_t type_size;
754
+ uint16_t envelope_size;
755
+ uint16_t constraints_size;
756
+ uint16_t valid_amp_conditions_size;
757
+ _bool amp_limited;
758
+ }
759
+
760
+ The only change compared to :ref:`qpy_version_5` is the addition of `class_name_size`. The header
761
+ is then immediately followed by ``class_name_size`` utf8 bytes with the name of the class. Currently,
762
+ either `SymbolicPulse` or `ScalableSymbolicPulse` are supported. The rest of the data is then
763
+ identical to :ref:`qpy_version_5`.
764
+
765
+ .. _qpy_version_5:
766
+
767
+ Version 5
768
+ ---------
769
+
770
+ Version 5 changes from :ref:`qpy_version_4` by adding support for :class:`.~ScheduleBlock`
771
+ and changing two payloads the INSTRUCTION metadata payload and the CUSTOM_INSTRUCTION block.
772
+ These now have new fields to better account for :class:`~.ControlledGate` objects in a circuit.
773
+ In addition, new payload MAP_ITEM is defined to implement the :ref:`qpy_mapping` block.
774
+
775
+ With the support of :class:`.~ScheduleBlock`, now :class:`~.QuantumCircuit` can be
776
+ serialized together with :attr:`~.QuantumCircuit.calibrations`, or
777
+ `Pulse Gates <https://docs.quantum.ibm.com/guides/pulse>`_.
778
+ In QPY version 5 and above, :ref:`qpy_circuit_calibrations` payload is
779
+ packed after the :ref:`qpy_instructions` block.
780
+
781
+ In QPY version 5 and above,
782
+
783
+ .. code-block:: c
784
+
785
+ struct {
786
+ char type;
787
+ }
788
+
789
+ immediately follows the file header block to represent the program type stored in the file.
790
+
791
+ - When ``type==c``, :class:`~.QuantumCircuit` payload follows
792
+ - When ``type==s``, :class:`~.ScheduleBlock` payload follows
793
+
794
+ .. note::
795
+
796
+ Different programs cannot be packed together in the same file.
797
+ You must create different files for different program types.
798
+ Multiple objects with the same type can be saved in a single file.
799
+
800
+ .. _qpy_schedule_block:
801
+
802
+ SCHEDULE_BLOCK
803
+ ~~~~~~~~~~~~~~
804
+
805
+ :class:`~.ScheduleBlock` is first supported in QPY Version 5. This allows
806
+ users to save pulse programs in the QPY binary format as follows:
807
+
808
+ .. code-block:: python
809
+
810
+ from qiskit import pulse, qpy
811
+
812
+ with pulse.build() as schedule:
813
+ pulse.play(pulse.Gaussian(160, 0.1, 40), pulse.DriveChannel(0))
814
+
815
+ with open('schedule.qpy', 'wb') as fd:
816
+ qpy.dump(qc, fd)
817
+
818
+ with open('schedule.qpy', 'rb') as fd:
819
+ new_qc = qpy.load(fd)[0]
820
+
821
+ Note that circuit and schedule block are serialized and deserialized through
822
+ the same QPY interface. Input data type is implicitly analyzed and
823
+ no extra option is required to save the schedule block.
824
+
825
+ .. _qpy_schedule_block_header:
826
+
827
+ SCHEDULE_BLOCK_HEADER
828
+ ~~~~~~~~~~~~~~~~~~~~~
829
+
830
+ :class:`~.ScheduleBlock` block starts with the following header:
831
+
832
+ .. code-block:: c
833
+
834
+ struct {
835
+ uint16_t name_size;
836
+ uint64_t metadata_size;
837
+ uint16_t num_element;
838
+ }
839
+
840
+ which is immediately followed by ``name_size`` utf8 bytes of schedule name and
841
+ ``metadata_size`` utf8 bytes of the JSON serialized metadata dictionary
842
+ attached to the schedule.
843
+
844
+ .. _qpy_schedule_alignments:
845
+
846
+ SCHEDULE_BLOCK_ALIGNMENTS
847
+ ~~~~~~~~~~~~~~~~~~~~~~~~~
848
+
849
+ Then, alignment context of the schedule block starts with ``char``
850
+ representing the supported context type followed by the :ref:`qpy_sequence` block representing
851
+ the parameters associated with the alignment context :attr:`AlignmentKind._context_params`.
852
+ The context type char is mapped to each alignment subclass as follows:
853
+
854
+ - ``l``: :class:`~.AlignLeft`
855
+ - ``r``: :class:`~.AlignRight`
856
+ - ``s``: :class:`~.AlignSequential`
857
+ - ``e``: :class:`~.AlignEquispaced`
858
+
859
+ Note that :class:`~.AlignFunc` context is not supported because of the callback function
860
+ stored in the context parameters.
861
+
862
+ .. _qpy_schedule_instructions:
863
+
864
+ SCHEDULE_BLOCK_INSTRUCTIONS
865
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
866
+
867
+ This alignment block is further followed by ``num_element`` length of block elements which may
868
+ consist of nested schedule blocks and schedule instructions.
869
+ Each schedule instruction starts with ``char`` representing the instruction type
870
+ followed by the :ref:`qpy_sequence` block representing the instruction
871
+ :attr:`~qiskit.pulse.instructions.Instruction.operands`.
872
+ Note that the data structure of pulse :class:`~qiskit.pulse.instructions.Instruction`
873
+ is unified so that instance can be uniquely determined by the class and a tuple of operands.
874
+ The mapping of type char to the instruction subclass is defined as follows:
875
+
876
+ - ``a``: :class:`~qiskit.pulse.instructions.Acquire` instruction
877
+ - ``p``: :class:`~qiskit.pulse.instructions.Play` instruction
878
+ - ``d``: :class:`~qiskit.pulse.instructions.Delay` instruction
879
+ - ``f``: :class:`~qiskit.pulse.instructions.SetFrequency` instruction
880
+ - ``g``: :class:`~qiskit.pulse.instructions.ShiftFrequency` instruction
881
+ - ``q``: :class:`~qiskit.pulse.instructions.SetPhase` instruction
882
+ - ``r``: :class:`~qiskit.pulse.instructions.ShiftPhase` instruction
883
+ - ``b``: :class:`~qiskit.pulse.instructions.RelativeBarrier` instruction
884
+ - ``t``: :class:`~qiskit.pulse.instructions.TimeBlockade` instruction
885
+ - ``y``: :class:`~qiskit.pulse.instructions.Reference` instruction (new in version 0.7)
886
+
887
+ .. _qpy_schedule_operands:
888
+
889
+ SCHEDULE_BLOCK_OPERANDS
890
+ ~~~~~~~~~~~~~~~~~~~~~~~
891
+
892
+ The operands of these instances can be serialized through the standard QPY value serialization
893
+ mechanism, however there are special object types that only appear in the schedule operands.
894
+ Since the operands are serialized as :ref:`qpy_sequence`, each element must be packed with the
895
+ INSTRUCTION_PARAM pack struct, where each payload starts with a header block consists of
896
+ the char ``type`` and uint64_t ``size``.
897
+ Special objects start with the following type key:
898
+
899
+ - ``c``: :class:`~qiskit.pulse.channels.Channel`
900
+ - ``w``: :class:`~qiskit.pulse.library.Waveform`
901
+ - ``s``: :class:`~qiskit.pulse.library.SymbolicPulse`
902
+ - ``o``: string (operand string, new in version 0.7)
903
+
904
+ .. _qpy_schedule_channel:
905
+
906
+ CHANNEL
907
+ ~~~~~~~
908
+
909
+ Channel block starts with channel subtype ``char`` that maps an object data to
910
+ :class:`~qiskit.pulse.channels.Channel` subclass. Mapping is defined as follows:
911
+
912
+ - ``d``: :class:`~qiskit.pulse.channels.DriveChannel`
913
+ - ``c``: :class:`~qiskit.pulse.channels.ControlChannel`
914
+ - ``m``: :class:`~qiskit.pulse.channels.MeasureChannel`
915
+ - ``a``: :class:`~qiskit.pulse.channels.AcquireChannel`
916
+ - ``e``: :class:`~qiskit.pulse.channels.MemorySlot`
917
+ - ``r``: :class:`~qiskit.pulse.channels.RegisterSlot`
918
+
919
+ The key is immediately followed by the channel index serialized as the INSTRUCTION_PARAM.
920
+
921
+ .. _qpy_schedule_waveform:
922
+
923
+ Waveform
924
+ ~~~~~~~~
925
+
926
+ Waveform block starts with WAVEFORM header:
927
+
928
+ .. code-block:: c
929
+
930
+ struct {
931
+ double epsilon;
932
+ uint32_t data_size;
933
+ _bool amp_limited;
934
+ }
935
+
936
+ which is followed by ``data_size`` bytes of complex ``ndarray`` binary generated by numpy.save_.
937
+ This represents the complex IQ data points played on a quantum device.
938
+ :attr:`~qiskit.pulse.library.Waveform.name` is saved after the samples in the
939
+ INSTRUCTION_PARAM pack struct, which can be string or ``None``.
940
+
941
+ .. _numpy.save: https://numpy.org/doc/stable/reference/generated/numpy.save.html
942
+
943
+ .. _qpy_schedule_symbolic_pulse:
944
+
945
+ SymbolicPulse
946
+ ~~~~~~~~~~~~~
947
+
948
+ SymbolicPulse block starts with SYMBOLIC_PULSE header:
949
+
950
+ .. code-block:: c
951
+
952
+ struct {
953
+ uint16_t type_size;
954
+ uint16_t envelope_size;
955
+ uint16_t constraints_size;
956
+ uint16_t valid_amp_conditions_size;
957
+ _bool amp_limited;
958
+ }
959
+
960
+ which is followed by ``type_size`` utf8 bytes of :attr:`.SymbolicPulse.pulse_type` string
961
+ that represents a class of waveform, such as "Gaussian" or "GaussianSquare".
962
+ Then, ``envelope_size``, ``constraints_size``, ``valid_amp_conditions_size`` utf8 bytes of
963
+ serialized symbolic expressions are generated for :attr:`.SymbolicPulse.envelope`,
964
+ :attr:`.SymbolicPulse.constraints`, and :attr:`.SymbolicPulse.valid_amp_conditions`, respectively.
965
+ Since string representation of these expressions are usually lengthy,
966
+ the expression binary is generated by the python zlib_ module with data compression.
967
+
968
+ To uniquely specify a pulse instance, we also need to store the associated parameters,
969
+ which consist of ``duration`` and the rest of parameters as a dictionary.
970
+ Dictionary parameters are first dumped in the :ref:`qpy_mapping` form, and then ``duration``
971
+ is dumped with the INSTRUCTION_PARAM pack struct.
972
+ Lastly, :attr:`~qiskit.pulse.library.SymbolicPulse.name` is saved also with the
973
+ INSTRUCTION_PARAM pack struct, which can be string or ``None``.
974
+
975
+ .. _zlib: https://docs.python.org/3/library/zlib.html
976
+
977
+ .. _qpy_mapping:
978
+
979
+ MAPPING
980
+ ~~~~~~~
981
+
982
+ The MAPPING is a representation for arbitrary mapping object. This is a fixed length
983
+ :ref:`qpy_sequence` of key-value pair represented by the MAP_ITEM payload.
984
+
985
+ A MAP_ITEM starts with a header defined as:
986
+
987
+ .. code-block:: c
988
+
989
+ struct {
990
+ uint16_t key_size;
991
+ char type;
992
+ uint16_t size;
993
+ }
994
+
995
+ which is immediately followed by the ``key_size`` utf8 bytes representing
996
+ the dictionary key in string and ``size`` utf8 bytes of arbitrary object data of
997
+ QPY serializable ``type``.
998
+
999
+ .. _qpy_circuit_calibrations:
1000
+
1001
+ CIRCUIT_CALIBRATIONS
1002
+ ~~~~~~~~~~~~~~~~~~~~
1003
+
1004
+ The CIRCUIT_CALIBRATIONS block is a dictionary to define pulse calibrations of the custom
1005
+ instruction set. This block starts with the following CALIBRATION header:
1006
+
1007
+ .. code-block:: c
1008
+
1009
+ struct {
1010
+ uint16_t num_cals;
1011
+ }
1012
+
1013
+ which is followed by the ``num_cals`` length of calibration entries, each starts with
1014
+ the CALIBRATION_DEF header:
1015
+
1016
+ .. code-block:: c
1017
+
1018
+ struct {
1019
+ uint16_t name_size;
1020
+ uint16_t num_qubits;
1021
+ uint16_t num_params;
1022
+ char type;
1023
+ }
1024
+
1025
+ The calibration definition header is then followed by ``name_size`` utf8 bytes of
1026
+ the gate name, ``num_qubits`` length of integers representing a sequence of qubits,
1027
+ and ``num_params`` length of INSTRUCTION_PARAM payload for parameters
1028
+ associated to the custom instruction.
1029
+ The ``type`` indicates the class of pulse program which is either, in principle,
1030
+ :class:`~.ScheduleBlock` or :class:`~.Schedule`. As of QPY Version 5,
1031
+ only :class:`~.ScheduleBlock` payload is supported.
1032
+ Finally, :ref:`qpy_schedule_block` payload is packed for each CALIBRATION_DEF entry.
1033
+
1034
+ .. _qpy_instruction_v5:
1035
+
1036
+ INSTRUCTION
1037
+ ~~~~~~~~~~~
1038
+
1039
+ The INSTRUCTION block was modified to add two new fields ``num_ctrl_qubits`` and ``ctrl_state``
1040
+ which are used to model the :attr:`.ControlledGate.num_ctrl_qubits` and
1041
+ :attr:`.ControlledGate.ctrl_state` attributes. The new payload packed struct
1042
+ format is:
1043
+
1044
+ .. code-block:: c
1045
+
1046
+ struct {
1047
+ uint16_t name_size;
1048
+ uint16_t label_size;
1049
+ uint16_t num_parameters;
1050
+ uint32_t num_qargs;
1051
+ uint32_t num_cargs;
1052
+ _Bool has_conditional;
1053
+ uint16_t conditional_reg_name_size;
1054
+ int64_t conditional_value;
1055
+ uint32_t num_ctrl_qubits;
1056
+ uint32_t ctrl_state;
1057
+ }
1058
+
1059
+ The rest of the instruction payload is the same. You can refer to
1060
+ :ref:`qpy_instructions` for the details of the full payload.
1061
+
1062
+ CUSTOM_INSTRUCTION
1063
+ ~~~~~~~~~~~~~~~~~~
1064
+
1065
+ The CUSTOM_INSTRUCTION block in QPY version 5 adds a new field
1066
+ ``base_gate_size`` which is used to define the size of the
1067
+ :class:`qiskit.circuit.Instruction` object stored in the
1068
+ :attr:`.ControlledGate.base_gate` attribute for a custom
1069
+ :class:`~.ControlledGate` object. With this change the CUSTOM_INSTRUCTION
1070
+ metadata block becomes:
1071
+
1072
+ .. code-block:: c
1073
+
1074
+ struct {
1075
+ uint16_t name_size;
1076
+ char type;
1077
+ uint32_t num_qubits;
1078
+ uint32_t num_clbits;
1079
+ _Bool custom_definition;
1080
+ uint64_t size;
1081
+ uint32_t num_ctrl_qubits;
1082
+ uint32_t ctrl_state;
1083
+ uint64_t base_gate_size
1084
+ }
1085
+
1086
+ Immediately following the CUSTOM_INSTRUCTION struct is the utf8 encoded name
1087
+ of size ``name_size``.
1088
+
1089
+ If ``custom_definition`` is ``True`` that means that the immediately following
1090
+ ``size`` bytes contains a QPY circuit data which can be used for the custom
1091
+ definition of that gate. If ``custom_definition`` is ``False`` then the
1092
+ instruction can be considered opaque (ie no definition). The ``type`` field
1093
+ determines what type of object will get created with the custom definition.
1094
+ If it's ``'g'`` it will be a :class:`~qiskit.circuit.Gate` object, ``'i'``
1095
+ it will be a :class:`~qiskit.circuit.Instruction` object.
1096
+
1097
+ Following this the next ``base_gate_size`` bytes contain the ``INSTRUCTION``
1098
+ payload for the :attr:`.ControlledGate.base_gate`.
1099
+
1100
+ Additionally an addition value for ``type`` is added ``'c'`` which is used to
1101
+ indicate the custom instruction is a custom :class:`~.ControlledGate`.
1102
+
1103
+ .. _qpy_version_4:
1104
+
1105
+ Version 4
1106
+ ---------
1107
+
1108
+ Version 4 is identical to :ref:`qpy_version_3` except that it adds 2 new type strings
1109
+ to the INSTRUCTION_PARAM struct, ``z`` to represent ``None`` (which is encoded as
1110
+ no data), ``q`` to represent a :class:`.QuantumCircuit` (which is encoded as
1111
+ a QPY circuit), ``r`` to represent a ``range`` of integers (which is encoded as
1112
+ a :ref:`qpy_range_pack`), and ``t`` to represent a ``sequence`` (which is encoded as
1113
+ defined by :ref:`qpy_sequence`). Additionally, version 4 changes the type of register
1114
+ index mapping array from ``uint32_t`` to ``int64_t``. If the values of any of the
1115
+ array elements are negative they represent a register bit that is not present in the
1116
+ circuit.
1117
+
1118
+ The :ref:`qpy_registers` header format has also been updated to
1119
+
1120
+ .. code-block:: c
1121
+
1122
+ struct {
1123
+ char type;
1124
+ _Bool standalone;
1125
+ uint32_t size;
1126
+ uint16_t name_size;
1127
+ _bool in_circuit;
1128
+ }
1129
+
1130
+ which just adds the ``in_circuit`` field which represents whether the register is
1131
+ part of the circuit or not.
1132
+
1133
+ .. _qpy_range_pack:
1134
+
1135
+ RANGE
1136
+ ~~~~~
1137
+
1138
+ A RANGE is a representation of a ``range`` object. It is defined as:
1139
+
1140
+ .. code-block:: c
1141
+
1142
+ struct {
1143
+ int64_t start;
1144
+ int64_t stop;
1145
+ int64_t step;
1146
+ }
1147
+
1148
+ .. _qpy_sequence:
1149
+
1150
+ SEQUENCE
1151
+ ~~~~~~~~
1152
+
1153
+ A SEQUENCE is a representation of an arbitrary sequence object. As sequence are just fixed length
1154
+ containers of arbitrary python objects their QPY can't fully represent any sequence,
1155
+ but as long as the contents in a sequence are other QPY serializable types for
1156
+ the INSTRUCTION_PARAM payload the ``sequence`` object can be serialized.
1157
+
1158
+ A sequence instruction parameter starts with a header defined as:
1159
+
1160
+ .. code-block:: c
1161
+
1162
+ struct {
1163
+ uint64_t size;
1164
+ }
1165
+
1166
+ followed by ``size`` elements that are INSTRUCTION_PARAM payloads, where each of
1167
+ these define an element in the sequence. The sequence object will be typecasted
1168
+ into proper type, e.g. ``tuple``, afterwards.
1169
+
1170
+ .. _qpy_version_3:
1171
+
1172
+ Version 3
1173
+ ---------
1174
+
1175
+ Version 3 of the QPY format is identical to :ref:`qpy_version_2` except that it defines
1176
+ a struct format to represent a :class:`~qiskit.circuit.library.PauliEvolutionGate`
1177
+ natively in QPY. To accomplish this the :ref:`qpy_custom_definition` struct now supports
1178
+ a new type value ``'p'`` to represent a :class:`~qiskit.circuit.library.PauliEvolutionGate`.
1179
+ Enties in the custom instructions tables have unique name generated that start with the
1180
+ string ``"###PauliEvolutionGate_"`` followed by a uuid string. This gate name is reservered
1181
+ in QPY and if you have a custom :class:`~qiskit.circuit.Instruction` object with a definition
1182
+ set and that name prefix it will error. If it's of type ``'p'`` the data payload is defined
1183
+ as follows:
1184
+
1185
+ .. _pauli_evo_qpy:
1186
+
1187
+ PAULI_EVOLUTION
1188
+ ~~~~~~~~~~~~~~~
1189
+
1190
+ This represents the high level :class:`~qiskit.circuit.library.PauliEvolutionGate`
1191
+
1192
+ .. code-block:: c
1193
+
1194
+ struct {
1195
+ uint64_t operator_count;
1196
+ _Bool standalone_op;
1197
+ char time_type;
1198
+ uint64_t time_size;
1199
+ uint64_t synthesis_size;
1200
+ }
1201
+
1202
+ This is immediately followed by ``operator_count`` elements defined by the :ref:`qpy_pauli_sum_op`
1203
+ payload. Following that we have ``time_size`` bytes representing the ``time`` attribute. If
1204
+ ``standalone_op`` is ``True`` then there must only be a single operator. The
1205
+ encoding of these bytes is determined by the value of ``time_type``. Possible values of
1206
+ ``time_type`` are ``'f'``, ``'p'``, and ``'e'``. If ``time_type`` is ``'f'`` it's a double,
1207
+ ``'p'`` defines a :class:`~qiskit.circuit.Parameter` object which is represented by a
1208
+ :ref:`qpy_param_struct`, ``e`` defines a :class:`~qiskit.circuit.ParameterExpression` object
1209
+ (that's not a :class:`~qiskit.circuit.Parameter`) which is represented by a :ref:`qpy_param_expr`.
1210
+ Following that is ``synthesis_size`` bytes which is a utf8 encoded json payload representing
1211
+ the :class:`.EvolutionSynthesis` class used by the gate.
1212
+
1213
+ .. _qpy_pauli_sum_op:
1214
+
1215
+ SPARSE_PAULI_OP_LIST_ELEM
1216
+ ~~~~~~~~~~~~~~~~~~~~~~~~~
1217
+
1218
+ This represents an instance of :class:`.SparsePauliOp`.
1219
+
1220
+
1221
+ .. code-block:: c
1222
+
1223
+ struct {
1224
+ uint32_t pauli_op_size;
1225
+ }
1226
+
1227
+ which is immediately followed by ``pauli_op_size`` bytes which are .npy format [#f2]_
1228
+ data which represents the :class:`~qiskit.quantum_info.SparsePauliOp`.
1229
+
1230
+ Version 3 of the QPY format also defines a struct format to represent a
1231
+ :class:`~qiskit.circuit.ParameterVectorElement` as a distinct subclass from
1232
+ a :class:`~qiskit.circuit.Parameter`. This adds a new parameter type char ``'v'``
1233
+ to represent a :class:`~qiskit.circuit.ParameterVectorElement` which is now
1234
+ supported as a type string value for an INSTRUCTION_PARAM. The payload for these
1235
+ parameters are defined below as :ref:`qpy_param_vector`.
1236
+
1237
+ .. _qpy_param_vector:
1238
+
1239
+ PARAMETER_VECTOR_ELEMENT
1240
+ ~~~~~~~~~~~~~~~~~~~~~~~~
1241
+
1242
+ A PARAMETER_VECTOR_ELEMENT represents a :class:`~qiskit.circuit.ParameterVectorElement`
1243
+ object the data for a INSTRUCTION_PARAM. The contents of the PARAMETER_VECTOR_ELEMENT are
1244
+ defined as:
1245
+
1246
+ .. code-block:: c
1247
+
1248
+ struct {
1249
+ uint16_t vector_name_size;
1250
+ uint64_t vector_size;
1251
+ char uuid[16];
1252
+ uint64_t index;
1253
+ }
1254
+
1255
+ which is immediately followed by ``vector_name_size`` utf8 bytes representing
1256
+ the parameter's vector name.
1257
+
1258
+ .. _qpy_param_expr_v3:
1259
+
1260
+
1261
+ PARAMETER_EXPR
1262
+ ~~~~~~~~~~~~~~
1263
+
1264
+ Additionally, since QPY format version v3 distinguishes between a
1265
+ :class:`~qiskit.circuit.Parameter` and :class:`~qiskit.circuit.ParameterVectorElement`
1266
+ the payload for a :class:`~qiskit.circuit.ParameterExpression` needs to be updated
1267
+ to distinguish between the types. The following is the modified payload format
1268
+ which is mostly identical to the format in Version 1 and :ref:`qpy_version_2` but just
1269
+ modifies the ``map_elements`` struct to include a symbol type field.
1270
+
1271
+ A PARAMETER_EXPR represents a :class:`~qiskit.circuit.ParameterExpression`
1272
+ object that the data for an INSTRUCTION_PARAM. The contents of a PARAMETER_EXPR
1273
+ are defined as:
1274
+
1275
+ .. code-block:: c
1276
+
1277
+ struct {
1278
+ uint64_t map_elements;
1279
+ uint64_t expr_size;
1280
+ }
1281
+
1282
+ Immediately following the header is ``expr_size`` bytes of utf8 data containing
1283
+ the expression string, which is the sympy srepr of the expression for the
1284
+ parameter expression. Following that is a symbol map which contains
1285
+ ``map_elements`` elements with the format
1286
+
1287
+ .. code-block:: c
1288
+
1289
+ struct {
1290
+ char symbol_type;
1291
+ char type;
1292
+ uint64_t size;
1293
+ }
1294
+
1295
+ The ``symbol_type`` key determines the payload type of the symbol representation
1296
+ for the element. If it's ``p`` it represents a :class:`~qiskit.circuit.Parameter`
1297
+ and if it's ``v`` it represents a :class:`~qiskit.circuit.ParameterVectorElement`.
1298
+ The map element struct is immediately followed by the symbol map key payload, if
1299
+ ``symbol_type`` is ``p`` then it is followed immediately by a :ref:`qpy_param_struct`
1300
+ object (both the struct and utf8 name bytes) and if ``symbol_type`` is ``v``
1301
+ then the struct is imediately followed by :ref:`qpy_param_vector` (both the struct
1302
+ and utf8 name bytes). That is followed by ``size`` bytes for the
1303
+ data of the symbol. The data format is dependent on the value of ``type``. If
1304
+ ``type`` is ``p`` then it represents a :class:`~qiskit.circuit.Parameter` and
1305
+ size will be 0, the value will just be the same as the key. Similarly if the
1306
+ ``type`` is ``v`` then it represents a :class:`~qiskit.circuit.ParameterVectorElement`
1307
+ and size will be 0 as the value will just be the same as the key. If
1308
+ ``type`` is ``f`` then it represents a double precision float. If ``type`` is
1309
+ ``c`` it represents a double precision complex, which is represented by the
1310
+ :ref:`qpy_complex`. Finally, if type is ``i`` it represents an integer which is an
1311
+ ``int64_t``.
1312
+
1313
+ .. _qpy_version_2:
1314
+
1315
+ Version 2
1316
+ ---------
1317
+
1318
+ Version 2 of the QPY format is identical to version 1 except for the HEADER
1319
+ section is slightly different. You can refer to the :ref:`qpy_version_1` section
1320
+ for the details on the rest of the payload format.
1321
+
1322
+ HEADER
1323
+ ~~~~~~
1324
+
1325
+ The contents of HEADER are defined as a C struct are:
1326
+
1327
+ .. code-block:: c
1328
+
1329
+ struct {
1330
+ uint16_t name_size;
1331
+ char global_phase_type;
1332
+ uint16_t global_phase_size;
1333
+ uint32_t num_qubits;
1334
+ uint32_t num_clbits;
1335
+ uint64_t metadata_size;
1336
+ uint32_t num_registers;
1337
+ uint64_t num_instructions;
1338
+ }
1339
+
1340
+ This is immediately followed by ``name_size`` bytes of utf8 data for the name
1341
+ of the circuit. Following this is immediately ``global_phase_size`` bytes
1342
+ representing the global phase. The content of that data is dictated by the
1343
+ value of ``global_phase_type``. If it's ``'f'`` the data is a float and is the
1344
+ size of a ``double``. If it's ``'p'`` defines a :class:`~qiskit.circuit.Parameter`
1345
+ object which is represented by a PARAM struct (see below), ``e`` defines a
1346
+ :class:`~qiskit.circuit.ParameterExpression` object (that's not a
1347
+ :class:`~qiskit.circuit.Parameter`) which is represented by a PARAM_EXPR struct
1348
+ (see below).
1349
+
1350
+ .. _qpy_version_1:
1351
+
1352
+ Version 1
1353
+ ---------
1354
+
1355
+ HEADER
1356
+ ~~~~~~
1357
+
1358
+ The contents of HEADER as defined as a C struct are:
1359
+
1360
+ .. code-block:: c
1361
+
1362
+ struct {
1363
+ uint16_t name_size;
1364
+ double global_phase;
1365
+ uint32_t num_qubits;
1366
+ uint32_t num_clbits;
1367
+ uint64_t metadata_size;
1368
+ uint32_t num_registers;
1369
+ uint64_t num_instructions;
1370
+ }
1371
+
1372
+ This is immediately followed by ``name_size`` bytes of utf8 data for the name
1373
+ of the circuit.
1374
+
1375
+ METADATA
1376
+ ~~~~~~~~
1377
+
1378
+ The METADATA field is a UTF8 encoded JSON string. After reading the HEADER
1379
+ (which is a fixed size at the start of the QPY file) and the ``name`` string
1380
+ you then read the ``metadata_size`` number of bytes and parse the JSON to get
1381
+ the metadata for the circuit.
1382
+
1383
+ .. _qpy_registers:
1384
+
1385
+ REGISTERS
1386
+ ~~~~~~~~~
1387
+
1388
+ The contents of REGISTERS is a number of REGISTER object. If num_registers is
1389
+ > 0 then after reading METADATA you read that number of REGISTER structs defined
1390
+ as:
1391
+
1392
+ .. code-block:: c
1393
+
1394
+ struct {
1395
+ char type;
1396
+ _Bool standalone;
1397
+ uint32_t size;
1398
+ uint16_t name_size;
1399
+ }
1400
+
1401
+ ``type`` can be ``'q'`` or ``'c'``.
1402
+
1403
+ Immediately following the REGISTER struct is the utf8 encoded register name of
1404
+ size ``name_size``. After the ``name`` utf8 bytes there is then an array of
1405
+ int64_t values of size ``size`` that contains a map of the register's index to
1406
+ the circuit's qubit index. For example, array element 0's value is the index
1407
+ of the ``register[0]``'s position in the containing circuit's qubits list.
1408
+
1409
+ .. note::
1410
+
1411
+ Prior to QPY :ref:`qpy_version_4` the type of array elements was uint32_t. This was changed
1412
+ to enable negative values which represent bits in the array not present in the
1413
+ circuit
1414
+
1415
+
1416
+ The standalone boolean determines whether the register is constructed as a
1417
+ standalone register that was added to the circuit or was created from existing
1418
+ bits. A register is considered standalone if it has bits constructed solely
1419
+ as part of it, for example::
1420
+
1421
+ qr = QuantumRegister(2)
1422
+ qc = QuantumCircuit(qr)
1423
+
1424
+ the register ``qr`` would be a standalone register. While something like::
1425
+
1426
+ bits = [Qubit(), Qubit()]
1427
+ qr2 = QuantumRegister(bits=bits)
1428
+ qc = QuantumCircuit(qr2)
1429
+
1430
+ ``qr2`` would have ``standalone`` set to ``False``.
1431
+
1432
+
1433
+ .. _qpy_custom_definition:
1434
+
1435
+ CUSTOM_DEFINITIONS
1436
+ ~~~~~~~~~~~~~~~~~~
1437
+
1438
+ This section specifies custom definitions for any of the instructions in the circuit.
1439
+
1440
+ CUSTOM_DEFINITION_HEADER contents are defined as:
1441
+
1442
+ .. code-block:: c
1443
+
1444
+ struct {
1445
+ uint64_t size;
1446
+ }
1447
+
1448
+ If size is greater than 0 that means the circuit contains custom instruction(s).
1449
+ Each custom instruction is defined with a CUSTOM_INSTRUCTION block defined as:
1450
+
1451
+ .. code-block:: c
1452
+
1453
+ struct {
1454
+ uint16_t name_size;
1455
+ char type;
1456
+ uint32_t num_qubits;
1457
+ uint32_t num_clbits;
1458
+ _Bool custom_definition;
1459
+ uint64_t size;
1460
+ }
1461
+
1462
+ Immediately following the CUSTOM_INSTRUCTION struct is the utf8 encoded name
1463
+ of size ``name_size``.
1464
+
1465
+ If ``custom_definition`` is ``True`` that means that the immediately following
1466
+ ``size`` bytes contains a QPY circuit data which can be used for the custom
1467
+ definition of that gate. If ``custom_definition`` is ``False`` then the
1468
+ instruction can be considered opaque (ie no definition). The ``type`` field
1469
+ determines what type of object will get created with the custom definition.
1470
+ If it's ``'g'`` it will be a :class:`~qiskit.circuit.Gate` object, ``'i'``
1471
+ it will be a :class:`~qiskit.circuit.Instruction` object.
1472
+
1473
+ .. _qpy_instructions:
1474
+
1475
+ INSTRUCTIONS
1476
+ ~~~~~~~~~~~~
1477
+
1478
+ The contents of INSTRUCTIONS is a list of INSTRUCTION metadata objects
1479
+
1480
+ .. code-block:: c
1481
+
1482
+ struct {
1483
+ uint16_t name_size;
1484
+ uint16_t label_size;
1485
+ uint16_t num_parameters;
1486
+ uint32_t num_qargs;
1487
+ uint32_t num_cargs;
1488
+ _Bool has_conditional;
1489
+ uint16_t conditional_reg_name_size;
1490
+ int64_t conditional_value;
1491
+ }
1492
+
1493
+ This metadata object is immediately followed by ``name_size`` bytes of utf8 bytes
1494
+ for the ``name``. ``name`` here is the Qiskit class name for the Instruction
1495
+ class if it's defined in Qiskit. Otherwise it falls back to the custom
1496
+ instruction name. Following the ``name`` bytes there are ``label_size`` bytes of
1497
+ utf8 data for the label if one was set on the instruction. Following the label
1498
+ bytes if ``has_conditional`` is ``True`` then there are
1499
+ ``conditional_reg_name_size`` bytes of utf8 data for the name of the conditional
1500
+ register name. In case of single classical bit conditions the register name
1501
+ utf8 data will be prefixed with a null character "\\x00" and then a utf8 string
1502
+ integer representing the classical bit index in the circuit that the condition
1503
+ is on.
1504
+
1505
+ This is immediately followed by the INSTRUCTION_ARG structs for the list of
1506
+ arguments of that instruction. These are in the order of all quantum arguments
1507
+ (there are num_qargs of these) followed by all classical arguments (num_cargs
1508
+ of these).
1509
+
1510
+ The contents of each INSTRUCTION_ARG is:
1511
+
1512
+ .. code-block:: c
1513
+
1514
+ struct {
1515
+ char type;
1516
+ uint32_t index;
1517
+ }
1518
+
1519
+ ``type`` can be ``'q'`` or ``'c'``.
1520
+
1521
+ After all arguments for an instruction the parameters are specified with
1522
+ ``num_parameters`` INSTRUCTION_PARAM structs.
1523
+
1524
+ The contents of each INSTRUCTION_PARAM is:
1525
+
1526
+ .. code-block:: c
1527
+
1528
+ struct {
1529
+ char type;
1530
+ uint64_t size;
1531
+ }
1532
+
1533
+ After each INSTRUCTION_PARAM the next ``size`` bytes are the parameter's data.
1534
+ The ``type`` field can be ``'i'``, ``'f'``, ``'p'``, ``'e'``, ``'s'``, ``'c'``
1535
+ or ``'n'`` which dictate the format. For ``'i'`` it's an integer, ``'f'`` it's
1536
+ a double, ``'s'`` if it's a string (encoded as utf8), ``'c'`` is a complex and
1537
+ the data is represented by the struct format in the :ref:`qpy_param_expr` section.
1538
+ ``'p'`` defines a :class:`~qiskit.circuit.Parameter` object which is
1539
+ represented by a :ref:`qpy_param_struct` struct, ``e`` defines a
1540
+ :class:`~qiskit.circuit.ParameterExpression` object (that's not a
1541
+ :class:`~qiskit.circuit.Parameter`) which is represented by a :ref:`qpy_param_expr`
1542
+ struct (on QPY format :ref:`qpy_version_3` the format is tweak slightly see:
1543
+ :ref:`qpy_param_expr_v3`), ``'n'`` represents an object from numpy (either an
1544
+ ``ndarray`` or a numpy type) which means the data is .npy format [#f2]_ data,
1545
+ and in QPY :ref:`qpy_version_3` ``'v'`` represents a
1546
+ :class:`~qiskit.circuit.ParameterVectorElement` which is represented by a
1547
+ :ref:`qpy_param_vector` struct.
1548
+
1549
+ .. _qpy_param_struct:
1550
+
1551
+ PARAMETER
1552
+ ~~~~~~~~~
1553
+
1554
+ A PARAMETER represents a :class:`~qiskit.circuit.Parameter` object the data for
1555
+ a INSTRUCTION_PARAM. The contents of the PARAMETER are defined as:
1556
+
1557
+ .. code-block:: c
1558
+
1559
+ struct {
1560
+ uint16_t name_size;
1561
+ char uuid[16];
1562
+ }
1563
+
1564
+ which is immediately followed by ``name_size`` utf8 bytes representing the
1565
+ parameter name.
1566
+
1567
+ .. _qpy_param_expr:
1568
+
1569
+ PARAMETER_EXPR
1570
+ ~~~~~~~~~~~~~~
1571
+
1572
+ A PARAMETER_EXPR represents a :class:`~qiskit.circuit.ParameterExpression`
1573
+ object that the data for an INSTRUCTION_PARAM. The contents of a PARAMETER_EXPR
1574
+ are defined as:
1575
+
1576
+ The PARAMETER_EXPR data starts with a header:
1577
+
1578
+ .. code-block:: c
1579
+
1580
+ struct {
1581
+ uint64_t map_elements;
1582
+ uint64_t expr_size;
1583
+ }
1584
+
1585
+ Immediately following the header is ``expr_size`` bytes of utf8 data containing
1586
+ the expression string, which is the sympy srepr of the expression for the
1587
+ parameter expression. Follwing that is a symbol map which contains
1588
+ ``map_elements`` elements with the format
1589
+
1590
+ .. code-block:: c
1591
+
1592
+ struct {
1593
+ char type;
1594
+ uint64_t size;
1595
+ }
1596
+
1597
+ Which is followed immediately by ``PARAMETER`` object (both the struct and utf8
1598
+ name bytes) for the symbol map key. That is followed by ``size`` bytes for the
1599
+ data of the symbol. The data format is dependent on the value of ``type``. If
1600
+ ``type`` is ``p`` then it represents a :class:`~qiskit.circuit.Parameter` and
1601
+ size will be 0, the value will just be the same as the key. If
1602
+ ``type`` is ``f`` then it represents a double precision float. If ``type`` is
1603
+ ``c`` it represents a double precision complex, which is represented by :ref:`qpy_complex`.
1604
+ Finally, if type is ``i`` it represents an integer which is an ``int64_t``.
1605
+
1606
+ .. _qpy_complex:
1607
+
1608
+ COMPLEX
1609
+ ~~~~~~~
1610
+
1611
+ When representing a double precision complex value in QPY the following
1612
+ struct is used:
1613
+
1614
+
1615
+ .. code-block:: c
1616
+
1617
+ struct {
1618
+ double real;
1619
+ double imag;
1620
+ }
1621
+
1622
+ this matches the internal C representation of Python's complex type. [#f3]_
1623
+
1624
+
1625
+ .. [#f1] https://tools.ietf.org/html/rfc1700
1626
+ .. [#f2] https://numpy.org/doc/stable/reference/generated/numpy.lib.format.html
1627
+ .. [#f3] https://docs.python.org/3/c-api/complex.html#c.Py_complex
1628
+ """
1629
+
1630
+ from .exceptions import QpyError, UnsupportedFeatureForVersion, QPYLoadingDeprecatedFeatureWarning
1631
+ from .interface import dump, load
1632
+
1633
+ # For backward compatibility. Provide, Runtime, Experiment call these private functions.
1634
+ from .binary_io import (
1635
+ _write_instruction,
1636
+ _read_instruction,
1637
+ _write_parameter_expression,
1638
+ _read_parameter_expression,
1639
+ _read_parameter_expression_v3,
1640
+ )
1641
+ from .common import QPY_VERSION, QPY_COMPATIBILITY_VERSION