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 qobj and qpy #9870

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
11 changes: 3 additions & 8 deletions qiskit/qobj/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@
PulseLibraryItem
"""

import warnings

from qiskit.qobj.common import QobjExperimentHeader
from qiskit.qobj.common import QobjHeader

Expand All @@ -77,16 +75,13 @@
from qiskit.qobj.qasm_qobj import QasmQobjConfig
from qiskit.qobj.qasm_qobj import QasmQobjExperimentConfig

from qiskit.utils.deprecation import deprecate_func


class Qobj(QasmQobj):
"""A backwards compat alias for QasmQobj."""

@deprecate_func(additional_msg="Instead, use QasmQobj or PulseQobj", since="0.19.0")
def __init__(self, qobj_id=None, config=None, experiments=None, header=None):
"""Initialize a Qobj object."""
warnings.warn(
"qiskit.qobj.Qobj is deprecated use either QasmQobj or "
"PulseQobj depending on your application instead.",
DeprecationWarning,
stacklevel=2,
)
super().__init__(qobj_id=qobj_id, config=config, experiments=experiments, header=header)
74 changes: 37 additions & 37 deletions qiskit/qobj/converters/pulse_instruction.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
from qiskit.pulse.schedule import Schedule
from qiskit.qobj import QobjMeasurementOption, PulseLibraryItem, PulseQobjInstruction
from qiskit.qobj.utils import MeasLevel
from qiskit.utils.deprecation import deprecate_function
from qiskit.utils.deprecation import deprecate_func

if sys.version_info >= (3, 8):
from functools import singledispatchmethod
Expand Down Expand Up @@ -506,64 +506,64 @@ def _convert_bundled_acquire(

return self._qobj_model(**command_dict)

@deprecate_function(
"'convert_acquire' has been deprecated. Instead, call converter instance directly.",
@deprecate_func(
additional_msg="Instead, call converter instance directory.",
since="0.23.0",
)
def convert_acquire(self, shift, instruction):
return self._convert_instruction(instruction, shift)

@deprecate_function(
"'convert_bundled_acquires' has been deprecated. Instead, call converter instance directly.",
@deprecate_func(
additional_msg="Instead, call converter instance directory.",
since="0.23.0",
)
def convert_bundled_acquires(self, shift, instructions_):
return self._convert_bundled_acquire(instructions_, shift)

@deprecate_function(
"'convert_set_frequency' has been deprecated. Instead, call converter instance directly.",
@deprecate_func(
additional_msg="Instead, call converter instance directory.",
since="0.23.0",
)
def convert_set_frequency(self, shift, instruction):
return self._convert_instruction(instruction, shift)

@deprecate_function(
"'convert_shift_frequency' has been deprecated. Instead, call converter instance directly.",
@deprecate_func(
additional_msg="Instead, call converter instance directory.",
since="0.23.0",
)
def convert_shift_frequency(self, shift, instruction):
return self._convert_instruction(instruction, shift)

@deprecate_function(
"'convert_set_phase' has been deprecated. Instead, call converter instance directly.",
@deprecate_func(
additional_msg="Instead, call converter instance directory.",
since="0.23.0",
)
def convert_set_phase(self, shift, instruction):
return self._convert_instruction(instruction, shift)

@deprecate_function(
"'convert_shift_phase' has been deprecated. Instead, call converter instance directly.",
@deprecate_func(
additional_msg="Instead, call converter instance directory.",
since="0.23.0",
)
def convert_shift_phase(self, shift, instruction):
return self._convert_instruction(instruction, shift)

@deprecate_function(
"'convert_delay' has been deprecated. Instead, call converter instance directly.",
@deprecate_func(
additional_msg="Instead, call converter instance directory.",
since="0.23.0",
)
def convert_delay(self, shift, instruction):
return self._convert_instruction(instruction, shift)

@deprecate_function(
"'convert_play' has been deprecated. Instead, call converter instance directly.",
@deprecate_func(
additional_msg="Instead, call converter instance directory.",
since="0.23.0",
)
def convert_play(self, shift, instruction):
return self._convert_instruction(instruction, shift)

@deprecate_function(
"'convert_snapshot' has been deprecated. Instead, call converter instance directly.",
@deprecate_func(
additional_msg="Instead, call converter instance directory.",
since="0.23.0",
)
def convert_snapshot(self, shift, instruction):
Expand Down Expand Up @@ -959,8 +959,8 @@ def _convert_generic(
"in Qiskit namespace. This instruction cannot be deserialized."
)

@deprecate_function(
"'convert_acquire' has been deprecated. Instead, call converter instance directly.",
@deprecate_func(
additional_msg="Instead, call converter instance directory.",
since="0.23.0",
)
def convert_acquire(self, instruction):
Expand All @@ -970,8 +970,8 @@ def convert_acquire(self, instruction):
schedule.insert(t0, inst, inplace=True)
return schedule

@deprecate_function(
"'convert_set_phase' has been deprecated. Instead, call converter instance directly.",
@deprecate_func(
additional_msg="Instead, call converter instance directory.",
since="0.23.0",
)
def convert_set_phase(self, instruction):
Expand All @@ -981,8 +981,8 @@ def convert_set_phase(self, instruction):
schedule.insert(t0, inst, inplace=True)
return schedule

@deprecate_function(
"'convert_shift_phase' has been deprecated. Instead, call converter instance directly.",
@deprecate_func(
additional_msg="Instead, call converter instance directory.",
since="0.23.0",
)
def convert_shift_phase(self, instruction):
Expand All @@ -992,8 +992,8 @@ def convert_shift_phase(self, instruction):
schedule.insert(t0, inst, inplace=True)
return schedule

@deprecate_function(
"'convert_set_frequency' has been deprecated. Instead, call converter instance directly.",
@deprecate_func(
additional_msg="Instead, call converter instance directory.",
since="0.23.0",
)
def convert_set_frequency(self, instruction):
Expand All @@ -1003,8 +1003,8 @@ def convert_set_frequency(self, instruction):
schedule.insert(t0, inst, inplace=True)
return schedule

@deprecate_function(
"'convert_shift_frequency' has been deprecated. Instead, call converter instance directly.",
@deprecate_func(
additional_msg="Instead, call converter instance directory.",
since="0.23.0",
)
def convert_shift_frequency(self, instruction):
Expand All @@ -1014,8 +1014,8 @@ def convert_shift_frequency(self, instruction):
schedule.insert(t0, inst, inplace=True)
return schedule

@deprecate_function(
"'convert_delay' has been deprecated. Instead, call converter instance directly.",
@deprecate_func(
additional_msg="Instead, call converter instance directory.",
since="0.23.0",
)
def convert_delay(self, instruction):
Expand All @@ -1025,16 +1025,16 @@ def convert_delay(self, instruction):
schedule.insert(t0, inst, inplace=True)
return schedule

@deprecate_function(
"'bind_pulse' has been deprecated. Instantiate the class with pulse library.",
@deprecate_func(
additional_msg="Instead, call converter instance directory.",
since="0.23.0",
)
def bind_pulse(self, pulse):
if pulse.name not in self._pulse_library:
self._pulse_library[pulse.name] = pulse.samples

@deprecate_function(
"'convert_parametric' has been deprecated. Instead, call converter instance directly.",
@deprecate_func(
additional_msg="Instead, call converter instance directory.",
since="0.23.0",
)
def convert_parametric(self, instruction):
Expand All @@ -1044,8 +1044,8 @@ def convert_parametric(self, instruction):
schedule.insert(t0, inst, inplace=True)
return schedule

@deprecate_function(
"'convert_snapshot' has been deprecated. Instead, call converter instance directly.",
@deprecate_func(
additional_msg="Instead, call converter instance directory.",
since="0.23.0",
)
def convert_snapshot(self, instruction):
Expand Down
18 changes: 10 additions & 8 deletions qiskit/qobj/pulse_qobj.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@
import copy
import pprint
from typing import Union, List
import warnings

import numpy
from qiskit.qobj.common import QobjDictField
from qiskit.qobj.common import QobjHeader
from qiskit.qobj.common import QobjExperimentHeader
from qiskit.utils.deprecation import deprecate_arg


class QobjMeasurementOption:
Expand Down Expand Up @@ -282,6 +283,14 @@ def _to_complex(value: Union[List[float], complex]) -> complex:
class PulseQobjConfig(QobjDictField):
"""A configuration for a Pulse Qobj."""

@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."
),
)
def __init__(
self,
meas_level,
Expand Down Expand Up @@ -344,13 +353,6 @@ def __init__(

if max_credits is not None:
self.max_credits = int(max_credits)
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 seed_simulator is not None:
self.seed_simulator = int(seed_simulator)
Expand Down
18 changes: 10 additions & 8 deletions qiskit/qobj/qasm_qobj.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
import copy
import pprint
from types import SimpleNamespace
import warnings
from qiskit.circuit.parameterexpression import ParameterExpression
from qiskit.qobj.pulse_qobj import PulseQobjInstruction, PulseLibraryItem
from qiskit.qobj.common import QobjDictField, QobjHeader
from qiskit.utils.deprecation import deprecate_arg


class QasmQobjInstruction:
Expand Down Expand Up @@ -279,6 +279,14 @@ def __eq__(self, other):
class QasmQobjConfig(SimpleNamespace):
"""A configuration for a QASM Qobj."""

@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."
),
)
def __init__(
self,
shots=None,
Expand Down Expand Up @@ -328,13 +336,7 @@ def __init__(

if max_credits is not None:
self.max_credits = int(max_credits)
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 seed_simulator is not None:
self.seed_simulator = int(seed_simulator)

Expand Down
7 changes: 2 additions & 5 deletions qiskit/qpy/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from qiskit.qpy import formats, common, binary_io, type_keys
from qiskit.qpy.exceptions import QpyError
from qiskit.version import __version__
from qiskit.utils.deprecation import deprecate_arguments
from qiskit.utils.deprecation import deprecate_arg


# pylint: disable=invalid-name
Expand Down Expand Up @@ -72,10 +72,7 @@
VERSION_PATTERN_REGEX = re.compile(VERSION_PATTERN, re.VERBOSE | re.IGNORECASE)


@deprecate_arguments(
{"circuits": "programs"},
since="0.21.0",
)
@deprecate_arg("circuits", new_alias="programs", since="0.21.0")
def dump(
programs: Union[List[QPY_SUPPORTED_TYPES], QPY_SUPPORTED_TYPES],
file_obj: BinaryIO,
Expand Down