qiskit 1.0.0b1__cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (1095) hide show
  1. qiskit/VERSION.txt +1 -0
  2. qiskit/__init__.py +195 -0
  3. qiskit/_accelerate.abi3.so +0 -0
  4. qiskit/_qasm2.abi3.so +0 -0
  5. qiskit/assembler/__init__.py +47 -0
  6. qiskit/assembler/assemble_circuits.py +408 -0
  7. qiskit/assembler/assemble_schedules.py +372 -0
  8. qiskit/assembler/disassemble.py +318 -0
  9. qiskit/assembler/run_config.py +77 -0
  10. qiskit/circuit/__init__.py +425 -0
  11. qiskit/circuit/_classical_resource_map.py +144 -0
  12. qiskit/circuit/_utils.py +170 -0
  13. qiskit/circuit/add_control.py +274 -0
  14. qiskit/circuit/annotated_operation.py +188 -0
  15. qiskit/circuit/barrier.py +51 -0
  16. qiskit/circuit/bit.py +142 -0
  17. qiskit/circuit/classical/__init__.py +41 -0
  18. qiskit/circuit/classical/expr/__init__.py +218 -0
  19. qiskit/circuit/classical/expr/constructors.py +473 -0
  20. qiskit/circuit/classical/expr/expr.py +356 -0
  21. qiskit/circuit/classical/expr/visitors.py +280 -0
  22. qiskit/circuit/classical/types/__init__.py +108 -0
  23. qiskit/circuit/classical/types/ordering.py +222 -0
  24. qiskit/circuit/classical/types/types.py +117 -0
  25. qiskit/circuit/classicalfunction/__init__.py +131 -0
  26. qiskit/circuit/classicalfunction/boolean_expression.py +129 -0
  27. qiskit/circuit/classicalfunction/classical_element.py +54 -0
  28. qiskit/circuit/classicalfunction/classical_function_visitor.py +155 -0
  29. qiskit/circuit/classicalfunction/classicalfunction.py +173 -0
  30. qiskit/circuit/classicalfunction/exceptions.py +35 -0
  31. qiskit/circuit/classicalfunction/types.py +18 -0
  32. qiskit/circuit/classicalfunction/utils.py +91 -0
  33. qiskit/circuit/classicalregister.py +71 -0
  34. qiskit/circuit/commutation_checker.py +176 -0
  35. qiskit/circuit/controlflow/__init__.py +27 -0
  36. qiskit/circuit/controlflow/_builder_utils.py +199 -0
  37. qiskit/circuit/controlflow/break_loop.py +70 -0
  38. qiskit/circuit/controlflow/builder.py +651 -0
  39. qiskit/circuit/controlflow/continue_loop.py +72 -0
  40. qiskit/circuit/controlflow/control_flow.py +52 -0
  41. qiskit/circuit/controlflow/for_loop.py +232 -0
  42. qiskit/circuit/controlflow/if_else.py +517 -0
  43. qiskit/circuit/controlflow/switch_case.py +424 -0
  44. qiskit/circuit/controlflow/while_loop.py +177 -0
  45. qiskit/circuit/controlledgate.py +271 -0
  46. qiskit/circuit/delay.py +104 -0
  47. qiskit/circuit/duration.py +88 -0
  48. qiskit/circuit/equivalence.py +291 -0
  49. qiskit/circuit/equivalence_library.py +18 -0
  50. qiskit/circuit/exceptions.py +19 -0
  51. qiskit/circuit/gate.py +245 -0
  52. qiskit/circuit/instruction.py +655 -0
  53. qiskit/circuit/instructionset.py +191 -0
  54. qiskit/circuit/library/__init__.py +581 -0
  55. qiskit/circuit/library/arithmetic/__init__.py +27 -0
  56. qiskit/circuit/library/arithmetic/adders/__init__.py +17 -0
  57. qiskit/circuit/library/arithmetic/adders/adder.py +58 -0
  58. qiskit/circuit/library/arithmetic/adders/cdkm_ripple_carry_adder.py +159 -0
  59. qiskit/circuit/library/arithmetic/adders/draper_qft_adder.py +116 -0
  60. qiskit/circuit/library/arithmetic/adders/vbe_ripple_carry_adder.py +165 -0
  61. qiskit/circuit/library/arithmetic/exact_reciprocal.py +88 -0
  62. qiskit/circuit/library/arithmetic/functional_pauli_rotations.py +114 -0
  63. qiskit/circuit/library/arithmetic/integer_comparator.py +243 -0
  64. qiskit/circuit/library/arithmetic/linear_amplitude_function.py +196 -0
  65. qiskit/circuit/library/arithmetic/linear_pauli_rotations.py +189 -0
  66. qiskit/circuit/library/arithmetic/multipliers/__init__.py +16 -0
  67. qiskit/circuit/library/arithmetic/multipliers/hrs_cumulative_multiplier.py +138 -0
  68. qiskit/circuit/library/arithmetic/multipliers/multiplier.py +101 -0
  69. qiskit/circuit/library/arithmetic/multipliers/rg_qft_multiplier.py +101 -0
  70. qiskit/circuit/library/arithmetic/piecewise_chebyshev.py +353 -0
  71. qiskit/circuit/library/arithmetic/piecewise_linear_pauli_rotations.py +277 -0
  72. qiskit/circuit/library/arithmetic/piecewise_polynomial_pauli_rotations.py +317 -0
  73. qiskit/circuit/library/arithmetic/polynomial_pauli_rotations.py +335 -0
  74. qiskit/circuit/library/arithmetic/quadratic_form.py +197 -0
  75. qiskit/circuit/library/arithmetic/weighted_adder.py +337 -0
  76. qiskit/circuit/library/basis_change/__init__.py +15 -0
  77. qiskit/circuit/library/basis_change/qft.py +289 -0
  78. qiskit/circuit/library/blueprintcircuit.py +186 -0
  79. qiskit/circuit/library/boolean_logic/__init__.py +18 -0
  80. qiskit/circuit/library/boolean_logic/inner_product.py +78 -0
  81. qiskit/circuit/library/boolean_logic/quantum_and.py +97 -0
  82. qiskit/circuit/library/boolean_logic/quantum_or.py +98 -0
  83. qiskit/circuit/library/boolean_logic/quantum_xor.py +71 -0
  84. qiskit/circuit/library/data_preparation/__init__.py +47 -0
  85. qiskit/circuit/library/data_preparation/initializer.py +96 -0
  86. qiskit/circuit/library/data_preparation/pauli_feature_map.py +296 -0
  87. qiskit/circuit/library/data_preparation/state_preparation.py +526 -0
  88. qiskit/circuit/library/data_preparation/z_feature_map.py +104 -0
  89. qiskit/circuit/library/data_preparation/zz_feature_map.py +114 -0
  90. qiskit/circuit/library/evolved_operator_ansatz.py +245 -0
  91. qiskit/circuit/library/fourier_checking.py +97 -0
  92. qiskit/circuit/library/generalized_gates/__init__.py +30 -0
  93. qiskit/circuit/library/generalized_gates/diagonal.py +164 -0
  94. qiskit/circuit/library/generalized_gates/gms.py +121 -0
  95. qiskit/circuit/library/generalized_gates/gr.py +215 -0
  96. qiskit/circuit/library/generalized_gates/isometry.py +573 -0
  97. qiskit/circuit/library/generalized_gates/linear_function.py +302 -0
  98. qiskit/circuit/library/generalized_gates/mcg_up_to_diagonal.py +138 -0
  99. qiskit/circuit/library/generalized_gates/mcmt.py +254 -0
  100. qiskit/circuit/library/generalized_gates/pauli.py +85 -0
  101. qiskit/circuit/library/generalized_gates/permutation.py +190 -0
  102. qiskit/circuit/library/generalized_gates/rv.py +93 -0
  103. qiskit/circuit/library/generalized_gates/uc.py +304 -0
  104. qiskit/circuit/library/generalized_gates/uc_pauli_rot.py +164 -0
  105. qiskit/circuit/library/generalized_gates/ucrx.py +32 -0
  106. qiskit/circuit/library/generalized_gates/ucry.py +32 -0
  107. qiskit/circuit/library/generalized_gates/ucrz.py +32 -0
  108. qiskit/circuit/library/generalized_gates/unitary.py +198 -0
  109. qiskit/circuit/library/graph_state.py +86 -0
  110. qiskit/circuit/library/grover_operator.py +311 -0
  111. qiskit/circuit/library/hamiltonian_gate.py +146 -0
  112. qiskit/circuit/library/hidden_linear_function.py +98 -0
  113. qiskit/circuit/library/iqp.py +96 -0
  114. qiskit/circuit/library/n_local/__init__.py +31 -0
  115. qiskit/circuit/library/n_local/efficient_su2.py +162 -0
  116. qiskit/circuit/library/n_local/excitation_preserving.py +176 -0
  117. qiskit/circuit/library/n_local/n_local.py +1044 -0
  118. qiskit/circuit/library/n_local/pauli_two_design.py +131 -0
  119. qiskit/circuit/library/n_local/qaoa_ansatz.py +288 -0
  120. qiskit/circuit/library/n_local/real_amplitudes.py +189 -0
  121. qiskit/circuit/library/n_local/two_local.py +334 -0
  122. qiskit/circuit/library/overlap.py +111 -0
  123. qiskit/circuit/library/pauli_evolution.py +180 -0
  124. qiskit/circuit/library/phase_estimation.py +99 -0
  125. qiskit/circuit/library/phase_oracle.py +153 -0
  126. qiskit/circuit/library/quantum_volume.py +114 -0
  127. qiskit/circuit/library/standard_gates/__init__.py +116 -0
  128. qiskit/circuit/library/standard_gates/dcx.py +71 -0
  129. qiskit/circuit/library/standard_gates/ecr.py +114 -0
  130. qiskit/circuit/library/standard_gates/equivalence_library.py +1677 -0
  131. qiskit/circuit/library/standard_gates/global_phase.py +63 -0
  132. qiskit/circuit/library/standard_gates/h.py +224 -0
  133. qiskit/circuit/library/standard_gates/i.py +60 -0
  134. qiskit/circuit/library/standard_gates/iswap.py +129 -0
  135. qiskit/circuit/library/standard_gates/multi_control_rotation_gates.py +390 -0
  136. qiskit/circuit/library/standard_gates/p.py +364 -0
  137. qiskit/circuit/library/standard_gates/r.py +101 -0
  138. qiskit/circuit/library/standard_gates/rx.py +246 -0
  139. qiskit/circuit/library/standard_gates/rxx.py +128 -0
  140. qiskit/circuit/library/standard_gates/ry.py +241 -0
  141. qiskit/circuit/library/standard_gates/ryy.py +128 -0
  142. qiskit/circuit/library/standard_gates/rz.py +261 -0
  143. qiskit/circuit/library/standard_gates/rzx.py +174 -0
  144. qiskit/circuit/library/standard_gates/rzz.py +141 -0
  145. qiskit/circuit/library/standard_gates/s.py +303 -0
  146. qiskit/circuit/library/standard_gates/swap.py +246 -0
  147. qiskit/circuit/library/standard_gates/sx.py +268 -0
  148. qiskit/circuit/library/standard_gates/t.py +150 -0
  149. qiskit/circuit/library/standard_gates/u.py +338 -0
  150. qiskit/circuit/library/standard_gates/u1.py +383 -0
  151. qiskit/circuit/library/standard_gates/u2.py +132 -0
  152. qiskit/circuit/library/standard_gates/u3.py +358 -0
  153. qiskit/circuit/library/standard_gates/x.py +1370 -0
  154. qiskit/circuit/library/standard_gates/xx_minus_yy.py +179 -0
  155. qiskit/circuit/library/standard_gates/xx_plus_yy.py +180 -0
  156. qiskit/circuit/library/standard_gates/y.py +221 -0
  157. qiskit/circuit/library/standard_gates/z.py +294 -0
  158. qiskit/circuit/library/templates/__init__.py +92 -0
  159. qiskit/circuit/library/templates/clifford/__init__.py +33 -0
  160. qiskit/circuit/library/templates/clifford/clifford_2_1.py +33 -0
  161. qiskit/circuit/library/templates/clifford/clifford_2_2.py +34 -0
  162. qiskit/circuit/library/templates/clifford/clifford_2_3.py +32 -0
  163. qiskit/circuit/library/templates/clifford/clifford_2_4.py +33 -0
  164. qiskit/circuit/library/templates/clifford/clifford_3_1.py +34 -0
  165. qiskit/circuit/library/templates/clifford/clifford_4_1.py +37 -0
  166. qiskit/circuit/library/templates/clifford/clifford_4_2.py +36 -0
  167. qiskit/circuit/library/templates/clifford/clifford_4_3.py +37 -0
  168. qiskit/circuit/library/templates/clifford/clifford_4_4.py +36 -0
  169. qiskit/circuit/library/templates/clifford/clifford_5_1.py +39 -0
  170. qiskit/circuit/library/templates/clifford/clifford_6_1.py +39 -0
  171. qiskit/circuit/library/templates/clifford/clifford_6_2.py +39 -0
  172. qiskit/circuit/library/templates/clifford/clifford_6_3.py +39 -0
  173. qiskit/circuit/library/templates/clifford/clifford_6_4.py +37 -0
  174. qiskit/circuit/library/templates/clifford/clifford_6_5.py +39 -0
  175. qiskit/circuit/library/templates/clifford/clifford_8_1.py +41 -0
  176. qiskit/circuit/library/templates/clifford/clifford_8_2.py +41 -0
  177. qiskit/circuit/library/templates/clifford/clifford_8_3.py +40 -0
  178. qiskit/circuit/library/templates/nct/__init__.py +67 -0
  179. qiskit/circuit/library/templates/nct/template_nct_2a_1.py +32 -0
  180. qiskit/circuit/library/templates/nct/template_nct_2a_2.py +33 -0
  181. qiskit/circuit/library/templates/nct/template_nct_2a_3.py +35 -0
  182. qiskit/circuit/library/templates/nct/template_nct_4a_1.py +41 -0
  183. qiskit/circuit/library/templates/nct/template_nct_4a_2.py +39 -0
  184. qiskit/circuit/library/templates/nct/template_nct_4a_3.py +37 -0
  185. qiskit/circuit/library/templates/nct/template_nct_4b_1.py +39 -0
  186. qiskit/circuit/library/templates/nct/template_nct_4b_2.py +37 -0
  187. qiskit/circuit/library/templates/nct/template_nct_5a_1.py +38 -0
  188. qiskit/circuit/library/templates/nct/template_nct_5a_2.py +38 -0
  189. qiskit/circuit/library/templates/nct/template_nct_5a_3.py +38 -0
  190. qiskit/circuit/library/templates/nct/template_nct_5a_4.py +37 -0
  191. qiskit/circuit/library/templates/nct/template_nct_6a_1.py +38 -0
  192. qiskit/circuit/library/templates/nct/template_nct_6a_2.py +39 -0
  193. qiskit/circuit/library/templates/nct/template_nct_6a_3.py +39 -0
  194. qiskit/circuit/library/templates/nct/template_nct_6a_4.py +39 -0
  195. qiskit/circuit/library/templates/nct/template_nct_6b_1.py +39 -0
  196. qiskit/circuit/library/templates/nct/template_nct_6b_2.py +39 -0
  197. qiskit/circuit/library/templates/nct/template_nct_6c_1.py +39 -0
  198. qiskit/circuit/library/templates/nct/template_nct_7a_1.py +41 -0
  199. qiskit/circuit/library/templates/nct/template_nct_7b_1.py +41 -0
  200. qiskit/circuit/library/templates/nct/template_nct_7c_1.py +41 -0
  201. qiskit/circuit/library/templates/nct/template_nct_7d_1.py +41 -0
  202. qiskit/circuit/library/templates/nct/template_nct_7e_1.py +41 -0
  203. qiskit/circuit/library/templates/nct/template_nct_9a_1.py +43 -0
  204. qiskit/circuit/library/templates/nct/template_nct_9c_1.py +41 -0
  205. qiskit/circuit/library/templates/nct/template_nct_9c_10.py +42 -0
  206. qiskit/circuit/library/templates/nct/template_nct_9c_11.py +42 -0
  207. qiskit/circuit/library/templates/nct/template_nct_9c_12.py +42 -0
  208. qiskit/circuit/library/templates/nct/template_nct_9c_2.py +42 -0
  209. qiskit/circuit/library/templates/nct/template_nct_9c_3.py +42 -0
  210. qiskit/circuit/library/templates/nct/template_nct_9c_4.py +42 -0
  211. qiskit/circuit/library/templates/nct/template_nct_9c_5.py +42 -0
  212. qiskit/circuit/library/templates/nct/template_nct_9c_6.py +42 -0
  213. qiskit/circuit/library/templates/nct/template_nct_9c_7.py +42 -0
  214. qiskit/circuit/library/templates/nct/template_nct_9c_8.py +42 -0
  215. qiskit/circuit/library/templates/nct/template_nct_9c_9.py +42 -0
  216. qiskit/circuit/library/templates/nct/template_nct_9d_1.py +41 -0
  217. qiskit/circuit/library/templates/nct/template_nct_9d_10.py +42 -0
  218. qiskit/circuit/library/templates/nct/template_nct_9d_2.py +42 -0
  219. qiskit/circuit/library/templates/nct/template_nct_9d_3.py +42 -0
  220. qiskit/circuit/library/templates/nct/template_nct_9d_4.py +42 -0
  221. qiskit/circuit/library/templates/nct/template_nct_9d_5.py +42 -0
  222. qiskit/circuit/library/templates/nct/template_nct_9d_6.py +42 -0
  223. qiskit/circuit/library/templates/nct/template_nct_9d_7.py +42 -0
  224. qiskit/circuit/library/templates/nct/template_nct_9d_8.py +42 -0
  225. qiskit/circuit/library/templates/nct/template_nct_9d_9.py +42 -0
  226. qiskit/circuit/library/templates/rzx/__init__.py +25 -0
  227. qiskit/circuit/library/templates/rzx/rzx_cy.py +46 -0
  228. qiskit/circuit/library/templates/rzx/rzx_xz.py +53 -0
  229. qiskit/circuit/library/templates/rzx/rzx_yz.py +43 -0
  230. qiskit/circuit/library/templates/rzx/rzx_zz1.py +67 -0
  231. qiskit/circuit/library/templates/rzx/rzx_zz2.py +58 -0
  232. qiskit/circuit/library/templates/rzx/rzx_zz3.py +57 -0
  233. qiskit/circuit/measure.py +41 -0
  234. qiskit/circuit/operation.py +62 -0
  235. qiskit/circuit/parameter.py +160 -0
  236. qiskit/circuit/parameterexpression.py +515 -0
  237. qiskit/circuit/parametertable.py +263 -0
  238. qiskit/circuit/parametervector.py +114 -0
  239. qiskit/circuit/qpy_serialization.py +28 -0
  240. qiskit/circuit/quantumcircuit.py +6074 -0
  241. qiskit/circuit/quantumcircuitdata.py +138 -0
  242. qiskit/circuit/quantumregister.py +90 -0
  243. qiskit/circuit/random/__init__.py +15 -0
  244. qiskit/circuit/random/utils.py +209 -0
  245. qiskit/circuit/register.py +256 -0
  246. qiskit/circuit/reset.py +31 -0
  247. qiskit/circuit/singleton.py +604 -0
  248. qiskit/circuit/store.py +87 -0
  249. qiskit/circuit/tools/__init__.py +16 -0
  250. qiskit/circuit/tools/pi_check.py +190 -0
  251. qiskit/compiler/__init__.py +33 -0
  252. qiskit/compiler/assembler.py +597 -0
  253. qiskit/compiler/scheduler.py +107 -0
  254. qiskit/compiler/sequencer.py +69 -0
  255. qiskit/compiler/transpiler.py +613 -0
  256. qiskit/converters/__init__.py +59 -0
  257. qiskit/converters/circuit_to_dag.py +96 -0
  258. qiskit/converters/circuit_to_dagdependency.py +51 -0
  259. qiskit/converters/circuit_to_gate.py +109 -0
  260. qiskit/converters/circuit_to_instruction.py +131 -0
  261. qiskit/converters/dag_to_circuit.py +77 -0
  262. qiskit/converters/dag_to_dagdependency.py +55 -0
  263. qiskit/converters/dagdependency_to_circuit.py +42 -0
  264. qiskit/converters/dagdependency_to_dag.py +49 -0
  265. qiskit/dagcircuit/__init__.py +44 -0
  266. qiskit/dagcircuit/collect_blocks.py +386 -0
  267. qiskit/dagcircuit/dagcircuit.py +2105 -0
  268. qiskit/dagcircuit/dagdependency.py +626 -0
  269. qiskit/dagcircuit/dagdepnode.py +157 -0
  270. qiskit/dagcircuit/dagnode.py +322 -0
  271. qiskit/dagcircuit/exceptions.py +42 -0
  272. qiskit/exceptions.py +97 -0
  273. qiskit/execute_function.py +354 -0
  274. qiskit/extensions/__init__.py +70 -0
  275. qiskit/extensions/exceptions.py +31 -0
  276. qiskit/extensions/quantum_initializer/__init__.py +26 -0
  277. qiskit/extensions/quantum_initializer/squ.py +163 -0
  278. qiskit/extensions/simulator/__init__.py +15 -0
  279. qiskit/extensions/simulator/snapshot.py +70 -0
  280. qiskit/namespace.py +76 -0
  281. qiskit/passmanager/__init__.py +242 -0
  282. qiskit/passmanager/base_tasks.py +230 -0
  283. qiskit/passmanager/compilation_status.py +74 -0
  284. qiskit/passmanager/exceptions.py +19 -0
  285. qiskit/passmanager/flow_controllers.py +336 -0
  286. qiskit/passmanager/passmanager.py +317 -0
  287. qiskit/primitives/__init__.py +62 -0
  288. qiskit/primitives/backend_estimator.py +473 -0
  289. qiskit/primitives/backend_sampler.py +209 -0
  290. qiskit/primitives/base/__init__.py +20 -0
  291. qiskit/primitives/base/base_estimator.py +256 -0
  292. qiskit/primitives/base/base_primitive.py +74 -0
  293. qiskit/primitives/base/base_result.py +87 -0
  294. qiskit/primitives/base/base_sampler.py +202 -0
  295. qiskit/primitives/base/estimator_result.py +46 -0
  296. qiskit/primitives/base/sampler_result.py +45 -0
  297. qiskit/primitives/base/validation.py +231 -0
  298. qiskit/primitives/estimator.py +158 -0
  299. qiskit/primitives/primitive_job.py +73 -0
  300. qiskit/primitives/sampler.py +155 -0
  301. qiskit/primitives/utils.py +216 -0
  302. qiskit/providers/__init__.py +773 -0
  303. qiskit/providers/backend.py +653 -0
  304. qiskit/providers/backend_compat.py +347 -0
  305. qiskit/providers/basicaer/__init__.py +73 -0
  306. qiskit/providers/basicaer/basicaerjob.py +65 -0
  307. qiskit/providers/basicaer/basicaerprovider.py +127 -0
  308. qiskit/providers/basicaer/basicaertools.py +186 -0
  309. qiskit/providers/basicaer/exceptions.py +30 -0
  310. qiskit/providers/basicaer/qasm_simulator.py +678 -0
  311. qiskit/providers/basicaer/statevector_simulator.py +121 -0
  312. qiskit/providers/basicaer/unitary_simulator.py +395 -0
  313. qiskit/providers/exceptions.py +45 -0
  314. qiskit/providers/fake_provider/__init__.py +267 -0
  315. qiskit/providers/fake_provider/backends/__init__.py +110 -0
  316. qiskit/providers/fake_provider/backends/almaden/__init__.py +16 -0
  317. qiskit/providers/fake_provider/backends/almaden/conf_almaden.json +1 -0
  318. qiskit/providers/fake_provider/backends/almaden/fake_almaden.py +58 -0
  319. qiskit/providers/fake_provider/backends/almaden/props_almaden.json +1 -0
  320. qiskit/providers/fake_provider/backends/armonk/__init__.py +16 -0
  321. qiskit/providers/fake_provider/backends/armonk/conf_armonk.json +1 -0
  322. qiskit/providers/fake_provider/backends/armonk/defs_armonk.json +1 -0
  323. qiskit/providers/fake_provider/backends/armonk/fake_armonk.py +48 -0
  324. qiskit/providers/fake_provider/backends/armonk/props_armonk.json +1 -0
  325. qiskit/providers/fake_provider/backends/athens/__init__.py +16 -0
  326. qiskit/providers/fake_provider/backends/athens/conf_athens.json +1 -0
  327. qiskit/providers/fake_provider/backends/athens/defs_athens.json +1 -0
  328. qiskit/providers/fake_provider/backends/athens/fake_athens.py +38 -0
  329. qiskit/providers/fake_provider/backends/athens/props_athens.json +1 -0
  330. qiskit/providers/fake_provider/backends/auckland/__init__.py +15 -0
  331. qiskit/providers/fake_provider/backends/auckland/conf_auckland.json +1 -0
  332. qiskit/providers/fake_provider/backends/auckland/defs_auckland.json +1 -0
  333. qiskit/providers/fake_provider/backends/auckland/fake_auckland.py +29 -0
  334. qiskit/providers/fake_provider/backends/auckland/props_auckland.json +1 -0
  335. qiskit/providers/fake_provider/backends/belem/__init__.py +16 -0
  336. qiskit/providers/fake_provider/backends/belem/conf_belem.json +1 -0
  337. qiskit/providers/fake_provider/backends/belem/defs_belem.json +1 -0
  338. qiskit/providers/fake_provider/backends/belem/fake_belem.py +38 -0
  339. qiskit/providers/fake_provider/backends/belem/props_belem.json +1 -0
  340. qiskit/providers/fake_provider/backends/boeblingen/__init__.py +16 -0
  341. qiskit/providers/fake_provider/backends/boeblingen/conf_boeblingen.json +1 -0
  342. qiskit/providers/fake_provider/backends/boeblingen/defs_boeblingen.json +1 -0
  343. qiskit/providers/fake_provider/backends/boeblingen/fake_boeblingen.py +60 -0
  344. qiskit/providers/fake_provider/backends/boeblingen/props_boeblingen.json +1 -0
  345. qiskit/providers/fake_provider/backends/bogota/__init__.py +16 -0
  346. qiskit/providers/fake_provider/backends/bogota/conf_bogota.json +1 -0
  347. qiskit/providers/fake_provider/backends/bogota/defs_bogota.json +1 -0
  348. qiskit/providers/fake_provider/backends/bogota/fake_bogota.py +38 -0
  349. qiskit/providers/fake_provider/backends/bogota/props_bogota.json +1 -0
  350. qiskit/providers/fake_provider/backends/brooklyn/__init__.py +16 -0
  351. qiskit/providers/fake_provider/backends/brooklyn/conf_brooklyn.json +1 -0
  352. qiskit/providers/fake_provider/backends/brooklyn/defs_brooklyn.json +1 -0
  353. qiskit/providers/fake_provider/backends/brooklyn/fake_brooklyn.py +38 -0
  354. qiskit/providers/fake_provider/backends/brooklyn/props_brooklyn.json +1 -0
  355. qiskit/providers/fake_provider/backends/burlington/__init__.py +16 -0
  356. qiskit/providers/fake_provider/backends/burlington/conf_burlington.json +1 -0
  357. qiskit/providers/fake_provider/backends/burlington/fake_burlington.py +50 -0
  358. qiskit/providers/fake_provider/backends/burlington/props_burlington.json +1 -0
  359. qiskit/providers/fake_provider/backends/cairo/__init__.py +16 -0
  360. qiskit/providers/fake_provider/backends/cairo/conf_cairo.json +1 -0
  361. qiskit/providers/fake_provider/backends/cairo/defs_cairo.json +1 -0
  362. qiskit/providers/fake_provider/backends/cairo/fake_cairo.py +38 -0
  363. qiskit/providers/fake_provider/backends/cairo/props_cairo.json +1 -0
  364. qiskit/providers/fake_provider/backends/cambridge/__init__.py +17 -0
  365. qiskit/providers/fake_provider/backends/cambridge/conf_cambridge.json +1 -0
  366. qiskit/providers/fake_provider/backends/cambridge/fake_cambridge.py +72 -0
  367. qiskit/providers/fake_provider/backends/cambridge/props_cambridge.json +1 -0
  368. qiskit/providers/fake_provider/backends/cambridge/props_cambridge_alt.json +1 -0
  369. qiskit/providers/fake_provider/backends/casablanca/__init__.py +16 -0
  370. qiskit/providers/fake_provider/backends/casablanca/conf_casablanca.json +1 -0
  371. qiskit/providers/fake_provider/backends/casablanca/defs_casablanca.json +1 -0
  372. qiskit/providers/fake_provider/backends/casablanca/fake_casablanca.py +38 -0
  373. qiskit/providers/fake_provider/backends/casablanca/props_casablanca.json +1 -0
  374. qiskit/providers/fake_provider/backends/essex/__init__.py +16 -0
  375. qiskit/providers/fake_provider/backends/essex/conf_essex.json +1 -0
  376. qiskit/providers/fake_provider/backends/essex/fake_essex.py +54 -0
  377. qiskit/providers/fake_provider/backends/essex/props_essex.json +1 -0
  378. qiskit/providers/fake_provider/backends/geneva/__init__.py +15 -0
  379. qiskit/providers/fake_provider/backends/geneva/conf_geneva.json +1 -0
  380. qiskit/providers/fake_provider/backends/geneva/defs_geneva.json +1 -0
  381. qiskit/providers/fake_provider/backends/geneva/fake_geneva.py +29 -0
  382. qiskit/providers/fake_provider/backends/geneva/props_geneva.json +1 -0
  383. qiskit/providers/fake_provider/backends/guadalupe/__init__.py +16 -0
  384. qiskit/providers/fake_provider/backends/guadalupe/conf_guadalupe.json +1 -0
  385. qiskit/providers/fake_provider/backends/guadalupe/defs_guadalupe.json +1 -0
  386. qiskit/providers/fake_provider/backends/guadalupe/fake_guadalupe.py +39 -0
  387. qiskit/providers/fake_provider/backends/guadalupe/props_guadalupe.json +1 -0
  388. qiskit/providers/fake_provider/backends/hanoi/__init__.py +16 -0
  389. qiskit/providers/fake_provider/backends/hanoi/conf_hanoi.json +1 -0
  390. qiskit/providers/fake_provider/backends/hanoi/defs_hanoi.json +1 -0
  391. qiskit/providers/fake_provider/backends/hanoi/fake_hanoi.py +38 -0
  392. qiskit/providers/fake_provider/backends/hanoi/props_hanoi.json +1 -0
  393. qiskit/providers/fake_provider/backends/jakarta/__init__.py +16 -0
  394. qiskit/providers/fake_provider/backends/jakarta/conf_jakarta.json +1 -0
  395. qiskit/providers/fake_provider/backends/jakarta/defs_jakarta.json +1 -0
  396. qiskit/providers/fake_provider/backends/jakarta/fake_jakarta.py +38 -0
  397. qiskit/providers/fake_provider/backends/jakarta/props_jakarta.json +1 -0
  398. qiskit/providers/fake_provider/backends/johannesburg/__init__.py +16 -0
  399. qiskit/providers/fake_provider/backends/johannesburg/conf_johannesburg.json +1 -0
  400. qiskit/providers/fake_provider/backends/johannesburg/fake_johannesburg.py +58 -0
  401. qiskit/providers/fake_provider/backends/johannesburg/props_johannesburg.json +1 -0
  402. qiskit/providers/fake_provider/backends/kolkata/__init__.py +16 -0
  403. qiskit/providers/fake_provider/backends/kolkata/conf_kolkata.json +1 -0
  404. qiskit/providers/fake_provider/backends/kolkata/defs_kolkata.json +1 -0
  405. qiskit/providers/fake_provider/backends/kolkata/fake_kolkata.py +38 -0
  406. qiskit/providers/fake_provider/backends/kolkata/props_kolkata.json +1 -0
  407. qiskit/providers/fake_provider/backends/lagos/__init__.py +16 -0
  408. qiskit/providers/fake_provider/backends/lagos/conf_lagos.json +1 -0
  409. qiskit/providers/fake_provider/backends/lagos/defs_lagos.json +1 -0
  410. qiskit/providers/fake_provider/backends/lagos/fake_lagos.py +38 -0
  411. qiskit/providers/fake_provider/backends/lagos/props_lagos.json +1 -0
  412. qiskit/providers/fake_provider/backends/lima/__init__.py +16 -0
  413. qiskit/providers/fake_provider/backends/lima/conf_lima.json +1 -0
  414. qiskit/providers/fake_provider/backends/lima/defs_lima.json +1 -0
  415. qiskit/providers/fake_provider/backends/lima/fake_lima.py +38 -0
  416. qiskit/providers/fake_provider/backends/lima/props_lima.json +1 -0
  417. qiskit/providers/fake_provider/backends/london/__init__.py +16 -0
  418. qiskit/providers/fake_provider/backends/london/conf_london.json +1 -0
  419. qiskit/providers/fake_provider/backends/london/fake_london.py +54 -0
  420. qiskit/providers/fake_provider/backends/london/props_london.json +1 -0
  421. qiskit/providers/fake_provider/backends/manhattan/__init__.py +16 -0
  422. qiskit/providers/fake_provider/backends/manhattan/conf_manhattan.json +1 -0
  423. qiskit/providers/fake_provider/backends/manhattan/defs_manhattan.json +1 -0
  424. qiskit/providers/fake_provider/backends/manhattan/fake_manhattan.py +38 -0
  425. qiskit/providers/fake_provider/backends/manhattan/props_manhattan.json +1 -0
  426. qiskit/providers/fake_provider/backends/manila/__init__.py +16 -0
  427. qiskit/providers/fake_provider/backends/manila/conf_manila.json +1 -0
  428. qiskit/providers/fake_provider/backends/manila/defs_manila.json +1 -0
  429. qiskit/providers/fake_provider/backends/manila/fake_manila.py +38 -0
  430. qiskit/providers/fake_provider/backends/manila/props_manila.json +1 -0
  431. qiskit/providers/fake_provider/backends/melbourne/__init__.py +16 -0
  432. qiskit/providers/fake_provider/backends/melbourne/conf_melbourne.json +1 -0
  433. qiskit/providers/fake_provider/backends/melbourne/fake_melbourne.py +91 -0
  434. qiskit/providers/fake_provider/backends/melbourne/props_melbourne.json +1 -0
  435. qiskit/providers/fake_provider/backends/montreal/__init__.py +16 -0
  436. qiskit/providers/fake_provider/backends/montreal/conf_montreal.json +1 -0
  437. qiskit/providers/fake_provider/backends/montreal/defs_montreal.json +1 -0
  438. qiskit/providers/fake_provider/backends/montreal/fake_montreal.py +38 -0
  439. qiskit/providers/fake_provider/backends/montreal/props_montreal.json +1 -0
  440. qiskit/providers/fake_provider/backends/mumbai/__init__.py +16 -0
  441. qiskit/providers/fake_provider/backends/mumbai/conf_mumbai.json +1 -0
  442. qiskit/providers/fake_provider/backends/mumbai/defs_mumbai.json +1 -0
  443. qiskit/providers/fake_provider/backends/mumbai/fake_mumbai.py +38 -0
  444. qiskit/providers/fake_provider/backends/mumbai/props_mumbai.json +1 -0
  445. qiskit/providers/fake_provider/backends/nairobi/__init__.py +16 -0
  446. qiskit/providers/fake_provider/backends/nairobi/conf_nairobi.json +1 -0
  447. qiskit/providers/fake_provider/backends/nairobi/defs_nairobi.json +1 -0
  448. qiskit/providers/fake_provider/backends/nairobi/fake_nairobi.py +38 -0
  449. qiskit/providers/fake_provider/backends/nairobi/props_nairobi.json +1 -0
  450. qiskit/providers/fake_provider/backends/oslo/__init__.py +15 -0
  451. qiskit/providers/fake_provider/backends/oslo/conf_oslo.json +1 -0
  452. qiskit/providers/fake_provider/backends/oslo/defs_oslo.json +1 -0
  453. qiskit/providers/fake_provider/backends/oslo/fake_oslo.py +29 -0
  454. qiskit/providers/fake_provider/backends/oslo/props_oslo.json +1 -0
  455. qiskit/providers/fake_provider/backends/ourense/__init__.py +16 -0
  456. qiskit/providers/fake_provider/backends/ourense/conf_ourense.json +1 -0
  457. qiskit/providers/fake_provider/backends/ourense/fake_ourense.py +50 -0
  458. qiskit/providers/fake_provider/backends/ourense/props_ourense.json +1 -0
  459. qiskit/providers/fake_provider/backends/paris/__init__.py +16 -0
  460. qiskit/providers/fake_provider/backends/paris/conf_paris.json +1 -0
  461. qiskit/providers/fake_provider/backends/paris/defs_paris.json +1 -0
  462. qiskit/providers/fake_provider/backends/paris/fake_paris.py +64 -0
  463. qiskit/providers/fake_provider/backends/paris/props_paris.json +1 -0
  464. qiskit/providers/fake_provider/backends/perth/__init__.py +15 -0
  465. qiskit/providers/fake_provider/backends/perth/conf_perth.json +1 -0
  466. qiskit/providers/fake_provider/backends/perth/defs_perth.json +1 -0
  467. qiskit/providers/fake_provider/backends/perth/fake_perth.py +29 -0
  468. qiskit/providers/fake_provider/backends/perth/props_perth.json +1 -0
  469. qiskit/providers/fake_provider/backends/poughkeepsie/__init__.py +16 -0
  470. qiskit/providers/fake_provider/backends/poughkeepsie/conf_poughkeepsie.json +1 -0
  471. qiskit/providers/fake_provider/backends/poughkeepsie/defs_poughkeepsie.json +1 -0
  472. qiskit/providers/fake_provider/backends/poughkeepsie/fake_poughkeepsie.py +124 -0
  473. qiskit/providers/fake_provider/backends/poughkeepsie/props_poughkeepsie.json +1 -0
  474. qiskit/providers/fake_provider/backends/prague/__init__.py +15 -0
  475. qiskit/providers/fake_provider/backends/prague/conf_prague.json +1 -0
  476. qiskit/providers/fake_provider/backends/prague/fake_prague.py +28 -0
  477. qiskit/providers/fake_provider/backends/prague/props_prague.json +1 -0
  478. qiskit/providers/fake_provider/backends/quito/__init__.py +16 -0
  479. qiskit/providers/fake_provider/backends/quito/conf_quito.json +1 -0
  480. qiskit/providers/fake_provider/backends/quito/defs_quito.json +1 -0
  481. qiskit/providers/fake_provider/backends/quito/fake_quito.py +38 -0
  482. qiskit/providers/fake_provider/backends/quito/props_quito.json +1 -0
  483. qiskit/providers/fake_provider/backends/rochester/__init__.py +16 -0
  484. qiskit/providers/fake_provider/backends/rochester/conf_rochester.json +1 -0
  485. qiskit/providers/fake_provider/backends/rochester/fake_rochester.py +36 -0
  486. qiskit/providers/fake_provider/backends/rochester/props_rochester.json +1 -0
  487. qiskit/providers/fake_provider/backends/rome/__init__.py +16 -0
  488. qiskit/providers/fake_provider/backends/rome/conf_rome.json +1 -0
  489. qiskit/providers/fake_provider/backends/rome/defs_rome.json +1 -0
  490. qiskit/providers/fake_provider/backends/rome/fake_rome.py +38 -0
  491. qiskit/providers/fake_provider/backends/rome/props_rome.json +1 -0
  492. qiskit/providers/fake_provider/backends/rueschlikon/__init__.py +15 -0
  493. qiskit/providers/fake_provider/backends/rueschlikon/fake_rueschlikon.py +74 -0
  494. qiskit/providers/fake_provider/backends/santiago/__init__.py +16 -0
  495. qiskit/providers/fake_provider/backends/santiago/conf_santiago.json +1 -0
  496. qiskit/providers/fake_provider/backends/santiago/defs_santiago.json +1 -0
  497. qiskit/providers/fake_provider/backends/santiago/fake_santiago.py +38 -0
  498. qiskit/providers/fake_provider/backends/santiago/props_santiago.json +1 -0
  499. qiskit/providers/fake_provider/backends/sherbrooke/__init__.py +17 -0
  500. qiskit/providers/fake_provider/backends/sherbrooke/conf_sherbrooke.json +1 -0
  501. qiskit/providers/fake_provider/backends/sherbrooke/defs_sherbrooke.json +1 -0
  502. qiskit/providers/fake_provider/backends/sherbrooke/fake_sherbrooke.py +28 -0
  503. qiskit/providers/fake_provider/backends/sherbrooke/props_sherbrooke.json +1 -0
  504. qiskit/providers/fake_provider/backends/singapore/__init__.py +16 -0
  505. qiskit/providers/fake_provider/backends/singapore/conf_singapore.json +1 -0
  506. qiskit/providers/fake_provider/backends/singapore/fake_singapore.py +58 -0
  507. qiskit/providers/fake_provider/backends/singapore/props_singapore.json +1 -0
  508. qiskit/providers/fake_provider/backends/sydney/__init__.py +16 -0
  509. qiskit/providers/fake_provider/backends/sydney/conf_sydney.json +1 -0
  510. qiskit/providers/fake_provider/backends/sydney/defs_sydney.json +1 -0
  511. qiskit/providers/fake_provider/backends/sydney/fake_sydney.py +38 -0
  512. qiskit/providers/fake_provider/backends/sydney/props_sydney.json +1 -0
  513. qiskit/providers/fake_provider/backends/tenerife/__init__.py +15 -0
  514. qiskit/providers/fake_provider/backends/tenerife/fake_tenerife.py +64 -0
  515. qiskit/providers/fake_provider/backends/tenerife/props_tenerife.json +1 -0
  516. qiskit/providers/fake_provider/backends/tokyo/__init__.py +15 -0
  517. qiskit/providers/fake_provider/backends/tokyo/fake_tokyo.py +137 -0
  518. qiskit/providers/fake_provider/backends/tokyo/props_tokyo.json +1 -0
  519. qiskit/providers/fake_provider/backends/toronto/__init__.py +16 -0
  520. qiskit/providers/fake_provider/backends/toronto/conf_toronto.json +1 -0
  521. qiskit/providers/fake_provider/backends/toronto/defs_toronto.json +1 -0
  522. qiskit/providers/fake_provider/backends/toronto/fake_toronto.py +38 -0
  523. qiskit/providers/fake_provider/backends/toronto/props_toronto.json +1 -0
  524. qiskit/providers/fake_provider/backends/valencia/__init__.py +16 -0
  525. qiskit/providers/fake_provider/backends/valencia/conf_valencia.json +1 -0
  526. qiskit/providers/fake_provider/backends/valencia/defs_valencia.json +1 -0
  527. qiskit/providers/fake_provider/backends/valencia/fake_valencia.py +38 -0
  528. qiskit/providers/fake_provider/backends/valencia/props_valencia.json +1 -0
  529. qiskit/providers/fake_provider/backends/vigo/__init__.py +16 -0
  530. qiskit/providers/fake_provider/backends/vigo/conf_vigo.json +1 -0
  531. qiskit/providers/fake_provider/backends/vigo/fake_vigo.py +50 -0
  532. qiskit/providers/fake_provider/backends/vigo/props_vigo.json +1 -0
  533. qiskit/providers/fake_provider/backends/washington/__init__.py +18 -0
  534. qiskit/providers/fake_provider/backends/washington/conf_washington.json +1 -0
  535. qiskit/providers/fake_provider/backends/washington/defs_washington.json +1 -0
  536. qiskit/providers/fake_provider/backends/washington/fake_washington.py +38 -0
  537. qiskit/providers/fake_provider/backends/washington/props_washington.json +1 -0
  538. qiskit/providers/fake_provider/backends/yorktown/__init__.py +16 -0
  539. qiskit/providers/fake_provider/backends/yorktown/conf_yorktown.json +1 -0
  540. qiskit/providers/fake_provider/backends/yorktown/fake_yorktown.py +54 -0
  541. qiskit/providers/fake_provider/backends/yorktown/props_yorktown.json +1 -0
  542. qiskit/providers/fake_provider/fake_1q.py +91 -0
  543. qiskit/providers/fake_provider/fake_backend.py +572 -0
  544. qiskit/providers/fake_provider/fake_backend_v2.py +217 -0
  545. qiskit/providers/fake_provider/fake_job.py +81 -0
  546. qiskit/providers/fake_provider/fake_mumbai_v2.py +637 -0
  547. qiskit/providers/fake_provider/fake_openpulse_2q.py +342 -0
  548. qiskit/providers/fake_provider/fake_openpulse_3q.py +332 -0
  549. qiskit/providers/fake_provider/fake_provider.py +214 -0
  550. qiskit/providers/fake_provider/fake_pulse_backend.py +43 -0
  551. qiskit/providers/fake_provider/fake_qasm_backend.py +72 -0
  552. qiskit/providers/fake_provider/fake_qasm_simulator.py +48 -0
  553. qiskit/providers/fake_provider/fake_qobj.py +44 -0
  554. qiskit/providers/fake_provider/utils/__init__.py +15 -0
  555. qiskit/providers/fake_provider/utils/backend_converter.py +150 -0
  556. qiskit/providers/fake_provider/utils/configurable_backend.py +360 -0
  557. qiskit/providers/fake_provider/utils/json_decoder.py +109 -0
  558. qiskit/providers/job.py +142 -0
  559. qiskit/providers/jobstatus.py +30 -0
  560. qiskit/providers/models/__init__.py +52 -0
  561. qiskit/providers/models/backendconfiguration.py +994 -0
  562. qiskit/providers/models/backendproperties.py +490 -0
  563. qiskit/providers/models/backendstatus.py +94 -0
  564. qiskit/providers/models/jobstatus.py +66 -0
  565. qiskit/providers/models/pulsedefaults.py +304 -0
  566. qiskit/providers/options.py +273 -0
  567. qiskit/providers/provider.py +79 -0
  568. qiskit/providers/providerutils.py +99 -0
  569. qiskit/pulse/__init__.py +170 -0
  570. qiskit/pulse/builder.py +2733 -0
  571. qiskit/pulse/calibration_entries.py +357 -0
  572. qiskit/pulse/channels.py +221 -0
  573. qiskit/pulse/configuration.py +244 -0
  574. qiskit/pulse/exceptions.py +43 -0
  575. qiskit/pulse/filters.py +302 -0
  576. qiskit/pulse/instruction_schedule_map.py +406 -0
  577. qiskit/pulse/instructions/__init__.py +69 -0
  578. qiskit/pulse/instructions/acquire.py +150 -0
  579. qiskit/pulse/instructions/call.py +176 -0
  580. qiskit/pulse/instructions/delay.py +69 -0
  581. qiskit/pulse/instructions/directives.py +145 -0
  582. qiskit/pulse/instructions/frequency.py +132 -0
  583. qiskit/pulse/instructions/instruction.py +266 -0
  584. qiskit/pulse/instructions/phase.py +149 -0
  585. qiskit/pulse/instructions/play.py +96 -0
  586. qiskit/pulse/instructions/reference.py +99 -0
  587. qiskit/pulse/instructions/snapshot.py +80 -0
  588. qiskit/pulse/library/__init__.py +99 -0
  589. qiskit/pulse/library/continuous.py +430 -0
  590. qiskit/pulse/library/parametric_pulses.py +629 -0
  591. qiskit/pulse/library/pulse.py +137 -0
  592. qiskit/pulse/library/samplers/__init__.py +15 -0
  593. qiskit/pulse/library/samplers/decorators.py +299 -0
  594. qiskit/pulse/library/samplers/strategies.py +71 -0
  595. qiskit/pulse/library/symbolic_pulses.py +1962 -0
  596. qiskit/pulse/library/waveform.py +134 -0
  597. qiskit/pulse/macros.py +256 -0
  598. qiskit/pulse/parameter_manager.py +432 -0
  599. qiskit/pulse/parser.py +314 -0
  600. qiskit/pulse/reference_manager.py +58 -0
  601. qiskit/pulse/schedule.py +2002 -0
  602. qiskit/pulse/transforms/__init__.py +106 -0
  603. qiskit/pulse/transforms/alignments.py +406 -0
  604. qiskit/pulse/transforms/base_transforms.py +71 -0
  605. qiskit/pulse/transforms/canonicalization.py +514 -0
  606. qiskit/pulse/transforms/dag.py +107 -0
  607. qiskit/pulse/utils.py +109 -0
  608. qiskit/qasm/libs/qelib1.inc +266 -0
  609. qiskit/qasm/libs/stdgates.inc +75 -0
  610. qiskit/qasm2/__init__.py +658 -0
  611. qiskit/qasm2/exceptions.py +27 -0
  612. qiskit/qasm2/export.py +374 -0
  613. qiskit/qasm2/parse.py +403 -0
  614. qiskit/qasm3/__init__.py +255 -0
  615. qiskit/qasm3/ast.py +606 -0
  616. qiskit/qasm3/exceptions.py +27 -0
  617. qiskit/qasm3/experimental.py +30 -0
  618. qiskit/qasm3/exporter.py +1079 -0
  619. qiskit/qasm3/printer.py +545 -0
  620. qiskit/qobj/__init__.py +75 -0
  621. qiskit/qobj/common.py +71 -0
  622. qiskit/qobj/converters/__init__.py +18 -0
  623. qiskit/qobj/converters/lo_config.py +168 -0
  624. qiskit/qobj/converters/pulse_instruction.py +1070 -0
  625. qiskit/qobj/pulse_qobj.py +655 -0
  626. qiskit/qobj/qasm_qobj.py +656 -0
  627. qiskit/qobj/utils.py +37 -0
  628. qiskit/qpy/__init__.py +1348 -0
  629. qiskit/qpy/binary_io/__init__.py +36 -0
  630. qiskit/qpy/binary_io/circuits.py +1212 -0
  631. qiskit/qpy/binary_io/schedules.py +619 -0
  632. qiskit/qpy/binary_io/value.py +549 -0
  633. qiskit/qpy/common.py +305 -0
  634. qiskit/qpy/exceptions.py +28 -0
  635. qiskit/qpy/formats.py +360 -0
  636. qiskit/qpy/interface.py +308 -0
  637. qiskit/qpy/type_keys.py +544 -0
  638. qiskit/quantum_info/__init__.py +173 -0
  639. qiskit/quantum_info/analysis/__init__.py +17 -0
  640. qiskit/quantum_info/analysis/average.py +47 -0
  641. qiskit/quantum_info/analysis/distance.py +101 -0
  642. qiskit/quantum_info/analysis/make_observable.py +43 -0
  643. qiskit/quantum_info/analysis/z2_symmetries.py +483 -0
  644. qiskit/quantum_info/operators/__init__.py +28 -0
  645. qiskit/quantum_info/operators/base_operator.py +145 -0
  646. qiskit/quantum_info/operators/channel/__init__.py +29 -0
  647. qiskit/quantum_info/operators/channel/chi.py +190 -0
  648. qiskit/quantum_info/operators/channel/choi.py +217 -0
  649. qiskit/quantum_info/operators/channel/kraus.py +336 -0
  650. qiskit/quantum_info/operators/channel/ptm.py +203 -0
  651. qiskit/quantum_info/operators/channel/quantum_channel.py +350 -0
  652. qiskit/quantum_info/operators/channel/stinespring.py +295 -0
  653. qiskit/quantum_info/operators/channel/superop.py +376 -0
  654. qiskit/quantum_info/operators/channel/transformations.py +467 -0
  655. qiskit/quantum_info/operators/custom_iterator.py +48 -0
  656. qiskit/quantum_info/operators/dihedral/__init__.py +18 -0
  657. qiskit/quantum_info/operators/dihedral/dihedral.py +508 -0
  658. qiskit/quantum_info/operators/dihedral/dihedral_circuits.py +218 -0
  659. qiskit/quantum_info/operators/dihedral/polynomial.py +313 -0
  660. qiskit/quantum_info/operators/dihedral/random.py +61 -0
  661. qiskit/quantum_info/operators/linear_op.py +25 -0
  662. qiskit/quantum_info/operators/measures.py +423 -0
  663. qiskit/quantum_info/operators/mixins/__init__.py +52 -0
  664. qiskit/quantum_info/operators/mixins/adjoint.py +52 -0
  665. qiskit/quantum_info/operators/mixins/group.py +171 -0
  666. qiskit/quantum_info/operators/mixins/linear.py +84 -0
  667. qiskit/quantum_info/operators/mixins/multiply.py +62 -0
  668. qiskit/quantum_info/operators/mixins/tolerances.py +72 -0
  669. qiskit/quantum_info/operators/op_shape.py +533 -0
  670. qiskit/quantum_info/operators/operator.py +778 -0
  671. qiskit/quantum_info/operators/predicates.py +170 -0
  672. qiskit/quantum_info/operators/random.py +154 -0
  673. qiskit/quantum_info/operators/scalar_op.py +253 -0
  674. qiskit/quantum_info/operators/symplectic/__init__.py +23 -0
  675. qiskit/quantum_info/operators/symplectic/base_pauli.py +720 -0
  676. qiskit/quantum_info/operators/symplectic/clifford.py +1022 -0
  677. qiskit/quantum_info/operators/symplectic/clifford_circuits.py +558 -0
  678. qiskit/quantum_info/operators/symplectic/pauli.py +699 -0
  679. qiskit/quantum_info/operators/symplectic/pauli_list.py +1209 -0
  680. qiskit/quantum_info/operators/symplectic/pauli_utils.py +40 -0
  681. qiskit/quantum_info/operators/symplectic/random.py +264 -0
  682. qiskit/quantum_info/operators/symplectic/sparse_pauli_op.py +1156 -0
  683. qiskit/quantum_info/operators/utils/__init__.py +20 -0
  684. qiskit/quantum_info/operators/utils/anti_commutator.py +36 -0
  685. qiskit/quantum_info/operators/utils/commutator.py +36 -0
  686. qiskit/quantum_info/operators/utils/double_commutator.py +76 -0
  687. qiskit/quantum_info/random.py +26 -0
  688. qiskit/quantum_info/states/__init__.py +28 -0
  689. qiskit/quantum_info/states/densitymatrix.py +848 -0
  690. qiskit/quantum_info/states/measures.py +288 -0
  691. qiskit/quantum_info/states/quantum_state.py +503 -0
  692. qiskit/quantum_info/states/random.py +157 -0
  693. qiskit/quantum_info/states/stabilizerstate.py +638 -0
  694. qiskit/quantum_info/states/statevector.py +961 -0
  695. qiskit/quantum_info/states/utils.py +245 -0
  696. qiskit/quantum_info/synthesis/__init__.py +20 -0
  697. qiskit/quantum_info/synthesis/clifford_decompose.py +69 -0
  698. qiskit/quantum_info/synthesis/cnotdihedral_decompose.py +50 -0
  699. qiskit/quantum_info/synthesis/ion_decompose.py +55 -0
  700. qiskit/quantum_info/synthesis/local_invariance.py +93 -0
  701. qiskit/quantum_info/synthesis/one_qubit_decompose.py +284 -0
  702. qiskit/quantum_info/synthesis/qsd.py +269 -0
  703. qiskit/quantum_info/synthesis/quaternion.py +156 -0
  704. qiskit/quantum_info/synthesis/two_qubit_decompose.py +1567 -0
  705. qiskit/quantum_info/synthesis/weyl.py +98 -0
  706. qiskit/quantum_info/synthesis/xx_decompose/__init__.py +19 -0
  707. qiskit/quantum_info/synthesis/xx_decompose/circuits.py +299 -0
  708. qiskit/quantum_info/synthesis/xx_decompose/decomposer.py +314 -0
  709. qiskit/quantum_info/synthesis/xx_decompose/embodiments.py +163 -0
  710. qiskit/quantum_info/synthesis/xx_decompose/paths.py +412 -0
  711. qiskit/quantum_info/synthesis/xx_decompose/polytopes.py +264 -0
  712. qiskit/quantum_info/synthesis/xx_decompose/utilities.py +40 -0
  713. qiskit/quantum_info/synthesis/xx_decompose/weyl.py +133 -0
  714. qiskit/result/__init__.py +67 -0
  715. qiskit/result/counts.py +189 -0
  716. qiskit/result/distributions/__init__.py +17 -0
  717. qiskit/result/distributions/probability.py +100 -0
  718. qiskit/result/distributions/quasi.py +154 -0
  719. qiskit/result/exceptions.py +40 -0
  720. qiskit/result/mitigation/__init__.py +13 -0
  721. qiskit/result/mitigation/base_readout_mitigator.py +79 -0
  722. qiskit/result/mitigation/correlated_readout_mitigator.py +268 -0
  723. qiskit/result/mitigation/local_readout_mitigator.py +319 -0
  724. qiskit/result/mitigation/utils.py +161 -0
  725. qiskit/result/models.py +233 -0
  726. qiskit/result/postprocess.py +239 -0
  727. qiskit/result/result.py +397 -0
  728. qiskit/result/sampled_expval.py +75 -0
  729. qiskit/result/utils.py +295 -0
  730. qiskit/scheduler/__init__.py +31 -0
  731. qiskit/scheduler/config.py +35 -0
  732. qiskit/scheduler/lowering.py +187 -0
  733. qiskit/scheduler/methods/__init__.py +22 -0
  734. qiskit/scheduler/methods/basic.py +137 -0
  735. qiskit/scheduler/schedule_circuit.py +67 -0
  736. qiskit/scheduler/sequence.py +102 -0
  737. qiskit/synthesis/__init__.py +122 -0
  738. qiskit/synthesis/clifford/__init__.py +19 -0
  739. qiskit/synthesis/clifford/clifford_decompose_ag.py +176 -0
  740. qiskit/synthesis/clifford/clifford_decompose_bm.py +276 -0
  741. qiskit/synthesis/clifford/clifford_decompose_full.py +61 -0
  742. qiskit/synthesis/clifford/clifford_decompose_greedy.py +347 -0
  743. qiskit/synthesis/clifford/clifford_decompose_layers.py +443 -0
  744. qiskit/synthesis/cnotdihedral/__init__.py +17 -0
  745. qiskit/synthesis/cnotdihedral/cnotdihedral_decompose_full.py +46 -0
  746. qiskit/synthesis/cnotdihedral/cnotdihedral_decompose_general.py +140 -0
  747. qiskit/synthesis/cnotdihedral/cnotdihedral_decompose_two_qubits.py +264 -0
  748. qiskit/synthesis/discrete_basis/__init__.py +16 -0
  749. qiskit/synthesis/discrete_basis/commutator_decompose.py +241 -0
  750. qiskit/synthesis/discrete_basis/gate_sequence.py +415 -0
  751. qiskit/synthesis/discrete_basis/generate_basis_approximations.py +163 -0
  752. qiskit/synthesis/discrete_basis/solovay_kitaev.py +207 -0
  753. qiskit/synthesis/evolution/__init__.py +20 -0
  754. qiskit/synthesis/evolution/evolution_synthesis.py +46 -0
  755. qiskit/synthesis/evolution/lie_trotter.py +123 -0
  756. qiskit/synthesis/evolution/matrix_synthesis.py +47 -0
  757. qiskit/synthesis/evolution/product_formula.py +328 -0
  758. qiskit/synthesis/evolution/qdrift.py +102 -0
  759. qiskit/synthesis/evolution/suzuki_trotter.py +145 -0
  760. qiskit/synthesis/linear/__init__.py +25 -0
  761. qiskit/synthesis/linear/cnot_synth.py +141 -0
  762. qiskit/synthesis/linear/linear_circuits_utils.py +127 -0
  763. qiskit/synthesis/linear/linear_depth_lnn.py +275 -0
  764. qiskit/synthesis/linear/linear_matrix_utils.py +175 -0
  765. qiskit/synthesis/linear_phase/__init__.py +17 -0
  766. qiskit/synthesis/linear_phase/cnot_phase_synth.py +203 -0
  767. qiskit/synthesis/linear_phase/cx_cz_depth_lnn.py +262 -0
  768. qiskit/synthesis/linear_phase/cz_depth_lnn.py +206 -0
  769. qiskit/synthesis/permutation/__init__.py +17 -0
  770. qiskit/synthesis/permutation/permutation_full.py +90 -0
  771. qiskit/synthesis/permutation/permutation_lnn.py +68 -0
  772. qiskit/synthesis/permutation/permutation_utils.py +73 -0
  773. qiskit/synthesis/stabilizer/__init__.py +15 -0
  774. qiskit/synthesis/stabilizer/stabilizer_decompose.py +188 -0
  775. qiskit/test/__init__.py +18 -0
  776. qiskit/test/_canonical.py +125 -0
  777. qiskit/test/base.py +331 -0
  778. qiskit/test/decorators.py +308 -0
  779. qiskit/test/ibmq_mock.py +45 -0
  780. qiskit/test/mock/__init__.py +40 -0
  781. qiskit/test/mock/backends/__init__.py +32 -0
  782. qiskit/test/mock/backends/almaden/__init__.py +32 -0
  783. qiskit/test/mock/backends/armonk/__init__.py +32 -0
  784. qiskit/test/mock/backends/athens/__init__.py +32 -0
  785. qiskit/test/mock/backends/belem/__init__.py +32 -0
  786. qiskit/test/mock/backends/boeblingen/__init__.py +32 -0
  787. qiskit/test/mock/backends/bogota/__init__.py +32 -0
  788. qiskit/test/mock/backends/brooklyn/__init__.py +32 -0
  789. qiskit/test/mock/backends/burlington/__init__.py +32 -0
  790. qiskit/test/mock/backends/cairo/__init__.py +32 -0
  791. qiskit/test/mock/backends/cambridge/__init__.py +32 -0
  792. qiskit/test/mock/backends/casablanca/__init__.py +32 -0
  793. qiskit/test/mock/backends/essex/__init__.py +32 -0
  794. qiskit/test/mock/backends/guadalupe/__init__.py +32 -0
  795. qiskit/test/mock/backends/hanoi/__init__.py +32 -0
  796. qiskit/test/mock/backends/jakarta/__init__.py +32 -0
  797. qiskit/test/mock/backends/johannesburg/__init__.py +32 -0
  798. qiskit/test/mock/backends/kolkata/__init__.py +32 -0
  799. qiskit/test/mock/backends/lagos/__init__.py +32 -0
  800. qiskit/test/mock/backends/lima/__init__.py +32 -0
  801. qiskit/test/mock/backends/london/__init__.py +32 -0
  802. qiskit/test/mock/backends/manhattan/__init__.py +32 -0
  803. qiskit/test/mock/backends/manila/__init__.py +32 -0
  804. qiskit/test/mock/backends/melbourne/__init__.py +32 -0
  805. qiskit/test/mock/backends/montreal/__init__.py +32 -0
  806. qiskit/test/mock/backends/mumbai/__init__.py +32 -0
  807. qiskit/test/mock/backends/nairobi/__init__.py +32 -0
  808. qiskit/test/mock/backends/ourense/__init__.py +32 -0
  809. qiskit/test/mock/backends/paris/__init__.py +32 -0
  810. qiskit/test/mock/backends/poughkeepsie/__init__.py +32 -0
  811. qiskit/test/mock/backends/quito/__init__.py +32 -0
  812. qiskit/test/mock/backends/rochester/__init__.py +32 -0
  813. qiskit/test/mock/backends/rome/__init__.py +32 -0
  814. qiskit/test/mock/backends/rueschlikon/__init__.py +32 -0
  815. qiskit/test/mock/backends/santiago/__init__.py +32 -0
  816. qiskit/test/mock/backends/singapore/__init__.py +32 -0
  817. qiskit/test/mock/backends/sydney/__init__.py +32 -0
  818. qiskit/test/mock/backends/tenerife/__init__.py +32 -0
  819. qiskit/test/mock/backends/tokyo/__init__.py +32 -0
  820. qiskit/test/mock/backends/toronto/__init__.py +32 -0
  821. qiskit/test/mock/backends/valencia/__init__.py +32 -0
  822. qiskit/test/mock/backends/vigo/__init__.py +32 -0
  823. qiskit/test/mock/backends/washington/__init__.py +32 -0
  824. qiskit/test/mock/backends/yorktown/__init__.py +32 -0
  825. qiskit/test/providers/__init__.py +16 -0
  826. qiskit/test/providers/backend.py +75 -0
  827. qiskit/test/providers/provider.py +59 -0
  828. qiskit/test/reference_circuits.py +41 -0
  829. qiskit/test/testing_options.py +93 -0
  830. qiskit/test/utils.py +87 -0
  831. qiskit/tools/__init__.py +44 -0
  832. qiskit/tools/events/__init__.py +25 -0
  833. qiskit/tools/events/progressbar.py +195 -0
  834. qiskit/tools/events/pubsub.py +158 -0
  835. qiskit/tools/jupyter/__init__.py +138 -0
  836. qiskit/tools/jupyter/backend_monitor.py +588 -0
  837. qiskit/tools/jupyter/backend_overview.py +322 -0
  838. qiskit/tools/jupyter/copyright.py +42 -0
  839. qiskit/tools/jupyter/job_watcher.py +167 -0
  840. qiskit/tools/jupyter/job_widgets.py +160 -0
  841. qiskit/tools/jupyter/jupyter_magics.py +190 -0
  842. qiskit/tools/jupyter/library.py +189 -0
  843. qiskit/tools/jupyter/monospace.py +29 -0
  844. qiskit/tools/jupyter/progressbar.py +122 -0
  845. qiskit/tools/jupyter/version_table.py +67 -0
  846. qiskit/tools/jupyter/watcher_monitor.py +74 -0
  847. qiskit/tools/monitor/__init__.py +16 -0
  848. qiskit/tools/monitor/job_monitor.py +107 -0
  849. qiskit/tools/monitor/overview.py +247 -0
  850. qiskit/tools/parallel.py +198 -0
  851. qiskit/tools/visualization.py +16 -0
  852. qiskit/transpiler/__init__.py +1287 -0
  853. qiskit/transpiler/basepasses.py +221 -0
  854. qiskit/transpiler/coupling.py +500 -0
  855. qiskit/transpiler/exceptions.py +55 -0
  856. qiskit/transpiler/fencedobjs.py +78 -0
  857. qiskit/transpiler/instruction_durations.py +278 -0
  858. qiskit/transpiler/layout.py +658 -0
  859. qiskit/transpiler/passes/__init__.py +296 -0
  860. qiskit/transpiler/passes/analysis/__init__.py +23 -0
  861. qiskit/transpiler/passes/analysis/count_ops.py +30 -0
  862. qiskit/transpiler/passes/analysis/count_ops_longest_path.py +26 -0
  863. qiskit/transpiler/passes/analysis/dag_longest_path.py +24 -0
  864. qiskit/transpiler/passes/analysis/depth.py +33 -0
  865. qiskit/transpiler/passes/analysis/num_qubits.py +26 -0
  866. qiskit/transpiler/passes/analysis/num_tensor_factors.py +26 -0
  867. qiskit/transpiler/passes/analysis/resource_estimation.py +41 -0
  868. qiskit/transpiler/passes/analysis/size.py +36 -0
  869. qiskit/transpiler/passes/analysis/width.py +27 -0
  870. qiskit/transpiler/passes/basis/__init__.py +20 -0
  871. qiskit/transpiler/passes/basis/basis_translator.py +697 -0
  872. qiskit/transpiler/passes/basis/decompose.py +98 -0
  873. qiskit/transpiler/passes/basis/translate_parameterized.py +177 -0
  874. qiskit/transpiler/passes/basis/unroll_3q_or_more.py +86 -0
  875. qiskit/transpiler/passes/basis/unroll_custom_definitions.py +107 -0
  876. qiskit/transpiler/passes/basis/unroller.py +145 -0
  877. qiskit/transpiler/passes/calibration/__init__.py +17 -0
  878. qiskit/transpiler/passes/calibration/base_builder.py +79 -0
  879. qiskit/transpiler/passes/calibration/builders.py +20 -0
  880. qiskit/transpiler/passes/calibration/exceptions.py +22 -0
  881. qiskit/transpiler/passes/calibration/pulse_gate.py +98 -0
  882. qiskit/transpiler/passes/calibration/rx_builder.py +160 -0
  883. qiskit/transpiler/passes/calibration/rzx_builder.py +394 -0
  884. qiskit/transpiler/passes/calibration/rzx_templates.py +51 -0
  885. qiskit/transpiler/passes/layout/__init__.py +27 -0
  886. qiskit/transpiler/passes/layout/_csp_custom_solver.py +65 -0
  887. qiskit/transpiler/passes/layout/apply_layout.py +108 -0
  888. qiskit/transpiler/passes/layout/csp_layout.py +132 -0
  889. qiskit/transpiler/passes/layout/dense_layout.py +202 -0
  890. qiskit/transpiler/passes/layout/disjoint_utils.py +205 -0
  891. qiskit/transpiler/passes/layout/enlarge_with_ancilla.py +49 -0
  892. qiskit/transpiler/passes/layout/full_ancilla_allocation.py +117 -0
  893. qiskit/transpiler/passes/layout/layout_2q_distance.py +77 -0
  894. qiskit/transpiler/passes/layout/noise_adaptive_layout.py +311 -0
  895. qiskit/transpiler/passes/layout/sabre_layout.py +468 -0
  896. qiskit/transpiler/passes/layout/sabre_pre_layout.py +217 -0
  897. qiskit/transpiler/passes/layout/set_layout.py +64 -0
  898. qiskit/transpiler/passes/layout/trivial_layout.py +66 -0
  899. qiskit/transpiler/passes/layout/vf2_layout.py +257 -0
  900. qiskit/transpiler/passes/layout/vf2_post_layout.py +419 -0
  901. qiskit/transpiler/passes/layout/vf2_utils.py +260 -0
  902. qiskit/transpiler/passes/optimization/__init__.py +38 -0
  903. qiskit/transpiler/passes/optimization/_gate_extension.py +80 -0
  904. qiskit/transpiler/passes/optimization/collect_1q_runs.py +31 -0
  905. qiskit/transpiler/passes/optimization/collect_2q_blocks.py +35 -0
  906. qiskit/transpiler/passes/optimization/collect_and_collapse.py +115 -0
  907. qiskit/transpiler/passes/optimization/collect_cliffords.py +97 -0
  908. qiskit/transpiler/passes/optimization/collect_linear_functions.py +80 -0
  909. qiskit/transpiler/passes/optimization/collect_multiqubit_blocks.py +227 -0
  910. qiskit/transpiler/passes/optimization/commutation_analysis.py +93 -0
  911. qiskit/transpiler/passes/optimization/commutative_cancellation.py +207 -0
  912. qiskit/transpiler/passes/optimization/commutative_inverse_cancellation.py +97 -0
  913. qiskit/transpiler/passes/optimization/consolidate_blocks.py +219 -0
  914. qiskit/transpiler/passes/optimization/crosstalk_adaptive_schedule.py +732 -0
  915. qiskit/transpiler/passes/optimization/cx_cancellation.py +55 -0
  916. qiskit/transpiler/passes/optimization/echo_rzx_weyl_decomposition.py +160 -0
  917. qiskit/transpiler/passes/optimization/hoare_opt.py +416 -0
  918. qiskit/transpiler/passes/optimization/inverse_cancellation.py +177 -0
  919. qiskit/transpiler/passes/optimization/normalize_rx_angle.py +149 -0
  920. qiskit/transpiler/passes/optimization/optimize_1q_commutation.py +268 -0
  921. qiskit/transpiler/passes/optimization/optimize_1q_decomposition.py +263 -0
  922. qiskit/transpiler/passes/optimization/optimize_1q_gates.py +384 -0
  923. qiskit/transpiler/passes/optimization/optimize_cliffords.py +89 -0
  924. qiskit/transpiler/passes/optimization/optimize_swap_before_measure.py +71 -0
  925. qiskit/transpiler/passes/optimization/remove_diagonal_gates_before_measure.py +69 -0
  926. qiskit/transpiler/passes/optimization/remove_reset_in_zero_state.py +37 -0
  927. qiskit/transpiler/passes/optimization/reset_after_measure_simplification.py +47 -0
  928. qiskit/transpiler/passes/optimization/template_matching/__init__.py +19 -0
  929. qiskit/transpiler/passes/optimization/template_matching/backward_match.py +749 -0
  930. qiskit/transpiler/passes/optimization/template_matching/forward_match.py +454 -0
  931. qiskit/transpiler/passes/optimization/template_matching/maximal_matches.py +77 -0
  932. qiskit/transpiler/passes/optimization/template_matching/template_matching.py +370 -0
  933. qiskit/transpiler/passes/optimization/template_matching/template_substitution.py +629 -0
  934. qiskit/transpiler/passes/optimization/template_optimization.py +158 -0
  935. qiskit/transpiler/passes/routing/__init__.py +21 -0
  936. qiskit/transpiler/passes/routing/algorithms/__init__.py +33 -0
  937. qiskit/transpiler/passes/routing/algorithms/token_swapper.py +105 -0
  938. qiskit/transpiler/passes/routing/algorithms/types.py +46 -0
  939. qiskit/transpiler/passes/routing/algorithms/util.py +103 -0
  940. qiskit/transpiler/passes/routing/basic_swap.py +155 -0
  941. qiskit/transpiler/passes/routing/commuting_2q_gate_routing/__init__.py +25 -0
  942. qiskit/transpiler/passes/routing/commuting_2q_gate_routing/commuting_2q_block.py +60 -0
  943. qiskit/transpiler/passes/routing/commuting_2q_gate_routing/commuting_2q_gate_router.py +387 -0
  944. qiskit/transpiler/passes/routing/commuting_2q_gate_routing/pauli_2q_evolution_commutation.py +141 -0
  945. qiskit/transpiler/passes/routing/commuting_2q_gate_routing/swap_strategy.py +306 -0
  946. qiskit/transpiler/passes/routing/layout_transformation.py +118 -0
  947. qiskit/transpiler/passes/routing/lookahead_swap.py +384 -0
  948. qiskit/transpiler/passes/routing/sabre_swap.py +430 -0
  949. qiskit/transpiler/passes/routing/stochastic_swap.py +512 -0
  950. qiskit/transpiler/passes/routing/utils.py +35 -0
  951. qiskit/transpiler/passes/scheduling/__init__.py +27 -0
  952. qiskit/transpiler/passes/scheduling/alap.py +155 -0
  953. qiskit/transpiler/passes/scheduling/alignments/__init__.py +81 -0
  954. qiskit/transpiler/passes/scheduling/alignments/align_measures.py +256 -0
  955. qiskit/transpiler/passes/scheduling/alignments/check_durations.py +75 -0
  956. qiskit/transpiler/passes/scheduling/alignments/pulse_gate_validation.py +97 -0
  957. qiskit/transpiler/passes/scheduling/alignments/reschedule.py +241 -0
  958. qiskit/transpiler/passes/scheduling/asap.py +177 -0
  959. qiskit/transpiler/passes/scheduling/base_scheduler.py +289 -0
  960. qiskit/transpiler/passes/scheduling/calibration_creators.py +27 -0
  961. qiskit/transpiler/passes/scheduling/dynamical_decoupling.py +285 -0
  962. qiskit/transpiler/passes/scheduling/padding/__init__.py +16 -0
  963. qiskit/transpiler/passes/scheduling/padding/base_padding.py +256 -0
  964. qiskit/transpiler/passes/scheduling/padding/dynamical_decoupling.py +408 -0
  965. qiskit/transpiler/passes/scheduling/padding/pad_delay.py +79 -0
  966. qiskit/transpiler/passes/scheduling/rzx_templates.py +28 -0
  967. qiskit/transpiler/passes/scheduling/scheduling/__init__.py +17 -0
  968. qiskit/transpiler/passes/scheduling/scheduling/alap.py +127 -0
  969. qiskit/transpiler/passes/scheduling/scheduling/asap.py +131 -0
  970. qiskit/transpiler/passes/scheduling/scheduling/base_scheduler.py +89 -0
  971. qiskit/transpiler/passes/scheduling/scheduling/set_io_latency.py +64 -0
  972. qiskit/transpiler/passes/scheduling/time_unit_conversion.py +135 -0
  973. qiskit/transpiler/passes/synthesis/__init__.py +19 -0
  974. qiskit/transpiler/passes/synthesis/high_level_synthesis.py +637 -0
  975. qiskit/transpiler/passes/synthesis/linear_functions_synthesis.py +63 -0
  976. qiskit/transpiler/passes/synthesis/plugin.py +597 -0
  977. qiskit/transpiler/passes/synthesis/solovay_kitaev_synthesis.py +289 -0
  978. qiskit/transpiler/passes/synthesis/unitary_synthesis.py +895 -0
  979. qiskit/transpiler/passes/utils/__init__.py +34 -0
  980. qiskit/transpiler/passes/utils/barrier_before_final_measurements.py +95 -0
  981. qiskit/transpiler/passes/utils/block_to_matrix.py +47 -0
  982. qiskit/transpiler/passes/utils/check_gate_direction.py +87 -0
  983. qiskit/transpiler/passes/utils/check_map.py +94 -0
  984. qiskit/transpiler/passes/utils/contains_instruction.py +45 -0
  985. qiskit/transpiler/passes/utils/control_flow.py +61 -0
  986. qiskit/transpiler/passes/utils/convert_conditions_to_if_ops.py +89 -0
  987. qiskit/transpiler/passes/utils/dag_fixed_point.py +36 -0
  988. qiskit/transpiler/passes/utils/error.py +69 -0
  989. qiskit/transpiler/passes/utils/filter_op_nodes.py +65 -0
  990. qiskit/transpiler/passes/utils/fixed_point.py +48 -0
  991. qiskit/transpiler/passes/utils/gate_direction.py +347 -0
  992. qiskit/transpiler/passes/utils/gates_basis.py +75 -0
  993. qiskit/transpiler/passes/utils/merge_adjacent_barriers.py +162 -0
  994. qiskit/transpiler/passes/utils/minimum_point.py +118 -0
  995. qiskit/transpiler/passes/utils/remove_barriers.py +49 -0
  996. qiskit/transpiler/passes/utils/remove_final_measurements.py +114 -0
  997. qiskit/transpiler/passes/utils/unroll_forloops.py +81 -0
  998. qiskit/transpiler/passmanager.py +617 -0
  999. qiskit/transpiler/passmanager_config.py +193 -0
  1000. qiskit/transpiler/preset_passmanagers/__init__.py +280 -0
  1001. qiskit/transpiler/preset_passmanagers/builtin_plugins.py +971 -0
  1002. qiskit/transpiler/preset_passmanagers/common.py +651 -0
  1003. qiskit/transpiler/preset_passmanagers/level0.py +113 -0
  1004. qiskit/transpiler/preset_passmanagers/level1.py +120 -0
  1005. qiskit/transpiler/preset_passmanagers/level2.py +119 -0
  1006. qiskit/transpiler/preset_passmanagers/level3.py +119 -0
  1007. qiskit/transpiler/preset_passmanagers/plugin.py +345 -0
  1008. qiskit/transpiler/propertyset.py +19 -0
  1009. qiskit/transpiler/runningpassmanager.py +174 -0
  1010. qiskit/transpiler/synthesis/__init__.py +16 -0
  1011. qiskit/transpiler/synthesis/aqc/__init__.py +178 -0
  1012. qiskit/transpiler/synthesis/aqc/approximate.py +116 -0
  1013. qiskit/transpiler/synthesis/aqc/aqc.py +170 -0
  1014. qiskit/transpiler/synthesis/aqc/aqc_plugin.py +146 -0
  1015. qiskit/transpiler/synthesis/aqc/cnot_structures.py +299 -0
  1016. qiskit/transpiler/synthesis/aqc/cnot_unit_circuit.py +103 -0
  1017. qiskit/transpiler/synthesis/aqc/cnot_unit_objective.py +299 -0
  1018. qiskit/transpiler/synthesis/aqc/elementary_operations.py +108 -0
  1019. qiskit/transpiler/synthesis/aqc/fast_gradient/__init__.py +164 -0
  1020. qiskit/transpiler/synthesis/aqc/fast_gradient/fast_grad_utils.py +237 -0
  1021. qiskit/transpiler/synthesis/aqc/fast_gradient/fast_gradient.py +225 -0
  1022. qiskit/transpiler/synthesis/aqc/fast_gradient/layer.py +370 -0
  1023. qiskit/transpiler/synthesis/aqc/fast_gradient/pmatrix.py +312 -0
  1024. qiskit/transpiler/synthesis/graysynth.py +114 -0
  1025. qiskit/transpiler/target.py +1540 -0
  1026. qiskit/transpiler/timing_constraints.py +59 -0
  1027. qiskit/user_config.py +239 -0
  1028. qiskit/utils/__init__.py +66 -0
  1029. qiskit/utils/classtools.py +146 -0
  1030. qiskit/utils/deprecation.py +489 -0
  1031. qiskit/utils/lazy_tester.py +334 -0
  1032. qiskit/utils/multiprocessing.py +48 -0
  1033. qiskit/utils/optionals.py +320 -0
  1034. qiskit/utils/units.py +143 -0
  1035. qiskit/version.py +84 -0
  1036. qiskit/visualization/__init__.py +289 -0
  1037. qiskit/visualization/array.py +204 -0
  1038. qiskit/visualization/bloch.py +741 -0
  1039. qiskit/visualization/circuit/__init__.py +15 -0
  1040. qiskit/visualization/circuit/_utils.py +633 -0
  1041. qiskit/visualization/circuit/circuit_visualization.py +717 -0
  1042. qiskit/visualization/circuit/latex.py +659 -0
  1043. qiskit/visualization/circuit/matplotlib.py +1975 -0
  1044. qiskit/visualization/circuit/qcstyle.py +420 -0
  1045. qiskit/visualization/circuit/styles/bw.json +202 -0
  1046. qiskit/visualization/circuit/styles/clifford.json +202 -0
  1047. qiskit/visualization/circuit/styles/iqp-dark.json +214 -0
  1048. qiskit/visualization/circuit/styles/iqp.json +214 -0
  1049. qiskit/visualization/circuit/styles/textbook.json +202 -0
  1050. qiskit/visualization/circuit/text.py +1802 -0
  1051. qiskit/visualization/circuit_visualization.py +19 -0
  1052. qiskit/visualization/counts_visualization.py +496 -0
  1053. qiskit/visualization/dag_visualization.py +224 -0
  1054. qiskit/visualization/exceptions.py +21 -0
  1055. qiskit/visualization/gate_map.py +1461 -0
  1056. qiskit/visualization/pass_manager_visualization.py +281 -0
  1057. qiskit/visualization/pulse_v2/__init__.py +21 -0
  1058. qiskit/visualization/pulse_v2/core.py +905 -0
  1059. qiskit/visualization/pulse_v2/device_info.py +146 -0
  1060. qiskit/visualization/pulse_v2/drawings.py +253 -0
  1061. qiskit/visualization/pulse_v2/events.py +254 -0
  1062. qiskit/visualization/pulse_v2/generators/__init__.py +40 -0
  1063. qiskit/visualization/pulse_v2/generators/barrier.py +76 -0
  1064. qiskit/visualization/pulse_v2/generators/chart.py +208 -0
  1065. qiskit/visualization/pulse_v2/generators/frame.py +437 -0
  1066. qiskit/visualization/pulse_v2/generators/snapshot.py +133 -0
  1067. qiskit/visualization/pulse_v2/generators/waveform.py +649 -0
  1068. qiskit/visualization/pulse_v2/interface.py +452 -0
  1069. qiskit/visualization/pulse_v2/layouts.py +395 -0
  1070. qiskit/visualization/pulse_v2/plotters/__init__.py +17 -0
  1071. qiskit/visualization/pulse_v2/plotters/base_plotter.py +53 -0
  1072. qiskit/visualization/pulse_v2/plotters/matplotlib.py +202 -0
  1073. qiskit/visualization/pulse_v2/stylesheet.py +322 -0
  1074. qiskit/visualization/pulse_v2/types.py +242 -0
  1075. qiskit/visualization/qcstyle.py +17 -0
  1076. qiskit/visualization/state_visualization.py +1518 -0
  1077. qiskit/visualization/timeline/__init__.py +21 -0
  1078. qiskit/visualization/timeline/core.py +457 -0
  1079. qiskit/visualization/timeline/drawings.py +260 -0
  1080. qiskit/visualization/timeline/generators.py +506 -0
  1081. qiskit/visualization/timeline/interface.py +414 -0
  1082. qiskit/visualization/timeline/layouts.py +115 -0
  1083. qiskit/visualization/timeline/plotters/__init__.py +16 -0
  1084. qiskit/visualization/timeline/plotters/base_plotter.py +58 -0
  1085. qiskit/visualization/timeline/plotters/matplotlib.py +193 -0
  1086. qiskit/visualization/timeline/stylesheet.py +311 -0
  1087. qiskit/visualization/timeline/types.py +148 -0
  1088. qiskit/visualization/transition_visualization.py +364 -0
  1089. qiskit/visualization/utils.py +49 -0
  1090. qiskit-1.0.0b1.dist-info/LICENSE.txt +203 -0
  1091. qiskit-1.0.0b1.dist-info/METADATA +430 -0
  1092. qiskit-1.0.0b1.dist-info/RECORD +1095 -0
  1093. qiskit-1.0.0b1.dist-info/WHEEL +6 -0
  1094. qiskit-1.0.0b1.dist-info/entry_points.txt +49 -0
  1095. qiskit-1.0.0b1.dist-info/top_level.txt +1 -0
@@ -0,0 +1,2733 @@
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 execute, 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 executed like a
78
+ normal Qiskit schedule using ``qiskit.execute(pulse_prog, backend)``.
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
+ import math
96
+
97
+ from qiskit import pulse
98
+ from qiskit.providers.fake_provider import FakeOpenPulse3Q
99
+
100
+ # TODO: This example should use a real mock backend.
101
+ backend = FakeOpenPulse3Q()
102
+
103
+ d2 = pulse.DriveChannel(2)
104
+
105
+ with pulse.build(backend) as bell_prep:
106
+ pulse.u2(0, math.pi, 0)
107
+ pulse.cx(0, 1)
108
+
109
+ with pulse.build(backend) as decoupled_bell_prep_and_measure:
110
+ # We call our bell state preparation schedule constructed above.
111
+ with pulse.align_right():
112
+ pulse.call(bell_prep)
113
+ pulse.play(pulse.Constant(bell_prep.duration, 0.02), d2)
114
+ pulse.barrier(0, 1, 2)
115
+ registers = pulse.measure_all()
116
+
117
+ decoupled_bell_prep_and_measure.draw()
118
+
119
+ With the pulse builder we are able to blend programming on qubits and channels.
120
+ While the pulse schedule is based on instructions that operate on
121
+ channels, the pulse builder automatically handles the mapping from qubits to
122
+ channels for you.
123
+
124
+ In the example below we demonstrate some more features of the pulse builder:
125
+
126
+ .. code-block::
127
+
128
+ import math
129
+
130
+ from qiskit import pulse, QuantumCircuit
131
+ from qiskit.pulse import library
132
+ from qiskit.providers.fake_provider import FakeOpenPulse2Q
133
+
134
+ backend = FakeOpenPulse2Q()
135
+
136
+ with pulse.build(backend) as pulse_prog:
137
+ # Create a pulse.
138
+ gaussian_pulse = library.gaussian(10, 1.0, 2)
139
+ # Get the qubit's corresponding drive channel from the backend.
140
+ d0 = pulse.drive_channel(0)
141
+ d1 = pulse.drive_channel(1)
142
+ # Play a pulse at t=0.
143
+ pulse.play(gaussian_pulse, d0)
144
+ # Play another pulse directly after the previous pulse at t=10.
145
+ pulse.play(gaussian_pulse, d0)
146
+ # The default scheduling behavior is to schedule pulses in parallel
147
+ # across channels. For example, the statement below
148
+ # plays the same pulse on a different channel at t=0.
149
+ pulse.play(gaussian_pulse, d1)
150
+
151
+ # We also provide pulse scheduling alignment contexts.
152
+ # The default alignment context is align_left.
153
+
154
+ # The sequential context schedules pulse instructions sequentially in time.
155
+ # This context starts at t=10 due to earlier pulses above.
156
+ with pulse.align_sequential():
157
+ pulse.play(gaussian_pulse, d0)
158
+ # Play another pulse after at t=20.
159
+ pulse.play(gaussian_pulse, d1)
160
+
161
+ # We can also nest contexts as each instruction is
162
+ # contained in its local scheduling context.
163
+ # The output of a child context is a context-schedule
164
+ # with the internal instructions timing fixed relative to
165
+ # one another. This is schedule is then called in the parent context.
166
+
167
+ # Context starts at t=30.
168
+ with pulse.align_left():
169
+ # Start at t=30.
170
+ pulse.play(gaussian_pulse, d0)
171
+ # Start at t=30.
172
+ pulse.play(gaussian_pulse, d1)
173
+ # Context ends at t=40.
174
+
175
+ # Alignment context where all pulse instructions are
176
+ # aligned to the right, ie., as late as possible.
177
+ with pulse.align_right():
178
+ # Shift the phase of a pulse channel.
179
+ pulse.shift_phase(math.pi, d1)
180
+ # Starts at t=40.
181
+ pulse.delay(100, d0)
182
+ # Ends at t=140.
183
+
184
+ # Starts at t=130.
185
+ pulse.play(gaussian_pulse, d1)
186
+ # Ends at t=140.
187
+
188
+ # Acquire data for a qubit and store in a memory slot.
189
+ pulse.acquire(100, 0, pulse.MemorySlot(0))
190
+
191
+ # We also support a variety of macros for common operations.
192
+
193
+ # Measure all qubits.
194
+ pulse.measure_all()
195
+
196
+ # Delay on some qubits.
197
+ # This requires knowledge of which channels belong to which qubits.
198
+ # delay for 100 cycles on qubits 0 and 1.
199
+ pulse.delay_qubits(100, 0, 1)
200
+
201
+ # Call a quantum circuit. The pulse builder lazily constructs a quantum
202
+ # circuit which is then transpiled and scheduled before inserting into
203
+ # a pulse schedule.
204
+ # NOTE: Quantum register indices correspond to physical qubit indices.
205
+ qc = QuantumCircuit(2, 2)
206
+ qc.cx(0, 1)
207
+ pulse.call(qc)
208
+ # Calling a small set of standard gates and decomposing to pulses is
209
+ # also supported with more natural syntax.
210
+ pulse.u3(0, math.pi, 0, 0)
211
+ pulse.cx(0, 1)
212
+
213
+
214
+ # It is also be possible to call a preexisting schedule
215
+ tmp_sched = pulse.Schedule()
216
+ tmp_sched += pulse.Play(gaussian_pulse, d0)
217
+ pulse.call(tmp_sched)
218
+
219
+ # We also support:
220
+
221
+ # frequency instructions
222
+ pulse.set_frequency(5.0e9, d0)
223
+
224
+ # phase instructions
225
+ pulse.shift_phase(0.1, d0)
226
+
227
+ # offset contexts
228
+ with pulse.phase_offset(math.pi, d0):
229
+ pulse.play(gaussian_pulse, d0)
230
+
231
+ The above is just a small taste of what is possible with the builder. See the rest of the module
232
+ documentation for more information on its capabilities.
233
+
234
+ .. autofunction:: build
235
+
236
+
237
+ Channels
238
+ ========
239
+
240
+ Methods to return the correct channels for the respective qubit indices.
241
+
242
+ .. code-block::
243
+
244
+ from qiskit import pulse
245
+ from qiskit.providers.fake_provider import FakeArmonk
246
+
247
+ backend = FakeArmonk()
248
+
249
+ with pulse.build(backend) as drive_sched:
250
+ d0 = pulse.drive_channel(0)
251
+ print(d0)
252
+
253
+ .. parsed-literal::
254
+
255
+ DriveChannel(0)
256
+
257
+ .. autofunction:: acquire_channel
258
+ .. autofunction:: control_channels
259
+ .. autofunction:: drive_channel
260
+ .. autofunction:: measure_channel
261
+
262
+
263
+ Instructions
264
+ ============
265
+
266
+ Pulse instructions are available within the builder interface. Here's an example:
267
+
268
+ .. plot::
269
+ :include-source:
270
+
271
+ from qiskit import pulse
272
+ from qiskit.providers.fake_provider import FakeArmonk
273
+
274
+ backend = FakeArmonk()
275
+
276
+ with pulse.build(backend) as drive_sched:
277
+ d0 = pulse.drive_channel(0)
278
+ a0 = pulse.acquire_channel(0)
279
+
280
+ pulse.play(pulse.library.Constant(10, 1.0), d0)
281
+ pulse.delay(20, d0)
282
+ pulse.shift_phase(3.14/2, d0)
283
+ pulse.set_phase(3.14, d0)
284
+ pulse.shift_frequency(1e7, d0)
285
+ pulse.set_frequency(5e9, d0)
286
+
287
+ with pulse.build() as temp_sched:
288
+ pulse.play(pulse.library.Gaussian(20, 1.0, 3.0), d0)
289
+ pulse.play(pulse.library.Gaussian(20, -1.0, 3.0), d0)
290
+
291
+ pulse.call(temp_sched)
292
+ pulse.acquire(30, a0, pulse.MemorySlot(0))
293
+
294
+ drive_sched.draw()
295
+
296
+ .. autofunction:: acquire
297
+ .. autofunction:: barrier
298
+ .. autofunction:: call
299
+ .. autofunction:: delay
300
+ .. autofunction:: play
301
+ .. autofunction:: reference
302
+ .. autofunction:: set_frequency
303
+ .. autofunction:: set_phase
304
+ .. autofunction:: shift_frequency
305
+ .. autofunction:: shift_phase
306
+ .. autofunction:: snapshot
307
+
308
+
309
+ Contexts
310
+ ========
311
+
312
+ Builder aware contexts that modify the construction of a pulse program. For
313
+ example an alignment context like :func:`align_right` may
314
+ be used to align all pulses as late as possible in a pulse program.
315
+
316
+ .. plot::
317
+ :include-source:
318
+
319
+ from qiskit import pulse
320
+
321
+ d0 = pulse.DriveChannel(0)
322
+ d1 = pulse.DriveChannel(1)
323
+
324
+ with pulse.build() as pulse_prog:
325
+ with pulse.align_right():
326
+ # this pulse will start at t=0
327
+ pulse.play(pulse.Constant(100, 1.0), d0)
328
+ # this pulse will start at t=80
329
+ pulse.play(pulse.Constant(20, 1.0), d1)
330
+
331
+ pulse_prog.draw()
332
+
333
+ .. autofunction:: align_equispaced
334
+ .. autofunction:: align_func
335
+ .. autofunction:: align_left
336
+ .. autofunction:: align_right
337
+ .. autofunction:: align_sequential
338
+ .. autofunction:: circuit_scheduler_settings
339
+ .. autofunction:: frequency_offset
340
+ .. autofunction:: phase_offset
341
+ .. autofunction:: transpiler_settings
342
+
343
+
344
+ Macros
345
+ ======
346
+
347
+ Macros help you add more complex functionality to your pulse program.
348
+
349
+ .. code-block::
350
+
351
+ from qiskit import pulse
352
+ from qiskit.providers.fake_provider import FakeArmonk
353
+
354
+ backend = FakeArmonk()
355
+
356
+ with pulse.build(backend) as measure_sched:
357
+ mem_slot = pulse.measure(0)
358
+ print(mem_slot)
359
+
360
+ .. parsed-literal::
361
+
362
+ MemorySlot(0)
363
+
364
+ .. autofunction:: measure
365
+ .. autofunction:: measure_all
366
+ .. autofunction:: delay_qubits
367
+
368
+
369
+ Circuit Gates
370
+ =============
371
+
372
+ To use circuit level gates within your pulse program call a circuit
373
+ with :func:`call`.
374
+
375
+ .. warning::
376
+ These will be removed in future versions with the release of a circuit
377
+ builder interface in which it will be possible to calibrate a gate in
378
+ terms of pulses and use that gate in a circuit.
379
+
380
+ .. code-block::
381
+
382
+ import math
383
+
384
+ from qiskit import pulse
385
+ from qiskit.providers.fake_provider import FakeArmonk
386
+
387
+ backend = FakeArmonk()
388
+
389
+ with pulse.build(backend) as u3_sched:
390
+ pulse.u3(math.pi, 0, math.pi, 0)
391
+
392
+ .. autofunction:: cx
393
+ .. autofunction:: u1
394
+ .. autofunction:: u2
395
+ .. autofunction:: u3
396
+ .. autofunction:: x
397
+
398
+
399
+ Utilities
400
+ =========
401
+
402
+ The utility functions can be used to gather attributes about the backend and modify
403
+ how the program is built.
404
+
405
+ .. code-block::
406
+
407
+ from qiskit import pulse
408
+
409
+ from qiskit.providers.fake_provider import FakeArmonk
410
+
411
+ backend = FakeArmonk()
412
+
413
+ with pulse.build(backend) as u3_sched:
414
+ print('Number of qubits in backend: {}'.format(pulse.num_qubits()))
415
+
416
+ samples = 160
417
+ print('There are {} samples in {} seconds'.format(
418
+ samples, pulse.samples_to_seconds(160)))
419
+
420
+ seconds = 1e-6
421
+ print('There are {} seconds in {} samples.'.format(
422
+ seconds, pulse.seconds_to_samples(1e-6)))
423
+
424
+ .. parsed-literal::
425
+
426
+ Number of qubits in backend: 1
427
+ There are 160 samples in 3.5555555555555554e-08 seconds
428
+ There are 1e-06 seconds in 4500 samples.
429
+
430
+ .. autofunction:: active_backend
431
+ .. autofunction:: active_transpiler_settings
432
+ .. autofunction:: active_circuit_scheduler_settings
433
+ .. autofunction:: num_qubits
434
+ .. autofunction:: qubit_channels
435
+ .. autofunction:: samples_to_seconds
436
+ .. autofunction:: seconds_to_samples
437
+ """
438
+ import collections
439
+ import contextvars
440
+ import functools
441
+ import itertools
442
+ import uuid
443
+ import warnings
444
+ from contextlib import contextmanager
445
+ from functools import singledispatchmethod
446
+ from typing import (
447
+ Any,
448
+ Callable,
449
+ ContextManager,
450
+ Dict,
451
+ Iterable,
452
+ List,
453
+ Mapping,
454
+ Optional,
455
+ Set,
456
+ Tuple,
457
+ TypeVar,
458
+ Union,
459
+ NewType,
460
+ )
461
+
462
+ import numpy as np
463
+
464
+ from qiskit import circuit
465
+ from qiskit.circuit.library import standard_gates as gates
466
+ from qiskit.circuit.parameterexpression import ParameterExpression, ParameterValueType
467
+ from qiskit.pulse import (
468
+ channels as chans,
469
+ configuration,
470
+ exceptions,
471
+ instructions,
472
+ macros,
473
+ library,
474
+ transforms,
475
+ )
476
+ from qiskit.providers.backend import BackendV2
477
+ from qiskit.pulse.instructions import directives
478
+ from qiskit.pulse.schedule import Schedule, ScheduleBlock
479
+ from qiskit.pulse.transforms.alignments import AlignmentKind
480
+
481
+
482
+ #: contextvars.ContextVar[BuilderContext]: active builder
483
+ BUILDER_CONTEXTVAR = contextvars.ContextVar("backend")
484
+
485
+ T = TypeVar("T")
486
+
487
+ StorageLocation = NewType("StorageLocation", Union[chans.MemorySlot, chans.RegisterSlot])
488
+
489
+
490
+ def _compile_lazy_circuit_before(function: Callable[..., T]) -> Callable[..., T]:
491
+ """Decorator thats schedules and calls the lazily compiled circuit before
492
+ executing the decorated builder method."""
493
+
494
+ @functools.wraps(function)
495
+ def wrapper(self, *args, **kwargs):
496
+ self._compile_lazy_circuit()
497
+ return function(self, *args, **kwargs)
498
+
499
+ return wrapper
500
+
501
+
502
+ def _requires_backend(function: Callable[..., T]) -> Callable[..., T]:
503
+ """Decorator a function to raise if it is called without a builder with a
504
+ set backend.
505
+ """
506
+
507
+ @functools.wraps(function)
508
+ def wrapper(self, *args, **kwargs):
509
+ if self.backend is None:
510
+ raise exceptions.BackendNotSet(
511
+ 'This function requires the builder to have a "backend" set.'
512
+ )
513
+ return function(self, *args, **kwargs)
514
+
515
+ return wrapper
516
+
517
+
518
+ class _PulseBuilder:
519
+ """Builder context class."""
520
+
521
+ __alignment_kinds__ = {
522
+ "left": transforms.AlignLeft(),
523
+ "right": transforms.AlignRight(),
524
+ "sequential": transforms.AlignSequential(),
525
+ }
526
+
527
+ def __init__(
528
+ self,
529
+ backend=None,
530
+ block: Optional[ScheduleBlock] = None,
531
+ name: Optional[str] = None,
532
+ default_alignment: Union[str, AlignmentKind] = "left",
533
+ default_transpiler_settings: Mapping = None,
534
+ default_circuit_scheduler_settings: Mapping = None,
535
+ ):
536
+ """Initialize the builder context.
537
+
538
+ .. note::
539
+ At some point we may consider incorporating the builder into
540
+ the :class:`~qiskit.pulse.Schedule` class. However, the risk of
541
+ this is tying the user interface to the intermediate
542
+ representation. For now we avoid this at the cost of some code
543
+ duplication.
544
+
545
+ Args:
546
+ backend (Backend): Input backend to use in
547
+ builder. If not set certain functionality will be unavailable.
548
+ block: Initital ``ScheduleBlock`` to build on.
549
+ name: Name of pulse program to be built.
550
+ default_alignment: Default scheduling alignment for builder.
551
+ One of ``left``, ``right``, ``sequential`` or an instance of
552
+ :class:`~qiskit.pulse.transforms.alignments.AlignmentKind` subclass.
553
+ default_transpiler_settings: Default settings for the transpiler.
554
+ default_circuit_scheduler_settings: Default settings for the
555
+ circuit to pulse scheduler.
556
+
557
+ Raises:
558
+ PulseError: When invalid ``default_alignment`` or `block` is specified.
559
+ """
560
+ #: Backend: Backend instance for context builder.
561
+ self._backend = backend
562
+
563
+ #: Union[None, ContextVar]: Token for this ``_PulseBuilder``'s ``ContextVar``.
564
+ self._backend_ctx_token = None
565
+
566
+ #: QuantumCircuit: Lazily constructed quantum circuit
567
+ self._lazy_circuit = None
568
+
569
+ #: Dict[str, Any]: Transpiler setting dictionary.
570
+ self._transpiler_settings = default_transpiler_settings or {}
571
+
572
+ #: Dict[str, Any]: Scheduler setting dictionary.
573
+ self._circuit_scheduler_settings = default_circuit_scheduler_settings or {}
574
+
575
+ #: List[ScheduleBlock]: Stack of context.
576
+ self._context_stack = []
577
+
578
+ #: str: Name of the output program
579
+ self._name = name
580
+
581
+ # Add root block if provided. Schedule will be built on top of this.
582
+ if block is not None:
583
+ if isinstance(block, ScheduleBlock):
584
+ root_block = block
585
+ elif isinstance(block, Schedule):
586
+ root_block = self._naive_typecast_schedule(block)
587
+ else:
588
+ raise exceptions.PulseError(
589
+ f"Input `block` type {block.__class__.__name__} is "
590
+ "not a valid format. Specify a pulse program."
591
+ )
592
+ self._context_stack.append(root_block)
593
+
594
+ # Set default alignment context
595
+ alignment = _PulseBuilder.__alignment_kinds__.get(default_alignment, default_alignment)
596
+ if not isinstance(alignment, AlignmentKind):
597
+ raise exceptions.PulseError(
598
+ f"Given `default_alignment` {repr(default_alignment)} is "
599
+ "not a valid transformation. Set one of "
600
+ f'{", ".join(_PulseBuilder.__alignment_kinds__.keys())}, '
601
+ "or set an instance of `AlignmentKind` subclass."
602
+ )
603
+ self.push_context(alignment)
604
+
605
+ def __enter__(self) -> ScheduleBlock:
606
+ """Enter this builder context and yield either the supplied schedule
607
+ or the schedule created for the user.
608
+
609
+ Returns:
610
+ The schedule that the builder will build on.
611
+ """
612
+ self._backend_ctx_token = BUILDER_CONTEXTVAR.set(self)
613
+ output = self._context_stack[0]
614
+ output._name = self._name or output.name
615
+
616
+ return output
617
+
618
+ @_compile_lazy_circuit_before
619
+ def __exit__(self, exc_type, exc_val, exc_tb):
620
+ """Exit the builder context and compile the built pulse program."""
621
+ self.compile()
622
+ BUILDER_CONTEXTVAR.reset(self._backend_ctx_token)
623
+
624
+ @property
625
+ def backend(self):
626
+ """Returns the builder backend if set.
627
+
628
+ Returns:
629
+ Optional[Backend]: The builder's backend.
630
+ """
631
+ return self._backend
632
+
633
+ @_compile_lazy_circuit_before
634
+ def push_context(self, alignment: AlignmentKind):
635
+ """Push new context to the stack."""
636
+ self._context_stack.append(ScheduleBlock(alignment_context=alignment))
637
+
638
+ @_compile_lazy_circuit_before
639
+ def pop_context(self) -> ScheduleBlock:
640
+ """Pop the last context from the stack."""
641
+ if len(self._context_stack) == 1:
642
+ raise exceptions.PulseError("The root context cannot be popped out.")
643
+
644
+ return self._context_stack.pop()
645
+
646
+ def get_context(self) -> ScheduleBlock:
647
+ """Get current context.
648
+
649
+ Notes:
650
+ New instruction can be added by `.append_subroutine` or `.append_instruction` method.
651
+ Use above methods rather than directly accessing to the current context.
652
+ """
653
+ return self._context_stack[-1]
654
+
655
+ @property
656
+ @_requires_backend
657
+ def num_qubits(self):
658
+ """Get the number of qubits in the backend."""
659
+ # backendV2
660
+ if isinstance(self.backend, BackendV2):
661
+ return self.backend.num_qubits
662
+ return self.backend.configuration().n_qubits
663
+
664
+ @property
665
+ def transpiler_settings(self) -> Mapping:
666
+ """The builder's transpiler settings."""
667
+ return self._transpiler_settings
668
+
669
+ @transpiler_settings.setter
670
+ @_compile_lazy_circuit_before
671
+ def transpiler_settings(self, settings: Mapping):
672
+ self._compile_lazy_circuit()
673
+ self._transpiler_settings = settings
674
+
675
+ @property
676
+ def circuit_scheduler_settings(self) -> Mapping:
677
+ """The builder's circuit to pulse scheduler settings."""
678
+ return self._circuit_scheduler_settings
679
+
680
+ @circuit_scheduler_settings.setter
681
+ @_compile_lazy_circuit_before
682
+ def circuit_scheduler_settings(self, settings: Mapping):
683
+ self._compile_lazy_circuit()
684
+ self._circuit_scheduler_settings = settings
685
+
686
+ @_compile_lazy_circuit_before
687
+ def compile(self) -> ScheduleBlock:
688
+ """Compile and output the built pulse program."""
689
+ # Not much happens because we currently compile as we build.
690
+ # This should be offloaded to a true compilation module
691
+ # once we define a more sophisticated IR.
692
+
693
+ while len(self._context_stack) > 1:
694
+ current = self.pop_context()
695
+ self.append_subroutine(current)
696
+
697
+ return self._context_stack[0]
698
+
699
+ def _compile_lazy_circuit(self):
700
+ """Call a context QuantumCircuit (lazy circuit) and append the output pulse schedule
701
+ to the builder's context schedule.
702
+
703
+ Note that the lazy circuit is not stored as a call instruction.
704
+ """
705
+ if self._lazy_circuit:
706
+ lazy_circuit = self._lazy_circuit
707
+ # reset lazy circuit
708
+ self._lazy_circuit = self._new_circuit()
709
+ self.call_subroutine(self._compile_circuit(lazy_circuit))
710
+
711
+ def _compile_circuit(self, circ) -> Schedule:
712
+ """Take a QuantumCircuit and output the pulse schedule associated with the circuit."""
713
+ from qiskit import compiler # pylint: disable=cyclic-import
714
+
715
+ transpiled_circuit = compiler.transpile(circ, self.backend, **self.transpiler_settings)
716
+ sched = compiler.schedule(
717
+ transpiled_circuit, self.backend, **self.circuit_scheduler_settings
718
+ )
719
+ return sched
720
+
721
+ def _new_circuit(self):
722
+ """Create a new circuit for lazy circuit scheduling."""
723
+ return circuit.QuantumCircuit(self.num_qubits)
724
+
725
+ @_compile_lazy_circuit_before
726
+ def append_instruction(self, instruction: instructions.Instruction):
727
+ """Add an instruction to the builder's context schedule.
728
+
729
+ Args:
730
+ instruction: Instruction to append.
731
+ """
732
+ self._context_stack[-1].append(instruction)
733
+
734
+ def append_reference(self, name: str, *extra_keys: str):
735
+ """Add external program as a :class:`~qiskit.pulse.instructions.Reference` instruction.
736
+
737
+ Args:
738
+ name: Name of subroutine.
739
+ extra_keys: Assistance keys to uniquely specify the subroutine.
740
+ """
741
+ inst = instructions.Reference(name, *extra_keys)
742
+ self.append_instruction(inst)
743
+
744
+ @_compile_lazy_circuit_before
745
+ def append_subroutine(self, subroutine: Union[Schedule, ScheduleBlock]):
746
+ """Append a :class:`ScheduleBlock` to the builder's context schedule.
747
+
748
+ This operation doesn't create a reference. Subroutine is directly
749
+ appended to current context schedule.
750
+
751
+ Args:
752
+ subroutine: ScheduleBlock to append to the current context block.
753
+
754
+ Raises:
755
+ PulseError: When subroutine is not Schedule nor ScheduleBlock.
756
+ """
757
+ if not isinstance(subroutine, (ScheduleBlock, Schedule)):
758
+ raise exceptions.PulseError(
759
+ f"'{subroutine.__class__.__name__}' is not valid data format in the builder. "
760
+ "'Schedule' and 'ScheduleBlock' can be appended to the builder context."
761
+ )
762
+
763
+ if len(subroutine) == 0:
764
+ return
765
+ if isinstance(subroutine, Schedule):
766
+ subroutine = self._naive_typecast_schedule(subroutine)
767
+ self._context_stack[-1].append(subroutine)
768
+
769
+ @singledispatchmethod
770
+ def call_subroutine(
771
+ self,
772
+ subroutine: Union[circuit.QuantumCircuit, Schedule, ScheduleBlock],
773
+ name: Optional[str] = None,
774
+ value_dict: Optional[Dict[ParameterExpression, ParameterValueType]] = None,
775
+ **kw_params: ParameterValueType,
776
+ ):
777
+ """Call a schedule or circuit defined outside of the current scope.
778
+
779
+ The ``subroutine`` is appended to the context schedule as a call instruction.
780
+ This logic just generates a convenient program representation in the compiler.
781
+ Thus, this doesn't affect execution of inline subroutines.
782
+ See :class:`~pulse.instructions.Call` for more details.
783
+
784
+ Args:
785
+ subroutine: Target schedule or circuit to append to the current context.
786
+ name: Name of subroutine if defined.
787
+ value_dict: Parameter object and assigned value mapping. This is more precise way to
788
+ identify a parameter since mapping is managed with unique object id rather than
789
+ name. Especially there is any name collision in a parameter table.
790
+ kw_params: Parameter values to bind to the target subroutine
791
+ with string parameter names. If there are parameter name overlapping,
792
+ these parameters are updated with the same assigned value.
793
+
794
+ Raises:
795
+ PulseError:
796
+ - When input subroutine is not valid data format.
797
+ """
798
+ raise exceptions.PulseError(
799
+ f"Subroutine type {subroutine.__class__.__name__} is "
800
+ "not valid data format. Call QuantumCircuit, "
801
+ "Schedule, or ScheduleBlock."
802
+ )
803
+
804
+ @call_subroutine.register
805
+ def _(
806
+ self,
807
+ target_block: ScheduleBlock,
808
+ name: Optional[str] = None,
809
+ value_dict: Optional[Dict[ParameterExpression, ParameterValueType]] = None,
810
+ **kw_params: ParameterValueType,
811
+ ):
812
+ if len(target_block) == 0:
813
+ return
814
+
815
+ # Create local parameter assignment
816
+ local_assignment = {}
817
+ for param_name, value in kw_params.items():
818
+ params = target_block.get_parameters(param_name)
819
+ if not params:
820
+ raise exceptions.PulseError(
821
+ f"Parameter {param_name} is not defined in the target subroutine. "
822
+ f'{", ".join(map(str, target_block.parameters))} can be specified.'
823
+ )
824
+ for param in params:
825
+ local_assignment[param] = value
826
+
827
+ if value_dict:
828
+ if local_assignment.keys() & value_dict.keys():
829
+ warnings.warn(
830
+ "Some parameters provided by 'value_dict' conflict with one through "
831
+ "keyword arguments. Parameter values in the keyword arguments "
832
+ "are overridden by the dictionary values.",
833
+ UserWarning,
834
+ )
835
+ local_assignment.update(value_dict)
836
+
837
+ if local_assignment:
838
+ target_block = target_block.assign_parameters(local_assignment, inplace=False)
839
+
840
+ if name is None:
841
+ # Add unique string, not to accidentally override existing reference entry.
842
+ keys = (target_block.name, uuid.uuid4().hex)
843
+ else:
844
+ keys = (name,)
845
+
846
+ self.append_reference(*keys)
847
+ self.get_context().assign_references({keys: target_block}, inplace=True)
848
+
849
+ @call_subroutine.register
850
+ def _(
851
+ self,
852
+ target_schedule: Schedule,
853
+ name: Optional[str] = None,
854
+ value_dict: Optional[Dict[ParameterExpression, ParameterValueType]] = None,
855
+ **kw_params: ParameterValueType,
856
+ ):
857
+ if len(target_schedule) == 0:
858
+ return
859
+
860
+ self.call_subroutine(
861
+ self._naive_typecast_schedule(target_schedule),
862
+ name=name,
863
+ value_dict=value_dict,
864
+ **kw_params,
865
+ )
866
+
867
+ @call_subroutine.register
868
+ def _(
869
+ self,
870
+ target_circuit: circuit.QuantumCircuit,
871
+ name: Optional[str] = None,
872
+ value_dict: Optional[Dict[ParameterExpression, ParameterValueType]] = None,
873
+ **kw_params: ParameterValueType,
874
+ ):
875
+ if len(target_circuit) == 0:
876
+ return
877
+
878
+ self._compile_lazy_circuit()
879
+ self.call_subroutine(
880
+ self._compile_circuit(target_circuit),
881
+ name=name,
882
+ value_dict=value_dict,
883
+ **kw_params,
884
+ )
885
+
886
+ @_requires_backend
887
+ def call_gate(self, gate: circuit.Gate, qubits: Tuple[int, ...], lazy: bool = True):
888
+ """Call the circuit ``gate`` in the pulse program.
889
+
890
+ The qubits are assumed to be defined on physical qubits.
891
+
892
+ If ``lazy == True`` this circuit will extend a lazily constructed
893
+ quantum circuit. When an operation occurs that breaks the underlying
894
+ circuit scheduling assumptions such as adding a pulse instruction or
895
+ changing the alignment context the circuit will be
896
+ transpiled and scheduled into pulses with the current active settings.
897
+
898
+ Args:
899
+ gate: Gate to call.
900
+ qubits: Qubits to call gate on.
901
+ lazy: If false the circuit will be transpiled and pulse scheduled
902
+ immediately. Otherwise, it will extend the active lazy circuit
903
+ as defined above.
904
+ """
905
+ try:
906
+ iter(qubits)
907
+ except TypeError:
908
+ qubits = (qubits,)
909
+
910
+ if lazy:
911
+ self._call_gate(gate, qubits)
912
+ else:
913
+ self._compile_lazy_circuit()
914
+ self._call_gate(gate, qubits)
915
+ self._compile_lazy_circuit()
916
+
917
+ def _call_gate(self, gate, qargs):
918
+ if self._lazy_circuit is None:
919
+ self._lazy_circuit = self._new_circuit()
920
+
921
+ self._lazy_circuit.append(gate, qargs=qargs)
922
+
923
+ @staticmethod
924
+ def _naive_typecast_schedule(schedule: Schedule):
925
+ # Naively convert into ScheduleBlock
926
+ from qiskit.pulse.transforms import inline_subroutines, flatten, pad
927
+
928
+ preprocessed_schedule = inline_subroutines(flatten(schedule))
929
+ pad(preprocessed_schedule, inplace=True, pad_with=instructions.TimeBlockade)
930
+
931
+ # default to left alignment, namely ASAP scheduling
932
+ target_block = ScheduleBlock(name=schedule.name)
933
+ for _, inst in preprocessed_schedule.instructions:
934
+ target_block.append(inst, inplace=True)
935
+
936
+ return target_block
937
+
938
+ def get_dt(self):
939
+ """Retrieve dt differently based on the type of Backend"""
940
+ if isinstance(self.backend, BackendV2):
941
+ return self.backend.dt
942
+ return self.backend.configuration().dt
943
+
944
+
945
+ def build(
946
+ backend=None,
947
+ schedule: Optional[ScheduleBlock] = None,
948
+ name: Optional[str] = None,
949
+ default_alignment: Optional[Union[str, AlignmentKind]] = "left",
950
+ default_transpiler_settings: Optional[Dict[str, Any]] = None,
951
+ default_circuit_scheduler_settings: Optional[Dict[str, Any]] = None,
952
+ ) -> ContextManager[ScheduleBlock]:
953
+ """Create a context manager for launching the imperative pulse builder DSL.
954
+
955
+ To enter a building context and starting building a pulse program:
956
+
957
+ .. code-block::
958
+
959
+ from qiskit import execute, pulse
960
+ from qiskit.providers.fake_provider import FakeOpenPulse2Q
961
+
962
+ backend = FakeOpenPulse2Q()
963
+
964
+ d0 = pulse.DriveChannel(0)
965
+
966
+ with pulse.build() as pulse_prog:
967
+ pulse.play(pulse.Constant(100, 0.5), d0)
968
+
969
+
970
+ While the output program ``pulse_prog`` cannot be executed as we are using
971
+ a mock backend. If a real backend is being used, executing the program is
972
+ done with:
973
+
974
+ .. code-block:: python
975
+
976
+ qiskit.execute(pulse_prog, backend)
977
+
978
+ Args:
979
+ backend (Backend): A Qiskit backend. If not supplied certain
980
+ builder functionality will be unavailable.
981
+ schedule: A pulse ``ScheduleBlock`` in which your pulse program will be built.
982
+ name: Name of pulse program to be built.
983
+ default_alignment: Default scheduling alignment for builder.
984
+ One of ``left``, ``right``, ``sequential`` or an alignment context.
985
+ default_transpiler_settings: Default settings for the transpiler.
986
+ default_circuit_scheduler_settings: Default settings for the
987
+ circuit to pulse scheduler.
988
+
989
+ Returns:
990
+ A new builder context which has the active builder initialized.
991
+ """
992
+ return _PulseBuilder(
993
+ backend=backend,
994
+ block=schedule,
995
+ name=name,
996
+ default_alignment=default_alignment,
997
+ default_transpiler_settings=default_transpiler_settings,
998
+ default_circuit_scheduler_settings=default_circuit_scheduler_settings,
999
+ )
1000
+
1001
+
1002
+ # Builder Utilities
1003
+
1004
+
1005
+ def _active_builder() -> _PulseBuilder:
1006
+ """Get the active builder in the active context.
1007
+
1008
+ Returns:
1009
+ The active active builder in this context.
1010
+
1011
+ Raises:
1012
+ exceptions.NoActiveBuilder: If a pulse builder function is called
1013
+ outside of a builder context.
1014
+ """
1015
+ try:
1016
+ return BUILDER_CONTEXTVAR.get()
1017
+ except LookupError as ex:
1018
+ raise exceptions.NoActiveBuilder(
1019
+ "A Pulse builder function was called outside of "
1020
+ "a builder context. Try calling within a builder "
1021
+ 'context, eg., "with pulse.build() as schedule: ...".'
1022
+ ) from ex
1023
+
1024
+
1025
+ def active_backend():
1026
+ """Get the backend of the currently active builder context.
1027
+
1028
+ Returns:
1029
+ Backend: The active backend in the currently active
1030
+ builder context.
1031
+
1032
+ Raises:
1033
+ exceptions.BackendNotSet: If the builder does not have a backend set.
1034
+ """
1035
+ builder = _active_builder().backend
1036
+ if builder is None:
1037
+ raise exceptions.BackendNotSet(
1038
+ 'This function requires the active builder to have a "backend" set.'
1039
+ )
1040
+ return builder
1041
+
1042
+
1043
+ def append_schedule(schedule: Union[Schedule, ScheduleBlock]):
1044
+ """Call a schedule by appending to the active builder's context block.
1045
+
1046
+ Args:
1047
+ schedule: Schedule or ScheduleBlock to append.
1048
+ """
1049
+ _active_builder().append_subroutine(schedule)
1050
+
1051
+
1052
+ def append_instruction(instruction: instructions.Instruction):
1053
+ """Append an instruction to the active builder's context schedule.
1054
+
1055
+ Examples:
1056
+
1057
+ .. code-block::
1058
+
1059
+ from qiskit import pulse
1060
+
1061
+ d0 = pulse.DriveChannel(0)
1062
+
1063
+ with pulse.build() as pulse_prog:
1064
+ pulse.builder.append_instruction(pulse.Delay(10, d0))
1065
+
1066
+ print(pulse_prog.instructions)
1067
+
1068
+ .. parsed-literal::
1069
+
1070
+ ((0, Delay(10, DriveChannel(0))),)
1071
+ """
1072
+ _active_builder().append_instruction(instruction)
1073
+
1074
+
1075
+ def num_qubits() -> int:
1076
+ """Return number of qubits in the currently active backend.
1077
+
1078
+ Examples:
1079
+
1080
+ .. code-block::
1081
+
1082
+ from qiskit import pulse
1083
+ from qiskit.providers.fake_provider import FakeOpenPulse2Q
1084
+
1085
+ backend = FakeOpenPulse2Q()
1086
+
1087
+ with pulse.build(backend):
1088
+ print(pulse.num_qubits())
1089
+
1090
+ .. parsed-literal::
1091
+
1092
+ 2
1093
+
1094
+ .. note:: Requires the active builder context to have a backend set.
1095
+ """
1096
+ if isinstance(active_backend(), BackendV2):
1097
+ return active_backend().num_qubits
1098
+ return active_backend().configuration().n_qubits
1099
+
1100
+
1101
+ def seconds_to_samples(seconds: Union[float, np.ndarray]) -> Union[int, np.ndarray]:
1102
+ """Obtain the number of samples that will elapse in ``seconds`` on the
1103
+ active backend.
1104
+
1105
+ Rounds down.
1106
+
1107
+ Args:
1108
+ seconds: Time in seconds to convert to samples.
1109
+
1110
+ Returns:
1111
+ The number of samples for the time to elapse
1112
+ """
1113
+ dt = _active_builder().get_dt()
1114
+ if isinstance(seconds, np.ndarray):
1115
+ return (seconds / dt).astype(int)
1116
+ return int(seconds / dt)
1117
+
1118
+
1119
+ def samples_to_seconds(samples: Union[int, np.ndarray]) -> Union[float, np.ndarray]:
1120
+ """Obtain the time in seconds that will elapse for the input number of
1121
+ samples on the active backend.
1122
+
1123
+ Args:
1124
+ samples: Number of samples to convert to time in seconds.
1125
+
1126
+ Returns:
1127
+ The time that elapses in ``samples``.
1128
+ """
1129
+ return samples * _active_builder().get_dt()
1130
+
1131
+
1132
+ def qubit_channels(qubit: int) -> Set[chans.Channel]:
1133
+ """Returns the set of channels associated with a qubit.
1134
+
1135
+ Examples:
1136
+
1137
+ .. code-block::
1138
+
1139
+ from qiskit import pulse
1140
+ from qiskit.providers.fake_provider import FakeOpenPulse2Q
1141
+
1142
+ backend = FakeOpenPulse2Q()
1143
+
1144
+ with pulse.build(backend):
1145
+ print(pulse.qubit_channels(0))
1146
+
1147
+ .. parsed-literal::
1148
+
1149
+ {MeasureChannel(0), ControlChannel(0), DriveChannel(0), AcquireChannel(0), ControlChannel(1)}
1150
+
1151
+ .. note:: Requires the active builder context to have a backend set.
1152
+
1153
+ .. note:: A channel may still be associated with another qubit in this list
1154
+ such as in the case where significant crosstalk exists.
1155
+
1156
+ """
1157
+
1158
+ # implement as the inner function to avoid API change for a patch release in 0.24.2.
1159
+ def get_qubit_channels_v2(backend: BackendV2, qubit: int):
1160
+ r"""Return a list of channels which operate on the given ``qubit``.
1161
+ Returns:
1162
+ List of ``Channel``\s operated on my the given ``qubit``.
1163
+ """
1164
+ channels = []
1165
+
1166
+ # add multi-qubit channels
1167
+ for node_qubits in backend.coupling_map:
1168
+ if qubit in node_qubits:
1169
+ control_channel = backend.control_channel(node_qubits)
1170
+ if control_channel:
1171
+ channels.extend(control_channel)
1172
+
1173
+ # add single qubit channels
1174
+ channels.append(backend.drive_channel(qubit))
1175
+ channels.append(backend.measure_channel(qubit))
1176
+ channels.append(backend.acquire_channel(qubit))
1177
+ return channels
1178
+
1179
+ # backendV2
1180
+ if isinstance(active_backend(), BackendV2):
1181
+ return set(get_qubit_channels_v2(active_backend(), qubit))
1182
+ return set(active_backend().configuration().get_qubit_channels(qubit))
1183
+
1184
+
1185
+ def _qubits_to_channels(*channels_or_qubits: Union[int, chans.Channel]) -> Set[chans.Channel]:
1186
+ """Returns the unique channels of the input qubits."""
1187
+ channels = set()
1188
+ for channel_or_qubit in channels_or_qubits:
1189
+ if isinstance(channel_or_qubit, int):
1190
+ channels |= qubit_channels(channel_or_qubit)
1191
+ elif isinstance(channel_or_qubit, chans.Channel):
1192
+ channels.add(channel_or_qubit)
1193
+ else:
1194
+ raise exceptions.PulseError(
1195
+ f'{channel_or_qubit} is not a "Channel" or qubit (integer).'
1196
+ )
1197
+ return channels
1198
+
1199
+
1200
+ def active_transpiler_settings() -> Dict[str, Any]:
1201
+ """Return the current active builder context's transpiler settings.
1202
+
1203
+ Examples:
1204
+
1205
+ .. code-block::
1206
+
1207
+ from qiskit import pulse
1208
+ from qiskit.providers.fake_provider import FakeOpenPulse2Q
1209
+
1210
+ backend = FakeOpenPulse2Q()
1211
+
1212
+ transpiler_settings = {'optimization_level': 3}
1213
+
1214
+ with pulse.build(backend,
1215
+ default_transpiler_settings=transpiler_settings):
1216
+ print(pulse.active_transpiler_settings())
1217
+
1218
+ .. parsed-literal::
1219
+
1220
+ {'optimization_level': 3}
1221
+
1222
+ """
1223
+ return dict(_active_builder().transpiler_settings)
1224
+
1225
+
1226
+ def active_circuit_scheduler_settings() -> Dict[str, Any]:
1227
+ """Return the current active builder context's circuit scheduler settings.
1228
+
1229
+ Examples:
1230
+
1231
+ .. code-block::
1232
+
1233
+ from qiskit import pulse
1234
+ from qiskit.providers.fake_provider import FakeOpenPulse2Q
1235
+
1236
+ backend = FakeOpenPulse2Q()
1237
+
1238
+ circuit_scheduler_settings = {'method': 'alap'}
1239
+
1240
+ with pulse.build(
1241
+ backend,
1242
+ default_circuit_scheduler_settings=circuit_scheduler_settings):
1243
+ print(pulse.active_circuit_scheduler_settings())
1244
+
1245
+ .. parsed-literal::
1246
+
1247
+ {'method': 'alap'}
1248
+
1249
+ """
1250
+ return dict(_active_builder().circuit_scheduler_settings)
1251
+
1252
+
1253
+ # Contexts
1254
+
1255
+
1256
+ @contextmanager
1257
+ def align_left() -> ContextManager[None]:
1258
+ """Left alignment pulse scheduling context.
1259
+
1260
+ Pulse instructions within this context are scheduled as early as possible
1261
+ by shifting them left to the earliest available time.
1262
+
1263
+ Examples:
1264
+
1265
+ .. code-block::
1266
+
1267
+ from qiskit import pulse
1268
+
1269
+ d0 = pulse.DriveChannel(0)
1270
+ d1 = pulse.DriveChannel(1)
1271
+
1272
+ with pulse.build() as pulse_prog:
1273
+ with pulse.align_left():
1274
+ # this pulse will start at t=0
1275
+ pulse.play(pulse.Constant(100, 1.0), d0)
1276
+ # this pulse will start at t=0
1277
+ pulse.play(pulse.Constant(20, 1.0), d1)
1278
+ pulse_prog = pulse.transforms.block_to_schedule(pulse_prog)
1279
+
1280
+ assert pulse_prog.ch_start_time(d0) == pulse_prog.ch_start_time(d1)
1281
+
1282
+ Yields:
1283
+ None
1284
+ """
1285
+ builder = _active_builder()
1286
+ builder.push_context(transforms.AlignLeft())
1287
+ try:
1288
+ yield
1289
+ finally:
1290
+ current = builder.pop_context()
1291
+ builder.append_subroutine(current)
1292
+
1293
+
1294
+ @contextmanager
1295
+ def align_right() -> AlignmentKind:
1296
+ """Right alignment pulse scheduling context.
1297
+
1298
+ Pulse instructions within this context are scheduled as late as possible
1299
+ by shifting them right to the latest available time.
1300
+
1301
+ Examples:
1302
+
1303
+ .. code-block::
1304
+
1305
+ from qiskit import pulse
1306
+
1307
+ d0 = pulse.DriveChannel(0)
1308
+ d1 = pulse.DriveChannel(1)
1309
+
1310
+ with pulse.build() as pulse_prog:
1311
+ with pulse.align_right():
1312
+ # this pulse will start at t=0
1313
+ pulse.play(pulse.Constant(100, 1.0), d0)
1314
+ # this pulse will start at t=80
1315
+ pulse.play(pulse.Constant(20, 1.0), d1)
1316
+ pulse_prog = pulse.transforms.block_to_schedule(pulse_prog)
1317
+
1318
+ assert pulse_prog.ch_stop_time(d0) == pulse_prog.ch_stop_time(d1)
1319
+
1320
+ Yields:
1321
+ None
1322
+ """
1323
+ builder = _active_builder()
1324
+ builder.push_context(transforms.AlignRight())
1325
+ try:
1326
+ yield
1327
+ finally:
1328
+ current = builder.pop_context()
1329
+ builder.append_subroutine(current)
1330
+
1331
+
1332
+ @contextmanager
1333
+ def align_sequential() -> AlignmentKind:
1334
+ """Sequential alignment pulse scheduling context.
1335
+
1336
+ Pulse instructions within this context are scheduled sequentially in time
1337
+ such that no two instructions will be played at the same time.
1338
+
1339
+ Examples:
1340
+
1341
+ .. code-block::
1342
+
1343
+ from qiskit import pulse
1344
+
1345
+ d0 = pulse.DriveChannel(0)
1346
+ d1 = pulse.DriveChannel(1)
1347
+
1348
+ with pulse.build() as pulse_prog:
1349
+ with pulse.align_sequential():
1350
+ # this pulse will start at t=0
1351
+ pulse.play(pulse.Constant(100, 1.0), d0)
1352
+ # this pulse will also start at t=100
1353
+ pulse.play(pulse.Constant(20, 1.0), d1)
1354
+ pulse_prog = pulse.transforms.block_to_schedule(pulse_prog)
1355
+
1356
+ assert pulse_prog.ch_stop_time(d0) == pulse_prog.ch_start_time(d1)
1357
+
1358
+ Yields:
1359
+ None
1360
+ """
1361
+ builder = _active_builder()
1362
+ builder.push_context(transforms.AlignSequential())
1363
+ try:
1364
+ yield
1365
+ finally:
1366
+ current = builder.pop_context()
1367
+ builder.append_subroutine(current)
1368
+
1369
+
1370
+ @contextmanager
1371
+ def align_equispaced(duration: Union[int, ParameterExpression]) -> AlignmentKind:
1372
+ """Equispaced alignment pulse scheduling context.
1373
+
1374
+ Pulse instructions within this context are scheduled with the same interval spacing such that
1375
+ the total length of the context block is ``duration``.
1376
+ If the total free ``duration`` cannot be evenly divided by the number of instructions
1377
+ within the context, the modulo is split and then prepended and appended to
1378
+ the returned schedule. Delay instructions are automatically inserted in between pulses.
1379
+
1380
+ This context is convenient to write a schedule for periodical dynamic decoupling or
1381
+ the Hahn echo sequence.
1382
+
1383
+ Examples:
1384
+
1385
+ .. plot::
1386
+ :include-source:
1387
+
1388
+ from qiskit import pulse
1389
+
1390
+ d0 = pulse.DriveChannel(0)
1391
+ x90 = pulse.Gaussian(10, 0.1, 3)
1392
+ x180 = pulse.Gaussian(10, 0.2, 3)
1393
+
1394
+ with pulse.build() as hahn_echo:
1395
+ with pulse.align_equispaced(duration=100):
1396
+ pulse.play(x90, d0)
1397
+ pulse.play(x180, d0)
1398
+ pulse.play(x90, d0)
1399
+
1400
+ hahn_echo.draw()
1401
+
1402
+ Args:
1403
+ duration: Duration of this context. This should be larger than the schedule duration.
1404
+
1405
+ Yields:
1406
+ None
1407
+
1408
+ Notes:
1409
+ The scheduling is performed for sub-schedules within the context rather than
1410
+ channel-wise. If you want to apply the equispaced context for each channel,
1411
+ you should use the context independently for channels.
1412
+ """
1413
+ builder = _active_builder()
1414
+ builder.push_context(transforms.AlignEquispaced(duration=duration))
1415
+ try:
1416
+ yield
1417
+ finally:
1418
+ current = builder.pop_context()
1419
+ builder.append_subroutine(current)
1420
+
1421
+
1422
+ @contextmanager
1423
+ def align_func(
1424
+ duration: Union[int, ParameterExpression], func: Callable[[int], float]
1425
+ ) -> AlignmentKind:
1426
+ """Callback defined alignment pulse scheduling context.
1427
+
1428
+ Pulse instructions within this context are scheduled at the location specified by
1429
+ arbitrary callback function `position` that takes integer index and returns
1430
+ the associated fractional location within [0, 1].
1431
+ Delay instruction is automatically inserted in between pulses.
1432
+
1433
+ This context may be convenient to write a schedule of arbitrary dynamical decoupling
1434
+ sequences such as Uhrig dynamical decoupling.
1435
+
1436
+ Examples:
1437
+
1438
+ .. plot::
1439
+ :include-source:
1440
+
1441
+ import numpy as np
1442
+ from qiskit import pulse
1443
+
1444
+ d0 = pulse.DriveChannel(0)
1445
+ x90 = pulse.Gaussian(10, 0.1, 3)
1446
+ x180 = pulse.Gaussian(10, 0.2, 3)
1447
+
1448
+ def udd10_pos(j):
1449
+ return np.sin(np.pi*j/(2*10 + 2))**2
1450
+
1451
+ with pulse.build() as udd_sched:
1452
+ pulse.play(x90, d0)
1453
+ with pulse.align_func(duration=300, func=udd10_pos):
1454
+ for _ in range(10):
1455
+ pulse.play(x180, d0)
1456
+ pulse.play(x90, d0)
1457
+
1458
+ udd_sched.draw()
1459
+
1460
+ Args:
1461
+ duration: Duration of context. This should be larger than the schedule duration.
1462
+ func: A function that takes an index of sub-schedule and returns the
1463
+ fractional coordinate of of that sub-schedule.
1464
+ The returned value should be defined within [0, 1].
1465
+ The pulse index starts from 1.
1466
+
1467
+ Yields:
1468
+ None
1469
+
1470
+ Notes:
1471
+ The scheduling is performed for sub-schedules within the context rather than
1472
+ channel-wise. If you want to apply the numerical context for each channel,
1473
+ you need to apply the context independently to channels.
1474
+ """
1475
+ builder = _active_builder()
1476
+ builder.push_context(transforms.AlignFunc(duration=duration, func=func))
1477
+ try:
1478
+ yield
1479
+ finally:
1480
+ current = builder.pop_context()
1481
+ builder.append_subroutine(current)
1482
+
1483
+
1484
+ @contextmanager
1485
+ def general_transforms(alignment_context: AlignmentKind) -> ContextManager[None]:
1486
+ """Arbitrary alignment transformation defined by a subclass instance of
1487
+ :class:`~qiskit.pulse.transforms.alignments.AlignmentKind`.
1488
+
1489
+ Args:
1490
+ alignment_context: Alignment context instance that defines schedule transformation.
1491
+
1492
+ Yields:
1493
+ None
1494
+
1495
+ Raises:
1496
+ PulseError: When input ``alignment_context`` is not ``AlignmentKind`` subclasses.
1497
+ """
1498
+ if not isinstance(alignment_context, AlignmentKind):
1499
+ raise exceptions.PulseError("Input alignment context is not `AlignmentKind` subclass.")
1500
+
1501
+ builder = _active_builder()
1502
+ builder.push_context(alignment_context)
1503
+ try:
1504
+ yield
1505
+ finally:
1506
+ current = builder.pop_context()
1507
+ builder.append_subroutine(current)
1508
+
1509
+
1510
+ @contextmanager
1511
+ def transpiler_settings(**settings) -> ContextManager[None]:
1512
+ """Set the currently active transpiler settings for this context.
1513
+
1514
+ Examples:
1515
+
1516
+ .. code-block::
1517
+
1518
+ from qiskit import pulse
1519
+ from qiskit.providers.fake_provider import FakeOpenPulse2Q
1520
+
1521
+ backend = FakeOpenPulse2Q()
1522
+
1523
+ with pulse.build(backend):
1524
+ print(pulse.active_transpiler_settings())
1525
+ with pulse.transpiler_settings(optimization_level=3):
1526
+ print(pulse.active_transpiler_settings())
1527
+
1528
+ .. parsed-literal::
1529
+
1530
+ {}
1531
+ {'optimization_level': 3}
1532
+ """
1533
+ builder = _active_builder()
1534
+ curr_transpiler_settings = builder.transpiler_settings
1535
+ builder.transpiler_settings = collections.ChainMap(settings, curr_transpiler_settings)
1536
+ try:
1537
+ yield
1538
+ finally:
1539
+ builder.transpiler_settings = curr_transpiler_settings
1540
+
1541
+
1542
+ @contextmanager
1543
+ def circuit_scheduler_settings(**settings) -> ContextManager[None]:
1544
+ """Set the currently active circuit scheduler settings for this context.
1545
+
1546
+ Examples:
1547
+
1548
+ .. code-block::
1549
+
1550
+ from qiskit import pulse
1551
+ from qiskit.providers.fake_provider import FakeOpenPulse2Q
1552
+
1553
+ backend = FakeOpenPulse2Q()
1554
+
1555
+ with pulse.build(backend):
1556
+ print(pulse.active_circuit_scheduler_settings())
1557
+ with pulse.circuit_scheduler_settings(method='alap'):
1558
+ print(pulse.active_circuit_scheduler_settings())
1559
+
1560
+ .. parsed-literal::
1561
+
1562
+ {}
1563
+ {'method': 'alap'}
1564
+
1565
+ """
1566
+ builder = _active_builder()
1567
+ curr_circuit_scheduler_settings = builder.circuit_scheduler_settings
1568
+ builder.circuit_scheduler_settings = collections.ChainMap(
1569
+ settings, curr_circuit_scheduler_settings
1570
+ )
1571
+ try:
1572
+ yield
1573
+ finally:
1574
+ builder.circuit_scheduler_settings = curr_circuit_scheduler_settings
1575
+
1576
+
1577
+ @contextmanager
1578
+ def phase_offset(phase: float, *channels: chans.PulseChannel) -> ContextManager[None]:
1579
+ """Shift the phase of input channels on entry into context and undo on exit.
1580
+
1581
+ Examples:
1582
+
1583
+ .. code-block::
1584
+
1585
+ import math
1586
+
1587
+ from qiskit import pulse
1588
+
1589
+ d0 = pulse.DriveChannel(0)
1590
+
1591
+ with pulse.build() as pulse_prog:
1592
+ with pulse.phase_offset(math.pi, d0):
1593
+ pulse.play(pulse.Constant(10, 1.0), d0)
1594
+
1595
+ assert len(pulse_prog.instructions) == 3
1596
+
1597
+ Args:
1598
+ phase: Amount of phase offset in radians.
1599
+ channels: Channels to offset phase of.
1600
+
1601
+ Yields:
1602
+ None
1603
+ """
1604
+ for channel in channels:
1605
+ shift_phase(phase, channel)
1606
+ try:
1607
+ yield
1608
+ finally:
1609
+ for channel in channels:
1610
+ shift_phase(-phase, channel)
1611
+
1612
+
1613
+ @contextmanager
1614
+ def frequency_offset(
1615
+ frequency: float, *channels: chans.PulseChannel, compensate_phase: bool = False
1616
+ ) -> ContextManager[None]:
1617
+ """Shift the frequency of inputs channels on entry into context and undo on exit.
1618
+
1619
+ Examples:
1620
+
1621
+ .. code-block:: python
1622
+ :emphasize-lines: 7, 16
1623
+
1624
+ from qiskit import pulse
1625
+
1626
+ d0 = pulse.DriveChannel(0)
1627
+
1628
+ with pulse.build(backend) as pulse_prog:
1629
+ # shift frequency by 1GHz
1630
+ with pulse.frequency_offset(1e9, d0):
1631
+ pulse.play(pulse.Constant(10, 1.0), d0)
1632
+
1633
+ assert len(pulse_prog.instructions) == 3
1634
+
1635
+ with pulse.build(backend) as pulse_prog:
1636
+ # Shift frequency by 1GHz.
1637
+ # Undo accumulated phase in the shifted frequency frame
1638
+ # when exiting the context.
1639
+ with pulse.frequency_offset(1e9, d0, compensate_phase=True):
1640
+ pulse.play(pulse.Constant(10, 1.0), d0)
1641
+
1642
+ assert len(pulse_prog.instructions) == 4
1643
+
1644
+ Args:
1645
+ frequency: Amount of frequency offset in Hz.
1646
+ channels: Channels to offset frequency of.
1647
+ compensate_phase: Compensate for accumulated phase accumulated with
1648
+ respect to the channels' frame at its initial frequency.
1649
+
1650
+ Yields:
1651
+ None
1652
+ """
1653
+ builder = _active_builder()
1654
+ # TODO: Need proper implementation of compensation. t0 may depend on the parent context.
1655
+ # For example, the instruction position within the equispaced context depends on
1656
+ # the current total number of instructions, thus adding more instruction after
1657
+ # offset context may change the t0 when the parent context is transformed.
1658
+ t0 = builder.get_context().duration
1659
+
1660
+ for channel in channels:
1661
+ shift_frequency(frequency, channel)
1662
+ try:
1663
+ yield
1664
+ finally:
1665
+ if compensate_phase:
1666
+ duration = builder.get_context().duration - t0
1667
+
1668
+ accumulated_phase = 2 * np.pi * ((duration * builder.get_dt() * frequency) % 1)
1669
+ for channel in channels:
1670
+ shift_phase(-accumulated_phase, channel)
1671
+
1672
+ for channel in channels:
1673
+ shift_frequency(-frequency, channel)
1674
+
1675
+
1676
+ # Channels
1677
+ def drive_channel(qubit: int) -> chans.DriveChannel:
1678
+ """Return ``DriveChannel`` for ``qubit`` on the active builder backend.
1679
+
1680
+ Examples:
1681
+
1682
+ .. code-block::
1683
+
1684
+ from qiskit import pulse
1685
+ from qiskit.providers.fake_provider import FakeOpenPulse2Q
1686
+
1687
+ backend = FakeOpenPulse2Q()
1688
+
1689
+ with pulse.build(backend):
1690
+ assert pulse.drive_channel(0) == pulse.DriveChannel(0)
1691
+
1692
+ .. note:: Requires the active builder context to have a backend set.
1693
+ """
1694
+ # backendV2
1695
+ if isinstance(active_backend(), BackendV2):
1696
+ return active_backend().drive_channel(qubit)
1697
+ return active_backend().configuration().drive(qubit)
1698
+
1699
+
1700
+ def measure_channel(qubit: int) -> chans.MeasureChannel:
1701
+ """Return ``MeasureChannel`` for ``qubit`` on the active builder backend.
1702
+
1703
+ Examples:
1704
+
1705
+ .. code-block::
1706
+
1707
+ from qiskit import pulse
1708
+ from qiskit.providers.fake_provider import FakeOpenPulse2Q
1709
+
1710
+ backend = FakeOpenPulse2Q()
1711
+
1712
+ with pulse.build(backend):
1713
+ assert pulse.measure_channel(0) == pulse.MeasureChannel(0)
1714
+
1715
+ .. note:: Requires the active builder context to have a backend set.
1716
+ """
1717
+ # backendV2
1718
+ if isinstance(active_backend(), BackendV2):
1719
+ return active_backend().measure_channel(qubit)
1720
+ return active_backend().configuration().measure(qubit)
1721
+
1722
+
1723
+ def acquire_channel(qubit: int) -> chans.AcquireChannel:
1724
+ """Return ``AcquireChannel`` for ``qubit`` on the active builder backend.
1725
+
1726
+ Examples:
1727
+
1728
+ .. code-block::
1729
+
1730
+ from qiskit import pulse
1731
+ from qiskit.providers.fake_provider import FakeOpenPulse2Q
1732
+
1733
+ backend = FakeOpenPulse2Q()
1734
+
1735
+ with pulse.build(backend):
1736
+ assert pulse.acquire_channel(0) == pulse.AcquireChannel(0)
1737
+
1738
+ .. note:: Requires the active builder context to have a backend set.
1739
+ """
1740
+ # backendV2
1741
+ if isinstance(active_backend(), BackendV2):
1742
+ return active_backend().acquire_channel(qubit)
1743
+ return active_backend().configuration().acquire(qubit)
1744
+
1745
+
1746
+ def control_channels(*qubits: Iterable[int]) -> List[chans.ControlChannel]:
1747
+ """Return ``ControlChannel`` for ``qubit`` on the active builder backend.
1748
+
1749
+ Return the secondary drive channel for the given qubit -- typically
1750
+ utilized for controlling multi-qubit interactions.
1751
+
1752
+ Examples:
1753
+
1754
+ .. code-block::
1755
+
1756
+ from qiskit import pulse
1757
+ from qiskit.providers.fake_provider import FakeOpenPulse2Q
1758
+
1759
+ backend = FakeOpenPulse2Q()
1760
+ with pulse.build(backend):
1761
+ assert pulse.control_channels(0, 1) == [pulse.ControlChannel(0)]
1762
+
1763
+ .. note:: Requires the active builder context to have a backend set.
1764
+
1765
+ Args:
1766
+ qubits: Tuple or list of ordered qubits of the form
1767
+ `(control_qubit, target_qubit)`.
1768
+
1769
+ Returns:
1770
+ List of control channels associated with the supplied ordered list
1771
+ of qubits.
1772
+ """
1773
+ # backendV2
1774
+ if isinstance(active_backend(), BackendV2):
1775
+ return active_backend().control_channel(qubits)
1776
+ return active_backend().configuration().control(qubits=qubits)
1777
+
1778
+
1779
+ # Base Instructions
1780
+ def delay(duration: int, channel: chans.Channel, name: Optional[str] = None):
1781
+ """Delay on a ``channel`` for a ``duration``.
1782
+
1783
+ Examples:
1784
+
1785
+ .. code-block::
1786
+
1787
+ from qiskit import pulse
1788
+
1789
+ d0 = pulse.DriveChannel(0)
1790
+
1791
+ with pulse.build() as pulse_prog:
1792
+ pulse.delay(10, d0)
1793
+
1794
+ Args:
1795
+ duration: Number of cycles to delay for on ``channel``.
1796
+ channel: Channel to delay on.
1797
+ name: Name of the instruction.
1798
+ """
1799
+ append_instruction(instructions.Delay(duration, channel, name=name))
1800
+
1801
+
1802
+ def play(
1803
+ pulse: Union[library.Pulse, np.ndarray], channel: chans.PulseChannel, name: Optional[str] = None
1804
+ ):
1805
+ """Play a ``pulse`` on a ``channel``.
1806
+
1807
+ Examples:
1808
+
1809
+ .. code-block::
1810
+
1811
+ from qiskit import pulse
1812
+
1813
+ d0 = pulse.DriveChannel(0)
1814
+
1815
+ with pulse.build() as pulse_prog:
1816
+ pulse.play(pulse.Constant(10, 1.0), d0)
1817
+
1818
+ Args:
1819
+ pulse: Pulse to play.
1820
+ channel: Channel to play pulse on.
1821
+ name: Name of the pulse.
1822
+ """
1823
+ if not isinstance(pulse, library.Pulse):
1824
+ pulse = library.Waveform(pulse)
1825
+
1826
+ append_instruction(instructions.Play(pulse, channel, name=name))
1827
+
1828
+
1829
+ def acquire(
1830
+ duration: int,
1831
+ qubit_or_channel: Union[int, chans.AcquireChannel],
1832
+ register: StorageLocation,
1833
+ **metadata: Union[configuration.Kernel, configuration.Discriminator],
1834
+ ):
1835
+ """Acquire for a ``duration`` on a ``channel`` and store the result
1836
+ in a ``register``.
1837
+
1838
+ Examples:
1839
+
1840
+ .. code-block::
1841
+
1842
+ from qiskit import pulse
1843
+
1844
+ acq0 = pulse.AcquireChannel(0)
1845
+ mem0 = pulse.MemorySlot(0)
1846
+
1847
+ with pulse.build() as pulse_prog:
1848
+ pulse.acquire(100, acq0, mem0)
1849
+
1850
+ # measurement metadata
1851
+ kernel = pulse.configuration.Kernel('linear_discriminator')
1852
+ pulse.acquire(100, acq0, mem0, kernel=kernel)
1853
+
1854
+ .. note:: The type of data acquire will depend on the execution ``meas_level``.
1855
+
1856
+ Args:
1857
+ duration: Duration to acquire data for
1858
+ qubit_or_channel: Either the qubit to acquire data for or the specific
1859
+ :class:`~qiskit.pulse.channels.AcquireChannel` to acquire on.
1860
+ register: Location to store measured result.
1861
+ metadata: Additional metadata for measurement. See
1862
+ :class:`~qiskit.pulse.instructions.Acquire` for more information.
1863
+
1864
+ Raises:
1865
+ exceptions.PulseError: If the register type is not supported.
1866
+ """
1867
+ if isinstance(qubit_or_channel, int):
1868
+ qubit_or_channel = chans.AcquireChannel(qubit_or_channel)
1869
+
1870
+ if isinstance(register, chans.MemorySlot):
1871
+ append_instruction(
1872
+ instructions.Acquire(duration, qubit_or_channel, mem_slot=register, **metadata)
1873
+ )
1874
+ elif isinstance(register, chans.RegisterSlot):
1875
+ append_instruction(
1876
+ instructions.Acquire(duration, qubit_or_channel, reg_slot=register, **metadata)
1877
+ )
1878
+ else:
1879
+ raise exceptions.PulseError(f'Register of type: "{type(register)}" is not supported')
1880
+
1881
+
1882
+ def set_frequency(frequency: float, channel: chans.PulseChannel, name: Optional[str] = None):
1883
+ """Set the ``frequency`` of a pulse ``channel``.
1884
+
1885
+ Examples:
1886
+
1887
+ .. code-block::
1888
+
1889
+ from qiskit import pulse
1890
+
1891
+ d0 = pulse.DriveChannel(0)
1892
+
1893
+ with pulse.build() as pulse_prog:
1894
+ pulse.set_frequency(1e9, d0)
1895
+
1896
+ Args:
1897
+ frequency: Frequency in Hz to set channel to.
1898
+ channel: Channel to set frequency of.
1899
+ name: Name of the instruction.
1900
+ """
1901
+ append_instruction(instructions.SetFrequency(frequency, channel, name=name))
1902
+
1903
+
1904
+ def shift_frequency(frequency: float, channel: chans.PulseChannel, name: Optional[str] = None):
1905
+ """Shift the ``frequency`` of a pulse ``channel``.
1906
+
1907
+ Examples:
1908
+
1909
+ .. code-block:: python
1910
+ :emphasize-lines: 6
1911
+
1912
+ from qiskit import pulse
1913
+
1914
+ d0 = pulse.DriveChannel(0)
1915
+
1916
+ with pulse.build() as pulse_prog:
1917
+ pulse.shift_frequency(1e9, d0)
1918
+
1919
+ Args:
1920
+ frequency: Frequency in Hz to shift channel frequency by.
1921
+ channel: Channel to shift frequency of.
1922
+ name: Name of the instruction.
1923
+ """
1924
+ append_instruction(instructions.ShiftFrequency(frequency, channel, name=name))
1925
+
1926
+
1927
+ def set_phase(phase: float, channel: chans.PulseChannel, name: Optional[str] = None):
1928
+ """Set the ``phase`` of a pulse ``channel``.
1929
+
1930
+ Examples:
1931
+
1932
+ .. code-block:: python
1933
+ :emphasize-lines: 8
1934
+
1935
+ import math
1936
+
1937
+ from qiskit import pulse
1938
+
1939
+ d0 = pulse.DriveChannel(0)
1940
+
1941
+ with pulse.build() as pulse_prog:
1942
+ pulse.set_phase(math.pi, d0)
1943
+
1944
+ Args:
1945
+ phase: Phase in radians to set channel carrier signal to.
1946
+ channel: Channel to set phase of.
1947
+ name: Name of the instruction.
1948
+ """
1949
+ append_instruction(instructions.SetPhase(phase, channel, name=name))
1950
+
1951
+
1952
+ def shift_phase(phase: float, channel: chans.PulseChannel, name: Optional[str] = None):
1953
+ """Shift the ``phase`` of a pulse ``channel``.
1954
+
1955
+ Examples:
1956
+
1957
+ .. code-block::
1958
+
1959
+ import math
1960
+
1961
+ from qiskit import pulse
1962
+
1963
+ d0 = pulse.DriveChannel(0)
1964
+
1965
+ with pulse.build() as pulse_prog:
1966
+ pulse.shift_phase(math.pi, d0)
1967
+
1968
+ Args:
1969
+ phase: Phase in radians to shift channel carrier signal by.
1970
+ channel: Channel to shift phase of.
1971
+ name: Name of the instruction.
1972
+ """
1973
+ append_instruction(instructions.ShiftPhase(phase, channel, name))
1974
+
1975
+
1976
+ def snapshot(label: str, snapshot_type: str = "statevector"):
1977
+ """Simulator snapshot.
1978
+
1979
+ Examples:
1980
+
1981
+ .. code-block::
1982
+
1983
+ from qiskit import pulse
1984
+
1985
+ with pulse.build() as pulse_prog:
1986
+ pulse.snapshot('first', 'statevector')
1987
+
1988
+ Args:
1989
+ label: Label for snapshot.
1990
+ snapshot_type: Type of snapshot.
1991
+ """
1992
+ append_instruction(instructions.Snapshot(label, snapshot_type=snapshot_type))
1993
+
1994
+
1995
+ def call(
1996
+ target: Optional[Union[circuit.QuantumCircuit, Schedule, ScheduleBlock]],
1997
+ name: Optional[str] = None,
1998
+ value_dict: Optional[Dict[ParameterValueType, ParameterValueType]] = None,
1999
+ **kw_params: ParameterValueType,
2000
+ ):
2001
+ """Call the subroutine within the currently active builder context with arbitrary
2002
+ parameters which will be assigned to the target program.
2003
+
2004
+ .. note::
2005
+
2006
+ If the ``target`` program is a :class:`.ScheduleBlock`, then a :class:`.Reference`
2007
+ instruction will be created and appended to the current context.
2008
+ The ``target`` program will be immediately assigned to the current scope as a subroutine.
2009
+ If the ``target`` program is :class:`.Schedule`, it will be wrapped by the
2010
+ :class:`.Call` instruction and appended to the current context to avoid
2011
+ a mixed representation of :class:`.ScheduleBlock` and :class:`.Schedule`.
2012
+ If the ``target`` program is a :class:`.QuantumCircuit` it will be scheduled
2013
+ and the new :class:`.Schedule` will be added as a :class:`.Call` instruction.
2014
+
2015
+ Examples:
2016
+
2017
+ 1. Calling a schedule block (recommended)
2018
+
2019
+ .. code-block::
2020
+
2021
+ from qiskit import circuit, pulse
2022
+ from qiskit.providers.fake_provider import FakeBogotaV2
2023
+
2024
+ backend = FakeBogotaV2()
2025
+
2026
+ with pulse.build() as x_sched:
2027
+ pulse.play(pulse.Gaussian(160, 0.1, 40), pulse.DriveChannel(0))
2028
+
2029
+ with pulse.build() as pulse_prog:
2030
+ pulse.call(x_sched)
2031
+
2032
+ print(pulse_prog)
2033
+
2034
+ .. parsed-literal::
2035
+
2036
+ ScheduleBlock(
2037
+ ScheduleBlock(
2038
+ Play(
2039
+ Gaussian(duration=160, amp=(0.1+0j), sigma=40),
2040
+ DriveChannel(0)
2041
+ ),
2042
+ name="block0",
2043
+ transform=AlignLeft()
2044
+ ),
2045
+ name="block1",
2046
+ transform=AlignLeft()
2047
+ )
2048
+
2049
+ The actual program is stored in the reference table attached to the schedule.
2050
+
2051
+ .. code-block::
2052
+
2053
+ print(pulse_prog.references)
2054
+
2055
+ .. parsed-literal::
2056
+
2057
+ ReferenceManager:
2058
+ - ('block0', '634b3b50bd684e26a673af1fbd2d6c81'): ScheduleBlock(Play(Gaussian(...
2059
+
2060
+ In addition, you can call a parameterized target program with parameter assignment.
2061
+
2062
+ .. code-block::
2063
+
2064
+ amp = circuit.Parameter("amp")
2065
+
2066
+ with pulse.build() as subroutine:
2067
+ pulse.play(pulse.Gaussian(160, amp, 40), pulse.DriveChannel(0))
2068
+
2069
+ with pulse.build() as pulse_prog:
2070
+ pulse.call(subroutine, amp=0.1)
2071
+ pulse.call(subroutine, amp=0.3)
2072
+
2073
+ print(pulse_prog)
2074
+
2075
+ .. parsed-literal::
2076
+
2077
+ ScheduleBlock(
2078
+ ScheduleBlock(
2079
+ Play(
2080
+ Gaussian(duration=160, amp=(0.1+0j), sigma=40),
2081
+ DriveChannel(0)
2082
+ ),
2083
+ name="block2",
2084
+ transform=AlignLeft()
2085
+ ),
2086
+ ScheduleBlock(
2087
+ Play(
2088
+ Gaussian(duration=160, amp=(0.3+0j), sigma=40),
2089
+ DriveChannel(0)
2090
+ ),
2091
+ name="block2",
2092
+ transform=AlignLeft()
2093
+ ),
2094
+ name="block3",
2095
+ transform=AlignLeft()
2096
+ )
2097
+
2098
+ If there is a name collision between parameters, you can distinguish them by specifying
2099
+ each parameter object in a python dictionary. For example,
2100
+
2101
+ .. code-block::
2102
+
2103
+ amp1 = circuit.Parameter('amp')
2104
+ amp2 = circuit.Parameter('amp')
2105
+
2106
+ with pulse.build() as subroutine:
2107
+ pulse.play(pulse.Gaussian(160, amp1, 40), pulse.DriveChannel(0))
2108
+ pulse.play(pulse.Gaussian(160, amp2, 40), pulse.DriveChannel(1))
2109
+
2110
+ with pulse.build() as pulse_prog:
2111
+ pulse.call(subroutine, value_dict={amp1: 0.1, amp2: 0.3})
2112
+
2113
+ print(pulse_prog)
2114
+
2115
+ .. parsed-literal::
2116
+
2117
+ ScheduleBlock(
2118
+ ScheduleBlock(
2119
+ Play(Gaussian(duration=160, amp=(0.1+0j), sigma=40), DriveChannel(0)),
2120
+ Play(Gaussian(duration=160, amp=(0.3+0j), sigma=40), DriveChannel(1)),
2121
+ name="block4",
2122
+ transform=AlignLeft()
2123
+ ),
2124
+ name="block5",
2125
+ transform=AlignLeft()
2126
+ )
2127
+
2128
+ 2. Calling a schedule
2129
+
2130
+ .. code-block::
2131
+
2132
+ x_sched = backend.instruction_schedule_map.get("x", (0,))
2133
+
2134
+ with pulse.build(backend) as pulse_prog:
2135
+ pulse.call(x_sched)
2136
+
2137
+ print(pulse_prog)
2138
+
2139
+ .. parsed-literal::
2140
+
2141
+ ScheduleBlock(
2142
+ Call(
2143
+ Schedule(
2144
+ (
2145
+ 0,
2146
+ Play(
2147
+ Drag(
2148
+ duration=160,
2149
+ amp=(0.18989731546729305+0j),
2150
+ sigma=40,
2151
+ beta=-1.201258305015517,
2152
+ name='drag_86a8'
2153
+ ),
2154
+ DriveChannel(0),
2155
+ name='drag_86a8'
2156
+ )
2157
+ ),
2158
+ name="x"
2159
+ ),
2160
+ name='x'
2161
+ ),
2162
+ name="block6",
2163
+ transform=AlignLeft()
2164
+ )
2165
+
2166
+ Currently, the backend calibrated gates are provided in the form of :class:`~.Schedule`.
2167
+ The parameter assignment mechanism is available also for schedules.
2168
+ However, the called schedule is not treated as a reference.
2169
+
2170
+ 3. Calling a quantum circuit
2171
+
2172
+ .. code-block::
2173
+
2174
+ backend = FakeBogotaV2()
2175
+
2176
+ qc = circuit.QuantumCircuit(1)
2177
+ qc.x(0)
2178
+
2179
+ with pulse.build(backend) as pulse_prog:
2180
+ pulse.call(qc)
2181
+
2182
+ print(pulse_prog)
2183
+
2184
+ .. parsed-literal::
2185
+
2186
+ ScheduleBlock(
2187
+ Call(
2188
+ Schedule(
2189
+ (
2190
+ 0,
2191
+ Play(
2192
+ Drag(
2193
+ duration=160,
2194
+ amp=(0.18989731546729305+0j),
2195
+ sigma=40,
2196
+ beta=-1.201258305015517,
2197
+ name='drag_86a8'
2198
+ ),
2199
+ DriveChannel(0),
2200
+ name='drag_86a8'
2201
+ )
2202
+ ),
2203
+ name="circuit-87"
2204
+ ),
2205
+ name='circuit-87'
2206
+ ),
2207
+ name="block7",
2208
+ transform=AlignLeft()
2209
+ )
2210
+
2211
+ .. warning::
2212
+
2213
+ Calling a circuit from a schedule is not encouraged. Currently, the Qiskit execution model
2214
+ is migrating toward the pulse gate model, where schedules are attached to
2215
+ circuits through the :meth:`.QuantumCircuit.add_calibration` method.
2216
+
2217
+ Args:
2218
+ target: Target circuit or pulse schedule to call.
2219
+ name: Optional. A unique name of subroutine if defined. When the name is explicitly
2220
+ provided, one cannot call different schedule blocks with the same name.
2221
+ value_dict: Optional. Parameters assigned to the ``target`` program.
2222
+ If this dictionary is provided, the ``target`` program is copied and
2223
+ then stored in the main built schedule and its parameters are assigned to the given values.
2224
+ This dictionary is keyed on :class:`~.Parameter` objects,
2225
+ allowing parameter name collision to be avoided.
2226
+ kw_params: Alternative way to provide parameters.
2227
+ Since this is keyed on the string parameter name,
2228
+ the parameters having the same name are all updated together.
2229
+ If you want to avoid name collision, use ``value_dict`` with :class:`~.Parameter`
2230
+ objects instead.
2231
+ """
2232
+ _active_builder().call_subroutine(target, name, value_dict, **kw_params)
2233
+
2234
+
2235
+ def reference(name: str, *extra_keys: str):
2236
+ """Refer to undefined subroutine by string keys.
2237
+
2238
+ A :class:`~qiskit.pulse.instructions.Reference` instruction is implicitly created
2239
+ and a schedule can be separately registered to the reference at a later stage.
2240
+
2241
+ .. code-block:: python
2242
+
2243
+ from qiskit import pulse
2244
+
2245
+ with pulse.build() as main_prog:
2246
+ pulse.reference("x_gate", "q0")
2247
+
2248
+ with pulse.build() as subroutine:
2249
+ pulse.play(pulse.Gaussian(160, 0.1, 40), pulse.DriveChannel(0))
2250
+
2251
+ main_prog.assign_references(subroutine_dict={("x_gate", "q0"): subroutine})
2252
+
2253
+ Args:
2254
+ name: Name of subroutine.
2255
+ extra_keys: Helper keys to uniquely specify the subroutine.
2256
+ """
2257
+ _active_builder().append_reference(name, *extra_keys)
2258
+
2259
+
2260
+ # Directives
2261
+ def barrier(*channels_or_qubits: Union[chans.Channel, int], name: Optional[str] = None):
2262
+ """Barrier directive for a set of channels and qubits.
2263
+
2264
+ This directive prevents the compiler from moving instructions across
2265
+ the barrier. Consider the case where we want to enforce that one pulse
2266
+ happens after another on separate channels, this can be done with:
2267
+
2268
+ .. code-block::
2269
+
2270
+ from qiskit import pulse
2271
+ from qiskit.providers.fake_provider import FakeOpenPulse2Q
2272
+
2273
+ backend = FakeOpenPulse2Q()
2274
+
2275
+ d0 = pulse.DriveChannel(0)
2276
+ d1 = pulse.DriveChannel(1)
2277
+
2278
+ with pulse.build(backend) as barrier_pulse_prog:
2279
+ pulse.play(pulse.Constant(10, 1.0), d0)
2280
+ pulse.barrier(d0, d1)
2281
+ pulse.play(pulse.Constant(10, 1.0), d1)
2282
+
2283
+ Of course this could have been accomplished with:
2284
+
2285
+ .. code-block::
2286
+
2287
+ from qiskit.pulse import transforms
2288
+
2289
+ with pulse.build(backend) as aligned_pulse_prog:
2290
+ with pulse.align_sequential():
2291
+ pulse.play(pulse.Constant(10, 1.0), d0)
2292
+ pulse.play(pulse.Constant(10, 1.0), d1)
2293
+
2294
+ barrier_pulse_prog = transforms.target_qobj_transform(barrier_pulse_prog)
2295
+ aligned_pulse_prog = transforms.target_qobj_transform(aligned_pulse_prog)
2296
+
2297
+ assert barrier_pulse_prog == aligned_pulse_prog
2298
+
2299
+ The barrier allows the pulse compiler to take care of more advanced
2300
+ scheduling alignment operations across channels. For example
2301
+ in the case where we are calling an outside circuit or schedule and
2302
+ want to align a pulse at the end of one call:
2303
+
2304
+ .. code-block::
2305
+
2306
+ import math
2307
+
2308
+ d0 = pulse.DriveChannel(0)
2309
+
2310
+ with pulse.build(backend) as pulse_prog:
2311
+ with pulse.align_right():
2312
+ pulse.x(1)
2313
+ # Barrier qubit 1 and d0.
2314
+ pulse.barrier(1, d0)
2315
+ # Due to barrier this will play before the gate on qubit 1.
2316
+ pulse.play(pulse.Constant(10, 1.0), d0)
2317
+ # This will end at the same time as the pulse above due to
2318
+ # the barrier.
2319
+ pulse.x(1)
2320
+
2321
+ .. note:: Requires the active builder context to have a backend set if
2322
+ qubits are barriered on.
2323
+
2324
+ Args:
2325
+ channels_or_qubits: Channels or qubits to barrier.
2326
+ name: Name for the barrier
2327
+ """
2328
+ channels = _qubits_to_channels(*channels_or_qubits)
2329
+ if len(channels) > 1:
2330
+ append_instruction(directives.RelativeBarrier(*channels, name=name))
2331
+
2332
+
2333
+ # Macros
2334
+ def macro(func: Callable):
2335
+ """Wrap a Python function and activate the parent builder context at calling time.
2336
+
2337
+ This enables embedding Python functions as builder macros. This generates a new
2338
+ :class:`pulse.Schedule` that is embedded in the parent builder context with
2339
+ every call of the decorated macro function. The decorated macro function will
2340
+ behave as if the function code was embedded inline in the parent builder context
2341
+ after parameter substitution.
2342
+
2343
+
2344
+ Examples:
2345
+
2346
+ .. plot::
2347
+ :include-source:
2348
+
2349
+ from qiskit import pulse
2350
+
2351
+ @pulse.macro
2352
+ def measure(qubit: int):
2353
+ pulse.play(pulse.GaussianSquare(16384, 256, 15872), pulse.measure_channel(qubit))
2354
+ mem_slot = pulse.MemorySlot(qubit)
2355
+ pulse.acquire(16384, pulse.acquire_channel(qubit), mem_slot)
2356
+
2357
+ return mem_slot
2358
+
2359
+ with pulse.build(backend=backend) as sched:
2360
+ mem_slot = measure(0)
2361
+ print(f"Qubit measured into {mem_slot}")
2362
+
2363
+ sched.draw()
2364
+
2365
+
2366
+ Args:
2367
+ func: The Python function to enable as a builder macro. There are no
2368
+ requirements on the signature of the function, any calls to pulse
2369
+ builder methods will be added to builder context the wrapped function
2370
+ is called from.
2371
+
2372
+ Returns:
2373
+ Callable: The wrapped ``func``.
2374
+ """
2375
+ func_name = getattr(func, "__name__", repr(func))
2376
+
2377
+ @functools.wraps(func)
2378
+ def wrapper(*args, **kwargs):
2379
+ _builder = _active_builder()
2380
+ # activate the pulse builder before calling the function
2381
+ with build(backend=_builder.backend, name=func_name) as built:
2382
+ output = func(*args, **kwargs)
2383
+
2384
+ _builder.call_subroutine(built)
2385
+ return output
2386
+
2387
+ return wrapper
2388
+
2389
+
2390
+ def measure(
2391
+ qubits: Union[List[int], int],
2392
+ registers: Union[List[StorageLocation], StorageLocation] = None,
2393
+ ) -> Union[List[StorageLocation], StorageLocation]:
2394
+ """Measure a qubit within the currently active builder context.
2395
+
2396
+ At the pulse level a measurement is composed of both a stimulus pulse and
2397
+ an acquisition instruction which tells the systems measurement unit to
2398
+ acquire data and process it. We provide this measurement macro to automate
2399
+ the process for you, but if desired full control is still available with
2400
+ :func:`acquire` and :func:`play`.
2401
+
2402
+ To use the measurement it is as simple as specifying the qubit you wish to
2403
+ measure:
2404
+
2405
+ .. code-block::
2406
+
2407
+ from qiskit import pulse
2408
+ from qiskit.providers.fake_provider import FakeOpenPulse2Q
2409
+
2410
+ backend = FakeOpenPulse2Q()
2411
+
2412
+ qubit = 0
2413
+
2414
+ with pulse.build(backend) as pulse_prog:
2415
+ # Do something to the qubit.
2416
+ qubit_drive_chan = pulse.drive_channel(0)
2417
+ pulse.play(pulse.Constant(100, 1.0), qubit_drive_chan)
2418
+ # Measure the qubit.
2419
+ reg = pulse.measure(qubit)
2420
+
2421
+ For now it is not possible to do much with the handle to ``reg`` but in the
2422
+ future we will support using this handle to a result register to build
2423
+ up ones program. It is also possible to supply this register:
2424
+
2425
+ .. code-block::
2426
+
2427
+ with pulse.build(backend) as pulse_prog:
2428
+ pulse.play(pulse.Constant(100, 1.0), qubit_drive_chan)
2429
+ # Measure the qubit.
2430
+ mem0 = pulse.MemorySlot(0)
2431
+ reg = pulse.measure(qubit, mem0)
2432
+
2433
+ assert reg == mem0
2434
+
2435
+ .. note:: Requires the active builder context to have a backend set.
2436
+
2437
+ Args:
2438
+ qubits: Physical qubit to measure.
2439
+ registers: Register to store result in. If not selected the current
2440
+ behavior is to return the :class:`MemorySlot` with the same
2441
+ index as ``qubit``. This register will be returned.
2442
+ Returns:
2443
+ The ``register`` the qubit measurement result will be stored in.
2444
+ """
2445
+ backend = active_backend()
2446
+
2447
+ try:
2448
+ qubits = list(qubits)
2449
+ except TypeError:
2450
+ qubits = [qubits]
2451
+
2452
+ if registers is None:
2453
+ registers = [chans.MemorySlot(qubit) for qubit in qubits]
2454
+ else:
2455
+ try:
2456
+ registers = list(registers)
2457
+ except TypeError:
2458
+ registers = [registers]
2459
+ measure_sched = macros.measure(
2460
+ qubits=qubits,
2461
+ backend=backend,
2462
+ qubit_mem_slots={qubit: register.index for qubit, register in zip(qubits, registers)},
2463
+ )
2464
+
2465
+ # note this is not a subroutine.
2466
+ # just a macro to automate combination of stimulus and acquisition.
2467
+ # prepare unique reference name based on qubit and memory slot index.
2468
+ qubits_repr = "&".join(map(str, qubits))
2469
+ mslots_repr = "&".join((str(r.index) for r in registers))
2470
+ _active_builder().call_subroutine(measure_sched, name=f"measure_{qubits_repr}..{mslots_repr}")
2471
+
2472
+ if len(qubits) == 1:
2473
+ return registers[0]
2474
+ else:
2475
+ return registers
2476
+
2477
+
2478
+ def measure_all() -> List[chans.MemorySlot]:
2479
+ r"""Measure all qubits within the currently active builder context.
2480
+
2481
+ A simple macro function to measure all of the qubits in the device at the
2482
+ same time. This is useful for handling device ``meas_map`` and single
2483
+ measurement constraints.
2484
+
2485
+ Examples:
2486
+
2487
+ .. code-block::
2488
+
2489
+ from qiskit import pulse
2490
+ from qiskit.providers.fake_provider import FakeOpenPulse2Q
2491
+
2492
+ backend = FakeOpenPulse2Q()
2493
+
2494
+ with pulse.build(backend) as pulse_prog:
2495
+ # Measure all qubits and return associated registers.
2496
+ regs = pulse.measure_all()
2497
+
2498
+ .. note::
2499
+ Requires the active builder context to have a backend set.
2500
+
2501
+ Returns:
2502
+ The ``register``\s the qubit measurement results will be stored in.
2503
+ """
2504
+ backend = active_backend()
2505
+ qubits = range(num_qubits())
2506
+ registers = [chans.MemorySlot(qubit) for qubit in qubits]
2507
+
2508
+ measure_sched = macros.measure(
2509
+ qubits=qubits,
2510
+ backend=backend,
2511
+ qubit_mem_slots={qubit: qubit for qubit in qubits},
2512
+ )
2513
+
2514
+ # note this is not a subroutine.
2515
+ # just a macro to automate combination of stimulus and acquisition.
2516
+ _active_builder().call_subroutine(measure_sched, name="measure_all")
2517
+
2518
+ return registers
2519
+
2520
+
2521
+ def delay_qubits(duration: int, *qubits: Union[int, Iterable[int]]):
2522
+ r"""Insert delays on all of the :class:`channels.Channel`\s that correspond
2523
+ to the input ``qubits`` at the same time.
2524
+
2525
+ Examples:
2526
+
2527
+ .. code-block::
2528
+
2529
+ from qiskit import pulse
2530
+ from qiskit.providers.fake_provider import FakeOpenPulse3Q
2531
+
2532
+ backend = FakeOpenPulse3Q()
2533
+
2534
+ with pulse.build(backend) as pulse_prog:
2535
+ # Delay for 100 cycles on qubits 0, 1 and 2.
2536
+ regs = pulse.delay_qubits(100, 0, 1, 2)
2537
+
2538
+ .. note:: Requires the active builder context to have a backend set.
2539
+
2540
+ Args:
2541
+ duration: Duration to delay for.
2542
+ qubits: Physical qubits to delay on. Delays will be inserted based on
2543
+ the channels returned by :func:`pulse.qubit_channels`.
2544
+ """
2545
+ qubit_chans = set(itertools.chain.from_iterable(qubit_channels(qubit) for qubit in qubits))
2546
+ with align_left():
2547
+ for chan in qubit_chans:
2548
+ delay(duration, chan)
2549
+
2550
+
2551
+ # Gate instructions
2552
+ def call_gate(gate: circuit.Gate, qubits: Tuple[int, ...], lazy: bool = True):
2553
+ """Call a gate and lazily schedule it to its corresponding
2554
+ pulse instruction.
2555
+
2556
+ .. note::
2557
+ Calling gates directly within the pulse builder namespace will be
2558
+ deprecated in the future in favor of tight integration with a circuit
2559
+ builder interface which is under development.
2560
+
2561
+ Examples:
2562
+
2563
+ .. code-block::
2564
+
2565
+ from qiskit import pulse
2566
+ from qiskit.pulse import builder
2567
+ from qiskit.circuit.library import standard_gates as gates
2568
+ from qiskit.providers.fake_provider import FakeOpenPulse2Q
2569
+
2570
+ backend = FakeOpenPulse2Q()
2571
+
2572
+ with pulse.build(backend) as pulse_prog:
2573
+ builder.call_gate(gates.CXGate(), (0, 1))
2574
+
2575
+ We can see the role of the transpiler in scheduling gates by optimizing
2576
+ away two consecutive CNOT gates:
2577
+
2578
+ .. code-block::
2579
+
2580
+ with pulse.build(backend) as pulse_prog:
2581
+ with pulse.transpiler_settings(optimization_level=3):
2582
+ builder.call_gate(gates.CXGate(), (0, 1))
2583
+ builder.call_gate(gates.CXGate(), (0, 1))
2584
+
2585
+ assert pulse_prog == pulse.Schedule()
2586
+
2587
+ .. note:: If multiple gates are called in a row they may be optimized by
2588
+ the transpiler, depending on the
2589
+ :func:`pulse.active_transpiler_settings``.
2590
+
2591
+ .. note:: Requires the active builder context to have a backend set.
2592
+
2593
+ Args:
2594
+ gate: Circuit gate instance to call.
2595
+ qubits: Qubits to call gate on.
2596
+ lazy: If ``false`` the gate will be compiled immediately, otherwise
2597
+ it will be added onto a lazily evaluated quantum circuit to be
2598
+ compiled when the builder is forced to by a circuit assumption
2599
+ being broken, such as the inclusion of a pulse instruction or
2600
+ new alignment context.
2601
+ """
2602
+ _active_builder().call_gate(gate, qubits, lazy=lazy)
2603
+
2604
+
2605
+ def cx(control: int, target: int): # pylint: disable=invalid-name
2606
+ """Call a :class:`~qiskit.circuit.library.standard_gates.CXGate` on the
2607
+ input physical qubits.
2608
+
2609
+ .. note::
2610
+ Calling gates directly within the pulse builder namespace will be
2611
+ deprecated in the future in favor of tight integration with a circuit
2612
+ builder interface which is under development.
2613
+
2614
+ Examples:
2615
+
2616
+ .. code-block::
2617
+
2618
+ from qiskit import pulse
2619
+ from qiskit.providers.fake_provider import FakeOpenPulse2Q
2620
+
2621
+ backend = FakeOpenPulse2Q()
2622
+
2623
+ with pulse.build(backend) as pulse_prog:
2624
+ pulse.cx(0, 1)
2625
+
2626
+ """
2627
+ call_gate(gates.CXGate(), (control, target))
2628
+
2629
+
2630
+ def u1(theta: float, qubit: int): # pylint: disable=invalid-name
2631
+ """Call a :class:`~qiskit.circuit.library.standard_gates.U1Gate` on the
2632
+ input physical qubit.
2633
+
2634
+ .. note::
2635
+ Calling gates directly within the pulse builder namespace will be
2636
+ deprecated in the future in favor of tight integration with a circuit
2637
+ builder interface which is under development.
2638
+
2639
+ Examples:
2640
+
2641
+ .. code-block::
2642
+
2643
+ import math
2644
+
2645
+ from qiskit import pulse
2646
+ from qiskit.providers.fake_provider import FakeOpenPulse2Q
2647
+
2648
+ backend = FakeOpenPulse2Q()
2649
+
2650
+ with pulse.build(backend) as pulse_prog:
2651
+ pulse.u1(math.pi, 1)
2652
+
2653
+ """
2654
+ call_gate(gates.U1Gate(theta), qubit)
2655
+
2656
+
2657
+ def u2(phi: float, lam: float, qubit: int): # pylint: disable=invalid-name
2658
+ """Call a :class:`~qiskit.circuit.library.standard_gates.U2Gate` on the
2659
+ input physical qubit.
2660
+
2661
+ .. note::
2662
+ Calling gates directly within the pulse builder namespace will be
2663
+ deprecated in the future in favor of tight integration with a circuit
2664
+ builder interface which is under development.
2665
+
2666
+ Examples:
2667
+
2668
+ .. code-block::
2669
+
2670
+ import math
2671
+
2672
+ from qiskit import pulse
2673
+ from qiskit.providers.fake_provider import FakeOpenPulse2Q
2674
+
2675
+ backend = FakeOpenPulse2Q()
2676
+
2677
+ with pulse.build(backend) as pulse_prog:
2678
+ pulse.u2(0, math.pi, 1)
2679
+
2680
+ """
2681
+ call_gate(gates.U2Gate(phi, lam), qubit)
2682
+
2683
+
2684
+ def u3(theta: float, phi: float, lam: float, qubit: int): # pylint: disable=invalid-name
2685
+ """Call a :class:`~qiskit.circuit.library.standard_gates.U3Gate` on the
2686
+ input physical qubit.
2687
+
2688
+ .. note::
2689
+ Calling gates directly within the pulse builder namespace will be
2690
+ deprecated in the future in favor of tight integration with a circuit
2691
+ builder interface which is under development.
2692
+
2693
+ Examples:
2694
+
2695
+ .. code-block::
2696
+
2697
+ import math
2698
+
2699
+ from qiskit import pulse
2700
+ from qiskit.providers.fake_provider import FakeOpenPulse2Q
2701
+
2702
+ backend = FakeOpenPulse2Q()
2703
+
2704
+ with pulse.build(backend) as pulse_prog:
2705
+ pulse.u3(math.pi, 0, math.pi, 1)
2706
+
2707
+ """
2708
+ call_gate(gates.U3Gate(theta, phi, lam), qubit)
2709
+
2710
+
2711
+ def x(qubit: int):
2712
+ """Call a :class:`~qiskit.circuit.library.standard_gates.XGate` on the
2713
+ input physical qubit.
2714
+
2715
+ .. note::
2716
+ Calling gates directly within the pulse builder namespace will be
2717
+ deprecated in the future in favor of tight integration with a circuit
2718
+ builder interface which is under development.
2719
+
2720
+ Examples:
2721
+
2722
+ .. code-block::
2723
+
2724
+ from qiskit import pulse
2725
+ from qiskit.providers.fake_provider import FakeOpenPulse2Q
2726
+
2727
+ backend = FakeOpenPulse2Q()
2728
+
2729
+ with pulse.build(backend) as pulse_prog:
2730
+ pulse.x(0)
2731
+
2732
+ """
2733
+ call_gate(gates.XGate(), qubit)