Skip to content

Commit

Permalink
Apply new deprecation decorators to pulse folder (Qiskit#9871)
Browse files Browse the repository at this point in the history
* Apply new deprecation decorators to pulse folder

* Update qiskit/pulse/library/parametric_pulses.py

Co-authored-by: Naoki Kanazawa <[email protected]>

* Fix bad use of DeMorgan's law for boolean

---------

Co-authored-by: Naoki Kanazawa <[email protected]>
  • Loading branch information
2 people authored and giacomoRanieri committed Apr 16, 2023
1 parent 5b82b89 commit b3f129f
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 47 deletions.
12 changes: 7 additions & 5 deletions qiskit/pulse/instructions/instruction.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
from qiskit.pulse.exceptions import PulseError
from qiskit.utils import optionals as _optionals

from qiskit.utils.deprecation import deprecate_function
from qiskit.utils.deprecation import deprecate_func


# pylint: disable=bad-docstring-quotes
Expand Down Expand Up @@ -223,10 +223,12 @@ def is_parameterized(self) -> bool:
"""Return True iff the instruction is parameterized."""
return any(self.parameters)

@deprecate_function(
"Drawing individual pulses is deprecated since Terra 0.23, and will be removed in a future"
" version of the library. No direct alternative is being provided, but instructions can"
" be visualized as part of a complete schedule using `qiskit.visualization.pulse_drawer`.",
@deprecate_func(
additional_msg=(
"No direct alternative is being provided to drawing individual pulses. But, "
"instructions can be visualized as part of a complete schedule using "
"``qiskit.visualization.pulse_drawer``."
),
since="0.23.0",
)
@_optionals.HAS_MATPLOTLIB.require_in_call
Expand Down
50 changes: 41 additions & 9 deletions qiskit/pulse/library/parametric_pulses.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ class ParametricPulseShapes(Enum):
...
new_supported_pulse_name = library.YourPulseWaveformClass
"""
import warnings
from abc import abstractmethod
from typing import Any, Dict, Optional, Union

Expand All @@ -49,6 +48,7 @@ class ParametricPulseShapes(Enum):
from qiskit.pulse.library.discrete import gaussian, gaussian_square, drag, constant
from qiskit.pulse.library.pulse import Pulse
from qiskit.pulse.library.waveform import Waveform
from qiskit.utils.deprecation import deprecate_func


class ParametricPulse(Pulse):
Expand All @@ -63,6 +63,14 @@ class ParametricPulse(Pulse):
"""

@abstractmethod
@deprecate_func(
additional_msg=(
"Instead, use SymbolicPulse because of QPY serialization support. See "
"qiskit.pulse.library.symbolic_pulses for details."
),
since="0.22",
pending=True,
)
def __init__(
self,
duration: Union[int, ParameterExpression],
Expand All @@ -79,14 +87,6 @@ def __init__(
amplitude is constrained to 1.
"""
super().__init__(duration=duration, name=name, limit_amplitude=limit_amplitude)

warnings.warn(
"ParametricPulse and its subclass will be deprecated and will be replaced with "
"SymbolicPulse and its subclass because of QPY serialization support. "
"See qiskit.pulse.library.symbolic_pulses for details.",
PendingDeprecationWarning,
stacklevel=3,
)
self.validate_parameters()

@abstractmethod
Expand Down Expand Up @@ -132,6 +132,14 @@ class Gaussian(ParametricPulse):
and practical DSP reasons it has the name ``Gaussian``.
"""

@deprecate_func(
additional_msg=(
"Instead, use Gaussian from qiskit.pulse.library.symbolic_pulses because of "
"QPY serialization support."
),
since="0.22",
pending=True,
)
def __init__(
self,
duration: Union[int, ParameterExpression],
Expand Down Expand Up @@ -236,6 +244,14 @@ class GaussianSquare(ParametricPulse):
and practical DSP reasons it has the name ``GaussianSquare``.
"""

@deprecate_func(
additional_msg=(
"Instead, use GaussianSquare from qiskit.pulse.library.symbolic_pulses because of "
"QPY serialization support."
),
since="0.22",
pending=True,
)
def __init__(
self,
duration: Union[int, ParameterExpression],
Expand Down Expand Up @@ -398,6 +414,14 @@ class Drag(ParametricPulse):
Phys. Rev. Lett. 103, 110501 – Published 8 September 2009.*
"""

@deprecate_func(
additional_msg=(
"Instead, use Drag from qiskit.pulse.library.symbolic_pulses because of "
"QPY serialization support."
),
since="0.22",
pending=True,
)
def __init__(
self,
duration: Union[int, ParameterExpression],
Expand Down Expand Up @@ -513,6 +537,14 @@ class Constant(ParametricPulse):
f(x) = 0 , elsewhere
"""

@deprecate_func(
additional_msg=(
"Instead, use Constant from qiskit.pulse.library.symbolic_pulses because of "
"QPY serialization support."
),
since="0.22",
pending=True,
)
def __init__(
self,
duration: Union[int, ParameterExpression],
Expand Down
27 changes: 16 additions & 11 deletions qiskit/pulse/library/symbolic_pulses.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
from qiskit.pulse.library.pulse import Pulse
from qiskit.pulse.library.waveform import Waveform
from qiskit.utils import optionals as _optional
from qiskit.utils.deprecation import deprecate_arg

if _optional.HAS_SYMENGINE:
import symengine as sym
Expand Down Expand Up @@ -586,6 +587,18 @@ class ScalableSymbolicPulse(SymbolicPulse):
:math:'\text{amp}\times\exp\left(i\times\text{angle}\right)' is compared.
"""

@deprecate_arg(
"amp",
deprecation_description=(
"Setting ``amp`` to a complex in the ScalableSymbolicPulse constructor"
),
additional_msg=(
"Instead, use a float for ``amp`` (for the magnitude) and a float for ``angle``"
),
since="0.23.0",
pending=True,
predicate=lambda amp: isinstance(amp, complex),
)
def __init__(
self,
pulse_type: str,
Expand Down Expand Up @@ -620,18 +633,10 @@ def __init__(
Raises:
PulseError: If both `amp` is complex and `angle` is not `None` or 0.
"""
# This should be removed once complex amp support is deprecated.
if isinstance(amp, complex):
if angle is None or angle == 0:
warnings.warn(
"Complex amp will be deprecated. "
"Use float amp (for the magnitude) and float angle instead.",
PendingDeprecationWarning,
)
else:
raise PulseError("amp can't be complex with angle not None or 0")
# This should be removed once complex amp support is removed.
if isinstance(amp, complex) and angle is not None and angle != 0:
raise PulseError("amp can't be complex with angle not None or 0")

if angle is None:
angle = 0
Expand Down
23 changes: 4 additions & 19 deletions qiskit/pulse/transforms/alignments.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@

import abc
from typing import Callable, Dict, Any, Union, Tuple
import warnings

import numpy as np

from qiskit.circuit.parameterexpression import ParameterExpression, ParameterValueType
from qiskit.pulse.exceptions import PulseError
from qiskit.pulse.schedule import Schedule, ScheduleComponent
from qiskit.pulse.utils import instruction_duration_validation
from qiskit.utils.deprecation import deprecate_func


class AlignmentKind(abc.ABC):
Expand All @@ -45,14 +45,9 @@ def align(self, schedule: Schedule) -> Schedule:
"""
pass

@deprecate_func(since="0.21")
def to_dict(self) -> Dict[str, Any]:
"""Returns dictionary to represent this alignment."""
warnings.warn(
"The AlignmentKind.to_dict method is deprecated as of Qiskit Terra "
"0.21 and will be removed no sooner than 3 months after the release date.",
category=DeprecationWarning,
stacklevel=2,
)
return {"alignment": self.__class__.__name__}

@property
Expand Down Expand Up @@ -335,14 +330,9 @@ def align(self, schedule: Schedule) -> Schedule:

return aligned

@deprecate_func(since="0.21")
def to_dict(self) -> Dict[str, Any]:
"""Returns dictionary to represent this alignment."""
warnings.warn(
"The AlignEquispaced.to_dict method is deprecated as of Qiskit Terra "
"0.21 and will be removed no sooner than 3 months after the release date.",
category=DeprecationWarning,
stacklevel=2,
)
return {"alignment": self.__class__.__name__, "duration": self.duration}


Expand Down Expand Up @@ -424,17 +414,12 @@ def align(self, schedule: Schedule) -> Schedule:

return aligned

@deprecate_func(since="0.21")
def to_dict(self) -> Dict[str, Any]:
"""Returns dictionary to represent this alignment.
.. note:: ``func`` is not presented in this dictionary. Just name.
"""
warnings.warn(
"The AlignFunc.to_dict method is deprecated as of Qiskit Terra "
"0.21 and will be removed no sooner than 3 months after the release date.",
category=DeprecationWarning,
stacklevel=2,
)
return {
"alignment": self.__class__.__name__,
"duration": self.duration,
Expand Down
6 changes: 3 additions & 3 deletions qiskit/pulse/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

from qiskit.circuit.parameterexpression import ParameterExpression
from qiskit.pulse.exceptions import UnassignedDurationError, QiskitError
from qiskit.utils import deprecate_function # pylint: disable=cyclic-import
from qiskit.utils.deprecation import deprecate_func, deprecate_function


def format_meas_map(meas_map: List[List[int]]) -> Dict[int, List[int]]:
Expand Down Expand Up @@ -98,8 +98,8 @@ def instruction_duration_validation(duration: int):
)


@deprecate_function(
"Deprecated since Terra 0.22.0. Use 'qiskit.utils.deprecate_function' instead.",
@deprecate_func(
additional_msg="Instead, use 'qiskit.utils.deprecate_func'.",
since="0.22.0",
)
def deprecated_functionality(func):
Expand Down

0 comments on commit b3f129f

Please sign in to comment.