qiskit 1.4.2__cp39-abi3-macosx_11_0_arm64.whl → 2.0.0__cp39-abi3-macosx_11_0_arm64.whl

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