From f99b16f1157db89ea19d45686e8c11ec8abefbd4 Mon Sep 17 00:00:00 2001 From: Jim Garrison Date: Fri, 7 Oct 2022 13:05:10 -0400 Subject: [PATCH 1/2] Fix deprecation warning for `deprecated_functionality` --- qiskit/pulse/transforms/alignments.py | 9 +++++---- .../deprecated-pulse-deprecator-394ec75079441cda.yaml | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/qiskit/pulse/transforms/alignments.py b/qiskit/pulse/transforms/alignments.py index 412a543387d2..1c4599deb41c 100644 --- a/qiskit/pulse/transforms/alignments.py +++ b/qiskit/pulse/transforms/alignments.py @@ -19,7 +19,8 @@ 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, deprecated_functionality +from qiskit.pulse.utils import instruction_duration_validation +from qiskit.utils import deprecate_function class AlignmentKind(abc.ABC): @@ -44,7 +45,7 @@ def align(self, schedule: Schedule) -> Schedule: """ pass - @deprecated_functionality + @deprecate_function def to_dict(self) -> Dict[str, Any]: """Returns dictionary to represent this alignment.""" return {"alignment": self.__class__.__name__} @@ -329,7 +330,7 @@ def align(self, schedule: Schedule) -> Schedule: return aligned - @deprecated_functionality + @deprecate_function def to_dict(self) -> Dict[str, Any]: """Returns dictionary to represent this alignment.""" return {"alignment": self.__class__.__name__, "duration": self.duration} @@ -413,7 +414,7 @@ def align(self, schedule: Schedule) -> Schedule: return aligned - @deprecated_functionality + @deprecate_function def to_dict(self) -> Dict[str, Any]: """Returns dictionary to represent this alignment. diff --git a/releasenotes/notes/0.22/deprecated-pulse-deprecator-394ec75079441cda.yaml b/releasenotes/notes/0.22/deprecated-pulse-deprecator-394ec75079441cda.yaml index 15b895c46017..17a114f347cb 100644 --- a/releasenotes/notes/0.22/deprecated-pulse-deprecator-394ec75079441cda.yaml +++ b/releasenotes/notes/0.22/deprecated-pulse-deprecator-394ec75079441cda.yaml @@ -1,7 +1,7 @@ --- deprecations: - | - The pulse-module function ``qiskit.pulse.utils.deprecate_functionality`` is + The pulse-module function ``qiskit.pulse.utils.deprecated_functionality`` is deprecated and will be removed in a future release. This was a primarily internal-only function. The same functionality is supplied by ``qiskit.utils.deprecate_function``, which should be used instead. From f84f1b09ac21722dddc9148163aa4998b5ef2423 Mon Sep 17 00:00:00 2001 From: Jim Garrison Date: Tue, 11 Oct 2022 17:38:29 -0400 Subject: [PATCH 2/2] Emit the deprecation warning inline to avoid cyclic import --- qiskit/pulse/transforms/alignments.py | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/qiskit/pulse/transforms/alignments.py b/qiskit/pulse/transforms/alignments.py index 1c4599deb41c..a00ee82873ba 100644 --- a/qiskit/pulse/transforms/alignments.py +++ b/qiskit/pulse/transforms/alignments.py @@ -13,6 +13,7 @@ import abc from typing import Callable, Dict, Any, Union, Tuple +import warnings import numpy as np @@ -20,7 +21,6 @@ from qiskit.pulse.exceptions import PulseError from qiskit.pulse.schedule import Schedule, ScheduleComponent from qiskit.pulse.utils import instruction_duration_validation -from qiskit.utils import deprecate_function class AlignmentKind(abc.ABC): @@ -45,9 +45,14 @@ def align(self, schedule: Schedule) -> Schedule: """ pass - @deprecate_function 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 @@ -330,9 +335,14 @@ def align(self, schedule: Schedule) -> Schedule: return aligned - @deprecate_function 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} @@ -414,12 +424,17 @@ def align(self, schedule: Schedule) -> Schedule: return aligned - @deprecate_function 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,