Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply new deprecation decorators to algorithms folder #9864

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 9 additions & 22 deletions qiskit/algorithms/amplitude_amplifiers/grover.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from qiskit.providers import Backend
from qiskit.quantum_info import partial_trace
from qiskit.utils import QuantumInstance, algorithm_globals
from qiskit.utils.deprecation import deprecate_function
from qiskit.utils.deprecation import deprecate_arg, deprecate_func

from .amplification_problem import AmplificationProblem
from .amplitude_amplifier import AmplitudeAmplifier, AmplitudeAmplifierResult
Expand Down Expand Up @@ -112,6 +112,12 @@ class Grover(AmplitudeAmplifier):
`arXiv:quant-ph/0005055 <http://arxiv.org/abs/quant-ph/0005055>`_.
"""

@deprecate_arg(
"quantum_instance",
additional_msg="Instead, use the ``sampler`` argument.",
since="0.22.0",
pending=True,
)
def __init__(
self,
iterations: Optional[Union[List[int], Iterator[int], int]] = None,
Expand Down Expand Up @@ -174,13 +180,6 @@ def __init__(

self._quantum_instance = None
if quantum_instance is not None:
warnings.warn(
"The quantum_instance argument has been superseded by the sampler argument. "
"This argument will be deprecated in a future release and subsequently "
"removed after that.",
category=PendingDeprecationWarning,
stacklevel=2,
)
with warnings.catch_warnings():
warnings.simplefilter("ignore", category=PendingDeprecationWarning)
self.quantum_instance = quantum_instance
Expand All @@ -191,13 +190,7 @@ def __init__(
self._iterations_arg = iterations

@property
@deprecate_function(
"The Grover.quantum_instance getter is pending deprecation. "
"This property will be deprecated in a future release and subsequently "
"removed after that.",
category=PendingDeprecationWarning,
since="0.23.0",
)
@deprecate_func(since="0.23.0", pending=True, is_property=True)
def quantum_instance(self) -> Optional[QuantumInstance]:
r"""Pending deprecation\; Get the quantum instance.

Expand All @@ -207,13 +200,7 @@ def quantum_instance(self) -> Optional[QuantumInstance]:
return self._quantum_instance

@quantum_instance.setter
@deprecate_function(
"The Grover.quantum_instance setter is pending deprecation. "
"This property will be deprecated in a future release and subsequently "
"removed after that.",
category=PendingDeprecationWarning,
since="0.23.0",
)
@deprecate_func(since="0.23.0", pending=True, is_property=True)
def quantum_instance(self, quantum_instance: Union[QuantumInstance, Backend]) -> None:
r"""Pending deprecation\; Set quantum instance.

Expand Down
31 changes: 9 additions & 22 deletions qiskit/algorithms/amplitude_estimators/ae.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from qiskit.providers import Backend
from qiskit.primitives import BaseSampler
from qiskit.utils import QuantumInstance
from qiskit.utils.deprecation import deprecate_function
from qiskit.utils.deprecation import deprecate_arg, deprecate_func
from .amplitude_estimator import AmplitudeEstimator, AmplitudeEstimatorResult
from .ae_utils import pdf_a, derivative_log_pdf_a, bisect_max
from .estimation_problem import EstimationProblem
Expand Down Expand Up @@ -57,6 +57,12 @@ class AmplitudeEstimation(AmplitudeEstimator):
`arXiv:1912.05559 <https://arxiv.org/abs/1912.05559>`_.
"""

@deprecate_arg(
"quantum_instance",
additional_msg="Instead, use the ``sampler`` argument.",
since="0.22.0",
pending=True,
)
def __init__(
self,
num_eval_qubits: int,
Expand Down Expand Up @@ -86,13 +92,6 @@ def __init__(
super().__init__()

# set quantum instance
if quantum_instance is not None:
warnings.warn(
"The quantum_instance argument has been superseded by the sampler argument. "
"This argument will be deprecated in a future release and subsequently "
"removed after that.",
category=PendingDeprecationWarning,
)
with warnings.catch_warnings():
warnings.simplefilter("ignore")
self.quantum_instance = quantum_instance
Expand Down Expand Up @@ -124,13 +123,7 @@ def sampler(self, sampler: BaseSampler) -> None:
self._sampler = sampler

@property
@deprecate_function(
"The AmplitudeEstimation.quantum_instance getter is pending deprecation. "
"This property will be deprecated in a future release and subsequently "
"removed after that.",
category=PendingDeprecationWarning,
since="0.23.0",
)
@deprecate_func(since="0.23.0", pending=True, is_property=True)
def quantum_instance(self) -> QuantumInstance | None:
"""Pending deprecation; Get the quantum instance.

Expand All @@ -140,13 +133,7 @@ def quantum_instance(self) -> QuantumInstance | None:
return self._quantum_instance

@quantum_instance.setter
@deprecate_function(
"The AmplitudeEstimation.quantum_instance setter is pending deprecation. "
"This property will be deprecated in a future release and subsequently "
"removed after that.",
category=PendingDeprecationWarning,
since="0.23.0",
)
@deprecate_func(since="0.23.0", pending=True, is_property=True)
def quantum_instance(self, quantum_instance: QuantumInstance | Backend) -> None:
"""Pending deprecation; Set quantum instance.

Expand Down
31 changes: 9 additions & 22 deletions qiskit/algorithms/amplitude_estimators/fae.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from qiskit.providers import Backend
from qiskit.primitives import BaseSampler
from qiskit.utils import QuantumInstance
from qiskit.utils.deprecation import deprecate_function
from qiskit.utils.deprecation import deprecate_arg, deprecate_func
from qiskit.algorithms.exceptions import AlgorithmError

from .amplitude_estimator import AmplitudeEstimator, AmplitudeEstimatorResult
Expand Down Expand Up @@ -48,6 +48,12 @@ class FasterAmplitudeEstimation(AmplitudeEstimator):

"""

@deprecate_arg(
"quantum_instance",
additional_msg="Instead, use the ``sampler`` argument.",
since="0.22.0",
pending=True,
)
def __init__(
self,
delta: float,
Expand All @@ -73,13 +79,6 @@ def __init__(
"""
super().__init__()
# set quantum instance
if quantum_instance is not None:
warnings.warn(
"The quantum_instance argument has been superseded by the sampler argument. "
"This argument will be deprecated in a future release and subsequently "
"removed after that.",
category=PendingDeprecationWarning,
)
with warnings.catch_warnings():
warnings.simplefilter("ignore")
self.quantum_instance = quantum_instance
Expand Down Expand Up @@ -109,13 +108,7 @@ def sampler(self, sampler: BaseSampler) -> None:
self._sampler = sampler

@property
@deprecate_function(
"The FasterAmplitudeEstimation.quantum_instance getter is pending deprecation. "
"This property will be deprecated in a future release and subsequently "
"removed after that.",
category=PendingDeprecationWarning,
since="0.23.0",
)
@deprecate_func(since="0.23.0", pending=True, is_property=True)
def quantum_instance(self) -> QuantumInstance | None:
"""Pending deprecation; Get the quantum instance.

Expand All @@ -125,13 +118,7 @@ def quantum_instance(self) -> QuantumInstance | None:
return self._quantum_instance

@quantum_instance.setter
@deprecate_function(
"The FasterAmplitudeEstimation.quantum_instance setter is pending deprecation. "
"This property will be deprecated in a future release and subsequently "
"removed after that.",
category=PendingDeprecationWarning,
since="0.23.0",
)
@deprecate_func(since="0.23.0", pending=True, is_property=True)
def quantum_instance(self, quantum_instance: QuantumInstance | Backend) -> None:
"""Pending deprecation; Set quantum instance.

Expand Down
31 changes: 9 additions & 22 deletions qiskit/algorithms/amplitude_estimators/iae.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from qiskit.providers import Backend
from qiskit.primitives import BaseSampler
from qiskit.utils import QuantumInstance
from qiskit.utils.deprecation import deprecate_function
from qiskit.utils.deprecation import deprecate_arg, deprecate_func

from .amplitude_estimator import AmplitudeEstimator, AmplitudeEstimatorResult
from .estimation_problem import EstimationProblem
Expand Down Expand Up @@ -50,6 +50,12 @@ class IterativeAmplitudeEstimation(AmplitudeEstimator):
`arXiv:quant-ph/0005055 <http://arxiv.org/abs/quant-ph/0005055>`_.
"""

@deprecate_arg(
"quantum_instance",
additional_msg="Instead, use the ``sampler`` argument.",
since="0.22.0",
pending=True,
)
def __init__(
self,
epsilon_target: float,
Expand Down Expand Up @@ -95,13 +101,6 @@ def __init__(
super().__init__()

# set quantum instance
if quantum_instance is not None:
warnings.warn(
"The quantum_instance argument has been superseded by the sampler argument. "
"This argument will be deprecated in a future release and subsequently "
"removed after that.",
category=PendingDeprecationWarning,
)
with warnings.catch_warnings():
warnings.simplefilter("ignore")
self.quantum_instance = quantum_instance
Expand Down Expand Up @@ -132,13 +131,7 @@ def sampler(self, sampler: BaseSampler) -> None:
self._sampler = sampler

@property
@deprecate_function(
"The IterativeAmplitudeEstimation.quantum_instance getter is pending deprecation. "
"This property will be deprecated in a future release and subsequently "
"removed after that.",
category=PendingDeprecationWarning,
since="0.23.0",
)
@deprecate_func(since="0.23.0", pending=True, is_property=True)
def quantum_instance(self) -> QuantumInstance | None:
"""Pending deprecation; Get the quantum instance.

Expand All @@ -148,13 +141,7 @@ def quantum_instance(self) -> QuantumInstance | None:
return self._quantum_instance

@quantum_instance.setter
@deprecate_function(
"The IterativeAmplitudeEstimation.quantum_instance setter is pending deprecation. "
"This property will be deprecated in a future release and subsequently "
"removed after that.",
category=PendingDeprecationWarning,
since="0.23.0",
)
@deprecate_func(since="0.23.0", pending=True, is_property=True)
def quantum_instance(self, quantum_instance: QuantumInstance | Backend) -> None:
"""Pending deprecation; Set quantum instance.

Expand Down
31 changes: 9 additions & 22 deletions qiskit/algorithms/amplitude_estimators/mlae.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from qiskit import ClassicalRegister, QuantumRegister, QuantumCircuit
from qiskit.utils import QuantumInstance
from qiskit.primitives import BaseSampler
from qiskit.utils.deprecation import deprecate_function
from qiskit.utils.deprecation import deprecate_arg, deprecate_func

from .amplitude_estimator import AmplitudeEstimator, AmplitudeEstimatorResult
from .estimation_problem import EstimationProblem
Expand Down Expand Up @@ -53,6 +53,12 @@ class in named ``MaximumLikelihoodAmplitudeEstimation``.
`arXiv:quant-ph/0005055 <http://arxiv.org/abs/quant-ph/0005055>`_.
"""

@deprecate_arg(
"quantum_instance",
additional_msg="Instead, use the ``sampler`` argument.",
since="0.22.0",
pending=True,
)
def __init__(
self,
evaluation_schedule: list[int] | int,
Expand Down Expand Up @@ -81,13 +87,6 @@ def __init__(
super().__init__()

# set quantum instance
if quantum_instance is not None:
warnings.warn(
"The quantum_instance argument has been superseded by the sampler argument. "
"This argument will be deprecated in a future release and subsequently "
"removed after that.",
category=PendingDeprecationWarning,
)
with warnings.catch_warnings():
warnings.simplefilter("ignore")
self.quantum_instance = quantum_instance
Expand Down Expand Up @@ -136,13 +135,7 @@ def sampler(self, sampler: BaseSampler) -> None:
self._sampler = sampler

@property
@deprecate_function(
"The MaximumLikelihoodAmplitudeEstimation.quantum_instance getter is pending deprecation. "
"This property will be deprecated in a future release and subsequently "
"removed after that.",
category=PendingDeprecationWarning,
since="0.23.0",
)
@deprecate_func(since="0.23.0", pending=True, is_property=True)
def quantum_instance(self) -> QuantumInstance | None:
"""Pending deprecation; Get the quantum instance.

Expand All @@ -152,13 +145,7 @@ def quantum_instance(self) -> QuantumInstance | None:
return self._quantum_instance

@quantum_instance.setter
@deprecate_function(
"The MaximumLikelihoodAmplitudeEstimation.quantum_instance setter is pending deprecation. "
"This property will be deprecated in a future release and subsequently "
"removed after that.",
category=PendingDeprecationWarning,
since="0.23.0",
)
@deprecate_func(since="0.23.0", pending=True, is_property=True)
def quantum_instance(self, quantum_instance: QuantumInstance | Backend) -> None:
"""Pending deprecation; Set quantum instance.

Expand Down
14 changes: 7 additions & 7 deletions qiskit/algorithms/aux_ops_evaluator.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,18 @@
from qiskit.providers import Backend
from qiskit.quantum_info import Statevector
from qiskit.utils import QuantumInstance
from qiskit.utils.deprecation import deprecate_function
from qiskit.utils.deprecation import deprecate_func

from .list_or_dict import ListOrDict


@deprecate_function(
"The eval_observables function has been superseded by the "
"qiskit.algorithms.observables_evaluator.estimate_observables function. "
"This function will be deprecated in a future release and subsequently "
"removed after that.",
category=PendingDeprecationWarning,
@deprecate_func(
additional_msg=(
"Instead, use the function "
"``qiskit.algorithms.observables_evaluator.estimate_observables``."
Comment on lines +36 to +37
Copy link
Member

@woodsp-ibm woodsp-ibm Mar 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just commenting - after the support is added to allow these to be sphinx refs I guess this one example where it can be a link instead of plain text as we need it now. And quite a few more examples follow for classes.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These can be Sphinx's references now :) We only want #9815 so that the runtime warning doesn't include noise like the :ref:.

But, if it's okay with you, I'd prefer to not spend more time re-updating all these references to use :ref, at least this week. Migrating the whole repo to use these new decorators took several hours, and fixing up #9532 and friends will take me some time too. I'm trying to balance this project w/ other docs priorities we have for March/early April.

I'm happy to open a ticket to track this improvement, though, so that we don't forget we want to do it.

),
since="0.23.0",
pending=True,
)
def eval_observables(
quantum_instance: Union[QuantumInstance, Backend],
Expand Down
Loading