qiskit 1.3.0b1__cp39-abi3-macosx_10_9_x86_64.whl

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