qiskit 1.3.0__cp39-abi3-macosx_11_0_arm64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (836) hide show
  1. qiskit/VERSION.txt +1 -0
  2. qiskit/__init__.py +146 -0
  3. qiskit/_accelerate.abi3.so +0 -0
  4. qiskit/_numpy_compat.py +73 -0
  5. qiskit/assembler/__init__.py +42 -0
  6. qiskit/assembler/assemble_circuits.py +451 -0
  7. qiskit/assembler/assemble_schedules.py +367 -0
  8. qiskit/assembler/disassemble.py +310 -0
  9. qiskit/assembler/run_config.py +77 -0
  10. qiskit/circuit/__init__.py +1313 -0
  11. qiskit/circuit/_classical_resource_map.py +148 -0
  12. qiskit/circuit/_standard_gates_commutations.py +3849 -0
  13. qiskit/circuit/_utils.py +167 -0
  14. qiskit/circuit/add_control.py +274 -0
  15. qiskit/circuit/annotated_operation.py +279 -0
  16. qiskit/circuit/barrier.py +50 -0
  17. qiskit/circuit/bit.py +94 -0
  18. qiskit/circuit/classical/__init__.py +41 -0
  19. qiskit/circuit/classical/expr/__init__.py +238 -0
  20. qiskit/circuit/classical/expr/constructors.py +556 -0
  21. qiskit/circuit/classical/expr/expr.py +397 -0
  22. qiskit/circuit/classical/expr/visitors.py +300 -0
  23. qiskit/circuit/classical/types/__init__.py +109 -0
  24. qiskit/circuit/classical/types/ordering.py +222 -0
  25. qiskit/circuit/classical/types/types.py +117 -0
  26. qiskit/circuit/classicalfunction/__init__.py +140 -0
  27. qiskit/circuit/classicalfunction/boolean_expression.py +129 -0
  28. qiskit/circuit/classicalfunction/classical_element.py +54 -0
  29. qiskit/circuit/classicalfunction/classical_function_visitor.py +155 -0
  30. qiskit/circuit/classicalfunction/classicalfunction.py +173 -0
  31. qiskit/circuit/classicalfunction/exceptions.py +35 -0
  32. qiskit/circuit/classicalfunction/types.py +18 -0
  33. qiskit/circuit/classicalfunction/utils.py +91 -0
  34. qiskit/circuit/classicalregister.py +57 -0
  35. qiskit/circuit/commutation_checker.py +106 -0
  36. qiskit/circuit/commutation_library.py +20 -0
  37. qiskit/circuit/controlflow/__init__.py +28 -0
  38. qiskit/circuit/controlflow/_builder_utils.py +207 -0
  39. qiskit/circuit/controlflow/break_loop.py +56 -0
  40. qiskit/circuit/controlflow/builder.py +691 -0
  41. qiskit/circuit/controlflow/continue_loop.py +58 -0
  42. qiskit/circuit/controlflow/control_flow.py +84 -0
  43. qiskit/circuit/controlflow/for_loop.py +217 -0
  44. qiskit/circuit/controlflow/if_else.py +511 -0
  45. qiskit/circuit/controlflow/switch_case.py +417 -0
  46. qiskit/circuit/controlflow/while_loop.py +171 -0
  47. qiskit/circuit/controlledgate.py +274 -0
  48. qiskit/circuit/delay.py +123 -0
  49. qiskit/circuit/duration.py +95 -0
  50. qiskit/circuit/equivalence.py +94 -0
  51. qiskit/circuit/equivalence_library.py +18 -0
  52. qiskit/circuit/exceptions.py +19 -0
  53. qiskit/circuit/gate.py +263 -0
  54. qiskit/circuit/instruction.py +697 -0
  55. qiskit/circuit/instructionset.py +179 -0
  56. qiskit/circuit/library/__init__.py +668 -0
  57. qiskit/circuit/library/arithmetic/__init__.py +34 -0
  58. qiskit/circuit/library/arithmetic/adders/__init__.py +18 -0
  59. qiskit/circuit/library/arithmetic/adders/adder.py +210 -0
  60. qiskit/circuit/library/arithmetic/adders/cdkm_ripple_carry_adder.py +123 -0
  61. qiskit/circuit/library/arithmetic/adders/draper_qft_adder.py +129 -0
  62. qiskit/circuit/library/arithmetic/adders/vbe_ripple_carry_adder.py +95 -0
  63. qiskit/circuit/library/arithmetic/exact_reciprocal.py +88 -0
  64. qiskit/circuit/library/arithmetic/functional_pauli_rotations.py +114 -0
  65. qiskit/circuit/library/arithmetic/integer_comparator.py +243 -0
  66. qiskit/circuit/library/arithmetic/linear_amplitude_function.py +196 -0
  67. qiskit/circuit/library/arithmetic/linear_pauli_rotations.py +189 -0
  68. qiskit/circuit/library/arithmetic/multipliers/__init__.py +17 -0
  69. qiskit/circuit/library/arithmetic/multipliers/hrs_cumulative_multiplier.py +145 -0
  70. qiskit/circuit/library/arithmetic/multipliers/multiplier.py +192 -0
  71. qiskit/circuit/library/arithmetic/multipliers/rg_qft_multiplier.py +108 -0
  72. qiskit/circuit/library/arithmetic/piecewise_chebyshev.py +353 -0
  73. qiskit/circuit/library/arithmetic/piecewise_linear_pauli_rotations.py +277 -0
  74. qiskit/circuit/library/arithmetic/piecewise_polynomial_pauli_rotations.py +317 -0
  75. qiskit/circuit/library/arithmetic/polynomial_pauli_rotations.py +335 -0
  76. qiskit/circuit/library/arithmetic/quadratic_form.py +198 -0
  77. qiskit/circuit/library/arithmetic/weighted_adder.py +337 -0
  78. qiskit/circuit/library/basis_change/__init__.py +15 -0
  79. qiskit/circuit/library/basis_change/qft.py +313 -0
  80. qiskit/circuit/library/blueprintcircuit.py +280 -0
  81. qiskit/circuit/library/boolean_logic/__init__.py +18 -0
  82. qiskit/circuit/library/boolean_logic/inner_product.py +155 -0
  83. qiskit/circuit/library/boolean_logic/quantum_and.py +200 -0
  84. qiskit/circuit/library/boolean_logic/quantum_or.py +202 -0
  85. qiskit/circuit/library/boolean_logic/quantum_xor.py +165 -0
  86. qiskit/circuit/library/data_preparation/__init__.py +57 -0
  87. qiskit/circuit/library/data_preparation/_z_feature_map.py +115 -0
  88. qiskit/circuit/library/data_preparation/_zz_feature_map.py +150 -0
  89. qiskit/circuit/library/data_preparation/initializer.py +107 -0
  90. qiskit/circuit/library/data_preparation/pauli_feature_map.py +656 -0
  91. qiskit/circuit/library/data_preparation/state_preparation.py +336 -0
  92. qiskit/circuit/library/fourier_checking.py +158 -0
  93. qiskit/circuit/library/generalized_gates/__init__.py +30 -0
  94. qiskit/circuit/library/generalized_gates/diagonal.py +159 -0
  95. qiskit/circuit/library/generalized_gates/gms.py +174 -0
  96. qiskit/circuit/library/generalized_gates/gr.py +215 -0
  97. qiskit/circuit/library/generalized_gates/isometry.py +370 -0
  98. qiskit/circuit/library/generalized_gates/linear_function.py +318 -0
  99. qiskit/circuit/library/generalized_gates/mcg_up_to_diagonal.py +143 -0
  100. qiskit/circuit/library/generalized_gates/mcmt.py +316 -0
  101. qiskit/circuit/library/generalized_gates/pauli.py +85 -0
  102. qiskit/circuit/library/generalized_gates/permutation.py +194 -0
  103. qiskit/circuit/library/generalized_gates/rv.py +96 -0
  104. qiskit/circuit/library/generalized_gates/uc.py +213 -0
  105. qiskit/circuit/library/generalized_gates/uc_pauli_rot.py +164 -0
  106. qiskit/circuit/library/generalized_gates/ucrx.py +32 -0
  107. qiskit/circuit/library/generalized_gates/ucry.py +32 -0
  108. qiskit/circuit/library/generalized_gates/ucrz.py +32 -0
  109. qiskit/circuit/library/generalized_gates/unitary.py +215 -0
  110. qiskit/circuit/library/graph_state.py +169 -0
  111. qiskit/circuit/library/grover_operator.py +579 -0
  112. qiskit/circuit/library/hamiltonian_gate.py +142 -0
  113. qiskit/circuit/library/hidden_linear_function.py +161 -0
  114. qiskit/circuit/library/iqp.py +175 -0
  115. qiskit/circuit/library/n_local/__init__.py +45 -0
  116. qiskit/circuit/library/n_local/efficient_su2.py +277 -0
  117. qiskit/circuit/library/n_local/evolved_operator_ansatz.py +515 -0
  118. qiskit/circuit/library/n_local/excitation_preserving.py +297 -0
  119. qiskit/circuit/library/n_local/n_local.py +1472 -0
  120. qiskit/circuit/library/n_local/pauli_two_design.py +243 -0
  121. qiskit/circuit/library/n_local/qaoa_ansatz.py +366 -0
  122. qiskit/circuit/library/n_local/real_amplitudes.py +306 -0
  123. qiskit/circuit/library/n_local/two_local.py +289 -0
  124. qiskit/circuit/library/overlap.py +182 -0
  125. qiskit/circuit/library/pauli_evolution.py +186 -0
  126. qiskit/circuit/library/phase_estimation.py +175 -0
  127. qiskit/circuit/library/phase_oracle.py +153 -0
  128. qiskit/circuit/library/quantum_volume.py +167 -0
  129. qiskit/circuit/library/standard_gates/__init__.py +142 -0
  130. qiskit/circuit/library/standard_gates/dcx.py +78 -0
  131. qiskit/circuit/library/standard_gates/ecr.py +130 -0
  132. qiskit/circuit/library/standard_gates/equivalence_library.py +1800 -0
  133. qiskit/circuit/library/standard_gates/global_phase.py +85 -0
  134. qiskit/circuit/library/standard_gates/h.py +258 -0
  135. qiskit/circuit/library/standard_gates/i.py +76 -0
  136. qiskit/circuit/library/standard_gates/iswap.py +134 -0
  137. qiskit/circuit/library/standard_gates/multi_control_rotation_gates.py +405 -0
  138. qiskit/circuit/library/standard_gates/p.py +441 -0
  139. qiskit/circuit/library/standard_gates/r.py +117 -0
  140. qiskit/circuit/library/standard_gates/rx.py +303 -0
  141. qiskit/circuit/library/standard_gates/rxx.py +183 -0
  142. qiskit/circuit/library/standard_gates/ry.py +298 -0
  143. qiskit/circuit/library/standard_gates/ryy.py +183 -0
  144. qiskit/circuit/library/standard_gates/rz.py +319 -0
  145. qiskit/circuit/library/standard_gates/rzx.py +229 -0
  146. qiskit/circuit/library/standard_gates/rzz.py +196 -0
  147. qiskit/circuit/library/standard_gates/s.py +428 -0
  148. qiskit/circuit/library/standard_gates/swap.py +288 -0
  149. qiskit/circuit/library/standard_gates/sx.py +315 -0
  150. qiskit/circuit/library/standard_gates/t.py +179 -0
  151. qiskit/circuit/library/standard_gates/u.py +403 -0
  152. qiskit/circuit/library/standard_gates/u1.py +501 -0
  153. qiskit/circuit/library/standard_gates/u2.py +149 -0
  154. qiskit/circuit/library/standard_gates/u3.py +436 -0
  155. qiskit/circuit/library/standard_gates/x.py +1529 -0
  156. qiskit/circuit/library/standard_gates/xx_minus_yy.py +235 -0
  157. qiskit/circuit/library/standard_gates/xx_plus_yy.py +239 -0
  158. qiskit/circuit/library/standard_gates/y.py +262 -0
  159. qiskit/circuit/library/standard_gates/z.py +348 -0
  160. qiskit/circuit/library/templates/__init__.py +92 -0
  161. qiskit/circuit/library/templates/clifford/__init__.py +33 -0
  162. qiskit/circuit/library/templates/clifford/clifford_2_1.py +34 -0
  163. qiskit/circuit/library/templates/clifford/clifford_2_2.py +35 -0
  164. qiskit/circuit/library/templates/clifford/clifford_2_3.py +34 -0
  165. qiskit/circuit/library/templates/clifford/clifford_2_4.py +34 -0
  166. qiskit/circuit/library/templates/clifford/clifford_3_1.py +35 -0
  167. qiskit/circuit/library/templates/clifford/clifford_4_1.py +38 -0
  168. qiskit/circuit/library/templates/clifford/clifford_4_2.py +37 -0
  169. qiskit/circuit/library/templates/clifford/clifford_4_3.py +38 -0
  170. qiskit/circuit/library/templates/clifford/clifford_4_4.py +37 -0
  171. qiskit/circuit/library/templates/clifford/clifford_5_1.py +40 -0
  172. qiskit/circuit/library/templates/clifford/clifford_6_1.py +40 -0
  173. qiskit/circuit/library/templates/clifford/clifford_6_2.py +40 -0
  174. qiskit/circuit/library/templates/clifford/clifford_6_3.py +40 -0
  175. qiskit/circuit/library/templates/clifford/clifford_6_4.py +38 -0
  176. qiskit/circuit/library/templates/clifford/clifford_6_5.py +40 -0
  177. qiskit/circuit/library/templates/clifford/clifford_8_1.py +42 -0
  178. qiskit/circuit/library/templates/clifford/clifford_8_2.py +42 -0
  179. qiskit/circuit/library/templates/clifford/clifford_8_3.py +41 -0
  180. qiskit/circuit/library/templates/nct/__init__.py +67 -0
  181. qiskit/circuit/library/templates/nct/template_nct_2a_1.py +34 -0
  182. qiskit/circuit/library/templates/nct/template_nct_2a_2.py +35 -0
  183. qiskit/circuit/library/templates/nct/template_nct_2a_3.py +37 -0
  184. qiskit/circuit/library/templates/nct/template_nct_4a_1.py +43 -0
  185. qiskit/circuit/library/templates/nct/template_nct_4a_2.py +41 -0
  186. qiskit/circuit/library/templates/nct/template_nct_4a_3.py +39 -0
  187. qiskit/circuit/library/templates/nct/template_nct_4b_1.py +41 -0
  188. qiskit/circuit/library/templates/nct/template_nct_4b_2.py +39 -0
  189. qiskit/circuit/library/templates/nct/template_nct_5a_1.py +40 -0
  190. qiskit/circuit/library/templates/nct/template_nct_5a_2.py +40 -0
  191. qiskit/circuit/library/templates/nct/template_nct_5a_3.py +40 -0
  192. qiskit/circuit/library/templates/nct/template_nct_5a_4.py +39 -0
  193. qiskit/circuit/library/templates/nct/template_nct_6a_1.py +40 -0
  194. qiskit/circuit/library/templates/nct/template_nct_6a_2.py +41 -0
  195. qiskit/circuit/library/templates/nct/template_nct_6a_3.py +41 -0
  196. qiskit/circuit/library/templates/nct/template_nct_6a_4.py +41 -0
  197. qiskit/circuit/library/templates/nct/template_nct_6b_1.py +41 -0
  198. qiskit/circuit/library/templates/nct/template_nct_6b_2.py +41 -0
  199. qiskit/circuit/library/templates/nct/template_nct_6c_1.py +41 -0
  200. qiskit/circuit/library/templates/nct/template_nct_7a_1.py +43 -0
  201. qiskit/circuit/library/templates/nct/template_nct_7b_1.py +43 -0
  202. qiskit/circuit/library/templates/nct/template_nct_7c_1.py +43 -0
  203. qiskit/circuit/library/templates/nct/template_nct_7d_1.py +43 -0
  204. qiskit/circuit/library/templates/nct/template_nct_7e_1.py +43 -0
  205. qiskit/circuit/library/templates/nct/template_nct_9a_1.py +45 -0
  206. qiskit/circuit/library/templates/nct/template_nct_9c_1.py +43 -0
  207. qiskit/circuit/library/templates/nct/template_nct_9c_10.py +44 -0
  208. qiskit/circuit/library/templates/nct/template_nct_9c_11.py +44 -0
  209. qiskit/circuit/library/templates/nct/template_nct_9c_12.py +44 -0
  210. qiskit/circuit/library/templates/nct/template_nct_9c_2.py +44 -0
  211. qiskit/circuit/library/templates/nct/template_nct_9c_3.py +44 -0
  212. qiskit/circuit/library/templates/nct/template_nct_9c_4.py +44 -0
  213. qiskit/circuit/library/templates/nct/template_nct_9c_5.py +44 -0
  214. qiskit/circuit/library/templates/nct/template_nct_9c_6.py +44 -0
  215. qiskit/circuit/library/templates/nct/template_nct_9c_7.py +44 -0
  216. qiskit/circuit/library/templates/nct/template_nct_9c_8.py +44 -0
  217. qiskit/circuit/library/templates/nct/template_nct_9c_9.py +44 -0
  218. qiskit/circuit/library/templates/nct/template_nct_9d_1.py +43 -0
  219. qiskit/circuit/library/templates/nct/template_nct_9d_10.py +44 -0
  220. qiskit/circuit/library/templates/nct/template_nct_9d_2.py +44 -0
  221. qiskit/circuit/library/templates/nct/template_nct_9d_3.py +44 -0
  222. qiskit/circuit/library/templates/nct/template_nct_9d_4.py +44 -0
  223. qiskit/circuit/library/templates/nct/template_nct_9d_5.py +44 -0
  224. qiskit/circuit/library/templates/nct/template_nct_9d_6.py +44 -0
  225. qiskit/circuit/library/templates/nct/template_nct_9d_7.py +44 -0
  226. qiskit/circuit/library/templates/nct/template_nct_9d_8.py +44 -0
  227. qiskit/circuit/library/templates/nct/template_nct_9d_9.py +44 -0
  228. qiskit/circuit/library/templates/rzx/__init__.py +25 -0
  229. qiskit/circuit/library/templates/rzx/rzx_cy.py +47 -0
  230. qiskit/circuit/library/templates/rzx/rzx_xz.py +54 -0
  231. qiskit/circuit/library/templates/rzx/rzx_yz.py +45 -0
  232. qiskit/circuit/library/templates/rzx/rzx_zz1.py +69 -0
  233. qiskit/circuit/library/templates/rzx/rzx_zz2.py +59 -0
  234. qiskit/circuit/library/templates/rzx/rzx_zz3.py +59 -0
  235. qiskit/circuit/measure.py +44 -0
  236. qiskit/circuit/operation.py +67 -0
  237. qiskit/circuit/parameter.py +178 -0
  238. qiskit/circuit/parameterexpression.py +692 -0
  239. qiskit/circuit/parametertable.py +119 -0
  240. qiskit/circuit/parametervector.py +120 -0
  241. qiskit/circuit/quantumcircuit.py +6829 -0
  242. qiskit/circuit/quantumcircuitdata.py +136 -0
  243. qiskit/circuit/quantumregister.py +75 -0
  244. qiskit/circuit/random/__init__.py +15 -0
  245. qiskit/circuit/random/utils.py +358 -0
  246. qiskit/circuit/register.py +233 -0
  247. qiskit/circuit/reset.py +34 -0
  248. qiskit/circuit/singleton.py +606 -0
  249. qiskit/circuit/store.py +97 -0
  250. qiskit/circuit/tools/__init__.py +16 -0
  251. qiskit/circuit/tools/pi_check.py +190 -0
  252. qiskit/circuit/twirling.py +145 -0
  253. qiskit/compiler/__init__.py +33 -0
  254. qiskit/compiler/assembler.py +681 -0
  255. qiskit/compiler/scheduler.py +109 -0
  256. qiskit/compiler/sequencer.py +71 -0
  257. qiskit/compiler/transpiler.py +533 -0
  258. qiskit/converters/__init__.py +74 -0
  259. qiskit/converters/circuit_to_dag.py +78 -0
  260. qiskit/converters/circuit_to_dagdependency.py +51 -0
  261. qiskit/converters/circuit_to_dagdependency_v2.py +47 -0
  262. qiskit/converters/circuit_to_gate.py +107 -0
  263. qiskit/converters/circuit_to_instruction.py +155 -0
  264. qiskit/converters/dag_to_circuit.py +79 -0
  265. qiskit/converters/dag_to_dagdependency.py +55 -0
  266. qiskit/converters/dag_to_dagdependency_v2.py +44 -0
  267. qiskit/converters/dagdependency_to_circuit.py +46 -0
  268. qiskit/converters/dagdependency_to_dag.py +54 -0
  269. qiskit/dagcircuit/__init__.py +44 -0
  270. qiskit/dagcircuit/collect_blocks.py +391 -0
  271. qiskit/dagcircuit/dagcircuit.py +24 -0
  272. qiskit/dagcircuit/dagdependency.py +646 -0
  273. qiskit/dagcircuit/dagdependency_v2.py +641 -0
  274. qiskit/dagcircuit/dagdepnode.py +160 -0
  275. qiskit/dagcircuit/dagnode.py +176 -0
  276. qiskit/dagcircuit/exceptions.py +42 -0
  277. qiskit/exceptions.py +153 -0
  278. qiskit/passmanager/__init__.py +240 -0
  279. qiskit/passmanager/base_tasks.py +230 -0
  280. qiskit/passmanager/compilation_status.py +74 -0
  281. qiskit/passmanager/exceptions.py +19 -0
  282. qiskit/passmanager/flow_controllers.py +116 -0
  283. qiskit/passmanager/passmanager.py +333 -0
  284. qiskit/primitives/__init__.py +481 -0
  285. qiskit/primitives/backend_estimator.py +486 -0
  286. qiskit/primitives/backend_estimator_v2.py +434 -0
  287. qiskit/primitives/backend_sampler.py +222 -0
  288. qiskit/primitives/backend_sampler_v2.py +339 -0
  289. qiskit/primitives/base/__init__.py +20 -0
  290. qiskit/primitives/base/base_estimator.py +252 -0
  291. qiskit/primitives/base/base_primitive.py +45 -0
  292. qiskit/primitives/base/base_primitive_job.py +78 -0
  293. qiskit/primitives/base/base_result.py +65 -0
  294. qiskit/primitives/base/base_sampler.py +204 -0
  295. qiskit/primitives/base/estimator_result.py +46 -0
  296. qiskit/primitives/base/sampler_result.py +45 -0
  297. qiskit/primitives/base/validation.py +231 -0
  298. qiskit/primitives/containers/__init__.py +26 -0
  299. qiskit/primitives/containers/bindings_array.py +389 -0
  300. qiskit/primitives/containers/bit_array.py +741 -0
  301. qiskit/primitives/containers/data_bin.py +173 -0
  302. qiskit/primitives/containers/estimator_pub.py +222 -0
  303. qiskit/primitives/containers/object_array.py +94 -0
  304. qiskit/primitives/containers/observables_array.py +279 -0
  305. qiskit/primitives/containers/primitive_result.py +53 -0
  306. qiskit/primitives/containers/pub_result.py +51 -0
  307. qiskit/primitives/containers/sampler_pub.py +193 -0
  308. qiskit/primitives/containers/sampler_pub_result.py +74 -0
  309. qiskit/primitives/containers/shape.py +129 -0
  310. qiskit/primitives/estimator.py +172 -0
  311. qiskit/primitives/primitive_job.py +81 -0
  312. qiskit/primitives/sampler.py +162 -0
  313. qiskit/primitives/statevector_estimator.py +174 -0
  314. qiskit/primitives/statevector_sampler.py +292 -0
  315. qiskit/primitives/utils.py +247 -0
  316. qiskit/providers/__init__.py +803 -0
  317. qiskit/providers/backend.py +667 -0
  318. qiskit/providers/backend_compat.py +472 -0
  319. qiskit/providers/basic_provider/__init__.py +45 -0
  320. qiskit/providers/basic_provider/basic_provider.py +101 -0
  321. qiskit/providers/basic_provider/basic_provider_job.py +65 -0
  322. qiskit/providers/basic_provider/basic_provider_tools.py +218 -0
  323. qiskit/providers/basic_provider/basic_simulator.py +821 -0
  324. qiskit/providers/basic_provider/exceptions.py +30 -0
  325. qiskit/providers/exceptions.py +45 -0
  326. qiskit/providers/fake_provider/__init__.py +105 -0
  327. qiskit/providers/fake_provider/backends_v1/__init__.py +22 -0
  328. qiskit/providers/fake_provider/backends_v1/fake_127q_pulse/__init__.py +18 -0
  329. qiskit/providers/fake_provider/backends_v1/fake_127q_pulse/conf_washington.json +1 -0
  330. qiskit/providers/fake_provider/backends_v1/fake_127q_pulse/defs_washington.json +1 -0
  331. qiskit/providers/fake_provider/backends_v1/fake_127q_pulse/fake_127q_pulse_v1.py +37 -0
  332. qiskit/providers/fake_provider/backends_v1/fake_127q_pulse/props_washington.json +1 -0
  333. qiskit/providers/fake_provider/backends_v1/fake_20q/__init__.py +18 -0
  334. qiskit/providers/fake_provider/backends_v1/fake_20q/conf_singapore.json +1 -0
  335. qiskit/providers/fake_provider/backends_v1/fake_20q/fake_20q.py +43 -0
  336. qiskit/providers/fake_provider/backends_v1/fake_20q/props_singapore.json +1 -0
  337. qiskit/providers/fake_provider/backends_v1/fake_27q_pulse/__init__.py +18 -0
  338. qiskit/providers/fake_provider/backends_v1/fake_27q_pulse/conf_hanoi.json +1 -0
  339. qiskit/providers/fake_provider/backends_v1/fake_27q_pulse/defs_hanoi.json +1 -0
  340. qiskit/providers/fake_provider/backends_v1/fake_27q_pulse/fake_27q_pulse_v1.py +50 -0
  341. qiskit/providers/fake_provider/backends_v1/fake_27q_pulse/props_hanoi.json +1 -0
  342. qiskit/providers/fake_provider/backends_v1/fake_5q/__init__.py +18 -0
  343. qiskit/providers/fake_provider/backends_v1/fake_5q/conf_yorktown.json +1 -0
  344. qiskit/providers/fake_provider/backends_v1/fake_5q/fake_5q_v1.py +41 -0
  345. qiskit/providers/fake_provider/backends_v1/fake_5q/props_yorktown.json +1 -0
  346. qiskit/providers/fake_provider/backends_v1/fake_7q_pulse/__init__.py +18 -0
  347. qiskit/providers/fake_provider/backends_v1/fake_7q_pulse/conf_nairobi.json +1 -0
  348. qiskit/providers/fake_provider/backends_v1/fake_7q_pulse/defs_nairobi.json +1 -0
  349. qiskit/providers/fake_provider/backends_v1/fake_7q_pulse/fake_7q_pulse_v1.py +44 -0
  350. qiskit/providers/fake_provider/backends_v1/fake_7q_pulse/props_nairobi.json +1 -0
  351. qiskit/providers/fake_provider/fake_1q.py +91 -0
  352. qiskit/providers/fake_provider/fake_backend.py +165 -0
  353. qiskit/providers/fake_provider/fake_openpulse_2q.py +391 -0
  354. qiskit/providers/fake_provider/fake_openpulse_3q.py +340 -0
  355. qiskit/providers/fake_provider/fake_pulse_backend.py +49 -0
  356. qiskit/providers/fake_provider/fake_qasm_backend.py +77 -0
  357. qiskit/providers/fake_provider/generic_backend_v2.py +1035 -0
  358. qiskit/providers/fake_provider/utils/__init__.py +15 -0
  359. qiskit/providers/fake_provider/utils/backend_converter.py +150 -0
  360. qiskit/providers/fake_provider/utils/json_decoder.py +109 -0
  361. qiskit/providers/job.py +147 -0
  362. qiskit/providers/jobstatus.py +30 -0
  363. qiskit/providers/models/__init__.py +89 -0
  364. qiskit/providers/models/backendconfiguration.py +1040 -0
  365. qiskit/providers/models/backendproperties.py +517 -0
  366. qiskit/providers/models/backendstatus.py +94 -0
  367. qiskit/providers/models/jobstatus.py +66 -0
  368. qiskit/providers/models/pulsedefaults.py +305 -0
  369. qiskit/providers/options.py +273 -0
  370. qiskit/providers/provider.py +95 -0
  371. qiskit/providers/providerutils.py +110 -0
  372. qiskit/pulse/__init__.py +158 -0
  373. qiskit/pulse/builder.py +2254 -0
  374. qiskit/pulse/calibration_entries.py +381 -0
  375. qiskit/pulse/channels.py +227 -0
  376. qiskit/pulse/configuration.py +245 -0
  377. qiskit/pulse/exceptions.py +45 -0
  378. qiskit/pulse/filters.py +309 -0
  379. qiskit/pulse/instruction_schedule_map.py +424 -0
  380. qiskit/pulse/instructions/__init__.py +67 -0
  381. qiskit/pulse/instructions/acquire.py +150 -0
  382. qiskit/pulse/instructions/delay.py +71 -0
  383. qiskit/pulse/instructions/directives.py +154 -0
  384. qiskit/pulse/instructions/frequency.py +135 -0
  385. qiskit/pulse/instructions/instruction.py +270 -0
  386. qiskit/pulse/instructions/phase.py +152 -0
  387. qiskit/pulse/instructions/play.py +99 -0
  388. qiskit/pulse/instructions/reference.py +100 -0
  389. qiskit/pulse/instructions/snapshot.py +82 -0
  390. qiskit/pulse/library/__init__.py +97 -0
  391. qiskit/pulse/library/continuous.py +430 -0
  392. qiskit/pulse/library/pulse.py +148 -0
  393. qiskit/pulse/library/samplers/__init__.py +15 -0
  394. qiskit/pulse/library/samplers/decorators.py +295 -0
  395. qiskit/pulse/library/samplers/strategies.py +71 -0
  396. qiskit/pulse/library/symbolic_pulses.py +1988 -0
  397. qiskit/pulse/library/waveform.py +136 -0
  398. qiskit/pulse/macros.py +262 -0
  399. qiskit/pulse/parameter_manager.py +445 -0
  400. qiskit/pulse/parser.py +314 -0
  401. qiskit/pulse/reference_manager.py +58 -0
  402. qiskit/pulse/schedule.py +1854 -0
  403. qiskit/pulse/transforms/__init__.py +106 -0
  404. qiskit/pulse/transforms/alignments.py +406 -0
  405. qiskit/pulse/transforms/base_transforms.py +71 -0
  406. qiskit/pulse/transforms/canonicalization.py +498 -0
  407. qiskit/pulse/transforms/dag.py +122 -0
  408. qiskit/pulse/utils.py +149 -0
  409. qiskit/qasm/libs/dummy/stdgates.inc +75 -0
  410. qiskit/qasm/libs/qelib1.inc +266 -0
  411. qiskit/qasm/libs/stdgates.inc +82 -0
  412. qiskit/qasm2/__init__.py +654 -0
  413. qiskit/qasm2/exceptions.py +27 -0
  414. qiskit/qasm2/export.py +372 -0
  415. qiskit/qasm2/parse.py +452 -0
  416. qiskit/qasm3/__init__.py +367 -0
  417. qiskit/qasm3/ast.py +738 -0
  418. qiskit/qasm3/exceptions.py +27 -0
  419. qiskit/qasm3/experimental.py +70 -0
  420. qiskit/qasm3/exporter.py +1299 -0
  421. qiskit/qasm3/printer.py +577 -0
  422. qiskit/qobj/__init__.py +75 -0
  423. qiskit/qobj/common.py +81 -0
  424. qiskit/qobj/converters/__init__.py +18 -0
  425. qiskit/qobj/converters/lo_config.py +177 -0
  426. qiskit/qobj/converters/pulse_instruction.py +897 -0
  427. qiskit/qobj/pulse_qobj.py +709 -0
  428. qiskit/qobj/qasm_qobj.py +708 -0
  429. qiskit/qobj/utils.py +46 -0
  430. qiskit/qpy/__init__.py +1822 -0
  431. qiskit/qpy/binary_io/__init__.py +36 -0
  432. qiskit/qpy/binary_io/circuits.py +1475 -0
  433. qiskit/qpy/binary_io/schedules.py +635 -0
  434. qiskit/qpy/binary_io/value.py +1025 -0
  435. qiskit/qpy/common.py +350 -0
  436. qiskit/qpy/exceptions.py +53 -0
  437. qiskit/qpy/formats.py +401 -0
  438. qiskit/qpy/interface.py +377 -0
  439. qiskit/qpy/type_keys.py +572 -0
  440. qiskit/quantum_info/__init__.py +162 -0
  441. qiskit/quantum_info/analysis/__init__.py +17 -0
  442. qiskit/quantum_info/analysis/average.py +47 -0
  443. qiskit/quantum_info/analysis/distance.py +102 -0
  444. qiskit/quantum_info/analysis/make_observable.py +44 -0
  445. qiskit/quantum_info/analysis/z2_symmetries.py +484 -0
  446. qiskit/quantum_info/operators/__init__.py +28 -0
  447. qiskit/quantum_info/operators/base_operator.py +145 -0
  448. qiskit/quantum_info/operators/channel/__init__.py +29 -0
  449. qiskit/quantum_info/operators/channel/chi.py +191 -0
  450. qiskit/quantum_info/operators/channel/choi.py +218 -0
  451. qiskit/quantum_info/operators/channel/kraus.py +337 -0
  452. qiskit/quantum_info/operators/channel/ptm.py +204 -0
  453. qiskit/quantum_info/operators/channel/quantum_channel.py +348 -0
  454. qiskit/quantum_info/operators/channel/stinespring.py +296 -0
  455. qiskit/quantum_info/operators/channel/superop.py +377 -0
  456. qiskit/quantum_info/operators/channel/transformations.py +475 -0
  457. qiskit/quantum_info/operators/custom_iterator.py +48 -0
  458. qiskit/quantum_info/operators/dihedral/__init__.py +18 -0
  459. qiskit/quantum_info/operators/dihedral/dihedral.py +509 -0
  460. qiskit/quantum_info/operators/dihedral/dihedral_circuits.py +216 -0
  461. qiskit/quantum_info/operators/dihedral/polynomial.py +313 -0
  462. qiskit/quantum_info/operators/dihedral/random.py +64 -0
  463. qiskit/quantum_info/operators/linear_op.py +25 -0
  464. qiskit/quantum_info/operators/measures.py +418 -0
  465. qiskit/quantum_info/operators/mixins/__init__.py +52 -0
  466. qiskit/quantum_info/operators/mixins/adjoint.py +52 -0
  467. qiskit/quantum_info/operators/mixins/group.py +171 -0
  468. qiskit/quantum_info/operators/mixins/linear.py +84 -0
  469. qiskit/quantum_info/operators/mixins/multiply.py +62 -0
  470. qiskit/quantum_info/operators/mixins/tolerances.py +72 -0
  471. qiskit/quantum_info/operators/op_shape.py +525 -0
  472. qiskit/quantum_info/operators/operator.py +865 -0
  473. qiskit/quantum_info/operators/operator_utils.py +76 -0
  474. qiskit/quantum_info/operators/predicates.py +183 -0
  475. qiskit/quantum_info/operators/random.py +154 -0
  476. qiskit/quantum_info/operators/scalar_op.py +254 -0
  477. qiskit/quantum_info/operators/symplectic/__init__.py +23 -0
  478. qiskit/quantum_info/operators/symplectic/base_pauli.py +719 -0
  479. qiskit/quantum_info/operators/symplectic/clifford.py +1030 -0
  480. qiskit/quantum_info/operators/symplectic/clifford_circuits.py +558 -0
  481. qiskit/quantum_info/operators/symplectic/pauli.py +753 -0
  482. qiskit/quantum_info/operators/symplectic/pauli_list.py +1230 -0
  483. qiskit/quantum_info/operators/symplectic/pauli_utils.py +40 -0
  484. qiskit/quantum_info/operators/symplectic/random.py +117 -0
  485. qiskit/quantum_info/operators/symplectic/sparse_pauli_op.py +1196 -0
  486. qiskit/quantum_info/operators/utils/__init__.py +20 -0
  487. qiskit/quantum_info/operators/utils/anti_commutator.py +36 -0
  488. qiskit/quantum_info/operators/utils/commutator.py +36 -0
  489. qiskit/quantum_info/operators/utils/double_commutator.py +76 -0
  490. qiskit/quantum_info/quaternion.py +156 -0
  491. qiskit/quantum_info/random.py +26 -0
  492. qiskit/quantum_info/states/__init__.py +28 -0
  493. qiskit/quantum_info/states/densitymatrix.py +845 -0
  494. qiskit/quantum_info/states/measures.py +288 -0
  495. qiskit/quantum_info/states/quantum_state.py +503 -0
  496. qiskit/quantum_info/states/random.py +157 -0
  497. qiskit/quantum_info/states/stabilizerstate.py +773 -0
  498. qiskit/quantum_info/states/statevector.py +958 -0
  499. qiskit/quantum_info/states/utils.py +247 -0
  500. qiskit/result/__init__.py +73 -0
  501. qiskit/result/counts.py +189 -0
  502. qiskit/result/distributions/__init__.py +17 -0
  503. qiskit/result/distributions/probability.py +100 -0
  504. qiskit/result/distributions/quasi.py +154 -0
  505. qiskit/result/exceptions.py +40 -0
  506. qiskit/result/mitigation/__init__.py +13 -0
  507. qiskit/result/mitigation/base_readout_mitigator.py +79 -0
  508. qiskit/result/mitigation/correlated_readout_mitigator.py +277 -0
  509. qiskit/result/mitigation/local_readout_mitigator.py +328 -0
  510. qiskit/result/mitigation/utils.py +217 -0
  511. qiskit/result/models.py +234 -0
  512. qiskit/result/postprocess.py +239 -0
  513. qiskit/result/result.py +392 -0
  514. qiskit/result/sampled_expval.py +75 -0
  515. qiskit/result/utils.py +295 -0
  516. qiskit/scheduler/__init__.py +40 -0
  517. qiskit/scheduler/config.py +37 -0
  518. qiskit/scheduler/lowering.py +187 -0
  519. qiskit/scheduler/methods/__init__.py +15 -0
  520. qiskit/scheduler/methods/basic.py +140 -0
  521. qiskit/scheduler/schedule_circuit.py +69 -0
  522. qiskit/scheduler/sequence.py +104 -0
  523. qiskit/synthesis/__init__.py +220 -0
  524. qiskit/synthesis/arithmetic/__init__.py +16 -0
  525. qiskit/synthesis/arithmetic/adders/__init__.py +17 -0
  526. qiskit/synthesis/arithmetic/adders/cdkm_ripple_carry_adder.py +154 -0
  527. qiskit/synthesis/arithmetic/adders/draper_qft_adder.py +103 -0
  528. qiskit/synthesis/arithmetic/adders/vbe_ripple_carry_adder.py +161 -0
  529. qiskit/synthesis/arithmetic/multipliers/__init__.py +16 -0
  530. qiskit/synthesis/arithmetic/multipliers/hrs_cumulative_multiplier.py +102 -0
  531. qiskit/synthesis/arithmetic/multipliers/rg_qft_multiplier.py +99 -0
  532. qiskit/synthesis/clifford/__init__.py +19 -0
  533. qiskit/synthesis/clifford/clifford_decompose_ag.py +178 -0
  534. qiskit/synthesis/clifford/clifford_decompose_bm.py +46 -0
  535. qiskit/synthesis/clifford/clifford_decompose_full.py +64 -0
  536. qiskit/synthesis/clifford/clifford_decompose_greedy.py +58 -0
  537. qiskit/synthesis/clifford/clifford_decompose_layers.py +447 -0
  538. qiskit/synthesis/cnotdihedral/__init__.py +17 -0
  539. qiskit/synthesis/cnotdihedral/cnotdihedral_decompose_full.py +52 -0
  540. qiskit/synthesis/cnotdihedral/cnotdihedral_decompose_general.py +141 -0
  541. qiskit/synthesis/cnotdihedral/cnotdihedral_decompose_two_qubits.py +266 -0
  542. qiskit/synthesis/discrete_basis/__init__.py +16 -0
  543. qiskit/synthesis/discrete_basis/commutator_decompose.py +241 -0
  544. qiskit/synthesis/discrete_basis/gate_sequence.py +415 -0
  545. qiskit/synthesis/discrete_basis/generate_basis_approximations.py +163 -0
  546. qiskit/synthesis/discrete_basis/solovay_kitaev.py +217 -0
  547. qiskit/synthesis/evolution/__init__.py +21 -0
  548. qiskit/synthesis/evolution/evolution_synthesis.py +48 -0
  549. qiskit/synthesis/evolution/lie_trotter.py +117 -0
  550. qiskit/synthesis/evolution/matrix_synthesis.py +47 -0
  551. qiskit/synthesis/evolution/pauli_network.py +80 -0
  552. qiskit/synthesis/evolution/product_formula.py +311 -0
  553. qiskit/synthesis/evolution/qdrift.py +138 -0
  554. qiskit/synthesis/evolution/suzuki_trotter.py +215 -0
  555. qiskit/synthesis/linear/__init__.py +26 -0
  556. qiskit/synthesis/linear/cnot_synth.py +69 -0
  557. qiskit/synthesis/linear/linear_circuits_utils.py +128 -0
  558. qiskit/synthesis/linear/linear_depth_lnn.py +276 -0
  559. qiskit/synthesis/linear/linear_matrix_utils.py +27 -0
  560. qiskit/synthesis/linear_phase/__init__.py +17 -0
  561. qiskit/synthesis/linear_phase/cnot_phase_synth.py +206 -0
  562. qiskit/synthesis/linear_phase/cx_cz_depth_lnn.py +262 -0
  563. qiskit/synthesis/linear_phase/cz_depth_lnn.py +58 -0
  564. qiskit/synthesis/multi_controlled/__init__.py +24 -0
  565. qiskit/synthesis/multi_controlled/mcmt_vchain.py +52 -0
  566. qiskit/synthesis/multi_controlled/mcx_synthesis.py +356 -0
  567. qiskit/synthesis/one_qubit/__init__.py +15 -0
  568. qiskit/synthesis/one_qubit/one_qubit_decompose.py +288 -0
  569. qiskit/synthesis/permutation/__init__.py +18 -0
  570. qiskit/synthesis/permutation/permutation_full.py +78 -0
  571. qiskit/synthesis/permutation/permutation_lnn.py +54 -0
  572. qiskit/synthesis/permutation/permutation_reverse_lnn.py +93 -0
  573. qiskit/synthesis/permutation/permutation_utils.py +16 -0
  574. qiskit/synthesis/qft/__init__.py +16 -0
  575. qiskit/synthesis/qft/qft_decompose_full.py +97 -0
  576. qiskit/synthesis/qft/qft_decompose_lnn.py +79 -0
  577. qiskit/synthesis/stabilizer/__init__.py +16 -0
  578. qiskit/synthesis/stabilizer/stabilizer_circuit.py +149 -0
  579. qiskit/synthesis/stabilizer/stabilizer_decompose.py +194 -0
  580. qiskit/synthesis/two_qubit/__init__.py +19 -0
  581. qiskit/synthesis/two_qubit/local_invariance.py +63 -0
  582. qiskit/synthesis/two_qubit/two_qubit_decompose.py +700 -0
  583. qiskit/synthesis/two_qubit/xx_decompose/__init__.py +19 -0
  584. qiskit/synthesis/two_qubit/xx_decompose/circuits.py +300 -0
  585. qiskit/synthesis/two_qubit/xx_decompose/decomposer.py +324 -0
  586. qiskit/synthesis/two_qubit/xx_decompose/embodiments.py +163 -0
  587. qiskit/synthesis/two_qubit/xx_decompose/paths.py +412 -0
  588. qiskit/synthesis/two_qubit/xx_decompose/polytopes.py +262 -0
  589. qiskit/synthesis/two_qubit/xx_decompose/utilities.py +40 -0
  590. qiskit/synthesis/two_qubit/xx_decompose/weyl.py +133 -0
  591. qiskit/synthesis/unitary/__init__.py +13 -0
  592. qiskit/synthesis/unitary/aqc/__init__.py +177 -0
  593. qiskit/synthesis/unitary/aqc/approximate.py +116 -0
  594. qiskit/synthesis/unitary/aqc/aqc.py +175 -0
  595. qiskit/synthesis/unitary/aqc/cnot_structures.py +300 -0
  596. qiskit/synthesis/unitary/aqc/cnot_unit_circuit.py +103 -0
  597. qiskit/synthesis/unitary/aqc/cnot_unit_objective.py +299 -0
  598. qiskit/synthesis/unitary/aqc/elementary_operations.py +108 -0
  599. qiskit/synthesis/unitary/aqc/fast_gradient/__init__.py +164 -0
  600. qiskit/synthesis/unitary/aqc/fast_gradient/fast_grad_utils.py +237 -0
  601. qiskit/synthesis/unitary/aqc/fast_gradient/fast_gradient.py +226 -0
  602. qiskit/synthesis/unitary/aqc/fast_gradient/layer.py +370 -0
  603. qiskit/synthesis/unitary/aqc/fast_gradient/pmatrix.py +312 -0
  604. qiskit/synthesis/unitary/qsd.py +288 -0
  605. qiskit/transpiler/__init__.py +1290 -0
  606. qiskit/transpiler/basepasses.py +221 -0
  607. qiskit/transpiler/coupling.py +500 -0
  608. qiskit/transpiler/exceptions.py +59 -0
  609. qiskit/transpiler/instruction_durations.py +281 -0
  610. qiskit/transpiler/layout.py +737 -0
  611. qiskit/transpiler/passes/__init__.py +312 -0
  612. qiskit/transpiler/passes/analysis/__init__.py +23 -0
  613. qiskit/transpiler/passes/analysis/count_ops.py +30 -0
  614. qiskit/transpiler/passes/analysis/count_ops_longest_path.py +26 -0
  615. qiskit/transpiler/passes/analysis/dag_longest_path.py +24 -0
  616. qiskit/transpiler/passes/analysis/depth.py +33 -0
  617. qiskit/transpiler/passes/analysis/num_qubits.py +26 -0
  618. qiskit/transpiler/passes/analysis/num_tensor_factors.py +26 -0
  619. qiskit/transpiler/passes/analysis/resource_estimation.py +41 -0
  620. qiskit/transpiler/passes/analysis/size.py +36 -0
  621. qiskit/transpiler/passes/analysis/width.py +27 -0
  622. qiskit/transpiler/passes/basis/__init__.py +19 -0
  623. qiskit/transpiler/passes/basis/basis_translator.py +137 -0
  624. qiskit/transpiler/passes/basis/decompose.py +131 -0
  625. qiskit/transpiler/passes/basis/translate_parameterized.py +175 -0
  626. qiskit/transpiler/passes/basis/unroll_3q_or_more.py +88 -0
  627. qiskit/transpiler/passes/basis/unroll_custom_definitions.py +109 -0
  628. qiskit/transpiler/passes/calibration/__init__.py +17 -0
  629. qiskit/transpiler/passes/calibration/base_builder.py +79 -0
  630. qiskit/transpiler/passes/calibration/builders.py +20 -0
  631. qiskit/transpiler/passes/calibration/exceptions.py +22 -0
  632. qiskit/transpiler/passes/calibration/pulse_gate.py +100 -0
  633. qiskit/transpiler/passes/calibration/rx_builder.py +164 -0
  634. qiskit/transpiler/passes/calibration/rzx_builder.py +411 -0
  635. qiskit/transpiler/passes/calibration/rzx_templates.py +51 -0
  636. qiskit/transpiler/passes/layout/__init__.py +26 -0
  637. qiskit/transpiler/passes/layout/_csp_custom_solver.py +65 -0
  638. qiskit/transpiler/passes/layout/apply_layout.py +123 -0
  639. qiskit/transpiler/passes/layout/csp_layout.py +132 -0
  640. qiskit/transpiler/passes/layout/dense_layout.py +202 -0
  641. qiskit/transpiler/passes/layout/disjoint_utils.py +219 -0
  642. qiskit/transpiler/passes/layout/enlarge_with_ancilla.py +49 -0
  643. qiskit/transpiler/passes/layout/full_ancilla_allocation.py +117 -0
  644. qiskit/transpiler/passes/layout/layout_2q_distance.py +77 -0
  645. qiskit/transpiler/passes/layout/sabre_layout.py +487 -0
  646. qiskit/transpiler/passes/layout/sabre_pre_layout.py +225 -0
  647. qiskit/transpiler/passes/layout/set_layout.py +69 -0
  648. qiskit/transpiler/passes/layout/trivial_layout.py +66 -0
  649. qiskit/transpiler/passes/layout/vf2_layout.py +263 -0
  650. qiskit/transpiler/passes/layout/vf2_post_layout.py +419 -0
  651. qiskit/transpiler/passes/layout/vf2_utils.py +260 -0
  652. qiskit/transpiler/passes/optimization/__init__.py +43 -0
  653. qiskit/transpiler/passes/optimization/_gate_extension.py +80 -0
  654. qiskit/transpiler/passes/optimization/collect_1q_runs.py +31 -0
  655. qiskit/transpiler/passes/optimization/collect_2q_blocks.py +35 -0
  656. qiskit/transpiler/passes/optimization/collect_and_collapse.py +115 -0
  657. qiskit/transpiler/passes/optimization/collect_cliffords.py +104 -0
  658. qiskit/transpiler/passes/optimization/collect_linear_functions.py +80 -0
  659. qiskit/transpiler/passes/optimization/collect_multiqubit_blocks.py +227 -0
  660. qiskit/transpiler/passes/optimization/commutation_analysis.py +44 -0
  661. qiskit/transpiler/passes/optimization/commutative_cancellation.py +82 -0
  662. qiskit/transpiler/passes/optimization/commutative_inverse_cancellation.py +140 -0
  663. qiskit/transpiler/passes/optimization/consolidate_blocks.py +149 -0
  664. qiskit/transpiler/passes/optimization/cx_cancellation.py +65 -0
  665. qiskit/transpiler/passes/optimization/echo_rzx_weyl_decomposition.py +162 -0
  666. qiskit/transpiler/passes/optimization/elide_permutations.py +91 -0
  667. qiskit/transpiler/passes/optimization/hoare_opt.py +420 -0
  668. qiskit/transpiler/passes/optimization/inverse_cancellation.py +95 -0
  669. qiskit/transpiler/passes/optimization/normalize_rx_angle.py +149 -0
  670. qiskit/transpiler/passes/optimization/optimize_1q_commutation.py +268 -0
  671. qiskit/transpiler/passes/optimization/optimize_1q_decomposition.py +254 -0
  672. qiskit/transpiler/passes/optimization/optimize_1q_gates.py +384 -0
  673. qiskit/transpiler/passes/optimization/optimize_annotated.py +448 -0
  674. qiskit/transpiler/passes/optimization/optimize_cliffords.py +89 -0
  675. qiskit/transpiler/passes/optimization/optimize_swap_before_measure.py +71 -0
  676. qiskit/transpiler/passes/optimization/remove_diagonal_gates_before_measure.py +41 -0
  677. qiskit/transpiler/passes/optimization/remove_final_reset.py +37 -0
  678. qiskit/transpiler/passes/optimization/remove_identity_equiv.py +69 -0
  679. qiskit/transpiler/passes/optimization/remove_reset_in_zero_state.py +37 -0
  680. qiskit/transpiler/passes/optimization/reset_after_measure_simplification.py +47 -0
  681. qiskit/transpiler/passes/optimization/split_2q_unitaries.py +40 -0
  682. qiskit/transpiler/passes/optimization/template_matching/__init__.py +19 -0
  683. qiskit/transpiler/passes/optimization/template_matching/backward_match.py +749 -0
  684. qiskit/transpiler/passes/optimization/template_matching/forward_match.py +452 -0
  685. qiskit/transpiler/passes/optimization/template_matching/maximal_matches.py +77 -0
  686. qiskit/transpiler/passes/optimization/template_matching/template_matching.py +370 -0
  687. qiskit/transpiler/passes/optimization/template_matching/template_substitution.py +638 -0
  688. qiskit/transpiler/passes/optimization/template_optimization.py +158 -0
  689. qiskit/transpiler/passes/routing/__init__.py +22 -0
  690. qiskit/transpiler/passes/routing/algorithms/__init__.py +33 -0
  691. qiskit/transpiler/passes/routing/algorithms/token_swapper.py +105 -0
  692. qiskit/transpiler/passes/routing/algorithms/types.py +46 -0
  693. qiskit/transpiler/passes/routing/algorithms/util.py +103 -0
  694. qiskit/transpiler/passes/routing/basic_swap.py +166 -0
  695. qiskit/transpiler/passes/routing/commuting_2q_gate_routing/__init__.py +25 -0
  696. qiskit/transpiler/passes/routing/commuting_2q_gate_routing/commuting_2q_block.py +60 -0
  697. qiskit/transpiler/passes/routing/commuting_2q_gate_routing/commuting_2q_gate_router.py +395 -0
  698. qiskit/transpiler/passes/routing/commuting_2q_gate_routing/pauli_2q_evolution_commutation.py +145 -0
  699. qiskit/transpiler/passes/routing/commuting_2q_gate_routing/swap_strategy.py +306 -0
  700. qiskit/transpiler/passes/routing/layout_transformation.py +119 -0
  701. qiskit/transpiler/passes/routing/lookahead_swap.py +390 -0
  702. qiskit/transpiler/passes/routing/sabre_swap.py +447 -0
  703. qiskit/transpiler/passes/routing/star_prerouting.py +392 -0
  704. qiskit/transpiler/passes/routing/stochastic_swap.py +532 -0
  705. qiskit/transpiler/passes/routing/utils.py +35 -0
  706. qiskit/transpiler/passes/scheduling/__init__.py +27 -0
  707. qiskit/transpiler/passes/scheduling/alap.py +153 -0
  708. qiskit/transpiler/passes/scheduling/alignments/__init__.py +81 -0
  709. qiskit/transpiler/passes/scheduling/alignments/align_measures.py +255 -0
  710. qiskit/transpiler/passes/scheduling/alignments/check_durations.py +78 -0
  711. qiskit/transpiler/passes/scheduling/alignments/pulse_gate_validation.py +107 -0
  712. qiskit/transpiler/passes/scheduling/alignments/reschedule.py +250 -0
  713. qiskit/transpiler/passes/scheduling/asap.py +175 -0
  714. qiskit/transpiler/passes/scheduling/base_scheduler.py +310 -0
  715. qiskit/transpiler/passes/scheduling/dynamical_decoupling.py +312 -0
  716. qiskit/transpiler/passes/scheduling/padding/__init__.py +16 -0
  717. qiskit/transpiler/passes/scheduling/padding/base_padding.py +256 -0
  718. qiskit/transpiler/passes/scheduling/padding/dynamical_decoupling.py +452 -0
  719. qiskit/transpiler/passes/scheduling/padding/pad_delay.py +82 -0
  720. qiskit/transpiler/passes/scheduling/scheduling/__init__.py +17 -0
  721. qiskit/transpiler/passes/scheduling/scheduling/alap.py +127 -0
  722. qiskit/transpiler/passes/scheduling/scheduling/asap.py +131 -0
  723. qiskit/transpiler/passes/scheduling/scheduling/base_scheduler.py +94 -0
  724. qiskit/transpiler/passes/scheduling/scheduling/set_io_latency.py +64 -0
  725. qiskit/transpiler/passes/scheduling/time_unit_conversion.py +165 -0
  726. qiskit/transpiler/passes/synthesis/__init__.py +20 -0
  727. qiskit/transpiler/passes/synthesis/aqc_plugin.py +153 -0
  728. qiskit/transpiler/passes/synthesis/high_level_synthesis.py +854 -0
  729. qiskit/transpiler/passes/synthesis/hls_plugins.py +1559 -0
  730. qiskit/transpiler/passes/synthesis/linear_functions_synthesis.py +41 -0
  731. qiskit/transpiler/passes/synthesis/plugin.py +734 -0
  732. qiskit/transpiler/passes/synthesis/solovay_kitaev_synthesis.py +297 -0
  733. qiskit/transpiler/passes/synthesis/unitary_synthesis.py +1076 -0
  734. qiskit/transpiler/passes/utils/__init__.py +33 -0
  735. qiskit/transpiler/passes/utils/barrier_before_final_measurements.py +41 -0
  736. qiskit/transpiler/passes/utils/check_gate_direction.py +52 -0
  737. qiskit/transpiler/passes/utils/check_map.py +78 -0
  738. qiskit/transpiler/passes/utils/contains_instruction.py +45 -0
  739. qiskit/transpiler/passes/utils/control_flow.py +65 -0
  740. qiskit/transpiler/passes/utils/convert_conditions_to_if_ops.py +93 -0
  741. qiskit/transpiler/passes/utils/dag_fixed_point.py +36 -0
  742. qiskit/transpiler/passes/utils/error.py +69 -0
  743. qiskit/transpiler/passes/utils/filter_op_nodes.py +65 -0
  744. qiskit/transpiler/passes/utils/fixed_point.py +48 -0
  745. qiskit/transpiler/passes/utils/gate_direction.py +86 -0
  746. qiskit/transpiler/passes/utils/gates_basis.py +51 -0
  747. qiskit/transpiler/passes/utils/merge_adjacent_barriers.py +163 -0
  748. qiskit/transpiler/passes/utils/minimum_point.py +118 -0
  749. qiskit/transpiler/passes/utils/remove_barriers.py +49 -0
  750. qiskit/transpiler/passes/utils/remove_final_measurements.py +114 -0
  751. qiskit/transpiler/passes/utils/unroll_forloops.py +81 -0
  752. qiskit/transpiler/passmanager.py +490 -0
  753. qiskit/transpiler/passmanager_config.py +216 -0
  754. qiskit/transpiler/preset_passmanagers/__init__.py +73 -0
  755. qiskit/transpiler/preset_passmanagers/builtin_plugins.py +1045 -0
  756. qiskit/transpiler/preset_passmanagers/common.py +649 -0
  757. qiskit/transpiler/preset_passmanagers/generate_preset_pass_manager.py +626 -0
  758. qiskit/transpiler/preset_passmanagers/level0.py +113 -0
  759. qiskit/transpiler/preset_passmanagers/level1.py +120 -0
  760. qiskit/transpiler/preset_passmanagers/level2.py +119 -0
  761. qiskit/transpiler/preset_passmanagers/level3.py +119 -0
  762. qiskit/transpiler/preset_passmanagers/plugin.py +353 -0
  763. qiskit/transpiler/target.py +1319 -0
  764. qiskit/transpiler/timing_constraints.py +59 -0
  765. qiskit/user_config.py +262 -0
  766. qiskit/utils/__init__.py +89 -0
  767. qiskit/utils/classtools.py +146 -0
  768. qiskit/utils/deprecate_pulse.py +119 -0
  769. qiskit/utils/deprecation.py +490 -0
  770. qiskit/utils/lazy_tester.py +363 -0
  771. qiskit/utils/multiprocessing.py +56 -0
  772. qiskit/utils/optionals.py +347 -0
  773. qiskit/utils/parallel.py +191 -0
  774. qiskit/utils/units.py +143 -0
  775. qiskit/version.py +84 -0
  776. qiskit/visualization/__init__.py +288 -0
  777. qiskit/visualization/array.py +204 -0
  778. qiskit/visualization/bloch.py +778 -0
  779. qiskit/visualization/circuit/__init__.py +15 -0
  780. qiskit/visualization/circuit/_utils.py +675 -0
  781. qiskit/visualization/circuit/circuit_visualization.py +727 -0
  782. qiskit/visualization/circuit/latex.py +661 -0
  783. qiskit/visualization/circuit/matplotlib.py +2029 -0
  784. qiskit/visualization/circuit/qcstyle.py +278 -0
  785. qiskit/visualization/circuit/styles/__init__.py +13 -0
  786. qiskit/visualization/circuit/styles/bw.json +202 -0
  787. qiskit/visualization/circuit/styles/clifford.json +202 -0
  788. qiskit/visualization/circuit/styles/iqp-dark.json +214 -0
  789. qiskit/visualization/circuit/styles/iqp.json +214 -0
  790. qiskit/visualization/circuit/styles/textbook.json +202 -0
  791. qiskit/visualization/circuit/text.py +1844 -0
  792. qiskit/visualization/circuit_visualization.py +19 -0
  793. qiskit/visualization/counts_visualization.py +481 -0
  794. qiskit/visualization/dag_visualization.py +316 -0
  795. qiskit/visualization/exceptions.py +21 -0
  796. qiskit/visualization/gate_map.py +1485 -0
  797. qiskit/visualization/library.py +37 -0
  798. qiskit/visualization/pass_manager_visualization.py +308 -0
  799. qiskit/visualization/pulse_v2/__init__.py +21 -0
  800. qiskit/visualization/pulse_v2/core.py +901 -0
  801. qiskit/visualization/pulse_v2/device_info.py +173 -0
  802. qiskit/visualization/pulse_v2/drawings.py +253 -0
  803. qiskit/visualization/pulse_v2/events.py +254 -0
  804. qiskit/visualization/pulse_v2/generators/__init__.py +40 -0
  805. qiskit/visualization/pulse_v2/generators/barrier.py +76 -0
  806. qiskit/visualization/pulse_v2/generators/chart.py +208 -0
  807. qiskit/visualization/pulse_v2/generators/frame.py +436 -0
  808. qiskit/visualization/pulse_v2/generators/snapshot.py +133 -0
  809. qiskit/visualization/pulse_v2/generators/waveform.py +645 -0
  810. qiskit/visualization/pulse_v2/interface.py +458 -0
  811. qiskit/visualization/pulse_v2/layouts.py +387 -0
  812. qiskit/visualization/pulse_v2/plotters/__init__.py +17 -0
  813. qiskit/visualization/pulse_v2/plotters/base_plotter.py +53 -0
  814. qiskit/visualization/pulse_v2/plotters/matplotlib.py +201 -0
  815. qiskit/visualization/pulse_v2/stylesheet.py +312 -0
  816. qiskit/visualization/pulse_v2/types.py +242 -0
  817. qiskit/visualization/state_visualization.py +1518 -0
  818. qiskit/visualization/timeline/__init__.py +21 -0
  819. qiskit/visualization/timeline/core.py +480 -0
  820. qiskit/visualization/timeline/drawings.py +260 -0
  821. qiskit/visualization/timeline/generators.py +506 -0
  822. qiskit/visualization/timeline/interface.py +436 -0
  823. qiskit/visualization/timeline/layouts.py +115 -0
  824. qiskit/visualization/timeline/plotters/__init__.py +16 -0
  825. qiskit/visualization/timeline/plotters/base_plotter.py +58 -0
  826. qiskit/visualization/timeline/plotters/matplotlib.py +192 -0
  827. qiskit/visualization/timeline/stylesheet.py +301 -0
  828. qiskit/visualization/timeline/types.py +148 -0
  829. qiskit/visualization/transition_visualization.py +369 -0
  830. qiskit/visualization/utils.py +49 -0
  831. qiskit-1.3.0.dist-info/LICENSE.txt +203 -0
  832. qiskit-1.3.0.dist-info/METADATA +222 -0
  833. qiskit-1.3.0.dist-info/RECORD +836 -0
  834. qiskit-1.3.0.dist-info/WHEEL +5 -0
  835. qiskit-1.3.0.dist-info/entry_points.txt +76 -0
  836. qiskit-1.3.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,1988 @@
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
+ # pylint: disable=invalid-name
14
+
15
+ """Symbolic waveform module.
16
+
17
+ These are pulses which are described by symbolic equations for their envelopes and for their
18
+ parameter constraints.
19
+ """
20
+ from __future__ import annotations
21
+ import functools
22
+ import warnings
23
+ from collections.abc import Mapping, Callable
24
+ from copy import deepcopy
25
+ from typing import Any
26
+
27
+ import numpy as np
28
+ import symengine as sym
29
+
30
+ from qiskit.circuit.parameterexpression import ParameterExpression, ParameterValueType
31
+ from qiskit.pulse.exceptions import PulseError
32
+ from qiskit.pulse.library.pulse import Pulse
33
+ from qiskit.pulse.library.waveform import Waveform
34
+ from qiskit.utils.deprecate_pulse import deprecate_pulse_func
35
+
36
+
37
+ def _lifted_gaussian(
38
+ t: sym.Symbol,
39
+ center: sym.Symbol | sym.Expr | complex,
40
+ t_zero: sym.Symbol | sym.Expr | complex,
41
+ sigma: sym.Symbol | sym.Expr | complex,
42
+ ) -> sym.Expr:
43
+ r"""Helper function that returns a lifted Gaussian symbolic equation.
44
+
45
+ For :math:`\sigma=` ``sigma`` the symbolic equation will be
46
+
47
+ .. math::
48
+
49
+ f(x) = \exp\left(-\frac12 \left(\frac{x - \mu}{\sigma}\right)^2 \right),
50
+
51
+ with the center :math:`\mu=` ``duration/2``.
52
+ Then, each output sample :math:`y` is modified according to:
53
+
54
+ .. math::
55
+
56
+ y \mapsto \frac{y-y^*}{1.0-y^*},
57
+
58
+ where :math:`y^*` is the value of the un-normalized Gaussian at the endpoints of the pulse.
59
+ This sets the endpoints to :math:`0` while preserving the amplitude at the center,
60
+ i.e. :math:`y` is set to :math:`1.0`.
61
+
62
+ Args:
63
+ t: Symbol object representing time.
64
+ center: Symbol or expression representing the middle point of the samples.
65
+ t_zero: The value of t at which the pulse is lowered to 0.
66
+ sigma: Symbol or expression representing Gaussian sigma.
67
+
68
+ Returns:
69
+ Symbolic equation.
70
+ """
71
+ # Sympy automatically does expand.
72
+ # This causes expression inconsistency after qpy round-trip serializing through sympy.
73
+ # See issue for details: https://github.com/symengine/symengine.py/issues/409
74
+ t_shifted = (t - center).expand()
75
+ t_offset = (t_zero - center).expand()
76
+
77
+ gauss = sym.exp(-((t_shifted / sigma) ** 2) / 2)
78
+ offset = sym.exp(-((t_offset / sigma) ** 2) / 2)
79
+
80
+ return (gauss - offset) / (1 - offset)
81
+
82
+
83
+ @functools.lru_cache(maxsize=None)
84
+ def _is_amplitude_valid(
85
+ envelope_lam: Callable, time: tuple[float, ...], *fargs: float
86
+ ) -> bool | np.bool_:
87
+ """A helper function to validate maximum amplitude limit.
88
+
89
+ Result is cached for better performance.
90
+
91
+ Args:
92
+ envelope_lam: The SymbolicPulse's lambdified envelope_lam expression.
93
+ time: The SymbolicPulse's time array, given as a tuple for hashability.
94
+ fargs: The arguments for the lambdified envelope_lam, as given by `_get_expression_args`,
95
+ except for the time array.
96
+
97
+ Returns:
98
+ Return True if no sample point exceeds 1.0 in absolute value.
99
+ """
100
+
101
+ time = np.asarray(time, dtype=float)
102
+ samples_norm = np.abs(envelope_lam(time, *fargs))
103
+ epsilon = 1e-7 # The value of epsilon mimics that of Waveform._clip()
104
+ return np.all(samples_norm < 1.0 + epsilon)
105
+
106
+
107
+ def _get_expression_args(expr: sym.Expr, params: dict[str, float]) -> list[np.ndarray | float]:
108
+ """A helper function to get argument to evaluate expression.
109
+
110
+ Args:
111
+ expr: Symbolic expression to evaluate.
112
+ params: Dictionary of parameter, which is a superset of expression arguments.
113
+
114
+ Returns:
115
+ Arguments passed to the lambdified expression.
116
+
117
+ Raises:
118
+ PulseError: When a free symbol value is not defined in the pulse instance parameters.
119
+ """
120
+ args: list[np.ndarray | float] = []
121
+ for symbol in sorted(expr.free_symbols, key=lambda s: s.name):
122
+ if symbol.name == "t":
123
+ # 't' is a special parameter to represent time vector.
124
+ # This should be place at first to broadcast other parameters
125
+ # in symengine lambdify function.
126
+ times = np.arange(0, params["duration"]) + 1 / 2
127
+ args.insert(0, times)
128
+ continue
129
+ try:
130
+ args.append(params[symbol.name])
131
+ except KeyError as ex:
132
+ raise PulseError(
133
+ f"Pulse parameter '{symbol.name}' is not defined for this instance. "
134
+ "Please check your waveform expression is correct."
135
+ ) from ex
136
+ return args
137
+
138
+
139
+ class LambdifiedExpression:
140
+ """Descriptor to lambdify symbolic expression with cache.
141
+
142
+ When a new symbolic expression is assigned for the first time, :class:`.LambdifiedExpression`
143
+ will internally lambdify the expressions and store the resulting callbacks in its cache.
144
+ The next time it encounters the same expression it will return the cached callbacks
145
+ thereby increasing the code's speed.
146
+
147
+ Note that this class is a python `Descriptor`_, and thus not intended to be
148
+ directly called by end-users. This class is designed to be attached to the
149
+ :class:`.SymbolicPulse` as attributes for symbolic expressions.
150
+
151
+ _`Descriptor`: https://docs.python.org/3/reference/datamodel.html#descriptors
152
+ """
153
+
154
+ def __init__(self, attribute: str):
155
+ """Create new descriptor.
156
+
157
+ Args:
158
+ attribute: Name of attribute of :class:`.SymbolicPulse` that returns
159
+ the target expression to evaluate.
160
+ """
161
+ self.attribute = attribute
162
+ self.lambda_funcs: dict[int, Callable] = {}
163
+
164
+ def __get__(self, instance, owner) -> Callable:
165
+ expr = getattr(instance, self.attribute, None)
166
+ if expr is None:
167
+ raise PulseError(f"'{self.attribute}' of '{instance.pulse_type}' is not assigned.")
168
+ key = hash(expr)
169
+ if key not in self.lambda_funcs:
170
+ self.__set__(instance, expr)
171
+
172
+ return self.lambda_funcs[key]
173
+
174
+ def __set__(self, instance, value):
175
+ key = hash(value)
176
+ if key not in self.lambda_funcs:
177
+ params: list[Any] = []
178
+ for p in sorted(value.free_symbols, key=lambda s: s.name):
179
+ if p.name == "t":
180
+ # Argument "t" must be placed at first. This is a vector.
181
+ params.insert(0, p)
182
+ continue
183
+ params.append(p)
184
+
185
+ try:
186
+ lamb = sym.lambdify(params, [value], real=False)
187
+
188
+ def _wrapped_lamb(*args):
189
+ if isinstance(args[0], np.ndarray):
190
+ # When the args[0] is a vector ("t"), tile other arguments args[1:]
191
+ # to prevent evaluation from looping over each element in t.
192
+ t = args[0]
193
+ args = np.hstack(
194
+ (
195
+ t.reshape(t.size, 1),
196
+ np.tile(args[1:], t.size).reshape(t.size, len(args) - 1),
197
+ )
198
+ )
199
+ return lamb(args)
200
+
201
+ func = _wrapped_lamb
202
+ except RuntimeError:
203
+ # Currently symengine doesn't support complex_double version for
204
+ # several functions such as comparison operator and piecewise.
205
+ # If expression contains these function, it fall back to sympy lambdify.
206
+ # See https://github.com/symengine/symengine.py/issues/406 for details.
207
+ import sympy
208
+
209
+ func = sympy.lambdify(params, value)
210
+
211
+ self.lambda_funcs[key] = func
212
+
213
+
214
+ class SymbolicPulse(Pulse):
215
+ r"""The pulse representation model with parameters and symbolic expressions.
216
+
217
+ A symbolic pulse instance can be defined with an envelope and parameter constraints.
218
+ Envelope and parameter constraints should be provided as symbolic expressions.
219
+ Rather than creating a subclass, different pulse shapes can be distinguished by
220
+ the instance attributes :attr:`SymbolicPulse.envelope` and :attr:`SymbolicPulse.pulse_type`.
221
+
222
+ The symbolic expressions must be defined either with SymPy_ or Symengine_.
223
+ Usually Symengine-based expression is much more performant for instantiation
224
+ of the :class:`SymbolicPulse`, however, it doesn't support every functions available in SymPy.
225
+ You may need to choose proper library depending on how you define your pulses.
226
+ Symengine works in the most envelopes and constraints, and thus it is recommended to use
227
+ this library especially when your program contains a lot of pulses.
228
+ Also note that Symengine has the limited platform support and may not be available
229
+ for your local system. Symengine is a required dependency for Qiskit on platforms
230
+ that support it will always be installed along with Qiskit on macOS ``x86_64`` and ``arm64``,
231
+ and Linux ``x86_64``, ``aarch64``, and ``ppc64le``.
232
+ For 64-bit Windows users they will need to manual install it.
233
+ For 32-bit platforms such as ``i686`` and ``armv7`` Linux, and on Linux ``s390x``
234
+ there are no pre-compiled packages available and to use symengine you'll need to
235
+ compile it from source. If Symengine is not available in your environment SymPy will be used.
236
+
237
+ .. _SymPy: https://www.sympy.org/en/index.html
238
+ .. _Symengine: https://symengine.org
239
+
240
+ .. _symbolic_pulse_envelope:
241
+
242
+ .. rubric:: Envelope function
243
+
244
+ The waveform at time :math:`t` is generated by the :meth:`get_waveform` according to
245
+
246
+ .. math::
247
+
248
+ F(t, \Theta) = \times F(t, {\rm duration}, \overline{\rm params})
249
+
250
+ where :math:`\Theta` is the set of full pulse parameters in the :attr:`SymbolicPulse.parameters`
251
+ dictionary which must include the :math:`\rm duration`.
252
+ Note that the :math:`F` is an envelope of the waveform, and a programmer must provide this
253
+ as a symbolic expression. :math:`\overline{\rm params}` can be arbitrary complex values
254
+ as long as they pass :meth:`.validate_parameters` and your quantum backend can accept.
255
+ The time :math:`t` and :math:`\rm duration` are in units of dt, i.e. sample time resolution,
256
+ and this function is sampled with a discrete time vector in :math:`[0, {\rm duration}]`
257
+ sampling the pulse envelope at every 0.5 dt (middle sampling strategy) when
258
+ the :meth:`SymbolicPulse.get_waveform` method is called.
259
+ The sample data is not generated until this method is called
260
+ thus a symbolic pulse instance only stores parameter values and waveform shape,
261
+ which greatly reduces memory footprint during the program generation.
262
+
263
+
264
+ .. _symbolic_pulse_validation:
265
+
266
+ .. rubric:: Pulse validation
267
+
268
+ When a symbolic pulse is instantiated, the method :meth:`.validate_parameters` is called,
269
+ and performs validation of the pulse. The validation process involves testing the constraint
270
+ functions and the maximal amplitude of the pulse (see below). While the validation process
271
+ will improve code stability, it will reduce performance and might create
272
+ compatibility issues (particularly with JAX). Therefore, it is possible to disable the
273
+ validation by setting the class attribute :attr:`.disable_validation` to ``True``.
274
+
275
+ .. _symbolic_pulse_constraints:
276
+
277
+ .. rubric:: Constraint functions
278
+
279
+ Constraints on the parameters are defined with an instance attribute
280
+ :attr:`SymbolicPulse.constraints` which can be provided through the constructor.
281
+ The constraints value must be a symbolic expression, which is a
282
+ function of parameters to be validated and must return a boolean value
283
+ being ``True`` when parameters are valid.
284
+ If there are multiple conditions to be evaluated, these conditions can be
285
+ concatenated with logical expressions such as ``And`` and ``Or`` in SymPy or Symengine.
286
+ The symbolic pulse instance can be played only when the constraint function returns ``True``.
287
+ The constraint is evaluated when :meth:`.validate_parameters` is called.
288
+
289
+
290
+ .. _symbolic_pulse_eval_condition:
291
+
292
+ .. rubric:: Maximum amplitude validation
293
+
294
+ When you play a pulse in a quantum backend, you might face the restriction on the power
295
+ that your waveform generator can handle. Usually, the pulse amplitude is normalized
296
+ by this maximum power, namely :math:`\max |F| \leq 1`. This condition is
297
+ evaluated along with above constraints when you set ``limit_amplitude = True`` in the constructor.
298
+ To evaluate maximum amplitude of the waveform, we need to call :meth:`get_waveform`.
299
+ However, this introduces a significant overhead in the validation, and this cannot be ignored
300
+ when you repeatedly instantiate symbolic pulse instances.
301
+ :attr:`SymbolicPulse.valid_amp_conditions` provides a condition to skip this waveform validation,
302
+ and the waveform is not generated as long as this condition returns ``True``,
303
+ so that `healthy` symbolic pulses are created very quick.
304
+ For example, for a simple pulse shape like ``amp * cos(f * t)``, we know that
305
+ pulse amplitude is valid as long as ``amp`` remains less than magnitude 1.0.
306
+ So ``abs(amp) <= 1`` could be passed as :attr:`SymbolicPulse.valid_amp_conditions` to skip
307
+ doing a full waveform evaluation for amplitude validation.
308
+ This expression is provided through the constructor. If this is not provided,
309
+ the waveform is generated everytime when :meth:`.validate_parameters` is called.
310
+
311
+
312
+ .. rubric:: Examples
313
+
314
+ This is how a user can instantiate a symbolic pulse instance.
315
+ In this example, we instantiate a custom `Sawtooth` envelope.
316
+
317
+ .. code-block::
318
+
319
+ from qiskit.pulse.library import SymbolicPulse
320
+
321
+ my_pulse = SymbolicPulse(
322
+ pulse_type="Sawtooth",
323
+ duration=100,
324
+ parameters={"amp": 0.1, "freq": 0.05},
325
+ name="pulse1",
326
+ )
327
+
328
+ Note that :class:`SymbolicPulse` can be instantiated without providing
329
+ the envelope and constraints. However, this instance cannot generate waveforms
330
+ without knowing the envelope definition. Now you need to provide the envelope.
331
+
332
+ .. plot::
333
+ :include-source:
334
+
335
+ import sympy
336
+ from qiskit.pulse.library import SymbolicPulse
337
+
338
+ t, amp, freq = sympy.symbols("t, amp, freq")
339
+ envelope = 2 * amp * (freq * t - sympy.floor(1 / 2 + freq * t))
340
+
341
+ my_pulse = SymbolicPulse(
342
+ pulse_type="Sawtooth",
343
+ duration=100,
344
+ parameters={"amp": 0.1, "freq": 0.05},
345
+ envelope=envelope,
346
+ name="pulse1",
347
+ )
348
+
349
+ my_pulse.draw()
350
+
351
+ Likewise, you can define :attr:`SymbolicPulse.constraints` for ``my_pulse``.
352
+ After providing the envelope definition, you can generate the waveform data.
353
+ Note that it would be convenient to define a factory function that automatically
354
+ accomplishes this procedure.
355
+
356
+ .. code-block:: python
357
+
358
+ def Sawtooth(duration, amp, freq, name):
359
+ t, amp, freq = sympy.symbols("t, amp, freq")
360
+
361
+ instance = SymbolicPulse(
362
+ pulse_type="Sawtooth",
363
+ duration=duration,
364
+ parameters={"amp": amp, "freq": freq},
365
+ envelope=2 * amp * (freq * t - sympy.floor(1 / 2 + freq * t)),
366
+ name=name,
367
+ )
368
+
369
+ return instance
370
+
371
+ You can also provide a :class:`Parameter` object in the ``parameters`` dictionary,
372
+ or define ``duration`` with a :class:`Parameter` object when you instantiate
373
+ the symbolic pulse instance.
374
+ A waveform cannot be generated until you assign all unbounded parameters.
375
+ Note that parameters will be assigned through the schedule playing the pulse.
376
+
377
+
378
+ .. _symbolic_pulse_serialize:
379
+
380
+ .. rubric:: Serialization
381
+
382
+ The :class:`~SymbolicPulse` subclass can be serialized along with the
383
+ symbolic expressions through :mod:`qiskit.qpy`.
384
+ A user can therefore create a custom pulse subclass with a novel envelope and constraints,
385
+ and then one can instantiate the class with certain parameters to run on a backend.
386
+ This pulse instance can be saved in the QPY binary, which can be loaded afterwards
387
+ even within the environment not having original class definition loaded.
388
+ This mechanism also allows us to easily share a pulse program including
389
+ custom pulse instructions with collaborators.
390
+ """
391
+
392
+ __slots__ = (
393
+ "_pulse_type",
394
+ "_params",
395
+ "_envelope",
396
+ "_constraints",
397
+ "_valid_amp_conditions",
398
+ )
399
+
400
+ disable_validation = False
401
+
402
+ # Lambdify caches keyed on sympy expressions. Returns the corresponding callable.
403
+ _envelope_lam = LambdifiedExpression("_envelope")
404
+ _constraints_lam = LambdifiedExpression("_constraints")
405
+ _valid_amp_conditions_lam = LambdifiedExpression("_valid_amp_conditions")
406
+
407
+ @deprecate_pulse_func
408
+ def __init__(
409
+ self,
410
+ pulse_type: str,
411
+ duration: ParameterExpression | int,
412
+ parameters: Mapping[str, ParameterExpression | complex] | None = None,
413
+ name: str | None = None,
414
+ limit_amplitude: bool | None = None,
415
+ envelope: sym.Expr | None = None,
416
+ constraints: sym.Expr | None = None,
417
+ valid_amp_conditions: sym.Expr | None = None,
418
+ ):
419
+ """Create a parametric pulse.
420
+
421
+ Args:
422
+ pulse_type: Display name of this pulse shape.
423
+ duration: Duration of pulse.
424
+ parameters: Dictionary of pulse parameters that defines the pulse envelope.
425
+ name: Display name for this particular pulse envelope.
426
+ limit_amplitude: If ``True``, then limit the absolute value of the amplitude of the
427
+ waveform to 1. The default is ``True`` and the amplitude is constrained to 1.
428
+ envelope: Pulse envelope expression.
429
+ constraints: Pulse parameter constraint expression.
430
+ valid_amp_conditions: Extra conditions to skip a full-waveform check for the
431
+ amplitude limit. If this condition is not met, then the validation routine
432
+ will investigate the full-waveform and raise an error when the amplitude norm
433
+ of any data point exceeds 1.0. If not provided, the validation always
434
+ creates a full-waveform.
435
+
436
+ Raises:
437
+ PulseError: When not all parameters are listed in the attribute :attr:`PARAM_DEF`.
438
+ """
439
+ super().__init__(
440
+ duration=duration,
441
+ name=name,
442
+ limit_amplitude=limit_amplitude,
443
+ )
444
+ if parameters is None:
445
+ parameters = {}
446
+
447
+ self._pulse_type = pulse_type
448
+ self._params = parameters
449
+
450
+ self._envelope = envelope
451
+ self._constraints = constraints
452
+ self._valid_amp_conditions = valid_amp_conditions
453
+ if not self.__class__.disable_validation:
454
+ self.validate_parameters()
455
+
456
+ def __getattr__(self, item):
457
+ # Get pulse parameters with attribute-like access.
458
+ params = object.__getattribute__(self, "_params")
459
+ if item not in params:
460
+ raise AttributeError(f"'{self.__class__.__name__}' object has no attribute '{item}'")
461
+ return params[item]
462
+
463
+ @property
464
+ def pulse_type(self) -> str:
465
+ """Return display name of the pulse shape."""
466
+ return self._pulse_type
467
+
468
+ @property
469
+ def envelope(self) -> sym.Expr:
470
+ """Return symbolic expression for the pulse envelope."""
471
+ return self._envelope
472
+
473
+ @property
474
+ def constraints(self) -> sym.Expr:
475
+ """Return symbolic expression for the pulse parameter constraints."""
476
+ return self._constraints
477
+
478
+ @property
479
+ def valid_amp_conditions(self) -> sym.Expr:
480
+ """Return symbolic expression for the pulse amplitude constraints."""
481
+ return self._valid_amp_conditions
482
+
483
+ def get_waveform(self) -> Waveform:
484
+ r"""Return a Waveform with samples filled according to the formula that the pulse
485
+ represents and the parameter values it contains.
486
+
487
+ Since the returned array is a discretized time series of the continuous function,
488
+ this method uses a midpoint sampler. For ``duration``, return:
489
+
490
+ .. math::
491
+
492
+ \{f(t+0.5) \in \mathbb{C} | t \in \mathbb{Z} \wedge 0<=t<\texttt{duration}\}
493
+
494
+ Returns:
495
+ A waveform representation of this pulse.
496
+
497
+ Raises:
498
+ PulseError: When parameters are not assigned.
499
+ PulseError: When expression for pulse envelope is not assigned.
500
+ """
501
+ if self.is_parameterized():
502
+ raise PulseError("Unassigned parameter exists. All parameters must be assigned.")
503
+
504
+ if self._envelope is None:
505
+ raise PulseError("Pulse envelope expression is not assigned.")
506
+
507
+ fargs = _get_expression_args(self._envelope, self.parameters)
508
+ return Waveform(samples=self._envelope_lam(*fargs), name=self.name)
509
+
510
+ def validate_parameters(self) -> None:
511
+ """Validate parameters.
512
+
513
+ Raises:
514
+ PulseError: If the parameters passed are not valid.
515
+ """
516
+ if self.is_parameterized():
517
+ return
518
+
519
+ if self._constraints is not None:
520
+ fargs = _get_expression_args(self._constraints, self.parameters)
521
+ if not bool(self._constraints_lam(*fargs)):
522
+ param_repr = ", ".join(f"{p}={v}" for p, v in self.parameters.items())
523
+ const_repr = str(self._constraints)
524
+ raise PulseError(
525
+ f"Assigned parameters {param_repr} violate following constraint: {const_repr}."
526
+ )
527
+
528
+ if self._limit_amplitude:
529
+ if self._valid_amp_conditions is not None:
530
+ fargs = _get_expression_args(self._valid_amp_conditions, self.parameters)
531
+ check_full_waveform = not bool(self._valid_amp_conditions_lam(*fargs))
532
+ else:
533
+ check_full_waveform = True
534
+
535
+ if check_full_waveform:
536
+ # Check full waveform only when the condition is satisified or
537
+ # evaluation condition is not provided.
538
+ # This operation is slower due to overhead of 'get_waveform'.
539
+ fargs = _get_expression_args(self._envelope, self.parameters)
540
+
541
+ if not _is_amplitude_valid(self._envelope_lam, tuple(fargs.pop(0)), *fargs):
542
+ param_repr = ", ".join(f"{p}={v}" for p, v in self.parameters.items())
543
+ raise PulseError(
544
+ f"Maximum pulse amplitude norm exceeds 1.0 with parameters {param_repr}."
545
+ "This can be overruled by setting Pulse.limit_amplitude."
546
+ )
547
+
548
+ def is_parameterized(self) -> bool:
549
+ """Return True iff the instruction is parameterized."""
550
+ return any(isinstance(val, ParameterExpression) for val in self.parameters.values())
551
+
552
+ @property
553
+ def parameters(self) -> dict[str, Any]:
554
+ params: dict[str, ParameterExpression | complex | int] = {"duration": self.duration}
555
+ params.update(self._params)
556
+ return params
557
+
558
+ def __eq__(self, other: object) -> bool:
559
+ if not isinstance(other, SymbolicPulse):
560
+ return NotImplemented
561
+
562
+ if self._pulse_type != other._pulse_type:
563
+ return False
564
+
565
+ if self._envelope != other._envelope:
566
+ return False
567
+
568
+ if self.parameters != other.parameters:
569
+ return False
570
+
571
+ return True
572
+
573
+ def __repr__(self) -> str:
574
+ param_repr = ", ".join(f"{p}={v}" for p, v in self.parameters.items())
575
+ name_repr = f", name='{self.name}'" if self.name is not None else ""
576
+ return f"{self._pulse_type}({param_repr}{name_repr})"
577
+
578
+ __hash__ = None
579
+
580
+
581
+ class ScalableSymbolicPulse(SymbolicPulse):
582
+ r"""Subclass of :class:`SymbolicPulse` for pulses with scalable envelope.
583
+
584
+ Instance of :class:`ScalableSymbolicPulse` behaves the same as an instance of
585
+ :class:`SymbolicPulse`, but its envelope is assumed to have a scalable form
586
+ :math:`\text{amp}\times\exp\left(i\times\text{angle}\right)\times\text{F}
587
+ \left(t,\text{parameters}\right)`,
588
+ where :math:`\text{F}` is some function describing the rest of the envelope,
589
+ and both `amp` and `angle` are real (float). Note that both `amp` and `angle` are
590
+ stored in the :attr:`parameters` dictionary of the :class:`ScalableSymbolicPulse`
591
+ instance.
592
+
593
+ When two :class:`ScalableSymbolicPulse` objects are equated, instead of comparing
594
+ `amp` and `angle` individually, only the complex amplitude
595
+ :math:'\text{amp}\times\exp\left(i\times\text{angle}\right)' is compared.
596
+ """
597
+
598
+ def __init__(
599
+ self,
600
+ pulse_type: str,
601
+ duration: ParameterExpression | int,
602
+ amp: ParameterValueType,
603
+ angle: ParameterValueType,
604
+ parameters: dict[str, ParameterExpression | complex] | None = None,
605
+ name: str | None = None,
606
+ limit_amplitude: bool | None = None,
607
+ envelope: sym.Expr | None = None,
608
+ constraints: sym.Expr | None = None,
609
+ valid_amp_conditions: sym.Expr | None = None,
610
+ ):
611
+ """Create a scalable symbolic pulse.
612
+
613
+ Args:
614
+ pulse_type: Display name of this pulse shape.
615
+ duration: Duration of pulse.
616
+ amp: The magnitude of the complex amplitude of the pulse.
617
+ angle: The phase of the complex amplitude of the pulse.
618
+ parameters: Dictionary of pulse parameters that defines the pulse envelope.
619
+ name: Display name for this particular pulse envelope.
620
+ limit_amplitude: If ``True``, then limit the absolute value of the amplitude of the
621
+ waveform to 1. The default is ``True`` and the amplitude is constrained to 1.
622
+ envelope: Pulse envelope expression.
623
+ constraints: Pulse parameter constraint expression.
624
+ valid_amp_conditions: Extra conditions to skip a full-waveform check for the
625
+ amplitude limit. If this condition is not met, then the validation routine
626
+ will investigate the full-waveform and raise an error when the amplitude norm
627
+ of any data point exceeds 1.0. If not provided, the validation always
628
+ creates a full-waveform.
629
+
630
+ Raises:
631
+ PulseError: If ``amp`` is complex.
632
+ """
633
+ if isinstance(amp, complex):
634
+ raise PulseError(
635
+ "amp represents the magnitude of the complex amplitude and can't be complex"
636
+ )
637
+
638
+ if not isinstance(parameters, dict):
639
+ parameters = {"amp": amp, "angle": angle}
640
+ else:
641
+ parameters = deepcopy(parameters)
642
+ parameters["amp"] = amp
643
+ parameters["angle"] = angle
644
+
645
+ super().__init__(
646
+ pulse_type=pulse_type,
647
+ duration=duration,
648
+ parameters=parameters,
649
+ name=name,
650
+ limit_amplitude=limit_amplitude,
651
+ envelope=envelope,
652
+ constraints=constraints,
653
+ valid_amp_conditions=valid_amp_conditions,
654
+ )
655
+
656
+ # pylint: disable=too-many-return-statements
657
+ def __eq__(self, other: object) -> bool:
658
+ if not isinstance(other, ScalableSymbolicPulse):
659
+ return NotImplemented
660
+
661
+ if self._pulse_type != other._pulse_type:
662
+ return False
663
+
664
+ if self._envelope != other._envelope:
665
+ return False
666
+
667
+ complex_amp1 = self.amp * np.exp(1j * self.angle)
668
+ complex_amp2 = other.amp * np.exp(1j * other.angle)
669
+
670
+ if isinstance(complex_amp1, ParameterExpression) or isinstance(
671
+ complex_amp2, ParameterExpression
672
+ ):
673
+ if complex_amp1 != complex_amp2:
674
+ return False
675
+ else:
676
+ if not np.isclose(complex_amp1, complex_amp2):
677
+ return False
678
+
679
+ for key, value in self.parameters.items():
680
+ if key not in ["amp", "angle"] and value != other.parameters[key]:
681
+ return False
682
+
683
+ return True
684
+
685
+
686
+ class _PulseType(type):
687
+ """Metaclass to warn at isinstance check."""
688
+
689
+ def __instancecheck__(cls, instance):
690
+ cls_alias = getattr(cls, "alias", None)
691
+
692
+ # TODO promote this to Deprecation warning in future.
693
+ # Once type information usage is removed from user code,
694
+ # we will convert pulse classes into functions.
695
+ warnings.warn(
696
+ "Typechecking with the symbolic pulse subclass will be deprecated. "
697
+ f"'{cls_alias}' subclass instance is turned into SymbolicPulse instance. "
698
+ f"Use self.pulse_type == '{cls_alias}' instead.",
699
+ PendingDeprecationWarning,
700
+ )
701
+
702
+ if not isinstance(instance, SymbolicPulse):
703
+ return False
704
+ return instance.pulse_type == cls_alias
705
+
706
+ def __getattr__(cls, item):
707
+ # For pylint. A SymbolicPulse subclass must implement several methods
708
+ # such as .get_waveform and .validate_parameters.
709
+ # In addition, they conventionally offer attribute-like access to the pulse parameters,
710
+ # for example, instance.amp returns instance._params["amp"].
711
+ # If pulse classes are directly instantiated, pylint yells no-member
712
+ # since the pulse class itself implements nothing. These classes just
713
+ # behave like a factory by internally instantiating the SymbolicPulse and return it.
714
+ # It is not realistic to write disable=no-member across qiskit packages.
715
+ return NotImplemented
716
+
717
+
718
+ class Gaussian(metaclass=_PulseType):
719
+ r"""A lifted and truncated pulse envelope shaped according to the Gaussian function whose
720
+ mean is centered at the center of the pulse (duration / 2):
721
+
722
+ .. math::
723
+
724
+ \begin{aligned}
725
+ f'(x) &= \exp\Bigl( -\frac12 \frac{{(x - \text{duration}/2)}^2}{\text{sigma}^2} \Bigr)\\
726
+ f(x) &= \text{A} \times \frac{f'(x) - f'(-1)}{1-f'(-1)}, \quad 0 \le x < \text{duration}
727
+ \end{aligned}
728
+
729
+ where :math:`f'(x)` is the gaussian waveform without lifting or amplitude scaling, and
730
+ :math:`\text{A} = \text{amp} \times \exp\left(i\times\text{angle}\right)`.
731
+ """
732
+
733
+ alias = "Gaussian"
734
+
735
+ def __new__(
736
+ cls,
737
+ duration: int | ParameterValueType,
738
+ amp: ParameterValueType,
739
+ sigma: ParameterValueType,
740
+ angle: ParameterValueType = 0.0,
741
+ name: str | None = None,
742
+ limit_amplitude: bool | None = None,
743
+ ) -> ScalableSymbolicPulse:
744
+ """Create new pulse instance.
745
+
746
+ Args:
747
+ duration: Pulse length in terms of the sampling period `dt`.
748
+ amp: The magnitude of the amplitude of the Gaussian envelope.
749
+ sigma: A measure of how wide or narrow the Gaussian peak is; described mathematically
750
+ in the class docstring.
751
+ angle: The angle of the complex amplitude of the Gaussian envelope. Default value 0.
752
+ name: Display name for this pulse envelope.
753
+ limit_amplitude: If ``True``, then limit the amplitude of the
754
+ waveform to 1. The default is ``True`` and the amplitude is constrained to 1.
755
+
756
+ Returns:
757
+ ScalableSymbolicPulse instance.
758
+ """
759
+ parameters = {"sigma": sigma}
760
+
761
+ # Prepare symbolic expressions
762
+ _t, _duration, _amp, _sigma, _angle = sym.symbols("t, duration, amp, sigma, angle")
763
+ _center = _duration / 2
764
+
765
+ envelope_expr = (
766
+ _amp * sym.exp(sym.I * _angle) * _lifted_gaussian(_t, _center, _duration + 1, _sigma)
767
+ )
768
+
769
+ consts_expr = _sigma > 0
770
+ valid_amp_conditions_expr = sym.Abs(_amp) <= 1.0
771
+
772
+ return ScalableSymbolicPulse(
773
+ pulse_type=cls.alias,
774
+ duration=duration,
775
+ amp=amp,
776
+ angle=angle,
777
+ parameters=parameters,
778
+ name=name,
779
+ limit_amplitude=limit_amplitude,
780
+ envelope=envelope_expr,
781
+ constraints=consts_expr,
782
+ valid_amp_conditions=valid_amp_conditions_expr,
783
+ )
784
+
785
+ @deprecate_pulse_func
786
+ def __init__(self):
787
+ pass
788
+
789
+
790
+ class GaussianSquare(metaclass=_PulseType):
791
+ """A square pulse with a Gaussian shaped risefall on both sides lifted such that
792
+ its first sample is zero.
793
+
794
+ Exactly one of the ``risefall_sigma_ratio`` and ``width`` parameters has to be specified.
795
+
796
+ If ``risefall_sigma_ratio`` is not None and ``width`` is None:
797
+
798
+ .. math::
799
+
800
+ \\begin{aligned}
801
+ \\text{risefall} &= \\text{risefall\\_sigma\\_ratio} \\times \\text{sigma}\\\\
802
+ \\text{width} &= \\text{duration} - 2 \\times \\text{risefall}
803
+ \\end{aligned}
804
+
805
+ If ``width`` is not None and ``risefall_sigma_ratio`` is None:
806
+
807
+ .. math:: \\text{risefall} = \\frac{\\text{duration} - \\text{width}}{2}
808
+
809
+ In both cases, the lifted gaussian square pulse :math:`f'(x)` is defined as:
810
+
811
+ .. math::
812
+
813
+ \\begin{aligned}
814
+ f'(x) &= \\begin{cases}\
815
+ \\exp\\biggl(-\\frac12 \\frac{(x - \\text{risefall})^2}{\\text{sigma}^2}\\biggr)\
816
+ & x < \\text{risefall}\\\\
817
+ 1\
818
+ & \\text{risefall} \\le x < \\text{risefall} + \\text{width}\\\\
819
+ \\exp\\biggl(-\\frac12\
820
+ \\frac{{\\bigl(x - (\\text{risefall} + \\text{width})\\bigr)}^2}\
821
+ {\\text{sigma}^2}\
822
+ \\biggr)\
823
+ & \\text{risefall} + \\text{width} \\le x\
824
+ \\end{cases}\\\\
825
+ f(x) &= \\text{A} \\times \\frac{f'(x) - f'(-1)}{1-f'(-1)},\
826
+ \\quad 0 \\le x < \\text{duration}
827
+ \\end{aligned}
828
+
829
+ where :math:`f'(x)` is the gaussian square waveform without lifting or amplitude scaling, and
830
+ :math:`\\text{A} = \\text{amp} \\times \\exp\\left(i\\times\\text{angle}\\right)`.
831
+ """
832
+
833
+ alias = "GaussianSquare"
834
+
835
+ def __new__(
836
+ cls,
837
+ duration: int | ParameterValueType,
838
+ amp: ParameterValueType,
839
+ sigma: ParameterValueType,
840
+ width: ParameterValueType | None = None,
841
+ angle: ParameterValueType = 0.0,
842
+ risefall_sigma_ratio: ParameterValueType | None = None,
843
+ name: str | None = None,
844
+ limit_amplitude: bool | None = None,
845
+ ) -> ScalableSymbolicPulse:
846
+ """Create new pulse instance.
847
+
848
+ Args:
849
+ duration: Pulse length in terms of the sampling period `dt`.
850
+ amp: The magnitude of the amplitude of the Gaussian and square pulse.
851
+ sigma: A measure of how wide or narrow the Gaussian risefall is; see the class
852
+ docstring for more details.
853
+ width: The duration of the embedded square pulse.
854
+ angle: The angle of the complex amplitude of the pulse. Default value 0.
855
+ risefall_sigma_ratio: The ratio of each risefall duration to sigma.
856
+ name: Display name for this pulse envelope.
857
+ limit_amplitude: If ``True``, then limit the amplitude of the
858
+ waveform to 1. The default is ``True`` and the amplitude is constrained to 1.
859
+
860
+ Returns:
861
+ ScalableSymbolicPulse instance.
862
+
863
+ Raises:
864
+ PulseError: When width and risefall_sigma_ratio are both empty or both non-empty.
865
+ """
866
+ # Convert risefall_sigma_ratio into width which is defined in OpenPulse spec
867
+ if width is None and risefall_sigma_ratio is None:
868
+ raise PulseError(
869
+ "Either the pulse width or the risefall_sigma_ratio parameter must be specified."
870
+ )
871
+ if width is not None and risefall_sigma_ratio is not None:
872
+ raise PulseError(
873
+ "Either the pulse width or the risefall_sigma_ratio parameter can be specified"
874
+ " but not both."
875
+ )
876
+ if width is None and risefall_sigma_ratio is not None:
877
+ width = duration - 2.0 * risefall_sigma_ratio * sigma
878
+
879
+ parameters = {"sigma": sigma, "width": width}
880
+
881
+ # Prepare symbolic expressions
882
+ _t, _duration, _amp, _sigma, _width, _angle = sym.symbols(
883
+ "t, duration, amp, sigma, width, angle"
884
+ )
885
+ _center = _duration / 2
886
+
887
+ _sq_t0 = _center - _width / 2
888
+ _sq_t1 = _center + _width / 2
889
+
890
+ _gaussian_ledge = _lifted_gaussian(_t, _sq_t0, -1, _sigma)
891
+ _gaussian_redge = _lifted_gaussian(_t, _sq_t1, _duration + 1, _sigma)
892
+
893
+ envelope_expr = (
894
+ _amp
895
+ * sym.exp(sym.I * _angle)
896
+ * sym.Piecewise(
897
+ (_gaussian_ledge, _t <= _sq_t0), (_gaussian_redge, _t >= _sq_t1), (1, True)
898
+ )
899
+ )
900
+
901
+ consts_expr = sym.And(_sigma > 0, _width >= 0, _duration >= _width)
902
+ valid_amp_conditions_expr = sym.Abs(_amp) <= 1.0
903
+
904
+ return ScalableSymbolicPulse(
905
+ pulse_type=cls.alias,
906
+ duration=duration,
907
+ amp=amp,
908
+ angle=angle,
909
+ parameters=parameters,
910
+ name=name,
911
+ limit_amplitude=limit_amplitude,
912
+ envelope=envelope_expr,
913
+ constraints=consts_expr,
914
+ valid_amp_conditions=valid_amp_conditions_expr,
915
+ )
916
+
917
+ @deprecate_pulse_func
918
+ def __init__(self):
919
+ pass
920
+
921
+
922
+ @deprecate_pulse_func
923
+ def GaussianSquareDrag(
924
+ duration: int | ParameterExpression,
925
+ amp: float | ParameterExpression,
926
+ sigma: float | ParameterExpression,
927
+ beta: float | ParameterExpression,
928
+ width: float | ParameterExpression | None = None,
929
+ angle: float | ParameterExpression | None = 0.0,
930
+ risefall_sigma_ratio: float | ParameterExpression | None = None,
931
+ name: str | None = None,
932
+ limit_amplitude: bool | None = None,
933
+ ) -> ScalableSymbolicPulse:
934
+ """A square pulse with a Drag shaped rise and fall
935
+
936
+ This pulse shape is similar to :class:`~.GaussianSquare` but uses
937
+ :class:`~.Drag` for its rise and fall instead of :class:`~.Gaussian`. The
938
+ addition of the DRAG component of the rise and fall is sometimes helpful in
939
+ suppressing the spectral content of the pulse at frequencies near to, but
940
+ slightly offset from, the fundamental frequency of the drive. When there is
941
+ a spectator qubit close in frequency to the fundamental frequency,
942
+ suppressing the drive at the spectator's frequency can help avoid unwanted
943
+ excitation of the spectator.
944
+
945
+ Exactly one of the ``risefall_sigma_ratio`` and ``width`` parameters has to be specified.
946
+
947
+ If ``risefall_sigma_ratio`` is not ``None`` and ``width`` is ``None``:
948
+
949
+ .. math::
950
+
951
+ \\begin{aligned}
952
+ \\text{risefall} &= \\text{risefall\\_sigma\\_ratio} \\times \\text{sigma}\\\\
953
+ \\text{width} &= \\text{duration} - 2 \\times \\text{risefall}
954
+ \\end{aligned}
955
+
956
+ If ``width`` is not None and ``risefall_sigma_ratio`` is None:
957
+
958
+ .. math:: \\text{risefall} = \\frac{\\text{duration} - \\text{width}}{2}
959
+
960
+ Gaussian :math:`g(x, c, σ)` and lifted gaussian :math:`g'(x, c, σ)` curves
961
+ can be written as:
962
+
963
+ .. math::
964
+
965
+ \\begin{aligned}
966
+ g(x, c, σ) &= \\exp\\Bigl(-\\frac12 \\frac{(x - c)^2}{σ^2}\\Bigr)\\\\
967
+ g'(x, c, σ) &= \\frac{g(x, c, σ)-g(-1, c, σ)}{1-g(-1, c, σ)}
968
+ \\end{aligned}
969
+
970
+ From these, the lifted DRAG curve :math:`d'(x, c, σ, β)` can be written as
971
+
972
+ .. math::
973
+
974
+ d'(x, c, σ, β) = g'(x, c, σ) \\times \\Bigl(1 + 1j \\times β \\times\
975
+ \\Bigl(-\\frac{x - c}{σ^2}\\Bigr)\\Bigr)
976
+
977
+ The lifted gaussian square drag pulse :math:`f'(x)` is defined as:
978
+
979
+ .. math::
980
+
981
+ \\begin{aligned}
982
+ f'(x) &= \\begin{cases}\
983
+ \\text{A} \\times d'(x, \\text{risefall}, \\text{sigma}, \\text{beta})\
984
+ & x < \\text{risefall}\\\\
985
+ \\text{A}\
986
+ & \\text{risefall} \\le x < \\text{risefall} + \\text{width}\\\\
987
+ \\text{A} \\times \\times d'(\
988
+ x - (\\text{risefall} + \\text{width}),\
989
+ \\text{risefall},\
990
+ \\text{sigma},\
991
+ \\text{beta}\
992
+ )\
993
+ & \\text{risefall} + \\text{width} \\le x\
994
+ \\end{cases}\\\\
995
+ \\end{aligned}
996
+
997
+ where :math:`\\text{A} = \\text{amp} \\times
998
+ \\exp\\left(i\\times\\text{angle}\\right)`.
999
+
1000
+ Args:
1001
+ duration: Pulse length in terms of the sampling period `dt`.
1002
+ amp: The amplitude of the DRAG rise and fall and of the square pulse.
1003
+ sigma: A measure of how wide or narrow the DRAG risefall is; see the class
1004
+ docstring for more details.
1005
+ beta: The DRAG correction amplitude.
1006
+ width: The duration of the embedded square pulse.
1007
+ angle: The angle in radians of the complex phase factor uniformly
1008
+ scaling the pulse. Default value 0.
1009
+ risefall_sigma_ratio: The ratio of each risefall duration to sigma.
1010
+ name: Display name for this pulse envelope.
1011
+ limit_amplitude: If ``True``, then limit the amplitude of the
1012
+ waveform to 1. The default is ``True`` and the amplitude is constrained to 1.
1013
+
1014
+ Returns:
1015
+ ScalableSymbolicPulse instance.
1016
+
1017
+ Raises:
1018
+ PulseError: When width and risefall_sigma_ratio are both empty or both non-empty.
1019
+ """
1020
+ # Convert risefall_sigma_ratio into width which is defined in OpenPulse spec
1021
+ if width is None and risefall_sigma_ratio is None:
1022
+ raise PulseError(
1023
+ "Either the pulse width or the risefall_sigma_ratio parameter must be specified."
1024
+ )
1025
+ if width is not None and risefall_sigma_ratio is not None:
1026
+ raise PulseError(
1027
+ "Either the pulse width or the risefall_sigma_ratio parameter can be specified"
1028
+ " but not both."
1029
+ )
1030
+ if width is None and risefall_sigma_ratio is not None:
1031
+ width = duration - 2.0 * risefall_sigma_ratio * sigma
1032
+
1033
+ parameters = {"sigma": sigma, "width": width, "beta": beta}
1034
+
1035
+ # Prepare symbolic expressions
1036
+ _t, _duration, _amp, _sigma, _beta, _width, _angle = sym.symbols(
1037
+ "t, duration, amp, sigma, beta, width, angle"
1038
+ )
1039
+ _center = _duration / 2
1040
+
1041
+ _sq_t0 = _center - _width / 2
1042
+ _sq_t1 = _center + _width / 2
1043
+
1044
+ _gaussian_ledge = _lifted_gaussian(_t, _sq_t0, -1, _sigma)
1045
+ _gaussian_redge = _lifted_gaussian(_t, _sq_t1, _duration + 1, _sigma)
1046
+ _deriv_ledge = -(_t - _sq_t0) / (_sigma**2) * _gaussian_ledge
1047
+ _deriv_redge = -(_t - _sq_t1) / (_sigma**2) * _gaussian_redge
1048
+
1049
+ envelope_expr = (
1050
+ _amp
1051
+ * sym.exp(sym.I * _angle)
1052
+ * sym.Piecewise(
1053
+ (_gaussian_ledge + sym.I * _beta * _deriv_ledge, _t <= _sq_t0),
1054
+ (_gaussian_redge + sym.I * _beta * _deriv_redge, _t >= _sq_t1),
1055
+ (1, True),
1056
+ )
1057
+ )
1058
+ consts_expr = sym.And(_sigma > 0, _width >= 0, _duration >= _width)
1059
+ valid_amp_conditions_expr = sym.And(sym.Abs(_amp) <= 1.0, sym.Abs(_beta) < _sigma)
1060
+
1061
+ return ScalableSymbolicPulse(
1062
+ pulse_type="GaussianSquareDrag",
1063
+ duration=duration,
1064
+ amp=amp,
1065
+ angle=angle,
1066
+ parameters=parameters,
1067
+ name=name,
1068
+ limit_amplitude=limit_amplitude,
1069
+ envelope=envelope_expr,
1070
+ constraints=consts_expr,
1071
+ valid_amp_conditions=valid_amp_conditions_expr,
1072
+ )
1073
+
1074
+
1075
+ @deprecate_pulse_func
1076
+ def gaussian_square_echo(
1077
+ duration: int | ParameterValueType,
1078
+ amp: float | ParameterExpression,
1079
+ sigma: float | ParameterExpression,
1080
+ width: float | ParameterExpression | None = None,
1081
+ angle: float | ParameterExpression | None = 0.0,
1082
+ active_amp: float | ParameterExpression | None = 0.0,
1083
+ active_angle: float | ParameterExpression | None = 0.0,
1084
+ risefall_sigma_ratio: float | ParameterExpression | None = None,
1085
+ name: str | None = None,
1086
+ limit_amplitude: bool | None = None,
1087
+ ) -> SymbolicPulse:
1088
+ """An echoed Gaussian square pulse with an active tone overlaid on it.
1089
+
1090
+ The Gaussian Square Echo pulse is composed of three pulses. First, a Gaussian Square pulse
1091
+ :math:`f_{echo}(x)` with amplitude ``amp`` and phase ``angle`` playing for half duration,
1092
+ followed by a second Gaussian Square pulse :math:`-f_{echo}(x)` with opposite amplitude
1093
+ and same phase playing for the rest of the duration. Third a Gaussian Square pulse
1094
+ :math:`f_{active}(x)` with amplitude ``active_amp`` and phase ``active_angle``
1095
+ playing for the entire duration. The Gaussian Square Echo pulse :math:`g_e()`
1096
+ can be written as:
1097
+
1098
+ .. math::
1099
+
1100
+ \\begin{aligned}
1101
+ g_e(x) &= \\begin{cases}\
1102
+ f_{\\text{active}} + f_{\\text{echo}}(x)\
1103
+ & x < \\frac{\\text{duration}}{2}\\\\
1104
+ f_{\\text{active}} - f_{\\text{echo}}(x)\
1105
+ & \\frac{\\text{duration}}{2} < x\
1106
+ \\end{cases}\\\\
1107
+ \\end{aligned}
1108
+
1109
+ One case where this pulse can be used is when implementing a direct CNOT gate with
1110
+ a cross-resonance superconducting qubit architecture. When applying this pulse to
1111
+ the target qubit, the active portion can be used to cancel IX terms from the
1112
+ cross-resonance drive while the echo portion can reduce the impact of a static ZZ coupling.
1113
+
1114
+ Exactly one of the ``risefall_sigma_ratio`` and ``width`` parameters has to be specified.
1115
+
1116
+ If ``risefall_sigma_ratio`` is not ``None`` and ``width`` is ``None``:
1117
+
1118
+ .. math::
1119
+
1120
+ \\begin{aligned}
1121
+ \\text{risefall} &= \\text{risefall\\_sigma\\_ratio} \\times \\text{sigma}\\\\
1122
+ \\text{width} &= \\text{duration} - 2 \\times \\text{risefall}
1123
+ \\end{aligned}
1124
+
1125
+ If ``width`` is not None and ``risefall_sigma_ratio`` is None:
1126
+
1127
+ .. math:: \\text{risefall} = \\frac{\\text{duration} - \\text{width}}{2}
1128
+
1129
+ References:
1130
+ 1. |citation1|_
1131
+
1132
+ .. _citation1: https://iopscience.iop.org/article/10.1088/2058-9565/abe519
1133
+
1134
+ .. |citation1| replace:: *Jurcevic, P., Javadi-Abhari, A., Bishop, L. S.,
1135
+ Lauer, I., Bogorin, D. F., Brink, M., Capelluto, L., G{\"u}nl{\"u}k, O.,
1136
+ Itoko, T., Kanazawa, N. & others
1137
+ Demonstration of quantum volume 64 on a superconducting quantum
1138
+ computing system. (Section V)*
1139
+ Args:
1140
+ duration: Pulse length in terms of the sampling period `dt`.
1141
+ amp: The amplitude of the rise and fall and of the echoed pulse.
1142
+ sigma: A measure of how wide or narrow the risefall is; see the class
1143
+ docstring for more details.
1144
+ width: The duration of the embedded square pulse.
1145
+ angle: The angle in radians of the complex phase factor uniformly
1146
+ scaling the echoed pulse. Default value 0.
1147
+ active_amp: The amplitude of the active pulse.
1148
+ active_angle: The angle in radian of the complex phase factor uniformly
1149
+ scaling the active pulse. Default value 0.
1150
+ risefall_sigma_ratio: The ratio of each risefall duration to sigma.
1151
+ name: Display name for this pulse envelope.
1152
+ limit_amplitude: If ``True``, then limit the amplitude of the
1153
+ waveform to 1. The default is ``True`` and the amplitude is constrained to 1.
1154
+
1155
+ Returns:
1156
+ ScalableSymbolicPulse instance.
1157
+ Raises:
1158
+ PulseError: When width and risefall_sigma_ratio are both empty or both non-empty.
1159
+ """
1160
+ # Convert risefall_sigma_ratio into width which is defined in OpenPulse spec
1161
+ if width is None and risefall_sigma_ratio is None:
1162
+ raise PulseError(
1163
+ "Either the pulse width or the risefall_sigma_ratio parameter must be specified."
1164
+ )
1165
+ if width is not None and risefall_sigma_ratio is not None:
1166
+ raise PulseError(
1167
+ "Either the pulse width or the risefall_sigma_ratio parameter can be specified"
1168
+ " but not both."
1169
+ )
1170
+
1171
+ if width is None and risefall_sigma_ratio is not None:
1172
+ width = duration - 2.0 * risefall_sigma_ratio * sigma
1173
+
1174
+ parameters = {
1175
+ "amp": amp,
1176
+ "angle": angle,
1177
+ "sigma": sigma,
1178
+ "width": width,
1179
+ "active_amp": active_amp,
1180
+ "active_angle": active_angle,
1181
+ }
1182
+
1183
+ # Prepare symbolic expressions
1184
+ (
1185
+ _t,
1186
+ _duration,
1187
+ _amp,
1188
+ _sigma,
1189
+ _active_amp,
1190
+ _width,
1191
+ _angle,
1192
+ _active_angle,
1193
+ ) = sym.symbols("t, duration, amp, sigma, active_amp, width, angle, active_angle")
1194
+
1195
+ # gaussian square echo for rotary tone
1196
+ _center = _duration / 4
1197
+
1198
+ _width_echo = (_duration - 2 * (_duration - _width)) / 2
1199
+
1200
+ _sq_t0 = _center - _width_echo / 2
1201
+ _sq_t1 = _center + _width_echo / 2
1202
+
1203
+ _gaussian_ledge = _lifted_gaussian(_t, _sq_t0, -1, _sigma)
1204
+ _gaussian_redge = _lifted_gaussian(_t, _sq_t1, _duration / 2 + 1, _sigma)
1205
+
1206
+ envelope_expr_p = (
1207
+ _amp
1208
+ * sym.exp(sym.I * _angle)
1209
+ * sym.Piecewise(
1210
+ (_gaussian_ledge, _t <= _sq_t0),
1211
+ (_gaussian_redge, _t >= _sq_t1),
1212
+ (1, True),
1213
+ )
1214
+ )
1215
+
1216
+ _center_echo = _duration / 2 + _duration / 4
1217
+
1218
+ _sq_t0_echo = _center_echo - _width_echo / 2
1219
+ _sq_t1_echo = _center_echo + _width_echo / 2
1220
+
1221
+ _gaussian_ledge_echo = _lifted_gaussian(_t, _sq_t0_echo, _duration / 2 - 1, _sigma)
1222
+ _gaussian_redge_echo = _lifted_gaussian(_t, _sq_t1_echo, _duration + 1, _sigma)
1223
+
1224
+ envelope_expr_echo = (
1225
+ -1
1226
+ * _amp
1227
+ * sym.exp(sym.I * _angle)
1228
+ * sym.Piecewise(
1229
+ (_gaussian_ledge_echo, _t <= _sq_t0_echo),
1230
+ (_gaussian_redge_echo, _t >= _sq_t1_echo),
1231
+ (1, True),
1232
+ )
1233
+ )
1234
+
1235
+ envelope_expr = sym.Piecewise(
1236
+ (envelope_expr_p, _t <= _duration / 2), (envelope_expr_echo, _t >= _duration / 2), (0, True)
1237
+ )
1238
+
1239
+ # gaussian square for active cancellation tone
1240
+ _center_active = _duration / 2
1241
+
1242
+ _sq_t0_active = _center_active - _width / 2
1243
+ _sq_t1_active = _center_active + _width / 2
1244
+
1245
+ _gaussian_ledge_active = _lifted_gaussian(_t, _sq_t0_active, -1, _sigma)
1246
+ _gaussian_redge_active = _lifted_gaussian(_t, _sq_t1_active, _duration + 1, _sigma)
1247
+
1248
+ envelope_expr_active = (
1249
+ _active_amp
1250
+ * sym.exp(sym.I * _active_angle)
1251
+ * sym.Piecewise(
1252
+ (_gaussian_ledge_active, _t <= _sq_t0_active),
1253
+ (_gaussian_redge_active, _t >= _sq_t1_active),
1254
+ (1, True),
1255
+ )
1256
+ )
1257
+
1258
+ envelop_expr_total = envelope_expr + envelope_expr_active
1259
+
1260
+ consts_expr = sym.And(
1261
+ _sigma > 0, _width >= 0, _duration >= _width, _duration / 2 >= _width_echo
1262
+ )
1263
+
1264
+ # Check validity of amplitudes
1265
+ valid_amp_conditions_expr = sym.And(sym.Abs(_amp) + sym.Abs(_active_amp) <= 1.0)
1266
+
1267
+ return SymbolicPulse(
1268
+ pulse_type="gaussian_square_echo",
1269
+ duration=duration,
1270
+ parameters=parameters,
1271
+ name=name,
1272
+ limit_amplitude=limit_amplitude,
1273
+ envelope=envelop_expr_total,
1274
+ constraints=consts_expr,
1275
+ valid_amp_conditions=valid_amp_conditions_expr,
1276
+ )
1277
+
1278
+
1279
+ @deprecate_pulse_func
1280
+ def GaussianDeriv(
1281
+ duration: int | ParameterValueType,
1282
+ amp: float | ParameterExpression,
1283
+ sigma: float | ParameterExpression,
1284
+ angle: float | ParameterExpression | None = 0.0,
1285
+ name: str | None = None,
1286
+ limit_amplitude: bool | None = None,
1287
+ ) -> ScalableSymbolicPulse:
1288
+ """An unnormalized Gaussian derivative pulse.
1289
+
1290
+ The Gaussian function is centered around the halfway point of the pulse,
1291
+ and the envelope of the pulse is given by:
1292
+
1293
+ .. math::
1294
+
1295
+ f(x) = -\\text{A}\\frac{x-\\mu}{\\text{sigma}^{2}}\\exp
1296
+ \\left[-\\left(\\frac{x-\\mu}{2\\text{sigma}}\\right)^{2}\\right] , 0 <= x < duration
1297
+
1298
+ where :math:`\\text{A} = \\text{amp} \\times\\exp\\left(i\\times\\text{angle}\\right)`,
1299
+ and :math:`\\mu=\\text{duration}/2`.
1300
+
1301
+ Args:
1302
+ duration: Pulse length in terms of the sampling period `dt`.
1303
+ amp: The magnitude of the amplitude of the pulse
1304
+ (the value of the corresponding Gaussian at the midpoint `duration`/2).
1305
+ sigma: A measure of how wide or narrow the corresponding Gaussian peak is in terms of `dt`;
1306
+ described mathematically in the class docstring.
1307
+ angle: The angle in radians of the complex phase factor uniformly
1308
+ scaling the pulse. Default value 0.
1309
+ name: Display name for this pulse envelope.
1310
+ limit_amplitude: If ``True``, then limit the amplitude of the
1311
+ waveform to 1. The default is ``True`` and the amplitude is constrained to 1.
1312
+
1313
+ Returns:
1314
+ ScalableSymbolicPulse instance.
1315
+ """
1316
+ parameters = {"sigma": sigma}
1317
+
1318
+ # Prepare symbolic expressions
1319
+ _t, _duration, _amp, _angle, _sigma = sym.symbols("t, duration, amp, angle, sigma")
1320
+ envelope_expr = (
1321
+ -_amp
1322
+ * sym.exp(sym.I * _angle)
1323
+ * ((_t - (_duration / 2)) / _sigma**2)
1324
+ * sym.exp(-(1 / 2) * ((_t - (_duration / 2)) / _sigma) ** 2)
1325
+ )
1326
+ consts_expr = _sigma > 0
1327
+ valid_amp_conditions_expr = sym.Abs(_amp / _sigma) <= sym.exp(1 / 2)
1328
+
1329
+ return ScalableSymbolicPulse(
1330
+ pulse_type="GaussianDeriv",
1331
+ duration=duration,
1332
+ amp=amp,
1333
+ angle=angle,
1334
+ parameters=parameters,
1335
+ name=name,
1336
+ limit_amplitude=limit_amplitude,
1337
+ envelope=envelope_expr,
1338
+ constraints=consts_expr,
1339
+ valid_amp_conditions=valid_amp_conditions_expr,
1340
+ )
1341
+
1342
+
1343
+ class Drag(metaclass=_PulseType):
1344
+ """The Derivative Removal by Adiabatic Gate (DRAG) pulse is a standard Gaussian pulse
1345
+ with an additional Gaussian derivative component and lifting applied.
1346
+
1347
+ It can be calibrated either to reduce the phase error due to virtual population of the
1348
+ :math:`|2\\rangle` state during the pulse or to reduce the frequency spectrum of a
1349
+ standard Gaussian pulse near the :math:`|1\\rangle\\leftrightarrow|2\\rangle` transition,
1350
+ reducing the chance of leakage to the :math:`|2\\rangle` state.
1351
+
1352
+ .. math::
1353
+
1354
+ \\begin{aligned}
1355
+ g(x) &= \\exp\\Bigl(-\\frac12 \\frac{(x - \\text{duration}/2)^2}{\\text{sigma}^2}\\Bigr)\\\\
1356
+ g'(x) &= \\text{A}\\times\\frac{g(x)-g(-1)}{1-g(-1)}\\\\
1357
+ f(x) &= g'(x) \\times \\Bigl(1 + 1j \\times \\text{beta} \\times\
1358
+ \\Bigl(-\\frac{x - \\text{duration}/2}{\\text{sigma}^2}\\Bigr) \\Bigr),
1359
+ \\quad 0 \\le x < \\text{duration}
1360
+ \\end{aligned}
1361
+
1362
+ where :math:`g(x)` is a standard unlifted Gaussian waveform, :math:`g'(x)` is the lifted
1363
+ :class:`~qiskit.pulse.library.Gaussian` waveform, and
1364
+ :math:`\\text{A} = \\text{amp} \\times \\exp\\left(i\\times\\text{angle}\\right)`.
1365
+
1366
+ References:
1367
+ 1. |citation1|_
1368
+
1369
+ .. _citation1: https://link.aps.org/doi/10.1103/PhysRevA.83.012308
1370
+
1371
+ .. |citation1| replace:: *Gambetta, J. M., Motzoi, F., Merkel, S. T. & Wilhelm, F. K.
1372
+ Analytic control methods for high-fidelity unitary operations
1373
+ in a weakly nonlinear oscillator. Phys. Rev. A 83, 012308 (2011).*
1374
+
1375
+ 2. |citation2|_
1376
+
1377
+ .. _citation2: https://link.aps.org/doi/10.1103/PhysRevLett.103.110501
1378
+
1379
+ .. |citation2| replace:: *F. Motzoi, J. M. Gambetta, P. Rebentrost, and F. K. Wilhelm
1380
+ Phys. Rev. Lett. 103, 110501 – Published 8 September 2009.*
1381
+ """
1382
+
1383
+ alias = "Drag"
1384
+
1385
+ def __new__(
1386
+ cls,
1387
+ duration: int | ParameterValueType,
1388
+ amp: ParameterValueType,
1389
+ sigma: ParameterValueType,
1390
+ beta: ParameterValueType,
1391
+ angle: ParameterValueType = 0.0,
1392
+ name: str | None = None,
1393
+ limit_amplitude: bool | None = None,
1394
+ ) -> ScalableSymbolicPulse:
1395
+ """Create new pulse instance.
1396
+
1397
+ Args:
1398
+ duration: Pulse length in terms of the sampling period `dt`.
1399
+ amp: The magnitude of the amplitude of the DRAG envelope.
1400
+ sigma: A measure of how wide or narrow the Gaussian peak is; described mathematically
1401
+ in the class docstring.
1402
+ beta: The correction amplitude.
1403
+ angle: The angle of the complex amplitude of the DRAG envelope. Default value 0.
1404
+ name: Display name for this pulse envelope.
1405
+ limit_amplitude: If ``True``, then limit the amplitude of the
1406
+ waveform to 1. The default is ``True`` and the amplitude is constrained to 1.
1407
+
1408
+ Returns:
1409
+ ScalableSymbolicPulse instance.
1410
+ """
1411
+ parameters = {"sigma": sigma, "beta": beta}
1412
+
1413
+ # Prepare symbolic expressions
1414
+ _t, _duration, _amp, _sigma, _beta, _angle = sym.symbols(
1415
+ "t, duration, amp, sigma, beta, angle"
1416
+ )
1417
+ _center = _duration / 2
1418
+
1419
+ _gauss = _lifted_gaussian(_t, _center, _duration + 1, _sigma)
1420
+ _deriv = -(_t - _center) / (_sigma**2) * _gauss
1421
+
1422
+ envelope_expr = _amp * sym.exp(sym.I * _angle) * (_gauss + sym.I * _beta * _deriv)
1423
+
1424
+ consts_expr = _sigma > 0
1425
+ valid_amp_conditions_expr = sym.And(sym.Abs(_amp) <= 1.0, sym.Abs(_beta) < _sigma)
1426
+
1427
+ return ScalableSymbolicPulse(
1428
+ pulse_type="Drag",
1429
+ duration=duration,
1430
+ amp=amp,
1431
+ angle=angle,
1432
+ parameters=parameters,
1433
+ name=name,
1434
+ limit_amplitude=limit_amplitude,
1435
+ envelope=envelope_expr,
1436
+ constraints=consts_expr,
1437
+ valid_amp_conditions=valid_amp_conditions_expr,
1438
+ )
1439
+
1440
+ @deprecate_pulse_func
1441
+ def __init__(self):
1442
+ pass
1443
+
1444
+
1445
+ class Constant(metaclass=_PulseType):
1446
+ """A simple constant pulse, with an amplitude value and a duration:
1447
+
1448
+ .. math::
1449
+
1450
+ f(x) = \\text{amp}\\times\\exp\\left(i\\text{angle}\\right) , 0 <= x < duration
1451
+ f(x) = 0 , elsewhere
1452
+ """
1453
+
1454
+ alias = "Constant"
1455
+
1456
+ def __new__(
1457
+ cls,
1458
+ duration: int | ParameterValueType,
1459
+ amp: ParameterValueType,
1460
+ angle: ParameterValueType = 0.0,
1461
+ name: str | None = None,
1462
+ limit_amplitude: bool | None = None,
1463
+ ) -> ScalableSymbolicPulse:
1464
+ """Create new pulse instance.
1465
+
1466
+ Args:
1467
+ duration: Pulse length in terms of the sampling period `dt`.
1468
+ amp: The magnitude of the amplitude of the square envelope.
1469
+ angle: The angle of the complex amplitude of the square envelope. Default value 0.
1470
+ name: Display name for this pulse envelope.
1471
+ limit_amplitude: If ``True``, then limit the amplitude of the
1472
+ waveform to 1. The default is ``True`` and the amplitude is constrained to 1.
1473
+
1474
+ Returns:
1475
+ ScalableSymbolicPulse instance.
1476
+ """
1477
+ # Prepare symbolic expressions
1478
+ _t, _amp, _duration, _angle = sym.symbols("t, amp, duration, angle")
1479
+
1480
+ # Note this is implemented using Piecewise instead of just returning amp
1481
+ # directly because otherwise the expression has no t dependence and sympy's
1482
+ # lambdify will produce a function f that for an array t returns amp
1483
+ # instead of amp * np.ones(t.shape).
1484
+ #
1485
+ # See: https://github.com/sympy/sympy/issues/5642
1486
+ envelope_expr = (
1487
+ _amp
1488
+ * sym.exp(sym.I * _angle)
1489
+ * sym.Piecewise((1, sym.And(_t >= 0, _t <= _duration)), (0, True))
1490
+ )
1491
+
1492
+ valid_amp_conditions_expr = sym.Abs(_amp) <= 1.0
1493
+
1494
+ return ScalableSymbolicPulse(
1495
+ pulse_type="Constant",
1496
+ duration=duration,
1497
+ amp=amp,
1498
+ angle=angle,
1499
+ name=name,
1500
+ limit_amplitude=limit_amplitude,
1501
+ envelope=envelope_expr,
1502
+ valid_amp_conditions=valid_amp_conditions_expr,
1503
+ )
1504
+
1505
+ @deprecate_pulse_func
1506
+ def __init__(self):
1507
+ pass
1508
+
1509
+
1510
+ @deprecate_pulse_func
1511
+ def Sin(
1512
+ duration: int | ParameterExpression,
1513
+ amp: float | ParameterExpression,
1514
+ phase: float | ParameterExpression,
1515
+ freq: float | ParameterExpression | None = None,
1516
+ angle: float | ParameterExpression | None = 0.0,
1517
+ name: str | None = None,
1518
+ limit_amplitude: bool | None = None,
1519
+ ) -> ScalableSymbolicPulse:
1520
+ """A sinusoidal pulse.
1521
+
1522
+ The envelope of the pulse is given by:
1523
+
1524
+ .. math::
1525
+
1526
+ f(x) = \\text{A}\\sin\\left(2\\pi\\text{freq}x+\\text{phase}\\right) , 0 <= x < duration
1527
+
1528
+ where :math:`\\text{A} = \\text{amp} \\times\\exp\\left(i\\times\\text{angle}\\right)`.
1529
+
1530
+ Args:
1531
+ duration: Pulse length in terms of the sampling period `dt`.
1532
+ amp: The magnitude of the amplitude of the sinusoidal wave. Wave range is [-`amp`,`amp`].
1533
+ phase: The phase of the sinusoidal wave (note that this is not equivalent to the angle of
1534
+ the complex amplitude)
1535
+ freq: The frequency of the sinusoidal wave, in terms of 1 over sampling period.
1536
+ If not provided defaults to a single cycle (i.e :math:'\\frac{1}{\\text{duration}}').
1537
+ The frequency is limited to the range :math:`\\left(0,0.5\\right]` (the Nyquist frequency).
1538
+ angle: The angle in radians of the complex phase factor uniformly
1539
+ scaling the pulse. Default value 0.
1540
+ name: Display name for this pulse envelope.
1541
+ limit_amplitude: If ``True``, then limit the amplitude of the
1542
+ waveform to 1. The default is ``True`` and the amplitude is constrained to 1.
1543
+
1544
+ Returns:
1545
+ ScalableSymbolicPulse instance.
1546
+ """
1547
+ if freq is None:
1548
+ freq = 1 / duration
1549
+ parameters = {"freq": freq, "phase": phase}
1550
+
1551
+ # Prepare symbolic expressions
1552
+ _t, _duration, _amp, _angle, _freq, _phase = sym.symbols("t, duration, amp, angle, freq, phase")
1553
+
1554
+ envelope_expr = _amp * sym.exp(sym.I * _angle) * sym.sin(2 * sym.pi * _freq * _t + _phase)
1555
+
1556
+ consts_expr = sym.And(_freq > 0, _freq < 0.5)
1557
+
1558
+ # This might fail for waves shorter than a single cycle
1559
+ valid_amp_conditions_expr = sym.Abs(_amp) <= 1.0
1560
+
1561
+ return ScalableSymbolicPulse(
1562
+ pulse_type="Sin",
1563
+ duration=duration,
1564
+ amp=amp,
1565
+ angle=angle,
1566
+ parameters=parameters,
1567
+ name=name,
1568
+ limit_amplitude=limit_amplitude,
1569
+ envelope=envelope_expr,
1570
+ constraints=consts_expr,
1571
+ valid_amp_conditions=valid_amp_conditions_expr,
1572
+ )
1573
+
1574
+
1575
+ @deprecate_pulse_func
1576
+ def Cos(
1577
+ duration: int | ParameterExpression,
1578
+ amp: float | ParameterExpression,
1579
+ phase: float | ParameterExpression,
1580
+ freq: float | ParameterExpression | None = None,
1581
+ angle: float | ParameterExpression | None = 0.0,
1582
+ name: str | None = None,
1583
+ limit_amplitude: bool | None = None,
1584
+ ) -> ScalableSymbolicPulse:
1585
+ """A cosine pulse.
1586
+
1587
+ The envelope of the pulse is given by:
1588
+
1589
+ .. math::
1590
+
1591
+ f(x) = \\text{A}\\cos\\left(2\\pi\\text{freq}x+\\text{phase}\\right) , 0 <= x < duration
1592
+
1593
+ where :math:`\\text{A} = \\text{amp} \\times\\exp\\left(i\\times\\text{angle}\\right)`.
1594
+
1595
+ Args:
1596
+ duration: Pulse length in terms of the sampling period `dt`.
1597
+ amp: The magnitude of the amplitude of the cosine wave. Wave range is [-`amp`,`amp`].
1598
+ phase: The phase of the cosine wave (note that this is not equivalent to the angle
1599
+ of the complex amplitude).
1600
+ freq: The frequency of the cosine wave, in terms of 1 over sampling period.
1601
+ If not provided defaults to a single cycle (i.e :math:'\\frac{1}{\\text{duration}}').
1602
+ The frequency is limited to the range :math:`\\left(0,0.5\\right]` (the Nyquist frequency).
1603
+ angle: The angle in radians of the complex phase factor uniformly
1604
+ scaling the pulse. Default value 0.
1605
+ name: Display name for this pulse envelope.
1606
+ limit_amplitude: If ``True``, then limit the amplitude of the
1607
+ waveform to 1. The default is ``True`` and the amplitude is constrained to 1.
1608
+
1609
+ Returns:
1610
+ ScalableSymbolicPulse instance.
1611
+ """
1612
+ if freq is None:
1613
+ freq = 1 / duration
1614
+ parameters = {"freq": freq, "phase": phase}
1615
+
1616
+ # Prepare symbolic expressions
1617
+ _t, _duration, _amp, _angle, _freq, _phase = sym.symbols("t, duration, amp, angle, freq, phase")
1618
+
1619
+ envelope_expr = _amp * sym.exp(sym.I * _angle) * sym.cos(2 * sym.pi * _freq * _t + _phase)
1620
+
1621
+ consts_expr = sym.And(_freq > 0, _freq < 0.5)
1622
+
1623
+ # This might fail for waves shorter than a single cycle
1624
+ valid_amp_conditions_expr = sym.Abs(_amp) <= 1.0
1625
+
1626
+ return ScalableSymbolicPulse(
1627
+ pulse_type="Cos",
1628
+ duration=duration,
1629
+ amp=amp,
1630
+ angle=angle,
1631
+ parameters=parameters,
1632
+ name=name,
1633
+ limit_amplitude=limit_amplitude,
1634
+ envelope=envelope_expr,
1635
+ constraints=consts_expr,
1636
+ valid_amp_conditions=valid_amp_conditions_expr,
1637
+ )
1638
+
1639
+
1640
+ @deprecate_pulse_func
1641
+ def Sawtooth(
1642
+ duration: int | ParameterExpression,
1643
+ amp: float | ParameterExpression,
1644
+ phase: float | ParameterExpression,
1645
+ freq: float | ParameterExpression | None = None,
1646
+ angle: float | ParameterExpression | None = 0.0,
1647
+ name: str | None = None,
1648
+ limit_amplitude: bool | None = None,
1649
+ ) -> ScalableSymbolicPulse:
1650
+ """A sawtooth pulse.
1651
+
1652
+ The envelope of the pulse is given by:
1653
+
1654
+ .. math::
1655
+
1656
+ f(x) = 2\\text{A}\\left[g\\left(x\\right)-
1657
+ \\lfloor g\\left(x\\right)+\\frac{1}{2}\\rfloor\\right]
1658
+
1659
+ where :math:`\\text{A} = \\text{amp} \\times\\exp\\left(i\\times\\text{angle}\\right)`,
1660
+ :math:`g\\left(x\\right)=x\\times\\text{freq}+\\frac{\\text{phase}}{2\\pi}`,
1661
+ and :math:`\\lfloor ...\\rfloor` is the floor operation.
1662
+
1663
+ Args:
1664
+ duration: Pulse length in terms of the sampling period `dt`.
1665
+ amp: The magnitude of the amplitude of the sawtooth wave. Wave range is [-`amp`,`amp`].
1666
+ phase: The phase of the sawtooth wave (note that this is not equivalent to the angle
1667
+ of the complex amplitude)
1668
+ freq: The frequency of the sawtooth wave, in terms of 1 over sampling period.
1669
+ If not provided defaults to a single cycle (i.e :math:'\\frac{1}{\\text{duration}}').
1670
+ The frequency is limited to the range :math:`\\left(0,0.5\\right]` (the Nyquist frequency).
1671
+ angle: The angle in radians of the complex phase factor uniformly
1672
+ scaling the pulse. Default value 0.
1673
+ name: Display name for this pulse envelope.
1674
+ limit_amplitude: If ``True``, then limit the amplitude of the
1675
+ waveform to 1. The default is ``True`` and the amplitude is constrained to 1.
1676
+
1677
+ Returns:
1678
+ ScalableSymbolicPulse instance.
1679
+ """
1680
+ if freq is None:
1681
+ freq = 1 / duration
1682
+ parameters = {"freq": freq, "phase": phase}
1683
+
1684
+ # Prepare symbolic expressions
1685
+ _t, _duration, _amp, _angle, _freq, _phase = sym.symbols("t, duration, amp, angle, freq, phase")
1686
+ lin_expr = _t * _freq + _phase / (2 * sym.pi)
1687
+
1688
+ envelope_expr = 2 * _amp * sym.exp(sym.I * _angle) * (lin_expr - sym.floor(lin_expr + 1 / 2))
1689
+
1690
+ consts_expr = sym.And(_freq > 0, _freq < 0.5)
1691
+
1692
+ # This might fail for waves shorter than a single cycle
1693
+ valid_amp_conditions_expr = sym.Abs(_amp) <= 1.0
1694
+
1695
+ return ScalableSymbolicPulse(
1696
+ pulse_type="Sawtooth",
1697
+ duration=duration,
1698
+ amp=amp,
1699
+ angle=angle,
1700
+ parameters=parameters,
1701
+ name=name,
1702
+ limit_amplitude=limit_amplitude,
1703
+ envelope=envelope_expr,
1704
+ constraints=consts_expr,
1705
+ valid_amp_conditions=valid_amp_conditions_expr,
1706
+ )
1707
+
1708
+
1709
+ @deprecate_pulse_func
1710
+ def Triangle(
1711
+ duration: int | ParameterExpression,
1712
+ amp: float | ParameterExpression,
1713
+ phase: float | ParameterExpression,
1714
+ freq: float | ParameterExpression | None = None,
1715
+ angle: float | ParameterExpression | None = 0.0,
1716
+ name: str | None = None,
1717
+ limit_amplitude: bool | None = None,
1718
+ ) -> ScalableSymbolicPulse:
1719
+ """A triangle wave pulse.
1720
+
1721
+ The envelope of the pulse is given by:
1722
+
1723
+ .. math::
1724
+
1725
+ f(x) = \\text{A}\\left[\\text{sawtooth}\\left(x\\right)\\right] , 0 <= x < duration
1726
+
1727
+ where :math:`\\text{A} = \\text{amp} \\times\\exp\\left(i\\times\\text{angle}\\right)`,
1728
+ and :math:`\\text{sawtooth}\\left(x\\right)` is a sawtooth wave with the same frequency
1729
+ as the triangle wave, but a phase shifted by :math:`\\frac{\\pi}{2}`.
1730
+
1731
+ Args:
1732
+ duration: Pulse length in terms of the sampling period `dt`.
1733
+ amp: The magnitude of the amplitude of the triangle wave. Wave range is [-`amp`,`amp`].
1734
+ phase: The phase of the triangle wave (note that this is not equivalent to the angle
1735
+ of the complex amplitude)
1736
+ freq: The frequency of the triangle wave, in terms of 1 over sampling period.
1737
+ If not provided defaults to a single cycle (i.e :math:'\\frac{1}{\\text{duration}}').
1738
+ The frequency is limited to the range :math:`\\left(0,0.5\\right]` (the Nyquist frequency).
1739
+ angle: The angle in radians of the complex phase factor uniformly
1740
+ scaling the pulse. Default value 0.
1741
+ name: Display name for this pulse envelope.
1742
+ limit_amplitude: If ``True``, then limit the amplitude of the
1743
+ waveform to 1. The default is ``True`` and the amplitude is constrained to 1.
1744
+
1745
+ Returns:
1746
+ ScalableSymbolicPulse instance.
1747
+ """
1748
+ if freq is None:
1749
+ freq = 1 / duration
1750
+ parameters = {"freq": freq, "phase": phase}
1751
+
1752
+ # Prepare symbolic expressions
1753
+ _t, _duration, _amp, _angle, _freq, _phase = sym.symbols("t, duration, amp, angle, freq, phase")
1754
+ lin_expr = _t * _freq + _phase / (2 * sym.pi) - 0.25
1755
+ sawtooth_expr = 2 * (lin_expr - sym.floor(lin_expr + 1 / 2))
1756
+
1757
+ envelope_expr = _amp * sym.exp(sym.I * _angle) * (-2 * sym.Abs(sawtooth_expr) + 1)
1758
+
1759
+ consts_expr = sym.And(_freq > 0, _freq < 0.5)
1760
+
1761
+ # This might fail for waves shorter than a single cycle
1762
+ valid_amp_conditions_expr = sym.Abs(_amp) <= 1.0
1763
+
1764
+ return ScalableSymbolicPulse(
1765
+ pulse_type="Triangle",
1766
+ duration=duration,
1767
+ amp=amp,
1768
+ angle=angle,
1769
+ parameters=parameters,
1770
+ name=name,
1771
+ limit_amplitude=limit_amplitude,
1772
+ envelope=envelope_expr,
1773
+ constraints=consts_expr,
1774
+ valid_amp_conditions=valid_amp_conditions_expr,
1775
+ )
1776
+
1777
+
1778
+ @deprecate_pulse_func
1779
+ def Square(
1780
+ duration: int | ParameterValueType,
1781
+ amp: float | ParameterExpression,
1782
+ phase: float | ParameterExpression,
1783
+ freq: float | ParameterExpression | None = None,
1784
+ angle: float | ParameterExpression | None = 0.0,
1785
+ name: str | None = None,
1786
+ limit_amplitude: bool | None = None,
1787
+ ) -> ScalableSymbolicPulse:
1788
+ """A square wave pulse.
1789
+
1790
+ The envelope of the pulse is given by:
1791
+
1792
+ .. math::
1793
+
1794
+ f(x) = \\text{A}\\text{sign}\\left[\\sin
1795
+ \\left(2\\pi x\\times\\text{freq}+\\text{phase}\\right)\\right] , 0 <= x < duration
1796
+
1797
+ where :math:`\\text{A} = \\text{amp} \\times\\exp\\left(i\\times\\text{angle}\\right)`,
1798
+ and :math:`\\text{sign}`
1799
+ is the sign function with the convention :math:`\\text{sign}\\left(0\\right)=1`.
1800
+
1801
+ Args:
1802
+ duration: Pulse length in terms of the sampling period ``dt``.
1803
+ amp: The magnitude of the amplitude of the square wave. Wave range is
1804
+ :math:`\\left[-\\texttt{amp},\\texttt{amp}\\right]`.
1805
+ phase: The phase of the square wave (note that this is not equivalent to the angle of
1806
+ the complex amplitude).
1807
+ freq: The frequency of the square wave, in terms of 1 over sampling period.
1808
+ If not provided defaults to a single cycle (i.e :math:`\\frac{1}{\\text{duration}}`).
1809
+ The frequency is limited to the range :math:`\\left(0,0.5\\right]` (the Nyquist frequency).
1810
+ angle: The angle in radians of the complex phase factor uniformly
1811
+ scaling the pulse. Default value 0.
1812
+ name: Display name for this pulse envelope.
1813
+ limit_amplitude: If ``True``, then limit the amplitude of the
1814
+ waveform to 1. The default is ``True`` and the amplitude is constrained to 1.
1815
+
1816
+ Returns:
1817
+ ScalableSymbolicPulse instance.
1818
+ """
1819
+ if freq is None:
1820
+ freq = 1 / duration
1821
+ parameters = {"freq": freq, "phase": phase}
1822
+
1823
+ # Prepare symbolic expressions
1824
+ _t, _duration, _amp, _angle, _freq, _phase = sym.symbols("t, duration, amp, angle, freq, phase")
1825
+ _x = _freq * _t + _phase / (2 * sym.pi)
1826
+
1827
+ envelope_expr = (
1828
+ _amp * sym.exp(sym.I * _angle) * (2 * (2 * sym.floor(_x) - sym.floor(2 * _x)) + 1)
1829
+ )
1830
+
1831
+ consts_expr = sym.And(_freq > 0, _freq < 0.5)
1832
+
1833
+ # This might fail for waves shorter than a single cycle
1834
+ valid_amp_conditions_expr = sym.Abs(_amp) <= 1.0
1835
+
1836
+ return ScalableSymbolicPulse(
1837
+ pulse_type="Square",
1838
+ duration=duration,
1839
+ amp=amp,
1840
+ angle=angle,
1841
+ parameters=parameters,
1842
+ name=name,
1843
+ limit_amplitude=limit_amplitude,
1844
+ envelope=envelope_expr,
1845
+ constraints=consts_expr,
1846
+ valid_amp_conditions=valid_amp_conditions_expr,
1847
+ )
1848
+
1849
+
1850
+ @deprecate_pulse_func
1851
+ def Sech(
1852
+ duration: int | ParameterValueType,
1853
+ amp: float | ParameterExpression,
1854
+ sigma: float | ParameterExpression,
1855
+ angle: float | ParameterExpression | None = 0.0,
1856
+ name: str | None = None,
1857
+ zero_ends: bool | None = True,
1858
+ limit_amplitude: bool | None = None,
1859
+ ) -> ScalableSymbolicPulse:
1860
+ """An unnormalized sech pulse.
1861
+
1862
+ The sech function is centered around the halfway point of the pulse,
1863
+ and the envelope of the pulse is given by:
1864
+
1865
+ .. math::
1866
+
1867
+ f(x) = \\text{A}\\text{sech}\\left(
1868
+ \\frac{x-\\mu}{\\text{sigma}}\\right) , 0 <= x < duration
1869
+
1870
+ where :math:`\\text{A} = \\text{amp} \\times\\exp\\left(i\\times\\text{angle}\\right)`,
1871
+ and :math:`\\mu=\\text{duration}/2`.
1872
+
1873
+ If `zero_ends` is set to `True`, the output `y` is modified:
1874
+ .. math::
1875
+
1876
+ y\\left(x\\right) \\mapsto \\text{A}\\frac{y-y^{*}}{\\text{A}-y^{*}},
1877
+
1878
+ where :math:`y^{*}` is the value of :math:`y` at the endpoints (at :math:`x=-1
1879
+ and :math:`x=\\text{duration}+1`). This shifts the endpoints value to zero, while also
1880
+ rescaling to preserve the amplitude at `:math:`\\text{duration}/2``.
1881
+
1882
+ Args:
1883
+ duration: Pulse length in terms of the sampling period `dt`.
1884
+ amp: The magnitude of the amplitude of the pulse (the value at the midpoint `duration`/2).
1885
+ sigma: A measure of how wide or narrow the sech peak is in terms of `dt`;
1886
+ described mathematically in the class docstring.
1887
+ angle: The angle in radians of the complex phase factor uniformly
1888
+ scaling the pulse. Default value 0.
1889
+ name: Display name for this pulse envelope.
1890
+ zero_ends: If True, zeros the ends at x = -1, x = `duration` + 1,
1891
+ but rescales to preserve `amp`. Default value True.
1892
+ limit_amplitude: If ``True``, then limit the amplitude of the
1893
+ waveform to 1. The default is ``True`` and the amplitude is constrained to 1.
1894
+
1895
+ Returns:
1896
+ ScalableSymbolicPulse instance.
1897
+ """
1898
+ parameters = {"sigma": sigma}
1899
+
1900
+ # Prepare symbolic expressions
1901
+ _t, _duration, _amp, _angle, _sigma = sym.symbols("t, duration, amp, angle, sigma")
1902
+ complex_amp = _amp * sym.exp(sym.I * _angle)
1903
+ envelope_expr = complex_amp * sym.sech((_t - (_duration / 2)) / _sigma)
1904
+
1905
+ if zero_ends:
1906
+ shift_val = complex_amp * sym.sech((-1 - (_duration / 2)) / _sigma)
1907
+ envelope_expr = complex_amp * (envelope_expr - shift_val) / (complex_amp - shift_val)
1908
+
1909
+ consts_expr = _sigma > 0
1910
+
1911
+ valid_amp_conditions_expr = sym.Abs(_amp) <= 1.0
1912
+
1913
+ return ScalableSymbolicPulse(
1914
+ pulse_type="Sech",
1915
+ duration=duration,
1916
+ amp=amp,
1917
+ angle=angle,
1918
+ parameters=parameters,
1919
+ name=name,
1920
+ limit_amplitude=limit_amplitude,
1921
+ envelope=envelope_expr,
1922
+ constraints=consts_expr,
1923
+ valid_amp_conditions=valid_amp_conditions_expr,
1924
+ )
1925
+
1926
+
1927
+ @deprecate_pulse_func
1928
+ def SechDeriv(
1929
+ duration: int | ParameterValueType,
1930
+ amp: float | ParameterExpression,
1931
+ sigma: float | ParameterExpression,
1932
+ angle: float | ParameterExpression | None = 0.0,
1933
+ name: str | None = None,
1934
+ limit_amplitude: bool | None = None,
1935
+ ) -> ScalableSymbolicPulse:
1936
+ """An unnormalized sech derivative pulse.
1937
+
1938
+ The sech function is centered around the halfway point of the pulse, and the envelope of the
1939
+ pulse is given by:
1940
+
1941
+ .. math::
1942
+
1943
+ f(x) = \\text{A}\\frac{d}{dx}\\left[\\text{sech}
1944
+ \\left(\\frac{x-\\mu}{\\text{sigma}}\\right)\\right] , 0 <= x < duration
1945
+
1946
+ where :math:`\\text{A} = \\text{amp} \\times\\exp\\left(i\\times\\text{angle}\\right)`,
1947
+ :math:`\\mu=\\text{duration}/2`, and :math:`d/dx` is a derivative with respect to `x`.
1948
+
1949
+ Args:
1950
+ duration: Pulse length in terms of the sampling period `dt`.
1951
+ amp: The magnitude of the amplitude of the pulse (the value of the corresponding sech
1952
+ function at the midpoint `duration`/2).
1953
+ sigma: A measure of how wide or narrow the corresponding sech peak is, in terms of `dt`;
1954
+ described mathematically in the class docstring.
1955
+ angle: The angle in radians of the complex phase factor uniformly
1956
+ scaling the pulse. Default value 0.
1957
+ name: Display name for this pulse envelope.
1958
+ limit_amplitude: If ``True``, then limit the amplitude of the
1959
+ waveform to 1. The default is ``True`` and the amplitude is constrained to 1.
1960
+
1961
+ Returns:
1962
+ ScalableSymbolicPulse instance.
1963
+ """
1964
+ parameters = {"sigma": sigma}
1965
+
1966
+ # Prepare symbolic expressions
1967
+ _t, _duration, _amp, _angle, _sigma = sym.symbols("t, duration, amp, angle, sigma")
1968
+ time_argument = (_t - (_duration / 2)) / _sigma
1969
+ sech_deriv = -sym.tanh(time_argument) * sym.sech(time_argument) / _sigma
1970
+
1971
+ envelope_expr = _amp * sym.exp(sym.I * _angle) * sech_deriv
1972
+
1973
+ consts_expr = _sigma > 0
1974
+
1975
+ valid_amp_conditions_expr = sym.Abs(_amp) / _sigma <= 2.0
1976
+
1977
+ return ScalableSymbolicPulse(
1978
+ pulse_type="SechDeriv",
1979
+ duration=duration,
1980
+ amp=amp,
1981
+ angle=angle,
1982
+ parameters=parameters,
1983
+ name=name,
1984
+ limit_amplitude=limit_amplitude,
1985
+ envelope=envelope_expr,
1986
+ constraints=consts_expr,
1987
+ valid_amp_conditions=valid_amp_conditions_expr,
1988
+ )