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 util files and folders #9875

Merged
merged 1 commit into from
Mar 30, 2023
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
38 changes: 15 additions & 23 deletions qiskit/execute_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@
"""
import logging
from time import time
import warnings

from qiskit.compiler import transpile, schedule
from qiskit.providers.backend import Backend
from qiskit.pulse import Schedule, ScheduleBlock
from qiskit.exceptions import QiskitError
from qiskit.utils.deprecation import deprecate_arg

logger = logging.getLogger(__name__)

Expand All @@ -35,6 +36,16 @@ def _log_submission_time(start_time, end_time):
logger.info(log_msg)


@deprecate_arg(
"max_credits",
since="0.20.0",
additional_msg=(
"This argument has no effect on modern IBM Quantum systems, and no alternative is"
"necessary."
),
)
@deprecate_arg("qobj_id", since="0.21.0", additional_msg="This argument has no effect anymore.")
@deprecate_arg("qobj_header", since="0.21.0", additional_msg="This argument has no effect anymore.")
def execute(
experiments,
backend,
Expand Down Expand Up @@ -280,6 +291,9 @@ def execute(

job = execute(qc, backend, shots=4321)
"""
del qobj_id
del qobj_header
del max_credits
if isinstance(experiments, (Schedule, ScheduleBlock)) or (
isinstance(experiments, list) and isinstance(experiments[0], (Schedule, ScheduleBlock))
):
Expand Down Expand Up @@ -318,28 +332,6 @@ def execute(
meas_map=meas_map,
method=scheduling_method,
)
if max_credits is not None:
warnings.warn(
"The `max_credits` parameter is deprecated as of Qiskit Terra 0.20.0, "
"and will be removed in a future release. This parameter has no effect on "
"modern IBM Quantum systems, and no alternative is necessary.",
DeprecationWarning,
stacklevel=2,
)

if qobj_id is not None:
warnings.warn(
"The qobj_id argument is deprecated as of the Qiskit Terra 0.21.0, "
"and will be remvoed in a future release. This argument has no effect and "
"is not used by any backends."
)

if qobj_header is not None:
warnings.warn(
"The qobj_header argument is deprecated as of the Qiskit Terra 0.21.0, "
"and will be remvoed in a future release. This argument has no effect and "
"is not used by any backends."
)

if isinstance(backend, Backend):
start_time = time()
Expand Down
13 changes: 4 additions & 9 deletions qiskit/opflow/gradients/derivative_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@

"""DerivativeBase Class"""

import warnings
from abc import abstractmethod
from typing import Callable, Iterable, List, Optional, Tuple, Union

import numpy as np
from qiskit.utils.deprecation import deprecate_func
from qiskit.utils.quantum_instance import QuantumInstance
from qiskit.circuit import ParameterExpression, ParameterVector
from qiskit.providers import Backend
Expand Down Expand Up @@ -128,6 +128,9 @@ def gradient_fn(p_values):
return gradient_fn

@staticmethod
@deprecate_func(
since="0.18.0", additional_msg="Instead, use the ParameterExpression.gradient method."
)
def parameter_expression_grad(
param_expr: ParameterExpression, param: ParameterExpression
) -> Union[ParameterExpression, float]:
Expand All @@ -140,14 +143,6 @@ def parameter_expression_grad(
Returns:
ParameterExpression representing the gradient of param_expr w.r.t. param
"""
warnings.warn(
"The DerivativeBase.parameter_expression_grad method is deprecated as of "
"Qiskit Terra 0.18.0 and will be removed no earlier than 3 months after "
"the release date. Use the ParameterExpression.gradient method instead for "
"a direct replacement.",
DeprecationWarning,
stacklevel=2,
)
return _coeff_derivative(param_expr, param)

@classmethod
Expand Down
29 changes: 16 additions & 13 deletions qiskit/synthesis/evolution/suzuki_trotter.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@

from typing import Callable, Optional, Union

import warnings
import numpy as np

from qiskit.circuit.quantumcircuit import QuantumCircuit
from qiskit.quantum_info.operators import SparsePauliOp, Pauli
from qiskit.utils.deprecation import deprecate_arg

from .product_formula import ProductFormula

Expand Down Expand Up @@ -51,6 +51,17 @@ class SuzukiTrotter(ProductFormula):
`arXiv:math-ph/0506007 <https://arxiv.org/pdf/math-ph/0506007.pdf>`_
"""

@deprecate_arg(
"order",
deprecation_description=(
"Setting `order` to an odd number in the constructor of SuzukiTrotter"
),
additional_msg=(
"Suzuki product formulae are symmetric and therefore only defined for even orders."
),
since="0.20.0",
predicate=lambda order: order % 2 == 1,
)
def __init__(
self,
order: int = 2,
Expand All @@ -73,18 +84,10 @@ def __init__(
Pauli string. Per default, a single Pauli evolution is decomopsed in a CX chain
and a single qubit Z rotation.
"""
if order % 2 == 1:
warnings.warn(
"SuzukiTrotter for odd orders is deprecated as of 0.20.0, and will be "
"removed no earlier than 3 months after that release date. Suzuki "
"product formulae are symmetric and therefore only defined for even"
"orders.",
DeprecationWarning,
stacklevel=2,
)
# TODO replace deprecation warning by the following error and add unit test for odd
# raise ValueError("Suzuki product formulae are symmetric and therefore only defined "
# "for even orders.")
# TODO replace deprecation warning by the following error and add unit test for odd
# if order % 2 == 1:
# raise ValueError("Suzuki product formulae are symmetric and therefore only defined "
# "for even orders.")
super().__init__(order, reps, insert_barriers, cx_structure, atomic_evolution)

def synthesize(self, evolution):
Expand Down
6 changes: 2 additions & 4 deletions qiskit/test/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
import sys
from typing import Union, Callable, Type, Iterable
import unittest
from warnings import warn

from qiskit.utils import wrap_method
from qiskit.utils.deprecation import deprecate_func
from .testing_options import get_test_options

HAS_NET_CONNECTION = None
Expand Down Expand Up @@ -141,11 +141,9 @@ def _get_credentials():
)


@deprecate_func(additional_msg="Instead, use ``online_test``", since="0.17.0")
def requires_qe_access(func):
"""Deprecated in favor of `online_test`"""
warn(
"`requires_qe_access` is going to be replaced in favor of `online_test`", DeprecationWarning
)

@functools.wraps(func)
def _wrapper(self, *args, **kwargs):
Expand Down
18 changes: 9 additions & 9 deletions qiskit/utils/quantum_instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
_get_backend_provider,
_get_backend_interface_version,
)
from qiskit.utils.deprecation import deprecate_arg
from qiskit.utils.mitigation import (
CompleteMeasFitter,
TensoredMeasFitter,
Expand Down Expand Up @@ -143,6 +144,14 @@ class QuantumInstance:
"statevector_hpc_gate_opt",
] + _BACKEND_OPTIONS_QASM_ONLY

@deprecate_arg(
"max_credits",
since="0.20.0",
additional_msg=(
"This parameter has no effect on modern IBM Quantum systems, and no "
"alternative is necessary."
),
)
def __init__(
self,
backend,
Expand Down Expand Up @@ -265,15 +274,6 @@ def __init__(
# pylint: disable=cyclic-import
from qiskit.assembler.run_config import RunConfig

if max_credits is not None:
warnings.warn(
"The `max_credits` parameter is deprecated as of Qiskit Terra 0.20.0, "
"and will be removed in a future release. This parameter has no effect on "
"modern IBM Quantum systems, and no alternative is necessary.",
DeprecationWarning,
stacklevel=2,
)

run_config = RunConfig(shots=shots, max_credits=max_credits)
if seed_simulator is not None:
run_config.seed_simulator = seed_simulator
Expand Down