Skip to content

Commit

Permalink
Deprecate the discrete pulse library (#11110)
Browse files Browse the repository at this point in the history
* Promote to deprecation and correct tests

* remove `guassian` from tutorial

* Release notes

* change to 0.46.0

* Test fix

* Lynt

(cherry picked from commit 7c89b68)
  • Loading branch information
TsafrirA authored and mergify[bot] committed Nov 17, 2023
1 parent 33ed163 commit addb62e
Show file tree
Hide file tree
Showing 9 changed files with 202 additions and 158 deletions.
61 changes: 31 additions & 30 deletions docs/tutorials/circuits_advanced/06_building_pulse_schedules.ipynb

Large diffs are not rendered by default.

88 changes: 44 additions & 44 deletions qiskit/pulse/library/discrete.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@


@deprecate_func(
since="0.25.0",
additional_msg="The discrete pulses library, including constant() is pending deprecation."
since="0.46.0",
additional_msg="The discrete pulses library, including constant() is deprecated."
" Instead, use the SymbolicPulse library to create the waveform with"
" pulse.Constant(...).get_waveform(). "
" Note that complex value support for the `amp` parameter is pending deprecation"
" in the SymbolicPulse library. It is therefore recommended to use two float values"
" Note that complex value support for the `amp` parameter is deprecated"
" in the SymbolicPulse library. Use two float values"
" for (`amp`, `angle`) instead of complex `amp`",
pending=True,
pending=False,
)
def constant(duration: int, amp: complex, name: Optional[str] = None) -> Waveform:
r"""Generates constant-sampled :class:`~qiskit.pulse.library.Waveform`.
Expand All @@ -58,11 +58,11 @@ def constant(duration: int, amp: complex, name: Optional[str] = None) -> Wavefor


@deprecate_func(
since="0.25.0",
additional_msg="The discrete pulses library, including zero() is pending deprecation."
since="0.46.0",
additional_msg="The discrete pulses library, including zero() is deprecated."
" Instead, use the SymbolicPulse library to create the waveform with"
" pulse.Constant(amp=0,...).get_waveform().",
pending=True,
pending=False,
)
def zero(duration: int, name: Optional[str] = None) -> Waveform:
"""Generates zero-sampled :class:`~qiskit.pulse.library.Waveform`.
Expand All @@ -84,13 +84,13 @@ def zero(duration: int, name: Optional[str] = None) -> Waveform:


@deprecate_func(
since="0.25.0",
additional_msg="The discrete pulses library, including square() is pending deprecation."
since="0.46.0",
additional_msg="The discrete pulses library, including square() is deprecated."
" Instead, use the SymbolicPulse library to create the waveform with"
" pulse.Square(...).get_waveform()."
" Note that pulse.Square() does not support complex values for `amp`,"
" and that the phase is defined differently. See documentation.",
pending=True,
pending=False,
)
def square(
duration: int, amp: complex, freq: float = None, phase: float = 0, name: Optional[str] = None
Expand Down Expand Up @@ -125,15 +125,15 @@ def square(


@deprecate_func(
since="0.25.0",
additional_msg="The discrete pulses library, including sawtooth() is pending deprecation."
since="0.46.0",
additional_msg="The discrete pulses library, including sawtooth() is deprecated."
" Instead, use the SymbolicPulse library to create the waveform with"
" pulse.Sawtooth(...).get_waveform()."
" Note that pulse.Sawtooth() does not support complex values for `amp`."
" Instead, use two float values for (`amp`, `angle`)."
" Also note that the phase is defined differently, such that 2*pi phase"
" shifts by a full cycle.",
pending=True,
pending=False,
)
def sawtooth(
duration: int, amp: complex, freq: float = None, phase: float = 0, name: Optional[str] = None
Expand Down Expand Up @@ -182,13 +182,13 @@ def sawtooth(


@deprecate_func(
since="0.25.0",
additional_msg="The discrete pulses library, including triangle() is pending deprecation."
since="0.46.0",
additional_msg="The discrete pulses library, including triangle() is deprecated."
" Instead, use the SymbolicPulse library to create the waveform with"
" pulse.Triangle(...).get_waveform()."
" Note that pulse.Triangle() does not support complex values for `amp`."
" Instead, use two float values for (`amp`, `angle`).",
pending=True,
pending=False,
)
def triangle(
duration: int, amp: complex, freq: float = None, phase: float = 0, name: Optional[str] = None
Expand Down Expand Up @@ -237,13 +237,13 @@ def triangle(


@deprecate_func(
since="0.25.0",
additional_msg="The discrete pulses library, including cos() is pending deprecation."
since="0.46.0",
additional_msg="The discrete pulses library, including cos() is deprecated."
" Instead, use the SymbolicPulse library to create the waveform with"
" pulse.Cos(...).get_waveform()."
" Note that pulse.Cos() does not support complex values for `amp`."
" Instead, use two float values for (`amp`, `angle`).",
pending=True,
pending=False,
)
def cos(
duration: int, amp: complex, freq: float = None, phase: float = 0, name: Optional[str] = None
Expand Down Expand Up @@ -275,13 +275,13 @@ def cos(


@deprecate_func(
since="0.25.0",
additional_msg="The discrete pulses library, including sin() is pending deprecation."
since="0.46.0",
additional_msg="The discrete pulses library, including sin() is deprecated."
" Instead, use the SymbolicPulse library to create the waveform with"
" pulse.Sin(...).get_waveform()."
" Note that pulse.Sin() does not support complex values for `amp`."
" Instead, use two float values for (`amp`, `angle`).",
pending=True,
pending=False,
)
def sin(
duration: int, amp: complex, freq: float = None, phase: float = 0, name: Optional[str] = None
Expand Down Expand Up @@ -313,14 +313,14 @@ def sin(


@deprecate_func(
since="0.25.0",
additional_msg="The discrete pulses library, including gaussian() is pending deprecation."
since="0.46.0",
additional_msg="The discrete pulses library, including gaussian() is deprecated."
" Instead, use the SymbolicPulse library to create the waveform with"
" pulse.Gaussian(...).get_waveform()."
" Note that complex value support for the `amp` parameter is pending deprecation"
" Note that complex value support for the `amp` parameter is deprecated"
" in the SymbolicPulse library. It is therefore recommended to use two float values"
" for (`amp`, `angle`) instead of complex `amp`",
pending=True,
pending=False,
)
def gaussian(
duration: int, amp: complex, sigma: float, name: Optional[str] = None, zero_ends: bool = True
Expand Down Expand Up @@ -367,13 +367,13 @@ def gaussian(


@deprecate_func(
since="0.25.0",
additional_msg="The discrete pulses library, including gaussian_deriv() is pending deprecation."
since="0.46.0",
additional_msg="The discrete pulses library, including gaussian_deriv() is deprecated."
" Instead, use the SymbolicPulse library to create the waveform with"
" pulse.GaussianDeriv(...).get_waveform()."
" Note that pulse.GaussianDeriv() does not support complex values for `amp`."
" Instead, use two float values for (`amp`, `angle`).",
pending=True,
pending=False,
)
def gaussian_deriv(
duration: int, amp: complex, sigma: float, name: Optional[str] = None
Expand Down Expand Up @@ -404,13 +404,13 @@ def gaussian_deriv(


@deprecate_func(
since="0.25.0",
additional_msg="The discrete pulses library, including sech() is pending deprecation."
since="0.46.0",
additional_msg="The discrete pulses library, including sech() is deprecated."
" Instead, use the SymbolicPulse library to create the waveform with"
" pulse.Sech(...).get_waveform()."
" Note that pulse.Sech() does not support complex values for `amp`."
" Instead, use two float values for (`amp`, `angle`).",
pending=True,
pending=False,
)
def sech(
duration: int, amp: complex, sigma: float, name: str = None, zero_ends: bool = True
Expand Down Expand Up @@ -455,13 +455,13 @@ def sech(


@deprecate_func(
since="0.25.0",
additional_msg="The discrete pulses library, including sech_deriv() is pending deprecation."
since="0.46.0",
additional_msg="The discrete pulses library, including sech_deriv() is deprecated."
" Instead, use the SymbolicPulse library to create the waveform with"
" pulse.SechDeriv(...).get_waveform()."
" Note that pulse.SechDeriv() does not support complex values for `amp`."
" Instead, use two float values for (`amp`, `angle`).",
pending=True,
pending=False,
)
def sech_deriv(duration: int, amp: complex, sigma: float, name: str = None) -> Waveform:
r"""Generates unnormalized sech derivative :class:`~qiskit.pulse.library.Waveform`.
Expand Down Expand Up @@ -489,14 +489,14 @@ def sech_deriv(duration: int, amp: complex, sigma: float, name: str = None) -> W


@deprecate_func(
since="0.25.0",
additional_msg="The discrete pulses library, including gaussian_square() is pending deprecation."
since="0.46.0",
additional_msg="The discrete pulses library, including gaussian_square() is deprecated."
" Instead, use the SymbolicPulse library to create the waveform with"
" pulse.GaussianSquare(...).get_waveform()."
" Note that complex value support for the `amp` parameter is pending deprecation"
" Note that complex value support for the `amp` parameter is deprecated"
" in the SymbolicPulse library. It is therefore recommended to use two float values"
" for (`amp`, `angle`) instead of complex `amp`",
pending=True,
pending=False,
)
def gaussian_square(
duration: int,
Expand Down Expand Up @@ -565,14 +565,14 @@ def gaussian_square(


@deprecate_func(
since="0.25.0",
additional_msg="The discrete pulses library, including drag() is pending deprecation."
since="0.46.0",
additional_msg="The discrete pulses library, including drag() is deprecated."
" Instead, use the SymbolicPulse library to create the waveform with"
" pulse.Drag(...).get_waveform()."
" Note that complex value support for the `amp` parameter is pending deprecation"
" Note that complex value support for the `amp` parameter is deprecated"
" in the SymbolicPulse library. It is therefore recommended to use two float values"
" for (`amp`, `angle`) instead of complex `amp`",
pending=True,
pending=False,
)
def drag(
duration: int,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
deprecations:
- |
The discrete pulse library is now deprecated and will be removed in a future release. This includes:
* :func:`~qiskit.pulse.library.constant`
* :func:`~qiskit.pulse.library.zero`
* :func:`~qiskit.pulse.library.square`
* :func:`~qiskit.pulse.library.sawtooth`
* :func:`~qiskit.pulse.library.triangle`
* :func:`~qiskit.pulse.library.cos`
* :func:`~qiskit.pulse.library.sin`
* :func:`~qiskit.pulse.library.gaussian`
* :func:`~qiskit.pulse.library.gaussian_deriv`
* :func:`~qiskit.pulse.library.sech`
* :func:`~qiskit.pulse.library.sech_deriv`
* :func:`~qiskit.pulse.library.gaussian_square`
* :func:`~qiskit.pulse.library.drag`
Instead, use the corresponding :class:`~qiskit.pulse.SymbolicPulse`, with :meth:`~.SymbolicPulse.get_waveform()`.
For example, instead of ``pulse.gaussian(100,0.5,10)`` use ``pulse.Gaussian(100,0.5,10).get_waveform()``.
Note that the phase of both ``Sawtooth`` and ``Square`` is defined such that a phase of :math:``2\\pi``
shifts by a full cycle, contrary to the discrete counterpart. Also note that complex amplitude support is
deprecated in the symbolic pulse library - use ``float`` ``amp`` and ``angle`` instead.
3 changes: 1 addition & 2 deletions test/python/compiler/test_assembler.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
from qiskit.pulse import Schedule, Acquire, Play
from qiskit.pulse.channels import MemorySlot, AcquireChannel, DriveChannel, MeasureChannel
from qiskit.pulse.configuration import Kernel, Discriminator
from qiskit.pulse.library import gaussian
from qiskit.qobj import QasmQobj, PulseQobj
from qiskit.qobj.utils import MeasLevel, MeasReturnType
from qiskit.pulse.macros import measure
Expand Down Expand Up @@ -1201,7 +1200,7 @@ def test_pulse_name_conflicts_in_other_schedule(self):
ch_d0 = pulse.DriveChannel(0)
for amp in (0.1, 0.2):
sched = Schedule()
sched += Play(gaussian(duration=100, amp=amp, sigma=30, name="my_pulse"), ch_d0)
sched += Play(pulse.Gaussian(duration=100, amp=amp, sigma=30, name="my_pulse"), ch_d0)
sched += measure(qubits=[0], backend=backend) << 100
schedules.append(sched)

Expand Down
Loading

0 comments on commit addb62e

Please sign in to comment.