Skip to content

Commit

Permalink
Change algorithms from pending deprecation to deprecated (Qiskit#9883)
Browse files Browse the repository at this point in the history
* Change algorithms from pending deprecation to deprecated

Co-authored-by: Manoel Marques <[email protected]>

* Review feedback & fix fmt

* Try to fix the tests

* Another round of test fixes

* Last round of test fixes?

* Actual last test fix!

* Use HTTPS

* Refer to migration guide in deprecation changelog

---------

Co-authored-by: Manoel Marques <[email protected]>
  • Loading branch information
Eric-Arellano and manoelmarques authored Apr 14, 2023
1 parent 2c67f66 commit 3ebef17
Show file tree
Hide file tree
Showing 43 changed files with 947 additions and 659 deletions.
28 changes: 19 additions & 9 deletions qiskit/algorithms/amplitude_amplifiers/grover.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,11 @@ class Grover(AmplitudeAmplifier):

@deprecate_arg(
"quantum_instance",
additional_msg="Instead, use the ``sampler`` argument.",
since="0.22.0",
pending=True,
additional_msg=(
"Instead, use the ``sampler`` argument. "
"See https://qisk.it/algo_migration for a migration guide."
),
since="0.24.0",
)
def __init__(
self,
Expand All @@ -145,7 +147,7 @@ def __init__(
sample_from_iterations: If True, instead of taking the values in ``iterations`` as
powers of the Grover operator, a random integer sample between 0 and smaller value
than the iteration is used as a power, see [1], Section 4.
quantum_instance: Pending deprecation: A Quantum Instance or Backend to run the circuits.
quantum_instance: Deprecated: A Quantum Instance or Backend to run the circuits.
sampler: A Sampler to use for sampling the results of the circuits.
Raises:
Expand Down Expand Up @@ -185,7 +187,7 @@ def __init__(
self._quantum_instance: QuantumInstance | None = None
if quantum_instance is not None:
with warnings.catch_warnings():
warnings.simplefilter("ignore", category=PendingDeprecationWarning)
warnings.simplefilter("ignore", DeprecationWarning)
self.quantum_instance = quantum_instance

self._sampler = sampler
Expand All @@ -194,19 +196,27 @@ def __init__(
self._iterations_arg = iterations

@property
@deprecate_func(since="0.23.0", pending=True, is_property=True)
@deprecate_func(
since="0.24.0",
is_property=True,
additional_msg="See https://qisk.it/algo_migration for a migration guide.",
)
def quantum_instance(self) -> QuantumInstance | None:
r"""Pending deprecation\; Get the quantum instance.
r"""Deprecated. Get the quantum instance.
Returns:
The quantum instance used to run this algorithm.
"""
return self._quantum_instance

@quantum_instance.setter
@deprecate_func(since="0.23.0", pending=True, is_property=True)
@deprecate_func(
since="0.24.0",
is_property=True,
additional_msg="See https://qisk.it/algo_migration for a migration guide.",
)
def quantum_instance(self, quantum_instance: QuantumInstance | Backend) -> None:
r"""Pending deprecation\; Set quantum instance.
r"""Deprecated. Set quantum instance.
Args:
quantum_instance: The quantum instance used to run this algorithm.
Expand Down
26 changes: 18 additions & 8 deletions qiskit/algorithms/amplitude_estimators/ae.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,11 @@ class AmplitudeEstimation(AmplitudeEstimator):

@deprecate_arg(
"quantum_instance",
additional_msg="Instead, use the ``sampler`` argument.",
since="0.22.0",
pending=True,
additional_msg=(
"Instead, use the ``sampler`` argument. See https://qisk.it/algo_migration for a "
"migration guide."
),
since="0.24.0",
)
def __init__(
self,
Expand All @@ -86,7 +88,7 @@ def __init__(
`qiskit.circuit.library.PhaseEstimation` when None.
iqft: The inverse quantum Fourier transform component, defaults to using a standard
implementation from `qiskit.circuit.library.QFT` when None.
quantum_instance: Pending deprecation\: The backend (or `QuantumInstance`) to execute
quantum_instance: Deprecated: The backend (or `QuantumInstance`) to execute
the circuits on.
sampler: A sampler primitive to evaluate the circuits.
Expand Down Expand Up @@ -130,19 +132,27 @@ def sampler(self, sampler: BaseSampler) -> None:
self._sampler = sampler

@property
@deprecate_func(since="0.23.0", pending=True, is_property=True)
@deprecate_func(
additional_msg="See https://qisk.it/algo_migration for a migration guide.",
since="0.24.0",
is_property=True,
)
def quantum_instance(self) -> QuantumInstance | None:
"""Pending deprecation; Get the quantum instance.
"""Deprecated: Get the quantum instance.
Returns:
The quantum instance used to run this algorithm.
"""
return self._quantum_instance

@quantum_instance.setter
@deprecate_func(since="0.23.0", pending=True, is_property=True)
@deprecate_func(
additional_msg="See https://qisk.it/algo_migration for a migration guide.",
since="0.24.0",
is_property=True,
)
def quantum_instance(self, quantum_instance: QuantumInstance | Backend) -> None:
"""Pending deprecation; Set quantum instance.
"""Deprecated: Set quantum instance.
Args:
quantum_instance: The quantum instance used to run this algorithm.
Expand Down
26 changes: 18 additions & 8 deletions qiskit/algorithms/amplitude_estimators/fae.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,11 @@ class FasterAmplitudeEstimation(AmplitudeEstimator):

@deprecate_arg(
"quantum_instance",
additional_msg="Instead, use the ``sampler`` argument.",
since="0.22.0",
pending=True,
additional_msg=(
"Instead, use the ``sampler`` argument. See https://qisk.it/algo_migration for a "
"migration guide."
),
since="0.24.0",
)
def __init__(
self,
Expand All @@ -67,7 +69,7 @@ def __init__(
delta: The probability that the true value is outside of the final confidence interval.
maxiter: The number of iterations, the maximal power of Q is `2 ** (maxiter - 1)`.
rescale: Whether to rescale the problem passed to `estimate`.
quantum_instance: Pending deprecation\: The quantum instance or backend
quantum_instance: Deprecated: The quantum instance or backend
to run the circuits.
sampler: A sampler primitive to evaluate the circuits.
Expand Down Expand Up @@ -108,19 +110,27 @@ def sampler(self, sampler: BaseSampler) -> None:
self._sampler = sampler

@property
@deprecate_func(since="0.23.0", pending=True, is_property=True)
@deprecate_func(
since="0.24.0",
is_property=True,
additional_msg="See https://qisk.it/algo_migration for a migration guide.",
)
def quantum_instance(self) -> QuantumInstance | None:
"""Pending deprecation; Get the quantum instance.
"""Deprecated. Get the quantum instance.
Returns:
The quantum instance used to run this algorithm.
"""
return self._quantum_instance

@quantum_instance.setter
@deprecate_func(since="0.23.0", pending=True, is_property=True)
@deprecate_func(
since="0.24.0",
is_property=True,
additional_msg="See https://qisk.it/algo_migration for a migration guide.",
)
def quantum_instance(self, quantum_instance: QuantumInstance | Backend) -> None:
"""Pending deprecation; Set quantum instance.
"""Deprecated. Set quantum instance.
Args:
quantum_instance: The quantum instance used to run this algorithm.
Expand Down
26 changes: 18 additions & 8 deletions qiskit/algorithms/amplitude_estimators/iae.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,11 @@ class IterativeAmplitudeEstimation(AmplitudeEstimator):

@deprecate_arg(
"quantum_instance",
additional_msg="Instead, use the ``sampler`` argument.",
since="0.22.0",
pending=True,
additional_msg=(
"Instead, use the ``sampler`` argument. See https://qisk.it/algo_migration for a "
"migration guide."
),
since="0.24.0",
)
def __init__(
self,
Expand All @@ -77,7 +79,7 @@ def __init__(
each iteration, can be 'chernoff' for the Chernoff intervals or 'beta' for the
Clopper-Pearson intervals (default)
min_ratio: Minimal q-ratio (:math:`K_{i+1} / K_i`) for FindNextK
quantum_instance: Pending deprecation\: Quantum Instance or Backend
quantum_instance: Deprecated: Quantum Instance or Backend
sampler: A sampler primitive to evaluate the circuits.
Raises:
Expand Down Expand Up @@ -131,19 +133,27 @@ def sampler(self, sampler: BaseSampler) -> None:
self._sampler = sampler

@property
@deprecate_func(since="0.23.0", pending=True, is_property=True)
@deprecate_func(
since="0.24.0",
is_property=True,
additional_msg="See https://qisk.it/algo_migration for a migration guide.",
)
def quantum_instance(self) -> QuantumInstance | None:
"""Pending deprecation; Get the quantum instance.
"""Deprecated. Get the quantum instance.
Returns:
The quantum instance used to run this algorithm.
"""
return self._quantum_instance

@quantum_instance.setter
@deprecate_func(since="0.23.0", pending=True, is_property=True)
@deprecate_func(
since="0.24.0",
is_property=True,
additional_msg="See https://qisk.it/algo_migration for a migration guide.",
)
def quantum_instance(self, quantum_instance: QuantumInstance | Backend) -> None:
"""Pending deprecation; Set quantum instance.
"""Deprecated. Set quantum instance.
Args:
quantum_instance: The quantum instance used to run this algorithm.
Expand Down
26 changes: 18 additions & 8 deletions qiskit/algorithms/amplitude_estimators/mlae.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,11 @@ class in named ``MaximumLikelihoodAmplitudeEstimation``.

@deprecate_arg(
"quantum_instance",
additional_msg="Instead, use the ``sampler`` argument.",
since="0.22.0",
pending=True,
additional_msg=(
"Instead, use the ``sampler`` argument. See https://qisk.it/algo_migration for a "
"migration guide."
),
since="0.24.0",
)
def __init__(
self,
Expand All @@ -77,7 +79,7 @@ def __init__(
according to ``evaluation_schedule``. The minimizer takes a function as first
argument and a list of (float, float) tuples (as bounds) as second argument and
returns a single float which is the found minimum.
quantum_instance: Pending deprecation\: Quantum Instance or Backend
quantum_instance: Deprecated: Quantum Instance or Backend
sampler: A sampler primitive to evaluate the circuits.
Raises:
Expand Down Expand Up @@ -135,19 +137,27 @@ def sampler(self, sampler: BaseSampler) -> None:
self._sampler = sampler

@property
@deprecate_func(since="0.23.0", pending=True, is_property=True)
@deprecate_func(
since="0.24.0",
is_property=True,
additional_msg="See https://qisk.it/algo_migration for a migration guide.",
)
def quantum_instance(self) -> QuantumInstance | None:
"""Pending deprecation; Get the quantum instance.
"""Deprecated. Get the quantum instance.
Returns:
The quantum instance used to run this algorithm.
"""
return self._quantum_instance

@quantum_instance.setter
@deprecate_func(since="0.23.0", pending=True, is_property=True)
@deprecate_func(
since="0.24.0",
is_property=True,
additional_msg="See https://qisk.it/algo_migration for a migration guide.",
)
def quantum_instance(self, quantum_instance: QuantumInstance | Backend) -> None:
"""Pending deprecation; Set quantum instance.
"""Deprecated. Set quantum instance.
Args:
quantum_instance: The quantum instance used to run this algorithm.
Expand Down
8 changes: 4 additions & 4 deletions qiskit/algorithms/aux_ops_evaluator.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@
@deprecate_func(
additional_msg=(
"Instead, use the function "
"``qiskit.algorithms.observables_evaluator.estimate_observables``."
"``qiskit.algorithms.observables_evaluator.estimate_observables``. See "
"https://qisk.it/algo_migration for a migration guide."
),
since="0.23.0",
pending=True,
since="0.24.0",
)
def eval_observables(
quantum_instance: QuantumInstance | Backend,
Expand All @@ -47,7 +47,7 @@ def eval_observables(
threshold: float = 1e-12,
) -> ListOrDict[tuple[complex, complex]]:
"""
Pending deprecation: Accepts a list or a dictionary of operators and calculates
Deprecated: Accepts a list or a dictionary of operators and calculates
their expectation values - means
and standard deviations. They are calculated with respect to a quantum state provided. A user
can optionally provide a threshold value which filters mean values falling below the threshold.
Expand Down
18 changes: 10 additions & 8 deletions qiskit/algorithms/eigen_solvers/eigen_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@


class Eigensolver(ABC):
"""Pending deprecation: Eigensolver Interface.
"""Deprecated: Eigensolver Interface.
The Eigensolver interface has been superseded by the
:class:`qiskit.algorithms.eigensolvers.Eigensolver` interface.
Expand All @@ -36,9 +36,11 @@ class Eigensolver(ABC):
"""

@deprecate_func(
additional_msg="Instead, use the interface ``qiskit.algorithms.eigensolvers.Eigensolver``",
since="0.23.0",
pending=True,
additional_msg=(
"Instead, use the interface ``qiskit.algorithms.eigensolvers.Eigensolver``. See "
"https://qisk.it/algo_migration for a migration guide."
),
since="0.24.0",
)
def __init__(self) -> None:
pass
Expand Down Expand Up @@ -76,7 +78,7 @@ def supports_aux_operators(cls) -> bool:


class EigensolverResult(AlgorithmResult):
"""Pending deprecation: Eigensolver Result.
"""Deprecated: Eigensolver Result.
The EigensolverResult class has been superseded by the
:class:`qiskit.algorithms.eigensolvers.EigensolverResult` class.
Expand All @@ -87,10 +89,10 @@ class EigensolverResult(AlgorithmResult):

@deprecate_func(
additional_msg=(
"Instead, use the class ``qiskit.algorithms.eigensolvers.EigensolverResult``."
"Instead, use the class ``qiskit.algorithms.eigensolvers.EigensolverResult``. "
"See https://qisk.it/algo_migration for a migration guide."
),
since="0.23.0",
pending=True,
since="0.24.0",
)
def __init__(self) -> None:
super().__init__()
Expand Down
8 changes: 4 additions & 4 deletions qiskit/algorithms/eigen_solvers/numpy_eigen_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

class NumPyEigensolver(Eigensolver):
r"""
Pending deprecation: NumPy Eigensolver algorithm.
Deprecated: NumPy Eigensolver algorithm.
The NumPyEigensolver class has been superseded by the
:class:`qiskit.algorithms.eigensolvers.NumPyEigensolver` class.
Expand All @@ -50,10 +50,10 @@ class NumPyEigensolver(Eigensolver):

@deprecate_func(
additional_msg=(
"Instead, use the class ``qiskit.algorithms.eigensolvers.NumPyEigensolver``."
"Instead, use the class ``qiskit.algorithms.eigensolvers.NumPyEigensolver``. "
"See https://qisk.it/algo_migration for a migration guide."
),
since="0.23.0",
pending=True,
since="0.24.0",
)
def __init__(
self,
Expand Down
Loading

0 comments on commit 3ebef17

Please sign in to comment.