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
@@ -0,0 +1,2213 @@
1
+ # This code is part of Qiskit.
2
+ #
3
+ # (C) Copyright IBM 2020.
4
+ #
5
+ # This code is licensed under the Apache License, Version 2.0. You may
6
+ # obtain a copy of this license in the LICENSE.txt file in the root directory
7
+ # of this source tree or at http://www.apache.org/licenses/LICENSE-2.0.
8
+ #
9
+ # Any modifications or derivative works of this code must retain this
10
+ # copyright notice, and modified files need to carry a notice indicating
11
+ # that they have been altered from the originals.
12
+
13
+ r"""
14
+
15
+ .. _pulse_builder:
16
+
17
+ =============
18
+ Pulse Builder
19
+ =============
20
+
21
+ ..
22
+ We actually want people to think of these functions as being defined within the ``qiskit.pulse``
23
+ namespace, not the submodule ``qiskit.pulse.builder``.
24
+
25
+ .. currentmodule: qiskit.pulse
26
+
27
+ Use the pulse builder DSL to write pulse programs with an imperative syntax.
28
+
29
+ .. warning::
30
+ The pulse builder interface is still in active development. It may have
31
+ breaking API changes without deprecation warnings in future releases until
32
+ otherwise indicated.
33
+
34
+
35
+ The pulse builder provides an imperative API for writing pulse programs
36
+ with less difficulty than the :class:`~qiskit.pulse.Schedule` API.
37
+ It contextually constructs a pulse schedule and then emits the schedule for
38
+ execution. For example, to play a series of pulses on channels is as simple as:
39
+
40
+
41
+ .. plot::
42
+ :include-source:
43
+
44
+ from qiskit import pulse
45
+
46
+ dc = pulse.DriveChannel
47
+ d0, d1, d2, d3, d4 = dc(0), dc(1), dc(2), dc(3), dc(4)
48
+
49
+ with pulse.build(name='pulse_programming_in') as pulse_prog:
50
+ pulse.play([1, 1, 1, 0, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 0, 1, 0, 1, 1, 1, 0, 1, 1, 1], d0)
51
+ pulse.play([1, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0], d1)
52
+ pulse.play([1, 0, 1, 0, 0, 0, 1, 0, 0, 1, 1, 1, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0], d2)
53
+ pulse.play([1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0], d3)
54
+ pulse.play([1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 0, 1, 0, 1, 1, 1, 0, 0, 1, 0], d4)
55
+
56
+ pulse_prog.draw()
57
+
58
+ To begin pulse programming we must first initialize our program builder
59
+ context with :func:`build`, after which we can begin adding program
60
+ statements. For example, below we write a simple program that :func:`play`\s
61
+ a pulse:
62
+
63
+ .. plot::
64
+ :include-source:
65
+
66
+ from qiskit import pulse
67
+
68
+ d0 = pulse.DriveChannel(0)
69
+
70
+ with pulse.build() as pulse_prog:
71
+ pulse.play(pulse.Constant(100, 1.0), d0)
72
+
73
+ pulse_prog.draw()
74
+
75
+ The builder initializes a :class:`.pulse.Schedule`, ``pulse_prog``
76
+ and then begins to construct the program within the context. The output pulse
77
+ schedule will survive after the context is exited and can be used like a
78
+ normal Qiskit schedule.
79
+
80
+ Pulse programming has a simple imperative style. This leaves the programmer
81
+ to worry about the raw experimental physics of pulse programming and not
82
+ constructing cumbersome data structures.
83
+
84
+ We can optionally pass a :class:`~qiskit.providers.Backend` to
85
+ :func:`build` to enable enhanced functionality. Below, we prepare a Bell state
86
+ by automatically compiling the required pulses from their gate-level
87
+ representations, while simultaneously applying a long decoupling pulse to a
88
+ neighboring qubit. We terminate the experiment with a measurement to observe the
89
+ state we prepared. This program which mixes circuits and pulses will be
90
+ automatically lowered to be run as a pulse program:
91
+
92
+ .. plot::
93
+ :include-source:
94
+
95
+ from math import pi
96
+ from qiskit.compiler import schedule
97
+ from qiskit.circuit import QuantumCircuit
98
+
99
+ from qiskit import pulse
100
+ from qiskit.providers.fake_provider import GenericBackendV2
101
+
102
+ backend = GenericBackendV2(num_qubits=5, calibrate_instructions=True)
103
+
104
+ d2 = pulse.DriveChannel(2)
105
+
106
+ qc = QuantumCircuit(2)
107
+ # Hadamard
108
+ qc.rz(pi/2, 0)
109
+ qc.sx(0)
110
+ qc.rz(pi/2, 0)
111
+
112
+ qc.cx(0, 1)
113
+
114
+ bell_sched = schedule(qc, backend)
115
+
116
+ with pulse.build(backend) as decoupled_bell_prep_and_measure:
117
+ # We call our bell state preparation schedule constructed above.
118
+ with pulse.align_right():
119
+ pulse.call(bell_sched)
120
+ pulse.play(pulse.Constant(bell_sched.duration, 0.02), d2)
121
+ pulse.barrier(0, 1, 2)
122
+ registers = pulse.measure_all()
123
+
124
+ decoupled_bell_prep_and_measure.draw()
125
+
126
+
127
+ With the pulse builder we are able to blend programming on qubits and channels.
128
+ While the pulse schedule is based on instructions that operate on
129
+ channels, the pulse builder automatically handles the mapping from qubits to
130
+ channels for you.
131
+
132
+ In the example below we demonstrate some more features of the pulse builder:
133
+
134
+ .. code-block::
135
+
136
+ import math
137
+ from qiskit.compiler import schedule
138
+
139
+ from qiskit import pulse, QuantumCircuit
140
+ from qiskit.pulse import library
141
+ from qiskit.providers.fake_provider import FakeOpenPulse2Q
142
+
143
+ backend = FakeOpenPulse2Q()
144
+
145
+ qc = QuantumCircuit(2, 2)
146
+ qc.cx(0, 1)
147
+
148
+ with pulse.build(backend) as pulse_prog:
149
+ # Create a pulse.
150
+ gaussian_pulse = library.gaussian(10, 1.0, 2)
151
+ # Get the qubit's corresponding drive channel from the backend.
152
+ d0 = pulse.drive_channel(0)
153
+ d1 = pulse.drive_channel(1)
154
+ # Play a pulse at t=0.
155
+ pulse.play(gaussian_pulse, d0)
156
+ # Play another pulse directly after the previous pulse at t=10.
157
+ pulse.play(gaussian_pulse, d0)
158
+ # The default scheduling behavior is to schedule pulses in parallel
159
+ # across channels. For example, the statement below
160
+ # plays the same pulse on a different channel at t=0.
161
+ pulse.play(gaussian_pulse, d1)
162
+
163
+ # We also provide pulse scheduling alignment contexts.
164
+ # The default alignment context is align_left.
165
+
166
+ # The sequential context schedules pulse instructions sequentially in time.
167
+ # This context starts at t=10 due to earlier pulses above.
168
+ with pulse.align_sequential():
169
+ pulse.play(gaussian_pulse, d0)
170
+ # Play another pulse after at t=20.
171
+ pulse.play(gaussian_pulse, d1)
172
+
173
+ # We can also nest contexts as each instruction is
174
+ # contained in its local scheduling context.
175
+ # The output of a child context is a context-schedule
176
+ # with the internal instructions timing fixed relative to
177
+ # one another. This is schedule is then called in the parent context.
178
+
179
+ # Context starts at t=30.
180
+ with pulse.align_left():
181
+ # Start at t=30.
182
+ pulse.play(gaussian_pulse, d0)
183
+ # Start at t=30.
184
+ pulse.play(gaussian_pulse, d1)
185
+ # Context ends at t=40.
186
+
187
+ # Alignment context where all pulse instructions are
188
+ # aligned to the right, ie., as late as possible.
189
+ with pulse.align_right():
190
+ # Shift the phase of a pulse channel.
191
+ pulse.shift_phase(math.pi, d1)
192
+ # Starts at t=40.
193
+ pulse.delay(100, d0)
194
+ # Ends at t=140.
195
+
196
+ # Starts at t=130.
197
+ pulse.play(gaussian_pulse, d1)
198
+ # Ends at t=140.
199
+
200
+ # Acquire data for a qubit and store in a memory slot.
201
+ pulse.acquire(100, 0, pulse.MemorySlot(0))
202
+
203
+ # We also support a variety of macros for common operations.
204
+
205
+ # Measure all qubits.
206
+ pulse.measure_all()
207
+
208
+ # Delay on some qubits.
209
+ # This requires knowledge of which channels belong to which qubits.
210
+ # delay for 100 cycles on qubits 0 and 1.
211
+ pulse.delay_qubits(100, 0, 1)
212
+
213
+ # Call a schedule for a quantum circuit thereby inserting into
214
+ # the pulse schedule.
215
+ qc = QuantumCircuit(2, 2)
216
+ qc.cx(0, 1)
217
+ qc_sched = schedule(qc, backend)
218
+ pulse.call(qc_sched)
219
+
220
+
221
+ # It is also be possible to call a preexisting schedule
222
+ tmp_sched = pulse.Schedule()
223
+ tmp_sched += pulse.Play(gaussian_pulse, d0)
224
+ pulse.call(tmp_sched)
225
+
226
+ # We also support:
227
+
228
+ # frequency instructions
229
+ pulse.set_frequency(5.0e9, d0)
230
+
231
+ # phase instructions
232
+ pulse.shift_phase(0.1, d0)
233
+
234
+ # offset contexts
235
+ with pulse.phase_offset(math.pi, d0):
236
+ pulse.play(gaussian_pulse, d0)
237
+
238
+
239
+ The above is just a small taste of what is possible with the builder. See the rest of the module
240
+ documentation for more information on its capabilities.
241
+
242
+ .. autofunction:: build
243
+
244
+
245
+ Channels
246
+ ========
247
+
248
+ Methods to return the correct channels for the respective qubit indices.
249
+
250
+ .. code-block::
251
+
252
+ from qiskit import pulse
253
+ from qiskit.providers.fake_provider import GenericBackendV2
254
+
255
+ backend = GenericBackendV2(num_qubits=2, calibrate_instructions=True)
256
+
257
+ with pulse.build(backend) as drive_sched:
258
+ d0 = pulse.drive_channel(0)
259
+ print(d0)
260
+
261
+ .. parsed-literal::
262
+
263
+ DriveChannel(0)
264
+
265
+ .. autofunction:: acquire_channel
266
+ .. autofunction:: control_channels
267
+ .. autofunction:: drive_channel
268
+ .. autofunction:: measure_channel
269
+
270
+
271
+ Instructions
272
+ ============
273
+
274
+ Pulse instructions are available within the builder interface. Here's an example:
275
+
276
+ .. plot::
277
+ :include-source:
278
+
279
+ from qiskit import pulse
280
+ from qiskit.providers.fake_provider import GenericBackendV2
281
+
282
+ backend = GenericBackendV2(num_qubits=2, calibrate_instructions=True)
283
+
284
+ with pulse.build(backend) as drive_sched:
285
+ d0 = pulse.drive_channel(0)
286
+ a0 = pulse.acquire_channel(0)
287
+
288
+ pulse.play(pulse.library.Constant(10, 1.0), d0)
289
+ pulse.delay(20, d0)
290
+ pulse.shift_phase(3.14/2, d0)
291
+ pulse.set_phase(3.14, d0)
292
+ pulse.shift_frequency(1e7, d0)
293
+ pulse.set_frequency(5e9, d0)
294
+
295
+ with pulse.build() as temp_sched:
296
+ pulse.play(pulse.library.Gaussian(20, 1.0, 3.0), d0)
297
+ pulse.play(pulse.library.Gaussian(20, -1.0, 3.0), d0)
298
+
299
+ pulse.call(temp_sched)
300
+ pulse.acquire(30, a0, pulse.MemorySlot(0))
301
+
302
+ drive_sched.draw()
303
+
304
+ .. autofunction:: acquire
305
+ .. autofunction:: barrier
306
+ .. autofunction:: call
307
+ .. autofunction:: delay
308
+ .. autofunction:: play
309
+ .. autofunction:: reference
310
+ .. autofunction:: set_frequency
311
+ .. autofunction:: set_phase
312
+ .. autofunction:: shift_frequency
313
+ .. autofunction:: shift_phase
314
+ .. autofunction:: snapshot
315
+
316
+
317
+ Contexts
318
+ ========
319
+
320
+ Builder aware contexts that modify the construction of a pulse program. For
321
+ example an alignment context like :func:`align_right` may
322
+ be used to align all pulses as late as possible in a pulse program.
323
+
324
+ .. plot::
325
+ :include-source:
326
+
327
+ from qiskit import pulse
328
+
329
+ d0 = pulse.DriveChannel(0)
330
+ d1 = pulse.DriveChannel(1)
331
+
332
+ with pulse.build() as pulse_prog:
333
+ with pulse.align_right():
334
+ # this pulse will start at t=0
335
+ pulse.play(pulse.Constant(100, 1.0), d0)
336
+ # this pulse will start at t=80
337
+ pulse.play(pulse.Constant(20, 1.0), d1)
338
+
339
+ pulse_prog.draw()
340
+
341
+ .. autofunction:: align_equispaced
342
+ .. autofunction:: align_func
343
+ .. autofunction:: align_left
344
+ .. autofunction:: align_right
345
+ .. autofunction:: align_sequential
346
+ .. autofunction:: frequency_offset
347
+ .. autofunction:: phase_offset
348
+
349
+
350
+ Macros
351
+ ======
352
+
353
+ Macros help you add more complex functionality to your pulse program.
354
+
355
+ .. code-block::
356
+
357
+ from qiskit import pulse
358
+ from qiskit.providers.fake_provider import GenericBackendV2
359
+
360
+ backend = GenericBackendV2(num_qubits=2, calibrate_instructions=True)
361
+
362
+ with pulse.build(backend) as measure_sched:
363
+ mem_slot = pulse.measure(0)
364
+ print(mem_slot)
365
+
366
+ .. parsed-literal::
367
+
368
+ MemorySlot(0)
369
+
370
+ .. autofunction:: measure
371
+ .. autofunction:: measure_all
372
+ .. autofunction:: delay_qubits
373
+
374
+
375
+ Utilities
376
+ =========
377
+
378
+ The utility functions can be used to gather attributes about the backend and modify
379
+ how the program is built.
380
+
381
+ .. code-block::
382
+
383
+ from qiskit import pulse
384
+
385
+ from qiskit.providers.fake_provider import GenericBackendV2
386
+
387
+ backend = GenericBackendV2(num_qubits=2, calibrate_instructions=True)
388
+
389
+ with pulse.build(backend) as u3_sched:
390
+ print('Number of qubits in backend: {}'.format(pulse.num_qubits()))
391
+
392
+ samples = 160
393
+ print('There are {} samples in {} seconds'.format(
394
+ samples, pulse.samples_to_seconds(160)))
395
+
396
+ seconds = 1e-6
397
+ print('There are {} seconds in {} samples.'.format(
398
+ seconds, pulse.seconds_to_samples(1e-6)))
399
+
400
+ .. parsed-literal::
401
+
402
+ Number of qubits in backend: 1
403
+ There are 160 samples in 3.5555555555555554e-08 seconds
404
+ There are 1e-06 seconds in 4500 samples.
405
+
406
+ .. autofunction:: active_backend
407
+ .. autofunction:: num_qubits
408
+ .. autofunction:: qubit_channels
409
+ .. autofunction:: samples_to_seconds
410
+ .. autofunction:: seconds_to_samples
411
+ """
412
+ from __future__ import annotations
413
+ import contextvars
414
+ import functools
415
+ import itertools
416
+ import sys
417
+ import uuid
418
+ import warnings
419
+ from collections.abc import Generator, Callable, Iterable
420
+ from contextlib import contextmanager
421
+ from functools import singledispatchmethod
422
+ from typing import TypeVar, ContextManager, TypedDict, Union, Optional, Dict
423
+
424
+ import numpy as np
425
+
426
+ from qiskit.circuit.parameterexpression import ParameterExpression, ParameterValueType
427
+ from qiskit.pulse import (
428
+ channels as chans,
429
+ configuration,
430
+ exceptions,
431
+ instructions,
432
+ macros,
433
+ library,
434
+ transforms,
435
+ )
436
+ from qiskit.providers.backend import BackendV2
437
+ from qiskit.pulse.instructions import directives
438
+ from qiskit.pulse.schedule import Schedule, ScheduleBlock
439
+ from qiskit.pulse.transforms.alignments import AlignmentKind
440
+
441
+
442
+ if sys.version_info >= (3, 12):
443
+ from typing import Unpack
444
+ else:
445
+ from typing_extensions import Unpack
446
+
447
+ #: contextvars.ContextVar[BuilderContext]: active builder
448
+ BUILDER_CONTEXTVAR: contextvars.ContextVar["_PulseBuilder"] = contextvars.ContextVar("backend")
449
+
450
+ T = TypeVar("T")
451
+
452
+ StorageLocation = Union[chans.MemorySlot, chans.RegisterSlot]
453
+
454
+
455
+ def _requires_backend(function: Callable[..., T]) -> Callable[..., T]:
456
+ """Decorator a function to raise if it is called without a builder with a
457
+ set backend.
458
+ """
459
+
460
+ @functools.wraps(function)
461
+ def wrapper(self, *args, **kwargs):
462
+ if self.backend is None:
463
+ raise exceptions.BackendNotSet(
464
+ 'This function requires the builder to have a "backend" set.'
465
+ )
466
+ return function(self, *args, **kwargs)
467
+
468
+ return wrapper
469
+
470
+
471
+ class _PulseBuilder:
472
+ """Builder context class."""
473
+
474
+ __alignment_kinds__ = {
475
+ "left": transforms.AlignLeft(),
476
+ "right": transforms.AlignRight(),
477
+ "sequential": transforms.AlignSequential(),
478
+ }
479
+
480
+ def __init__(
481
+ self,
482
+ backend=None,
483
+ block: ScheduleBlock | None = None,
484
+ name: str | None = None,
485
+ default_alignment: str | AlignmentKind = "left",
486
+ ):
487
+ """Initialize the builder context.
488
+
489
+ .. note::
490
+ At some point we may consider incorporating the builder into
491
+ the :class:`~qiskit.pulse.Schedule` class. However, the risk of
492
+ this is tying the user interface to the intermediate
493
+ representation. For now we avoid this at the cost of some code
494
+ duplication.
495
+
496
+ Args:
497
+ backend (Backend): Input backend to use in
498
+ builder. If not set certain functionality will be unavailable.
499
+ block: Initital ``ScheduleBlock`` to build on.
500
+ name: Name of pulse program to be built.
501
+ default_alignment: Default scheduling alignment for builder.
502
+ One of ``left``, ``right``, ``sequential`` or an instance of
503
+ :class:`~qiskit.pulse.transforms.alignments.AlignmentKind` subclass.
504
+
505
+ Raises:
506
+ PulseError: When invalid ``default_alignment`` or `block` is specified.
507
+ """
508
+ #: Backend: Backend instance for context builder.
509
+ self._backend = backend
510
+
511
+ # Token for this ``_PulseBuilder``'s ``ContextVar``.
512
+ self._backend_ctx_token: contextvars.Token[_PulseBuilder] | None = None
513
+
514
+ # Stack of context.
515
+ self._context_stack: list[ScheduleBlock] = []
516
+
517
+ #: str: Name of the output program
518
+ self._name = name
519
+
520
+ # Add root block if provided. Schedule will be built on top of this.
521
+ if block is not None:
522
+ if isinstance(block, ScheduleBlock):
523
+ root_block = block
524
+ elif isinstance(block, Schedule):
525
+ root_block = self._naive_typecast_schedule(block)
526
+ else:
527
+ raise exceptions.PulseError(
528
+ f"Input `block` type {block.__class__.__name__} is "
529
+ "not a valid format. Specify a pulse program."
530
+ )
531
+ self._context_stack.append(root_block)
532
+
533
+ # Set default alignment context
534
+ if isinstance(default_alignment, AlignmentKind): # AlignmentKind instance
535
+ alignment = default_alignment
536
+ else: # str identifier
537
+ alignment = _PulseBuilder.__alignment_kinds__.get(default_alignment, default_alignment)
538
+ if not isinstance(alignment, AlignmentKind):
539
+ raise exceptions.PulseError(
540
+ f"Given `default_alignment` {repr(default_alignment)} is "
541
+ "not a valid transformation. Set one of "
542
+ f'{", ".join(_PulseBuilder.__alignment_kinds__.keys())}, '
543
+ "or set an instance of `AlignmentKind` subclass."
544
+ )
545
+ self.push_context(alignment)
546
+
547
+ def __enter__(self) -> ScheduleBlock:
548
+ """Enter this builder context and yield either the supplied schedule
549
+ or the schedule created for the user.
550
+
551
+ Returns:
552
+ The schedule that the builder will build on.
553
+ """
554
+ self._backend_ctx_token = BUILDER_CONTEXTVAR.set(self)
555
+ output = self._context_stack[0]
556
+ output._name = self._name or output.name
557
+
558
+ return output
559
+
560
+ def __exit__(self, exc_type, exc_val, exc_tb):
561
+ """Exit the builder context and compile the built pulse program."""
562
+ self.compile()
563
+ BUILDER_CONTEXTVAR.reset(self._backend_ctx_token)
564
+
565
+ @property
566
+ def backend(self):
567
+ """Returns the builder backend if set.
568
+
569
+ Returns:
570
+ Optional[Backend]: The builder's backend.
571
+ """
572
+ return self._backend
573
+
574
+ def push_context(self, alignment: AlignmentKind):
575
+ """Push new context to the stack."""
576
+ self._context_stack.append(ScheduleBlock(alignment_context=alignment))
577
+
578
+ def pop_context(self) -> ScheduleBlock:
579
+ """Pop the last context from the stack."""
580
+ if len(self._context_stack) == 1:
581
+ raise exceptions.PulseError("The root context cannot be popped out.")
582
+
583
+ return self._context_stack.pop()
584
+
585
+ def get_context(self) -> ScheduleBlock:
586
+ """Get current context.
587
+
588
+ Notes:
589
+ New instruction can be added by `.append_subroutine` or `.append_instruction` method.
590
+ Use above methods rather than directly accessing to the current context.
591
+ """
592
+ return self._context_stack[-1]
593
+
594
+ @property
595
+ @_requires_backend
596
+ def num_qubits(self):
597
+ """Get the number of qubits in the backend."""
598
+ # backendV2
599
+ if isinstance(self.backend, BackendV2):
600
+ return self.backend.num_qubits
601
+ return self.backend.configuration().n_qubits
602
+
603
+ def compile(self) -> ScheduleBlock:
604
+ """Compile and output the built pulse program."""
605
+ # Not much happens because we currently compile as we build.
606
+ # This should be offloaded to a true compilation module
607
+ # once we define a more sophisticated IR.
608
+
609
+ while len(self._context_stack) > 1:
610
+ current = self.pop_context()
611
+ self.append_subroutine(current)
612
+
613
+ return self._context_stack[0]
614
+
615
+ def append_instruction(self, instruction: instructions.Instruction):
616
+ """Add an instruction to the builder's context schedule.
617
+
618
+ Args:
619
+ instruction: Instruction to append.
620
+ """
621
+ self._context_stack[-1].append(instruction)
622
+
623
+ def append_reference(self, name: str, *extra_keys: str):
624
+ """Add external program as a :class:`~qiskit.pulse.instructions.Reference` instruction.
625
+
626
+ Args:
627
+ name: Name of subroutine.
628
+ extra_keys: Assistance keys to uniquely specify the subroutine.
629
+ """
630
+ inst = instructions.Reference(name, *extra_keys)
631
+ self.append_instruction(inst)
632
+
633
+ def append_subroutine(self, subroutine: Schedule | ScheduleBlock):
634
+ """Append a :class:`ScheduleBlock` to the builder's context schedule.
635
+
636
+ This operation doesn't create a reference. Subroutine is directly
637
+ appended to current context schedule.
638
+
639
+ Args:
640
+ subroutine: ScheduleBlock to append to the current context block.
641
+
642
+ Raises:
643
+ PulseError: When subroutine is not Schedule nor ScheduleBlock.
644
+ """
645
+ if not isinstance(subroutine, (ScheduleBlock, Schedule)):
646
+ raise exceptions.PulseError(
647
+ f"'{subroutine.__class__.__name__}' is not valid data format in the builder. "
648
+ "'Schedule' and 'ScheduleBlock' can be appended to the builder context."
649
+ )
650
+
651
+ if len(subroutine) == 0:
652
+ return
653
+ if isinstance(subroutine, Schedule):
654
+ subroutine = self._naive_typecast_schedule(subroutine)
655
+ self._context_stack[-1].append(subroutine)
656
+
657
+ @singledispatchmethod
658
+ def call_subroutine(
659
+ self,
660
+ subroutine: Schedule | ScheduleBlock,
661
+ name: str | None = None,
662
+ value_dict: dict[ParameterExpression, ParameterValueType] | None = None,
663
+ **kw_params: ParameterValueType,
664
+ ):
665
+ """Call a schedule or circuit defined outside of the current scope.
666
+
667
+ The ``subroutine`` is appended to the context schedule as a call instruction.
668
+ This logic just generates a convenient program representation in the compiler.
669
+ Thus, this doesn't affect execution of inline subroutines.
670
+ See :class:`~pulse.instructions.Call` for more details.
671
+
672
+ Args:
673
+ subroutine: Target schedule or circuit to append to the current context.
674
+ name: Name of subroutine if defined.
675
+ value_dict: Parameter object and assigned value mapping. This is more precise way to
676
+ identify a parameter since mapping is managed with unique object id rather than
677
+ name. Especially there is any name collision in a parameter table.
678
+ kw_params: Parameter values to bind to the target subroutine
679
+ with string parameter names. If there are parameter name overlapping,
680
+ these parameters are updated with the same assigned value.
681
+
682
+ Raises:
683
+ PulseError:
684
+ - When input subroutine is not valid data format.
685
+ """
686
+ raise exceptions.PulseError(
687
+ f"Subroutine type {subroutine.__class__.__name__} is "
688
+ "not valid data format. Call "
689
+ "Schedule, or ScheduleBlock."
690
+ )
691
+
692
+ @call_subroutine.register
693
+ def _(
694
+ self,
695
+ target_block: ScheduleBlock,
696
+ name: Optional[str] = None,
697
+ value_dict: Optional[Dict[ParameterExpression, ParameterValueType]] = None,
698
+ **kw_params: ParameterValueType,
699
+ ):
700
+ if len(target_block) == 0:
701
+ return
702
+
703
+ # Create local parameter assignment
704
+ local_assignment = {}
705
+ for param_name, value in kw_params.items():
706
+ params = target_block.get_parameters(param_name)
707
+ if not params:
708
+ raise exceptions.PulseError(
709
+ f"Parameter {param_name} is not defined in the target subroutine. "
710
+ f'{", ".join(map(str, target_block.parameters))} can be specified.'
711
+ )
712
+ for param in params:
713
+ local_assignment[param] = value
714
+
715
+ if value_dict:
716
+ if local_assignment.keys() & value_dict.keys():
717
+ warnings.warn(
718
+ "Some parameters provided by 'value_dict' conflict with one through "
719
+ "keyword arguments. Parameter values in the keyword arguments "
720
+ "are overridden by the dictionary values.",
721
+ UserWarning,
722
+ )
723
+ local_assignment.update(value_dict)
724
+
725
+ if local_assignment:
726
+ target_block = target_block.assign_parameters(local_assignment, inplace=False)
727
+
728
+ if name is None:
729
+ # Add unique string, not to accidentally override existing reference entry.
730
+ keys: tuple[str, ...] = (target_block.name, uuid.uuid4().hex)
731
+ else:
732
+ keys = (name,)
733
+
734
+ self.append_reference(*keys)
735
+ self.get_context().assign_references({keys: target_block}, inplace=True)
736
+
737
+ @call_subroutine.register
738
+ def _(
739
+ self,
740
+ target_schedule: Schedule,
741
+ name: Optional[str] = None,
742
+ value_dict: Optional[Dict[ParameterExpression, ParameterValueType]] = None,
743
+ **kw_params: ParameterValueType,
744
+ ):
745
+ if len(target_schedule) == 0:
746
+ return
747
+
748
+ self.call_subroutine(
749
+ self._naive_typecast_schedule(target_schedule),
750
+ name=name,
751
+ value_dict=value_dict,
752
+ **kw_params,
753
+ )
754
+
755
+ @staticmethod
756
+ def _naive_typecast_schedule(schedule: Schedule):
757
+ # Naively convert into ScheduleBlock
758
+ from qiskit.pulse.transforms import inline_subroutines, flatten, pad
759
+
760
+ preprocessed_schedule = inline_subroutines(flatten(schedule))
761
+ pad(preprocessed_schedule, inplace=True, pad_with=instructions.TimeBlockade)
762
+
763
+ # default to left alignment, namely ASAP scheduling
764
+ target_block = ScheduleBlock(name=schedule.name)
765
+ for _, inst in preprocessed_schedule.instructions:
766
+ target_block.append(inst, inplace=True)
767
+
768
+ return target_block
769
+
770
+ def get_dt(self):
771
+ """Retrieve dt differently based on the type of Backend"""
772
+ if isinstance(self.backend, BackendV2):
773
+ return self.backend.dt
774
+ return self.backend.configuration().dt
775
+
776
+
777
+ def build(
778
+ backend=None,
779
+ schedule: ScheduleBlock | None = None,
780
+ name: str | None = None,
781
+ default_alignment: str | AlignmentKind | None = "left",
782
+ ) -> ContextManager[ScheduleBlock]:
783
+ """Create a context manager for launching the imperative pulse builder DSL.
784
+
785
+ To enter a building context and starting building a pulse program:
786
+
787
+ .. code-block::
788
+
789
+ from qiskit import transpile, pulse
790
+ from qiskit.providers.fake_provider import FakeOpenPulse2Q
791
+
792
+ backend = FakeOpenPulse2Q()
793
+
794
+ d0 = pulse.DriveChannel(0)
795
+
796
+ with pulse.build() as pulse_prog:
797
+ pulse.play(pulse.Constant(100, 0.5), d0)
798
+
799
+
800
+ While the output program ``pulse_prog`` cannot be executed as we are using
801
+ a mock backend. If a real backend is being used, executing the program is
802
+ done with:
803
+
804
+ .. code-block:: python
805
+
806
+ backend.run(transpile(pulse_prog, backend))
807
+
808
+ Args:
809
+ backend (Backend): A Qiskit backend. If not supplied certain
810
+ builder functionality will be unavailable.
811
+ schedule: A pulse ``ScheduleBlock`` in which your pulse program will be built.
812
+ name: Name of pulse program to be built.
813
+ default_alignment: Default scheduling alignment for builder.
814
+ One of ``left``, ``right``, ``sequential`` or an alignment context.
815
+
816
+ Returns:
817
+ A new builder context which has the active builder initialized.
818
+ """
819
+ return _PulseBuilder(
820
+ backend=backend,
821
+ block=schedule,
822
+ name=name,
823
+ default_alignment=default_alignment,
824
+ )
825
+
826
+
827
+ # Builder Utilities
828
+
829
+
830
+ def _active_builder() -> _PulseBuilder:
831
+ """Get the active builder in the active context.
832
+
833
+ Returns:
834
+ The active active builder in this context.
835
+
836
+ Raises:
837
+ exceptions.NoActiveBuilder: If a pulse builder function is called
838
+ outside of a builder context.
839
+ """
840
+ try:
841
+ return BUILDER_CONTEXTVAR.get()
842
+ except LookupError as ex:
843
+ raise exceptions.NoActiveBuilder(
844
+ "A Pulse builder function was called outside of "
845
+ "a builder context. Try calling within a builder "
846
+ 'context, eg., "with pulse.build() as schedule: ...".'
847
+ ) from ex
848
+
849
+
850
+ def active_backend():
851
+ """Get the backend of the currently active builder context.
852
+
853
+ Returns:
854
+ Backend: The active backend in the currently active
855
+ builder context.
856
+
857
+ Raises:
858
+ exceptions.BackendNotSet: If the builder does not have a backend set.
859
+ """
860
+ builder = _active_builder().backend
861
+ if builder is None:
862
+ raise exceptions.BackendNotSet(
863
+ 'This function requires the active builder to have a "backend" set.'
864
+ )
865
+ return builder
866
+
867
+
868
+ def append_schedule(schedule: Schedule | ScheduleBlock):
869
+ """Call a schedule by appending to the active builder's context block.
870
+
871
+ Args:
872
+ schedule: Schedule or ScheduleBlock to append.
873
+ """
874
+ _active_builder().append_subroutine(schedule)
875
+
876
+
877
+ def append_instruction(instruction: instructions.Instruction):
878
+ """Append an instruction to the active builder's context schedule.
879
+
880
+ Examples:
881
+
882
+ .. code-block::
883
+
884
+ from qiskit import pulse
885
+
886
+ d0 = pulse.DriveChannel(0)
887
+
888
+ with pulse.build() as pulse_prog:
889
+ pulse.builder.append_instruction(pulse.Delay(10, d0))
890
+
891
+ print(pulse_prog.instructions)
892
+
893
+ .. parsed-literal::
894
+
895
+ ((0, Delay(10, DriveChannel(0))),)
896
+ """
897
+ _active_builder().append_instruction(instruction)
898
+
899
+
900
+ def num_qubits() -> int:
901
+ """Return number of qubits in the currently active backend.
902
+
903
+ Examples:
904
+
905
+ .. code-block::
906
+
907
+ from qiskit import pulse
908
+ from qiskit.providers.fake_provider import FakeOpenPulse2Q
909
+
910
+ backend = FakeOpenPulse2Q()
911
+
912
+ with pulse.build(backend):
913
+ print(pulse.num_qubits())
914
+
915
+ .. parsed-literal::
916
+
917
+ 2
918
+
919
+ .. note:: Requires the active builder context to have a backend set.
920
+ """
921
+ if isinstance(active_backend(), BackendV2):
922
+ return active_backend().num_qubits
923
+ return active_backend().configuration().n_qubits
924
+
925
+
926
+ def seconds_to_samples(seconds: float | np.ndarray) -> int | np.ndarray:
927
+ """Obtain the number of samples that will elapse in ``seconds`` on the
928
+ active backend.
929
+
930
+ Rounds down.
931
+
932
+ Args:
933
+ seconds: Time in seconds to convert to samples.
934
+
935
+ Returns:
936
+ The number of samples for the time to elapse
937
+ """
938
+ dt = _active_builder().get_dt()
939
+ if isinstance(seconds, np.ndarray):
940
+ return (seconds / dt).astype(int)
941
+ return int(seconds / dt)
942
+
943
+
944
+ def samples_to_seconds(samples: int | np.ndarray) -> float | np.ndarray:
945
+ """Obtain the time in seconds that will elapse for the input number of
946
+ samples on the active backend.
947
+
948
+ Args:
949
+ samples: Number of samples to convert to time in seconds.
950
+
951
+ Returns:
952
+ The time that elapses in ``samples``.
953
+ """
954
+ return samples * _active_builder().get_dt()
955
+
956
+
957
+ def qubit_channels(qubit: int) -> set[chans.Channel]:
958
+ """Returns the set of channels associated with a qubit.
959
+
960
+ Examples:
961
+
962
+ .. code-block::
963
+
964
+ from qiskit import pulse
965
+ from qiskit.providers.fake_provider import FakeOpenPulse2Q
966
+
967
+ backend = FakeOpenPulse2Q()
968
+
969
+ with pulse.build(backend):
970
+ print(pulse.qubit_channels(0))
971
+
972
+ .. parsed-literal::
973
+
974
+ {MeasureChannel(0), ControlChannel(0), DriveChannel(0), AcquireChannel(0), ControlChannel(1)}
975
+
976
+ .. note:: Requires the active builder context to have a backend set.
977
+
978
+ .. note:: A channel may still be associated with another qubit in this list
979
+ such as in the case where significant crosstalk exists.
980
+
981
+ """
982
+
983
+ # implement as the inner function to avoid API change for a patch release in 0.24.2.
984
+ def get_qubit_channels_v2(backend: BackendV2, qubit: int):
985
+ r"""Return a list of channels which operate on the given ``qubit``.
986
+ Returns:
987
+ List of ``Channel``\s operated on my the given ``qubit``.
988
+ """
989
+ channels = []
990
+
991
+ # add multi-qubit channels
992
+ for node_qubits in backend.coupling_map:
993
+ if qubit in node_qubits:
994
+ control_channel = backend.control_channel(node_qubits)
995
+ if control_channel:
996
+ channels.extend(control_channel)
997
+
998
+ # add single qubit channels
999
+ channels.append(backend.drive_channel(qubit))
1000
+ channels.append(backend.measure_channel(qubit))
1001
+ channels.append(backend.acquire_channel(qubit))
1002
+ return channels
1003
+
1004
+ # backendV2
1005
+ if isinstance(active_backend(), BackendV2):
1006
+ return set(get_qubit_channels_v2(active_backend(), qubit))
1007
+ return set(active_backend().configuration().get_qubit_channels(qubit))
1008
+
1009
+
1010
+ def _qubits_to_channels(*channels_or_qubits: int | chans.Channel) -> set[chans.Channel]:
1011
+ """Returns the unique channels of the input qubits."""
1012
+ channels = set()
1013
+ for channel_or_qubit in channels_or_qubits:
1014
+ if isinstance(channel_or_qubit, int):
1015
+ channels |= qubit_channels(channel_or_qubit)
1016
+ elif isinstance(channel_or_qubit, chans.Channel):
1017
+ channels.add(channel_or_qubit)
1018
+ else:
1019
+ raise exceptions.PulseError(
1020
+ f'{channel_or_qubit} is not a "Channel" or qubit (integer).'
1021
+ )
1022
+ return channels
1023
+
1024
+
1025
+ # Contexts
1026
+
1027
+
1028
+ @contextmanager
1029
+ def align_left() -> Generator[None, None, None]:
1030
+ """Left alignment pulse scheduling context.
1031
+
1032
+ Pulse instructions within this context are scheduled as early as possible
1033
+ by shifting them left to the earliest available time.
1034
+
1035
+ Examples:
1036
+
1037
+ .. code-block::
1038
+
1039
+ from qiskit import pulse
1040
+
1041
+ d0 = pulse.DriveChannel(0)
1042
+ d1 = pulse.DriveChannel(1)
1043
+
1044
+ with pulse.build() as pulse_prog:
1045
+ with pulse.align_left():
1046
+ # this pulse will start at t=0
1047
+ pulse.play(pulse.Constant(100, 1.0), d0)
1048
+ # this pulse will start at t=0
1049
+ pulse.play(pulse.Constant(20, 1.0), d1)
1050
+ pulse_prog = pulse.transforms.block_to_schedule(pulse_prog)
1051
+
1052
+ assert pulse_prog.ch_start_time(d0) == pulse_prog.ch_start_time(d1)
1053
+
1054
+ Yields:
1055
+ None
1056
+ """
1057
+ builder = _active_builder()
1058
+ builder.push_context(transforms.AlignLeft())
1059
+ try:
1060
+ yield
1061
+ finally:
1062
+ current = builder.pop_context()
1063
+ builder.append_subroutine(current)
1064
+
1065
+
1066
+ @contextmanager
1067
+ def align_right() -> Generator[None, None, None]:
1068
+ """Right alignment pulse scheduling context.
1069
+
1070
+ Pulse instructions within this context are scheduled as late as possible
1071
+ by shifting them right to the latest available time.
1072
+
1073
+ Examples:
1074
+
1075
+ .. code-block::
1076
+
1077
+ from qiskit import pulse
1078
+
1079
+ d0 = pulse.DriveChannel(0)
1080
+ d1 = pulse.DriveChannel(1)
1081
+
1082
+ with pulse.build() as pulse_prog:
1083
+ with pulse.align_right():
1084
+ # this pulse will start at t=0
1085
+ pulse.play(pulse.Constant(100, 1.0), d0)
1086
+ # this pulse will start at t=80
1087
+ pulse.play(pulse.Constant(20, 1.0), d1)
1088
+ pulse_prog = pulse.transforms.block_to_schedule(pulse_prog)
1089
+
1090
+ assert pulse_prog.ch_stop_time(d0) == pulse_prog.ch_stop_time(d1)
1091
+
1092
+ Yields:
1093
+ None
1094
+ """
1095
+ builder = _active_builder()
1096
+ builder.push_context(transforms.AlignRight())
1097
+ try:
1098
+ yield
1099
+ finally:
1100
+ current = builder.pop_context()
1101
+ builder.append_subroutine(current)
1102
+
1103
+
1104
+ @contextmanager
1105
+ def align_sequential() -> Generator[None, None, None]:
1106
+ """Sequential alignment pulse scheduling context.
1107
+
1108
+ Pulse instructions within this context are scheduled sequentially in time
1109
+ such that no two instructions will be played at the same time.
1110
+
1111
+ Examples:
1112
+
1113
+ .. code-block::
1114
+
1115
+ from qiskit import pulse
1116
+
1117
+ d0 = pulse.DriveChannel(0)
1118
+ d1 = pulse.DriveChannel(1)
1119
+
1120
+ with pulse.build() as pulse_prog:
1121
+ with pulse.align_sequential():
1122
+ # this pulse will start at t=0
1123
+ pulse.play(pulse.Constant(100, 1.0), d0)
1124
+ # this pulse will also start at t=100
1125
+ pulse.play(pulse.Constant(20, 1.0), d1)
1126
+ pulse_prog = pulse.transforms.block_to_schedule(pulse_prog)
1127
+
1128
+ assert pulse_prog.ch_stop_time(d0) == pulse_prog.ch_start_time(d1)
1129
+
1130
+ Yields:
1131
+ None
1132
+ """
1133
+ builder = _active_builder()
1134
+ builder.push_context(transforms.AlignSequential())
1135
+ try:
1136
+ yield
1137
+ finally:
1138
+ current = builder.pop_context()
1139
+ builder.append_subroutine(current)
1140
+
1141
+
1142
+ @contextmanager
1143
+ def align_equispaced(duration: int | ParameterExpression) -> Generator[None, None, None]:
1144
+ """Equispaced alignment pulse scheduling context.
1145
+
1146
+ Pulse instructions within this context are scheduled with the same interval spacing such that
1147
+ the total length of the context block is ``duration``.
1148
+ If the total free ``duration`` cannot be evenly divided by the number of instructions
1149
+ within the context, the modulo is split and then prepended and appended to
1150
+ the returned schedule. Delay instructions are automatically inserted in between pulses.
1151
+
1152
+ This context is convenient to write a schedule for periodical dynamic decoupling or
1153
+ the Hahn echo sequence.
1154
+
1155
+ Examples:
1156
+
1157
+ .. plot::
1158
+ :include-source:
1159
+
1160
+ from qiskit import pulse
1161
+
1162
+ d0 = pulse.DriveChannel(0)
1163
+ x90 = pulse.Gaussian(10, 0.1, 3)
1164
+ x180 = pulse.Gaussian(10, 0.2, 3)
1165
+
1166
+ with pulse.build() as hahn_echo:
1167
+ with pulse.align_equispaced(duration=100):
1168
+ pulse.play(x90, d0)
1169
+ pulse.play(x180, d0)
1170
+ pulse.play(x90, d0)
1171
+
1172
+ hahn_echo.draw()
1173
+
1174
+ Args:
1175
+ duration: Duration of this context. This should be larger than the schedule duration.
1176
+
1177
+ Yields:
1178
+ None
1179
+
1180
+ Notes:
1181
+ The scheduling is performed for sub-schedules within the context rather than
1182
+ channel-wise. If you want to apply the equispaced context for each channel,
1183
+ you should use the context independently for channels.
1184
+ """
1185
+ builder = _active_builder()
1186
+ builder.push_context(transforms.AlignEquispaced(duration=duration))
1187
+ try:
1188
+ yield
1189
+ finally:
1190
+ current = builder.pop_context()
1191
+ builder.append_subroutine(current)
1192
+
1193
+
1194
+ @contextmanager
1195
+ def align_func(
1196
+ duration: int | ParameterExpression, func: Callable[[int], float]
1197
+ ) -> Generator[None, None, None]:
1198
+ """Callback defined alignment pulse scheduling context.
1199
+
1200
+ Pulse instructions within this context are scheduled at the location specified by
1201
+ arbitrary callback function `position` that takes integer index and returns
1202
+ the associated fractional location within [0, 1].
1203
+ Delay instruction is automatically inserted in between pulses.
1204
+
1205
+ This context may be convenient to write a schedule of arbitrary dynamical decoupling
1206
+ sequences such as Uhrig dynamical decoupling.
1207
+
1208
+ Examples:
1209
+
1210
+ .. plot::
1211
+ :include-source:
1212
+
1213
+ import numpy as np
1214
+ from qiskit import pulse
1215
+
1216
+ d0 = pulse.DriveChannel(0)
1217
+ x90 = pulse.Gaussian(10, 0.1, 3)
1218
+ x180 = pulse.Gaussian(10, 0.2, 3)
1219
+
1220
+ def udd10_pos(j):
1221
+ return np.sin(np.pi*j/(2*10 + 2))**2
1222
+
1223
+ with pulse.build() as udd_sched:
1224
+ pulse.play(x90, d0)
1225
+ with pulse.align_func(duration=300, func=udd10_pos):
1226
+ for _ in range(10):
1227
+ pulse.play(x180, d0)
1228
+ pulse.play(x90, d0)
1229
+
1230
+ udd_sched.draw()
1231
+
1232
+ Args:
1233
+ duration: Duration of context. This should be larger than the schedule duration.
1234
+ func: A function that takes an index of sub-schedule and returns the
1235
+ fractional coordinate of of that sub-schedule.
1236
+ The returned value should be defined within [0, 1].
1237
+ The pulse index starts from 1.
1238
+
1239
+ Yields:
1240
+ None
1241
+
1242
+ Notes:
1243
+ The scheduling is performed for sub-schedules within the context rather than
1244
+ channel-wise. If you want to apply the numerical context for each channel,
1245
+ you need to apply the context independently to channels.
1246
+ """
1247
+ builder = _active_builder()
1248
+ builder.push_context(transforms.AlignFunc(duration=duration, func=func))
1249
+ try:
1250
+ yield
1251
+ finally:
1252
+ current = builder.pop_context()
1253
+ builder.append_subroutine(current)
1254
+
1255
+
1256
+ @contextmanager
1257
+ def general_transforms(alignment_context: AlignmentKind) -> Generator[None, None, None]:
1258
+ """Arbitrary alignment transformation defined by a subclass instance of
1259
+ :class:`~qiskit.pulse.transforms.alignments.AlignmentKind`.
1260
+
1261
+ Args:
1262
+ alignment_context: Alignment context instance that defines schedule transformation.
1263
+
1264
+ Yields:
1265
+ None
1266
+
1267
+ Raises:
1268
+ PulseError: When input ``alignment_context`` is not ``AlignmentKind`` subclasses.
1269
+ """
1270
+ if not isinstance(alignment_context, AlignmentKind):
1271
+ raise exceptions.PulseError("Input alignment context is not `AlignmentKind` subclass.")
1272
+
1273
+ builder = _active_builder()
1274
+ builder.push_context(alignment_context)
1275
+ try:
1276
+ yield
1277
+ finally:
1278
+ current = builder.pop_context()
1279
+ builder.append_subroutine(current)
1280
+
1281
+
1282
+ @contextmanager
1283
+ def phase_offset(phase: float, *channels: chans.PulseChannel) -> Generator[None, None, None]:
1284
+ """Shift the phase of input channels on entry into context and undo on exit.
1285
+
1286
+ Examples:
1287
+
1288
+ .. code-block::
1289
+
1290
+ import math
1291
+
1292
+ from qiskit import pulse
1293
+
1294
+ d0 = pulse.DriveChannel(0)
1295
+
1296
+ with pulse.build() as pulse_prog:
1297
+ with pulse.phase_offset(math.pi, d0):
1298
+ pulse.play(pulse.Constant(10, 1.0), d0)
1299
+
1300
+ assert len(pulse_prog.instructions) == 3
1301
+
1302
+ Args:
1303
+ phase: Amount of phase offset in radians.
1304
+ channels: Channels to offset phase of.
1305
+
1306
+ Yields:
1307
+ None
1308
+ """
1309
+ for channel in channels:
1310
+ shift_phase(phase, channel)
1311
+ try:
1312
+ yield
1313
+ finally:
1314
+ for channel in channels:
1315
+ shift_phase(-phase, channel)
1316
+
1317
+
1318
+ @contextmanager
1319
+ def frequency_offset(
1320
+ frequency: float, *channels: chans.PulseChannel, compensate_phase: bool = False
1321
+ ) -> Generator[None, None, None]:
1322
+ """Shift the frequency of inputs channels on entry into context and undo on exit.
1323
+
1324
+ Examples:
1325
+
1326
+ .. code-block:: python
1327
+ :emphasize-lines: 7, 16
1328
+
1329
+ from qiskit import pulse
1330
+
1331
+ d0 = pulse.DriveChannel(0)
1332
+
1333
+ with pulse.build(backend) as pulse_prog:
1334
+ # shift frequency by 1GHz
1335
+ with pulse.frequency_offset(1e9, d0):
1336
+ pulse.play(pulse.Constant(10, 1.0), d0)
1337
+
1338
+ assert len(pulse_prog.instructions) == 3
1339
+
1340
+ with pulse.build(backend) as pulse_prog:
1341
+ # Shift frequency by 1GHz.
1342
+ # Undo accumulated phase in the shifted frequency frame
1343
+ # when exiting the context.
1344
+ with pulse.frequency_offset(1e9, d0, compensate_phase=True):
1345
+ pulse.play(pulse.Constant(10, 1.0), d0)
1346
+
1347
+ assert len(pulse_prog.instructions) == 4
1348
+
1349
+ Args:
1350
+ frequency: Amount of frequency offset in Hz.
1351
+ channels: Channels to offset frequency of.
1352
+ compensate_phase: Compensate for accumulated phase accumulated with
1353
+ respect to the channels' frame at its initial frequency.
1354
+
1355
+ Yields:
1356
+ None
1357
+ """
1358
+ builder = _active_builder()
1359
+ # TODO: Need proper implementation of compensation. t0 may depend on the parent context.
1360
+ # For example, the instruction position within the equispaced context depends on
1361
+ # the current total number of instructions, thus adding more instruction after
1362
+ # offset context may change the t0 when the parent context is transformed.
1363
+ t0 = builder.get_context().duration
1364
+
1365
+ for channel in channels:
1366
+ shift_frequency(frequency, channel)
1367
+ try:
1368
+ yield
1369
+ finally:
1370
+ if compensate_phase:
1371
+ duration = builder.get_context().duration - t0
1372
+
1373
+ accumulated_phase = 2 * np.pi * ((duration * builder.get_dt() * frequency) % 1)
1374
+ for channel in channels:
1375
+ shift_phase(-accumulated_phase, channel)
1376
+
1377
+ for channel in channels:
1378
+ shift_frequency(-frequency, channel)
1379
+
1380
+
1381
+ # Channels
1382
+ def drive_channel(qubit: int) -> chans.DriveChannel:
1383
+ """Return ``DriveChannel`` for ``qubit`` on the active builder backend.
1384
+
1385
+ Examples:
1386
+
1387
+ .. code-block::
1388
+
1389
+ from qiskit import pulse
1390
+ from qiskit.providers.fake_provider import FakeOpenPulse2Q
1391
+
1392
+ backend = FakeOpenPulse2Q()
1393
+
1394
+ with pulse.build(backend):
1395
+ assert pulse.drive_channel(0) == pulse.DriveChannel(0)
1396
+
1397
+ .. note:: Requires the active builder context to have a backend set.
1398
+ """
1399
+ # backendV2
1400
+ if isinstance(active_backend(), BackendV2):
1401
+ return active_backend().drive_channel(qubit)
1402
+ return active_backend().configuration().drive(qubit)
1403
+
1404
+
1405
+ def measure_channel(qubit: int) -> chans.MeasureChannel:
1406
+ """Return ``MeasureChannel`` for ``qubit`` on the active builder backend.
1407
+
1408
+ Examples:
1409
+
1410
+ .. code-block::
1411
+
1412
+ from qiskit import pulse
1413
+ from qiskit.providers.fake_provider import FakeOpenPulse2Q
1414
+
1415
+ backend = FakeOpenPulse2Q()
1416
+
1417
+ with pulse.build(backend):
1418
+ assert pulse.measure_channel(0) == pulse.MeasureChannel(0)
1419
+
1420
+ .. note:: Requires the active builder context to have a backend set.
1421
+ """
1422
+ # backendV2
1423
+ if isinstance(active_backend(), BackendV2):
1424
+ return active_backend().measure_channel(qubit)
1425
+ return active_backend().configuration().measure(qubit)
1426
+
1427
+
1428
+ def acquire_channel(qubit: int) -> chans.AcquireChannel:
1429
+ """Return ``AcquireChannel`` for ``qubit`` on the active builder backend.
1430
+
1431
+ Examples:
1432
+
1433
+ .. code-block::
1434
+
1435
+ from qiskit import pulse
1436
+ from qiskit.providers.fake_provider import FakeOpenPulse2Q
1437
+
1438
+ backend = FakeOpenPulse2Q()
1439
+
1440
+ with pulse.build(backend):
1441
+ assert pulse.acquire_channel(0) == pulse.AcquireChannel(0)
1442
+
1443
+ .. note:: Requires the active builder context to have a backend set.
1444
+ """
1445
+ # backendV2
1446
+ if isinstance(active_backend(), BackendV2):
1447
+ return active_backend().acquire_channel(qubit)
1448
+ return active_backend().configuration().acquire(qubit)
1449
+
1450
+
1451
+ def control_channels(*qubits: Iterable[int]) -> list[chans.ControlChannel]:
1452
+ """Return ``ControlChannel`` for ``qubit`` on the active builder backend.
1453
+
1454
+ Return the secondary drive channel for the given qubit -- typically
1455
+ utilized for controlling multi-qubit interactions.
1456
+
1457
+ Examples:
1458
+
1459
+ .. code-block::
1460
+
1461
+ from qiskit import pulse
1462
+ from qiskit.providers.fake_provider import FakeOpenPulse2Q
1463
+
1464
+ backend = FakeOpenPulse2Q()
1465
+ with pulse.build(backend):
1466
+ assert pulse.control_channels(0, 1) == [pulse.ControlChannel(0)]
1467
+
1468
+ .. note:: Requires the active builder context to have a backend set.
1469
+
1470
+ Args:
1471
+ qubits: Tuple or list of ordered qubits of the form
1472
+ `(control_qubit, target_qubit)`.
1473
+
1474
+ Returns:
1475
+ List of control channels associated with the supplied ordered list
1476
+ of qubits.
1477
+ """
1478
+ # backendV2
1479
+ if isinstance(active_backend(), BackendV2):
1480
+ return active_backend().control_channel(qubits)
1481
+ return active_backend().configuration().control(qubits=qubits)
1482
+
1483
+
1484
+ # Base Instructions
1485
+ def delay(duration: int, channel: chans.Channel, name: str | None = None):
1486
+ """Delay on a ``channel`` for a ``duration``.
1487
+
1488
+ Examples:
1489
+
1490
+ .. code-block::
1491
+
1492
+ from qiskit import pulse
1493
+
1494
+ d0 = pulse.DriveChannel(0)
1495
+
1496
+ with pulse.build() as pulse_prog:
1497
+ pulse.delay(10, d0)
1498
+
1499
+ Args:
1500
+ duration: Number of cycles to delay for on ``channel``.
1501
+ channel: Channel to delay on.
1502
+ name: Name of the instruction.
1503
+ """
1504
+ append_instruction(instructions.Delay(duration, channel, name=name))
1505
+
1506
+
1507
+ def play(pulse: library.Pulse | np.ndarray, channel: chans.PulseChannel, name: str | None = None):
1508
+ """Play a ``pulse`` on a ``channel``.
1509
+
1510
+ Examples:
1511
+
1512
+ .. code-block::
1513
+
1514
+ from qiskit import pulse
1515
+
1516
+ d0 = pulse.DriveChannel(0)
1517
+
1518
+ with pulse.build() as pulse_prog:
1519
+ pulse.play(pulse.Constant(10, 1.0), d0)
1520
+
1521
+ Args:
1522
+ pulse: Pulse to play.
1523
+ channel: Channel to play pulse on.
1524
+ name: Name of the pulse.
1525
+ """
1526
+ if not isinstance(pulse, library.Pulse):
1527
+ pulse = library.Waveform(pulse)
1528
+
1529
+ append_instruction(instructions.Play(pulse, channel, name=name))
1530
+
1531
+
1532
+ class _MetaDataType(TypedDict, total=False):
1533
+ kernel: configuration.Kernel
1534
+ discriminator: configuration.Discriminator
1535
+ mem_slot: chans.MemorySlot
1536
+ reg_slot: chans.RegisterSlot
1537
+ name: str
1538
+
1539
+
1540
+ def acquire(
1541
+ duration: int,
1542
+ qubit_or_channel: int | chans.AcquireChannel,
1543
+ register: StorageLocation,
1544
+ **metadata: Unpack[_MetaDataType],
1545
+ ):
1546
+ """Acquire for a ``duration`` on a ``channel`` and store the result
1547
+ in a ``register``.
1548
+
1549
+ Examples:
1550
+
1551
+ .. code-block::
1552
+
1553
+ from qiskit import pulse
1554
+
1555
+ acq0 = pulse.AcquireChannel(0)
1556
+ mem0 = pulse.MemorySlot(0)
1557
+
1558
+ with pulse.build() as pulse_prog:
1559
+ pulse.acquire(100, acq0, mem0)
1560
+
1561
+ # measurement metadata
1562
+ kernel = pulse.configuration.Kernel('linear_discriminator')
1563
+ pulse.acquire(100, acq0, mem0, kernel=kernel)
1564
+
1565
+ .. note:: The type of data acquire will depend on the execution ``meas_level``.
1566
+
1567
+ Args:
1568
+ duration: Duration to acquire data for
1569
+ qubit_or_channel: Either the qubit to acquire data for or the specific
1570
+ :class:`~qiskit.pulse.channels.AcquireChannel` to acquire on.
1571
+ register: Location to store measured result.
1572
+ metadata: Additional metadata for measurement. See
1573
+ :class:`~qiskit.pulse.instructions.Acquire` for more information.
1574
+
1575
+ Raises:
1576
+ exceptions.PulseError: If the register type is not supported.
1577
+ """
1578
+ if isinstance(qubit_or_channel, int):
1579
+ qubit_or_channel = chans.AcquireChannel(qubit_or_channel)
1580
+
1581
+ if isinstance(register, chans.MemorySlot):
1582
+ append_instruction(
1583
+ instructions.Acquire(duration, qubit_or_channel, mem_slot=register, **metadata)
1584
+ )
1585
+ elif isinstance(register, chans.RegisterSlot):
1586
+ append_instruction(
1587
+ instructions.Acquire(duration, qubit_or_channel, reg_slot=register, **metadata)
1588
+ )
1589
+ else:
1590
+ raise exceptions.PulseError(f'Register of type: "{type(register)}" is not supported')
1591
+
1592
+
1593
+ def set_frequency(frequency: float, channel: chans.PulseChannel, name: str | None = None):
1594
+ """Set the ``frequency`` of a pulse ``channel``.
1595
+
1596
+ Examples:
1597
+
1598
+ .. code-block::
1599
+
1600
+ from qiskit import pulse
1601
+
1602
+ d0 = pulse.DriveChannel(0)
1603
+
1604
+ with pulse.build() as pulse_prog:
1605
+ pulse.set_frequency(1e9, d0)
1606
+
1607
+ Args:
1608
+ frequency: Frequency in Hz to set channel to.
1609
+ channel: Channel to set frequency of.
1610
+ name: Name of the instruction.
1611
+ """
1612
+ append_instruction(instructions.SetFrequency(frequency, channel, name=name))
1613
+
1614
+
1615
+ def shift_frequency(frequency: float, channel: chans.PulseChannel, name: str | None = None):
1616
+ """Shift the ``frequency`` of a pulse ``channel``.
1617
+
1618
+ Examples:
1619
+
1620
+ .. code-block:: python
1621
+ :emphasize-lines: 6
1622
+
1623
+ from qiskit import pulse
1624
+
1625
+ d0 = pulse.DriveChannel(0)
1626
+
1627
+ with pulse.build() as pulse_prog:
1628
+ pulse.shift_frequency(1e9, d0)
1629
+
1630
+ Args:
1631
+ frequency: Frequency in Hz to shift channel frequency by.
1632
+ channel: Channel to shift frequency of.
1633
+ name: Name of the instruction.
1634
+ """
1635
+ append_instruction(instructions.ShiftFrequency(frequency, channel, name=name))
1636
+
1637
+
1638
+ def set_phase(phase: float, channel: chans.PulseChannel, name: str | None = None):
1639
+ """Set the ``phase`` of a pulse ``channel``.
1640
+
1641
+ Examples:
1642
+
1643
+ .. code-block:: python
1644
+ :emphasize-lines: 8
1645
+
1646
+ import math
1647
+
1648
+ from qiskit import pulse
1649
+
1650
+ d0 = pulse.DriveChannel(0)
1651
+
1652
+ with pulse.build() as pulse_prog:
1653
+ pulse.set_phase(math.pi, d0)
1654
+
1655
+ Args:
1656
+ phase: Phase in radians to set channel carrier signal to.
1657
+ channel: Channel to set phase of.
1658
+ name: Name of the instruction.
1659
+ """
1660
+ append_instruction(instructions.SetPhase(phase, channel, name=name))
1661
+
1662
+
1663
+ def shift_phase(phase: float, channel: chans.PulseChannel, name: str | None = None):
1664
+ """Shift the ``phase`` of a pulse ``channel``.
1665
+
1666
+ Examples:
1667
+
1668
+ .. code-block::
1669
+
1670
+ import math
1671
+
1672
+ from qiskit import pulse
1673
+
1674
+ d0 = pulse.DriveChannel(0)
1675
+
1676
+ with pulse.build() as pulse_prog:
1677
+ pulse.shift_phase(math.pi, d0)
1678
+
1679
+ Args:
1680
+ phase: Phase in radians to shift channel carrier signal by.
1681
+ channel: Channel to shift phase of.
1682
+ name: Name of the instruction.
1683
+ """
1684
+ append_instruction(instructions.ShiftPhase(phase, channel, name))
1685
+
1686
+
1687
+ def snapshot(label: str, snapshot_type: str = "statevector"):
1688
+ """Simulator snapshot.
1689
+
1690
+ Examples:
1691
+
1692
+ .. code-block::
1693
+
1694
+ from qiskit import pulse
1695
+
1696
+ with pulse.build() as pulse_prog:
1697
+ pulse.snapshot('first', 'statevector')
1698
+
1699
+ Args:
1700
+ label: Label for snapshot.
1701
+ snapshot_type: Type of snapshot.
1702
+ """
1703
+ append_instruction(instructions.Snapshot(label, snapshot_type=snapshot_type))
1704
+
1705
+
1706
+ def call(
1707
+ target: Schedule | ScheduleBlock | None,
1708
+ name: str | None = None,
1709
+ value_dict: dict[ParameterValueType, ParameterValueType] | None = None,
1710
+ **kw_params: ParameterValueType,
1711
+ ):
1712
+ """Call the subroutine within the currently active builder context with arbitrary
1713
+ parameters which will be assigned to the target program.
1714
+
1715
+ .. note::
1716
+
1717
+ If the ``target`` program is a :class:`.ScheduleBlock`, then a :class:`.Reference`
1718
+ instruction will be created and appended to the current context.
1719
+ The ``target`` program will be immediately assigned to the current scope as a subroutine.
1720
+ If the ``target`` program is :class:`.Schedule`, it will be wrapped by the
1721
+ :class:`.Call` instruction and appended to the current context to avoid
1722
+ a mixed representation of :class:`.ScheduleBlock` and :class:`.Schedule`.
1723
+ If the ``target`` program is a :class:`.QuantumCircuit` it will be scheduled
1724
+ and the new :class:`.Schedule` will be added as a :class:`.Call` instruction.
1725
+
1726
+ Examples:
1727
+
1728
+ 1. Calling a schedule block (recommended)
1729
+
1730
+ .. code-block::
1731
+
1732
+ from qiskit import circuit, pulse
1733
+ from qiskit.providers.fake_provider import GenericBackendV2
1734
+
1735
+ backend = GenericBackendV2(num_qubits=5, calibrate_instructions=True)
1736
+
1737
+ with pulse.build() as x_sched:
1738
+ pulse.play(pulse.Gaussian(160, 0.1, 40), pulse.DriveChannel(0))
1739
+
1740
+ with pulse.build() as pulse_prog:
1741
+ pulse.call(x_sched)
1742
+
1743
+ print(pulse_prog)
1744
+
1745
+ .. parsed-literal::
1746
+
1747
+ ScheduleBlock(
1748
+ ScheduleBlock(
1749
+ Play(
1750
+ Gaussian(duration=160, amp=(0.1+0j), sigma=40),
1751
+ DriveChannel(0)
1752
+ ),
1753
+ name="block0",
1754
+ transform=AlignLeft()
1755
+ ),
1756
+ name="block1",
1757
+ transform=AlignLeft()
1758
+ )
1759
+
1760
+ The actual program is stored in the reference table attached to the schedule.
1761
+
1762
+ .. code-block::
1763
+
1764
+ print(pulse_prog.references)
1765
+
1766
+ .. parsed-literal::
1767
+
1768
+ ReferenceManager:
1769
+ - ('block0', '634b3b50bd684e26a673af1fbd2d6c81'): ScheduleBlock(Play(Gaussian(...
1770
+
1771
+ In addition, you can call a parameterized target program with parameter assignment.
1772
+
1773
+ .. code-block::
1774
+
1775
+ amp = circuit.Parameter("amp")
1776
+
1777
+ with pulse.build() as subroutine:
1778
+ pulse.play(pulse.Gaussian(160, amp, 40), pulse.DriveChannel(0))
1779
+
1780
+ with pulse.build() as pulse_prog:
1781
+ pulse.call(subroutine, amp=0.1)
1782
+ pulse.call(subroutine, amp=0.3)
1783
+
1784
+ print(pulse_prog)
1785
+
1786
+ .. parsed-literal::
1787
+
1788
+ ScheduleBlock(
1789
+ ScheduleBlock(
1790
+ Play(
1791
+ Gaussian(duration=160, amp=(0.1+0j), sigma=40),
1792
+ DriveChannel(0)
1793
+ ),
1794
+ name="block2",
1795
+ transform=AlignLeft()
1796
+ ),
1797
+ ScheduleBlock(
1798
+ Play(
1799
+ Gaussian(duration=160, amp=(0.3+0j), sigma=40),
1800
+ DriveChannel(0)
1801
+ ),
1802
+ name="block2",
1803
+ transform=AlignLeft()
1804
+ ),
1805
+ name="block3",
1806
+ transform=AlignLeft()
1807
+ )
1808
+
1809
+ If there is a name collision between parameters, you can distinguish them by specifying
1810
+ each parameter object in a python dictionary. For example,
1811
+
1812
+ .. code-block::
1813
+
1814
+ amp1 = circuit.Parameter('amp')
1815
+ amp2 = circuit.Parameter('amp')
1816
+
1817
+ with pulse.build() as subroutine:
1818
+ pulse.play(pulse.Gaussian(160, amp1, 40), pulse.DriveChannel(0))
1819
+ pulse.play(pulse.Gaussian(160, amp2, 40), pulse.DriveChannel(1))
1820
+
1821
+ with pulse.build() as pulse_prog:
1822
+ pulse.call(subroutine, value_dict={amp1: 0.1, amp2: 0.3})
1823
+
1824
+ print(pulse_prog)
1825
+
1826
+ .. parsed-literal::
1827
+
1828
+ ScheduleBlock(
1829
+ ScheduleBlock(
1830
+ Play(Gaussian(duration=160, amp=(0.1+0j), sigma=40), DriveChannel(0)),
1831
+ Play(Gaussian(duration=160, amp=(0.3+0j), sigma=40), DriveChannel(1)),
1832
+ name="block4",
1833
+ transform=AlignLeft()
1834
+ ),
1835
+ name="block5",
1836
+ transform=AlignLeft()
1837
+ )
1838
+
1839
+ 2. Calling a schedule
1840
+
1841
+ .. code-block::
1842
+
1843
+ x_sched = backend.instruction_schedule_map.get("x", (0,))
1844
+
1845
+ with pulse.build(backend) as pulse_prog:
1846
+ pulse.call(x_sched)
1847
+
1848
+ print(pulse_prog)
1849
+
1850
+ .. parsed-literal::
1851
+
1852
+ ScheduleBlock(
1853
+ Call(
1854
+ Schedule(
1855
+ (
1856
+ 0,
1857
+ Play(
1858
+ Drag(
1859
+ duration=160,
1860
+ amp=(0.18989731546729305+0j),
1861
+ sigma=40,
1862
+ beta=-1.201258305015517,
1863
+ name='drag_86a8'
1864
+ ),
1865
+ DriveChannel(0),
1866
+ name='drag_86a8'
1867
+ )
1868
+ ),
1869
+ name="x"
1870
+ ),
1871
+ name='x'
1872
+ ),
1873
+ name="block6",
1874
+ transform=AlignLeft()
1875
+ )
1876
+
1877
+ Currently, the backend calibrated gates are provided in the form of :class:`~.Schedule`.
1878
+ The parameter assignment mechanism is available also for schedules.
1879
+ However, the called schedule is not treated as a reference.
1880
+
1881
+
1882
+ Args:
1883
+ target: Target circuit or pulse schedule to call.
1884
+ name: Optional. A unique name of subroutine if defined. When the name is explicitly
1885
+ provided, one cannot call different schedule blocks with the same name.
1886
+ value_dict: Optional. Parameters assigned to the ``target`` program.
1887
+ If this dictionary is provided, the ``target`` program is copied and
1888
+ then stored in the main built schedule and its parameters are assigned to the given values.
1889
+ This dictionary is keyed on :class:`~.Parameter` objects,
1890
+ allowing parameter name collision to be avoided.
1891
+ kw_params: Alternative way to provide parameters.
1892
+ Since this is keyed on the string parameter name,
1893
+ the parameters having the same name are all updated together.
1894
+ If you want to avoid name collision, use ``value_dict`` with :class:`~.Parameter`
1895
+ objects instead.
1896
+ """
1897
+ _active_builder().call_subroutine(target, name, value_dict, **kw_params)
1898
+
1899
+
1900
+ def reference(name: str, *extra_keys: str):
1901
+ """Refer to undefined subroutine by string keys.
1902
+
1903
+ A :class:`~qiskit.pulse.instructions.Reference` instruction is implicitly created
1904
+ and a schedule can be separately registered to the reference at a later stage.
1905
+
1906
+ .. code-block:: python
1907
+
1908
+ from qiskit import pulse
1909
+
1910
+ with pulse.build() as main_prog:
1911
+ pulse.reference("x_gate", "q0")
1912
+
1913
+ with pulse.build() as subroutine:
1914
+ pulse.play(pulse.Gaussian(160, 0.1, 40), pulse.DriveChannel(0))
1915
+
1916
+ main_prog.assign_references(subroutine_dict={("x_gate", "q0"): subroutine})
1917
+
1918
+ Args:
1919
+ name: Name of subroutine.
1920
+ extra_keys: Helper keys to uniquely specify the subroutine.
1921
+ """
1922
+ _active_builder().append_reference(name, *extra_keys)
1923
+
1924
+
1925
+ # Directives
1926
+ def barrier(*channels_or_qubits: chans.Channel | int, name: str | None = None):
1927
+ """Barrier directive for a set of channels and qubits.
1928
+
1929
+ This directive prevents the compiler from moving instructions across
1930
+ the barrier. Consider the case where we want to enforce that one pulse
1931
+ happens after another on separate channels, this can be done with:
1932
+
1933
+ .. code-block::
1934
+
1935
+ from qiskit import pulse
1936
+ from qiskit.providers.fake_provider import FakeOpenPulse2Q
1937
+
1938
+ backend = FakeOpenPulse2Q()
1939
+
1940
+ d0 = pulse.DriveChannel(0)
1941
+ d1 = pulse.DriveChannel(1)
1942
+
1943
+ with pulse.build(backend) as barrier_pulse_prog:
1944
+ pulse.play(pulse.Constant(10, 1.0), d0)
1945
+ pulse.barrier(d0, d1)
1946
+ pulse.play(pulse.Constant(10, 1.0), d1)
1947
+
1948
+ Of course this could have been accomplished with:
1949
+
1950
+ .. code-block::
1951
+
1952
+ from qiskit.pulse import transforms
1953
+
1954
+ with pulse.build(backend) as aligned_pulse_prog:
1955
+ with pulse.align_sequential():
1956
+ pulse.play(pulse.Constant(10, 1.0), d0)
1957
+ pulse.play(pulse.Constant(10, 1.0), d1)
1958
+
1959
+ barrier_pulse_prog = transforms.target_qobj_transform(barrier_pulse_prog)
1960
+ aligned_pulse_prog = transforms.target_qobj_transform(aligned_pulse_prog)
1961
+
1962
+ assert barrier_pulse_prog == aligned_pulse_prog
1963
+
1964
+ The barrier allows the pulse compiler to take care of more advanced
1965
+ scheduling alignment operations across channels. For example
1966
+ in the case where we are calling an outside circuit or schedule and
1967
+ want to align a pulse at the end of one call:
1968
+
1969
+ .. code-block::
1970
+
1971
+ import math
1972
+
1973
+ d0 = pulse.DriveChannel(0)
1974
+
1975
+ with pulse.build(backend) as pulse_prog:
1976
+ with pulse.align_right():
1977
+ pulse.call(backend.defaults.instruction_schedule_map.get('x', (1,)))
1978
+ # Barrier qubit 1 and d0.
1979
+ pulse.barrier(1, d0)
1980
+ # Due to barrier this will play before the gate on qubit 1.
1981
+ pulse.play(pulse.Constant(10, 1.0), d0)
1982
+ # This will end at the same time as the pulse above due to
1983
+ # the barrier.
1984
+ pulse.call(backend.defaults.instruction_schedule_map.get('x', (1,)))
1985
+
1986
+ .. note:: Requires the active builder context to have a backend set if
1987
+ qubits are barriered on.
1988
+
1989
+ Args:
1990
+ channels_or_qubits: Channels or qubits to barrier.
1991
+ name: Name for the barrier
1992
+ """
1993
+ channels = _qubits_to_channels(*channels_or_qubits)
1994
+ if len(channels) > 1:
1995
+ append_instruction(directives.RelativeBarrier(*channels, name=name))
1996
+
1997
+
1998
+ # Macros
1999
+ def macro(func: Callable):
2000
+ """Wrap a Python function and activate the parent builder context at calling time.
2001
+
2002
+ This enables embedding Python functions as builder macros. This generates a new
2003
+ :class:`pulse.Schedule` that is embedded in the parent builder context with
2004
+ every call of the decorated macro function. The decorated macro function will
2005
+ behave as if the function code was embedded inline in the parent builder context
2006
+ after parameter substitution.
2007
+
2008
+
2009
+ Examples:
2010
+
2011
+ .. plot::
2012
+ :include-source:
2013
+
2014
+ from qiskit import pulse
2015
+
2016
+ @pulse.macro
2017
+ def measure(qubit: int):
2018
+ pulse.play(pulse.GaussianSquare(16384, 256, 15872), pulse.measure_channel(qubit))
2019
+ mem_slot = pulse.MemorySlot(qubit)
2020
+ pulse.acquire(16384, pulse.acquire_channel(qubit), mem_slot)
2021
+
2022
+ return mem_slot
2023
+
2024
+ with pulse.build(backend=backend) as sched:
2025
+ mem_slot = measure(0)
2026
+ print(f"Qubit measured into {mem_slot}")
2027
+
2028
+ sched.draw()
2029
+
2030
+
2031
+ Args:
2032
+ func: The Python function to enable as a builder macro. There are no
2033
+ requirements on the signature of the function, any calls to pulse
2034
+ builder methods will be added to builder context the wrapped function
2035
+ is called from.
2036
+
2037
+ Returns:
2038
+ Callable: The wrapped ``func``.
2039
+ """
2040
+ func_name = getattr(func, "__name__", repr(func))
2041
+
2042
+ @functools.wraps(func)
2043
+ def wrapper(*args, **kwargs):
2044
+ _builder = _active_builder()
2045
+ # activate the pulse builder before calling the function
2046
+ with build(backend=_builder.backend, name=func_name) as built:
2047
+ output = func(*args, **kwargs)
2048
+
2049
+ _builder.call_subroutine(built)
2050
+ return output
2051
+
2052
+ return wrapper
2053
+
2054
+
2055
+ def measure(
2056
+ qubits: list[int] | int,
2057
+ registers: list[StorageLocation] | StorageLocation = None,
2058
+ ) -> list[StorageLocation] | StorageLocation:
2059
+ """Measure a qubit within the currently active builder context.
2060
+
2061
+ At the pulse level a measurement is composed of both a stimulus pulse and
2062
+ an acquisition instruction which tells the systems measurement unit to
2063
+ acquire data and process it. We provide this measurement macro to automate
2064
+ the process for you, but if desired full control is still available with
2065
+ :func:`acquire` and :func:`play`.
2066
+
2067
+ To use the measurement it is as simple as specifying the qubit you wish to
2068
+ measure:
2069
+
2070
+ .. code-block::
2071
+
2072
+ from qiskit import pulse
2073
+ from qiskit.providers.fake_provider import FakeOpenPulse2Q
2074
+
2075
+ backend = FakeOpenPulse2Q()
2076
+
2077
+ qubit = 0
2078
+
2079
+ with pulse.build(backend) as pulse_prog:
2080
+ # Do something to the qubit.
2081
+ qubit_drive_chan = pulse.drive_channel(0)
2082
+ pulse.play(pulse.Constant(100, 1.0), qubit_drive_chan)
2083
+ # Measure the qubit.
2084
+ reg = pulse.measure(qubit)
2085
+
2086
+ For now it is not possible to do much with the handle to ``reg`` but in the
2087
+ future we will support using this handle to a result register to build
2088
+ up ones program. It is also possible to supply this register:
2089
+
2090
+ .. code-block::
2091
+
2092
+ with pulse.build(backend) as pulse_prog:
2093
+ pulse.play(pulse.Constant(100, 1.0), qubit_drive_chan)
2094
+ # Measure the qubit.
2095
+ mem0 = pulse.MemorySlot(0)
2096
+ reg = pulse.measure(qubit, mem0)
2097
+
2098
+ assert reg == mem0
2099
+
2100
+ .. note:: Requires the active builder context to have a backend set.
2101
+
2102
+ Args:
2103
+ qubits: Physical qubit to measure.
2104
+ registers: Register to store result in. If not selected the current
2105
+ behavior is to return the :class:`MemorySlot` with the same
2106
+ index as ``qubit``. This register will be returned.
2107
+ Returns:
2108
+ The ``register`` the qubit measurement result will be stored in.
2109
+ """
2110
+ backend = active_backend()
2111
+
2112
+ try:
2113
+ qubits = list(qubits)
2114
+ except TypeError:
2115
+ qubits = [qubits]
2116
+
2117
+ if registers is None:
2118
+ registers = [chans.MemorySlot(qubit) for qubit in qubits]
2119
+ else:
2120
+ try:
2121
+ registers = list(registers)
2122
+ except TypeError:
2123
+ registers = [registers]
2124
+ measure_sched = macros.measure(
2125
+ qubits=qubits,
2126
+ backend=backend,
2127
+ qubit_mem_slots={qubit: register.index for qubit, register in zip(qubits, registers)},
2128
+ )
2129
+
2130
+ # note this is not a subroutine.
2131
+ # just a macro to automate combination of stimulus and acquisition.
2132
+ # prepare unique reference name based on qubit and memory slot index.
2133
+ qubits_repr = "&".join(map(str, qubits))
2134
+ mslots_repr = "&".join((str(r.index) for r in registers))
2135
+ _active_builder().call_subroutine(measure_sched, name=f"measure_{qubits_repr}..{mslots_repr}")
2136
+
2137
+ if len(qubits) == 1:
2138
+ return registers[0]
2139
+ else:
2140
+ return registers
2141
+
2142
+
2143
+ def measure_all() -> list[chans.MemorySlot]:
2144
+ r"""Measure all qubits within the currently active builder context.
2145
+
2146
+ A simple macro function to measure all of the qubits in the device at the
2147
+ same time. This is useful for handling device ``meas_map`` and single
2148
+ measurement constraints.
2149
+
2150
+ Examples:
2151
+
2152
+ .. code-block::
2153
+
2154
+ from qiskit import pulse
2155
+ from qiskit.providers.fake_provider import FakeOpenPulse2Q
2156
+
2157
+ backend = FakeOpenPulse2Q()
2158
+
2159
+ with pulse.build(backend) as pulse_prog:
2160
+ # Measure all qubits and return associated registers.
2161
+ regs = pulse.measure_all()
2162
+
2163
+ .. note::
2164
+ Requires the active builder context to have a backend set.
2165
+
2166
+ Returns:
2167
+ The ``register``\s the qubit measurement results will be stored in.
2168
+ """
2169
+ backend = active_backend()
2170
+ qubits = range(num_qubits())
2171
+ registers = [chans.MemorySlot(qubit) for qubit in qubits]
2172
+
2173
+ measure_sched = macros.measure(
2174
+ qubits=qubits,
2175
+ backend=backend,
2176
+ qubit_mem_slots={qubit: qubit for qubit in qubits},
2177
+ )
2178
+
2179
+ # note this is not a subroutine.
2180
+ # just a macro to automate combination of stimulus and acquisition.
2181
+ _active_builder().call_subroutine(measure_sched, name="measure_all")
2182
+
2183
+ return registers
2184
+
2185
+
2186
+ def delay_qubits(duration: int, *qubits: int):
2187
+ r"""Insert delays on all the :class:`channels.Channel`\s that correspond
2188
+ to the input ``qubits`` at the same time.
2189
+
2190
+ Examples:
2191
+
2192
+ .. code-block::
2193
+
2194
+ from qiskit import pulse
2195
+ from qiskit.providers.fake_provider import FakeOpenPulse3Q
2196
+
2197
+ backend = FakeOpenPulse3Q()
2198
+
2199
+ with pulse.build(backend) as pulse_prog:
2200
+ # Delay for 100 cycles on qubits 0, 1 and 2.
2201
+ regs = pulse.delay_qubits(100, 0, 1, 2)
2202
+
2203
+ .. note:: Requires the active builder context to have a backend set.
2204
+
2205
+ Args:
2206
+ duration: Duration to delay for.
2207
+ qubits: Physical qubits to delay on. Delays will be inserted based on
2208
+ the channels returned by :func:`pulse.qubit_channels`.
2209
+ """
2210
+ qubit_chans = set(itertools.chain.from_iterable(qubit_channels(qubit) for qubit in qubits))
2211
+ with align_left():
2212
+ for chan in qubit_chans:
2213
+ delay(duration, chan)