From b13979bf36a82b78b89ea7887511c0bd1dce0bc7 Mon Sep 17 00:00:00 2001 From: Eli Arbel Date: Tue, 17 Sep 2024 12:51:09 +0300 Subject: [PATCH 01/23] Deprecate classes, a couple functions & fix tests --- qiskit/pulse/builder.py | 4 ++ qiskit/pulse/calibration_entries.py | 4 ++ qiskit/pulse/channels.py | 3 ++ qiskit/pulse/configuration.py | 5 +++ qiskit/pulse/deprecate.py | 44 +++++++++++++++++++ qiskit/pulse/exceptions.py | 2 + qiskit/pulse/instruction_schedule_map.py | 2 + qiskit/pulse/instructions/acquire.py | 2 + qiskit/pulse/instructions/delay.py | 2 + qiskit/pulse/instructions/directives.py | 3 ++ qiskit/pulse/instructions/frequency.py | 3 ++ qiskit/pulse/instructions/instruction.py | 2 + qiskit/pulse/instructions/phase.py | 3 ++ qiskit/pulse/instructions/play.py | 2 + qiskit/pulse/instructions/reference.py | 2 + qiskit/pulse/instructions/snapshot.py | 2 + qiskit/pulse/library/symbolic_pulses.py | 4 ++ qiskit/pulse/library/waveform.py | 2 + qiskit/pulse/parameter_manager.py | 4 ++ qiskit/pulse/parser.py | 2 + qiskit/pulse/schedule.py | 3 ++ qiskit/pulse/transforms/alignments.py | 6 +++ test/python/pulse/test_block.py | 9 ++++ test/python/pulse/test_builder.py | 10 +++++ test/python/pulse/test_builder_v2.py | 7 +++ test/python/pulse/test_calibration_entries.py | 4 ++ test/python/pulse/test_channels.py | 8 ++++ .../pulse/test_experiment_configurations.py | 5 +++ .../pulse/test_instruction_schedule_map.py | 2 + test/python/pulse/test_instructions.py | 12 +++++ test/python/pulse/test_macros.py | 5 +++ test/python/pulse/test_parameter_manager.py | 7 +++ test/python/pulse/test_parser.py | 2 + test/python/pulse/test_pulse_lib.py | 5 +++ test/python/pulse/test_reference.py | 4 ++ test/python/pulse/test_samplers.py | 2 + test/python/pulse/test_schedule.py | 6 +++ test/python/pulse/test_transforms.py | 17 +++++++ 38 files changed, 211 insertions(+) create mode 100644 qiskit/pulse/deprecate.py diff --git a/qiskit/pulse/builder.py b/qiskit/pulse/builder.py index 8767e8c4e93a..57d89fa45c73 100644 --- a/qiskit/pulse/builder.py +++ b/qiskit/pulse/builder.py @@ -437,6 +437,7 @@ from qiskit.pulse.instructions import directives from qiskit.pulse.schedule import Schedule, ScheduleBlock from qiskit.pulse.transforms.alignments import AlignmentKind +from qiskit.pulse.deprecate import deprecate_pulse_func if sys.version_info >= (3, 12): @@ -477,6 +478,7 @@ class _PulseBuilder: "sequential": transforms.AlignSequential(), } + @deprecate_pulse_func def __init__( self, backend=None, @@ -774,6 +776,7 @@ def get_dt(self): return self.backend.configuration().dt +@deprecate_pulse_func def build( backend=None, schedule: ScheduleBlock | None = None, @@ -1504,6 +1507,7 @@ def delay(duration: int, channel: chans.Channel, name: str | None = None): append_instruction(instructions.Delay(duration, channel, name=name)) +@deprecate_pulse_func def play(pulse: library.Pulse | np.ndarray, channel: chans.PulseChannel, name: str | None = None): """Play a ``pulse`` on a ``channel``. diff --git a/qiskit/pulse/calibration_entries.py b/qiskit/pulse/calibration_entries.py index 8a5ba1b6e3d6..855f69cec14a 100644 --- a/qiskit/pulse/calibration_entries.py +++ b/qiskit/pulse/calibration_entries.py @@ -24,6 +24,7 @@ from qiskit.qobj.converters import QobjToInstructionConverter from qiskit.qobj.pulse_qobj import PulseQobjInstruction from qiskit.exceptions import QiskitError +from qiskit.pulse.deprecate import deprecate_pulse_func IncompletePulseQobj = object() @@ -122,6 +123,7 @@ class ScheduleDef(CalibrationEntry): """ + @deprecate_pulse_func def __init__(self, arguments: Sequence[str] | None = None): """Define an empty entry. @@ -238,6 +240,7 @@ class CallableDef(CalibrationEntry): """ + @deprecate_pulse_func def __init__(self): """Define an empty entry.""" self._definition = None @@ -300,6 +303,7 @@ class PulseQobjDef(ScheduleDef): """ + @deprecate_pulse_func def __init__( self, arguments: Sequence[str] | None = None, diff --git a/qiskit/pulse/channels.py b/qiskit/pulse/channels.py index c70aac38ba19..0d98775c62a4 100644 --- a/qiskit/pulse/channels.py +++ b/qiskit/pulse/channels.py @@ -58,6 +58,7 @@ from qiskit.circuit import Parameter from qiskit.circuit.parameterexpression import ParameterExpression from qiskit.pulse.exceptions import PulseError +from qiskit.pulse.deprecate import deprecate_pulse_func class Channel(metaclass=ABCMeta): @@ -90,6 +91,7 @@ def __new__(cls, *args, **kwargs): return super().__new__(cls) + @deprecate_pulse_func def __init__(self, index: int): """Channel class. @@ -206,6 +208,7 @@ class SnapshotChannel(ClassicalIOChannel): prefix = "s" + @deprecate_pulse_func def __init__(self): """Create new snapshot channel.""" super().__init__(0) diff --git a/qiskit/pulse/configuration.py b/qiskit/pulse/configuration.py index 1bfd1f13e2ee..2049da6cfd3d 100644 --- a/qiskit/pulse/configuration.py +++ b/qiskit/pulse/configuration.py @@ -18,6 +18,7 @@ from .channels import DriveChannel, MeasureChannel from .exceptions import PulseError +from qiskit.pulse.deprecate import deprecate_pulse_func def _assert_nested_dict_equal(a: dict, b: dict): @@ -44,6 +45,7 @@ class Kernel: into IQ points. """ + @deprecate_pulse_func def __init__(self, name: str | None = None, **params): """Create new kernel. @@ -70,6 +72,7 @@ class Discriminator: into 0/1 state results. """ + @deprecate_pulse_func def __init__(self, name: str | None = None, **params): """Create new discriminator. @@ -94,6 +97,7 @@ def __eq__(self, other): class LoRange: """Range of LO frequency.""" + @deprecate_pulse_func def __init__(self, lower_bound: float, upper_bound: float): self._lb = lower_bound self._ub = upper_bound @@ -142,6 +146,7 @@ def __eq__(self, other): class LoConfig: """Pulse channel LO frequency container.""" + @deprecate_pulse_func def __init__( self, channel_los: dict[DriveChannel | MeasureChannel, float] | None = None, diff --git a/qiskit/pulse/deprecate.py b/qiskit/pulse/deprecate.py new file mode 100644 index 000000000000..206634ae3dec --- /dev/null +++ b/qiskit/pulse/deprecate.py @@ -0,0 +1,44 @@ +# This code is part of Qiskit. +# +# (C) Copyright IBM 2020. +# +# This code is licensed under the Apache License, Version 2.0. You may +# obtain a copy of this license in the LICENSE.txt file in the root directory +# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0. +# +# Any modifications or derivative works of this code must retain this +# copyright notice, and modified files need to carry a notice indicating +# that they have been altered from the originals. + +""" +Deprecation functions for Qiskit Pulse +""" + +import warnings +from functools import wraps +from qiskit.utils.deprecation import deprecate_func + + +def deprecate_pulse_func(func): + """Deprecation message for functions and classes""" + return deprecate_func( + since="1.3", + removal_timeline="in Qiskit 2.0", + additional_msg="This is part of the entire Qiskit Pulse package deprecation. " + "The package will be moved to the Qiskit Dynamics repository: " + "https://github.com/qiskit-community/qiskit-dynamics/", + )(func) + + +def ignore_pulse_deprecation_warnings(func): + """Filter Pulse deprecation warnings in a decorated function""" + + @wraps(func) + def wrapper(*args, **kwargs): + with warnings.catch_warnings(): + warnings.filterwarnings( + "ignore", category=DeprecationWarning, message=".*Qiskit Pulse package" + ) + return func(*args, **kwargs) + + return wrapper diff --git a/qiskit/pulse/exceptions.py b/qiskit/pulse/exceptions.py index 21bda97ee1b9..5fc3793398ea 100644 --- a/qiskit/pulse/exceptions.py +++ b/qiskit/pulse/exceptions.py @@ -12,11 +12,13 @@ """Exception for errors raised by the pulse module.""" from qiskit.exceptions import QiskitError +from qiskit.pulse.deprecate import deprecate_pulse_func class PulseError(QiskitError): """Errors raised by the pulse module.""" + @deprecate_pulse_func def __init__(self, *message): """Set the error message.""" super().__init__(*message) diff --git a/qiskit/pulse/instruction_schedule_map.py b/qiskit/pulse/instruction_schedule_map.py index afa71b6825a7..e46de27b3afd 100644 --- a/qiskit/pulse/instruction_schedule_map.py +++ b/qiskit/pulse/instruction_schedule_map.py @@ -46,6 +46,7 @@ ) from qiskit.pulse.exceptions import PulseError from qiskit.pulse.schedule import Schedule, ScheduleBlock +from qiskit.pulse.deprecate import deprecate_pulse_func class InstructionScheduleMap: @@ -62,6 +63,7 @@ class InstructionScheduleMap: These can usually be seen as gate calibrations. """ + @deprecate_pulse_func def __init__(self): """Initialize a circuit instruction to schedule mapper instance.""" # The processed and reformatted circuit instruction definitions diff --git a/qiskit/pulse/instructions/acquire.py b/qiskit/pulse/instructions/acquire.py index 98fbf460c1b3..263d14b0f102 100644 --- a/qiskit/pulse/instructions/acquire.py +++ b/qiskit/pulse/instructions/acquire.py @@ -19,6 +19,7 @@ from qiskit.pulse.configuration import Kernel, Discriminator from qiskit.pulse.exceptions import PulseError from qiskit.pulse.instructions.instruction import Instruction +from qiskit.pulse.deprecate import deprecate_pulse_func class Acquire(Instruction): @@ -38,6 +39,7 @@ class Acquire(Instruction): * the discriminator to classify kerneled IQ points. """ + @deprecate_pulse_func def __init__( self, duration: int | ParameterExpression, diff --git a/qiskit/pulse/instructions/delay.py b/qiskit/pulse/instructions/delay.py index 13f36d3b7d9b..c69115484623 100644 --- a/qiskit/pulse/instructions/delay.py +++ b/qiskit/pulse/instructions/delay.py @@ -16,6 +16,7 @@ from qiskit.circuit import ParameterExpression from qiskit.pulse.channels import Channel from qiskit.pulse.instructions.instruction import Instruction +from qiskit.pulse.deprecate import deprecate_pulse_func class Delay(Instruction): @@ -34,6 +35,7 @@ class Delay(Instruction): The ``channel`` will output no signal from time=0 up until time=10. """ + @deprecate_pulse_func def __init__( self, duration: int | ParameterExpression, diff --git a/qiskit/pulse/instructions/directives.py b/qiskit/pulse/instructions/directives.py index f1e7f9b24569..6b09b1e66373 100644 --- a/qiskit/pulse/instructions/directives.py +++ b/qiskit/pulse/instructions/directives.py @@ -18,6 +18,7 @@ from qiskit.pulse import channels as chans from qiskit.pulse.instructions import instruction from qiskit.pulse.exceptions import PulseError +from qiskit.pulse.deprecate import deprecate_pulse_func class Directive(instruction.Instruction, ABC): @@ -35,6 +36,7 @@ def duration(self) -> int: class RelativeBarrier(Directive): """Pulse ``RelativeBarrier`` directive.""" + @deprecate_pulse_func def __init__(self, *channels: chans.Channel, name: str | None = None): """Create a relative barrier directive. @@ -102,6 +104,7 @@ class TimeBlockade(Directive): user can insert another instruction without timing overlap. """ + @deprecate_pulse_func def __init__( self, duration: int, diff --git a/qiskit/pulse/instructions/frequency.py b/qiskit/pulse/instructions/frequency.py index a14e60ee1a32..de56222c42bb 100644 --- a/qiskit/pulse/instructions/frequency.py +++ b/qiskit/pulse/instructions/frequency.py @@ -19,6 +19,7 @@ from qiskit.pulse.channels import PulseChannel from qiskit.pulse.instructions.instruction import Instruction from qiskit.pulse.exceptions import PulseError +from qiskit.pulse.deprecate import deprecate_pulse_func class SetFrequency(Instruction): @@ -35,6 +36,7 @@ class SetFrequency(Instruction): The duration of SetFrequency is 0. """ + @deprecate_pulse_func def __init__( self, frequency: Union[float, ParameterExpression], @@ -85,6 +87,7 @@ def duration(self) -> int: class ShiftFrequency(Instruction): """Shift the channel frequency away from the current frequency.""" + @deprecate_pulse_func def __init__( self, frequency: Union[float, ParameterExpression], diff --git a/qiskit/pulse/instructions/instruction.py b/qiskit/pulse/instructions/instruction.py index 61ebe67777f8..a604a0af1e91 100644 --- a/qiskit/pulse/instructions/instruction.py +++ b/qiskit/pulse/instructions/instruction.py @@ -28,6 +28,7 @@ from qiskit.circuit import Parameter, ParameterExpression from qiskit.pulse.channels import Channel from qiskit.pulse.exceptions import PulseError +from qiskit.pulse.deprecate import deprecate_pulse_func # pylint: disable=bad-docstring-quotes @@ -38,6 +39,7 @@ class Instruction(ABC): channels. """ + @deprecate_pulse_func def __init__( self, operands: tuple, diff --git a/qiskit/pulse/instructions/phase.py b/qiskit/pulse/instructions/phase.py index 21f46dfb5f72..b1a889d40963 100644 --- a/qiskit/pulse/instructions/phase.py +++ b/qiskit/pulse/instructions/phase.py @@ -21,6 +21,7 @@ from qiskit.pulse.channels import PulseChannel from qiskit.pulse.instructions.instruction import Instruction from qiskit.pulse.exceptions import PulseError +from qiskit.pulse.deprecate import deprecate_pulse_func class ShiftPhase(Instruction): @@ -40,6 +41,7 @@ class ShiftPhase(Instruction): by using a ShiftPhase to update the frame tracking the qubit state. """ + @deprecate_pulse_func def __init__( self, phase: Union[complex, ParameterExpression], @@ -101,6 +103,7 @@ class SetPhase(Instruction): The ``SetPhase`` instruction sets :math:`\phi` to the instruction's ``phase`` operand. """ + @deprecate_pulse_func def __init__( self, phase: Union[complex, ParameterExpression], diff --git a/qiskit/pulse/instructions/play.py b/qiskit/pulse/instructions/play.py index 1f42b8e3a08d..3d2edca0cacb 100644 --- a/qiskit/pulse/instructions/play.py +++ b/qiskit/pulse/instructions/play.py @@ -21,6 +21,7 @@ from qiskit.pulse.exceptions import PulseError from qiskit.pulse.instructions.instruction import Instruction from qiskit.pulse.library.pulse import Pulse +from qiskit.pulse.deprecate import deprecate_pulse_func class Play(Instruction): @@ -32,6 +33,7 @@ class Play(Instruction): cycle time, dt, of the backend. """ + @deprecate_pulse_func def __init__(self, pulse: Pulse, channel: PulseChannel, name: str | None = None): """Create a new pulse instruction. diff --git a/qiskit/pulse/instructions/reference.py b/qiskit/pulse/instructions/reference.py index cf3e01f8ea6e..3863b8044682 100644 --- a/qiskit/pulse/instructions/reference.py +++ b/qiskit/pulse/instructions/reference.py @@ -17,6 +17,7 @@ from qiskit.pulse.channels import Channel from qiskit.pulse.exceptions import PulseError, UnassignedReferenceError from qiskit.pulse.instructions import instruction +from qiskit.pulse.deprecate import deprecate_pulse_func class Reference(instruction.Instruction): @@ -40,6 +41,7 @@ class Reference(instruction.Instruction): # Delimiter for tuple keys. key_delimiter = "," + @deprecate_pulse_func def __init__(self, name: str, *extra_keys: str): """Create new reference. diff --git a/qiskit/pulse/instructions/snapshot.py b/qiskit/pulse/instructions/snapshot.py index b78858b5d2c0..4edc1e7d170a 100644 --- a/qiskit/pulse/instructions/snapshot.py +++ b/qiskit/pulse/instructions/snapshot.py @@ -18,11 +18,13 @@ from qiskit.pulse.channels import SnapshotChannel from qiskit.pulse.exceptions import PulseError from qiskit.pulse.instructions.instruction import Instruction +from qiskit.pulse.deprecate import deprecate_pulse_func class Snapshot(Instruction): """An instruction targeted for simulators, to capture a moment in the simulation.""" + @deprecate_pulse_func def __init__(self, label: str, snapshot_type: str = "statevector", name: Optional[str] = None): """Create new snapshot. diff --git a/qiskit/pulse/library/symbolic_pulses.py b/qiskit/pulse/library/symbolic_pulses.py index b7ba658da1be..19e4e3715213 100644 --- a/qiskit/pulse/library/symbolic_pulses.py +++ b/qiskit/pulse/library/symbolic_pulses.py @@ -31,6 +31,7 @@ from qiskit.pulse.exceptions import PulseError from qiskit.pulse.library.pulse import Pulse from qiskit.pulse.library.waveform import Waveform +from qiskit.pulse.deprecate import deprecate_pulse_func def _lifted_gaussian( @@ -150,6 +151,7 @@ class LambdifiedExpression: _`Descriptor`: https://docs.python.org/3/reference/datamodel.html#descriptors """ + @deprecate_pulse_func def __init__(self, attribute: str): """Create new descriptor. @@ -403,6 +405,7 @@ def Sawtooth(duration, amp, freq, name): _constraints_lam = LambdifiedExpression("_constraints") _valid_amp_conditions_lam = LambdifiedExpression("_valid_amp_conditions") + @deprecate_pulse_func def __init__( self, pulse_type: str, @@ -593,6 +596,7 @@ class ScalableSymbolicPulse(SymbolicPulse): :math:'\text{amp}\times\exp\left(i\times\text{angle}\right)' is compared. """ + @deprecate_pulse_func def __init__( self, pulse_type: str, diff --git a/qiskit/pulse/library/waveform.py b/qiskit/pulse/library/waveform.py index ad852f226ac2..ae625febaf74 100644 --- a/qiskit/pulse/library/waveform.py +++ b/qiskit/pulse/library/waveform.py @@ -18,6 +18,7 @@ from qiskit.pulse.exceptions import PulseError from qiskit.pulse.library.pulse import Pulse +from qiskit.pulse.deprecate import deprecate_pulse_func class Waveform(Pulse): @@ -25,6 +26,7 @@ class Waveform(Pulse): duration of the backend cycle-time, dt. """ + @deprecate_pulse_func def __init__( self, samples: np.ndarray | list[complex], diff --git a/qiskit/pulse/parameter_manager.py b/qiskit/pulse/parameter_manager.py index e5a4a1a1d2bd..426dd59a78a2 100644 --- a/qiskit/pulse/parameter_manager.py +++ b/qiskit/pulse/parameter_manager.py @@ -67,6 +67,7 @@ _validate_parameter_vector, _validate_parameter_value, ) +from qiskit.pulse.deprecate import deprecate_pulse_func class NodeVisitor: @@ -131,6 +132,7 @@ class ParameterSetter(NodeVisitor): and assign values to operands of nodes found. """ + @deprecate_pulse_func def __init__(self, param_map: dict[ParameterExpression, ParameterValueType]): self._param_map = param_map @@ -261,6 +263,7 @@ class ParameterGetter(NodeVisitor): and add parameters found to the array. """ + @deprecate_pulse_func def __init__(self): self.parameters = set() @@ -331,6 +334,7 @@ class ParameterManager: Instruction data and its location are not directly associated with this object. """ + @deprecate_pulse_func def __init__(self): """Create new parameter table for pulse programs.""" self._parameters = set() diff --git a/qiskit/pulse/parser.py b/qiskit/pulse/parser.py index e9cd4917a7ce..5a7f9abab10a 100644 --- a/qiskit/pulse/parser.py +++ b/qiskit/pulse/parser.py @@ -24,6 +24,7 @@ from qiskit.pulse.exceptions import PulseError from qiskit.circuit import ParameterExpression +from qiskit.pulse.deprecate import deprecate_pulse_func class PulseExpression(ast.NodeTransformer): @@ -63,6 +64,7 @@ class PulseExpression(ast.NodeTransformer): _unary_ops = {ast.UAdd: operator.pos, ast.USub: operator.neg} """Valid unary operations.""" + @deprecate_pulse_func def __init__(self, source: str | ast.Expression, partial_binding: bool = False): """Create new evaluator. diff --git a/qiskit/pulse/schedule.py b/qiskit/pulse/schedule.py index c89fe3b4e306..a56e80d925da 100644 --- a/qiskit/pulse/schedule.py +++ b/qiskit/pulse/schedule.py @@ -54,6 +54,7 @@ from qiskit.pulse.reference_manager import ReferenceManager from qiskit.utils.multiprocessing import is_main_process from qiskit.utils import deprecate_arg +from qiskit.pulse.deprecate import deprecate_pulse_func Interval = Tuple[int, int] @@ -120,6 +121,7 @@ class Schedule: # Counter to count instance number. instances_counter = itertools.count() + @deprecate_pulse_func def __init__( self, *schedules: "ScheduleComponent" | tuple[int, "ScheduleComponent"], @@ -986,6 +988,7 @@ class ScheduleBlock: # Counter to count instance number. instances_counter = itertools.count() + @deprecate_pulse_func def __init__( self, name: str | None = None, metadata: dict | None = None, alignment_context=None ): diff --git a/qiskit/pulse/transforms/alignments.py b/qiskit/pulse/transforms/alignments.py index 5e383972c255..846247b280e5 100644 --- a/qiskit/pulse/transforms/alignments.py +++ b/qiskit/pulse/transforms/alignments.py @@ -20,6 +20,7 @@ from qiskit.pulse.exceptions import PulseError from qiskit.pulse.schedule import Schedule, ScheduleComponent from qiskit.pulse.utils import instruction_duration_validation +from qiskit.pulse.deprecate import deprecate_pulse_func class AlignmentKind(abc.ABC): @@ -93,6 +94,7 @@ class AlignLeft(AlignmentKind): Instructions are placed at earliest available timeslots. """ + @deprecate_pulse_func def __init__(self): """Create new left-justified context.""" super().__init__(context_params=()) @@ -160,6 +162,7 @@ class AlignRight(AlignmentKind): Instructions are placed at latest available timeslots. """ + @deprecate_pulse_func def __init__(self): """Create new right-justified context.""" super().__init__(context_params=()) @@ -229,6 +232,7 @@ class AlignSequential(AlignmentKind): No buffer time is inserted in between instructions. """ + @deprecate_pulse_func def __init__(self): """Create new sequential context.""" super().__init__(context_params=()) @@ -263,6 +267,7 @@ class AlignEquispaced(AlignmentKind): This alignment is convenient to create dynamical decoupling sequences such as PDD. """ + @deprecate_pulse_func def __init__(self, duration: int | ParameterExpression): """Create new equispaced context. @@ -348,6 +353,7 @@ def udd10_pos(j): """ + @deprecate_pulse_func def __init__(self, duration: int | ParameterExpression, func: Callable): """Create new equispaced context. diff --git a/test/python/pulse/test_block.py b/test/python/pulse/test_block.py index c6a2c2384f64..cc3b286eaa2e 100644 --- a/test/python/pulse/test_block.py +++ b/test/python/pulse/test_block.py @@ -20,11 +20,13 @@ from qiskit.pulse.exceptions import PulseError from qiskit.providers.fake_provider import FakeOpenPulse2Q from test import QiskitTestCase # pylint: disable=wrong-import-order +from qiskit.pulse.deprecate import ignore_pulse_deprecation_warnings class BaseTestBlock(QiskitTestCase): """ScheduleBlock tests.""" + @ignore_pulse_deprecation_warnings def setUp(self): super().setUp() @@ -91,6 +93,7 @@ def test_sequential_alignment(self): self.assertScheduleEqual(block, ref_sched) + @ignore_pulse_deprecation_warnings def test_equispace_alignment(self): """Test equispace alignment context.""" block = pulse.ScheduleBlock(alignment_context=self.equispaced_context) @@ -150,6 +153,7 @@ class TestBlockOperation(BaseTestBlock): This operation should be tested in `test.python.pulse.test_block.TestTransformation`. """ + @ignore_pulse_deprecation_warnings def setUp(self): super().setUp() @@ -181,6 +185,7 @@ def test_append_an_instruction_to_empty_block_inplace(self): self.assertEqual(block.blocks[0], pulse.Play(self.test_waveform0, self.d0)) + @ignore_pulse_deprecation_warnings def test_append_a_block_to_empty_block(self): """Test append another ScheduleBlock to empty block.""" block = pulse.ScheduleBlock() @@ -379,6 +384,7 @@ class TestBlockEquality(BaseTestBlock): This should be tested for each transform. """ + @ignore_pulse_deprecation_warnings def test_different_channels(self): """Test equality is False if different channels.""" block1 = pulse.ScheduleBlock() @@ -614,6 +620,7 @@ def test_instruction_out_of_order_complex_not_equal(self): class TestParametrizedBlockOperation(BaseTestBlock): """Test fundamental operation with parametrization.""" + @ignore_pulse_deprecation_warnings def setUp(self): super().setUp() @@ -639,6 +646,7 @@ def test_report_parameter_assignment(self): self.assertTrue(block.is_parameterized()) self.assertTrue(block.is_schedulable()) + @ignore_pulse_deprecation_warnings def test_cannot_get_duration_if_not_assigned(self): """Test raise error when duration is not assigned.""" block = pulse.ScheduleBlock() @@ -722,6 +730,7 @@ def test_parametrized_context(self): class TestBlockFilter(BaseTestBlock): """Test ScheduleBlock filtering methods.""" + @ignore_pulse_deprecation_warnings def test_filter_channels(self): """Test filtering over channels.""" with pulse.build() as blk: diff --git a/test/python/pulse/test_builder.py b/test/python/pulse/test_builder.py index 72a6de11ae08..483b0727cce7 100644 --- a/test/python/pulse/test_builder.py +++ b/test/python/pulse/test_builder.py @@ -14,6 +14,7 @@ from math import pi import numpy as np +from qiskit.pulse.deprecate import ignore_pulse_deprecation_warnings from qiskit import circuit, compiler, pulse from qiskit.pulse import builder, exceptions, macros @@ -108,6 +109,7 @@ def test_default_alignment_sequential(self): self.assertScheduleEqual(schedule, reference) + @ignore_pulse_deprecation_warnings def test_default_alignment_alignmentkind_instance(self): """Test default AlignmentKind instance""" d0 = pulse.DriveChannel(0) @@ -155,6 +157,7 @@ def test_align_sequential(self): self.assertScheduleEqual(schedule, reference) + @ignore_pulse_deprecation_warnings def test_align_left(self): """Test the left alignment context.""" d0 = pulse.DriveChannel(0) @@ -268,6 +271,7 @@ def test_measure_channel(self): with pulse.build(self.backend): self.assertEqual(pulse.measure_channel(0), pulse.MeasureChannel(0)) + @ignore_pulse_deprecation_warnings def test_acquire_channel(self): """Text context builder acquire channel.""" with pulse.build(self.backend): @@ -344,6 +348,7 @@ def test_play_name_argument(self): self.assertEqual(schedule.instructions[0][1].name, "new_name") + @ignore_pulse_deprecation_warnings def test_acquire_memory_slot(self): """Test acquire instruction into memory slot.""" acquire0 = pulse.AcquireChannel(0) @@ -512,6 +517,7 @@ def test_barrier_with_align_left(self): self.assertScheduleEqual(schedule, reference) + @ignore_pulse_deprecation_warnings def test_barrier_on_qubits(self): """Test barrier directive on qubits.""" with pulse.build(self.backend) as schedule: @@ -541,6 +547,7 @@ def test_trivial_barrier(self): class TestUtilities(TestBuilder): """Test builder utilities.""" + @ignore_pulse_deprecation_warnings def test_active_backend(self): """Test getting active builder backend.""" with pulse.build(self.backend): @@ -702,6 +709,7 @@ def test_measure_all(self): self.assertScheduleEqual(schedule, reference) + @ignore_pulse_deprecation_warnings def test_delay_qubit(self): """Test delaying on a qubit macro.""" with pulse.build(self.backend) as schedule: @@ -752,6 +760,7 @@ def test_delay_qubits(self): class TestBuilderComposition(TestBuilder): """Test more sophisticated composite builder examples.""" + @ignore_pulse_deprecation_warnings def test_complex_build(self): """Test a general program build with nested contexts, circuits and macros.""" @@ -849,6 +858,7 @@ def get_sched(qubit_idx: [int], backend): class TestSubroutineCall(TestBuilder): """Test for calling subroutine.""" + @ignore_pulse_deprecation_warnings def test_call(self): """Test calling schedule instruction.""" d0 = pulse.DriveChannel(0) diff --git a/test/python/pulse/test_builder_v2.py b/test/python/pulse/test_builder_v2.py index 79d3ac5b6020..94a02d50941d 100644 --- a/test/python/pulse/test_builder_v2.py +++ b/test/python/pulse/test_builder_v2.py @@ -24,11 +24,13 @@ from test import QiskitTestCase # pylint: disable=wrong-import-order from ..legacy_cmaps import MUMBAI_CMAP +from qiskit.pulse.deprecate import ignore_pulse_deprecation_warnings class TestBuilderV2(QiskitTestCase): """Test the pulse builder context with backendV2.""" + @ignore_pulse_deprecation_warnings def setUp(self): super().setUp() self.backend = GenericBackendV2( @@ -46,6 +48,7 @@ def assertScheduleEqual(self, program, target): class TestContextsV2(TestBuilderV2): """Test builder contexts.""" + @ignore_pulse_deprecation_warnings def test_phase_compensated_frequency_offset(self): """Test that the phase offset context properly compensates for phase accumulation with backendV2.""" @@ -77,6 +80,7 @@ def test_measure_channel(self): with pulse.build(self.backend): self.assertEqual(pulse.measure_channel(0), pulse.MeasureChannel(0)) + @ignore_pulse_deprecation_warnings def test_acquire_channel(self): """Text context builder acquire channel.""" with pulse.build(self.backend): @@ -91,6 +95,7 @@ def test_control_channel(self): class TestDirectivesV2(TestBuilderV2): """Test builder directives.""" + @ignore_pulse_deprecation_warnings def test_barrier_on_qubits(self): """Test barrier directive on qubits with backendV2. A part of qubits map of Mumbai @@ -122,6 +127,7 @@ def test_barrier_on_qubits(self): class TestUtilitiesV2(TestBuilderV2): """Test builder utilities.""" + @ignore_pulse_deprecation_warnings def test_active_backend(self): """Test getting active builder backend.""" with pulse.build(self.backend): @@ -248,6 +254,7 @@ def test_measure_all(self): self.assertScheduleEqual(schedule, reference) + @ignore_pulse_deprecation_warnings def test_delay_qubit(self): """Test delaying on a qubit macro.""" with pulse.build(self.backend) as schedule: diff --git a/test/python/pulse/test_calibration_entries.py b/test/python/pulse/test_calibration_entries.py index cc31789ef683..52e054625f08 100644 --- a/test/python/pulse/test_calibration_entries.py +++ b/test/python/pulse/test_calibration_entries.py @@ -33,6 +33,7 @@ from qiskit.qobj.converters.pulse_instruction import QobjToInstructionConverter from qiskit.qobj.pulse_qobj import PulseLibraryItem, PulseQobjInstruction from test import QiskitTestCase # pylint: disable=wrong-import-order +from qiskit.pulse.deprecate import ignore_pulse_deprecation_warnings class TestSchedule(QiskitTestCase): @@ -58,6 +59,7 @@ def test_add_schedule(self): schedule_ref = program self.assertEqual(schedule_to_test, schedule_ref) + @ignore_pulse_deprecation_warnings def test_add_block(self): """Basic test pulse Schedule format.""" program = ScheduleBlock() @@ -184,6 +186,7 @@ def test_equality(self): class TestCallable(QiskitTestCase): """Test case for the CallableDef.""" + @ignore_pulse_deprecation_warnings def test_add_callable(self): """Basic test callable format.""" program = Schedule() @@ -288,6 +291,7 @@ def setUp(self): ] ) + @ignore_pulse_deprecation_warnings def test_add_qobj(self): """Basic test PulseQobj format.""" with self.assertWarns(DeprecationWarning): diff --git a/test/python/pulse/test_channels.py b/test/python/pulse/test_channels.py index 59c4d15bf67b..8b50e8ba0ec6 100644 --- a/test/python/pulse/test_channels.py +++ b/test/python/pulse/test_channels.py @@ -28,6 +28,7 @@ PulseError, ) from test import QiskitTestCase # pylint: disable=wrong-import-order +from qiskit.pulse.deprecate import ignore_pulse_deprecation_warnings class TestChannel(QiskitTestCase): @@ -58,6 +59,7 @@ def test_default(self): self.assertEqual(acquire_channel.index, 123) self.assertEqual(acquire_channel.name, "a123") + @ignore_pulse_deprecation_warnings def test_channel_hash(self): """Test hashing for acquire channel.""" acq_channel_1 = AcquireChannel(123) @@ -81,6 +83,7 @@ def test_cannot_be_instantiated(self): class TestMemorySlot(QiskitTestCase): """MemorySlot tests.""" + @ignore_pulse_deprecation_warnings def test_default(self): """Test default memory slot.""" memory_slot = MemorySlot(123) @@ -100,6 +103,7 @@ def test_validation(self): class TestRegisterSlot(QiskitTestCase): """RegisterSlot tests.""" + @ignore_pulse_deprecation_warnings def test_default(self): """Test default register slot.""" register_slot = RegisterSlot(123) @@ -119,6 +123,7 @@ def test_validation(self): class TestSnapshotChannel(QiskitTestCase): """SnapshotChannel tests.""" + @ignore_pulse_deprecation_warnings def test_default(self): """Test default snapshot channel.""" snapshot_channel = SnapshotChannel() @@ -131,6 +136,7 @@ def test_default(self): class TestDriveChannel(QiskitTestCase): """DriveChannel tests.""" + @ignore_pulse_deprecation_warnings def test_default(self): """Test default drive channel.""" drive_channel = DriveChannel(123) @@ -149,6 +155,7 @@ def test_validation(self): class TestControlChannel(QiskitTestCase): """ControlChannel tests.""" + @ignore_pulse_deprecation_warnings def test_default(self): """Test default control channel.""" control_channel = ControlChannel(123) @@ -167,6 +174,7 @@ def test_validation(self): class TestMeasureChannel(QiskitTestCase): """MeasureChannel tests.""" + @ignore_pulse_deprecation_warnings def test_default(self): """Test default measure channel.""" measure_channel = MeasureChannel(123) diff --git a/test/python/pulse/test_experiment_configurations.py b/test/python/pulse/test_experiment_configurations.py index 8d6a93b39eac..51e3e2184531 100644 --- a/test/python/pulse/test_experiment_configurations.py +++ b/test/python/pulse/test_experiment_configurations.py @@ -18,11 +18,13 @@ from qiskit.pulse.exceptions import PulseError from qiskit.pulse import LoConfig, LoRange, Kernel, Discriminator from test import QiskitTestCase # pylint: disable=wrong-import-order +from qiskit.pulse.deprecate import ignore_pulse_deprecation_warnings class TestLoRange(QiskitTestCase): """Test LO LoRange.""" + @ignore_pulse_deprecation_warnings def test_properties_includes_and_eq(self): """Test creation of LoRange. Test upper/lower bounds and includes. Test __eq__ for two same and different LoRange's. @@ -43,6 +45,7 @@ def test_properties_includes_and_eq(self): class TestLoConfig(QiskitTestCase): """LoConfig tests.""" + @ignore_pulse_deprecation_warnings def test_can_create_empty_user_lo_config(self): """Test if a LoConfig can be created without no arguments.""" user_lo_config = LoConfig() @@ -97,6 +100,7 @@ def test_get_channel_lo(self): class TestKernel(QiskitTestCase): """Test Kernel.""" + @ignore_pulse_deprecation_warnings def test_eq(self): """Test if two kernels are equal.""" kernel_a = Kernel( @@ -157,6 +161,7 @@ def test_neq_nested_params(self): class TestDiscriminator(QiskitTestCase): """Test Discriminator.""" + @ignore_pulse_deprecation_warnings def test_eq(self): """Test if two discriminators are equal.""" discriminator_a = Discriminator( diff --git a/test/python/pulse/test_instruction_schedule_map.py b/test/python/pulse/test_instruction_schedule_map.py index d1610d7ebcc0..8e9af4456fdd 100644 --- a/test/python/pulse/test_instruction_schedule_map.py +++ b/test/python/pulse/test_instruction_schedule_map.py @@ -35,11 +35,13 @@ from qiskit.qobj.converters import QobjToInstructionConverter from qiskit.providers.fake_provider import FakeOpenPulse2Q, Fake7QPulseV1 from test import QiskitTestCase # pylint: disable=wrong-import-order +from qiskit.pulse.deprecate import ignore_pulse_deprecation_warnings class TestInstructionScheduleMap(QiskitTestCase): """Test the InstructionScheduleMap.""" + @ignore_pulse_deprecation_warnings def test_add(self): """Test add, and that errors are raised when expected.""" sched = Schedule() diff --git a/test/python/pulse/test_instructions.py b/test/python/pulse/test_instructions.py index f0bdd165db08..a7dbc58f9012 100644 --- a/test/python/pulse/test_instructions.py +++ b/test/python/pulse/test_instructions.py @@ -17,11 +17,13 @@ from qiskit import circuit from qiskit.pulse import channels, configuration, instructions, library, exceptions from test import QiskitTestCase # pylint: disable=wrong-import-order +from qiskit.pulse.deprecate import ignore_pulse_deprecation_warnings class TestAcquire(QiskitTestCase): """Acquisition tests.""" + @ignore_pulse_deprecation_warnings def test_can_construct_valid_acquire_command(self): """Test if valid acquire command can be constructed.""" kernel_opts = {"start_window": 0, "stop_window": 10} @@ -88,6 +90,7 @@ def test_instructions_hash(self): class TestDelay(QiskitTestCase): """Delay tests.""" + @ignore_pulse_deprecation_warnings def test_delay(self): """Test delay.""" delay = instructions.Delay(10, channels.DriveChannel(0), name="test_name") @@ -124,6 +127,7 @@ def test_operator_delay(self): class TestSetFrequency(QiskitTestCase): """Set frequency tests.""" + @ignore_pulse_deprecation_warnings def test_freq(self): """Test set frequency basic functionality.""" set_freq = instructions.SetFrequency(4.5e9, channels.DriveChannel(1), name="test") @@ -140,6 +144,7 @@ def test_freq(self): ) self.assertEqual(repr(set_freq), "SetFrequency(4500000000.0, DriveChannel(1), name='test')") + @ignore_pulse_deprecation_warnings def test_freq_non_pulse_channel(self): """Test set frequency constructor with illegal channel""" with self.assertRaises(exceptions.PulseError): @@ -176,6 +181,7 @@ def test_shift_freq(self): repr(shift_freq), "ShiftFrequency(4500000000.0, DriveChannel(1), name='test')" ) + @ignore_pulse_deprecation_warnings def test_freq_non_pulse_channel(self): """Test shift frequency constructor with illegal channel""" with self.assertRaises(exceptions.PulseError): @@ -194,6 +200,7 @@ def test_parameter_expression(self): class TestSetPhase(QiskitTestCase): """Test the instruction construction.""" + @ignore_pulse_deprecation_warnings def test_default(self): """Test basic SetPhase.""" set_phase = instructions.SetPhase(1.57, channels.DriveChannel(0)) @@ -229,6 +236,7 @@ def test_parameter_expression(self): class TestShiftPhase(QiskitTestCase): """Test the instruction construction.""" + @ignore_pulse_deprecation_warnings def test_default(self): """Test basic ShiftPhase.""" shift_phase = instructions.ShiftPhase(1.57, channels.DriveChannel(0)) @@ -264,6 +272,7 @@ def test_parameter_expression(self): class TestSnapshot(QiskitTestCase): """Snapshot tests.""" + @ignore_pulse_deprecation_warnings def test_default(self): """Test default snapshot.""" snapshot = instructions.Snapshot(label="test_name", snapshot_type="state") @@ -279,12 +288,14 @@ def test_default(self): class TestPlay(QiskitTestCase): """Play tests.""" + @ignore_pulse_deprecation_warnings def setUp(self): """Setup play tests.""" super().setUp() self.duration = 4 self.pulse_op = library.Waveform([1.0] * self.duration, name="test") + @ignore_pulse_deprecation_warnings def test_play(self): """Test basic play instruction.""" play = instructions.Play(self.pulse_op, channels.DriveChannel(1)) @@ -307,6 +318,7 @@ def test_play_non_pulse_ch_raises(self): class TestDirectives(QiskitTestCase): """Test pulse directives.""" + @ignore_pulse_deprecation_warnings def test_relative_barrier(self): """Test the relative barrier directive.""" a0 = channels.AcquireChannel(0) diff --git a/test/python/pulse/test_macros.py b/test/python/pulse/test_macros.py index 6d87320cf480..b1595e7e006d 100644 --- a/test/python/pulse/test_macros.py +++ b/test/python/pulse/test_macros.py @@ -26,11 +26,13 @@ from qiskit.pulse.exceptions import PulseError from qiskit.providers.fake_provider import FakeOpenPulse2Q, Fake27QPulseV1, GenericBackendV2 from test import QiskitTestCase # pylint: disable=wrong-import-order +from qiskit.pulse.deprecate import ignore_pulse_deprecation_warnings class TestMeasure(QiskitTestCase): """Pulse measure macro.""" + @ignore_pulse_deprecation_warnings def setUp(self): super().setUp() with self.assertWarns(DeprecationWarning): @@ -91,6 +93,7 @@ def test_measure_with_custom_inst_map(self): with self.assertRaises(PulseError): macros.measure(qubits=[0], measure_name="name", inst_map=inst_map, meas_map=[[0]]) + @ignore_pulse_deprecation_warnings def test_fail_measure(self): """Test failing measure.""" with self.assertRaises(PulseError): @@ -213,6 +216,7 @@ def test_output_with_multiple_measure_v1_and_measure_v2(self): class TestMeasureAll(QiskitTestCase): """Pulse measure all macro.""" + @ignore_pulse_deprecation_warnings def setUp(self): super().setUp() with self.assertWarns(DeprecationWarning): @@ -224,6 +228,7 @@ def setUp(self): seed=42, ) + @ignore_pulse_deprecation_warnings def test_measure_all(self): """Test measure_all function.""" sched = macros.measure_all(self.backend_v1) diff --git a/test/python/pulse/test_parameter_manager.py b/test/python/pulse/test_parameter_manager.py index 0b91aaeaab4a..92a44ef6e7fd 100644 --- a/test/python/pulse/test_parameter_manager.py +++ b/test/python/pulse/test_parameter_manager.py @@ -27,11 +27,13 @@ from qiskit.pulse.transforms import AlignEquispaced, AlignLeft, inline_subroutines from qiskit.pulse.utils import format_parameter_value from test import QiskitTestCase # pylint: disable=wrong-import-order +from qiskit.pulse.deprecate import ignore_pulse_deprecation_warnings class ParameterTestBase(QiskitTestCase): """A base class for parameter manager unittest, providing test schedule.""" + @ignore_pulse_deprecation_warnings def setUp(self): """Just some useful, reusable Parameters, constants, schedules.""" super().setUp() @@ -103,6 +105,7 @@ def setUp(self): class TestParameterGetter(ParameterTestBase): """Test getting parameters.""" + @ignore_pulse_deprecation_warnings def test_get_parameter_from_channel(self): """Test get parameters from channel.""" test_obj = pulse.DriveChannel(self.ch1 + self.ch2) @@ -125,6 +128,7 @@ def test_get_parameter_from_pulse(self): self.assertSetEqual(visitor.parameters, ref_params) + @ignore_pulse_deprecation_warnings def test_get_parameter_from_acquire(self): """Test get parameters from acquire instruction.""" test_obj = pulse.Acquire(16000, pulse.AcquireChannel(self.ch1), pulse.MemorySlot(self.ch1)) @@ -331,6 +335,7 @@ def test_complex_value_to_parameter(self): self.assertEqual(assigned.amp, 0.1j) + @ignore_pulse_deprecation_warnings def test_complex_parameter_expression(self): """Test assignment of complex-valued parameter expression to parameter, but raises PendingDeprecationWarning.""" @@ -454,6 +459,7 @@ def test_set_parameter_to_complex_schedule(self): class TestAssignFromProgram(QiskitTestCase): """Test managing parameters from programs. Parameter manager is implicitly called.""" + @ignore_pulse_deprecation_warnings def test_attribute_parameters(self): """Test the ``parameter`` attributes.""" sigma = Parameter("sigma") @@ -619,6 +625,7 @@ def test_overlapping_on_multiple_assignment(self): with self.assertRaises(PulseError): schedule.assign_parameters({param_idx2: 2}) + @ignore_pulse_deprecation_warnings def test_cannot_build_schedule_with_unassigned_duration(self): """Test we cannot build schedule with parameterized instructions""" dur = Parameter("dur") diff --git a/test/python/pulse/test_parser.py b/test/python/pulse/test_parser.py index 8fb491b9da74..45cf35fbeac1 100644 --- a/test/python/pulse/test_parser.py +++ b/test/python/pulse/test_parser.py @@ -15,6 +15,7 @@ from qiskit.pulse.parser import parse_string_expr from qiskit.pulse.exceptions import PulseError from test import QiskitTestCase # pylint: disable=wrong-import-order +from qiskit.pulse.deprecate import ignore_pulse_deprecation_warnings class TestInstructionToQobjConverter(QiskitTestCase): @@ -212,6 +213,7 @@ def test_partial_binding(self): self.assertEqual(bound_four_new(P5=5), -2.925) self.assertEqual(bound_four_new(5), -2.925) + @ignore_pulse_deprecation_warnings def test_argument_duplication(self): """Test duplication of *args and **kwargs.""" diff --git a/test/python/pulse/test_pulse_lib.py b/test/python/pulse/test_pulse_lib.py index 9c57579d0bf1..82ff640bd335 100644 --- a/test/python/pulse/test_pulse_lib.py +++ b/test/python/pulse/test_pulse_lib.py @@ -39,6 +39,7 @@ ) from qiskit.pulse import functional_pulse, PulseError from test import QiskitTestCase # pylint: disable=wrong-import-order +from qiskit.pulse.deprecate import ignore_pulse_deprecation_warnings class TestWaveform(QiskitTestCase): @@ -85,6 +86,7 @@ def test_type_casting(self): sample_pulse_list = Waveform(samples_list) self.assertEqual(sample_pulse_list.samples.dtype, np.complex128) + @ignore_pulse_deprecation_warnings def test_pulse_limits(self): """Test that limits of pulse norm of one are enforced properly.""" @@ -586,6 +588,7 @@ def test_class_level_limit_amplitude(self): waveform = GaussianSquareDrag(duration=100, sigma=1.0, amp=1.1, beta=0.1, width=10) self.assertGreater(np.abs(waveform.amp), 1.0) + @ignore_pulse_deprecation_warnings def test_class_level_disable_validation(self): """Test that pulse validation can be disabled on the class level. @@ -833,6 +836,7 @@ class TestFunctionalPulse(QiskitTestCase): """Waveform tests.""" # pylint: disable=invalid-name + @ignore_pulse_deprecation_warnings def test_gaussian(self): """Test gaussian pulse.""" @@ -888,6 +892,7 @@ def test_scalable_comparison(self): gaussian1._params["sigma"] = 10 self.assertNotEqual(gaussian1, gaussian2) + @ignore_pulse_deprecation_warnings def test_complex_amp_error(self): """Test that initializing a pulse with complex amp raises an error""" with self.assertRaises(PulseError): diff --git a/test/python/pulse/test_reference.py b/test/python/pulse/test_reference.py index 3d7603461756..8fdff3eaaa6b 100644 --- a/test/python/pulse/test_reference.py +++ b/test/python/pulse/test_reference.py @@ -18,6 +18,7 @@ from qiskit.pulse import ScheduleBlock, builder from qiskit.pulse.transforms import inline_subroutines from test import QiskitTestCase # pylint: disable=wrong-import-order +from qiskit.pulse.deprecate import ignore_pulse_deprecation_warnings class TestReference(QiskitTestCase): @@ -247,6 +248,7 @@ def test_calling_same_schedule_with_different_assignment(self): self.assertEqual(len(sched_z1.references), 2) + @ignore_pulse_deprecation_warnings def test_alignment_context(self): """Test nested alignment context. @@ -433,6 +435,7 @@ def test_assign_existing_reference(self): class TestSubroutineWithCXGate(QiskitTestCase): """Test called program scope with practical example of building fully parametrized CX gate.""" + @ignore_pulse_deprecation_warnings def setUp(self): super().setUp() @@ -537,6 +540,7 @@ def test_lazy_ecr(self): params = sched.get_parameters(parameter_name="amp") self.assertEqual(len(params), 2) + @ignore_pulse_deprecation_warnings def test_cnot(self): """Integration test with CNOT schedule construction.""" # echoed cross resonance diff --git a/test/python/pulse/test_samplers.py b/test/python/pulse/test_samplers.py index 4e6ab46737d6..9238d81a4aa3 100644 --- a/test/python/pulse/test_samplers.py +++ b/test/python/pulse/test_samplers.py @@ -18,6 +18,7 @@ from qiskit.pulse import library from qiskit.pulse.library import samplers from test import QiskitTestCase # pylint: disable=wrong-import-order +from qiskit.pulse.deprecate import ignore_pulse_deprecation_warnings def linear(times: np.ndarray, m: float, b: float = 0.1) -> np.ndarray: @@ -82,6 +83,7 @@ def test_sampler_name(self): self.assertIsInstance(pulse, library.Waveform) self.assertEqual(pulse.name, "test") + @ignore_pulse_deprecation_warnings def test_default_arg_sampler(self): """Test that default arguments work with sampler.""" m = 0.1 diff --git a/test/python/pulse/test_schedule.py b/test/python/pulse/test_schedule.py index 5e5676e7c2d9..a8a382d5f698 100644 --- a/test/python/pulse/test_schedule.py +++ b/test/python/pulse/test_schedule.py @@ -47,6 +47,7 @@ from qiskit.pulse.schedule import Schedule, _overlaps, _find_insertion_index from qiskit.providers.fake_provider import FakeOpenPulse2Q from test import QiskitTestCase # pylint: disable=wrong-import-order +from qiskit.pulse.deprecate import ignore_pulse_deprecation_warnings class BaseTestSchedule(QiskitTestCase): @@ -232,6 +233,7 @@ def test_flat_instruction_sequence_returns_instructions(self): for _, instr in sched.instructions: self.assertIsInstance(instr, Instruction) + @ignore_pulse_deprecation_warnings def test_absolute_start_time_of_grandchild(self): """Test correct calculation of start time of grandchild of a schedule.""" lp0 = self.linear(duration=10, slope=0.02, intercept=0.01) @@ -514,6 +516,7 @@ def test_replace_schedule(self): sched.replace(old, new, inplace=True) self.assertEqual(sched, ref_sched) + @ignore_pulse_deprecation_warnings def test_replace_fails_on_overlap(self): """Test that replacement fails on overlap.""" old = Play(Constant(20, 1.0), DriveChannel(0)) @@ -575,6 +578,7 @@ def test_delay_control_channel(self): sched = Delay(self.delay_time, control_ch) | Play(pulse, control_ch) self.assertIsInstance(sched, Schedule) + @ignore_pulse_deprecation_warnings def test_delay_acquire_channel(self): """Test Delay on DriveChannel""" @@ -803,6 +807,7 @@ def test_filter_multiple(self): self.assertIsInstance(inst, Acquire) self.assertTrue(len(filtered.instructions), 2) + @ignore_pulse_deprecation_warnings def test_custom_filters(self): """Test custom filters.""" lp0 = self.linear(duration=3, slope=0.2, intercept=0.1) @@ -885,6 +890,7 @@ def _filter_and_test_consistency(self, schedule: Schedule, *args, **kwargs): class TestScheduleEquality(BaseTestSchedule): """Test equality of schedules.""" + @ignore_pulse_deprecation_warnings def test_different_channels(self): """Test equality is False if different channels.""" self.assertNotEqual( diff --git a/test/python/pulse/test_transforms.py b/test/python/pulse/test_transforms.py index c16405cff4d1..7cd306567dcd 100644 --- a/test/python/pulse/test_transforms.py +++ b/test/python/pulse/test_transforms.py @@ -39,11 +39,13 @@ from qiskit.pulse.instructions import directives from qiskit.providers.fake_provider import FakeOpenPulse2Q from test import QiskitTestCase # pylint: disable=wrong-import-order +from qiskit.pulse.deprecate import ignore_pulse_deprecation_warnings class TestAlignMeasures(QiskitTestCase): """Test the helper function which aligns acquires.""" + @ignore_pulse_deprecation_warnings def setUp(self): super().setUp() with self.assertWarns(DeprecationWarning): @@ -134,6 +136,7 @@ def test_multiple_acquires(self): self.assertEqual(aligned, ref) + @ignore_pulse_deprecation_warnings def test_align_across_schedules(self): """Test that acquires are aligned together across multiple schedules.""" sched1 = pulse.Schedule(name="fake_experiment") @@ -201,6 +204,7 @@ def test_measurement_at_zero(self): class TestAddImplicitAcquires(QiskitTestCase): """Test the helper function which makes implicit acquires explicit.""" + @ignore_pulse_deprecation_warnings def setUp(self): super().setUp() with self.assertWarns(DeprecationWarning): @@ -224,6 +228,7 @@ def test_add_implicit(self): acquired_qubits.add(inst.acquire.index) self.assertEqual(acquired_qubits, {0, 1}) + @ignore_pulse_deprecation_warnings def test_add_across_meas_map_sublists(self): """Test that implicit acquires in separate meas map sublists are all added.""" sched = transforms.add_implicit_acquires(self.sched, [[0, 2], [1, 3]]) @@ -361,6 +366,7 @@ def test_padding_prepended_delay(self): self.assertEqual(transforms.pad(sched, until=30, inplace=True), ref_sched) + @ignore_pulse_deprecation_warnings def test_pad_no_delay_on_classical_io_channels(self): """Test padding does not apply to classical IO channels.""" delay = 10 @@ -496,6 +502,7 @@ def test_sample_pulses_with_tolerance(self): self.assertEqual(len(original_pulse_ids), 2) self.assertEqual(len(compressed_pulse_ids), 1) + @ignore_pulse_deprecation_warnings def test_multiple_schedules(self): """Test multiple schedules.""" schedules = [] @@ -517,6 +524,7 @@ def test_multiple_schedules(self): class TestAlignSequential(QiskitTestCase): """Test sequential alignment transform.""" + @ignore_pulse_deprecation_warnings def test_align_sequential(self): """Test sequential alignment without a barrier.""" context = transforms.AlignSequential() @@ -565,6 +573,7 @@ def test_align_sequential_with_barrier(self): class TestAlignLeft(QiskitTestCase): """Test left alignment transform.""" + @ignore_pulse_deprecation_warnings def test_align_left(self): """Test left alignment without a barrier.""" context = transforms.AlignLeft() @@ -628,6 +637,7 @@ def test_align_left_with_barrier(self): class TestAlignRight(QiskitTestCase): """Test right alignment transform.""" + @ignore_pulse_deprecation_warnings def test_align_right(self): """Test right alignment without a barrier.""" context = transforms.AlignRight() @@ -692,6 +702,7 @@ def test_align_right_with_barrier(self): class TestAlignEquispaced(QiskitTestCase): """Test equispaced alignment transform.""" + @ignore_pulse_deprecation_warnings def test_equispaced_with_short_duration(self): """Test equispaced context with duration shorter than the schedule duration.""" context = transforms.AlignEquispaced(duration=20) @@ -710,6 +721,7 @@ def test_equispaced_with_short_duration(self): self.assertEqual(schedule, reference) + @ignore_pulse_deprecation_warnings def test_equispaced_with_longer_duration(self): """Test equispaced context with duration longer than the schedule duration.""" context = transforms.AlignEquispaced(duration=50) @@ -775,6 +787,7 @@ def _position(ind): """Returns 0.25, 0.5, 0.75 for ind = 1, 2, 3.""" return ind / (3 + 1) + @ignore_pulse_deprecation_warnings def test_numerical_with_short_duration(self): """Test numerical alignment context with duration shorter than the schedule duration.""" context = transforms.AlignFunc(duration=20, func=self._position) @@ -793,6 +806,7 @@ def test_numerical_with_short_duration(self): self.assertEqual(schedule, reference) + @ignore_pulse_deprecation_warnings def test_numerical_with_longer_duration(self): """Test numerical alignment context with duration longer than the schedule duration.""" context = transforms.AlignFunc(duration=80, func=self._position) @@ -815,6 +829,7 @@ def test_numerical_with_longer_duration(self): class TestFlatten(QiskitTestCase): """Test flattening transform.""" + @ignore_pulse_deprecation_warnings def test_flatten(self): """Test the flatten transform.""" context_left = transforms.AlignLeft() @@ -864,6 +879,7 @@ def channels(self): class TestRemoveDirectives(QiskitTestCase): """Test removing of directives.""" + @ignore_pulse_deprecation_warnings def test_remove_directives(self): """Test that all directives are removed.""" d0 = pulse.DriveChannel(0) @@ -884,6 +900,7 @@ def test_remove_directives(self): class TestRemoveTrivialBarriers(QiskitTestCase): """Test scheduling transforms.""" + @ignore_pulse_deprecation_warnings def test_remove_trivial_barriers(self): """Test that trivial barriers are properly removed.""" schedule = pulse.Schedule() From 945e7f5ccb9d0a6092a7eb0f0fd058531153e2d5 Mon Sep 17 00:00:00 2001 From: Eli Arbel Date: Tue, 17 Sep 2024 12:51:09 +0300 Subject: [PATCH 02/23] Deprecate classes, a couple functions & fix tests --- qiskit/pulse/builder.py | 4 ++ qiskit/pulse/calibration_entries.py | 4 ++ qiskit/pulse/channels.py | 3 ++ qiskit/pulse/configuration.py | 5 +++ qiskit/pulse/deprecate.py | 43 +++++++++++++++++++ qiskit/pulse/exceptions.py | 2 + qiskit/pulse/instruction_schedule_map.py | 2 + qiskit/pulse/instructions/acquire.py | 2 + qiskit/pulse/instructions/delay.py | 2 + qiskit/pulse/instructions/directives.py | 3 ++ qiskit/pulse/instructions/frequency.py | 3 ++ qiskit/pulse/instructions/instruction.py | 2 + qiskit/pulse/instructions/phase.py | 3 ++ qiskit/pulse/instructions/play.py | 2 + qiskit/pulse/instructions/reference.py | 2 + qiskit/pulse/instructions/snapshot.py | 2 + qiskit/pulse/library/symbolic_pulses.py | 4 ++ qiskit/pulse/library/waveform.py | 2 + qiskit/pulse/parameter_manager.py | 4 ++ qiskit/pulse/parser.py | 2 + qiskit/pulse/schedule.py | 3 ++ qiskit/pulse/transforms/alignments.py | 6 +++ test/python/pulse/test_block.py | 9 ++++ test/python/pulse/test_builder.py | 10 +++++ test/python/pulse/test_builder_v2.py | 7 +++ test/python/pulse/test_calibration_entries.py | 4 ++ test/python/pulse/test_channels.py | 8 ++++ .../pulse/test_experiment_configurations.py | 5 +++ .../pulse/test_instruction_schedule_map.py | 2 + test/python/pulse/test_instructions.py | 12 ++++++ test/python/pulse/test_macros.py | 5 +++ test/python/pulse/test_parameter_manager.py | 7 +++ test/python/pulse/test_parser.py | 2 + test/python/pulse/test_pulse_lib.py | 5 +++ test/python/pulse/test_reference.py | 4 ++ test/python/pulse/test_samplers.py | 2 + test/python/pulse/test_schedule.py | 6 +++ test/python/pulse/test_transforms.py | 17 ++++++++ 38 files changed, 210 insertions(+) create mode 100644 qiskit/pulse/deprecate.py diff --git a/qiskit/pulse/builder.py b/qiskit/pulse/builder.py index 8767e8c4e93a..57d89fa45c73 100644 --- a/qiskit/pulse/builder.py +++ b/qiskit/pulse/builder.py @@ -437,6 +437,7 @@ from qiskit.pulse.instructions import directives from qiskit.pulse.schedule import Schedule, ScheduleBlock from qiskit.pulse.transforms.alignments import AlignmentKind +from qiskit.pulse.deprecate import deprecate_pulse_func if sys.version_info >= (3, 12): @@ -477,6 +478,7 @@ class _PulseBuilder: "sequential": transforms.AlignSequential(), } + @deprecate_pulse_func def __init__( self, backend=None, @@ -774,6 +776,7 @@ def get_dt(self): return self.backend.configuration().dt +@deprecate_pulse_func def build( backend=None, schedule: ScheduleBlock | None = None, @@ -1504,6 +1507,7 @@ def delay(duration: int, channel: chans.Channel, name: str | None = None): append_instruction(instructions.Delay(duration, channel, name=name)) +@deprecate_pulse_func def play(pulse: library.Pulse | np.ndarray, channel: chans.PulseChannel, name: str | None = None): """Play a ``pulse`` on a ``channel``. diff --git a/qiskit/pulse/calibration_entries.py b/qiskit/pulse/calibration_entries.py index 8a5ba1b6e3d6..855f69cec14a 100644 --- a/qiskit/pulse/calibration_entries.py +++ b/qiskit/pulse/calibration_entries.py @@ -24,6 +24,7 @@ from qiskit.qobj.converters import QobjToInstructionConverter from qiskit.qobj.pulse_qobj import PulseQobjInstruction from qiskit.exceptions import QiskitError +from qiskit.pulse.deprecate import deprecate_pulse_func IncompletePulseQobj = object() @@ -122,6 +123,7 @@ class ScheduleDef(CalibrationEntry): """ + @deprecate_pulse_func def __init__(self, arguments: Sequence[str] | None = None): """Define an empty entry. @@ -238,6 +240,7 @@ class CallableDef(CalibrationEntry): """ + @deprecate_pulse_func def __init__(self): """Define an empty entry.""" self._definition = None @@ -300,6 +303,7 @@ class PulseQobjDef(ScheduleDef): """ + @deprecate_pulse_func def __init__( self, arguments: Sequence[str] | None = None, diff --git a/qiskit/pulse/channels.py b/qiskit/pulse/channels.py index c70aac38ba19..0d98775c62a4 100644 --- a/qiskit/pulse/channels.py +++ b/qiskit/pulse/channels.py @@ -58,6 +58,7 @@ from qiskit.circuit import Parameter from qiskit.circuit.parameterexpression import ParameterExpression from qiskit.pulse.exceptions import PulseError +from qiskit.pulse.deprecate import deprecate_pulse_func class Channel(metaclass=ABCMeta): @@ -90,6 +91,7 @@ def __new__(cls, *args, **kwargs): return super().__new__(cls) + @deprecate_pulse_func def __init__(self, index: int): """Channel class. @@ -206,6 +208,7 @@ class SnapshotChannel(ClassicalIOChannel): prefix = "s" + @deprecate_pulse_func def __init__(self): """Create new snapshot channel.""" super().__init__(0) diff --git a/qiskit/pulse/configuration.py b/qiskit/pulse/configuration.py index 1bfd1f13e2ee..2049da6cfd3d 100644 --- a/qiskit/pulse/configuration.py +++ b/qiskit/pulse/configuration.py @@ -18,6 +18,7 @@ from .channels import DriveChannel, MeasureChannel from .exceptions import PulseError +from qiskit.pulse.deprecate import deprecate_pulse_func def _assert_nested_dict_equal(a: dict, b: dict): @@ -44,6 +45,7 @@ class Kernel: into IQ points. """ + @deprecate_pulse_func def __init__(self, name: str | None = None, **params): """Create new kernel. @@ -70,6 +72,7 @@ class Discriminator: into 0/1 state results. """ + @deprecate_pulse_func def __init__(self, name: str | None = None, **params): """Create new discriminator. @@ -94,6 +97,7 @@ def __eq__(self, other): class LoRange: """Range of LO frequency.""" + @deprecate_pulse_func def __init__(self, lower_bound: float, upper_bound: float): self._lb = lower_bound self._ub = upper_bound @@ -142,6 +146,7 @@ def __eq__(self, other): class LoConfig: """Pulse channel LO frequency container.""" + @deprecate_pulse_func def __init__( self, channel_los: dict[DriveChannel | MeasureChannel, float] | None = None, diff --git a/qiskit/pulse/deprecate.py b/qiskit/pulse/deprecate.py new file mode 100644 index 000000000000..751184f0a228 --- /dev/null +++ b/qiskit/pulse/deprecate.py @@ -0,0 +1,43 @@ +# This code is part of Qiskit. +# +# (C) Copyright IBM 2024 +# +# This code is licensed under the Apache License, Version 2.0. You may +# obtain a copy of this license in the LICENSE.txt file in the root directory +# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0. +# +# Any modifications or derivative works of this code must retain this +# copyright notice, and modified files need to carry a notice indicating +# that they have been altered from the originals. +""" +Deprecation functions for Qiskit Pulse +""" + +import warnings +from functools import wraps +from qiskit.utils.deprecation import deprecate_func + + +def deprecate_pulse_func(func): + """Deprecation message for functions and classes""" + return deprecate_func( + since="1.3", + removal_timeline="in Qiskit 2.0", + additional_msg="This is part of the entire Qiskit Pulse package deprecation. " + "The package will be moved to the Qiskit Dynamics repository: " + "https://github.com/qiskit-community/qiskit-dynamics/", + )(func) + + +def ignore_pulse_deprecation_warnings(func): + """Filter Pulse deprecation warnings in a decorated function""" + + @wraps(func) + def wrapper(*args, **kwargs): + with warnings.catch_warnings(): + warnings.filterwarnings( + "ignore", category=DeprecationWarning, message=".*Qiskit Pulse package" + ) + return func(*args, **kwargs) + + return wrapper diff --git a/qiskit/pulse/exceptions.py b/qiskit/pulse/exceptions.py index 21bda97ee1b9..5fc3793398ea 100644 --- a/qiskit/pulse/exceptions.py +++ b/qiskit/pulse/exceptions.py @@ -12,11 +12,13 @@ """Exception for errors raised by the pulse module.""" from qiskit.exceptions import QiskitError +from qiskit.pulse.deprecate import deprecate_pulse_func class PulseError(QiskitError): """Errors raised by the pulse module.""" + @deprecate_pulse_func def __init__(self, *message): """Set the error message.""" super().__init__(*message) diff --git a/qiskit/pulse/instruction_schedule_map.py b/qiskit/pulse/instruction_schedule_map.py index afa71b6825a7..e46de27b3afd 100644 --- a/qiskit/pulse/instruction_schedule_map.py +++ b/qiskit/pulse/instruction_schedule_map.py @@ -46,6 +46,7 @@ ) from qiskit.pulse.exceptions import PulseError from qiskit.pulse.schedule import Schedule, ScheduleBlock +from qiskit.pulse.deprecate import deprecate_pulse_func class InstructionScheduleMap: @@ -62,6 +63,7 @@ class InstructionScheduleMap: These can usually be seen as gate calibrations. """ + @deprecate_pulse_func def __init__(self): """Initialize a circuit instruction to schedule mapper instance.""" # The processed and reformatted circuit instruction definitions diff --git a/qiskit/pulse/instructions/acquire.py b/qiskit/pulse/instructions/acquire.py index 98fbf460c1b3..263d14b0f102 100644 --- a/qiskit/pulse/instructions/acquire.py +++ b/qiskit/pulse/instructions/acquire.py @@ -19,6 +19,7 @@ from qiskit.pulse.configuration import Kernel, Discriminator from qiskit.pulse.exceptions import PulseError from qiskit.pulse.instructions.instruction import Instruction +from qiskit.pulse.deprecate import deprecate_pulse_func class Acquire(Instruction): @@ -38,6 +39,7 @@ class Acquire(Instruction): * the discriminator to classify kerneled IQ points. """ + @deprecate_pulse_func def __init__( self, duration: int | ParameterExpression, diff --git a/qiskit/pulse/instructions/delay.py b/qiskit/pulse/instructions/delay.py index 13f36d3b7d9b..c69115484623 100644 --- a/qiskit/pulse/instructions/delay.py +++ b/qiskit/pulse/instructions/delay.py @@ -16,6 +16,7 @@ from qiskit.circuit import ParameterExpression from qiskit.pulse.channels import Channel from qiskit.pulse.instructions.instruction import Instruction +from qiskit.pulse.deprecate import deprecate_pulse_func class Delay(Instruction): @@ -34,6 +35,7 @@ class Delay(Instruction): The ``channel`` will output no signal from time=0 up until time=10. """ + @deprecate_pulse_func def __init__( self, duration: int | ParameterExpression, diff --git a/qiskit/pulse/instructions/directives.py b/qiskit/pulse/instructions/directives.py index f1e7f9b24569..6b09b1e66373 100644 --- a/qiskit/pulse/instructions/directives.py +++ b/qiskit/pulse/instructions/directives.py @@ -18,6 +18,7 @@ from qiskit.pulse import channels as chans from qiskit.pulse.instructions import instruction from qiskit.pulse.exceptions import PulseError +from qiskit.pulse.deprecate import deprecate_pulse_func class Directive(instruction.Instruction, ABC): @@ -35,6 +36,7 @@ def duration(self) -> int: class RelativeBarrier(Directive): """Pulse ``RelativeBarrier`` directive.""" + @deprecate_pulse_func def __init__(self, *channels: chans.Channel, name: str | None = None): """Create a relative barrier directive. @@ -102,6 +104,7 @@ class TimeBlockade(Directive): user can insert another instruction without timing overlap. """ + @deprecate_pulse_func def __init__( self, duration: int, diff --git a/qiskit/pulse/instructions/frequency.py b/qiskit/pulse/instructions/frequency.py index a14e60ee1a32..de56222c42bb 100644 --- a/qiskit/pulse/instructions/frequency.py +++ b/qiskit/pulse/instructions/frequency.py @@ -19,6 +19,7 @@ from qiskit.pulse.channels import PulseChannel from qiskit.pulse.instructions.instruction import Instruction from qiskit.pulse.exceptions import PulseError +from qiskit.pulse.deprecate import deprecate_pulse_func class SetFrequency(Instruction): @@ -35,6 +36,7 @@ class SetFrequency(Instruction): The duration of SetFrequency is 0. """ + @deprecate_pulse_func def __init__( self, frequency: Union[float, ParameterExpression], @@ -85,6 +87,7 @@ def duration(self) -> int: class ShiftFrequency(Instruction): """Shift the channel frequency away from the current frequency.""" + @deprecate_pulse_func def __init__( self, frequency: Union[float, ParameterExpression], diff --git a/qiskit/pulse/instructions/instruction.py b/qiskit/pulse/instructions/instruction.py index 61ebe67777f8..a604a0af1e91 100644 --- a/qiskit/pulse/instructions/instruction.py +++ b/qiskit/pulse/instructions/instruction.py @@ -28,6 +28,7 @@ from qiskit.circuit import Parameter, ParameterExpression from qiskit.pulse.channels import Channel from qiskit.pulse.exceptions import PulseError +from qiskit.pulse.deprecate import deprecate_pulse_func # pylint: disable=bad-docstring-quotes @@ -38,6 +39,7 @@ class Instruction(ABC): channels. """ + @deprecate_pulse_func def __init__( self, operands: tuple, diff --git a/qiskit/pulse/instructions/phase.py b/qiskit/pulse/instructions/phase.py index 21f46dfb5f72..b1a889d40963 100644 --- a/qiskit/pulse/instructions/phase.py +++ b/qiskit/pulse/instructions/phase.py @@ -21,6 +21,7 @@ from qiskit.pulse.channels import PulseChannel from qiskit.pulse.instructions.instruction import Instruction from qiskit.pulse.exceptions import PulseError +from qiskit.pulse.deprecate import deprecate_pulse_func class ShiftPhase(Instruction): @@ -40,6 +41,7 @@ class ShiftPhase(Instruction): by using a ShiftPhase to update the frame tracking the qubit state. """ + @deprecate_pulse_func def __init__( self, phase: Union[complex, ParameterExpression], @@ -101,6 +103,7 @@ class SetPhase(Instruction): The ``SetPhase`` instruction sets :math:`\phi` to the instruction's ``phase`` operand. """ + @deprecate_pulse_func def __init__( self, phase: Union[complex, ParameterExpression], diff --git a/qiskit/pulse/instructions/play.py b/qiskit/pulse/instructions/play.py index 1f42b8e3a08d..3d2edca0cacb 100644 --- a/qiskit/pulse/instructions/play.py +++ b/qiskit/pulse/instructions/play.py @@ -21,6 +21,7 @@ from qiskit.pulse.exceptions import PulseError from qiskit.pulse.instructions.instruction import Instruction from qiskit.pulse.library.pulse import Pulse +from qiskit.pulse.deprecate import deprecate_pulse_func class Play(Instruction): @@ -32,6 +33,7 @@ class Play(Instruction): cycle time, dt, of the backend. """ + @deprecate_pulse_func def __init__(self, pulse: Pulse, channel: PulseChannel, name: str | None = None): """Create a new pulse instruction. diff --git a/qiskit/pulse/instructions/reference.py b/qiskit/pulse/instructions/reference.py index cf3e01f8ea6e..3863b8044682 100644 --- a/qiskit/pulse/instructions/reference.py +++ b/qiskit/pulse/instructions/reference.py @@ -17,6 +17,7 @@ from qiskit.pulse.channels import Channel from qiskit.pulse.exceptions import PulseError, UnassignedReferenceError from qiskit.pulse.instructions import instruction +from qiskit.pulse.deprecate import deprecate_pulse_func class Reference(instruction.Instruction): @@ -40,6 +41,7 @@ class Reference(instruction.Instruction): # Delimiter for tuple keys. key_delimiter = "," + @deprecate_pulse_func def __init__(self, name: str, *extra_keys: str): """Create new reference. diff --git a/qiskit/pulse/instructions/snapshot.py b/qiskit/pulse/instructions/snapshot.py index b78858b5d2c0..4edc1e7d170a 100644 --- a/qiskit/pulse/instructions/snapshot.py +++ b/qiskit/pulse/instructions/snapshot.py @@ -18,11 +18,13 @@ from qiskit.pulse.channels import SnapshotChannel from qiskit.pulse.exceptions import PulseError from qiskit.pulse.instructions.instruction import Instruction +from qiskit.pulse.deprecate import deprecate_pulse_func class Snapshot(Instruction): """An instruction targeted for simulators, to capture a moment in the simulation.""" + @deprecate_pulse_func def __init__(self, label: str, snapshot_type: str = "statevector", name: Optional[str] = None): """Create new snapshot. diff --git a/qiskit/pulse/library/symbolic_pulses.py b/qiskit/pulse/library/symbolic_pulses.py index b7ba658da1be..19e4e3715213 100644 --- a/qiskit/pulse/library/symbolic_pulses.py +++ b/qiskit/pulse/library/symbolic_pulses.py @@ -31,6 +31,7 @@ from qiskit.pulse.exceptions import PulseError from qiskit.pulse.library.pulse import Pulse from qiskit.pulse.library.waveform import Waveform +from qiskit.pulse.deprecate import deprecate_pulse_func def _lifted_gaussian( @@ -150,6 +151,7 @@ class LambdifiedExpression: _`Descriptor`: https://docs.python.org/3/reference/datamodel.html#descriptors """ + @deprecate_pulse_func def __init__(self, attribute: str): """Create new descriptor. @@ -403,6 +405,7 @@ def Sawtooth(duration, amp, freq, name): _constraints_lam = LambdifiedExpression("_constraints") _valid_amp_conditions_lam = LambdifiedExpression("_valid_amp_conditions") + @deprecate_pulse_func def __init__( self, pulse_type: str, @@ -593,6 +596,7 @@ class ScalableSymbolicPulse(SymbolicPulse): :math:'\text{amp}\times\exp\left(i\times\text{angle}\right)' is compared. """ + @deprecate_pulse_func def __init__( self, pulse_type: str, diff --git a/qiskit/pulse/library/waveform.py b/qiskit/pulse/library/waveform.py index ad852f226ac2..ae625febaf74 100644 --- a/qiskit/pulse/library/waveform.py +++ b/qiskit/pulse/library/waveform.py @@ -18,6 +18,7 @@ from qiskit.pulse.exceptions import PulseError from qiskit.pulse.library.pulse import Pulse +from qiskit.pulse.deprecate import deprecate_pulse_func class Waveform(Pulse): @@ -25,6 +26,7 @@ class Waveform(Pulse): duration of the backend cycle-time, dt. """ + @deprecate_pulse_func def __init__( self, samples: np.ndarray | list[complex], diff --git a/qiskit/pulse/parameter_manager.py b/qiskit/pulse/parameter_manager.py index e5a4a1a1d2bd..426dd59a78a2 100644 --- a/qiskit/pulse/parameter_manager.py +++ b/qiskit/pulse/parameter_manager.py @@ -67,6 +67,7 @@ _validate_parameter_vector, _validate_parameter_value, ) +from qiskit.pulse.deprecate import deprecate_pulse_func class NodeVisitor: @@ -131,6 +132,7 @@ class ParameterSetter(NodeVisitor): and assign values to operands of nodes found. """ + @deprecate_pulse_func def __init__(self, param_map: dict[ParameterExpression, ParameterValueType]): self._param_map = param_map @@ -261,6 +263,7 @@ class ParameterGetter(NodeVisitor): and add parameters found to the array. """ + @deprecate_pulse_func def __init__(self): self.parameters = set() @@ -331,6 +334,7 @@ class ParameterManager: Instruction data and its location are not directly associated with this object. """ + @deprecate_pulse_func def __init__(self): """Create new parameter table for pulse programs.""" self._parameters = set() diff --git a/qiskit/pulse/parser.py b/qiskit/pulse/parser.py index e9cd4917a7ce..5a7f9abab10a 100644 --- a/qiskit/pulse/parser.py +++ b/qiskit/pulse/parser.py @@ -24,6 +24,7 @@ from qiskit.pulse.exceptions import PulseError from qiskit.circuit import ParameterExpression +from qiskit.pulse.deprecate import deprecate_pulse_func class PulseExpression(ast.NodeTransformer): @@ -63,6 +64,7 @@ class PulseExpression(ast.NodeTransformer): _unary_ops = {ast.UAdd: operator.pos, ast.USub: operator.neg} """Valid unary operations.""" + @deprecate_pulse_func def __init__(self, source: str | ast.Expression, partial_binding: bool = False): """Create new evaluator. diff --git a/qiskit/pulse/schedule.py b/qiskit/pulse/schedule.py index c89fe3b4e306..a56e80d925da 100644 --- a/qiskit/pulse/schedule.py +++ b/qiskit/pulse/schedule.py @@ -54,6 +54,7 @@ from qiskit.pulse.reference_manager import ReferenceManager from qiskit.utils.multiprocessing import is_main_process from qiskit.utils import deprecate_arg +from qiskit.pulse.deprecate import deprecate_pulse_func Interval = Tuple[int, int] @@ -120,6 +121,7 @@ class Schedule: # Counter to count instance number. instances_counter = itertools.count() + @deprecate_pulse_func def __init__( self, *schedules: "ScheduleComponent" | tuple[int, "ScheduleComponent"], @@ -986,6 +988,7 @@ class ScheduleBlock: # Counter to count instance number. instances_counter = itertools.count() + @deprecate_pulse_func def __init__( self, name: str | None = None, metadata: dict | None = None, alignment_context=None ): diff --git a/qiskit/pulse/transforms/alignments.py b/qiskit/pulse/transforms/alignments.py index 5e383972c255..846247b280e5 100644 --- a/qiskit/pulse/transforms/alignments.py +++ b/qiskit/pulse/transforms/alignments.py @@ -20,6 +20,7 @@ from qiskit.pulse.exceptions import PulseError from qiskit.pulse.schedule import Schedule, ScheduleComponent from qiskit.pulse.utils import instruction_duration_validation +from qiskit.pulse.deprecate import deprecate_pulse_func class AlignmentKind(abc.ABC): @@ -93,6 +94,7 @@ class AlignLeft(AlignmentKind): Instructions are placed at earliest available timeslots. """ + @deprecate_pulse_func def __init__(self): """Create new left-justified context.""" super().__init__(context_params=()) @@ -160,6 +162,7 @@ class AlignRight(AlignmentKind): Instructions are placed at latest available timeslots. """ + @deprecate_pulse_func def __init__(self): """Create new right-justified context.""" super().__init__(context_params=()) @@ -229,6 +232,7 @@ class AlignSequential(AlignmentKind): No buffer time is inserted in between instructions. """ + @deprecate_pulse_func def __init__(self): """Create new sequential context.""" super().__init__(context_params=()) @@ -263,6 +267,7 @@ class AlignEquispaced(AlignmentKind): This alignment is convenient to create dynamical decoupling sequences such as PDD. """ + @deprecate_pulse_func def __init__(self, duration: int | ParameterExpression): """Create new equispaced context. @@ -348,6 +353,7 @@ def udd10_pos(j): """ + @deprecate_pulse_func def __init__(self, duration: int | ParameterExpression, func: Callable): """Create new equispaced context. diff --git a/test/python/pulse/test_block.py b/test/python/pulse/test_block.py index c6a2c2384f64..cc3b286eaa2e 100644 --- a/test/python/pulse/test_block.py +++ b/test/python/pulse/test_block.py @@ -20,11 +20,13 @@ from qiskit.pulse.exceptions import PulseError from qiskit.providers.fake_provider import FakeOpenPulse2Q from test import QiskitTestCase # pylint: disable=wrong-import-order +from qiskit.pulse.deprecate import ignore_pulse_deprecation_warnings class BaseTestBlock(QiskitTestCase): """ScheduleBlock tests.""" + @ignore_pulse_deprecation_warnings def setUp(self): super().setUp() @@ -91,6 +93,7 @@ def test_sequential_alignment(self): self.assertScheduleEqual(block, ref_sched) + @ignore_pulse_deprecation_warnings def test_equispace_alignment(self): """Test equispace alignment context.""" block = pulse.ScheduleBlock(alignment_context=self.equispaced_context) @@ -150,6 +153,7 @@ class TestBlockOperation(BaseTestBlock): This operation should be tested in `test.python.pulse.test_block.TestTransformation`. """ + @ignore_pulse_deprecation_warnings def setUp(self): super().setUp() @@ -181,6 +185,7 @@ def test_append_an_instruction_to_empty_block_inplace(self): self.assertEqual(block.blocks[0], pulse.Play(self.test_waveform0, self.d0)) + @ignore_pulse_deprecation_warnings def test_append_a_block_to_empty_block(self): """Test append another ScheduleBlock to empty block.""" block = pulse.ScheduleBlock() @@ -379,6 +384,7 @@ class TestBlockEquality(BaseTestBlock): This should be tested for each transform. """ + @ignore_pulse_deprecation_warnings def test_different_channels(self): """Test equality is False if different channels.""" block1 = pulse.ScheduleBlock() @@ -614,6 +620,7 @@ def test_instruction_out_of_order_complex_not_equal(self): class TestParametrizedBlockOperation(BaseTestBlock): """Test fundamental operation with parametrization.""" + @ignore_pulse_deprecation_warnings def setUp(self): super().setUp() @@ -639,6 +646,7 @@ def test_report_parameter_assignment(self): self.assertTrue(block.is_parameterized()) self.assertTrue(block.is_schedulable()) + @ignore_pulse_deprecation_warnings def test_cannot_get_duration_if_not_assigned(self): """Test raise error when duration is not assigned.""" block = pulse.ScheduleBlock() @@ -722,6 +730,7 @@ def test_parametrized_context(self): class TestBlockFilter(BaseTestBlock): """Test ScheduleBlock filtering methods.""" + @ignore_pulse_deprecation_warnings def test_filter_channels(self): """Test filtering over channels.""" with pulse.build() as blk: diff --git a/test/python/pulse/test_builder.py b/test/python/pulse/test_builder.py index 72a6de11ae08..483b0727cce7 100644 --- a/test/python/pulse/test_builder.py +++ b/test/python/pulse/test_builder.py @@ -14,6 +14,7 @@ from math import pi import numpy as np +from qiskit.pulse.deprecate import ignore_pulse_deprecation_warnings from qiskit import circuit, compiler, pulse from qiskit.pulse import builder, exceptions, macros @@ -108,6 +109,7 @@ def test_default_alignment_sequential(self): self.assertScheduleEqual(schedule, reference) + @ignore_pulse_deprecation_warnings def test_default_alignment_alignmentkind_instance(self): """Test default AlignmentKind instance""" d0 = pulse.DriveChannel(0) @@ -155,6 +157,7 @@ def test_align_sequential(self): self.assertScheduleEqual(schedule, reference) + @ignore_pulse_deprecation_warnings def test_align_left(self): """Test the left alignment context.""" d0 = pulse.DriveChannel(0) @@ -268,6 +271,7 @@ def test_measure_channel(self): with pulse.build(self.backend): self.assertEqual(pulse.measure_channel(0), pulse.MeasureChannel(0)) + @ignore_pulse_deprecation_warnings def test_acquire_channel(self): """Text context builder acquire channel.""" with pulse.build(self.backend): @@ -344,6 +348,7 @@ def test_play_name_argument(self): self.assertEqual(schedule.instructions[0][1].name, "new_name") + @ignore_pulse_deprecation_warnings def test_acquire_memory_slot(self): """Test acquire instruction into memory slot.""" acquire0 = pulse.AcquireChannel(0) @@ -512,6 +517,7 @@ def test_barrier_with_align_left(self): self.assertScheduleEqual(schedule, reference) + @ignore_pulse_deprecation_warnings def test_barrier_on_qubits(self): """Test barrier directive on qubits.""" with pulse.build(self.backend) as schedule: @@ -541,6 +547,7 @@ def test_trivial_barrier(self): class TestUtilities(TestBuilder): """Test builder utilities.""" + @ignore_pulse_deprecation_warnings def test_active_backend(self): """Test getting active builder backend.""" with pulse.build(self.backend): @@ -702,6 +709,7 @@ def test_measure_all(self): self.assertScheduleEqual(schedule, reference) + @ignore_pulse_deprecation_warnings def test_delay_qubit(self): """Test delaying on a qubit macro.""" with pulse.build(self.backend) as schedule: @@ -752,6 +760,7 @@ def test_delay_qubits(self): class TestBuilderComposition(TestBuilder): """Test more sophisticated composite builder examples.""" + @ignore_pulse_deprecation_warnings def test_complex_build(self): """Test a general program build with nested contexts, circuits and macros.""" @@ -849,6 +858,7 @@ def get_sched(qubit_idx: [int], backend): class TestSubroutineCall(TestBuilder): """Test for calling subroutine.""" + @ignore_pulse_deprecation_warnings def test_call(self): """Test calling schedule instruction.""" d0 = pulse.DriveChannel(0) diff --git a/test/python/pulse/test_builder_v2.py b/test/python/pulse/test_builder_v2.py index 79d3ac5b6020..94a02d50941d 100644 --- a/test/python/pulse/test_builder_v2.py +++ b/test/python/pulse/test_builder_v2.py @@ -24,11 +24,13 @@ from test import QiskitTestCase # pylint: disable=wrong-import-order from ..legacy_cmaps import MUMBAI_CMAP +from qiskit.pulse.deprecate import ignore_pulse_deprecation_warnings class TestBuilderV2(QiskitTestCase): """Test the pulse builder context with backendV2.""" + @ignore_pulse_deprecation_warnings def setUp(self): super().setUp() self.backend = GenericBackendV2( @@ -46,6 +48,7 @@ def assertScheduleEqual(self, program, target): class TestContextsV2(TestBuilderV2): """Test builder contexts.""" + @ignore_pulse_deprecation_warnings def test_phase_compensated_frequency_offset(self): """Test that the phase offset context properly compensates for phase accumulation with backendV2.""" @@ -77,6 +80,7 @@ def test_measure_channel(self): with pulse.build(self.backend): self.assertEqual(pulse.measure_channel(0), pulse.MeasureChannel(0)) + @ignore_pulse_deprecation_warnings def test_acquire_channel(self): """Text context builder acquire channel.""" with pulse.build(self.backend): @@ -91,6 +95,7 @@ def test_control_channel(self): class TestDirectivesV2(TestBuilderV2): """Test builder directives.""" + @ignore_pulse_deprecation_warnings def test_barrier_on_qubits(self): """Test barrier directive on qubits with backendV2. A part of qubits map of Mumbai @@ -122,6 +127,7 @@ def test_barrier_on_qubits(self): class TestUtilitiesV2(TestBuilderV2): """Test builder utilities.""" + @ignore_pulse_deprecation_warnings def test_active_backend(self): """Test getting active builder backend.""" with pulse.build(self.backend): @@ -248,6 +254,7 @@ def test_measure_all(self): self.assertScheduleEqual(schedule, reference) + @ignore_pulse_deprecation_warnings def test_delay_qubit(self): """Test delaying on a qubit macro.""" with pulse.build(self.backend) as schedule: diff --git a/test/python/pulse/test_calibration_entries.py b/test/python/pulse/test_calibration_entries.py index cc31789ef683..52e054625f08 100644 --- a/test/python/pulse/test_calibration_entries.py +++ b/test/python/pulse/test_calibration_entries.py @@ -33,6 +33,7 @@ from qiskit.qobj.converters.pulse_instruction import QobjToInstructionConverter from qiskit.qobj.pulse_qobj import PulseLibraryItem, PulseQobjInstruction from test import QiskitTestCase # pylint: disable=wrong-import-order +from qiskit.pulse.deprecate import ignore_pulse_deprecation_warnings class TestSchedule(QiskitTestCase): @@ -58,6 +59,7 @@ def test_add_schedule(self): schedule_ref = program self.assertEqual(schedule_to_test, schedule_ref) + @ignore_pulse_deprecation_warnings def test_add_block(self): """Basic test pulse Schedule format.""" program = ScheduleBlock() @@ -184,6 +186,7 @@ def test_equality(self): class TestCallable(QiskitTestCase): """Test case for the CallableDef.""" + @ignore_pulse_deprecation_warnings def test_add_callable(self): """Basic test callable format.""" program = Schedule() @@ -288,6 +291,7 @@ def setUp(self): ] ) + @ignore_pulse_deprecation_warnings def test_add_qobj(self): """Basic test PulseQobj format.""" with self.assertWarns(DeprecationWarning): diff --git a/test/python/pulse/test_channels.py b/test/python/pulse/test_channels.py index 59c4d15bf67b..8b50e8ba0ec6 100644 --- a/test/python/pulse/test_channels.py +++ b/test/python/pulse/test_channels.py @@ -28,6 +28,7 @@ PulseError, ) from test import QiskitTestCase # pylint: disable=wrong-import-order +from qiskit.pulse.deprecate import ignore_pulse_deprecation_warnings class TestChannel(QiskitTestCase): @@ -58,6 +59,7 @@ def test_default(self): self.assertEqual(acquire_channel.index, 123) self.assertEqual(acquire_channel.name, "a123") + @ignore_pulse_deprecation_warnings def test_channel_hash(self): """Test hashing for acquire channel.""" acq_channel_1 = AcquireChannel(123) @@ -81,6 +83,7 @@ def test_cannot_be_instantiated(self): class TestMemorySlot(QiskitTestCase): """MemorySlot tests.""" + @ignore_pulse_deprecation_warnings def test_default(self): """Test default memory slot.""" memory_slot = MemorySlot(123) @@ -100,6 +103,7 @@ def test_validation(self): class TestRegisterSlot(QiskitTestCase): """RegisterSlot tests.""" + @ignore_pulse_deprecation_warnings def test_default(self): """Test default register slot.""" register_slot = RegisterSlot(123) @@ -119,6 +123,7 @@ def test_validation(self): class TestSnapshotChannel(QiskitTestCase): """SnapshotChannel tests.""" + @ignore_pulse_deprecation_warnings def test_default(self): """Test default snapshot channel.""" snapshot_channel = SnapshotChannel() @@ -131,6 +136,7 @@ def test_default(self): class TestDriveChannel(QiskitTestCase): """DriveChannel tests.""" + @ignore_pulse_deprecation_warnings def test_default(self): """Test default drive channel.""" drive_channel = DriveChannel(123) @@ -149,6 +155,7 @@ def test_validation(self): class TestControlChannel(QiskitTestCase): """ControlChannel tests.""" + @ignore_pulse_deprecation_warnings def test_default(self): """Test default control channel.""" control_channel = ControlChannel(123) @@ -167,6 +174,7 @@ def test_validation(self): class TestMeasureChannel(QiskitTestCase): """MeasureChannel tests.""" + @ignore_pulse_deprecation_warnings def test_default(self): """Test default measure channel.""" measure_channel = MeasureChannel(123) diff --git a/test/python/pulse/test_experiment_configurations.py b/test/python/pulse/test_experiment_configurations.py index 8d6a93b39eac..51e3e2184531 100644 --- a/test/python/pulse/test_experiment_configurations.py +++ b/test/python/pulse/test_experiment_configurations.py @@ -18,11 +18,13 @@ from qiskit.pulse.exceptions import PulseError from qiskit.pulse import LoConfig, LoRange, Kernel, Discriminator from test import QiskitTestCase # pylint: disable=wrong-import-order +from qiskit.pulse.deprecate import ignore_pulse_deprecation_warnings class TestLoRange(QiskitTestCase): """Test LO LoRange.""" + @ignore_pulse_deprecation_warnings def test_properties_includes_and_eq(self): """Test creation of LoRange. Test upper/lower bounds and includes. Test __eq__ for two same and different LoRange's. @@ -43,6 +45,7 @@ def test_properties_includes_and_eq(self): class TestLoConfig(QiskitTestCase): """LoConfig tests.""" + @ignore_pulse_deprecation_warnings def test_can_create_empty_user_lo_config(self): """Test if a LoConfig can be created without no arguments.""" user_lo_config = LoConfig() @@ -97,6 +100,7 @@ def test_get_channel_lo(self): class TestKernel(QiskitTestCase): """Test Kernel.""" + @ignore_pulse_deprecation_warnings def test_eq(self): """Test if two kernels are equal.""" kernel_a = Kernel( @@ -157,6 +161,7 @@ def test_neq_nested_params(self): class TestDiscriminator(QiskitTestCase): """Test Discriminator.""" + @ignore_pulse_deprecation_warnings def test_eq(self): """Test if two discriminators are equal.""" discriminator_a = Discriminator( diff --git a/test/python/pulse/test_instruction_schedule_map.py b/test/python/pulse/test_instruction_schedule_map.py index d1610d7ebcc0..8e9af4456fdd 100644 --- a/test/python/pulse/test_instruction_schedule_map.py +++ b/test/python/pulse/test_instruction_schedule_map.py @@ -35,11 +35,13 @@ from qiskit.qobj.converters import QobjToInstructionConverter from qiskit.providers.fake_provider import FakeOpenPulse2Q, Fake7QPulseV1 from test import QiskitTestCase # pylint: disable=wrong-import-order +from qiskit.pulse.deprecate import ignore_pulse_deprecation_warnings class TestInstructionScheduleMap(QiskitTestCase): """Test the InstructionScheduleMap.""" + @ignore_pulse_deprecation_warnings def test_add(self): """Test add, and that errors are raised when expected.""" sched = Schedule() diff --git a/test/python/pulse/test_instructions.py b/test/python/pulse/test_instructions.py index f0bdd165db08..a7dbc58f9012 100644 --- a/test/python/pulse/test_instructions.py +++ b/test/python/pulse/test_instructions.py @@ -17,11 +17,13 @@ from qiskit import circuit from qiskit.pulse import channels, configuration, instructions, library, exceptions from test import QiskitTestCase # pylint: disable=wrong-import-order +from qiskit.pulse.deprecate import ignore_pulse_deprecation_warnings class TestAcquire(QiskitTestCase): """Acquisition tests.""" + @ignore_pulse_deprecation_warnings def test_can_construct_valid_acquire_command(self): """Test if valid acquire command can be constructed.""" kernel_opts = {"start_window": 0, "stop_window": 10} @@ -88,6 +90,7 @@ def test_instructions_hash(self): class TestDelay(QiskitTestCase): """Delay tests.""" + @ignore_pulse_deprecation_warnings def test_delay(self): """Test delay.""" delay = instructions.Delay(10, channels.DriveChannel(0), name="test_name") @@ -124,6 +127,7 @@ def test_operator_delay(self): class TestSetFrequency(QiskitTestCase): """Set frequency tests.""" + @ignore_pulse_deprecation_warnings def test_freq(self): """Test set frequency basic functionality.""" set_freq = instructions.SetFrequency(4.5e9, channels.DriveChannel(1), name="test") @@ -140,6 +144,7 @@ def test_freq(self): ) self.assertEqual(repr(set_freq), "SetFrequency(4500000000.0, DriveChannel(1), name='test')") + @ignore_pulse_deprecation_warnings def test_freq_non_pulse_channel(self): """Test set frequency constructor with illegal channel""" with self.assertRaises(exceptions.PulseError): @@ -176,6 +181,7 @@ def test_shift_freq(self): repr(shift_freq), "ShiftFrequency(4500000000.0, DriveChannel(1), name='test')" ) + @ignore_pulse_deprecation_warnings def test_freq_non_pulse_channel(self): """Test shift frequency constructor with illegal channel""" with self.assertRaises(exceptions.PulseError): @@ -194,6 +200,7 @@ def test_parameter_expression(self): class TestSetPhase(QiskitTestCase): """Test the instruction construction.""" + @ignore_pulse_deprecation_warnings def test_default(self): """Test basic SetPhase.""" set_phase = instructions.SetPhase(1.57, channels.DriveChannel(0)) @@ -229,6 +236,7 @@ def test_parameter_expression(self): class TestShiftPhase(QiskitTestCase): """Test the instruction construction.""" + @ignore_pulse_deprecation_warnings def test_default(self): """Test basic ShiftPhase.""" shift_phase = instructions.ShiftPhase(1.57, channels.DriveChannel(0)) @@ -264,6 +272,7 @@ def test_parameter_expression(self): class TestSnapshot(QiskitTestCase): """Snapshot tests.""" + @ignore_pulse_deprecation_warnings def test_default(self): """Test default snapshot.""" snapshot = instructions.Snapshot(label="test_name", snapshot_type="state") @@ -279,12 +288,14 @@ def test_default(self): class TestPlay(QiskitTestCase): """Play tests.""" + @ignore_pulse_deprecation_warnings def setUp(self): """Setup play tests.""" super().setUp() self.duration = 4 self.pulse_op = library.Waveform([1.0] * self.duration, name="test") + @ignore_pulse_deprecation_warnings def test_play(self): """Test basic play instruction.""" play = instructions.Play(self.pulse_op, channels.DriveChannel(1)) @@ -307,6 +318,7 @@ def test_play_non_pulse_ch_raises(self): class TestDirectives(QiskitTestCase): """Test pulse directives.""" + @ignore_pulse_deprecation_warnings def test_relative_barrier(self): """Test the relative barrier directive.""" a0 = channels.AcquireChannel(0) diff --git a/test/python/pulse/test_macros.py b/test/python/pulse/test_macros.py index 6d87320cf480..b1595e7e006d 100644 --- a/test/python/pulse/test_macros.py +++ b/test/python/pulse/test_macros.py @@ -26,11 +26,13 @@ from qiskit.pulse.exceptions import PulseError from qiskit.providers.fake_provider import FakeOpenPulse2Q, Fake27QPulseV1, GenericBackendV2 from test import QiskitTestCase # pylint: disable=wrong-import-order +from qiskit.pulse.deprecate import ignore_pulse_deprecation_warnings class TestMeasure(QiskitTestCase): """Pulse measure macro.""" + @ignore_pulse_deprecation_warnings def setUp(self): super().setUp() with self.assertWarns(DeprecationWarning): @@ -91,6 +93,7 @@ def test_measure_with_custom_inst_map(self): with self.assertRaises(PulseError): macros.measure(qubits=[0], measure_name="name", inst_map=inst_map, meas_map=[[0]]) + @ignore_pulse_deprecation_warnings def test_fail_measure(self): """Test failing measure.""" with self.assertRaises(PulseError): @@ -213,6 +216,7 @@ def test_output_with_multiple_measure_v1_and_measure_v2(self): class TestMeasureAll(QiskitTestCase): """Pulse measure all macro.""" + @ignore_pulse_deprecation_warnings def setUp(self): super().setUp() with self.assertWarns(DeprecationWarning): @@ -224,6 +228,7 @@ def setUp(self): seed=42, ) + @ignore_pulse_deprecation_warnings def test_measure_all(self): """Test measure_all function.""" sched = macros.measure_all(self.backend_v1) diff --git a/test/python/pulse/test_parameter_manager.py b/test/python/pulse/test_parameter_manager.py index 0b91aaeaab4a..92a44ef6e7fd 100644 --- a/test/python/pulse/test_parameter_manager.py +++ b/test/python/pulse/test_parameter_manager.py @@ -27,11 +27,13 @@ from qiskit.pulse.transforms import AlignEquispaced, AlignLeft, inline_subroutines from qiskit.pulse.utils import format_parameter_value from test import QiskitTestCase # pylint: disable=wrong-import-order +from qiskit.pulse.deprecate import ignore_pulse_deprecation_warnings class ParameterTestBase(QiskitTestCase): """A base class for parameter manager unittest, providing test schedule.""" + @ignore_pulse_deprecation_warnings def setUp(self): """Just some useful, reusable Parameters, constants, schedules.""" super().setUp() @@ -103,6 +105,7 @@ def setUp(self): class TestParameterGetter(ParameterTestBase): """Test getting parameters.""" + @ignore_pulse_deprecation_warnings def test_get_parameter_from_channel(self): """Test get parameters from channel.""" test_obj = pulse.DriveChannel(self.ch1 + self.ch2) @@ -125,6 +128,7 @@ def test_get_parameter_from_pulse(self): self.assertSetEqual(visitor.parameters, ref_params) + @ignore_pulse_deprecation_warnings def test_get_parameter_from_acquire(self): """Test get parameters from acquire instruction.""" test_obj = pulse.Acquire(16000, pulse.AcquireChannel(self.ch1), pulse.MemorySlot(self.ch1)) @@ -331,6 +335,7 @@ def test_complex_value_to_parameter(self): self.assertEqual(assigned.amp, 0.1j) + @ignore_pulse_deprecation_warnings def test_complex_parameter_expression(self): """Test assignment of complex-valued parameter expression to parameter, but raises PendingDeprecationWarning.""" @@ -454,6 +459,7 @@ def test_set_parameter_to_complex_schedule(self): class TestAssignFromProgram(QiskitTestCase): """Test managing parameters from programs. Parameter manager is implicitly called.""" + @ignore_pulse_deprecation_warnings def test_attribute_parameters(self): """Test the ``parameter`` attributes.""" sigma = Parameter("sigma") @@ -619,6 +625,7 @@ def test_overlapping_on_multiple_assignment(self): with self.assertRaises(PulseError): schedule.assign_parameters({param_idx2: 2}) + @ignore_pulse_deprecation_warnings def test_cannot_build_schedule_with_unassigned_duration(self): """Test we cannot build schedule with parameterized instructions""" dur = Parameter("dur") diff --git a/test/python/pulse/test_parser.py b/test/python/pulse/test_parser.py index 8fb491b9da74..45cf35fbeac1 100644 --- a/test/python/pulse/test_parser.py +++ b/test/python/pulse/test_parser.py @@ -15,6 +15,7 @@ from qiskit.pulse.parser import parse_string_expr from qiskit.pulse.exceptions import PulseError from test import QiskitTestCase # pylint: disable=wrong-import-order +from qiskit.pulse.deprecate import ignore_pulse_deprecation_warnings class TestInstructionToQobjConverter(QiskitTestCase): @@ -212,6 +213,7 @@ def test_partial_binding(self): self.assertEqual(bound_four_new(P5=5), -2.925) self.assertEqual(bound_four_new(5), -2.925) + @ignore_pulse_deprecation_warnings def test_argument_duplication(self): """Test duplication of *args and **kwargs.""" diff --git a/test/python/pulse/test_pulse_lib.py b/test/python/pulse/test_pulse_lib.py index 9c57579d0bf1..82ff640bd335 100644 --- a/test/python/pulse/test_pulse_lib.py +++ b/test/python/pulse/test_pulse_lib.py @@ -39,6 +39,7 @@ ) from qiskit.pulse import functional_pulse, PulseError from test import QiskitTestCase # pylint: disable=wrong-import-order +from qiskit.pulse.deprecate import ignore_pulse_deprecation_warnings class TestWaveform(QiskitTestCase): @@ -85,6 +86,7 @@ def test_type_casting(self): sample_pulse_list = Waveform(samples_list) self.assertEqual(sample_pulse_list.samples.dtype, np.complex128) + @ignore_pulse_deprecation_warnings def test_pulse_limits(self): """Test that limits of pulse norm of one are enforced properly.""" @@ -586,6 +588,7 @@ def test_class_level_limit_amplitude(self): waveform = GaussianSquareDrag(duration=100, sigma=1.0, amp=1.1, beta=0.1, width=10) self.assertGreater(np.abs(waveform.amp), 1.0) + @ignore_pulse_deprecation_warnings def test_class_level_disable_validation(self): """Test that pulse validation can be disabled on the class level. @@ -833,6 +836,7 @@ class TestFunctionalPulse(QiskitTestCase): """Waveform tests.""" # pylint: disable=invalid-name + @ignore_pulse_deprecation_warnings def test_gaussian(self): """Test gaussian pulse.""" @@ -888,6 +892,7 @@ def test_scalable_comparison(self): gaussian1._params["sigma"] = 10 self.assertNotEqual(gaussian1, gaussian2) + @ignore_pulse_deprecation_warnings def test_complex_amp_error(self): """Test that initializing a pulse with complex amp raises an error""" with self.assertRaises(PulseError): diff --git a/test/python/pulse/test_reference.py b/test/python/pulse/test_reference.py index 3d7603461756..8fdff3eaaa6b 100644 --- a/test/python/pulse/test_reference.py +++ b/test/python/pulse/test_reference.py @@ -18,6 +18,7 @@ from qiskit.pulse import ScheduleBlock, builder from qiskit.pulse.transforms import inline_subroutines from test import QiskitTestCase # pylint: disable=wrong-import-order +from qiskit.pulse.deprecate import ignore_pulse_deprecation_warnings class TestReference(QiskitTestCase): @@ -247,6 +248,7 @@ def test_calling_same_schedule_with_different_assignment(self): self.assertEqual(len(sched_z1.references), 2) + @ignore_pulse_deprecation_warnings def test_alignment_context(self): """Test nested alignment context. @@ -433,6 +435,7 @@ def test_assign_existing_reference(self): class TestSubroutineWithCXGate(QiskitTestCase): """Test called program scope with practical example of building fully parametrized CX gate.""" + @ignore_pulse_deprecation_warnings def setUp(self): super().setUp() @@ -537,6 +540,7 @@ def test_lazy_ecr(self): params = sched.get_parameters(parameter_name="amp") self.assertEqual(len(params), 2) + @ignore_pulse_deprecation_warnings def test_cnot(self): """Integration test with CNOT schedule construction.""" # echoed cross resonance diff --git a/test/python/pulse/test_samplers.py b/test/python/pulse/test_samplers.py index 4e6ab46737d6..9238d81a4aa3 100644 --- a/test/python/pulse/test_samplers.py +++ b/test/python/pulse/test_samplers.py @@ -18,6 +18,7 @@ from qiskit.pulse import library from qiskit.pulse.library import samplers from test import QiskitTestCase # pylint: disable=wrong-import-order +from qiskit.pulse.deprecate import ignore_pulse_deprecation_warnings def linear(times: np.ndarray, m: float, b: float = 0.1) -> np.ndarray: @@ -82,6 +83,7 @@ def test_sampler_name(self): self.assertIsInstance(pulse, library.Waveform) self.assertEqual(pulse.name, "test") + @ignore_pulse_deprecation_warnings def test_default_arg_sampler(self): """Test that default arguments work with sampler.""" m = 0.1 diff --git a/test/python/pulse/test_schedule.py b/test/python/pulse/test_schedule.py index 5e5676e7c2d9..a8a382d5f698 100644 --- a/test/python/pulse/test_schedule.py +++ b/test/python/pulse/test_schedule.py @@ -47,6 +47,7 @@ from qiskit.pulse.schedule import Schedule, _overlaps, _find_insertion_index from qiskit.providers.fake_provider import FakeOpenPulse2Q from test import QiskitTestCase # pylint: disable=wrong-import-order +from qiskit.pulse.deprecate import ignore_pulse_deprecation_warnings class BaseTestSchedule(QiskitTestCase): @@ -232,6 +233,7 @@ def test_flat_instruction_sequence_returns_instructions(self): for _, instr in sched.instructions: self.assertIsInstance(instr, Instruction) + @ignore_pulse_deprecation_warnings def test_absolute_start_time_of_grandchild(self): """Test correct calculation of start time of grandchild of a schedule.""" lp0 = self.linear(duration=10, slope=0.02, intercept=0.01) @@ -514,6 +516,7 @@ def test_replace_schedule(self): sched.replace(old, new, inplace=True) self.assertEqual(sched, ref_sched) + @ignore_pulse_deprecation_warnings def test_replace_fails_on_overlap(self): """Test that replacement fails on overlap.""" old = Play(Constant(20, 1.0), DriveChannel(0)) @@ -575,6 +578,7 @@ def test_delay_control_channel(self): sched = Delay(self.delay_time, control_ch) | Play(pulse, control_ch) self.assertIsInstance(sched, Schedule) + @ignore_pulse_deprecation_warnings def test_delay_acquire_channel(self): """Test Delay on DriveChannel""" @@ -803,6 +807,7 @@ def test_filter_multiple(self): self.assertIsInstance(inst, Acquire) self.assertTrue(len(filtered.instructions), 2) + @ignore_pulse_deprecation_warnings def test_custom_filters(self): """Test custom filters.""" lp0 = self.linear(duration=3, slope=0.2, intercept=0.1) @@ -885,6 +890,7 @@ def _filter_and_test_consistency(self, schedule: Schedule, *args, **kwargs): class TestScheduleEquality(BaseTestSchedule): """Test equality of schedules.""" + @ignore_pulse_deprecation_warnings def test_different_channels(self): """Test equality is False if different channels.""" self.assertNotEqual( diff --git a/test/python/pulse/test_transforms.py b/test/python/pulse/test_transforms.py index c16405cff4d1..7cd306567dcd 100644 --- a/test/python/pulse/test_transforms.py +++ b/test/python/pulse/test_transforms.py @@ -39,11 +39,13 @@ from qiskit.pulse.instructions import directives from qiskit.providers.fake_provider import FakeOpenPulse2Q from test import QiskitTestCase # pylint: disable=wrong-import-order +from qiskit.pulse.deprecate import ignore_pulse_deprecation_warnings class TestAlignMeasures(QiskitTestCase): """Test the helper function which aligns acquires.""" + @ignore_pulse_deprecation_warnings def setUp(self): super().setUp() with self.assertWarns(DeprecationWarning): @@ -134,6 +136,7 @@ def test_multiple_acquires(self): self.assertEqual(aligned, ref) + @ignore_pulse_deprecation_warnings def test_align_across_schedules(self): """Test that acquires are aligned together across multiple schedules.""" sched1 = pulse.Schedule(name="fake_experiment") @@ -201,6 +204,7 @@ def test_measurement_at_zero(self): class TestAddImplicitAcquires(QiskitTestCase): """Test the helper function which makes implicit acquires explicit.""" + @ignore_pulse_deprecation_warnings def setUp(self): super().setUp() with self.assertWarns(DeprecationWarning): @@ -224,6 +228,7 @@ def test_add_implicit(self): acquired_qubits.add(inst.acquire.index) self.assertEqual(acquired_qubits, {0, 1}) + @ignore_pulse_deprecation_warnings def test_add_across_meas_map_sublists(self): """Test that implicit acquires in separate meas map sublists are all added.""" sched = transforms.add_implicit_acquires(self.sched, [[0, 2], [1, 3]]) @@ -361,6 +366,7 @@ def test_padding_prepended_delay(self): self.assertEqual(transforms.pad(sched, until=30, inplace=True), ref_sched) + @ignore_pulse_deprecation_warnings def test_pad_no_delay_on_classical_io_channels(self): """Test padding does not apply to classical IO channels.""" delay = 10 @@ -496,6 +502,7 @@ def test_sample_pulses_with_tolerance(self): self.assertEqual(len(original_pulse_ids), 2) self.assertEqual(len(compressed_pulse_ids), 1) + @ignore_pulse_deprecation_warnings def test_multiple_schedules(self): """Test multiple schedules.""" schedules = [] @@ -517,6 +524,7 @@ def test_multiple_schedules(self): class TestAlignSequential(QiskitTestCase): """Test sequential alignment transform.""" + @ignore_pulse_deprecation_warnings def test_align_sequential(self): """Test sequential alignment without a barrier.""" context = transforms.AlignSequential() @@ -565,6 +573,7 @@ def test_align_sequential_with_barrier(self): class TestAlignLeft(QiskitTestCase): """Test left alignment transform.""" + @ignore_pulse_deprecation_warnings def test_align_left(self): """Test left alignment without a barrier.""" context = transforms.AlignLeft() @@ -628,6 +637,7 @@ def test_align_left_with_barrier(self): class TestAlignRight(QiskitTestCase): """Test right alignment transform.""" + @ignore_pulse_deprecation_warnings def test_align_right(self): """Test right alignment without a barrier.""" context = transforms.AlignRight() @@ -692,6 +702,7 @@ def test_align_right_with_barrier(self): class TestAlignEquispaced(QiskitTestCase): """Test equispaced alignment transform.""" + @ignore_pulse_deprecation_warnings def test_equispaced_with_short_duration(self): """Test equispaced context with duration shorter than the schedule duration.""" context = transforms.AlignEquispaced(duration=20) @@ -710,6 +721,7 @@ def test_equispaced_with_short_duration(self): self.assertEqual(schedule, reference) + @ignore_pulse_deprecation_warnings def test_equispaced_with_longer_duration(self): """Test equispaced context with duration longer than the schedule duration.""" context = transforms.AlignEquispaced(duration=50) @@ -775,6 +787,7 @@ def _position(ind): """Returns 0.25, 0.5, 0.75 for ind = 1, 2, 3.""" return ind / (3 + 1) + @ignore_pulse_deprecation_warnings def test_numerical_with_short_duration(self): """Test numerical alignment context with duration shorter than the schedule duration.""" context = transforms.AlignFunc(duration=20, func=self._position) @@ -793,6 +806,7 @@ def test_numerical_with_short_duration(self): self.assertEqual(schedule, reference) + @ignore_pulse_deprecation_warnings def test_numerical_with_longer_duration(self): """Test numerical alignment context with duration longer than the schedule duration.""" context = transforms.AlignFunc(duration=80, func=self._position) @@ -815,6 +829,7 @@ def test_numerical_with_longer_duration(self): class TestFlatten(QiskitTestCase): """Test flattening transform.""" + @ignore_pulse_deprecation_warnings def test_flatten(self): """Test the flatten transform.""" context_left = transforms.AlignLeft() @@ -864,6 +879,7 @@ def channels(self): class TestRemoveDirectives(QiskitTestCase): """Test removing of directives.""" + @ignore_pulse_deprecation_warnings def test_remove_directives(self): """Test that all directives are removed.""" d0 = pulse.DriveChannel(0) @@ -884,6 +900,7 @@ def test_remove_directives(self): class TestRemoveTrivialBarriers(QiskitTestCase): """Test scheduling transforms.""" + @ignore_pulse_deprecation_warnings def test_remove_trivial_barriers(self): """Test that trivial barriers are properly removed.""" schedule = pulse.Schedule() From d0de19f5d1b557568cb9102ce47b1ceddc1e7029 Mon Sep 17 00:00:00 2001 From: Eli Arbel Date: Sun, 22 Sep 2024 17:14:39 +0300 Subject: [PATCH 03/23] Deprecate some functionality that uses Pulse --- qiskit/assembler/assemble_schedules.py | 2 ++ qiskit/circuit/quantumcircuit.py | 7 ++++++- qiskit/compiler/transpiler.py | 3 ++- qiskit/dagcircuit/dagdependency.py | 3 +++ qiskit/providers/backend.py | 6 ++++++ qiskit/providers/backend_compat.py | 7 +++++++ qiskit/providers/fake_provider/generic_backend_v2.py | 10 ++++++++++ .../providers/fake_provider/utils/backend_converter.py | 2 ++ qiskit/providers/models/pulsedefaults.py | 2 ++ qiskit/qobj/converters/pulse_instruction.py | 2 ++ qiskit/scheduler/config.py | 2 ++ qiskit/transpiler/passes/calibration/pulse_gate.py | 2 ++ .../scheduling/alignments/pulse_gate_validation.py | 2 ++ qiskit/transpiler/target.py | 4 ++++ qiskit/visualization/pulse_v2/core.py | 3 +++ qiskit/visualization/pulse_v2/device_info.py | 3 +++ qiskit/visualization/pulse_v2/drawings.py | 5 +++++ qiskit/visualization/pulse_v2/events.py | 2 ++ qiskit/visualization/pulse_v2/generators/barrier.py | 2 ++ qiskit/visualization/pulse_v2/generators/chart.py | 5 +++++ qiskit/visualization/pulse_v2/generators/frame.py | 6 ++++++ qiskit/visualization/pulse_v2/generators/snapshot.py | 3 +++ qiskit/visualization/pulse_v2/generators/waveform.py | 4 ++++ qiskit/visualization/pulse_v2/interface.py | 2 ++ qiskit/visualization/pulse_v2/layouts.py | 8 ++++++++ qiskit/visualization/pulse_v2/plotters/base_plotter.py | 2 ++ qiskit/visualization/pulse_v2/plotters/matplotlib.py | 3 ++- qiskit/visualization/pulse_v2/stylesheet.py | 5 +++++ 28 files changed, 104 insertions(+), 3 deletions(-) diff --git a/qiskit/assembler/assemble_schedules.py b/qiskit/assembler/assemble_schedules.py index 2d5ebefa2fd1..3e82bb6228e5 100644 --- a/qiskit/assembler/assemble_schedules.py +++ b/qiskit/assembler/assemble_schedules.py @@ -22,8 +22,10 @@ from qiskit.pulse import instructions, transforms, library, schedule, channels from qiskit.qobj import utils as qobj_utils, converters from qiskit.qobj.converters.pulse_instruction import ParametricPulseShapes +from qiskit.utils.deprecate_pulse import _deprecate_pulse_dependency +@_deprecate_pulse_dependency def assemble_schedules( schedules: List[ Union[ diff --git a/qiskit/circuit/quantumcircuit.py b/qiskit/circuit/quantumcircuit.py index 780efba5faf1..c9c8ec65f7f3 100644 --- a/qiskit/circuit/quantumcircuit.py +++ b/qiskit/circuit/quantumcircuit.py @@ -69,6 +69,8 @@ from .quantumcircuitdata import QuantumCircuitData, CircuitInstruction from .delay import Delay from .store import Store +from qiskit.utils.deprecate_pulse import _deprecate_pulse_dependency + if typing.TYPE_CHECKING: import qiskit # pylint: disable=cyclic-import @@ -1152,7 +1154,7 @@ def __init__( """The unit that :attr:`duration` is specified in.""" self.metadata = {} if metadata is None else metadata """Arbitrary user-defined metadata for the circuit. - + Qiskit will not examine the content of this mapping, but it will pass it through the transpiler and reattach it to the output, so you can track your own metadata.""" @@ -1321,6 +1323,7 @@ def op_start_times(self) -> list[int]: return self._op_start_times @property + @_deprecate_pulse_dependency def calibrations(self) -> dict: """Return calibration dictionary. @@ -1330,6 +1333,7 @@ def calibrations(self) -> dict: return dict(self._calibrations) @calibrations.setter + @_deprecate_pulse_dependency def calibrations(self, calibrations: dict): """Set the circuit calibration data from a dictionary of calibration definition. @@ -6466,6 +6470,7 @@ def continue_loop(self) -> InstructionSet: ContinueLoopOp(self.num_qubits, self.num_clbits), self.qubits, self.clbits, copy=False ) + @_deprecate_pulse_dependency def add_calibration( self, gate: Union[Gate, str], diff --git a/qiskit/compiler/transpiler.py b/qiskit/compiler/transpiler.py index 5e2dcf8a1560..fbde378c8e12 100644 --- a/qiskit/compiler/transpiler.py +++ b/qiskit/compiler/transpiler.py @@ -32,12 +32,13 @@ from qiskit.transpiler.passes.synthesis.high_level_synthesis import HLSConfig from qiskit.transpiler.preset_passmanagers import generate_preset_pass_manager from qiskit.transpiler.target import Target +from qiskit.utils.deprecate_pulse import _deprecate_pulse_arg logger = logging.getLogger(__name__) _CircuitT = TypeVar("_CircuitT", bound=Union[QuantumCircuit, List[QuantumCircuit]]) - +@_deprecate_pulse_arg("inst_map") def transpile( # pylint: disable=too-many-return-statements circuits: _CircuitT, backend: Optional[Backend] = None, diff --git a/qiskit/dagcircuit/dagdependency.py b/qiskit/dagcircuit/dagdependency.py index 63b91f920631..45de998c02ae 100644 --- a/qiskit/dagcircuit/dagdependency.py +++ b/qiskit/dagcircuit/dagdependency.py @@ -29,6 +29,7 @@ from qiskit.dagcircuit.exceptions import DAGDependencyError from qiskit.dagcircuit.dagdepnode import DAGDepNode from qiskit.pulse import Schedule +from qiskit.utils.deprecate_pulse import _deprecate_pulse_dependency if typing.TYPE_CHECKING: from qiskit.circuit.parameterexpression import ParameterExpression @@ -146,6 +147,7 @@ def global_phase(self, angle: float | ParameterExpression): self._global_phase = angle % (2 * math.pi) @property + @_deprecate_pulse_dependency def calibrations(self) -> dict[str, dict[tuple, Schedule]]: """Return calibration dictionary. @@ -155,6 +157,7 @@ def calibrations(self) -> dict[str, dict[tuple, Schedule]]: return dict(self._calibrations) @calibrations.setter + @_deprecate_pulse_dependency def calibrations(self, calibrations: dict[str, dict[tuple, Schedule]]): """Set the circuit calibration data from a dictionary of calibration definition. diff --git a/qiskit/providers/backend.py b/qiskit/providers/backend.py index 6d9ed51043ec..08e21f79c24e 100644 --- a/qiskit/providers/backend.py +++ b/qiskit/providers/backend.py @@ -24,6 +24,7 @@ from qiskit.providers.models.backendstatus import BackendStatus from qiskit.circuit.gate import Instruction from qiskit.utils import deprecate_func +from qiskit.utils.deprecate_pulse import _deprecate_pulse_dependency class Backend: @@ -485,6 +486,7 @@ def meas_map(self) -> List[List[int]]: raise NotImplementedError @property + @_deprecate_pulse_dependency def instruction_schedule_map(self): """Return the :class:`~qiskit.pulse.InstructionScheduleMap` for the instructions defined in this backend's target.""" @@ -524,6 +526,7 @@ def qubit_properties( return self.target.qubit_properties[qubit] return [self.target.qubit_properties[q] for q in qubit] + @_deprecate_pulse_dependency def drive_channel(self, qubit: int): """Return the drive channel for the given qubit. @@ -539,6 +542,7 @@ def drive_channel(self, qubit: int): """ raise NotImplementedError + @_deprecate_pulse_dependency def measure_channel(self, qubit: int): """Return the measure stimulus channel for the given qubit. @@ -554,6 +558,7 @@ def measure_channel(self, qubit: int): """ raise NotImplementedError + @_deprecate_pulse_dependency def acquire_channel(self, qubit: int): """Return the acquisition channel for the given qubit. @@ -569,6 +574,7 @@ def acquire_channel(self, qubit: int): """ raise NotImplementedError + @_deprecate_pulse_dependency def control_channel(self, qubits: Iterable[int]): """Return the secondary drive channel for the given qubit diff --git a/qiskit/providers/backend_compat.py b/qiskit/providers/backend_compat.py index f554897d34c4..3070fc188d90 100644 --- a/qiskit/providers/backend_compat.py +++ b/qiskit/providers/backend_compat.py @@ -25,10 +25,13 @@ from qiskit.providers.models.pulsedefaults import PulseDefaults from qiskit.providers.options import Options from qiskit.providers.exceptions import BackendPropertyError +from qiskit.utils.deprecate_pulse import _deprecate_pulse_arg, _deprecate_pulse_dependency + logger = logging.getLogger(__name__) +@_deprecate_pulse_arg("defaults") def convert_to_target( configuration: BackendConfiguration, properties: BackendProperties = None, @@ -436,15 +439,19 @@ def dtm(self) -> float: def meas_map(self) -> List[List[int]]: return self._config.meas_map + @_deprecate_pulse_dependency def drive_channel(self, qubit: int): return self._config.drive(qubit) + @_deprecate_pulse_dependency def measure_channel(self, qubit: int): return self._config.measure(qubit) + @_deprecate_pulse_dependency def acquire_channel(self, qubit: int): return self._config.acquire(qubit) + @_deprecate_pulse_dependency def control_channel(self, qubits: Iterable[int]): return self._config.control(qubits) diff --git a/qiskit/providers/fake_provider/generic_backend_v2.py b/qiskit/providers/fake_provider/generic_backend_v2.py index 770c8762152e..43bdb1008bbd 100644 --- a/qiskit/providers/fake_provider/generic_backend_v2.py +++ b/qiskit/providers/fake_provider/generic_backend_v2.py @@ -42,6 +42,7 @@ from qiskit.pulse.calibration_entries import PulseQobjDef from qiskit.providers.models.pulsedefaults import MeasurementKernel, Discriminator from qiskit.qobj.pulse_qobj import QobjMeasurementOption +from qiskit.utils.deprecate_pulse import _deprecate_pulse_dependency, _deprecate_pulse_arg # Noise default values/ranges for duration and error of supported # instructions. There are two possible formats: @@ -87,6 +88,7 @@ class PulseDefaults: _data = {} + @_deprecate_pulse_dependency def __init__( self, qubit_freq_est: List[float], @@ -242,6 +244,7 @@ class PulseLibraryItem: """INTERNAL - An item in a pulse library.""" # Copy from the deprecated from qiskit.qobj.PulseLibraryItem + @_deprecate_pulse_dependency def __init__(self, name, samples): """Instantiate a pulse library item. @@ -310,6 +313,7 @@ class PulseQobjInstruction: "parameters", ] + @_deprecate_pulse_dependency def __init__( self, name, @@ -518,6 +522,8 @@ class GenericBackendV2(BackendV2): transpilation. """ + + @_deprecate_pulse_arg("pulse_channels") def __init__( self, num_qubits: int, @@ -990,6 +996,7 @@ def _default_options(cls) -> Options: else: return BasicSimulator._default_options() + @_deprecate_pulse_dependency def drive_channel(self, qubit: int): drive_channels_map = getattr(self, "channels_map", {}).get("drive", {}) qubits = (qubit,) @@ -997,6 +1004,7 @@ def drive_channel(self, qubit: int): return drive_channels_map[qubits][0] return None + @_deprecate_pulse_dependency def measure_channel(self, qubit: int): measure_channels_map = getattr(self, "channels_map", {}).get("measure", {}) qubits = (qubit,) @@ -1004,6 +1012,7 @@ def measure_channel(self, qubit: int): return measure_channels_map[qubits][0] return None + @_deprecate_pulse_dependency def acquire_channel(self, qubit: int): acquire_channels_map = getattr(self, "channels_map", {}).get("acquire", {}) qubits = (qubit,) @@ -1011,6 +1020,7 @@ def acquire_channel(self, qubit: int): return acquire_channels_map[qubits][0] return None + @_deprecate_pulse_dependency def control_channel(self, qubits: Iterable[int]): control_channels_map = getattr(self, "channels_map", {}).get("control", {}) qubits = tuple(qubits) diff --git a/qiskit/providers/fake_provider/utils/backend_converter.py b/qiskit/providers/fake_provider/utils/backend_converter.py index 9e038c39df38..1b8a2dba8dc5 100644 --- a/qiskit/providers/fake_provider/utils/backend_converter.py +++ b/qiskit/providers/fake_provider/utils/backend_converter.py @@ -25,8 +25,10 @@ from qiskit.circuit.measure import Measure from qiskit.circuit.reset import Reset from qiskit.providers.models.pulsedefaults import PulseDefaults +from qiskit.utils.deprecate_pulse import _deprecate_pulse_arg +@_deprecate_pulse_arg("defs_dict") def convert_to_target(conf_dict: dict, props_dict: dict = None, defs_dict: dict = None) -> Target: """Uses configuration, properties and pulse defaults dicts to construct and return Target class. diff --git a/qiskit/providers/models/pulsedefaults.py b/qiskit/providers/models/pulsedefaults.py index 1302994d40e6..d016d78f199e 100644 --- a/qiskit/providers/models/pulsedefaults.py +++ b/qiskit/providers/models/pulsedefaults.py @@ -18,6 +18,7 @@ from qiskit.pulse.instruction_schedule_map import InstructionScheduleMap, PulseQobjDef from qiskit.qobj import PulseLibraryItem, PulseQobjInstruction from qiskit.qobj.converters import QobjToInstructionConverter +from qiskit.utils.deprecate_pulse import _deprecate_pulse_dependency class MeasurementKernel: @@ -169,6 +170,7 @@ class PulseDefaults: _data = {} + @_deprecate_pulse_dependency def __init__( self, qubit_freq_est: List[float], diff --git a/qiskit/qobj/converters/pulse_instruction.py b/qiskit/qobj/converters/pulse_instruction.py index e17036210d57..acf39d5615f0 100644 --- a/qiskit/qobj/converters/pulse_instruction.py +++ b/qiskit/qobj/converters/pulse_instruction.py @@ -31,6 +31,7 @@ from qiskit.qobj import QobjMeasurementOption, PulseLibraryItem, PulseQobjInstruction from qiskit.qobj.utils import MeasLevel from qiskit.utils import deprecate_func +from qiskit.utils.deprecate_pulse import _deprecate_pulse_dependency class ParametricPulseShapes(Enum): @@ -532,6 +533,7 @@ def _convert_new_inst(self, instruction): __chan_regex__ = re.compile(r"([a-zA-Z]+)(\d+)") + @_deprecate_pulse_dependency def __init__( self, pulse_library: Optional[List[PulseLibraryItem]] = None, diff --git a/qiskit/scheduler/config.py b/qiskit/scheduler/config.py index b8e2d5ac2425..e2e29a4d2218 100644 --- a/qiskit/scheduler/config.py +++ b/qiskit/scheduler/config.py @@ -16,11 +16,13 @@ from qiskit.pulse.instruction_schedule_map import InstructionScheduleMap from qiskit.pulse.utils import format_meas_map +from qiskit.utils.deprecate_pulse import _deprecate_pulse_dependency class ScheduleConfig: """Configuration for pulse scheduling.""" + @_deprecate_pulse_dependency def __init__(self, inst_map: InstructionScheduleMap, meas_map: List[List[int]], dt: float): """ Container for information needed to schedule a QuantumCircuit into a pulse Schedule. diff --git a/qiskit/transpiler/passes/calibration/pulse_gate.py b/qiskit/transpiler/passes/calibration/pulse_gate.py index eacabbe89057..91bb723276d8 100644 --- a/qiskit/transpiler/passes/calibration/pulse_gate.py +++ b/qiskit/transpiler/passes/calibration/pulse_gate.py @@ -19,6 +19,7 @@ from qiskit.pulse.instruction_schedule_map import InstructionScheduleMap from qiskit.transpiler.target import Target from qiskit.transpiler.exceptions import TranspilerError +from qiskit.utils.deprecate_pulse import _deprecate_pulse_dependency from .base_builder import CalibrationBuilder @@ -47,6 +48,7 @@ class PulseGates(CalibrationBuilder): https://arxiv.org/abs/2104.14722 """ + @_deprecate_pulse_dependency def __init__( self, inst_map: InstructionScheduleMap = None, diff --git a/qiskit/transpiler/passes/scheduling/alignments/pulse_gate_validation.py b/qiskit/transpiler/passes/scheduling/alignments/pulse_gate_validation.py index a39b81092fbf..874ca0c7008b 100644 --- a/qiskit/transpiler/passes/scheduling/alignments/pulse_gate_validation.py +++ b/qiskit/transpiler/passes/scheduling/alignments/pulse_gate_validation.py @@ -17,6 +17,7 @@ from qiskit.transpiler.basepasses import AnalysisPass from qiskit.transpiler.exceptions import TranspilerError from qiskit.transpiler.target import Target +from qiskit.utils.deprecate_pulse import _deprecate_pulse_dependency class ValidatePulseGates(AnalysisPass): @@ -40,6 +41,7 @@ class ValidatePulseGates(AnalysisPass): the backend control electronics. """ + @_deprecate_pulse_dependency def __init__( self, granularity: int = 1, diff --git a/qiskit/transpiler/target.py b/qiskit/transpiler/target.py index da4a44a8ee02..de9e233ce722 100644 --- a/qiskit/transpiler/target.py +++ b/qiskit/transpiler/target.py @@ -57,6 +57,7 @@ from qiskit.providers.backend import QubitProperties # pylint: disable=unused-import from qiskit.providers.models.backendproperties import BackendProperties from qiskit.utils import deprecate_func +from qiskit.utils.deprecate_pulse import _deprecate_pulse_dependency logger = logging.getLogger(__name__) @@ -604,6 +605,7 @@ def timing_constraints(self): self.granularity, self.min_length, self.pulse_alignment, self.acquire_alignment ) + @_deprecate_pulse_dependency def instruction_schedule_map(self): """Return an :class:`~qiskit.pulse.InstructionScheduleMap` for the instructions in the target with a pulse schedule defined. @@ -626,6 +628,7 @@ def instruction_schedule_map(self): self._instruction_schedule_map = out_inst_schedule_map return out_inst_schedule_map + @_deprecate_pulse_dependency def has_calibration( self, operation_name: str, @@ -647,6 +650,7 @@ def has_calibration( return False return getattr(self._gate_map[operation_name][qargs], "_calibration", None) is not None + @_deprecate_pulse_dependency def get_calibration( self, operation_name: str, diff --git a/qiskit/visualization/pulse_v2/core.py b/qiskit/visualization/pulse_v2/core.py index 20686f6fb4f6..be286aab9133 100644 --- a/qiskit/visualization/pulse_v2/core.py +++ b/qiskit/visualization/pulse_v2/core.py @@ -79,6 +79,7 @@ from qiskit.visualization.exceptions import VisualizationError from qiskit.visualization.pulse_v2 import events, types, drawings, device_info from qiskit.visualization.pulse_v2.stylesheet import QiskitPulseStyle +from qiskit.utils.deprecate_pulse import _deprecate_pulse_dependency class DrawerCanvas: @@ -93,6 +94,7 @@ class DrawerCanvas: the appearance of the `Chart` output. """ + @_deprecate_pulse_dependency def __init__(self, stylesheet: QiskitPulseStyle, device: device_info.DrawerBackendInfo): """Create new data container with backend system information. @@ -437,6 +439,7 @@ class Chart: str(types.WaveformType.OPAQUE.value), ] + @_deprecate_pulse_dependency def __init__(self, parent: DrawerCanvas, name: str | None = None): """Create new chart. diff --git a/qiskit/visualization/pulse_v2/device_info.py b/qiskit/visualization/pulse_v2/device_info.py index 7898f978772c..7a4c26cbe959 100644 --- a/qiskit/visualization/pulse_v2/device_info.py +++ b/qiskit/visualization/pulse_v2/device_info.py @@ -41,11 +41,13 @@ class :py:class:``DrawerBackendInfo`` with necessary methods to generate drawing from qiskit import pulse from qiskit.providers import BackendConfigurationError from qiskit.providers.backend import Backend, BackendV2 +from qiskit.utils.deprecate_pulse import _deprecate_pulse_dependency class DrawerBackendInfo(ABC): """Backend information to be used for the drawing data generation.""" + @_deprecate_pulse_dependency def __init__( self, name: Optional[str] = None, @@ -97,6 +99,7 @@ class OpenPulseBackendInfo(DrawerBackendInfo): """Drawing information of backend that conforms to OpenPulse specification.""" @classmethod + @_deprecate_pulse_dependency def create_from_backend(cls, backend: Backend): """Initialize a class with backend information provided by provider. diff --git a/qiskit/visualization/pulse_v2/drawings.py b/qiskit/visualization/pulse_v2/drawings.py index e5a61512a6cd..cc06bd8f9915 100644 --- a/qiskit/visualization/pulse_v2/drawings.py +++ b/qiskit/visualization/pulse_v2/drawings.py @@ -66,6 +66,7 @@ from qiskit.pulse.channels import Channel from qiskit.visualization.pulse_v2 import types from qiskit.visualization.exceptions import VisualizationError +from qiskit.utils.deprecate_pulse import _deprecate_pulse_dependency class ElementaryData(ABC): @@ -73,6 +74,7 @@ class ElementaryData(ABC): __hash__ = None + @_deprecate_pulse_dependency def __init__( self, data_type: str | Enum, @@ -128,6 +130,7 @@ class LineData(ElementaryData): This is the counterpart of `matplotlib.pyplot.plot`. """ + @_deprecate_pulse_dependency def __init__( self, data_type: str | Enum, @@ -170,6 +173,7 @@ class TextData(ElementaryData): This is the counterpart of `matplotlib.pyplot.text`. """ + @_deprecate_pulse_dependency def __init__( self, data_type: str | Enum, @@ -215,6 +219,7 @@ class BoxData(ElementaryData): This is the counterpart of `matplotlib.patches.Rectangle`. """ + @_deprecate_pulse_dependency def __init__( self, data_type: str | Enum, diff --git a/qiskit/visualization/pulse_v2/events.py b/qiskit/visualization/pulse_v2/events.py index 74da24b1db25..e0e319118d18 100644 --- a/qiskit/visualization/pulse_v2/events.py +++ b/qiskit/visualization/pulse_v2/events.py @@ -84,6 +84,7 @@ from qiskit import pulse, circuit from qiskit.visualization.pulse_v2.types import PhaseFreqTuple, PulseInstruction +from qiskit.utils.deprecate_pulse import _deprecate_pulse_dependency class ChannelEvents: @@ -101,6 +102,7 @@ class ChannelEvents: pulse.instructions.ShiftPhase, ) + @_deprecate_pulse_dependency def __init__( self, waveforms: dict[int, pulse.Instruction], diff --git a/qiskit/visualization/pulse_v2/generators/barrier.py b/qiskit/visualization/pulse_v2/generators/barrier.py index 85f8271cf142..5d21a3d9fead 100644 --- a/qiskit/visualization/pulse_v2/generators/barrier.py +++ b/qiskit/visualization/pulse_v2/generators/barrier.py @@ -40,8 +40,10 @@ def my_object_generator(data: BarrierInstruction, from typing import Dict, Any, List from qiskit.visualization.pulse_v2 import drawings, types, device_info +from qiskit.utils.deprecate_pulse import _deprecate_pulse_dependency +@_deprecate_pulse_dependency def gen_barrier( data: types.BarrierInstruction, formatter: Dict[str, Any], device: device_info.DrawerBackendInfo ) -> List[drawings.LineData]: diff --git a/qiskit/visualization/pulse_v2/generators/chart.py b/qiskit/visualization/pulse_v2/generators/chart.py index 26a92fe3695e..bc39538e1810 100644 --- a/qiskit/visualization/pulse_v2/generators/chart.py +++ b/qiskit/visualization/pulse_v2/generators/chart.py @@ -40,8 +40,10 @@ def my_object_generator(data: ChartAxis, from typing import Dict, Any, List from qiskit.visualization.pulse_v2 import drawings, types, device_info +from qiskit.utils.deprecate_pulse import _deprecate_pulse_dependency +@_deprecate_pulse_dependency def gen_baseline( data: types.ChartAxis, formatter: Dict[str, Any], device: device_info.DrawerBackendInfo ) -> List[drawings.LineData]: @@ -78,6 +80,7 @@ def gen_baseline( return [baseline] +@_deprecate_pulse_dependency def gen_chart_name( data: types.ChartAxis, formatter: Dict[str, Any], device: device_info.DrawerBackendInfo ) -> List[drawings.TextData]: @@ -115,6 +118,7 @@ def gen_chart_name( return [text] +@_deprecate_pulse_dependency def gen_chart_scale( data: types.ChartAxis, formatter: Dict[str, Any], device: device_info.DrawerBackendInfo ) -> List[drawings.TextData]: @@ -155,6 +159,7 @@ def gen_chart_scale( return [text] +@_deprecate_pulse_dependency def gen_channel_freqs( data: types.ChartAxis, formatter: Dict[str, Any], device: device_info.DrawerBackendInfo ) -> List[drawings.TextData]: diff --git a/qiskit/visualization/pulse_v2/generators/frame.py b/qiskit/visualization/pulse_v2/generators/frame.py index 8b71b8596bb4..76ab41a5d380 100644 --- a/qiskit/visualization/pulse_v2/generators/frame.py +++ b/qiskit/visualization/pulse_v2/generators/frame.py @@ -44,8 +44,10 @@ def my_object_generator(data: PulseInstruction, from qiskit.pulse import instructions from qiskit.visualization.exceptions import VisualizationError from qiskit.visualization.pulse_v2 import drawings, types, device_info +from qiskit.utils.deprecate_pulse import _deprecate_pulse_dependency +@_deprecate_pulse_dependency def gen_formatted_phase( data: types.PulseInstruction, formatter: Dict[str, Any], device: device_info.DrawerBackendInfo ) -> List[drawings.TextData]: @@ -103,6 +105,7 @@ def gen_formatted_phase( return [text] +@_deprecate_pulse_dependency def gen_formatted_freq_mhz( data: types.PulseInstruction, formatter: Dict[str, Any], device: device_info.DrawerBackendInfo ) -> List[drawings.TextData]: @@ -151,6 +154,7 @@ def gen_formatted_freq_mhz( return [text] +@_deprecate_pulse_dependency def gen_formatted_frame_values( data: types.PulseInstruction, formatter: Dict[str, Any], device: device_info.DrawerBackendInfo ) -> List[drawings.TextData]: @@ -227,6 +231,7 @@ def gen_formatted_frame_values( return texts +@_deprecate_pulse_dependency def gen_raw_operand_values_compact( data: types.PulseInstruction, formatter: Dict[str, Any], device: device_info.DrawerBackendInfo ) -> List[drawings.TextData]: @@ -282,6 +287,7 @@ def gen_raw_operand_values_compact( return [text] +@_deprecate_pulse_dependency def gen_frame_symbol( data: types.PulseInstruction, formatter: Dict[str, Any], device: device_info.DrawerBackendInfo ) -> List[drawings.TextData]: diff --git a/qiskit/visualization/pulse_v2/generators/snapshot.py b/qiskit/visualization/pulse_v2/generators/snapshot.py index d86c89997a02..3dd40e417fa2 100644 --- a/qiskit/visualization/pulse_v2/generators/snapshot.py +++ b/qiskit/visualization/pulse_v2/generators/snapshot.py @@ -40,8 +40,10 @@ def my_object_generator(data: SnapshotInstruction, from typing import Dict, Any, List from qiskit.visualization.pulse_v2 import drawings, types, device_info +from qiskit.utils.deprecate_pulse import _deprecate_pulse_dependency +@_deprecate_pulse_dependency def gen_snapshot_name( data: types.SnapshotInstruction, formatter: Dict[str, Any], @@ -82,6 +84,7 @@ def gen_snapshot_name( return [text] +@_deprecate_pulse_dependency def gen_snapshot_symbol( data: types.SnapshotInstruction, formatter: Dict[str, Any], diff --git a/qiskit/visualization/pulse_v2/generators/waveform.py b/qiskit/visualization/pulse_v2/generators/waveform.py index e770f271c454..ae56ea218eda 100644 --- a/qiskit/visualization/pulse_v2/generators/waveform.py +++ b/qiskit/visualization/pulse_v2/generators/waveform.py @@ -49,8 +49,10 @@ def my_object_generator(data: PulseInstruction, from qiskit.pulse import instructions, library from qiskit.visualization.exceptions import VisualizationError from qiskit.visualization.pulse_v2 import drawings, types, device_info +from qiskit.utils.deprecate_pulse import _deprecate_pulse_dependency +@_deprecate_pulse_dependency def gen_filled_waveform_stepwise( data: types.PulseInstruction, formatter: dict[str, Any], device: device_info.DrawerBackendInfo ) -> list[drawings.LineData | drawings.BoxData | drawings.TextData]: @@ -127,6 +129,7 @@ def gen_filled_waveform_stepwise( raise VisualizationError("Invalid data format is provided.") +@_deprecate_pulse_dependency def gen_ibmq_latex_waveform_name( data: types.PulseInstruction, formatter: dict[str, Any], device: device_info.DrawerBackendInfo ) -> list[drawings.TextData]: @@ -235,6 +238,7 @@ def gen_ibmq_latex_waveform_name( return [text] +@_deprecate_pulse_dependency def gen_waveform_max_value( data: types.PulseInstruction, formatter: dict[str, Any], device: device_info.DrawerBackendInfo ) -> list[drawings.TextData]: diff --git a/qiskit/visualization/pulse_v2/interface.py b/qiskit/visualization/pulse_v2/interface.py index 75370905d8d9..626a5ca27e31 100644 --- a/qiskit/visualization/pulse_v2/interface.py +++ b/qiskit/visualization/pulse_v2/interface.py @@ -28,8 +28,10 @@ from qiskit.visualization.pulse_v2 import core, device_info, stylesheet, types from qiskit.exceptions import MissingOptionalLibraryError from qiskit.utils import deprecate_arg +from qiskit.utils.deprecate_pulse import _deprecate_pulse_dependency +@_deprecate_pulse_dependency @deprecate_arg("show_barriers", new_alias="plot_barriers", since="1.1.0", pending=True) def draw( program: Union[Waveform, SymbolicPulse, Schedule, ScheduleBlock], diff --git a/qiskit/visualization/pulse_v2/layouts.py b/qiskit/visualization/pulse_v2/layouts.py index 13b42e394e94..1e49c50c01ad 100644 --- a/qiskit/visualization/pulse_v2/layouts.py +++ b/qiskit/visualization/pulse_v2/layouts.py @@ -83,8 +83,10 @@ def my_figure_title(program: Union[pulse.Waveform, pulse.Schedule], from qiskit import pulse from qiskit.visualization.pulse_v2 import types from qiskit.visualization.pulse_v2.device_info import DrawerBackendInfo +from qiskit.utils.deprecate_pulse import _deprecate_pulse_dependency +@_deprecate_pulse_dependency def channel_type_grouped_sort( channels: List[pulse.channels.Channel], formatter: Dict[str, Any], device: DrawerBackendInfo ) -> Iterator[Tuple[str, List[pulse.channels.Channel]]]: @@ -135,6 +137,7 @@ def channel_type_grouped_sort( yield chan.name.upper(), [chan] +@_deprecate_pulse_dependency def channel_index_grouped_sort( channels: List[pulse.channels.Channel], formatter: Dict[str, Any], device: DrawerBackendInfo ) -> Iterator[Tuple[str, List[pulse.channels.Channel]]]: @@ -197,6 +200,7 @@ def channel_index_grouped_sort( yield chan.name.upper(), [chan] +@_deprecate_pulse_dependency def channel_index_grouped_sort_u( channels: List[pulse.channels.Channel], formatter: Dict[str, Any], device: DrawerBackendInfo ) -> Iterator[Tuple[str, List[pulse.channels.Channel]]]: @@ -260,6 +264,7 @@ def channel_index_grouped_sort_u( yield chan.name.upper(), [chan] +@_deprecate_pulse_dependency def qubit_index_sort( channels: List[pulse.channels.Channel], formatter: Dict[str, Any], device: DrawerBackendInfo ) -> Iterator[Tuple[str, List[pulse.channels.Channel]]]: @@ -303,6 +308,7 @@ def qubit_index_sort( yield f"Q{qind:d}", chans +@_deprecate_pulse_dependency def time_map_in_ns( time_window: Tuple[int, int], axis_breaks: List[Tuple[int, int]], dt: Optional[float] = None ) -> types.HorizontalAxis: @@ -361,6 +367,7 @@ def time_map_in_ns( ) +@_deprecate_pulse_dependency def detail_title(program: Union[pulse.Waveform, pulse.Schedule], device: DrawerBackendInfo) -> str: """Layout function for generating figure title. @@ -382,6 +389,7 @@ def detail_title(program: Union[pulse.Waveform, pulse.Schedule], device: DrawerB return ", ".join(title_str) +@_deprecate_pulse_dependency def empty_title(program: Union[pulse.Waveform, pulse.Schedule], device: DrawerBackendInfo) -> str: """Layout function for generating an empty figure title.""" return "" diff --git a/qiskit/visualization/pulse_v2/plotters/base_plotter.py b/qiskit/visualization/pulse_v2/plotters/base_plotter.py index ee6f79235145..98aa8cf802ab 100644 --- a/qiskit/visualization/pulse_v2/plotters/base_plotter.py +++ b/qiskit/visualization/pulse_v2/plotters/base_plotter.py @@ -16,11 +16,13 @@ from typing import Any from qiskit.visualization.pulse_v2 import core +from qiskit.utils.deprecate_pulse import _deprecate_pulse_dependency class BasePlotter(ABC): """Base class of Qiskit plotter.""" + @_deprecate_pulse_dependency def __init__(self, canvas: core.DrawerCanvas): """Create new plotter. diff --git a/qiskit/visualization/pulse_v2/plotters/matplotlib.py b/qiskit/visualization/pulse_v2/plotters/matplotlib.py index 1788a1254894..c144bff54c1c 100644 --- a/qiskit/visualization/pulse_v2/plotters/matplotlib.py +++ b/qiskit/visualization/pulse_v2/plotters/matplotlib.py @@ -23,7 +23,7 @@ from qiskit.visualization.pulse_v2 import core, drawings, types from qiskit.visualization.pulse_v2.plotters.base_plotter import BasePlotter from qiskit.visualization.utils import matplotlib_close_if_inline - +from qiskit.utils.deprecate_pulse import _deprecate_pulse_dependency class Mpl2DPlotter(BasePlotter): """Matplotlib API for pulse drawer. @@ -32,6 +32,7 @@ class Mpl2DPlotter(BasePlotter): Each chart is map to X-Y axis of the canvas. """ + @_deprecate_pulse_dependency def __init__(self, canvas: core.DrawerCanvas, axis: Optional[plt.Axes] = None): """Create new plotter. diff --git a/qiskit/visualization/pulse_v2/stylesheet.py b/qiskit/visualization/pulse_v2/stylesheet.py index 1a37756f4baa..c8d11d53cd2c 100644 --- a/qiskit/visualization/pulse_v2/stylesheet.py +++ b/qiskit/visualization/pulse_v2/stylesheet.py @@ -33,11 +33,13 @@ from typing import Dict, Any, Mapping from qiskit.visualization.pulse_v2 import generators, layouts +from qiskit.utils.deprecate_pulse import _deprecate_pulse_dependency class QiskitPulseStyle(dict): """Stylesheet for pulse drawer.""" + @_deprecate_pulse_dependency def __init__(self): super().__init__() # to inform which stylesheet is applied. some plotter may not support specific style. @@ -93,6 +95,7 @@ class IQXStandard(dict): - Channels are sorted by index and control channels are added to the end. """ + @_deprecate_pulse_dependency def __init__(self, **kwargs): super().__init__() style = { @@ -137,6 +140,7 @@ class IQXSimple(dict): - Channels are sorted by qubit index. """ + @_deprecate_pulse_dependency def __init__(self, **kwargs): super().__init__() style = { @@ -181,6 +185,7 @@ class IQXDebugging(dict): - Channels are sorted by index and control channels are added to the end. """ + @_deprecate_pulse_dependency def __init__(self, **kwargs): super().__init__() style = { From ca923081ccc3a4b2ebc75bf65710317d7b8d7759 Mon Sep 17 00:00:00 2001 From: Eli Arbel Date: Sun, 22 Sep 2024 17:32:27 +0300 Subject: [PATCH 04/23] Filter deprecation warnings in QiskitTestCase --- qiskit/assembler/assemble_schedules.py | 4 +- qiskit/circuit/quantumcircuit.py | 8 +-- qiskit/compiler/transpiler.py | 4 +- qiskit/dagcircuit/dagdependency.py | 6 +-- qiskit/providers/backend.py | 12 ++--- qiskit/providers/backend_compat.py | 12 ++--- .../fake_provider/generic_backend_v2.py | 18 +++---- .../fake_provider/utils/backend_converter.py | 4 +- qiskit/providers/models/pulsedefaults.py | 4 +- qiskit/pulse/deprecate.py | 44 ----------------- qiskit/qobj/converters/pulse_instruction.py | 4 +- qiskit/scheduler/config.py | 4 +- .../passes/calibration/pulse_gate.py | 4 +- .../alignments/pulse_gate_validation.py | 4 +- qiskit/transpiler/target.py | 8 +-- qiskit/utils/deprecate_pulse.py | 49 +++++++++++++++++++ qiskit/visualization/pulse_v2/core.py | 6 +-- qiskit/visualization/pulse_v2/device_info.py | 6 +-- qiskit/visualization/pulse_v2/drawings.py | 10 ++-- qiskit/visualization/pulse_v2/events.py | 4 +- .../pulse_v2/generators/barrier.py | 4 +- .../pulse_v2/generators/chart.py | 10 ++-- .../pulse_v2/generators/frame.py | 12 ++--- .../pulse_v2/generators/snapshot.py | 6 +-- .../pulse_v2/generators/waveform.py | 8 +-- qiskit/visualization/pulse_v2/interface.py | 4 +- qiskit/visualization/pulse_v2/layouts.py | 16 +++--- .../pulse_v2/plotters/base_plotter.py | 4 +- .../pulse_v2/plotters/matplotlib.py | 4 +- qiskit/visualization/pulse_v2/stylesheet.py | 10 ++-- test/python/pulse/test_block.py | 9 ---- test/python/pulse/test_builder.py | 10 ---- test/python/pulse/test_builder_v2.py | 7 --- test/python/pulse/test_calibration_entries.py | 4 -- test/python/pulse/test_channels.py | 8 --- .../pulse/test_experiment_configurations.py | 5 -- .../pulse/test_instruction_schedule_map.py | 2 - test/python/pulse/test_instructions.py | 12 ----- test/python/pulse/test_macros.py | 5 -- test/python/pulse/test_parameter_manager.py | 7 --- test/python/pulse/test_parser.py | 2 - test/python/pulse/test_pulse_lib.py | 5 -- test/python/pulse/test_reference.py | 4 -- test/python/pulse/test_samplers.py | 2 - test/python/pulse/test_schedule.py | 6 --- test/python/pulse/test_transforms.py | 17 ------- test/utils/base.py | 7 +++ 47 files changed, 156 insertions(+), 249 deletions(-) delete mode 100644 qiskit/pulse/deprecate.py create mode 100644 qiskit/utils/deprecate_pulse.py diff --git a/qiskit/assembler/assemble_schedules.py b/qiskit/assembler/assemble_schedules.py index 3e82bb6228e5..697f3a46677a 100644 --- a/qiskit/assembler/assemble_schedules.py +++ b/qiskit/assembler/assemble_schedules.py @@ -22,10 +22,10 @@ from qiskit.pulse import instructions, transforms, library, schedule, channels from qiskit.qobj import utils as qobj_utils, converters from qiskit.qobj.converters.pulse_instruction import ParametricPulseShapes -from qiskit.utils.deprecate_pulse import _deprecate_pulse_dependency +from qiskit.utils.deprecate_pulse import deprecate_pulse_dependency -@_deprecate_pulse_dependency +@deprecate_pulse_dependency def assemble_schedules( schedules: List[ Union[ diff --git a/qiskit/circuit/quantumcircuit.py b/qiskit/circuit/quantumcircuit.py index c9c8ec65f7f3..8199970c8fc0 100644 --- a/qiskit/circuit/quantumcircuit.py +++ b/qiskit/circuit/quantumcircuit.py @@ -69,7 +69,7 @@ from .quantumcircuitdata import QuantumCircuitData, CircuitInstruction from .delay import Delay from .store import Store -from qiskit.utils.deprecate_pulse import _deprecate_pulse_dependency +from qiskit.utils.deprecate_pulse import deprecate_pulse_dependency if typing.TYPE_CHECKING: @@ -1323,7 +1323,7 @@ def op_start_times(self) -> list[int]: return self._op_start_times @property - @_deprecate_pulse_dependency + @deprecate_pulse_dependency def calibrations(self) -> dict: """Return calibration dictionary. @@ -1333,7 +1333,7 @@ def calibrations(self) -> dict: return dict(self._calibrations) @calibrations.setter - @_deprecate_pulse_dependency + @deprecate_pulse_dependency def calibrations(self, calibrations: dict): """Set the circuit calibration data from a dictionary of calibration definition. @@ -6470,7 +6470,7 @@ def continue_loop(self) -> InstructionSet: ContinueLoopOp(self.num_qubits, self.num_clbits), self.qubits, self.clbits, copy=False ) - @_deprecate_pulse_dependency + @deprecate_pulse_dependency def add_calibration( self, gate: Union[Gate, str], diff --git a/qiskit/compiler/transpiler.py b/qiskit/compiler/transpiler.py index fbde378c8e12..1b0afe52d1d8 100644 --- a/qiskit/compiler/transpiler.py +++ b/qiskit/compiler/transpiler.py @@ -32,13 +32,13 @@ from qiskit.transpiler.passes.synthesis.high_level_synthesis import HLSConfig from qiskit.transpiler.preset_passmanagers import generate_preset_pass_manager from qiskit.transpiler.target import Target -from qiskit.utils.deprecate_pulse import _deprecate_pulse_arg +from qiskit.utils.deprecate_pulse import deprecate_pulse_arg logger = logging.getLogger(__name__) _CircuitT = TypeVar("_CircuitT", bound=Union[QuantumCircuit, List[QuantumCircuit]]) -@_deprecate_pulse_arg("inst_map") +@deprecate_pulse_arg("inst_map") def transpile( # pylint: disable=too-many-return-statements circuits: _CircuitT, backend: Optional[Backend] = None, diff --git a/qiskit/dagcircuit/dagdependency.py b/qiskit/dagcircuit/dagdependency.py index 45de998c02ae..9fc21d85db97 100644 --- a/qiskit/dagcircuit/dagdependency.py +++ b/qiskit/dagcircuit/dagdependency.py @@ -29,7 +29,7 @@ from qiskit.dagcircuit.exceptions import DAGDependencyError from qiskit.dagcircuit.dagdepnode import DAGDepNode from qiskit.pulse import Schedule -from qiskit.utils.deprecate_pulse import _deprecate_pulse_dependency +from qiskit.utils.deprecate_pulse import deprecate_pulse_dependency if typing.TYPE_CHECKING: from qiskit.circuit.parameterexpression import ParameterExpression @@ -147,7 +147,7 @@ def global_phase(self, angle: float | ParameterExpression): self._global_phase = angle % (2 * math.pi) @property - @_deprecate_pulse_dependency + @deprecate_pulse_dependency def calibrations(self) -> dict[str, dict[tuple, Schedule]]: """Return calibration dictionary. @@ -157,7 +157,7 @@ def calibrations(self) -> dict[str, dict[tuple, Schedule]]: return dict(self._calibrations) @calibrations.setter - @_deprecate_pulse_dependency + @deprecate_pulse_dependency def calibrations(self, calibrations: dict[str, dict[tuple, Schedule]]): """Set the circuit calibration data from a dictionary of calibration definition. diff --git a/qiskit/providers/backend.py b/qiskit/providers/backend.py index 08e21f79c24e..2420960784dc 100644 --- a/qiskit/providers/backend.py +++ b/qiskit/providers/backend.py @@ -24,7 +24,7 @@ from qiskit.providers.models.backendstatus import BackendStatus from qiskit.circuit.gate import Instruction from qiskit.utils import deprecate_func -from qiskit.utils.deprecate_pulse import _deprecate_pulse_dependency +from qiskit.utils.deprecate_pulse import deprecate_pulse_dependency class Backend: @@ -486,7 +486,7 @@ def meas_map(self) -> List[List[int]]: raise NotImplementedError @property - @_deprecate_pulse_dependency + @deprecate_pulse_dependency def instruction_schedule_map(self): """Return the :class:`~qiskit.pulse.InstructionScheduleMap` for the instructions defined in this backend's target.""" @@ -526,7 +526,7 @@ def qubit_properties( return self.target.qubit_properties[qubit] return [self.target.qubit_properties[q] for q in qubit] - @_deprecate_pulse_dependency + @deprecate_pulse_dependency def drive_channel(self, qubit: int): """Return the drive channel for the given qubit. @@ -542,7 +542,7 @@ def drive_channel(self, qubit: int): """ raise NotImplementedError - @_deprecate_pulse_dependency + @deprecate_pulse_dependency def measure_channel(self, qubit: int): """Return the measure stimulus channel for the given qubit. @@ -558,7 +558,7 @@ def measure_channel(self, qubit: int): """ raise NotImplementedError - @_deprecate_pulse_dependency + @deprecate_pulse_dependency def acquire_channel(self, qubit: int): """Return the acquisition channel for the given qubit. @@ -574,7 +574,7 @@ def acquire_channel(self, qubit: int): """ raise NotImplementedError - @_deprecate_pulse_dependency + @deprecate_pulse_dependency def control_channel(self, qubits: Iterable[int]): """Return the secondary drive channel for the given qubit diff --git a/qiskit/providers/backend_compat.py b/qiskit/providers/backend_compat.py index 3070fc188d90..1d447a4fa1b3 100644 --- a/qiskit/providers/backend_compat.py +++ b/qiskit/providers/backend_compat.py @@ -25,13 +25,13 @@ from qiskit.providers.models.pulsedefaults import PulseDefaults from qiskit.providers.options import Options from qiskit.providers.exceptions import BackendPropertyError -from qiskit.utils.deprecate_pulse import _deprecate_pulse_arg, _deprecate_pulse_dependency +from qiskit.utils.deprecate_pulse import deprecate_pulse_arg, deprecate_pulse_dependency logger = logging.getLogger(__name__) -@_deprecate_pulse_arg("defaults") +@deprecate_pulse_arg("defaults") def convert_to_target( configuration: BackendConfiguration, properties: BackendProperties = None, @@ -439,19 +439,19 @@ def dtm(self) -> float: def meas_map(self) -> List[List[int]]: return self._config.meas_map - @_deprecate_pulse_dependency + @deprecate_pulse_dependency def drive_channel(self, qubit: int): return self._config.drive(qubit) - @_deprecate_pulse_dependency + @deprecate_pulse_dependency def measure_channel(self, qubit: int): return self._config.measure(qubit) - @_deprecate_pulse_dependency + @deprecate_pulse_dependency def acquire_channel(self, qubit: int): return self._config.acquire(qubit) - @_deprecate_pulse_dependency + @deprecate_pulse_dependency def control_channel(self, qubits: Iterable[int]): return self._config.control(qubits) diff --git a/qiskit/providers/fake_provider/generic_backend_v2.py b/qiskit/providers/fake_provider/generic_backend_v2.py index 43bdb1008bbd..bfe6a07c224d 100644 --- a/qiskit/providers/fake_provider/generic_backend_v2.py +++ b/qiskit/providers/fake_provider/generic_backend_v2.py @@ -42,7 +42,7 @@ from qiskit.pulse.calibration_entries import PulseQobjDef from qiskit.providers.models.pulsedefaults import MeasurementKernel, Discriminator from qiskit.qobj.pulse_qobj import QobjMeasurementOption -from qiskit.utils.deprecate_pulse import _deprecate_pulse_dependency, _deprecate_pulse_arg +from qiskit.utils.deprecate_pulse import deprecate_pulse_dependency, deprecate_pulse_arg # Noise default values/ranges for duration and error of supported # instructions. There are two possible formats: @@ -88,7 +88,7 @@ class PulseDefaults: _data = {} - @_deprecate_pulse_dependency + @deprecate_pulse_dependency def __init__( self, qubit_freq_est: List[float], @@ -244,7 +244,7 @@ class PulseLibraryItem: """INTERNAL - An item in a pulse library.""" # Copy from the deprecated from qiskit.qobj.PulseLibraryItem - @_deprecate_pulse_dependency + @deprecate_pulse_dependency def __init__(self, name, samples): """Instantiate a pulse library item. @@ -313,7 +313,7 @@ class PulseQobjInstruction: "parameters", ] - @_deprecate_pulse_dependency + @deprecate_pulse_dependency def __init__( self, name, @@ -523,7 +523,7 @@ class GenericBackendV2(BackendV2): """ - @_deprecate_pulse_arg("pulse_channels") + @deprecate_pulse_arg("pulse_channels") def __init__( self, num_qubits: int, @@ -996,7 +996,7 @@ def _default_options(cls) -> Options: else: return BasicSimulator._default_options() - @_deprecate_pulse_dependency + @deprecate_pulse_dependency def drive_channel(self, qubit: int): drive_channels_map = getattr(self, "channels_map", {}).get("drive", {}) qubits = (qubit,) @@ -1004,7 +1004,7 @@ def drive_channel(self, qubit: int): return drive_channels_map[qubits][0] return None - @_deprecate_pulse_dependency + @deprecate_pulse_dependency def measure_channel(self, qubit: int): measure_channels_map = getattr(self, "channels_map", {}).get("measure", {}) qubits = (qubit,) @@ -1012,7 +1012,7 @@ def measure_channel(self, qubit: int): return measure_channels_map[qubits][0] return None - @_deprecate_pulse_dependency + @deprecate_pulse_dependency def acquire_channel(self, qubit: int): acquire_channels_map = getattr(self, "channels_map", {}).get("acquire", {}) qubits = (qubit,) @@ -1020,7 +1020,7 @@ def acquire_channel(self, qubit: int): return acquire_channels_map[qubits][0] return None - @_deprecate_pulse_dependency + @deprecate_pulse_dependency def control_channel(self, qubits: Iterable[int]): control_channels_map = getattr(self, "channels_map", {}).get("control", {}) qubits = tuple(qubits) diff --git a/qiskit/providers/fake_provider/utils/backend_converter.py b/qiskit/providers/fake_provider/utils/backend_converter.py index 1b8a2dba8dc5..2dfd2b497d44 100644 --- a/qiskit/providers/fake_provider/utils/backend_converter.py +++ b/qiskit/providers/fake_provider/utils/backend_converter.py @@ -25,10 +25,10 @@ from qiskit.circuit.measure import Measure from qiskit.circuit.reset import Reset from qiskit.providers.models.pulsedefaults import PulseDefaults -from qiskit.utils.deprecate_pulse import _deprecate_pulse_arg +from qiskit.utils.deprecate_pulse import deprecate_pulse_arg -@_deprecate_pulse_arg("defs_dict") +@deprecate_pulse_arg("defs_dict") def convert_to_target(conf_dict: dict, props_dict: dict = None, defs_dict: dict = None) -> Target: """Uses configuration, properties and pulse defaults dicts to construct and return Target class. diff --git a/qiskit/providers/models/pulsedefaults.py b/qiskit/providers/models/pulsedefaults.py index d016d78f199e..8f4101ffc510 100644 --- a/qiskit/providers/models/pulsedefaults.py +++ b/qiskit/providers/models/pulsedefaults.py @@ -18,7 +18,7 @@ from qiskit.pulse.instruction_schedule_map import InstructionScheduleMap, PulseQobjDef from qiskit.qobj import PulseLibraryItem, PulseQobjInstruction from qiskit.qobj.converters import QobjToInstructionConverter -from qiskit.utils.deprecate_pulse import _deprecate_pulse_dependency +from qiskit.utils.deprecate_pulse import deprecate_pulse_dependency class MeasurementKernel: @@ -170,7 +170,7 @@ class PulseDefaults: _data = {} - @_deprecate_pulse_dependency + @deprecate_pulse_dependency def __init__( self, qubit_freq_est: List[float], diff --git a/qiskit/pulse/deprecate.py b/qiskit/pulse/deprecate.py deleted file mode 100644 index fdb29d8e6d3a..000000000000 --- a/qiskit/pulse/deprecate.py +++ /dev/null @@ -1,44 +0,0 @@ -# This code is part of Qiskit. -# -# (C) Copyright IBM 2024 -# -# This code is licensed under the Apache License, Version 2.0. You may -# obtain a copy of this license in the LICENSE.txt file in the root directory -# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0. -# -# Any modifications or derivative works of this code must retain this -# copyright notice, and modified files need to carry a notice indicating -# that they have been altered from the originals. - -""" -Deprecation functions for Qiskit Pulse -""" - -import warnings -from functools import wraps -from qiskit.utils.deprecation import deprecate_func - - -def deprecate_pulse_func(func): - """Deprecation message for functions and classes""" - return deprecate_func( - since="1.3", - removal_timeline="in Qiskit 2.0", - additional_msg="This is part of the entire Qiskit Pulse package deprecation. " - "The package will be moved to the Qiskit Dynamics repository: " - "https://github.com/qiskit-community/qiskit-dynamics/", - )(func) - - -def ignore_pulse_deprecation_warnings(func): - """Filter Pulse deprecation warnings in a decorated function""" - - @wraps(func) - def wrapper(*args, **kwargs): - with warnings.catch_warnings(): - warnings.filterwarnings( - "ignore", category=DeprecationWarning, message=".*Qiskit Pulse package" - ) - return func(*args, **kwargs) - - return wrapper diff --git a/qiskit/qobj/converters/pulse_instruction.py b/qiskit/qobj/converters/pulse_instruction.py index acf39d5615f0..c84cd3cfe2a1 100644 --- a/qiskit/qobj/converters/pulse_instruction.py +++ b/qiskit/qobj/converters/pulse_instruction.py @@ -31,7 +31,7 @@ from qiskit.qobj import QobjMeasurementOption, PulseLibraryItem, PulseQobjInstruction from qiskit.qobj.utils import MeasLevel from qiskit.utils import deprecate_func -from qiskit.utils.deprecate_pulse import _deprecate_pulse_dependency +from qiskit.utils.deprecate_pulse import deprecate_pulse_dependency class ParametricPulseShapes(Enum): @@ -533,7 +533,7 @@ def _convert_new_inst(self, instruction): __chan_regex__ = re.compile(r"([a-zA-Z]+)(\d+)") - @_deprecate_pulse_dependency + @deprecate_pulse_dependency def __init__( self, pulse_library: Optional[List[PulseLibraryItem]] = None, diff --git a/qiskit/scheduler/config.py b/qiskit/scheduler/config.py index e2e29a4d2218..f104bf88a510 100644 --- a/qiskit/scheduler/config.py +++ b/qiskit/scheduler/config.py @@ -16,13 +16,13 @@ from qiskit.pulse.instruction_schedule_map import InstructionScheduleMap from qiskit.pulse.utils import format_meas_map -from qiskit.utils.deprecate_pulse import _deprecate_pulse_dependency +from qiskit.utils.deprecate_pulse import deprecate_pulse_dependency class ScheduleConfig: """Configuration for pulse scheduling.""" - @_deprecate_pulse_dependency + @deprecate_pulse_dependency def __init__(self, inst_map: InstructionScheduleMap, meas_map: List[List[int]], dt: float): """ Container for information needed to schedule a QuantumCircuit into a pulse Schedule. diff --git a/qiskit/transpiler/passes/calibration/pulse_gate.py b/qiskit/transpiler/passes/calibration/pulse_gate.py index 91bb723276d8..dfdb9f754e9a 100644 --- a/qiskit/transpiler/passes/calibration/pulse_gate.py +++ b/qiskit/transpiler/passes/calibration/pulse_gate.py @@ -19,7 +19,7 @@ from qiskit.pulse.instruction_schedule_map import InstructionScheduleMap from qiskit.transpiler.target import Target from qiskit.transpiler.exceptions import TranspilerError -from qiskit.utils.deprecate_pulse import _deprecate_pulse_dependency +from qiskit.utils.deprecate_pulse import deprecate_pulse_dependency from .base_builder import CalibrationBuilder @@ -48,7 +48,7 @@ class PulseGates(CalibrationBuilder): https://arxiv.org/abs/2104.14722 """ - @_deprecate_pulse_dependency + @deprecate_pulse_dependency def __init__( self, inst_map: InstructionScheduleMap = None, diff --git a/qiskit/transpiler/passes/scheduling/alignments/pulse_gate_validation.py b/qiskit/transpiler/passes/scheduling/alignments/pulse_gate_validation.py index 874ca0c7008b..885730aac48a 100644 --- a/qiskit/transpiler/passes/scheduling/alignments/pulse_gate_validation.py +++ b/qiskit/transpiler/passes/scheduling/alignments/pulse_gate_validation.py @@ -17,7 +17,7 @@ from qiskit.transpiler.basepasses import AnalysisPass from qiskit.transpiler.exceptions import TranspilerError from qiskit.transpiler.target import Target -from qiskit.utils.deprecate_pulse import _deprecate_pulse_dependency +from qiskit.utils.deprecate_pulse import deprecate_pulse_dependency class ValidatePulseGates(AnalysisPass): @@ -41,7 +41,7 @@ class ValidatePulseGates(AnalysisPass): the backend control electronics. """ - @_deprecate_pulse_dependency + @deprecate_pulse_dependency def __init__( self, granularity: int = 1, diff --git a/qiskit/transpiler/target.py b/qiskit/transpiler/target.py index de9e233ce722..cf6635b260a2 100644 --- a/qiskit/transpiler/target.py +++ b/qiskit/transpiler/target.py @@ -57,7 +57,7 @@ from qiskit.providers.backend import QubitProperties # pylint: disable=unused-import from qiskit.providers.models.backendproperties import BackendProperties from qiskit.utils import deprecate_func -from qiskit.utils.deprecate_pulse import _deprecate_pulse_dependency +from qiskit.utils.deprecate_pulse import deprecate_pulse_dependency logger = logging.getLogger(__name__) @@ -605,7 +605,7 @@ def timing_constraints(self): self.granularity, self.min_length, self.pulse_alignment, self.acquire_alignment ) - @_deprecate_pulse_dependency + @deprecate_pulse_dependency def instruction_schedule_map(self): """Return an :class:`~qiskit.pulse.InstructionScheduleMap` for the instructions in the target with a pulse schedule defined. @@ -628,7 +628,7 @@ def instruction_schedule_map(self): self._instruction_schedule_map = out_inst_schedule_map return out_inst_schedule_map - @_deprecate_pulse_dependency + @deprecate_pulse_dependency def has_calibration( self, operation_name: str, @@ -650,7 +650,7 @@ def has_calibration( return False return getattr(self._gate_map[operation_name][qargs], "_calibration", None) is not None - @_deprecate_pulse_dependency + @deprecate_pulse_dependency def get_calibration( self, operation_name: str, diff --git a/qiskit/utils/deprecate_pulse.py b/qiskit/utils/deprecate_pulse.py new file mode 100644 index 000000000000..67058931d3ca --- /dev/null +++ b/qiskit/utils/deprecate_pulse.py @@ -0,0 +1,49 @@ +# This code is part of Qiskit. +# +# (C) Copyright IBM 2024 +# +# This code is licensed under the Apache License, Version 2.0. You may +# obtain a copy of this license in the LICENSE.txt file in the root directory +# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0. +# +# Any modifications or derivative works of this code must retain this +# copyright notice, and modified files need to carry a notice indicating +# that they have been altered from the originals. + +""" +Deprecation functions for Qiskit Pulse. To be removed in Qiskit 2.0. +""" + +from qiskit.utils.deprecation import deprecate_func, deprecate_arg + + +def deprecate_pulse_func(func): + """Deprecation message for functions and classes""" + return deprecate_func( + since="1.3", + removal_timeline="in Qiskit 2.0", + additional_msg="The entire Qiskit Pulse package is being deprecated. " + "The package will be moved to the Qiskit Dynamics repository: " + "https://github.com/qiskit-community/qiskit-dynamics/", + )(func) + + +def deprecate_pulse_dependency(func): + """Deprecation message for functions and classes""" + return deprecate_func( + since="1.3", + removal_timeline="in Qiskit 2.0", + additional_msg="The entire Qiskit Pulse package is being deprecated. " + "This is a dependency on the package.", + )(func) + + +def deprecate_pulse_arg(arg_name): + """Deprecation message for arguments related to Pulse""" + return deprecate_arg( + name=arg_name, + since="1.3", + removal_timeline="in Qiskit 2.0", + additional_msg="The entire Qiskit Pulse package is being deprecated.", + ) + diff --git a/qiskit/visualization/pulse_v2/core.py b/qiskit/visualization/pulse_v2/core.py index be286aab9133..e65c9849f5ee 100644 --- a/qiskit/visualization/pulse_v2/core.py +++ b/qiskit/visualization/pulse_v2/core.py @@ -79,7 +79,7 @@ from qiskit.visualization.exceptions import VisualizationError from qiskit.visualization.pulse_v2 import events, types, drawings, device_info from qiskit.visualization.pulse_v2.stylesheet import QiskitPulseStyle -from qiskit.utils.deprecate_pulse import _deprecate_pulse_dependency +from qiskit.utils.deprecate_pulse import deprecate_pulse_dependency class DrawerCanvas: @@ -94,7 +94,7 @@ class DrawerCanvas: the appearance of the `Chart` output. """ - @_deprecate_pulse_dependency + @deprecate_pulse_dependency def __init__(self, stylesheet: QiskitPulseStyle, device: device_info.DrawerBackendInfo): """Create new data container with backend system information. @@ -439,7 +439,7 @@ class Chart: str(types.WaveformType.OPAQUE.value), ] - @_deprecate_pulse_dependency + @deprecate_pulse_dependency def __init__(self, parent: DrawerCanvas, name: str | None = None): """Create new chart. diff --git a/qiskit/visualization/pulse_v2/device_info.py b/qiskit/visualization/pulse_v2/device_info.py index 7a4c26cbe959..364afc4672cf 100644 --- a/qiskit/visualization/pulse_v2/device_info.py +++ b/qiskit/visualization/pulse_v2/device_info.py @@ -41,13 +41,13 @@ class :py:class:``DrawerBackendInfo`` with necessary methods to generate drawing from qiskit import pulse from qiskit.providers import BackendConfigurationError from qiskit.providers.backend import Backend, BackendV2 -from qiskit.utils.deprecate_pulse import _deprecate_pulse_dependency +from qiskit.utils.deprecate_pulse import deprecate_pulse_dependency class DrawerBackendInfo(ABC): """Backend information to be used for the drawing data generation.""" - @_deprecate_pulse_dependency + @deprecate_pulse_dependency def __init__( self, name: Optional[str] = None, @@ -99,7 +99,7 @@ class OpenPulseBackendInfo(DrawerBackendInfo): """Drawing information of backend that conforms to OpenPulse specification.""" @classmethod - @_deprecate_pulse_dependency + @deprecate_pulse_dependency def create_from_backend(cls, backend: Backend): """Initialize a class with backend information provided by provider. diff --git a/qiskit/visualization/pulse_v2/drawings.py b/qiskit/visualization/pulse_v2/drawings.py index cc06bd8f9915..ab776e1772e7 100644 --- a/qiskit/visualization/pulse_v2/drawings.py +++ b/qiskit/visualization/pulse_v2/drawings.py @@ -66,7 +66,7 @@ from qiskit.pulse.channels import Channel from qiskit.visualization.pulse_v2 import types from qiskit.visualization.exceptions import VisualizationError -from qiskit.utils.deprecate_pulse import _deprecate_pulse_dependency +from qiskit.utils.deprecate_pulse import deprecate_pulse_dependency class ElementaryData(ABC): @@ -74,7 +74,7 @@ class ElementaryData(ABC): __hash__ = None - @_deprecate_pulse_dependency + @deprecate_pulse_dependency def __init__( self, data_type: str | Enum, @@ -130,7 +130,7 @@ class LineData(ElementaryData): This is the counterpart of `matplotlib.pyplot.plot`. """ - @_deprecate_pulse_dependency + @deprecate_pulse_dependency def __init__( self, data_type: str | Enum, @@ -173,7 +173,7 @@ class TextData(ElementaryData): This is the counterpart of `matplotlib.pyplot.text`. """ - @_deprecate_pulse_dependency + @deprecate_pulse_dependency def __init__( self, data_type: str | Enum, @@ -219,7 +219,7 @@ class BoxData(ElementaryData): This is the counterpart of `matplotlib.patches.Rectangle`. """ - @_deprecate_pulse_dependency + @deprecate_pulse_dependency def __init__( self, data_type: str | Enum, diff --git a/qiskit/visualization/pulse_v2/events.py b/qiskit/visualization/pulse_v2/events.py index e0e319118d18..b06d1d0b3b4e 100644 --- a/qiskit/visualization/pulse_v2/events.py +++ b/qiskit/visualization/pulse_v2/events.py @@ -84,7 +84,7 @@ from qiskit import pulse, circuit from qiskit.visualization.pulse_v2.types import PhaseFreqTuple, PulseInstruction -from qiskit.utils.deprecate_pulse import _deprecate_pulse_dependency +from qiskit.utils.deprecate_pulse import deprecate_pulse_dependency class ChannelEvents: @@ -102,7 +102,7 @@ class ChannelEvents: pulse.instructions.ShiftPhase, ) - @_deprecate_pulse_dependency + @deprecate_pulse_dependency def __init__( self, waveforms: dict[int, pulse.Instruction], diff --git a/qiskit/visualization/pulse_v2/generators/barrier.py b/qiskit/visualization/pulse_v2/generators/barrier.py index 5d21a3d9fead..968791c33710 100644 --- a/qiskit/visualization/pulse_v2/generators/barrier.py +++ b/qiskit/visualization/pulse_v2/generators/barrier.py @@ -40,10 +40,10 @@ def my_object_generator(data: BarrierInstruction, from typing import Dict, Any, List from qiskit.visualization.pulse_v2 import drawings, types, device_info -from qiskit.utils.deprecate_pulse import _deprecate_pulse_dependency +from qiskit.utils.deprecate_pulse import deprecate_pulse_dependency -@_deprecate_pulse_dependency +@deprecate_pulse_dependency def gen_barrier( data: types.BarrierInstruction, formatter: Dict[str, Any], device: device_info.DrawerBackendInfo ) -> List[drawings.LineData]: diff --git a/qiskit/visualization/pulse_v2/generators/chart.py b/qiskit/visualization/pulse_v2/generators/chart.py index bc39538e1810..4abe442ad871 100644 --- a/qiskit/visualization/pulse_v2/generators/chart.py +++ b/qiskit/visualization/pulse_v2/generators/chart.py @@ -40,10 +40,10 @@ def my_object_generator(data: ChartAxis, from typing import Dict, Any, List from qiskit.visualization.pulse_v2 import drawings, types, device_info -from qiskit.utils.deprecate_pulse import _deprecate_pulse_dependency +from qiskit.utils.deprecate_pulse import deprecate_pulse_dependency -@_deprecate_pulse_dependency +@deprecate_pulse_dependency def gen_baseline( data: types.ChartAxis, formatter: Dict[str, Any], device: device_info.DrawerBackendInfo ) -> List[drawings.LineData]: @@ -80,7 +80,7 @@ def gen_baseline( return [baseline] -@_deprecate_pulse_dependency +@deprecate_pulse_dependency def gen_chart_name( data: types.ChartAxis, formatter: Dict[str, Any], device: device_info.DrawerBackendInfo ) -> List[drawings.TextData]: @@ -118,7 +118,7 @@ def gen_chart_name( return [text] -@_deprecate_pulse_dependency +@deprecate_pulse_dependency def gen_chart_scale( data: types.ChartAxis, formatter: Dict[str, Any], device: device_info.DrawerBackendInfo ) -> List[drawings.TextData]: @@ -159,7 +159,7 @@ def gen_chart_scale( return [text] -@_deprecate_pulse_dependency +@deprecate_pulse_dependency def gen_channel_freqs( data: types.ChartAxis, formatter: Dict[str, Any], device: device_info.DrawerBackendInfo ) -> List[drawings.TextData]: diff --git a/qiskit/visualization/pulse_v2/generators/frame.py b/qiskit/visualization/pulse_v2/generators/frame.py index 76ab41a5d380..6e1ac11c1b01 100644 --- a/qiskit/visualization/pulse_v2/generators/frame.py +++ b/qiskit/visualization/pulse_v2/generators/frame.py @@ -44,10 +44,10 @@ def my_object_generator(data: PulseInstruction, from qiskit.pulse import instructions from qiskit.visualization.exceptions import VisualizationError from qiskit.visualization.pulse_v2 import drawings, types, device_info -from qiskit.utils.deprecate_pulse import _deprecate_pulse_dependency +from qiskit.utils.deprecate_pulse import deprecate_pulse_dependency -@_deprecate_pulse_dependency +@deprecate_pulse_dependency def gen_formatted_phase( data: types.PulseInstruction, formatter: Dict[str, Any], device: device_info.DrawerBackendInfo ) -> List[drawings.TextData]: @@ -105,7 +105,7 @@ def gen_formatted_phase( return [text] -@_deprecate_pulse_dependency +@deprecate_pulse_dependency def gen_formatted_freq_mhz( data: types.PulseInstruction, formatter: Dict[str, Any], device: device_info.DrawerBackendInfo ) -> List[drawings.TextData]: @@ -154,7 +154,7 @@ def gen_formatted_freq_mhz( return [text] -@_deprecate_pulse_dependency +@deprecate_pulse_dependency def gen_formatted_frame_values( data: types.PulseInstruction, formatter: Dict[str, Any], device: device_info.DrawerBackendInfo ) -> List[drawings.TextData]: @@ -231,7 +231,7 @@ def gen_formatted_frame_values( return texts -@_deprecate_pulse_dependency +@deprecate_pulse_dependency def gen_raw_operand_values_compact( data: types.PulseInstruction, formatter: Dict[str, Any], device: device_info.DrawerBackendInfo ) -> List[drawings.TextData]: @@ -287,7 +287,7 @@ def gen_raw_operand_values_compact( return [text] -@_deprecate_pulse_dependency +@deprecate_pulse_dependency def gen_frame_symbol( data: types.PulseInstruction, formatter: Dict[str, Any], device: device_info.DrawerBackendInfo ) -> List[drawings.TextData]: diff --git a/qiskit/visualization/pulse_v2/generators/snapshot.py b/qiskit/visualization/pulse_v2/generators/snapshot.py index 3dd40e417fa2..fe3956bbc131 100644 --- a/qiskit/visualization/pulse_v2/generators/snapshot.py +++ b/qiskit/visualization/pulse_v2/generators/snapshot.py @@ -40,10 +40,10 @@ def my_object_generator(data: SnapshotInstruction, from typing import Dict, Any, List from qiskit.visualization.pulse_v2 import drawings, types, device_info -from qiskit.utils.deprecate_pulse import _deprecate_pulse_dependency +from qiskit.utils.deprecate_pulse import deprecate_pulse_dependency -@_deprecate_pulse_dependency +@deprecate_pulse_dependency def gen_snapshot_name( data: types.SnapshotInstruction, formatter: Dict[str, Any], @@ -84,7 +84,7 @@ def gen_snapshot_name( return [text] -@_deprecate_pulse_dependency +@deprecate_pulse_dependency def gen_snapshot_symbol( data: types.SnapshotInstruction, formatter: Dict[str, Any], diff --git a/qiskit/visualization/pulse_v2/generators/waveform.py b/qiskit/visualization/pulse_v2/generators/waveform.py index ae56ea218eda..4493a8c1fe6c 100644 --- a/qiskit/visualization/pulse_v2/generators/waveform.py +++ b/qiskit/visualization/pulse_v2/generators/waveform.py @@ -49,10 +49,10 @@ def my_object_generator(data: PulseInstruction, from qiskit.pulse import instructions, library from qiskit.visualization.exceptions import VisualizationError from qiskit.visualization.pulse_v2 import drawings, types, device_info -from qiskit.utils.deprecate_pulse import _deprecate_pulse_dependency +from qiskit.utils.deprecate_pulse import deprecate_pulse_dependency -@_deprecate_pulse_dependency +@deprecate_pulse_dependency def gen_filled_waveform_stepwise( data: types.PulseInstruction, formatter: dict[str, Any], device: device_info.DrawerBackendInfo ) -> list[drawings.LineData | drawings.BoxData | drawings.TextData]: @@ -129,7 +129,7 @@ def gen_filled_waveform_stepwise( raise VisualizationError("Invalid data format is provided.") -@_deprecate_pulse_dependency +@deprecate_pulse_dependency def gen_ibmq_latex_waveform_name( data: types.PulseInstruction, formatter: dict[str, Any], device: device_info.DrawerBackendInfo ) -> list[drawings.TextData]: @@ -238,7 +238,7 @@ def gen_ibmq_latex_waveform_name( return [text] -@_deprecate_pulse_dependency +@deprecate_pulse_dependency def gen_waveform_max_value( data: types.PulseInstruction, formatter: dict[str, Any], device: device_info.DrawerBackendInfo ) -> list[drawings.TextData]: diff --git a/qiskit/visualization/pulse_v2/interface.py b/qiskit/visualization/pulse_v2/interface.py index 626a5ca27e31..5d20ef7b5b5b 100644 --- a/qiskit/visualization/pulse_v2/interface.py +++ b/qiskit/visualization/pulse_v2/interface.py @@ -28,10 +28,10 @@ from qiskit.visualization.pulse_v2 import core, device_info, stylesheet, types from qiskit.exceptions import MissingOptionalLibraryError from qiskit.utils import deprecate_arg -from qiskit.utils.deprecate_pulse import _deprecate_pulse_dependency +from qiskit.utils.deprecate_pulse import deprecate_pulse_dependency -@_deprecate_pulse_dependency +@deprecate_pulse_dependency @deprecate_arg("show_barriers", new_alias="plot_barriers", since="1.1.0", pending=True) def draw( program: Union[Waveform, SymbolicPulse, Schedule, ScheduleBlock], diff --git a/qiskit/visualization/pulse_v2/layouts.py b/qiskit/visualization/pulse_v2/layouts.py index 1e49c50c01ad..55a5a206fc28 100644 --- a/qiskit/visualization/pulse_v2/layouts.py +++ b/qiskit/visualization/pulse_v2/layouts.py @@ -83,10 +83,10 @@ def my_figure_title(program: Union[pulse.Waveform, pulse.Schedule], from qiskit import pulse from qiskit.visualization.pulse_v2 import types from qiskit.visualization.pulse_v2.device_info import DrawerBackendInfo -from qiskit.utils.deprecate_pulse import _deprecate_pulse_dependency +from qiskit.utils.deprecate_pulse import deprecate_pulse_dependency -@_deprecate_pulse_dependency +@deprecate_pulse_dependency def channel_type_grouped_sort( channels: List[pulse.channels.Channel], formatter: Dict[str, Any], device: DrawerBackendInfo ) -> Iterator[Tuple[str, List[pulse.channels.Channel]]]: @@ -137,7 +137,7 @@ def channel_type_grouped_sort( yield chan.name.upper(), [chan] -@_deprecate_pulse_dependency +@deprecate_pulse_dependency def channel_index_grouped_sort( channels: List[pulse.channels.Channel], formatter: Dict[str, Any], device: DrawerBackendInfo ) -> Iterator[Tuple[str, List[pulse.channels.Channel]]]: @@ -200,7 +200,7 @@ def channel_index_grouped_sort( yield chan.name.upper(), [chan] -@_deprecate_pulse_dependency +@deprecate_pulse_dependency def channel_index_grouped_sort_u( channels: List[pulse.channels.Channel], formatter: Dict[str, Any], device: DrawerBackendInfo ) -> Iterator[Tuple[str, List[pulse.channels.Channel]]]: @@ -264,7 +264,7 @@ def channel_index_grouped_sort_u( yield chan.name.upper(), [chan] -@_deprecate_pulse_dependency +@deprecate_pulse_dependency def qubit_index_sort( channels: List[pulse.channels.Channel], formatter: Dict[str, Any], device: DrawerBackendInfo ) -> Iterator[Tuple[str, List[pulse.channels.Channel]]]: @@ -308,7 +308,7 @@ def qubit_index_sort( yield f"Q{qind:d}", chans -@_deprecate_pulse_dependency +@deprecate_pulse_dependency def time_map_in_ns( time_window: Tuple[int, int], axis_breaks: List[Tuple[int, int]], dt: Optional[float] = None ) -> types.HorizontalAxis: @@ -367,7 +367,7 @@ def time_map_in_ns( ) -@_deprecate_pulse_dependency +@deprecate_pulse_dependency def detail_title(program: Union[pulse.Waveform, pulse.Schedule], device: DrawerBackendInfo) -> str: """Layout function for generating figure title. @@ -389,7 +389,7 @@ def detail_title(program: Union[pulse.Waveform, pulse.Schedule], device: DrawerB return ", ".join(title_str) -@_deprecate_pulse_dependency +@deprecate_pulse_dependency def empty_title(program: Union[pulse.Waveform, pulse.Schedule], device: DrawerBackendInfo) -> str: """Layout function for generating an empty figure title.""" return "" diff --git a/qiskit/visualization/pulse_v2/plotters/base_plotter.py b/qiskit/visualization/pulse_v2/plotters/base_plotter.py index 98aa8cf802ab..3bfc352d8416 100644 --- a/qiskit/visualization/pulse_v2/plotters/base_plotter.py +++ b/qiskit/visualization/pulse_v2/plotters/base_plotter.py @@ -16,13 +16,13 @@ from typing import Any from qiskit.visualization.pulse_v2 import core -from qiskit.utils.deprecate_pulse import _deprecate_pulse_dependency +from qiskit.utils.deprecate_pulse import deprecate_pulse_dependency class BasePlotter(ABC): """Base class of Qiskit plotter.""" - @_deprecate_pulse_dependency + @deprecate_pulse_dependency def __init__(self, canvas: core.DrawerCanvas): """Create new plotter. diff --git a/qiskit/visualization/pulse_v2/plotters/matplotlib.py b/qiskit/visualization/pulse_v2/plotters/matplotlib.py index c144bff54c1c..c3ce963a4188 100644 --- a/qiskit/visualization/pulse_v2/plotters/matplotlib.py +++ b/qiskit/visualization/pulse_v2/plotters/matplotlib.py @@ -23,7 +23,7 @@ from qiskit.visualization.pulse_v2 import core, drawings, types from qiskit.visualization.pulse_v2.plotters.base_plotter import BasePlotter from qiskit.visualization.utils import matplotlib_close_if_inline -from qiskit.utils.deprecate_pulse import _deprecate_pulse_dependency +from qiskit.utils.deprecate_pulse import deprecate_pulse_dependency class Mpl2DPlotter(BasePlotter): """Matplotlib API for pulse drawer. @@ -32,7 +32,7 @@ class Mpl2DPlotter(BasePlotter): Each chart is map to X-Y axis of the canvas. """ - @_deprecate_pulse_dependency + @deprecate_pulse_dependency def __init__(self, canvas: core.DrawerCanvas, axis: Optional[plt.Axes] = None): """Create new plotter. diff --git a/qiskit/visualization/pulse_v2/stylesheet.py b/qiskit/visualization/pulse_v2/stylesheet.py index c8d11d53cd2c..e550d6e8eb31 100644 --- a/qiskit/visualization/pulse_v2/stylesheet.py +++ b/qiskit/visualization/pulse_v2/stylesheet.py @@ -33,13 +33,13 @@ from typing import Dict, Any, Mapping from qiskit.visualization.pulse_v2 import generators, layouts -from qiskit.utils.deprecate_pulse import _deprecate_pulse_dependency +from qiskit.utils.deprecate_pulse import deprecate_pulse_dependency class QiskitPulseStyle(dict): """Stylesheet for pulse drawer.""" - @_deprecate_pulse_dependency + @deprecate_pulse_dependency def __init__(self): super().__init__() # to inform which stylesheet is applied. some plotter may not support specific style. @@ -95,7 +95,7 @@ class IQXStandard(dict): - Channels are sorted by index and control channels are added to the end. """ - @_deprecate_pulse_dependency + @deprecate_pulse_dependency def __init__(self, **kwargs): super().__init__() style = { @@ -140,7 +140,7 @@ class IQXSimple(dict): - Channels are sorted by qubit index. """ - @_deprecate_pulse_dependency + @deprecate_pulse_dependency def __init__(self, **kwargs): super().__init__() style = { @@ -185,7 +185,7 @@ class IQXDebugging(dict): - Channels are sorted by index and control channels are added to the end. """ - @_deprecate_pulse_dependency + @deprecate_pulse_dependency def __init__(self, **kwargs): super().__init__() style = { diff --git a/test/python/pulse/test_block.py b/test/python/pulse/test_block.py index cc3b286eaa2e..c6a2c2384f64 100644 --- a/test/python/pulse/test_block.py +++ b/test/python/pulse/test_block.py @@ -20,13 +20,11 @@ from qiskit.pulse.exceptions import PulseError from qiskit.providers.fake_provider import FakeOpenPulse2Q from test import QiskitTestCase # pylint: disable=wrong-import-order -from qiskit.pulse.deprecate import ignore_pulse_deprecation_warnings class BaseTestBlock(QiskitTestCase): """ScheduleBlock tests.""" - @ignore_pulse_deprecation_warnings def setUp(self): super().setUp() @@ -93,7 +91,6 @@ def test_sequential_alignment(self): self.assertScheduleEqual(block, ref_sched) - @ignore_pulse_deprecation_warnings def test_equispace_alignment(self): """Test equispace alignment context.""" block = pulse.ScheduleBlock(alignment_context=self.equispaced_context) @@ -153,7 +150,6 @@ class TestBlockOperation(BaseTestBlock): This operation should be tested in `test.python.pulse.test_block.TestTransformation`. """ - @ignore_pulse_deprecation_warnings def setUp(self): super().setUp() @@ -185,7 +181,6 @@ def test_append_an_instruction_to_empty_block_inplace(self): self.assertEqual(block.blocks[0], pulse.Play(self.test_waveform0, self.d0)) - @ignore_pulse_deprecation_warnings def test_append_a_block_to_empty_block(self): """Test append another ScheduleBlock to empty block.""" block = pulse.ScheduleBlock() @@ -384,7 +379,6 @@ class TestBlockEquality(BaseTestBlock): This should be tested for each transform. """ - @ignore_pulse_deprecation_warnings def test_different_channels(self): """Test equality is False if different channels.""" block1 = pulse.ScheduleBlock() @@ -620,7 +614,6 @@ def test_instruction_out_of_order_complex_not_equal(self): class TestParametrizedBlockOperation(BaseTestBlock): """Test fundamental operation with parametrization.""" - @ignore_pulse_deprecation_warnings def setUp(self): super().setUp() @@ -646,7 +639,6 @@ def test_report_parameter_assignment(self): self.assertTrue(block.is_parameterized()) self.assertTrue(block.is_schedulable()) - @ignore_pulse_deprecation_warnings def test_cannot_get_duration_if_not_assigned(self): """Test raise error when duration is not assigned.""" block = pulse.ScheduleBlock() @@ -730,7 +722,6 @@ def test_parametrized_context(self): class TestBlockFilter(BaseTestBlock): """Test ScheduleBlock filtering methods.""" - @ignore_pulse_deprecation_warnings def test_filter_channels(self): """Test filtering over channels.""" with pulse.build() as blk: diff --git a/test/python/pulse/test_builder.py b/test/python/pulse/test_builder.py index 483b0727cce7..72a6de11ae08 100644 --- a/test/python/pulse/test_builder.py +++ b/test/python/pulse/test_builder.py @@ -14,7 +14,6 @@ from math import pi import numpy as np -from qiskit.pulse.deprecate import ignore_pulse_deprecation_warnings from qiskit import circuit, compiler, pulse from qiskit.pulse import builder, exceptions, macros @@ -109,7 +108,6 @@ def test_default_alignment_sequential(self): self.assertScheduleEqual(schedule, reference) - @ignore_pulse_deprecation_warnings def test_default_alignment_alignmentkind_instance(self): """Test default AlignmentKind instance""" d0 = pulse.DriveChannel(0) @@ -157,7 +155,6 @@ def test_align_sequential(self): self.assertScheduleEqual(schedule, reference) - @ignore_pulse_deprecation_warnings def test_align_left(self): """Test the left alignment context.""" d0 = pulse.DriveChannel(0) @@ -271,7 +268,6 @@ def test_measure_channel(self): with pulse.build(self.backend): self.assertEqual(pulse.measure_channel(0), pulse.MeasureChannel(0)) - @ignore_pulse_deprecation_warnings def test_acquire_channel(self): """Text context builder acquire channel.""" with pulse.build(self.backend): @@ -348,7 +344,6 @@ def test_play_name_argument(self): self.assertEqual(schedule.instructions[0][1].name, "new_name") - @ignore_pulse_deprecation_warnings def test_acquire_memory_slot(self): """Test acquire instruction into memory slot.""" acquire0 = pulse.AcquireChannel(0) @@ -517,7 +512,6 @@ def test_barrier_with_align_left(self): self.assertScheduleEqual(schedule, reference) - @ignore_pulse_deprecation_warnings def test_barrier_on_qubits(self): """Test barrier directive on qubits.""" with pulse.build(self.backend) as schedule: @@ -547,7 +541,6 @@ def test_trivial_barrier(self): class TestUtilities(TestBuilder): """Test builder utilities.""" - @ignore_pulse_deprecation_warnings def test_active_backend(self): """Test getting active builder backend.""" with pulse.build(self.backend): @@ -709,7 +702,6 @@ def test_measure_all(self): self.assertScheduleEqual(schedule, reference) - @ignore_pulse_deprecation_warnings def test_delay_qubit(self): """Test delaying on a qubit macro.""" with pulse.build(self.backend) as schedule: @@ -760,7 +752,6 @@ def test_delay_qubits(self): class TestBuilderComposition(TestBuilder): """Test more sophisticated composite builder examples.""" - @ignore_pulse_deprecation_warnings def test_complex_build(self): """Test a general program build with nested contexts, circuits and macros.""" @@ -858,7 +849,6 @@ def get_sched(qubit_idx: [int], backend): class TestSubroutineCall(TestBuilder): """Test for calling subroutine.""" - @ignore_pulse_deprecation_warnings def test_call(self): """Test calling schedule instruction.""" d0 = pulse.DriveChannel(0) diff --git a/test/python/pulse/test_builder_v2.py b/test/python/pulse/test_builder_v2.py index 94a02d50941d..79d3ac5b6020 100644 --- a/test/python/pulse/test_builder_v2.py +++ b/test/python/pulse/test_builder_v2.py @@ -24,13 +24,11 @@ from test import QiskitTestCase # pylint: disable=wrong-import-order from ..legacy_cmaps import MUMBAI_CMAP -from qiskit.pulse.deprecate import ignore_pulse_deprecation_warnings class TestBuilderV2(QiskitTestCase): """Test the pulse builder context with backendV2.""" - @ignore_pulse_deprecation_warnings def setUp(self): super().setUp() self.backend = GenericBackendV2( @@ -48,7 +46,6 @@ def assertScheduleEqual(self, program, target): class TestContextsV2(TestBuilderV2): """Test builder contexts.""" - @ignore_pulse_deprecation_warnings def test_phase_compensated_frequency_offset(self): """Test that the phase offset context properly compensates for phase accumulation with backendV2.""" @@ -80,7 +77,6 @@ def test_measure_channel(self): with pulse.build(self.backend): self.assertEqual(pulse.measure_channel(0), pulse.MeasureChannel(0)) - @ignore_pulse_deprecation_warnings def test_acquire_channel(self): """Text context builder acquire channel.""" with pulse.build(self.backend): @@ -95,7 +91,6 @@ def test_control_channel(self): class TestDirectivesV2(TestBuilderV2): """Test builder directives.""" - @ignore_pulse_deprecation_warnings def test_barrier_on_qubits(self): """Test barrier directive on qubits with backendV2. A part of qubits map of Mumbai @@ -127,7 +122,6 @@ def test_barrier_on_qubits(self): class TestUtilitiesV2(TestBuilderV2): """Test builder utilities.""" - @ignore_pulse_deprecation_warnings def test_active_backend(self): """Test getting active builder backend.""" with pulse.build(self.backend): @@ -254,7 +248,6 @@ def test_measure_all(self): self.assertScheduleEqual(schedule, reference) - @ignore_pulse_deprecation_warnings def test_delay_qubit(self): """Test delaying on a qubit macro.""" with pulse.build(self.backend) as schedule: diff --git a/test/python/pulse/test_calibration_entries.py b/test/python/pulse/test_calibration_entries.py index 52e054625f08..cc31789ef683 100644 --- a/test/python/pulse/test_calibration_entries.py +++ b/test/python/pulse/test_calibration_entries.py @@ -33,7 +33,6 @@ from qiskit.qobj.converters.pulse_instruction import QobjToInstructionConverter from qiskit.qobj.pulse_qobj import PulseLibraryItem, PulseQobjInstruction from test import QiskitTestCase # pylint: disable=wrong-import-order -from qiskit.pulse.deprecate import ignore_pulse_deprecation_warnings class TestSchedule(QiskitTestCase): @@ -59,7 +58,6 @@ def test_add_schedule(self): schedule_ref = program self.assertEqual(schedule_to_test, schedule_ref) - @ignore_pulse_deprecation_warnings def test_add_block(self): """Basic test pulse Schedule format.""" program = ScheduleBlock() @@ -186,7 +184,6 @@ def test_equality(self): class TestCallable(QiskitTestCase): """Test case for the CallableDef.""" - @ignore_pulse_deprecation_warnings def test_add_callable(self): """Basic test callable format.""" program = Schedule() @@ -291,7 +288,6 @@ def setUp(self): ] ) - @ignore_pulse_deprecation_warnings def test_add_qobj(self): """Basic test PulseQobj format.""" with self.assertWarns(DeprecationWarning): diff --git a/test/python/pulse/test_channels.py b/test/python/pulse/test_channels.py index 8b50e8ba0ec6..59c4d15bf67b 100644 --- a/test/python/pulse/test_channels.py +++ b/test/python/pulse/test_channels.py @@ -28,7 +28,6 @@ PulseError, ) from test import QiskitTestCase # pylint: disable=wrong-import-order -from qiskit.pulse.deprecate import ignore_pulse_deprecation_warnings class TestChannel(QiskitTestCase): @@ -59,7 +58,6 @@ def test_default(self): self.assertEqual(acquire_channel.index, 123) self.assertEqual(acquire_channel.name, "a123") - @ignore_pulse_deprecation_warnings def test_channel_hash(self): """Test hashing for acquire channel.""" acq_channel_1 = AcquireChannel(123) @@ -83,7 +81,6 @@ def test_cannot_be_instantiated(self): class TestMemorySlot(QiskitTestCase): """MemorySlot tests.""" - @ignore_pulse_deprecation_warnings def test_default(self): """Test default memory slot.""" memory_slot = MemorySlot(123) @@ -103,7 +100,6 @@ def test_validation(self): class TestRegisterSlot(QiskitTestCase): """RegisterSlot tests.""" - @ignore_pulse_deprecation_warnings def test_default(self): """Test default register slot.""" register_slot = RegisterSlot(123) @@ -123,7 +119,6 @@ def test_validation(self): class TestSnapshotChannel(QiskitTestCase): """SnapshotChannel tests.""" - @ignore_pulse_deprecation_warnings def test_default(self): """Test default snapshot channel.""" snapshot_channel = SnapshotChannel() @@ -136,7 +131,6 @@ def test_default(self): class TestDriveChannel(QiskitTestCase): """DriveChannel tests.""" - @ignore_pulse_deprecation_warnings def test_default(self): """Test default drive channel.""" drive_channel = DriveChannel(123) @@ -155,7 +149,6 @@ def test_validation(self): class TestControlChannel(QiskitTestCase): """ControlChannel tests.""" - @ignore_pulse_deprecation_warnings def test_default(self): """Test default control channel.""" control_channel = ControlChannel(123) @@ -174,7 +167,6 @@ def test_validation(self): class TestMeasureChannel(QiskitTestCase): """MeasureChannel tests.""" - @ignore_pulse_deprecation_warnings def test_default(self): """Test default measure channel.""" measure_channel = MeasureChannel(123) diff --git a/test/python/pulse/test_experiment_configurations.py b/test/python/pulse/test_experiment_configurations.py index 51e3e2184531..8d6a93b39eac 100644 --- a/test/python/pulse/test_experiment_configurations.py +++ b/test/python/pulse/test_experiment_configurations.py @@ -18,13 +18,11 @@ from qiskit.pulse.exceptions import PulseError from qiskit.pulse import LoConfig, LoRange, Kernel, Discriminator from test import QiskitTestCase # pylint: disable=wrong-import-order -from qiskit.pulse.deprecate import ignore_pulse_deprecation_warnings class TestLoRange(QiskitTestCase): """Test LO LoRange.""" - @ignore_pulse_deprecation_warnings def test_properties_includes_and_eq(self): """Test creation of LoRange. Test upper/lower bounds and includes. Test __eq__ for two same and different LoRange's. @@ -45,7 +43,6 @@ def test_properties_includes_and_eq(self): class TestLoConfig(QiskitTestCase): """LoConfig tests.""" - @ignore_pulse_deprecation_warnings def test_can_create_empty_user_lo_config(self): """Test if a LoConfig can be created without no arguments.""" user_lo_config = LoConfig() @@ -100,7 +97,6 @@ def test_get_channel_lo(self): class TestKernel(QiskitTestCase): """Test Kernel.""" - @ignore_pulse_deprecation_warnings def test_eq(self): """Test if two kernels are equal.""" kernel_a = Kernel( @@ -161,7 +157,6 @@ def test_neq_nested_params(self): class TestDiscriminator(QiskitTestCase): """Test Discriminator.""" - @ignore_pulse_deprecation_warnings def test_eq(self): """Test if two discriminators are equal.""" discriminator_a = Discriminator( diff --git a/test/python/pulse/test_instruction_schedule_map.py b/test/python/pulse/test_instruction_schedule_map.py index 8e9af4456fdd..d1610d7ebcc0 100644 --- a/test/python/pulse/test_instruction_schedule_map.py +++ b/test/python/pulse/test_instruction_schedule_map.py @@ -35,13 +35,11 @@ from qiskit.qobj.converters import QobjToInstructionConverter from qiskit.providers.fake_provider import FakeOpenPulse2Q, Fake7QPulseV1 from test import QiskitTestCase # pylint: disable=wrong-import-order -from qiskit.pulse.deprecate import ignore_pulse_deprecation_warnings class TestInstructionScheduleMap(QiskitTestCase): """Test the InstructionScheduleMap.""" - @ignore_pulse_deprecation_warnings def test_add(self): """Test add, and that errors are raised when expected.""" sched = Schedule() diff --git a/test/python/pulse/test_instructions.py b/test/python/pulse/test_instructions.py index a7dbc58f9012..f0bdd165db08 100644 --- a/test/python/pulse/test_instructions.py +++ b/test/python/pulse/test_instructions.py @@ -17,13 +17,11 @@ from qiskit import circuit from qiskit.pulse import channels, configuration, instructions, library, exceptions from test import QiskitTestCase # pylint: disable=wrong-import-order -from qiskit.pulse.deprecate import ignore_pulse_deprecation_warnings class TestAcquire(QiskitTestCase): """Acquisition tests.""" - @ignore_pulse_deprecation_warnings def test_can_construct_valid_acquire_command(self): """Test if valid acquire command can be constructed.""" kernel_opts = {"start_window": 0, "stop_window": 10} @@ -90,7 +88,6 @@ def test_instructions_hash(self): class TestDelay(QiskitTestCase): """Delay tests.""" - @ignore_pulse_deprecation_warnings def test_delay(self): """Test delay.""" delay = instructions.Delay(10, channels.DriveChannel(0), name="test_name") @@ -127,7 +124,6 @@ def test_operator_delay(self): class TestSetFrequency(QiskitTestCase): """Set frequency tests.""" - @ignore_pulse_deprecation_warnings def test_freq(self): """Test set frequency basic functionality.""" set_freq = instructions.SetFrequency(4.5e9, channels.DriveChannel(1), name="test") @@ -144,7 +140,6 @@ def test_freq(self): ) self.assertEqual(repr(set_freq), "SetFrequency(4500000000.0, DriveChannel(1), name='test')") - @ignore_pulse_deprecation_warnings def test_freq_non_pulse_channel(self): """Test set frequency constructor with illegal channel""" with self.assertRaises(exceptions.PulseError): @@ -181,7 +176,6 @@ def test_shift_freq(self): repr(shift_freq), "ShiftFrequency(4500000000.0, DriveChannel(1), name='test')" ) - @ignore_pulse_deprecation_warnings def test_freq_non_pulse_channel(self): """Test shift frequency constructor with illegal channel""" with self.assertRaises(exceptions.PulseError): @@ -200,7 +194,6 @@ def test_parameter_expression(self): class TestSetPhase(QiskitTestCase): """Test the instruction construction.""" - @ignore_pulse_deprecation_warnings def test_default(self): """Test basic SetPhase.""" set_phase = instructions.SetPhase(1.57, channels.DriveChannel(0)) @@ -236,7 +229,6 @@ def test_parameter_expression(self): class TestShiftPhase(QiskitTestCase): """Test the instruction construction.""" - @ignore_pulse_deprecation_warnings def test_default(self): """Test basic ShiftPhase.""" shift_phase = instructions.ShiftPhase(1.57, channels.DriveChannel(0)) @@ -272,7 +264,6 @@ def test_parameter_expression(self): class TestSnapshot(QiskitTestCase): """Snapshot tests.""" - @ignore_pulse_deprecation_warnings def test_default(self): """Test default snapshot.""" snapshot = instructions.Snapshot(label="test_name", snapshot_type="state") @@ -288,14 +279,12 @@ def test_default(self): class TestPlay(QiskitTestCase): """Play tests.""" - @ignore_pulse_deprecation_warnings def setUp(self): """Setup play tests.""" super().setUp() self.duration = 4 self.pulse_op = library.Waveform([1.0] * self.duration, name="test") - @ignore_pulse_deprecation_warnings def test_play(self): """Test basic play instruction.""" play = instructions.Play(self.pulse_op, channels.DriveChannel(1)) @@ -318,7 +307,6 @@ def test_play_non_pulse_ch_raises(self): class TestDirectives(QiskitTestCase): """Test pulse directives.""" - @ignore_pulse_deprecation_warnings def test_relative_barrier(self): """Test the relative barrier directive.""" a0 = channels.AcquireChannel(0) diff --git a/test/python/pulse/test_macros.py b/test/python/pulse/test_macros.py index b1595e7e006d..6d87320cf480 100644 --- a/test/python/pulse/test_macros.py +++ b/test/python/pulse/test_macros.py @@ -26,13 +26,11 @@ from qiskit.pulse.exceptions import PulseError from qiskit.providers.fake_provider import FakeOpenPulse2Q, Fake27QPulseV1, GenericBackendV2 from test import QiskitTestCase # pylint: disable=wrong-import-order -from qiskit.pulse.deprecate import ignore_pulse_deprecation_warnings class TestMeasure(QiskitTestCase): """Pulse measure macro.""" - @ignore_pulse_deprecation_warnings def setUp(self): super().setUp() with self.assertWarns(DeprecationWarning): @@ -93,7 +91,6 @@ def test_measure_with_custom_inst_map(self): with self.assertRaises(PulseError): macros.measure(qubits=[0], measure_name="name", inst_map=inst_map, meas_map=[[0]]) - @ignore_pulse_deprecation_warnings def test_fail_measure(self): """Test failing measure.""" with self.assertRaises(PulseError): @@ -216,7 +213,6 @@ def test_output_with_multiple_measure_v1_and_measure_v2(self): class TestMeasureAll(QiskitTestCase): """Pulse measure all macro.""" - @ignore_pulse_deprecation_warnings def setUp(self): super().setUp() with self.assertWarns(DeprecationWarning): @@ -228,7 +224,6 @@ def setUp(self): seed=42, ) - @ignore_pulse_deprecation_warnings def test_measure_all(self): """Test measure_all function.""" sched = macros.measure_all(self.backend_v1) diff --git a/test/python/pulse/test_parameter_manager.py b/test/python/pulse/test_parameter_manager.py index 92a44ef6e7fd..0b91aaeaab4a 100644 --- a/test/python/pulse/test_parameter_manager.py +++ b/test/python/pulse/test_parameter_manager.py @@ -27,13 +27,11 @@ from qiskit.pulse.transforms import AlignEquispaced, AlignLeft, inline_subroutines from qiskit.pulse.utils import format_parameter_value from test import QiskitTestCase # pylint: disable=wrong-import-order -from qiskit.pulse.deprecate import ignore_pulse_deprecation_warnings class ParameterTestBase(QiskitTestCase): """A base class for parameter manager unittest, providing test schedule.""" - @ignore_pulse_deprecation_warnings def setUp(self): """Just some useful, reusable Parameters, constants, schedules.""" super().setUp() @@ -105,7 +103,6 @@ def setUp(self): class TestParameterGetter(ParameterTestBase): """Test getting parameters.""" - @ignore_pulse_deprecation_warnings def test_get_parameter_from_channel(self): """Test get parameters from channel.""" test_obj = pulse.DriveChannel(self.ch1 + self.ch2) @@ -128,7 +125,6 @@ def test_get_parameter_from_pulse(self): self.assertSetEqual(visitor.parameters, ref_params) - @ignore_pulse_deprecation_warnings def test_get_parameter_from_acquire(self): """Test get parameters from acquire instruction.""" test_obj = pulse.Acquire(16000, pulse.AcquireChannel(self.ch1), pulse.MemorySlot(self.ch1)) @@ -335,7 +331,6 @@ def test_complex_value_to_parameter(self): self.assertEqual(assigned.amp, 0.1j) - @ignore_pulse_deprecation_warnings def test_complex_parameter_expression(self): """Test assignment of complex-valued parameter expression to parameter, but raises PendingDeprecationWarning.""" @@ -459,7 +454,6 @@ def test_set_parameter_to_complex_schedule(self): class TestAssignFromProgram(QiskitTestCase): """Test managing parameters from programs. Parameter manager is implicitly called.""" - @ignore_pulse_deprecation_warnings def test_attribute_parameters(self): """Test the ``parameter`` attributes.""" sigma = Parameter("sigma") @@ -625,7 +619,6 @@ def test_overlapping_on_multiple_assignment(self): with self.assertRaises(PulseError): schedule.assign_parameters({param_idx2: 2}) - @ignore_pulse_deprecation_warnings def test_cannot_build_schedule_with_unassigned_duration(self): """Test we cannot build schedule with parameterized instructions""" dur = Parameter("dur") diff --git a/test/python/pulse/test_parser.py b/test/python/pulse/test_parser.py index 45cf35fbeac1..8fb491b9da74 100644 --- a/test/python/pulse/test_parser.py +++ b/test/python/pulse/test_parser.py @@ -15,7 +15,6 @@ from qiskit.pulse.parser import parse_string_expr from qiskit.pulse.exceptions import PulseError from test import QiskitTestCase # pylint: disable=wrong-import-order -from qiskit.pulse.deprecate import ignore_pulse_deprecation_warnings class TestInstructionToQobjConverter(QiskitTestCase): @@ -213,7 +212,6 @@ def test_partial_binding(self): self.assertEqual(bound_four_new(P5=5), -2.925) self.assertEqual(bound_four_new(5), -2.925) - @ignore_pulse_deprecation_warnings def test_argument_duplication(self): """Test duplication of *args and **kwargs.""" diff --git a/test/python/pulse/test_pulse_lib.py b/test/python/pulse/test_pulse_lib.py index 82ff640bd335..9c57579d0bf1 100644 --- a/test/python/pulse/test_pulse_lib.py +++ b/test/python/pulse/test_pulse_lib.py @@ -39,7 +39,6 @@ ) from qiskit.pulse import functional_pulse, PulseError from test import QiskitTestCase # pylint: disable=wrong-import-order -from qiskit.pulse.deprecate import ignore_pulse_deprecation_warnings class TestWaveform(QiskitTestCase): @@ -86,7 +85,6 @@ def test_type_casting(self): sample_pulse_list = Waveform(samples_list) self.assertEqual(sample_pulse_list.samples.dtype, np.complex128) - @ignore_pulse_deprecation_warnings def test_pulse_limits(self): """Test that limits of pulse norm of one are enforced properly.""" @@ -588,7 +586,6 @@ def test_class_level_limit_amplitude(self): waveform = GaussianSquareDrag(duration=100, sigma=1.0, amp=1.1, beta=0.1, width=10) self.assertGreater(np.abs(waveform.amp), 1.0) - @ignore_pulse_deprecation_warnings def test_class_level_disable_validation(self): """Test that pulse validation can be disabled on the class level. @@ -836,7 +833,6 @@ class TestFunctionalPulse(QiskitTestCase): """Waveform tests.""" # pylint: disable=invalid-name - @ignore_pulse_deprecation_warnings def test_gaussian(self): """Test gaussian pulse.""" @@ -892,7 +888,6 @@ def test_scalable_comparison(self): gaussian1._params["sigma"] = 10 self.assertNotEqual(gaussian1, gaussian2) - @ignore_pulse_deprecation_warnings def test_complex_amp_error(self): """Test that initializing a pulse with complex amp raises an error""" with self.assertRaises(PulseError): diff --git a/test/python/pulse/test_reference.py b/test/python/pulse/test_reference.py index 8fdff3eaaa6b..3d7603461756 100644 --- a/test/python/pulse/test_reference.py +++ b/test/python/pulse/test_reference.py @@ -18,7 +18,6 @@ from qiskit.pulse import ScheduleBlock, builder from qiskit.pulse.transforms import inline_subroutines from test import QiskitTestCase # pylint: disable=wrong-import-order -from qiskit.pulse.deprecate import ignore_pulse_deprecation_warnings class TestReference(QiskitTestCase): @@ -248,7 +247,6 @@ def test_calling_same_schedule_with_different_assignment(self): self.assertEqual(len(sched_z1.references), 2) - @ignore_pulse_deprecation_warnings def test_alignment_context(self): """Test nested alignment context. @@ -435,7 +433,6 @@ def test_assign_existing_reference(self): class TestSubroutineWithCXGate(QiskitTestCase): """Test called program scope with practical example of building fully parametrized CX gate.""" - @ignore_pulse_deprecation_warnings def setUp(self): super().setUp() @@ -540,7 +537,6 @@ def test_lazy_ecr(self): params = sched.get_parameters(parameter_name="amp") self.assertEqual(len(params), 2) - @ignore_pulse_deprecation_warnings def test_cnot(self): """Integration test with CNOT schedule construction.""" # echoed cross resonance diff --git a/test/python/pulse/test_samplers.py b/test/python/pulse/test_samplers.py index 9238d81a4aa3..4e6ab46737d6 100644 --- a/test/python/pulse/test_samplers.py +++ b/test/python/pulse/test_samplers.py @@ -18,7 +18,6 @@ from qiskit.pulse import library from qiskit.pulse.library import samplers from test import QiskitTestCase # pylint: disable=wrong-import-order -from qiskit.pulse.deprecate import ignore_pulse_deprecation_warnings def linear(times: np.ndarray, m: float, b: float = 0.1) -> np.ndarray: @@ -83,7 +82,6 @@ def test_sampler_name(self): self.assertIsInstance(pulse, library.Waveform) self.assertEqual(pulse.name, "test") - @ignore_pulse_deprecation_warnings def test_default_arg_sampler(self): """Test that default arguments work with sampler.""" m = 0.1 diff --git a/test/python/pulse/test_schedule.py b/test/python/pulse/test_schedule.py index a8a382d5f698..5e5676e7c2d9 100644 --- a/test/python/pulse/test_schedule.py +++ b/test/python/pulse/test_schedule.py @@ -47,7 +47,6 @@ from qiskit.pulse.schedule import Schedule, _overlaps, _find_insertion_index from qiskit.providers.fake_provider import FakeOpenPulse2Q from test import QiskitTestCase # pylint: disable=wrong-import-order -from qiskit.pulse.deprecate import ignore_pulse_deprecation_warnings class BaseTestSchedule(QiskitTestCase): @@ -233,7 +232,6 @@ def test_flat_instruction_sequence_returns_instructions(self): for _, instr in sched.instructions: self.assertIsInstance(instr, Instruction) - @ignore_pulse_deprecation_warnings def test_absolute_start_time_of_grandchild(self): """Test correct calculation of start time of grandchild of a schedule.""" lp0 = self.linear(duration=10, slope=0.02, intercept=0.01) @@ -516,7 +514,6 @@ def test_replace_schedule(self): sched.replace(old, new, inplace=True) self.assertEqual(sched, ref_sched) - @ignore_pulse_deprecation_warnings def test_replace_fails_on_overlap(self): """Test that replacement fails on overlap.""" old = Play(Constant(20, 1.0), DriveChannel(0)) @@ -578,7 +575,6 @@ def test_delay_control_channel(self): sched = Delay(self.delay_time, control_ch) | Play(pulse, control_ch) self.assertIsInstance(sched, Schedule) - @ignore_pulse_deprecation_warnings def test_delay_acquire_channel(self): """Test Delay on DriveChannel""" @@ -807,7 +803,6 @@ def test_filter_multiple(self): self.assertIsInstance(inst, Acquire) self.assertTrue(len(filtered.instructions), 2) - @ignore_pulse_deprecation_warnings def test_custom_filters(self): """Test custom filters.""" lp0 = self.linear(duration=3, slope=0.2, intercept=0.1) @@ -890,7 +885,6 @@ def _filter_and_test_consistency(self, schedule: Schedule, *args, **kwargs): class TestScheduleEquality(BaseTestSchedule): """Test equality of schedules.""" - @ignore_pulse_deprecation_warnings def test_different_channels(self): """Test equality is False if different channels.""" self.assertNotEqual( diff --git a/test/python/pulse/test_transforms.py b/test/python/pulse/test_transforms.py index 7cd306567dcd..c16405cff4d1 100644 --- a/test/python/pulse/test_transforms.py +++ b/test/python/pulse/test_transforms.py @@ -39,13 +39,11 @@ from qiskit.pulse.instructions import directives from qiskit.providers.fake_provider import FakeOpenPulse2Q from test import QiskitTestCase # pylint: disable=wrong-import-order -from qiskit.pulse.deprecate import ignore_pulse_deprecation_warnings class TestAlignMeasures(QiskitTestCase): """Test the helper function which aligns acquires.""" - @ignore_pulse_deprecation_warnings def setUp(self): super().setUp() with self.assertWarns(DeprecationWarning): @@ -136,7 +134,6 @@ def test_multiple_acquires(self): self.assertEqual(aligned, ref) - @ignore_pulse_deprecation_warnings def test_align_across_schedules(self): """Test that acquires are aligned together across multiple schedules.""" sched1 = pulse.Schedule(name="fake_experiment") @@ -204,7 +201,6 @@ def test_measurement_at_zero(self): class TestAddImplicitAcquires(QiskitTestCase): """Test the helper function which makes implicit acquires explicit.""" - @ignore_pulse_deprecation_warnings def setUp(self): super().setUp() with self.assertWarns(DeprecationWarning): @@ -228,7 +224,6 @@ def test_add_implicit(self): acquired_qubits.add(inst.acquire.index) self.assertEqual(acquired_qubits, {0, 1}) - @ignore_pulse_deprecation_warnings def test_add_across_meas_map_sublists(self): """Test that implicit acquires in separate meas map sublists are all added.""" sched = transforms.add_implicit_acquires(self.sched, [[0, 2], [1, 3]]) @@ -366,7 +361,6 @@ def test_padding_prepended_delay(self): self.assertEqual(transforms.pad(sched, until=30, inplace=True), ref_sched) - @ignore_pulse_deprecation_warnings def test_pad_no_delay_on_classical_io_channels(self): """Test padding does not apply to classical IO channels.""" delay = 10 @@ -502,7 +496,6 @@ def test_sample_pulses_with_tolerance(self): self.assertEqual(len(original_pulse_ids), 2) self.assertEqual(len(compressed_pulse_ids), 1) - @ignore_pulse_deprecation_warnings def test_multiple_schedules(self): """Test multiple schedules.""" schedules = [] @@ -524,7 +517,6 @@ def test_multiple_schedules(self): class TestAlignSequential(QiskitTestCase): """Test sequential alignment transform.""" - @ignore_pulse_deprecation_warnings def test_align_sequential(self): """Test sequential alignment without a barrier.""" context = transforms.AlignSequential() @@ -573,7 +565,6 @@ def test_align_sequential_with_barrier(self): class TestAlignLeft(QiskitTestCase): """Test left alignment transform.""" - @ignore_pulse_deprecation_warnings def test_align_left(self): """Test left alignment without a barrier.""" context = transforms.AlignLeft() @@ -637,7 +628,6 @@ def test_align_left_with_barrier(self): class TestAlignRight(QiskitTestCase): """Test right alignment transform.""" - @ignore_pulse_deprecation_warnings def test_align_right(self): """Test right alignment without a barrier.""" context = transforms.AlignRight() @@ -702,7 +692,6 @@ def test_align_right_with_barrier(self): class TestAlignEquispaced(QiskitTestCase): """Test equispaced alignment transform.""" - @ignore_pulse_deprecation_warnings def test_equispaced_with_short_duration(self): """Test equispaced context with duration shorter than the schedule duration.""" context = transforms.AlignEquispaced(duration=20) @@ -721,7 +710,6 @@ def test_equispaced_with_short_duration(self): self.assertEqual(schedule, reference) - @ignore_pulse_deprecation_warnings def test_equispaced_with_longer_duration(self): """Test equispaced context with duration longer than the schedule duration.""" context = transforms.AlignEquispaced(duration=50) @@ -787,7 +775,6 @@ def _position(ind): """Returns 0.25, 0.5, 0.75 for ind = 1, 2, 3.""" return ind / (3 + 1) - @ignore_pulse_deprecation_warnings def test_numerical_with_short_duration(self): """Test numerical alignment context with duration shorter than the schedule duration.""" context = transforms.AlignFunc(duration=20, func=self._position) @@ -806,7 +793,6 @@ def test_numerical_with_short_duration(self): self.assertEqual(schedule, reference) - @ignore_pulse_deprecation_warnings def test_numerical_with_longer_duration(self): """Test numerical alignment context with duration longer than the schedule duration.""" context = transforms.AlignFunc(duration=80, func=self._position) @@ -829,7 +815,6 @@ def test_numerical_with_longer_duration(self): class TestFlatten(QiskitTestCase): """Test flattening transform.""" - @ignore_pulse_deprecation_warnings def test_flatten(self): """Test the flatten transform.""" context_left = transforms.AlignLeft() @@ -879,7 +864,6 @@ def channels(self): class TestRemoveDirectives(QiskitTestCase): """Test removing of directives.""" - @ignore_pulse_deprecation_warnings def test_remove_directives(self): """Test that all directives are removed.""" d0 = pulse.DriveChannel(0) @@ -900,7 +884,6 @@ def test_remove_directives(self): class TestRemoveTrivialBarriers(QiskitTestCase): """Test scheduling transforms.""" - @ignore_pulse_deprecation_warnings def test_remove_trivial_barriers(self): """Test that trivial barriers are properly removed.""" schedule = pulse.Schedule() diff --git a/test/utils/base.py b/test/utils/base.py index 0038f7772ebf..bd8a4039fc3b 100644 --- a/test/utils/base.py +++ b/test/utils/base.py @@ -164,6 +164,13 @@ def setUpClass(cls): module="qiskit.providers.fake_provider.fake_backend", ) + # Safe to remove once Pulse is removed in Qiskit 2.0 + warnings.filterwarnings( + 'ignore', + category=DeprecationWarning, + message=".*The entire Qiskit Pulse package is being deprecated.*", + ) + allow_DeprecationWarning_message = [ r"The property ``qiskit\.circuit\.bit\.Bit\.(register|index)`` is deprecated.*", ] From ce2ef84cfc4e381f1bfa648cb5bee1e92fd80a59 Mon Sep 17 00:00:00 2001 From: Eli Arbel Date: Mon, 23 Sep 2024 10:30:43 +0300 Subject: [PATCH 05/23] Fix import path for deprecate_pulse_func --- qiskit/pulse/builder.py | 2 +- qiskit/pulse/calibration_entries.py | 2 +- qiskit/pulse/channels.py | 2 +- qiskit/pulse/configuration.py | 2 +- qiskit/pulse/exceptions.py | 2 +- qiskit/pulse/instruction_schedule_map.py | 2 +- qiskit/pulse/instructions/acquire.py | 2 +- qiskit/pulse/instructions/delay.py | 2 +- qiskit/pulse/instructions/directives.py | 2 +- qiskit/pulse/instructions/frequency.py | 2 +- qiskit/pulse/instructions/instruction.py | 2 +- qiskit/pulse/instructions/phase.py | 2 +- qiskit/pulse/instructions/play.py | 2 +- qiskit/pulse/instructions/reference.py | 2 +- qiskit/pulse/instructions/snapshot.py | 2 +- qiskit/pulse/library/symbolic_pulses.py | 2 +- qiskit/pulse/library/waveform.py | 2 +- qiskit/pulse/parameter_manager.py | 2 +- qiskit/pulse/parser.py | 2 +- qiskit/pulse/schedule.py | 2 +- qiskit/pulse/transforms/alignments.py | 2 +- 21 files changed, 21 insertions(+), 21 deletions(-) diff --git a/qiskit/pulse/builder.py b/qiskit/pulse/builder.py index 57d89fa45c73..4987d5adf3b6 100644 --- a/qiskit/pulse/builder.py +++ b/qiskit/pulse/builder.py @@ -437,7 +437,7 @@ from qiskit.pulse.instructions import directives from qiskit.pulse.schedule import Schedule, ScheduleBlock from qiskit.pulse.transforms.alignments import AlignmentKind -from qiskit.pulse.deprecate import deprecate_pulse_func +from qiskit.utils.deprecate_pulse import deprecate_pulse_func if sys.version_info >= (3, 12): diff --git a/qiskit/pulse/calibration_entries.py b/qiskit/pulse/calibration_entries.py index 855f69cec14a..cce4885d31c1 100644 --- a/qiskit/pulse/calibration_entries.py +++ b/qiskit/pulse/calibration_entries.py @@ -24,7 +24,7 @@ from qiskit.qobj.converters import QobjToInstructionConverter from qiskit.qobj.pulse_qobj import PulseQobjInstruction from qiskit.exceptions import QiskitError -from qiskit.pulse.deprecate import deprecate_pulse_func +from qiskit.utils.deprecate_pulse import deprecate_pulse_func IncompletePulseQobj = object() diff --git a/qiskit/pulse/channels.py b/qiskit/pulse/channels.py index 0d98775c62a4..ebd0de886fb0 100644 --- a/qiskit/pulse/channels.py +++ b/qiskit/pulse/channels.py @@ -58,7 +58,7 @@ from qiskit.circuit import Parameter from qiskit.circuit.parameterexpression import ParameterExpression from qiskit.pulse.exceptions import PulseError -from qiskit.pulse.deprecate import deprecate_pulse_func +from qiskit.utils.deprecate_pulse import deprecate_pulse_func class Channel(metaclass=ABCMeta): diff --git a/qiskit/pulse/configuration.py b/qiskit/pulse/configuration.py index 2049da6cfd3d..2b9f12b41f09 100644 --- a/qiskit/pulse/configuration.py +++ b/qiskit/pulse/configuration.py @@ -18,7 +18,7 @@ from .channels import DriveChannel, MeasureChannel from .exceptions import PulseError -from qiskit.pulse.deprecate import deprecate_pulse_func +from qiskit.utils.deprecate_pulse import deprecate_pulse_func def _assert_nested_dict_equal(a: dict, b: dict): diff --git a/qiskit/pulse/exceptions.py b/qiskit/pulse/exceptions.py index 5fc3793398ea..29d5288bc121 100644 --- a/qiskit/pulse/exceptions.py +++ b/qiskit/pulse/exceptions.py @@ -12,7 +12,7 @@ """Exception for errors raised by the pulse module.""" from qiskit.exceptions import QiskitError -from qiskit.pulse.deprecate import deprecate_pulse_func +from qiskit.utils.deprecate_pulse import deprecate_pulse_func class PulseError(QiskitError): diff --git a/qiskit/pulse/instruction_schedule_map.py b/qiskit/pulse/instruction_schedule_map.py index e46de27b3afd..23e90df665fa 100644 --- a/qiskit/pulse/instruction_schedule_map.py +++ b/qiskit/pulse/instruction_schedule_map.py @@ -46,7 +46,7 @@ ) from qiskit.pulse.exceptions import PulseError from qiskit.pulse.schedule import Schedule, ScheduleBlock -from qiskit.pulse.deprecate import deprecate_pulse_func +from qiskit.utils.deprecate_pulse import deprecate_pulse_func class InstructionScheduleMap: diff --git a/qiskit/pulse/instructions/acquire.py b/qiskit/pulse/instructions/acquire.py index 263d14b0f102..3b5964d4ee3e 100644 --- a/qiskit/pulse/instructions/acquire.py +++ b/qiskit/pulse/instructions/acquire.py @@ -19,7 +19,7 @@ from qiskit.pulse.configuration import Kernel, Discriminator from qiskit.pulse.exceptions import PulseError from qiskit.pulse.instructions.instruction import Instruction -from qiskit.pulse.deprecate import deprecate_pulse_func +from qiskit.utils.deprecate_pulse import deprecate_pulse_func class Acquire(Instruction): diff --git a/qiskit/pulse/instructions/delay.py b/qiskit/pulse/instructions/delay.py index c69115484623..6dd028c94fcd 100644 --- a/qiskit/pulse/instructions/delay.py +++ b/qiskit/pulse/instructions/delay.py @@ -16,7 +16,7 @@ from qiskit.circuit import ParameterExpression from qiskit.pulse.channels import Channel from qiskit.pulse.instructions.instruction import Instruction -from qiskit.pulse.deprecate import deprecate_pulse_func +from qiskit.utils.deprecate_pulse import deprecate_pulse_func class Delay(Instruction): diff --git a/qiskit/pulse/instructions/directives.py b/qiskit/pulse/instructions/directives.py index 6b09b1e66373..1572c887f376 100644 --- a/qiskit/pulse/instructions/directives.py +++ b/qiskit/pulse/instructions/directives.py @@ -18,7 +18,7 @@ from qiskit.pulse import channels as chans from qiskit.pulse.instructions import instruction from qiskit.pulse.exceptions import PulseError -from qiskit.pulse.deprecate import deprecate_pulse_func +from qiskit.utils.deprecate_pulse import deprecate_pulse_func class Directive(instruction.Instruction, ABC): diff --git a/qiskit/pulse/instructions/frequency.py b/qiskit/pulse/instructions/frequency.py index de56222c42bb..545d26c92639 100644 --- a/qiskit/pulse/instructions/frequency.py +++ b/qiskit/pulse/instructions/frequency.py @@ -19,7 +19,7 @@ from qiskit.pulse.channels import PulseChannel from qiskit.pulse.instructions.instruction import Instruction from qiskit.pulse.exceptions import PulseError -from qiskit.pulse.deprecate import deprecate_pulse_func +from qiskit.utils.deprecate_pulse import deprecate_pulse_func class SetFrequency(Instruction): diff --git a/qiskit/pulse/instructions/instruction.py b/qiskit/pulse/instructions/instruction.py index a604a0af1e91..fda854d2b7eb 100644 --- a/qiskit/pulse/instructions/instruction.py +++ b/qiskit/pulse/instructions/instruction.py @@ -28,7 +28,7 @@ from qiskit.circuit import Parameter, ParameterExpression from qiskit.pulse.channels import Channel from qiskit.pulse.exceptions import PulseError -from qiskit.pulse.deprecate import deprecate_pulse_func +from qiskit.utils.deprecate_pulse import deprecate_pulse_func # pylint: disable=bad-docstring-quotes diff --git a/qiskit/pulse/instructions/phase.py b/qiskit/pulse/instructions/phase.py index b1a889d40963..1d08918cb7e9 100644 --- a/qiskit/pulse/instructions/phase.py +++ b/qiskit/pulse/instructions/phase.py @@ -21,7 +21,7 @@ from qiskit.pulse.channels import PulseChannel from qiskit.pulse.instructions.instruction import Instruction from qiskit.pulse.exceptions import PulseError -from qiskit.pulse.deprecate import deprecate_pulse_func +from qiskit.utils.deprecate_pulse import deprecate_pulse_func class ShiftPhase(Instruction): diff --git a/qiskit/pulse/instructions/play.py b/qiskit/pulse/instructions/play.py index 3d2edca0cacb..8c86555bbc8c 100644 --- a/qiskit/pulse/instructions/play.py +++ b/qiskit/pulse/instructions/play.py @@ -21,7 +21,7 @@ from qiskit.pulse.exceptions import PulseError from qiskit.pulse.instructions.instruction import Instruction from qiskit.pulse.library.pulse import Pulse -from qiskit.pulse.deprecate import deprecate_pulse_func +from qiskit.utils.deprecate_pulse import deprecate_pulse_func class Play(Instruction): diff --git a/qiskit/pulse/instructions/reference.py b/qiskit/pulse/instructions/reference.py index 3863b8044682..1f17327877a7 100644 --- a/qiskit/pulse/instructions/reference.py +++ b/qiskit/pulse/instructions/reference.py @@ -17,7 +17,7 @@ from qiskit.pulse.channels import Channel from qiskit.pulse.exceptions import PulseError, UnassignedReferenceError from qiskit.pulse.instructions import instruction -from qiskit.pulse.deprecate import deprecate_pulse_func +from qiskit.utils.deprecate_pulse import deprecate_pulse_func class Reference(instruction.Instruction): diff --git a/qiskit/pulse/instructions/snapshot.py b/qiskit/pulse/instructions/snapshot.py index 4edc1e7d170a..1692d13abc8f 100644 --- a/qiskit/pulse/instructions/snapshot.py +++ b/qiskit/pulse/instructions/snapshot.py @@ -18,7 +18,7 @@ from qiskit.pulse.channels import SnapshotChannel from qiskit.pulse.exceptions import PulseError from qiskit.pulse.instructions.instruction import Instruction -from qiskit.pulse.deprecate import deprecate_pulse_func +from qiskit.utils.deprecate_pulse import deprecate_pulse_func class Snapshot(Instruction): diff --git a/qiskit/pulse/library/symbolic_pulses.py b/qiskit/pulse/library/symbolic_pulses.py index 19e4e3715213..c681e0b61281 100644 --- a/qiskit/pulse/library/symbolic_pulses.py +++ b/qiskit/pulse/library/symbolic_pulses.py @@ -31,7 +31,7 @@ from qiskit.pulse.exceptions import PulseError from qiskit.pulse.library.pulse import Pulse from qiskit.pulse.library.waveform import Waveform -from qiskit.pulse.deprecate import deprecate_pulse_func +from qiskit.utils.deprecate_pulse import deprecate_pulse_func def _lifted_gaussian( diff --git a/qiskit/pulse/library/waveform.py b/qiskit/pulse/library/waveform.py index ae625febaf74..0a31ac11a8d8 100644 --- a/qiskit/pulse/library/waveform.py +++ b/qiskit/pulse/library/waveform.py @@ -18,7 +18,7 @@ from qiskit.pulse.exceptions import PulseError from qiskit.pulse.library.pulse import Pulse -from qiskit.pulse.deprecate import deprecate_pulse_func +from qiskit.utils.deprecate_pulse import deprecate_pulse_func class Waveform(Pulse): diff --git a/qiskit/pulse/parameter_manager.py b/qiskit/pulse/parameter_manager.py index 426dd59a78a2..72a5052a212e 100644 --- a/qiskit/pulse/parameter_manager.py +++ b/qiskit/pulse/parameter_manager.py @@ -67,7 +67,7 @@ _validate_parameter_vector, _validate_parameter_value, ) -from qiskit.pulse.deprecate import deprecate_pulse_func +from qiskit.utils.deprecate_pulse import deprecate_pulse_func class NodeVisitor: diff --git a/qiskit/pulse/parser.py b/qiskit/pulse/parser.py index 5a7f9abab10a..7c79e4152473 100644 --- a/qiskit/pulse/parser.py +++ b/qiskit/pulse/parser.py @@ -24,7 +24,7 @@ from qiskit.pulse.exceptions import PulseError from qiskit.circuit import ParameterExpression -from qiskit.pulse.deprecate import deprecate_pulse_func +from qiskit.utils.deprecate_pulse import deprecate_pulse_func class PulseExpression(ast.NodeTransformer): diff --git a/qiskit/pulse/schedule.py b/qiskit/pulse/schedule.py index a56e80d925da..794d511c077e 100644 --- a/qiskit/pulse/schedule.py +++ b/qiskit/pulse/schedule.py @@ -54,7 +54,7 @@ from qiskit.pulse.reference_manager import ReferenceManager from qiskit.utils.multiprocessing import is_main_process from qiskit.utils import deprecate_arg -from qiskit.pulse.deprecate import deprecate_pulse_func +from qiskit.utils.deprecate_pulse import deprecate_pulse_func Interval = Tuple[int, int] diff --git a/qiskit/pulse/transforms/alignments.py b/qiskit/pulse/transforms/alignments.py index 846247b280e5..e3bbeaa71ad0 100644 --- a/qiskit/pulse/transforms/alignments.py +++ b/qiskit/pulse/transforms/alignments.py @@ -20,7 +20,7 @@ from qiskit.pulse.exceptions import PulseError from qiskit.pulse.schedule import Schedule, ScheduleComponent from qiskit.pulse.utils import instruction_duration_validation -from qiskit.pulse.deprecate import deprecate_pulse_func +from qiskit.utils.deprecate_pulse import deprecate_pulse_func class AlignmentKind(abc.ABC): From b697bd6cafa42f41d04de178380dd62c3d1c7436 Mon Sep 17 00:00:00 2001 From: Eli Arbel Date: Mon, 23 Sep 2024 11:29:20 +0300 Subject: [PATCH 06/23] Deprecate `schedule_circuit` --- qiskit/scheduler/schedule_circuit.py | 2 ++ qiskit/utils/deprecate_pulse.py | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/qiskit/scheduler/schedule_circuit.py b/qiskit/scheduler/schedule_circuit.py index 52fd8bf72b76..3d74ffe3b5a8 100644 --- a/qiskit/scheduler/schedule_circuit.py +++ b/qiskit/scheduler/schedule_circuit.py @@ -20,8 +20,10 @@ from qiskit.scheduler.config import ScheduleConfig from qiskit.scheduler.methods import as_soon_as_possible, as_late_as_possible from qiskit.providers import BackendV1, BackendV2 +from qiskit.utils.deprecate_pulse import deprecate_pulse_dependency +@deprecate_pulse_dependency def schedule_circuit( circuit: QuantumCircuit, schedule_config: ScheduleConfig, diff --git a/qiskit/utils/deprecate_pulse.py b/qiskit/utils/deprecate_pulse.py index 67058931d3ca..ec22ce01e760 100644 --- a/qiskit/utils/deprecate_pulse.py +++ b/qiskit/utils/deprecate_pulse.py @@ -29,12 +29,12 @@ def deprecate_pulse_func(func): def deprecate_pulse_dependency(func): - """Deprecation message for functions and classes""" + """Deprecation message for functions and classes which use or depend on Pulse""" return deprecate_func( since="1.3", removal_timeline="in Qiskit 2.0", additional_msg="The entire Qiskit Pulse package is being deprecated. " - "This is a dependency on the package.", + "This is a dependency an as such it being deprecated as well.", )(func) From eebb01d2ef9000422e21d64e44c442cebc232f48 Mon Sep 17 00:00:00 2001 From: Eli Arbel Date: Mon, 23 Sep 2024 11:54:04 +0300 Subject: [PATCH 07/23] Deprecate compiler's `schedule`, `sequence` and related functions --- qiskit/compiler/scheduler.py | 2 ++ qiskit/compiler/sequencer.py | 2 ++ qiskit/scheduler/lowering.py | 2 ++ qiskit/scheduler/sequence.py | 2 ++ 4 files changed, 8 insertions(+) diff --git a/qiskit/compiler/scheduler.py b/qiskit/compiler/scheduler.py index e75e9a388f04..5e55b7df1ca2 100644 --- a/qiskit/compiler/scheduler.py +++ b/qiskit/compiler/scheduler.py @@ -26,6 +26,7 @@ from qiskit.scheduler.config import ScheduleConfig from qiskit.scheduler.schedule_circuit import schedule_circuit from qiskit.utils.parallel import parallel_map +from qiskit.utils.deprecate_pulse import deprecate_pulse_dependency logger = logging.getLogger(__name__) @@ -35,6 +36,7 @@ def _log_schedule_time(start_time, end_time): logger.info(log_msg) +@deprecate_pulse_dependency def schedule( circuits: Union[QuantumCircuit, List[QuantumCircuit]], backend: Optional[Backend] = None, diff --git a/qiskit/compiler/sequencer.py b/qiskit/compiler/sequencer.py index 541f78c9f762..3678f97ac969 100644 --- a/qiskit/compiler/sequencer.py +++ b/qiskit/compiler/sequencer.py @@ -21,8 +21,10 @@ from qiskit.pulse import InstructionScheduleMap, Schedule from qiskit.scheduler import ScheduleConfig from qiskit.scheduler.sequence import sequence as _sequence +from qiskit.utils.deprecate_pulse import deprecate_pulse_dependency +@deprecate_pulse_dependency def sequence( scheduled_circuits: Union[QuantumCircuit, List[QuantumCircuit]], backend: Optional[Backend] = None, diff --git a/qiskit/scheduler/lowering.py b/qiskit/scheduler/lowering.py index f0fb33957d9e..e0ea67f67aa0 100644 --- a/qiskit/scheduler/lowering.py +++ b/qiskit/scheduler/lowering.py @@ -29,6 +29,7 @@ from qiskit.pulse.macros import measure from qiskit.scheduler.config import ScheduleConfig from qiskit.providers import BackendV1, BackendV2 +from qiskit.utils.deprecate_pulse import deprecate_pulse_dependency CircuitPulseDef = namedtuple( "CircuitPulseDef", @@ -36,6 +37,7 @@ ) # The labels of the qubits involved in the command according to the circuit +@deprecate_pulse_dependency def lower_gates( circuit: QuantumCircuit, schedule_config: ScheduleConfig, diff --git a/qiskit/scheduler/sequence.py b/qiskit/scheduler/sequence.py index d73a5cdf93df..e05cac33a57c 100644 --- a/qiskit/scheduler/sequence.py +++ b/qiskit/scheduler/sequence.py @@ -25,8 +25,10 @@ from qiskit.scheduler.config import ScheduleConfig from qiskit.scheduler.lowering import lower_gates from qiskit.providers import BackendV1, BackendV2 +from qiskit.utils.deprecate_pulse import deprecate_pulse_dependency +@deprecate_pulse_dependency def sequence( scheduled_circuit: QuantumCircuit, schedule_config: ScheduleConfig, From 8bff31c53e2bc858de0fa2857f26eeece64840f7 Mon Sep 17 00:00:00 2001 From: Eli Arbel Date: Wed, 25 Sep 2024 13:14:14 +0300 Subject: [PATCH 08/23] Deprecate passing SchduleBlock(s) to qpy.dump --- qiskit/qpy/interface.py | 4 ++++ qiskit/utils/deprecate_pulse.py | 18 +++++++++++------- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/qiskit/qpy/interface.py b/qiskit/qpy/interface.py index d89117bc6a1c..ac774451fc19 100644 --- a/qiskit/qpy/interface.py +++ b/qiskit/qpy/interface.py @@ -27,6 +27,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.deprecate_pulse import deprecate_pulse_arg # pylint: disable=invalid-name @@ -73,6 +74,9 @@ VERSION_PATTERN_REGEX = re.compile(VERSION_PATTERN, re.VERBOSE | re.IGNORECASE) +@deprecate_pulse_arg("programs", + description="Passing 'ScheduleBlock'('s) to 'programs'", + predicate=lambda p: isinstance(p, ScheduleBlock)) def dump( programs: Union[List[QPY_SUPPORTED_TYPES], QPY_SUPPORTED_TYPES], file_obj: BinaryIO, diff --git a/qiskit/utils/deprecate_pulse.py b/qiskit/utils/deprecate_pulse.py index ec22ce01e760..a6ba38605daf 100644 --- a/qiskit/utils/deprecate_pulse.py +++ b/qiskit/utils/deprecate_pulse.py @@ -22,9 +22,9 @@ def deprecate_pulse_func(func): return deprecate_func( since="1.3", removal_timeline="in Qiskit 2.0", - additional_msg="The entire Qiskit Pulse package is being deprecated. " - "The package will be moved to the Qiskit Dynamics repository: " - "https://github.com/qiskit-community/qiskit-dynamics/", + additional_msg="The entire Qiskit Pulse package is being deprecated " + "and will be moved to the Qiskit Dynamics repository: " + "https://github.com/qiskit-community/qiskit-dynamics", )(func) @@ -33,17 +33,21 @@ def deprecate_pulse_dependency(func): return deprecate_func( since="1.3", removal_timeline="in Qiskit 2.0", - additional_msg="The entire Qiskit Pulse package is being deprecated. " - "This is a dependency an as such it being deprecated as well.", + additional_msg="The entire Qiskit Pulse package is being deprecated " + "and this is a dependency on the package.", )(func) -def deprecate_pulse_arg(arg_name): +def deprecate_pulse_arg(arg_name, description=None, predicate=None): """Deprecation message for arguments related to Pulse""" return deprecate_arg( name=arg_name, since="1.3", + deprecation_description=description, removal_timeline="in Qiskit 2.0", - additional_msg="The entire Qiskit Pulse package is being deprecated.", + additional_msg="The entire Qiskit Pulse package is being deprecated " + "and will be moved to the Qiskit Dynamics repository: " + "https://github.com/qiskit-community/qiskit-dynamics", + predicate=predicate ) From c90dd896dc4f1f1a2f03a5dd2ec9bb7f73e50ff0 Mon Sep 17 00:00:00 2001 From: Eli Arbel Date: Wed, 25 Sep 2024 18:25:39 +0300 Subject: [PATCH 09/23] More deprecations and misc updates --- qiskit/circuit/quantumcircuit.py | 3 ++- qiskit/providers/fake_provider/generic_backend_v2.py | 1 + qiskit/pulse/configuration.py | 2 +- qiskit/qpy/interface.py | 8 +++++--- qiskit/scheduler/methods/basic.py | 3 +++ qiskit/transpiler/passes/calibration/rx_builder.py | 2 ++ qiskit/transpiler/passes/calibration/rzx_builder.py | 2 ++ qiskit/transpiler/preset_passmanagers/common.py | 2 ++ .../preset_passmanagers/generate_preset_pass_manager.py | 2 ++ qiskit/transpiler/target.py | 7 ++++++- qiskit/utils/deprecate_pulse.py | 3 +-- test/utils/base.py | 2 +- 12 files changed, 28 insertions(+), 9 deletions(-) diff --git a/qiskit/circuit/quantumcircuit.py b/qiskit/circuit/quantumcircuit.py index 8199970c8fc0..1061c83ae85f 100644 --- a/qiskit/circuit/quantumcircuit.py +++ b/qiskit/circuit/quantumcircuit.py @@ -47,6 +47,7 @@ from qiskit.circuit.parameter import Parameter from qiskit.circuit.exceptions import CircuitError from qiskit.utils import deprecate_func +from qiskit.utils.deprecate_pulse import deprecate_pulse_dependency from . import _classical_resource_map from .controlflow import ControlFlowOp, _builder_utils from .controlflow.builder import CircuitScopeInterface, ControlFlowBuilderBlock @@ -69,7 +70,6 @@ from .quantumcircuitdata import QuantumCircuitData, CircuitInstruction from .delay import Delay from .store import Store -from qiskit.utils.deprecate_pulse import deprecate_pulse_dependency if typing.TYPE_CHECKING: @@ -1343,6 +1343,7 @@ def calibrations(self, calibrations: dict): """ self._calibrations = defaultdict(dict, calibrations) + @deprecate_pulse_dependency def has_calibration_for(self, instruction: CircuitInstruction | tuple): """Return True if the circuit has a calibration defined for the instruction context. In this case, the operation does not need to be translated to the device basis. diff --git a/qiskit/providers/fake_provider/generic_backend_v2.py b/qiskit/providers/fake_provider/generic_backend_v2.py index bfe6a07c224d..f5768afa83cb 100644 --- a/qiskit/providers/fake_provider/generic_backend_v2.py +++ b/qiskit/providers/fake_provider/generic_backend_v2.py @@ -524,6 +524,7 @@ class GenericBackendV2(BackendV2): @deprecate_pulse_arg("pulse_channels") + @deprecate_pulse_arg("calibration_instructions") def __init__( self, num_qubits: int, diff --git a/qiskit/pulse/configuration.py b/qiskit/pulse/configuration.py index 2b9f12b41f09..4c735caeeecc 100644 --- a/qiskit/pulse/configuration.py +++ b/qiskit/pulse/configuration.py @@ -15,10 +15,10 @@ """ from __future__ import annotations import numpy as np +from qiskit.utils.deprecate_pulse import deprecate_pulse_func from .channels import DriveChannel, MeasureChannel from .exceptions import PulseError -from qiskit.utils.deprecate_pulse import deprecate_pulse_func def _assert_nested_dict_equal(a: dict, b: dict): diff --git a/qiskit/qpy/interface.py b/qiskit/qpy/interface.py index ac774451fc19..381d3fc0720e 100644 --- a/qiskit/qpy/interface.py +++ b/qiskit/qpy/interface.py @@ -74,9 +74,11 @@ VERSION_PATTERN_REGEX = re.compile(VERSION_PATTERN, re.VERBOSE | re.IGNORECASE) -@deprecate_pulse_arg("programs", - description="Passing 'ScheduleBlock'('s) to 'programs'", - predicate=lambda p: isinstance(p, ScheduleBlock)) +@deprecate_pulse_arg( + "programs", + description="Passing 'ScheduleBlock'('s) to 'programs'", + predicate=lambda p: isinstance(p, ScheduleBlock), +) def dump( programs: Union[List[QPY_SUPPORTED_TYPES], QPY_SUPPORTED_TYPES], file_obj: BinaryIO, diff --git a/qiskit/scheduler/methods/basic.py b/qiskit/scheduler/methods/basic.py index 60b2f20056b3..48339bbe1b95 100644 --- a/qiskit/scheduler/methods/basic.py +++ b/qiskit/scheduler/methods/basic.py @@ -23,8 +23,10 @@ from qiskit.scheduler.config import ScheduleConfig from qiskit.scheduler.lowering import lower_gates from qiskit.providers import BackendV1, BackendV2 +from qiskit.utils.deprecate_pulse import deprecate_pulse_dependency +@deprecate_pulse_dependency def as_soon_as_possible( circuit: QuantumCircuit, schedule_config: ScheduleConfig, @@ -78,6 +80,7 @@ def update_times(inst_qubits: List[int], time: int = 0) -> None: return schedule +@deprecate_pulse_dependency def as_late_as_possible( circuit: QuantumCircuit, schedule_config: ScheduleConfig, diff --git a/qiskit/transpiler/passes/calibration/rx_builder.py b/qiskit/transpiler/passes/calibration/rx_builder.py index 45789e4cd109..bfe814833a5d 100644 --- a/qiskit/transpiler/passes/calibration/rx_builder.py +++ b/qiskit/transpiler/passes/calibration/rx_builder.py @@ -24,6 +24,7 @@ from qiskit.pulse.library.symbolic_pulses import Drag from qiskit.transpiler.passes.calibration.base_builder import CalibrationBuilder from qiskit.transpiler.target import Target +from qiskit.utils.deprecate_pulse import deprecate_pulse_dependency class RXCalibrationBuilder(CalibrationBuilder): @@ -75,6 +76,7 @@ class RXCalibrationBuilder(CalibrationBuilder): `arXiv:2004.11205 ` """ + @deprecate_pulse_dependency def __init__( self, target: Target = None, diff --git a/qiskit/transpiler/passes/calibration/rzx_builder.py b/qiskit/transpiler/passes/calibration/rzx_builder.py index c153c3eeef33..5c88e5fe88e3 100644 --- a/qiskit/transpiler/passes/calibration/rzx_builder.py +++ b/qiskit/transpiler/passes/calibration/rzx_builder.py @@ -36,6 +36,7 @@ from qiskit.pulse.filters import filter_instructions from qiskit.pulse.instruction_schedule_map import InstructionScheduleMap from qiskit.transpiler.target import Target +from qiskit.utils.deprecate_pulse import deprecate_pulse_dependency from .base_builder import CalibrationBuilder from .exceptions import CalibrationNotAvailable @@ -65,6 +66,7 @@ class RZXCalibrationBuilder(CalibrationBuilder): angle. Additional details can be found in https://arxiv.org/abs/2012.11660. """ + @deprecate_pulse_dependency def __init__( self, instruction_schedule_map: InstructionScheduleMap = None, diff --git a/qiskit/transpiler/preset_passmanagers/common.py b/qiskit/transpiler/preset_passmanagers/common.py index f01639ed115e..bf1a9c4a1038 100644 --- a/qiskit/transpiler/preset_passmanagers/common.py +++ b/qiskit/transpiler/preset_passmanagers/common.py @@ -52,6 +52,7 @@ from qiskit.transpiler.passes.layout.vf2_post_layout import VF2PostLayoutStopReason from qiskit.transpiler.exceptions import TranspilerError from qiskit.transpiler.layout import Layout +from qiskit.utils.deprecate_pulse import deprecate_pulse_arg _ControlFlowState = collections.namedtuple("_ControlFlowState", ("working", "not_working")) @@ -529,6 +530,7 @@ def generate_translation_passmanager( return PassManager(unroll) +@deprecate_pulse_arg("inst_map") def generate_scheduling( instruction_durations, scheduling_method, timing_constraints, inst_map, target=None ): diff --git a/qiskit/transpiler/preset_passmanagers/generate_preset_pass_manager.py b/qiskit/transpiler/preset_passmanagers/generate_preset_pass_manager.py index 830618845352..d90ac4477a58 100644 --- a/qiskit/transpiler/preset_passmanagers/generate_preset_pass_manager.py +++ b/qiskit/transpiler/preset_passmanagers/generate_preset_pass_manager.py @@ -29,6 +29,7 @@ from qiskit.transpiler.passmanager_config import PassManagerConfig from qiskit.transpiler.target import Target, target_to_backend_properties from qiskit.transpiler.timing_constraints import TimingConstraints +from qiskit.utils.deprecate_pulse import deprecate_pulse_arg from .level0 import level_0_pass_manager from .level1 import level_1_pass_manager @@ -36,6 +37,7 @@ from .level3 import level_3_pass_manager +@deprecate_pulse_arg("inst_map") def generate_preset_pass_manager( optimization_level=2, backend=None, diff --git a/qiskit/transpiler/target.py b/qiskit/transpiler/target.py index cf6635b260a2..060578faa30c 100644 --- a/qiskit/transpiler/target.py +++ b/qiskit/transpiler/target.py @@ -57,7 +57,7 @@ from qiskit.providers.backend import QubitProperties # pylint: disable=unused-import from qiskit.providers.models.backendproperties import BackendProperties from qiskit.utils import deprecate_func -from qiskit.utils.deprecate_pulse import deprecate_pulse_dependency +from qiskit.utils.deprecate_pulse import deprecate_pulse_dependency, deprecate_pulse_arg logger = logging.getLogger(__name__) @@ -87,6 +87,7 @@ def __new__( # pylint: disable=keyword-arg-before-vararg cls, duration, error ) + @deprecate_pulse_arg("calibration") def __init__( self, duration: float | None = None, # pylint: disable=unused-argument @@ -107,6 +108,7 @@ def __init__( self.calibration = calibration @property + @deprecate_pulse_dependency def calibration(self): """The pulse representation of the instruction. @@ -139,6 +141,7 @@ def calibration(self): return self._calibration.get_schedule() @calibration.setter + @deprecate_pulse_dependency def calibration(self, calibration: Schedule | ScheduleBlock | CalibrationEntry): if isinstance(calibration, (Schedule, ScheduleBlock)): new_entry = ScheduleDef() @@ -448,6 +451,7 @@ def update_instruction_properties(self, instruction, qargs, properties): self._instruction_durations = None self._instruction_schedule_map = None + @deprecate_pulse_dependency def update_from_instruction_schedule_map(self, inst_map, inst_name_map=None, error_dict=None): """Update the target from an instruction schedule map. @@ -931,6 +935,7 @@ def __setstate__(self, state: tuple): super().__setstate__(state["base"]) @classmethod + @deprecate_pulse_arg("inst_map") def from_configuration( cls, basis_gates: list[str], diff --git a/qiskit/utils/deprecate_pulse.py b/qiskit/utils/deprecate_pulse.py index a6ba38605daf..bf1e14240e6d 100644 --- a/qiskit/utils/deprecate_pulse.py +++ b/qiskit/utils/deprecate_pulse.py @@ -48,6 +48,5 @@ def deprecate_pulse_arg(arg_name, description=None, predicate=None): additional_msg="The entire Qiskit Pulse package is being deprecated " "and will be moved to the Qiskit Dynamics repository: " "https://github.com/qiskit-community/qiskit-dynamics", - predicate=predicate + predicate=predicate, ) - diff --git a/test/utils/base.py b/test/utils/base.py index bd8a4039fc3b..b4374b111ee2 100644 --- a/test/utils/base.py +++ b/test/utils/base.py @@ -166,7 +166,7 @@ def setUpClass(cls): # Safe to remove once Pulse is removed in Qiskit 2.0 warnings.filterwarnings( - 'ignore', + "ignore", category=DeprecationWarning, message=".*The entire Qiskit Pulse package is being deprecated.*", ) From e94e3ea95d1d580bde55b6edda8579c1353c975f Mon Sep 17 00:00:00 2001 From: Eli Arbel Date: Sun, 29 Sep 2024 16:58:32 +0300 Subject: [PATCH 10/23] Mark deprecated properties as such --- qiskit/circuit/quantumcircuit.py | 4 ++-- qiskit/compiler/transpiler.py | 1 + qiskit/dagcircuit/dagdependency.py | 4 ++-- qiskit/providers/backend.py | 2 +- .../fake_provider/generic_backend_v2.py | 1 - qiskit/transpiler/target.py | 4 ++-- qiskit/utils/deprecate_pulse.py | 19 +++++++++++++------ qiskit/visualization/pulse_v2/interface.py | 2 +- .../pulse_v2/plotters/matplotlib.py | 1 + 9 files changed, 23 insertions(+), 15 deletions(-) diff --git a/qiskit/circuit/quantumcircuit.py b/qiskit/circuit/quantumcircuit.py index 1061c83ae85f..562e43c4e09b 100644 --- a/qiskit/circuit/quantumcircuit.py +++ b/qiskit/circuit/quantumcircuit.py @@ -1323,7 +1323,7 @@ def op_start_times(self) -> list[int]: return self._op_start_times @property - @deprecate_pulse_dependency + @deprecate_pulse_dependency(is_property=True) def calibrations(self) -> dict: """Return calibration dictionary. @@ -1333,7 +1333,7 @@ def calibrations(self) -> dict: return dict(self._calibrations) @calibrations.setter - @deprecate_pulse_dependency + @deprecate_pulse_dependency(is_property=True) def calibrations(self, calibrations: dict): """Set the circuit calibration data from a dictionary of calibration definition. diff --git a/qiskit/compiler/transpiler.py b/qiskit/compiler/transpiler.py index 1b0afe52d1d8..8c455c813df4 100644 --- a/qiskit/compiler/transpiler.py +++ b/qiskit/compiler/transpiler.py @@ -38,6 +38,7 @@ _CircuitT = TypeVar("_CircuitT", bound=Union[QuantumCircuit, List[QuantumCircuit]]) + @deprecate_pulse_arg("inst_map") def transpile( # pylint: disable=too-many-return-statements circuits: _CircuitT, diff --git a/qiskit/dagcircuit/dagdependency.py b/qiskit/dagcircuit/dagdependency.py index 9fc21d85db97..d012aa2f92d6 100644 --- a/qiskit/dagcircuit/dagdependency.py +++ b/qiskit/dagcircuit/dagdependency.py @@ -147,7 +147,7 @@ def global_phase(self, angle: float | ParameterExpression): self._global_phase = angle % (2 * math.pi) @property - @deprecate_pulse_dependency + @deprecate_pulse_dependency(is_property=True) def calibrations(self) -> dict[str, dict[tuple, Schedule]]: """Return calibration dictionary. @@ -157,7 +157,7 @@ def calibrations(self) -> dict[str, dict[tuple, Schedule]]: return dict(self._calibrations) @calibrations.setter - @deprecate_pulse_dependency + @deprecate_pulse_dependency(is_property=True) def calibrations(self, calibrations: dict[str, dict[tuple, Schedule]]): """Set the circuit calibration data from a dictionary of calibration definition. diff --git a/qiskit/providers/backend.py b/qiskit/providers/backend.py index 2420960784dc..8d22eb86c5c5 100644 --- a/qiskit/providers/backend.py +++ b/qiskit/providers/backend.py @@ -486,7 +486,7 @@ def meas_map(self) -> List[List[int]]: raise NotImplementedError @property - @deprecate_pulse_dependency + @deprecate_pulse_dependency(is_property=True) def instruction_schedule_map(self): """Return the :class:`~qiskit.pulse.InstructionScheduleMap` for the instructions defined in this backend's target.""" diff --git a/qiskit/providers/fake_provider/generic_backend_v2.py b/qiskit/providers/fake_provider/generic_backend_v2.py index f5768afa83cb..9ab8ff857e74 100644 --- a/qiskit/providers/fake_provider/generic_backend_v2.py +++ b/qiskit/providers/fake_provider/generic_backend_v2.py @@ -522,7 +522,6 @@ class GenericBackendV2(BackendV2): transpilation. """ - @deprecate_pulse_arg("pulse_channels") @deprecate_pulse_arg("calibration_instructions") def __init__( diff --git a/qiskit/transpiler/target.py b/qiskit/transpiler/target.py index 060578faa30c..254d42b2329b 100644 --- a/qiskit/transpiler/target.py +++ b/qiskit/transpiler/target.py @@ -108,7 +108,7 @@ def __init__( self.calibration = calibration @property - @deprecate_pulse_dependency + @deprecate_pulse_dependency(is_property=True) def calibration(self): """The pulse representation of the instruction. @@ -141,7 +141,7 @@ def calibration(self): return self._calibration.get_schedule() @calibration.setter - @deprecate_pulse_dependency + @deprecate_pulse_dependency(is_property=True) def calibration(self, calibration: Schedule | ScheduleBlock | CalibrationEntry): if isinstance(calibration, (Schedule, ScheduleBlock)): new_entry = ScheduleDef() diff --git a/qiskit/utils/deprecate_pulse.py b/qiskit/utils/deprecate_pulse.py index bf1e14240e6d..4f19ebb91bfd 100644 --- a/qiskit/utils/deprecate_pulse.py +++ b/qiskit/utils/deprecate_pulse.py @@ -28,25 +28,32 @@ def deprecate_pulse_func(func): )(func) -def deprecate_pulse_dependency(func): +def deprecate_pulse_dependency(*args, **kwargs): """Deprecation message for functions and classes which use or depend on Pulse""" - return deprecate_func( + + decorator = deprecate_func( since="1.3", removal_timeline="in Qiskit 2.0", additional_msg="The entire Qiskit Pulse package is being deprecated " "and this is a dependency on the package.", - )(func) + **kwargs, + ) + + # Taken when `deprecate_pulse_dependency` is used with no arguments and with empty parentheses, + # in which case the decorated function is passed + if args: + return decorator(args[0]) + return decorator -def deprecate_pulse_arg(arg_name, description=None, predicate=None): +def deprecate_pulse_arg(arg_name, **kwargs): """Deprecation message for arguments related to Pulse""" return deprecate_arg( name=arg_name, since="1.3", - deprecation_description=description, removal_timeline="in Qiskit 2.0", additional_msg="The entire Qiskit Pulse package is being deprecated " "and will be moved to the Qiskit Dynamics repository: " "https://github.com/qiskit-community/qiskit-dynamics", - predicate=predicate, + **kwargs, ) diff --git a/qiskit/visualization/pulse_v2/interface.py b/qiskit/visualization/pulse_v2/interface.py index 5d20ef7b5b5b..089dbcfad90b 100644 --- a/qiskit/visualization/pulse_v2/interface.py +++ b/qiskit/visualization/pulse_v2/interface.py @@ -32,7 +32,7 @@ @deprecate_pulse_dependency -@deprecate_arg("show_barriers", new_alias="plot_barriers", since="1.1.0", pending=True) +@deprecate_arg("show_barrier", new_alias="plot_barrier", since="1.1.0", pending=True) def draw( program: Union[Waveform, SymbolicPulse, Schedule, ScheduleBlock], style: Optional[Dict[str, Any]] = None, diff --git a/qiskit/visualization/pulse_v2/plotters/matplotlib.py b/qiskit/visualization/pulse_v2/plotters/matplotlib.py index c3ce963a4188..deb01464fd0b 100644 --- a/qiskit/visualization/pulse_v2/plotters/matplotlib.py +++ b/qiskit/visualization/pulse_v2/plotters/matplotlib.py @@ -25,6 +25,7 @@ from qiskit.visualization.utils import matplotlib_close_if_inline from qiskit.utils.deprecate_pulse import deprecate_pulse_dependency + class Mpl2DPlotter(BasePlotter): """Matplotlib API for pulse drawer. From fe1597250ad72b9102313aa2052118de2cbe52fa Mon Sep 17 00:00:00 2001 From: Eli Arbel Date: Sun, 6 Oct 2024 22:57:23 +0300 Subject: [PATCH 11/23] Add, refine and fix deprecations Added deprecations in `dag_circuit.rs` Added more deprecations in `builder.py` Fixed some deprecations comments --- crates/circuit/src/dag_circuit.rs | 53 +++++++++++++++++-- qiskit/compiler/transpiler.py | 2 +- qiskit/providers/backend_compat.py | 2 +- .../fake_provider/generic_backend_v2.py | 6 +-- .../fake_provider/utils/backend_converter.py | 2 - qiskit/pulse/builder.py | 31 ++++++++++- qiskit/pulse/calibration_entries.py | 1 - qiskit/pulse/channels.py | 1 - qiskit/pulse/instructions/acquire.py | 2 - qiskit/pulse/instructions/delay.py | 2 - qiskit/pulse/instructions/directives.py | 3 -- qiskit/pulse/instructions/frequency.py | 3 -- qiskit/pulse/instructions/phase.py | 3 -- qiskit/pulse/instructions/play.py | 2 - qiskit/pulse/instructions/reference.py | 2 - qiskit/pulse/instructions/snapshot.py | 2 - qiskit/pulse/library/pulse.py | 2 + qiskit/pulse/library/symbolic_pulses.py | 4 -- qiskit/pulse/library/waveform.py | 2 - qiskit/pulse/parameter_manager.py | 4 -- qiskit/pulse/parser.py | 2 - qiskit/pulse/transforms/alignments.py | 6 --- qiskit/qpy/interface.py | 3 +- .../transpiler/preset_passmanagers/common.py | 2 +- .../generate_preset_pass_manager.py | 2 +- qiskit/transpiler/target.py | 4 +- 26 files changed, 93 insertions(+), 55 deletions(-) diff --git a/crates/circuit/src/dag_circuit.rs b/crates/circuit/src/dag_circuit.rs index 5b218b2de818..63eee43e395a 100644 --- a/crates/circuit/src/dag_circuit.rs +++ b/crates/circuit/src/dag_circuit.rs @@ -34,7 +34,9 @@ use hashbrown::{HashMap, HashSet}; use indexmap::IndexMap; use itertools::Itertools; -use pyo3::exceptions::{PyIndexError, PyRuntimeError, PyTypeError, PyValueError}; +use pyo3::exceptions::{ + PyDeprecationWarning, PyIndexError, PyRuntimeError, PyTypeError, PyValueError, +}; use pyo3::intern; use pyo3::prelude::*; use pyo3::types::{ @@ -808,8 +810,15 @@ impl DAGCircuit { /// /// The custom pulse definition of a given gate is of the form /// {'gate_name': {(qubits, params): schedule}} + /// + /// DEPRECATED since Qiskit 1.3.0 and will be removed in Qiskit 2.0.0 #[getter] - fn get_calibrations(&self) -> HashMap> { + fn get_calibrations(&self, py: Python) -> HashMap> { + emit_pulse_dependency_deprecation( + py, + "property ``qiskit.dagcircuit.dagcircuit.DAGCircuit.calibrations``", + ); + self.calibrations.clone() } @@ -818,8 +827,15 @@ impl DAGCircuit { /// Args: /// calibrations (dict): A dictionary of input in the format /// {'gate_name': {(qubits, gate_params): schedule}} + /// + /// DEPRECATED since Qiskit 1.3.0 and will be removed in Qiskit 2.0.0 #[setter] - fn set_calibrations(&mut self, calibrations: HashMap>) { + fn set_calibrations(&mut self, py: Python, calibrations: HashMap>) { + emit_pulse_dependency_deprecation( + py, + "property ``qiskit.dagcircuit.dagcircuit.DAGCircuit.calibrations``", + ); + self.calibrations = calibrations; } @@ -833,6 +849,8 @@ impl DAGCircuit { /// /// Raises: /// Exception: if the gate is of type string and params is None. + /// + /// DEPRECATED since Qiskit 1.3.0 and will be removed in Qiskit 2.0.0 fn add_calibration<'py>( &mut self, py: Python<'py>, @@ -841,6 +859,11 @@ impl DAGCircuit { schedule: Py, mut params: Option>, ) -> PyResult<()> { + emit_pulse_dependency_deprecation( + py, + "method ``qiskit.dagcircuit.dagcircuit.DAGCircuit.add_calibration``", + ); + if gate.is_instance(imports::GATE.get_bound(py))? { params = Some(gate.getattr(intern!(py, "params"))?); gate = gate.getattr(intern!(py, "name"))?; @@ -898,7 +921,14 @@ def _format(operand): /// Return True if the dag has a calibration defined for the node operation. In this /// case, the operation does not need to be translated to the device basis. + /// + /// DEPRECATED since Qiskit 1.3.0 and will be removed in Qiskit 2.0.0 fn has_calibration_for(&self, py: Python, node: PyRef) -> PyResult { + emit_pulse_dependency_deprecation( + py, + "method ``qiskit.dagcircuit.dagcircuit.DAGCircuit.has_calibration_for``", + ); + if !self .calibrations .contains_key(node.instruction.operation.name()) @@ -6800,3 +6830,20 @@ fn add_global_phase(py: Python, phase: &Param, other: &Param) -> PyResult } type SortKeyType<'a> = (&'a [Qubit], &'a [Clbit]); + +/// Emit a Python `DeprecationWarning` for pulse-related dependencies. +fn emit_pulse_dependency_deprecation(py: Python, msg: &str) { + let _ = imports::WARNINGS_WARN.get_bound(py).call1(( + PyString::new_bound( + py, + &format!( + "The {} is deprecated as of qiskit 1.3.0. It will be removed in Qiskit 2.0.0. \ + The entire Qiskit Pulse package is being deprecated \ + and this is a dependency on the package.", + msg + ), + ), + py.get_type_bound::(), + 1, + )); +} diff --git a/qiskit/compiler/transpiler.py b/qiskit/compiler/transpiler.py index 8c455c813df4..ff2925c40b31 100644 --- a/qiskit/compiler/transpiler.py +++ b/qiskit/compiler/transpiler.py @@ -106,7 +106,7 @@ def transpile( # pylint: disable=too-many-return-statements will override the backend's. basis_gates: List of basis gate names to unroll to (e.g: ``['u1', 'u2', 'u3', 'cx']``). If ``None``, do not unroll. - inst_map: Mapping of unrolled gates to pulse schedules. If this is not provided, + inst_map: DEPRECATED. Mapping of unrolled gates to pulse schedules. If this is not provided, transpiler tries to get from the backend. If any user defined calibration is found in the map and this is used in a circuit, transpiler attaches the custom gate definition to the circuit. This enables one to flexibly diff --git a/qiskit/providers/backend_compat.py b/qiskit/providers/backend_compat.py index 1d447a4fa1b3..b0a9cdd0b8ab 100644 --- a/qiskit/providers/backend_compat.py +++ b/qiskit/providers/backend_compat.py @@ -49,7 +49,7 @@ def convert_to_target( Args: configuration: Backend configuration as ``BackendConfiguration`` properties: Backend property dictionary or ``BackendProperties`` - defaults: Backend pulse defaults dictionary or ``PulseDefaults`` + defaults: DEPRECATED. Backend pulse defaults dictionary or ``PulseDefaults`` custom_name_mapping: A name mapping must be supplied for the operation not included in Qiskit Standard Gate name mapping, otherwise the operation will be dropped in the resulting ``Target`` object. diff --git a/qiskit/providers/fake_provider/generic_backend_v2.py b/qiskit/providers/fake_provider/generic_backend_v2.py index 9ab8ff857e74..78779dcd87a5 100644 --- a/qiskit/providers/fake_provider/generic_backend_v2.py +++ b/qiskit/providers/fake_provider/generic_backend_v2.py @@ -523,7 +523,7 @@ class GenericBackendV2(BackendV2): """ @deprecate_pulse_arg("pulse_channels") - @deprecate_pulse_arg("calibration_instructions") + @deprecate_pulse_arg("calibrate_instructions") def __init__( self, num_qubits: int, @@ -566,7 +566,7 @@ def __init__( control_flow: Flag to enable control flow directives on the target (defaults to False). - calibrate_instructions: Instruction calibration settings, this argument + calibrate_instructions: DEPRECATED. Instruction calibration settings, this argument supports both boolean and :class:`.InstructionScheduleMap` as input types, and is ``None`` by default: @@ -584,7 +584,7 @@ def __init__( seed: Optional seed for generation of default values. - pulse_channels: If true, sets default pulse channel information on the backend. + pulse_channels: DEPRECATED. If true, sets default pulse channel information on the backend. noise_info: If true, associates gates and qubits with default noise information. """ diff --git a/qiskit/providers/fake_provider/utils/backend_converter.py b/qiskit/providers/fake_provider/utils/backend_converter.py index 2dfd2b497d44..9e038c39df38 100644 --- a/qiskit/providers/fake_provider/utils/backend_converter.py +++ b/qiskit/providers/fake_provider/utils/backend_converter.py @@ -25,10 +25,8 @@ from qiskit.circuit.measure import Measure from qiskit.circuit.reset import Reset from qiskit.providers.models.pulsedefaults import PulseDefaults -from qiskit.utils.deprecate_pulse import deprecate_pulse_arg -@deprecate_pulse_arg("defs_dict") def convert_to_target(conf_dict: dict, props_dict: dict = None, defs_dict: dict = None) -> Target: """Uses configuration, properties and pulse defaults dicts to construct and return Target class. diff --git a/qiskit/pulse/builder.py b/qiskit/pulse/builder.py index 4987d5adf3b6..5890e232310f 100644 --- a/qiskit/pulse/builder.py +++ b/qiskit/pulse/builder.py @@ -478,7 +478,6 @@ class _PulseBuilder: "sequential": transforms.AlignSequential(), } - @deprecate_pulse_func def __init__( self, backend=None, @@ -850,6 +849,7 @@ def _active_builder() -> _PulseBuilder: ) from ex +@deprecate_pulse_func def active_backend(): """Get the backend of the currently active builder context. @@ -900,6 +900,7 @@ def append_instruction(instruction: instructions.Instruction): _active_builder().append_instruction(instruction) +@deprecate_pulse_func def num_qubits() -> int: """Return number of qubits in the currently active backend. @@ -926,6 +927,7 @@ def num_qubits() -> int: return active_backend().configuration().n_qubits +@deprecate_pulse_func def seconds_to_samples(seconds: float | np.ndarray) -> int | np.ndarray: """Obtain the number of samples that will elapse in ``seconds`` on the active backend. @@ -944,6 +946,7 @@ def seconds_to_samples(seconds: float | np.ndarray) -> int | np.ndarray: return int(seconds / dt) +@deprecate_pulse_func def samples_to_seconds(samples: int | np.ndarray) -> float | np.ndarray: """Obtain the time in seconds that will elapse for the input number of samples on the active backend. @@ -957,6 +960,7 @@ def samples_to_seconds(samples: int | np.ndarray) -> float | np.ndarray: return samples * _active_builder().get_dt() +@deprecate_pulse_func def qubit_channels(qubit: int) -> set[chans.Channel]: """Returns the set of channels associated with a qubit. @@ -1029,6 +1033,7 @@ def _qubits_to_channels(*channels_or_qubits: int | chans.Channel) -> set[chans.C @contextmanager +@deprecate_pulse_func def align_left() -> Generator[None, None, None]: """Left alignment pulse scheduling context. @@ -1067,6 +1072,7 @@ def align_left() -> Generator[None, None, None]: @contextmanager +@deprecate_pulse_func def align_right() -> Generator[None, None, None]: """Right alignment pulse scheduling context. @@ -1105,6 +1111,7 @@ def align_right() -> Generator[None, None, None]: @contextmanager +@deprecate_pulse_func def align_sequential() -> Generator[None, None, None]: """Sequential alignment pulse scheduling context. @@ -1143,6 +1150,7 @@ def align_sequential() -> Generator[None, None, None]: @contextmanager +@deprecate_pulse_func def align_equispaced(duration: int | ParameterExpression) -> Generator[None, None, None]: """Equispaced alignment pulse scheduling context. @@ -1195,6 +1203,7 @@ def align_equispaced(duration: int | ParameterExpression) -> Generator[None, Non @contextmanager +@deprecate_pulse_func def align_func( duration: int | ParameterExpression, func: Callable[[int], float] ) -> Generator[None, None, None]: @@ -1283,6 +1292,7 @@ def general_transforms(alignment_context: AlignmentKind) -> Generator[None, None @contextmanager +@deprecate_pulse_func def phase_offset(phase: float, *channels: chans.PulseChannel) -> Generator[None, None, None]: """Shift the phase of input channels on entry into context and undo on exit. @@ -1319,6 +1329,7 @@ def phase_offset(phase: float, *channels: chans.PulseChannel) -> Generator[None, @contextmanager +@deprecate_pulse_func def frequency_offset( frequency: float, *channels: chans.PulseChannel, compensate_phase: bool = False ) -> Generator[None, None, None]: @@ -1382,6 +1393,7 @@ def frequency_offset( # Channels +@deprecate_pulse_func def drive_channel(qubit: int) -> chans.DriveChannel: """Return ``DriveChannel`` for ``qubit`` on the active builder backend. @@ -1405,6 +1417,7 @@ def drive_channel(qubit: int) -> chans.DriveChannel: return active_backend().configuration().drive(qubit) +@deprecate_pulse_func def measure_channel(qubit: int) -> chans.MeasureChannel: """Return ``MeasureChannel`` for ``qubit`` on the active builder backend. @@ -1428,6 +1441,7 @@ def measure_channel(qubit: int) -> chans.MeasureChannel: return active_backend().configuration().measure(qubit) +@deprecate_pulse_func def acquire_channel(qubit: int) -> chans.AcquireChannel: """Return ``AcquireChannel`` for ``qubit`` on the active builder backend. @@ -1451,6 +1465,7 @@ def acquire_channel(qubit: int) -> chans.AcquireChannel: return active_backend().configuration().acquire(qubit) +@deprecate_pulse_func def control_channels(*qubits: Iterable[int]) -> list[chans.ControlChannel]: """Return ``ControlChannel`` for ``qubit`` on the active builder backend. @@ -1485,6 +1500,7 @@ def control_channels(*qubits: Iterable[int]) -> list[chans.ControlChannel]: # Base Instructions +@deprecate_pulse_func def delay(duration: int, channel: chans.Channel, name: str | None = None): """Delay on a ``channel`` for a ``duration``. @@ -1541,6 +1557,7 @@ class _MetaDataType(TypedDict, total=False): name: str +@deprecate_pulse_func def acquire( duration: int, qubit_or_channel: int | chans.AcquireChannel, @@ -1594,6 +1611,7 @@ def acquire( raise exceptions.PulseError(f'Register of type: "{type(register)}" is not supported') +@deprecate_pulse_func def set_frequency(frequency: float, channel: chans.PulseChannel, name: str | None = None): """Set the ``frequency`` of a pulse ``channel``. @@ -1616,6 +1634,7 @@ def set_frequency(frequency: float, channel: chans.PulseChannel, name: str | Non append_instruction(instructions.SetFrequency(frequency, channel, name=name)) +@deprecate_pulse_func def shift_frequency(frequency: float, channel: chans.PulseChannel, name: str | None = None): """Shift the ``frequency`` of a pulse ``channel``. @@ -1639,6 +1658,7 @@ def shift_frequency(frequency: float, channel: chans.PulseChannel, name: str | N append_instruction(instructions.ShiftFrequency(frequency, channel, name=name)) +@deprecate_pulse_func def set_phase(phase: float, channel: chans.PulseChannel, name: str | None = None): """Set the ``phase`` of a pulse ``channel``. @@ -1664,6 +1684,7 @@ def set_phase(phase: float, channel: chans.PulseChannel, name: str | None = None append_instruction(instructions.SetPhase(phase, channel, name=name)) +@deprecate_pulse_func def shift_phase(phase: float, channel: chans.PulseChannel, name: str | None = None): """Shift the ``phase`` of a pulse ``channel``. @@ -1688,6 +1709,7 @@ def shift_phase(phase: float, channel: chans.PulseChannel, name: str | None = No append_instruction(instructions.ShiftPhase(phase, channel, name)) +@deprecate_pulse_func def snapshot(label: str, snapshot_type: str = "statevector"): """Simulator snapshot. @@ -1707,6 +1729,7 @@ def snapshot(label: str, snapshot_type: str = "statevector"): append_instruction(instructions.Snapshot(label, snapshot_type=snapshot_type)) +@deprecate_pulse_func def call( target: Schedule | ScheduleBlock | None, name: str | None = None, @@ -1901,6 +1924,7 @@ def call( _active_builder().call_subroutine(target, name, value_dict, **kw_params) +@deprecate_pulse_func def reference(name: str, *extra_keys: str): """Refer to undefined subroutine by string keys. @@ -1927,6 +1951,7 @@ def reference(name: str, *extra_keys: str): # Directives +@deprecate_pulse_func def barrier(*channels_or_qubits: chans.Channel | int, name: str | None = None): """Barrier directive for a set of channels and qubits. @@ -2000,6 +2025,7 @@ def barrier(*channels_or_qubits: chans.Channel | int, name: str | None = None): # Macros +@deprecate_pulse_func def macro(func: Callable): """Wrap a Python function and activate the parent builder context at calling time. @@ -2056,6 +2082,7 @@ def wrapper(*args, **kwargs): return wrapper +@deprecate_pulse_func def measure( qubits: list[int] | int, registers: list[StorageLocation] | StorageLocation = None, @@ -2144,6 +2171,7 @@ def measure( return registers +@deprecate_pulse_func def measure_all() -> list[chans.MemorySlot]: r"""Measure all qubits within the currently active builder context. @@ -2187,6 +2215,7 @@ def measure_all() -> list[chans.MemorySlot]: return registers +@deprecate_pulse_func def delay_qubits(duration: int, *qubits: int): r"""Insert delays on all the :class:`channels.Channel`\s that correspond to the input ``qubits`` at the same time. diff --git a/qiskit/pulse/calibration_entries.py b/qiskit/pulse/calibration_entries.py index cce4885d31c1..b47580d02c07 100644 --- a/qiskit/pulse/calibration_entries.py +++ b/qiskit/pulse/calibration_entries.py @@ -303,7 +303,6 @@ class PulseQobjDef(ScheduleDef): """ - @deprecate_pulse_func def __init__( self, arguments: Sequence[str] | None = None, diff --git a/qiskit/pulse/channels.py b/qiskit/pulse/channels.py index ebd0de886fb0..8b196345c179 100644 --- a/qiskit/pulse/channels.py +++ b/qiskit/pulse/channels.py @@ -208,7 +208,6 @@ class SnapshotChannel(ClassicalIOChannel): prefix = "s" - @deprecate_pulse_func def __init__(self): """Create new snapshot channel.""" super().__init__(0) diff --git a/qiskit/pulse/instructions/acquire.py b/qiskit/pulse/instructions/acquire.py index 3b5964d4ee3e..98fbf460c1b3 100644 --- a/qiskit/pulse/instructions/acquire.py +++ b/qiskit/pulse/instructions/acquire.py @@ -19,7 +19,6 @@ from qiskit.pulse.configuration import Kernel, Discriminator from qiskit.pulse.exceptions import PulseError from qiskit.pulse.instructions.instruction import Instruction -from qiskit.utils.deprecate_pulse import deprecate_pulse_func class Acquire(Instruction): @@ -39,7 +38,6 @@ class Acquire(Instruction): * the discriminator to classify kerneled IQ points. """ - @deprecate_pulse_func def __init__( self, duration: int | ParameterExpression, diff --git a/qiskit/pulse/instructions/delay.py b/qiskit/pulse/instructions/delay.py index 6dd028c94fcd..13f36d3b7d9b 100644 --- a/qiskit/pulse/instructions/delay.py +++ b/qiskit/pulse/instructions/delay.py @@ -16,7 +16,6 @@ from qiskit.circuit import ParameterExpression from qiskit.pulse.channels import Channel from qiskit.pulse.instructions.instruction import Instruction -from qiskit.utils.deprecate_pulse import deprecate_pulse_func class Delay(Instruction): @@ -35,7 +34,6 @@ class Delay(Instruction): The ``channel`` will output no signal from time=0 up until time=10. """ - @deprecate_pulse_func def __init__( self, duration: int | ParameterExpression, diff --git a/qiskit/pulse/instructions/directives.py b/qiskit/pulse/instructions/directives.py index 1572c887f376..f1e7f9b24569 100644 --- a/qiskit/pulse/instructions/directives.py +++ b/qiskit/pulse/instructions/directives.py @@ -18,7 +18,6 @@ from qiskit.pulse import channels as chans from qiskit.pulse.instructions import instruction from qiskit.pulse.exceptions import PulseError -from qiskit.utils.deprecate_pulse import deprecate_pulse_func class Directive(instruction.Instruction, ABC): @@ -36,7 +35,6 @@ def duration(self) -> int: class RelativeBarrier(Directive): """Pulse ``RelativeBarrier`` directive.""" - @deprecate_pulse_func def __init__(self, *channels: chans.Channel, name: str | None = None): """Create a relative barrier directive. @@ -104,7 +102,6 @@ class TimeBlockade(Directive): user can insert another instruction without timing overlap. """ - @deprecate_pulse_func def __init__( self, duration: int, diff --git a/qiskit/pulse/instructions/frequency.py b/qiskit/pulse/instructions/frequency.py index 545d26c92639..a14e60ee1a32 100644 --- a/qiskit/pulse/instructions/frequency.py +++ b/qiskit/pulse/instructions/frequency.py @@ -19,7 +19,6 @@ from qiskit.pulse.channels import PulseChannel from qiskit.pulse.instructions.instruction import Instruction from qiskit.pulse.exceptions import PulseError -from qiskit.utils.deprecate_pulse import deprecate_pulse_func class SetFrequency(Instruction): @@ -36,7 +35,6 @@ class SetFrequency(Instruction): The duration of SetFrequency is 0. """ - @deprecate_pulse_func def __init__( self, frequency: Union[float, ParameterExpression], @@ -87,7 +85,6 @@ def duration(self) -> int: class ShiftFrequency(Instruction): """Shift the channel frequency away from the current frequency.""" - @deprecate_pulse_func def __init__( self, frequency: Union[float, ParameterExpression], diff --git a/qiskit/pulse/instructions/phase.py b/qiskit/pulse/instructions/phase.py index 1d08918cb7e9..21f46dfb5f72 100644 --- a/qiskit/pulse/instructions/phase.py +++ b/qiskit/pulse/instructions/phase.py @@ -21,7 +21,6 @@ from qiskit.pulse.channels import PulseChannel from qiskit.pulse.instructions.instruction import Instruction from qiskit.pulse.exceptions import PulseError -from qiskit.utils.deprecate_pulse import deprecate_pulse_func class ShiftPhase(Instruction): @@ -41,7 +40,6 @@ class ShiftPhase(Instruction): by using a ShiftPhase to update the frame tracking the qubit state. """ - @deprecate_pulse_func def __init__( self, phase: Union[complex, ParameterExpression], @@ -103,7 +101,6 @@ class SetPhase(Instruction): The ``SetPhase`` instruction sets :math:`\phi` to the instruction's ``phase`` operand. """ - @deprecate_pulse_func def __init__( self, phase: Union[complex, ParameterExpression], diff --git a/qiskit/pulse/instructions/play.py b/qiskit/pulse/instructions/play.py index 8c86555bbc8c..1f42b8e3a08d 100644 --- a/qiskit/pulse/instructions/play.py +++ b/qiskit/pulse/instructions/play.py @@ -21,7 +21,6 @@ from qiskit.pulse.exceptions import PulseError from qiskit.pulse.instructions.instruction import Instruction from qiskit.pulse.library.pulse import Pulse -from qiskit.utils.deprecate_pulse import deprecate_pulse_func class Play(Instruction): @@ -33,7 +32,6 @@ class Play(Instruction): cycle time, dt, of the backend. """ - @deprecate_pulse_func def __init__(self, pulse: Pulse, channel: PulseChannel, name: str | None = None): """Create a new pulse instruction. diff --git a/qiskit/pulse/instructions/reference.py b/qiskit/pulse/instructions/reference.py index 1f17327877a7..cf3e01f8ea6e 100644 --- a/qiskit/pulse/instructions/reference.py +++ b/qiskit/pulse/instructions/reference.py @@ -17,7 +17,6 @@ from qiskit.pulse.channels import Channel from qiskit.pulse.exceptions import PulseError, UnassignedReferenceError from qiskit.pulse.instructions import instruction -from qiskit.utils.deprecate_pulse import deprecate_pulse_func class Reference(instruction.Instruction): @@ -41,7 +40,6 @@ class Reference(instruction.Instruction): # Delimiter for tuple keys. key_delimiter = "," - @deprecate_pulse_func def __init__(self, name: str, *extra_keys: str): """Create new reference. diff --git a/qiskit/pulse/instructions/snapshot.py b/qiskit/pulse/instructions/snapshot.py index 1692d13abc8f..b78858b5d2c0 100644 --- a/qiskit/pulse/instructions/snapshot.py +++ b/qiskit/pulse/instructions/snapshot.py @@ -18,13 +18,11 @@ from qiskit.pulse.channels import SnapshotChannel from qiskit.pulse.exceptions import PulseError from qiskit.pulse.instructions.instruction import Instruction -from qiskit.utils.deprecate_pulse import deprecate_pulse_func class Snapshot(Instruction): """An instruction targeted for simulators, to capture a moment in the simulation.""" - @deprecate_pulse_func def __init__(self, label: str, snapshot_type: str = "statevector", name: Optional[str] = None): """Create new snapshot. diff --git a/qiskit/pulse/library/pulse.py b/qiskit/pulse/library/pulse.py index ebcc689e1e48..89d67a381ec5 100644 --- a/qiskit/pulse/library/pulse.py +++ b/qiskit/pulse/library/pulse.py @@ -18,6 +18,7 @@ import typing from abc import ABC, abstractmethod from typing import Any +from qiskit.utils.deprecate_pulse import deprecate_pulse_func from qiskit.circuit.parameterexpression import ParameterExpression @@ -36,6 +37,7 @@ class Pulse(ABC): limit_amplitude = True @abstractmethod + @deprecate_pulse_func def __init__( self, duration: int | ParameterExpression, diff --git a/qiskit/pulse/library/symbolic_pulses.py b/qiskit/pulse/library/symbolic_pulses.py index c681e0b61281..b7ba658da1be 100644 --- a/qiskit/pulse/library/symbolic_pulses.py +++ b/qiskit/pulse/library/symbolic_pulses.py @@ -31,7 +31,6 @@ from qiskit.pulse.exceptions import PulseError from qiskit.pulse.library.pulse import Pulse from qiskit.pulse.library.waveform import Waveform -from qiskit.utils.deprecate_pulse import deprecate_pulse_func def _lifted_gaussian( @@ -151,7 +150,6 @@ class LambdifiedExpression: _`Descriptor`: https://docs.python.org/3/reference/datamodel.html#descriptors """ - @deprecate_pulse_func def __init__(self, attribute: str): """Create new descriptor. @@ -405,7 +403,6 @@ def Sawtooth(duration, amp, freq, name): _constraints_lam = LambdifiedExpression("_constraints") _valid_amp_conditions_lam = LambdifiedExpression("_valid_amp_conditions") - @deprecate_pulse_func def __init__( self, pulse_type: str, @@ -596,7 +593,6 @@ class ScalableSymbolicPulse(SymbolicPulse): :math:'\text{amp}\times\exp\left(i\times\text{angle}\right)' is compared. """ - @deprecate_pulse_func def __init__( self, pulse_type: str, diff --git a/qiskit/pulse/library/waveform.py b/qiskit/pulse/library/waveform.py index 0a31ac11a8d8..ad852f226ac2 100644 --- a/qiskit/pulse/library/waveform.py +++ b/qiskit/pulse/library/waveform.py @@ -18,7 +18,6 @@ from qiskit.pulse.exceptions import PulseError from qiskit.pulse.library.pulse import Pulse -from qiskit.utils.deprecate_pulse import deprecate_pulse_func class Waveform(Pulse): @@ -26,7 +25,6 @@ class Waveform(Pulse): duration of the backend cycle-time, dt. """ - @deprecate_pulse_func def __init__( self, samples: np.ndarray | list[complex], diff --git a/qiskit/pulse/parameter_manager.py b/qiskit/pulse/parameter_manager.py index 72a5052a212e..e5a4a1a1d2bd 100644 --- a/qiskit/pulse/parameter_manager.py +++ b/qiskit/pulse/parameter_manager.py @@ -67,7 +67,6 @@ _validate_parameter_vector, _validate_parameter_value, ) -from qiskit.utils.deprecate_pulse import deprecate_pulse_func class NodeVisitor: @@ -132,7 +131,6 @@ class ParameterSetter(NodeVisitor): and assign values to operands of nodes found. """ - @deprecate_pulse_func def __init__(self, param_map: dict[ParameterExpression, ParameterValueType]): self._param_map = param_map @@ -263,7 +261,6 @@ class ParameterGetter(NodeVisitor): and add parameters found to the array. """ - @deprecate_pulse_func def __init__(self): self.parameters = set() @@ -334,7 +331,6 @@ class ParameterManager: Instruction data and its location are not directly associated with this object. """ - @deprecate_pulse_func def __init__(self): """Create new parameter table for pulse programs.""" self._parameters = set() diff --git a/qiskit/pulse/parser.py b/qiskit/pulse/parser.py index 7c79e4152473..e9cd4917a7ce 100644 --- a/qiskit/pulse/parser.py +++ b/qiskit/pulse/parser.py @@ -24,7 +24,6 @@ from qiskit.pulse.exceptions import PulseError from qiskit.circuit import ParameterExpression -from qiskit.utils.deprecate_pulse import deprecate_pulse_func class PulseExpression(ast.NodeTransformer): @@ -64,7 +63,6 @@ class PulseExpression(ast.NodeTransformer): _unary_ops = {ast.UAdd: operator.pos, ast.USub: operator.neg} """Valid unary operations.""" - @deprecate_pulse_func def __init__(self, source: str | ast.Expression, partial_binding: bool = False): """Create new evaluator. diff --git a/qiskit/pulse/transforms/alignments.py b/qiskit/pulse/transforms/alignments.py index e3bbeaa71ad0..5e383972c255 100644 --- a/qiskit/pulse/transforms/alignments.py +++ b/qiskit/pulse/transforms/alignments.py @@ -20,7 +20,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.deprecate_pulse import deprecate_pulse_func class AlignmentKind(abc.ABC): @@ -94,7 +93,6 @@ class AlignLeft(AlignmentKind): Instructions are placed at earliest available timeslots. """ - @deprecate_pulse_func def __init__(self): """Create new left-justified context.""" super().__init__(context_params=()) @@ -162,7 +160,6 @@ class AlignRight(AlignmentKind): Instructions are placed at latest available timeslots. """ - @deprecate_pulse_func def __init__(self): """Create new right-justified context.""" super().__init__(context_params=()) @@ -232,7 +229,6 @@ class AlignSequential(AlignmentKind): No buffer time is inserted in between instructions. """ - @deprecate_pulse_func def __init__(self): """Create new sequential context.""" super().__init__(context_params=()) @@ -267,7 +263,6 @@ class AlignEquispaced(AlignmentKind): This alignment is convenient to create dynamical decoupling sequences such as PDD. """ - @deprecate_pulse_func def __init__(self, duration: int | ParameterExpression): """Create new equispaced context. @@ -353,7 +348,6 @@ def udd10_pos(j): """ - @deprecate_pulse_func def __init__(self, duration: int | ParameterExpression, func: Callable): """Create new equispaced context. diff --git a/qiskit/qpy/interface.py b/qiskit/qpy/interface.py index 381d3fc0720e..138580c80d6f 100644 --- a/qiskit/qpy/interface.py +++ b/qiskit/qpy/interface.py @@ -76,7 +76,7 @@ @deprecate_pulse_arg( "programs", - description="Passing 'ScheduleBlock'('s) to 'programs'", + deprecation_description="Passing `ScheduleBlock` to `programs`", predicate=lambda p: isinstance(p, ScheduleBlock), ) def dump( @@ -126,6 +126,7 @@ def dump( programs: QPY supported object(s) to store in the specified file like object. QPY supports :class:`.QuantumCircuit` and :class:`.ScheduleBlock`. Different data types must be separately serialized. + Support for :class:`.ScheduleBlock` is deprecated since Qiskit 1.3.0. file_obj: The file like object to write the QPY data too metadata_serializer: An optional JSONEncoder class that will be passed the ``.metadata`` attribute for each program in ``programs`` and will be diff --git a/qiskit/transpiler/preset_passmanagers/common.py b/qiskit/transpiler/preset_passmanagers/common.py index bf1a9c4a1038..556435a9d420 100644 --- a/qiskit/transpiler/preset_passmanagers/common.py +++ b/qiskit/transpiler/preset_passmanagers/common.py @@ -542,7 +542,7 @@ def generate_scheduling( ``'asap'``/``'as_soon_as_possible'`` or ``'alap'``/``'as_late_as_possible'`` timing_constraints (TimingConstraints): Hardware time alignment restrictions. - inst_map (InstructionScheduleMap): Mapping object that maps gate to schedule. + inst_map (InstructionScheduleMap): DEPRECATED. Mapping object that maps gate to schedule. target (Target): The :class:`~.Target` object representing the backend Returns: diff --git a/qiskit/transpiler/preset_passmanagers/generate_preset_pass_manager.py b/qiskit/transpiler/preset_passmanagers/generate_preset_pass_manager.py index d90ac4477a58..564de5415a60 100644 --- a/qiskit/transpiler/preset_passmanagers/generate_preset_pass_manager.py +++ b/qiskit/transpiler/preset_passmanagers/generate_preset_pass_manager.py @@ -124,7 +124,7 @@ def generate_preset_pass_manager( and ``backend_properties``. basis_gates (list): List of basis gate names to unroll to (e.g: ``['u1', 'u2', 'u3', 'cx']``). - inst_map (InstructionScheduleMap): Mapping object that maps gates to schedules. + inst_map (InstructionScheduleMap): DEPRECATED. Mapping object that maps gates to schedules. If any user defined calibration is found in the map and this is used in a circuit, transpiler attaches the custom gate definition to the circuit. This enables one to flexibly override the low-level instruction diff --git a/qiskit/transpiler/target.py b/qiskit/transpiler/target.py index 254d42b2329b..433bb9819ee4 100644 --- a/qiskit/transpiler/target.py +++ b/qiskit/transpiler/target.py @@ -101,7 +101,7 @@ def __init__( specified set of qubits error: The average error rate for the instruction on the specified set of qubits. - calibration: The pulse representation of the instruction. + calibration: DEPRECATED. The pulse representation of the instruction. """ super().__init__() self._calibration: CalibrationEntry | None = None @@ -974,7 +974,7 @@ def from_configuration( coupling_map: The coupling map representing connectivity constraints on the backend. If specified all gates from ``basis_gates`` will be supported on all qubits (or pairs of qubits). - inst_map: The instruction schedule map representing the pulse + inst_map: DEPRECATED. The instruction schedule map representing the pulse :class:`~.Schedule` definitions for each instruction. If this is specified ``coupling_map`` must be specified. The ``coupling_map`` is used as the source of truth for connectivity From 9954e7a8eb726d02f81a62e11aefcd3bc2a95694 Mon Sep 17 00:00:00 2001 From: Eli Arbel Date: Mon, 7 Oct 2024 18:36:16 +0300 Subject: [PATCH 12/23] Add initial release notes and refine deprecations --- .../fake_provider/generic_backend_v2.py | 3 - qiskit/pulse/builder.py | 1 - qiskit/pulse/calibration_entries.py | 3 - qiskit/pulse/configuration.py | 5 -- qiskit/pulse/instructions/acquire.py | 2 + qiskit/pulse/instructions/delay.py | 2 + qiskit/pulse/instructions/directives.py | 3 + qiskit/pulse/instructions/frequency.py | 3 + qiskit/pulse/instructions/phase.py | 3 + qiskit/pulse/instructions/play.py | 2 + qiskit/pulse/instructions/reference.py | 2 + qiskit/pulse/instructions/snapshot.py | 2 + qiskit/pulse/library/symbolic_pulses.py | 28 +++++++ qiskit/pulse/library/waveform.py | 2 + qiskit/qobj/converters/pulse_instruction.py | 2 - qiskit/scheduler/lowering.py | 2 - qiskit/utils/deprecate_pulse.py | 3 +- qiskit/visualization/pulse_v2/core.py | 3 - qiskit/visualization/pulse_v2/device_info.py | 3 - qiskit/visualization/pulse_v2/drawings.py | 5 -- qiskit/visualization/pulse_v2/events.py | 2 - .../pulse_v2/generators/barrier.py | 2 - .../pulse_v2/generators/chart.py | 5 -- .../pulse_v2/generators/frame.py | 6 -- .../pulse_v2/generators/snapshot.py | 3 - .../pulse_v2/generators/waveform.py | 4 - qiskit/visualization/pulse_v2/layouts.py | 8 -- .../pulse_v2/plotters/base_plotter.py | 2 - .../pulse_v2/plotters/matplotlib.py | 2 - qiskit/visualization/pulse_v2/stylesheet.py | 5 -- ...recate-pulse-package-07a621be1db7fa30.yaml | 76 +++++++++++++++++++ 31 files changed, 126 insertions(+), 68 deletions(-) create mode 100644 releasenotes/notes/deprecate-pulse-package-07a621be1db7fa30.yaml diff --git a/qiskit/providers/fake_provider/generic_backend_v2.py b/qiskit/providers/fake_provider/generic_backend_v2.py index 78779dcd87a5..e6c308fcc3d0 100644 --- a/qiskit/providers/fake_provider/generic_backend_v2.py +++ b/qiskit/providers/fake_provider/generic_backend_v2.py @@ -88,7 +88,6 @@ class PulseDefaults: _data = {} - @deprecate_pulse_dependency def __init__( self, qubit_freq_est: List[float], @@ -244,7 +243,6 @@ class PulseLibraryItem: """INTERNAL - An item in a pulse library.""" # Copy from the deprecated from qiskit.qobj.PulseLibraryItem - @deprecate_pulse_dependency def __init__(self, name, samples): """Instantiate a pulse library item. @@ -313,7 +311,6 @@ class PulseQobjInstruction: "parameters", ] - @deprecate_pulse_dependency def __init__( self, name, diff --git a/qiskit/pulse/builder.py b/qiskit/pulse/builder.py index 5890e232310f..3cdcd61fa110 100644 --- a/qiskit/pulse/builder.py +++ b/qiskit/pulse/builder.py @@ -2025,7 +2025,6 @@ def barrier(*channels_or_qubits: chans.Channel | int, name: str | None = None): # Macros -@deprecate_pulse_func def macro(func: Callable): """Wrap a Python function and activate the parent builder context at calling time. diff --git a/qiskit/pulse/calibration_entries.py b/qiskit/pulse/calibration_entries.py index b47580d02c07..8a5ba1b6e3d6 100644 --- a/qiskit/pulse/calibration_entries.py +++ b/qiskit/pulse/calibration_entries.py @@ -24,7 +24,6 @@ from qiskit.qobj.converters import QobjToInstructionConverter from qiskit.qobj.pulse_qobj import PulseQobjInstruction from qiskit.exceptions import QiskitError -from qiskit.utils.deprecate_pulse import deprecate_pulse_func IncompletePulseQobj = object() @@ -123,7 +122,6 @@ class ScheduleDef(CalibrationEntry): """ - @deprecate_pulse_func def __init__(self, arguments: Sequence[str] | None = None): """Define an empty entry. @@ -240,7 +238,6 @@ class CallableDef(CalibrationEntry): """ - @deprecate_pulse_func def __init__(self): """Define an empty entry.""" self._definition = None diff --git a/qiskit/pulse/configuration.py b/qiskit/pulse/configuration.py index 4c735caeeecc..1bfd1f13e2ee 100644 --- a/qiskit/pulse/configuration.py +++ b/qiskit/pulse/configuration.py @@ -15,7 +15,6 @@ """ from __future__ import annotations import numpy as np -from qiskit.utils.deprecate_pulse import deprecate_pulse_func from .channels import DriveChannel, MeasureChannel from .exceptions import PulseError @@ -45,7 +44,6 @@ class Kernel: into IQ points. """ - @deprecate_pulse_func def __init__(self, name: str | None = None, **params): """Create new kernel. @@ -72,7 +70,6 @@ class Discriminator: into 0/1 state results. """ - @deprecate_pulse_func def __init__(self, name: str | None = None, **params): """Create new discriminator. @@ -97,7 +94,6 @@ def __eq__(self, other): class LoRange: """Range of LO frequency.""" - @deprecate_pulse_func def __init__(self, lower_bound: float, upper_bound: float): self._lb = lower_bound self._ub = upper_bound @@ -146,7 +142,6 @@ def __eq__(self, other): class LoConfig: """Pulse channel LO frequency container.""" - @deprecate_pulse_func def __init__( self, channel_los: dict[DriveChannel | MeasureChannel, float] | None = None, diff --git a/qiskit/pulse/instructions/acquire.py b/qiskit/pulse/instructions/acquire.py index 98fbf460c1b3..3b5964d4ee3e 100644 --- a/qiskit/pulse/instructions/acquire.py +++ b/qiskit/pulse/instructions/acquire.py @@ -19,6 +19,7 @@ from qiskit.pulse.configuration import Kernel, Discriminator from qiskit.pulse.exceptions import PulseError from qiskit.pulse.instructions.instruction import Instruction +from qiskit.utils.deprecate_pulse import deprecate_pulse_func class Acquire(Instruction): @@ -38,6 +39,7 @@ class Acquire(Instruction): * the discriminator to classify kerneled IQ points. """ + @deprecate_pulse_func def __init__( self, duration: int | ParameterExpression, diff --git a/qiskit/pulse/instructions/delay.py b/qiskit/pulse/instructions/delay.py index 13f36d3b7d9b..6dd028c94fcd 100644 --- a/qiskit/pulse/instructions/delay.py +++ b/qiskit/pulse/instructions/delay.py @@ -16,6 +16,7 @@ from qiskit.circuit import ParameterExpression from qiskit.pulse.channels import Channel from qiskit.pulse.instructions.instruction import Instruction +from qiskit.utils.deprecate_pulse import deprecate_pulse_func class Delay(Instruction): @@ -34,6 +35,7 @@ class Delay(Instruction): The ``channel`` will output no signal from time=0 up until time=10. """ + @deprecate_pulse_func def __init__( self, duration: int | ParameterExpression, diff --git a/qiskit/pulse/instructions/directives.py b/qiskit/pulse/instructions/directives.py index f1e7f9b24569..1572c887f376 100644 --- a/qiskit/pulse/instructions/directives.py +++ b/qiskit/pulse/instructions/directives.py @@ -18,6 +18,7 @@ from qiskit.pulse import channels as chans from qiskit.pulse.instructions import instruction from qiskit.pulse.exceptions import PulseError +from qiskit.utils.deprecate_pulse import deprecate_pulse_func class Directive(instruction.Instruction, ABC): @@ -35,6 +36,7 @@ def duration(self) -> int: class RelativeBarrier(Directive): """Pulse ``RelativeBarrier`` directive.""" + @deprecate_pulse_func def __init__(self, *channels: chans.Channel, name: str | None = None): """Create a relative barrier directive. @@ -102,6 +104,7 @@ class TimeBlockade(Directive): user can insert another instruction without timing overlap. """ + @deprecate_pulse_func def __init__( self, duration: int, diff --git a/qiskit/pulse/instructions/frequency.py b/qiskit/pulse/instructions/frequency.py index a14e60ee1a32..545d26c92639 100644 --- a/qiskit/pulse/instructions/frequency.py +++ b/qiskit/pulse/instructions/frequency.py @@ -19,6 +19,7 @@ from qiskit.pulse.channels import PulseChannel from qiskit.pulse.instructions.instruction import Instruction from qiskit.pulse.exceptions import PulseError +from qiskit.utils.deprecate_pulse import deprecate_pulse_func class SetFrequency(Instruction): @@ -35,6 +36,7 @@ class SetFrequency(Instruction): The duration of SetFrequency is 0. """ + @deprecate_pulse_func def __init__( self, frequency: Union[float, ParameterExpression], @@ -85,6 +87,7 @@ def duration(self) -> int: class ShiftFrequency(Instruction): """Shift the channel frequency away from the current frequency.""" + @deprecate_pulse_func def __init__( self, frequency: Union[float, ParameterExpression], diff --git a/qiskit/pulse/instructions/phase.py b/qiskit/pulse/instructions/phase.py index 21f46dfb5f72..1d08918cb7e9 100644 --- a/qiskit/pulse/instructions/phase.py +++ b/qiskit/pulse/instructions/phase.py @@ -21,6 +21,7 @@ from qiskit.pulse.channels import PulseChannel from qiskit.pulse.instructions.instruction import Instruction from qiskit.pulse.exceptions import PulseError +from qiskit.utils.deprecate_pulse import deprecate_pulse_func class ShiftPhase(Instruction): @@ -40,6 +41,7 @@ class ShiftPhase(Instruction): by using a ShiftPhase to update the frame tracking the qubit state. """ + @deprecate_pulse_func def __init__( self, phase: Union[complex, ParameterExpression], @@ -101,6 +103,7 @@ class SetPhase(Instruction): The ``SetPhase`` instruction sets :math:`\phi` to the instruction's ``phase`` operand. """ + @deprecate_pulse_func def __init__( self, phase: Union[complex, ParameterExpression], diff --git a/qiskit/pulse/instructions/play.py b/qiskit/pulse/instructions/play.py index 1f42b8e3a08d..8c86555bbc8c 100644 --- a/qiskit/pulse/instructions/play.py +++ b/qiskit/pulse/instructions/play.py @@ -21,6 +21,7 @@ from qiskit.pulse.exceptions import PulseError from qiskit.pulse.instructions.instruction import Instruction from qiskit.pulse.library.pulse import Pulse +from qiskit.utils.deprecate_pulse import deprecate_pulse_func class Play(Instruction): @@ -32,6 +33,7 @@ class Play(Instruction): cycle time, dt, of the backend. """ + @deprecate_pulse_func def __init__(self, pulse: Pulse, channel: PulseChannel, name: str | None = None): """Create a new pulse instruction. diff --git a/qiskit/pulse/instructions/reference.py b/qiskit/pulse/instructions/reference.py index cf3e01f8ea6e..1f17327877a7 100644 --- a/qiskit/pulse/instructions/reference.py +++ b/qiskit/pulse/instructions/reference.py @@ -17,6 +17,7 @@ from qiskit.pulse.channels import Channel from qiskit.pulse.exceptions import PulseError, UnassignedReferenceError from qiskit.pulse.instructions import instruction +from qiskit.utils.deprecate_pulse import deprecate_pulse_func class Reference(instruction.Instruction): @@ -40,6 +41,7 @@ class Reference(instruction.Instruction): # Delimiter for tuple keys. key_delimiter = "," + @deprecate_pulse_func def __init__(self, name: str, *extra_keys: str): """Create new reference. diff --git a/qiskit/pulse/instructions/snapshot.py b/qiskit/pulse/instructions/snapshot.py index b78858b5d2c0..1692d13abc8f 100644 --- a/qiskit/pulse/instructions/snapshot.py +++ b/qiskit/pulse/instructions/snapshot.py @@ -18,11 +18,13 @@ from qiskit.pulse.channels import SnapshotChannel from qiskit.pulse.exceptions import PulseError from qiskit.pulse.instructions.instruction import Instruction +from qiskit.utils.deprecate_pulse import deprecate_pulse_func class Snapshot(Instruction): """An instruction targeted for simulators, to capture a moment in the simulation.""" + @deprecate_pulse_func def __init__(self, label: str, snapshot_type: str = "statevector", name: Optional[str] = None): """Create new snapshot. diff --git a/qiskit/pulse/library/symbolic_pulses.py b/qiskit/pulse/library/symbolic_pulses.py index b7ba658da1be..0f3104dfa656 100644 --- a/qiskit/pulse/library/symbolic_pulses.py +++ b/qiskit/pulse/library/symbolic_pulses.py @@ -31,6 +31,7 @@ from qiskit.pulse.exceptions import PulseError from qiskit.pulse.library.pulse import Pulse from qiskit.pulse.library.waveform import Waveform +from qiskit.utils.deprecate_pulse import deprecate_pulse_func def _lifted_gaussian( @@ -403,6 +404,7 @@ def Sawtooth(duration, amp, freq, name): _constraints_lam = LambdifiedExpression("_constraints") _valid_amp_conditions_lam = LambdifiedExpression("_valid_amp_conditions") + @deprecate_pulse_func def __init__( self, pulse_type: str, @@ -780,6 +782,10 @@ def __new__( valid_amp_conditions=valid_amp_conditions_expr, ) + @deprecate_pulse_func + def __init__(self): + pass + class GaussianSquare(metaclass=_PulseType): """A square pulse with a Gaussian shaped risefall on both sides lifted such that @@ -908,7 +914,12 @@ def __new__( valid_amp_conditions=valid_amp_conditions_expr, ) + @deprecate_pulse_func + def __init__(self): + pass + +@deprecate_pulse_func def GaussianSquareDrag( duration: int | ParameterExpression, amp: float | ParameterExpression, @@ -1061,6 +1072,7 @@ def GaussianSquareDrag( ) +@deprecate_pulse_func def gaussian_square_echo( duration: int | ParameterValueType, amp: float | ParameterExpression, @@ -1264,6 +1276,7 @@ def gaussian_square_echo( ) +@deprecate_pulse_func def GaussianDeriv( duration: int | ParameterValueType, amp: float | ParameterExpression, @@ -1424,6 +1437,10 @@ def __new__( valid_amp_conditions=valid_amp_conditions_expr, ) + @deprecate_pulse_func + def __init__(self): + pass + class Constant(metaclass=_PulseType): """A simple constant pulse, with an amplitude value and a duration: @@ -1485,7 +1502,12 @@ def __new__( valid_amp_conditions=valid_amp_conditions_expr, ) + @deprecate_pulse_func + def __init__(self): + pass + +@deprecate_pulse_func def Sin( duration: int | ParameterExpression, amp: float | ParameterExpression, @@ -1550,6 +1572,7 @@ def Sin( ) +@deprecate_pulse_func def Cos( duration: int | ParameterExpression, amp: float | ParameterExpression, @@ -1614,6 +1637,7 @@ def Cos( ) +@deprecate_pulse_func def Sawtooth( duration: int | ParameterExpression, amp: float | ParameterExpression, @@ -1682,6 +1706,7 @@ def Sawtooth( ) +@deprecate_pulse_func def Triangle( duration: int | ParameterExpression, amp: float | ParameterExpression, @@ -1750,6 +1775,7 @@ def Triangle( ) +@deprecate_pulse_func def Square( duration: int | ParameterValueType, amp: float | ParameterExpression, @@ -1821,6 +1847,7 @@ def Square( ) +@deprecate_pulse_func def Sech( duration: int | ParameterValueType, amp: float | ParameterExpression, @@ -1897,6 +1924,7 @@ def Sech( ) +@deprecate_pulse_func def SechDeriv( duration: int | ParameterValueType, amp: float | ParameterExpression, diff --git a/qiskit/pulse/library/waveform.py b/qiskit/pulse/library/waveform.py index ad852f226ac2..0a31ac11a8d8 100644 --- a/qiskit/pulse/library/waveform.py +++ b/qiskit/pulse/library/waveform.py @@ -18,6 +18,7 @@ from qiskit.pulse.exceptions import PulseError from qiskit.pulse.library.pulse import Pulse +from qiskit.utils.deprecate_pulse import deprecate_pulse_func class Waveform(Pulse): @@ -25,6 +26,7 @@ class Waveform(Pulse): duration of the backend cycle-time, dt. """ + @deprecate_pulse_func def __init__( self, samples: np.ndarray | list[complex], diff --git a/qiskit/qobj/converters/pulse_instruction.py b/qiskit/qobj/converters/pulse_instruction.py index c84cd3cfe2a1..e17036210d57 100644 --- a/qiskit/qobj/converters/pulse_instruction.py +++ b/qiskit/qobj/converters/pulse_instruction.py @@ -31,7 +31,6 @@ from qiskit.qobj import QobjMeasurementOption, PulseLibraryItem, PulseQobjInstruction from qiskit.qobj.utils import MeasLevel from qiskit.utils import deprecate_func -from qiskit.utils.deprecate_pulse import deprecate_pulse_dependency class ParametricPulseShapes(Enum): @@ -533,7 +532,6 @@ def _convert_new_inst(self, instruction): __chan_regex__ = re.compile(r"([a-zA-Z]+)(\d+)") - @deprecate_pulse_dependency def __init__( self, pulse_library: Optional[List[PulseLibraryItem]] = None, diff --git a/qiskit/scheduler/lowering.py b/qiskit/scheduler/lowering.py index e0ea67f67aa0..f0fb33957d9e 100644 --- a/qiskit/scheduler/lowering.py +++ b/qiskit/scheduler/lowering.py @@ -29,7 +29,6 @@ from qiskit.pulse.macros import measure from qiskit.scheduler.config import ScheduleConfig from qiskit.providers import BackendV1, BackendV2 -from qiskit.utils.deprecate_pulse import deprecate_pulse_dependency CircuitPulseDef = namedtuple( "CircuitPulseDef", @@ -37,7 +36,6 @@ ) # The labels of the qubits involved in the command according to the circuit -@deprecate_pulse_dependency def lower_gates( circuit: QuantumCircuit, schedule_config: ScheduleConfig, diff --git a/qiskit/utils/deprecate_pulse.py b/qiskit/utils/deprecate_pulse.py index 4f19ebb91bfd..51fe3b5807da 100644 --- a/qiskit/utils/deprecate_pulse.py +++ b/qiskit/utils/deprecate_pulse.py @@ -53,7 +53,6 @@ def deprecate_pulse_arg(arg_name, **kwargs): since="1.3", removal_timeline="in Qiskit 2.0", additional_msg="The entire Qiskit Pulse package is being deprecated " - "and will be moved to the Qiskit Dynamics repository: " - "https://github.com/qiskit-community/qiskit-dynamics", + "and this argument uses a dependency on the package.", **kwargs, ) diff --git a/qiskit/visualization/pulse_v2/core.py b/qiskit/visualization/pulse_v2/core.py index e65c9849f5ee..20686f6fb4f6 100644 --- a/qiskit/visualization/pulse_v2/core.py +++ b/qiskit/visualization/pulse_v2/core.py @@ -79,7 +79,6 @@ from qiskit.visualization.exceptions import VisualizationError from qiskit.visualization.pulse_v2 import events, types, drawings, device_info from qiskit.visualization.pulse_v2.stylesheet import QiskitPulseStyle -from qiskit.utils.deprecate_pulse import deprecate_pulse_dependency class DrawerCanvas: @@ -94,7 +93,6 @@ class DrawerCanvas: the appearance of the `Chart` output. """ - @deprecate_pulse_dependency def __init__(self, stylesheet: QiskitPulseStyle, device: device_info.DrawerBackendInfo): """Create new data container with backend system information. @@ -439,7 +437,6 @@ class Chart: str(types.WaveformType.OPAQUE.value), ] - @deprecate_pulse_dependency def __init__(self, parent: DrawerCanvas, name: str | None = None): """Create new chart. diff --git a/qiskit/visualization/pulse_v2/device_info.py b/qiskit/visualization/pulse_v2/device_info.py index 364afc4672cf..7898f978772c 100644 --- a/qiskit/visualization/pulse_v2/device_info.py +++ b/qiskit/visualization/pulse_v2/device_info.py @@ -41,13 +41,11 @@ class :py:class:``DrawerBackendInfo`` with necessary methods to generate drawing from qiskit import pulse from qiskit.providers import BackendConfigurationError from qiskit.providers.backend import Backend, BackendV2 -from qiskit.utils.deprecate_pulse import deprecate_pulse_dependency class DrawerBackendInfo(ABC): """Backend information to be used for the drawing data generation.""" - @deprecate_pulse_dependency def __init__( self, name: Optional[str] = None, @@ -99,7 +97,6 @@ class OpenPulseBackendInfo(DrawerBackendInfo): """Drawing information of backend that conforms to OpenPulse specification.""" @classmethod - @deprecate_pulse_dependency def create_from_backend(cls, backend: Backend): """Initialize a class with backend information provided by provider. diff --git a/qiskit/visualization/pulse_v2/drawings.py b/qiskit/visualization/pulse_v2/drawings.py index ab776e1772e7..e5a61512a6cd 100644 --- a/qiskit/visualization/pulse_v2/drawings.py +++ b/qiskit/visualization/pulse_v2/drawings.py @@ -66,7 +66,6 @@ from qiskit.pulse.channels import Channel from qiskit.visualization.pulse_v2 import types from qiskit.visualization.exceptions import VisualizationError -from qiskit.utils.deprecate_pulse import deprecate_pulse_dependency class ElementaryData(ABC): @@ -74,7 +73,6 @@ class ElementaryData(ABC): __hash__ = None - @deprecate_pulse_dependency def __init__( self, data_type: str | Enum, @@ -130,7 +128,6 @@ class LineData(ElementaryData): This is the counterpart of `matplotlib.pyplot.plot`. """ - @deprecate_pulse_dependency def __init__( self, data_type: str | Enum, @@ -173,7 +170,6 @@ class TextData(ElementaryData): This is the counterpart of `matplotlib.pyplot.text`. """ - @deprecate_pulse_dependency def __init__( self, data_type: str | Enum, @@ -219,7 +215,6 @@ class BoxData(ElementaryData): This is the counterpart of `matplotlib.patches.Rectangle`. """ - @deprecate_pulse_dependency def __init__( self, data_type: str | Enum, diff --git a/qiskit/visualization/pulse_v2/events.py b/qiskit/visualization/pulse_v2/events.py index b06d1d0b3b4e..74da24b1db25 100644 --- a/qiskit/visualization/pulse_v2/events.py +++ b/qiskit/visualization/pulse_v2/events.py @@ -84,7 +84,6 @@ from qiskit import pulse, circuit from qiskit.visualization.pulse_v2.types import PhaseFreqTuple, PulseInstruction -from qiskit.utils.deprecate_pulse import deprecate_pulse_dependency class ChannelEvents: @@ -102,7 +101,6 @@ class ChannelEvents: pulse.instructions.ShiftPhase, ) - @deprecate_pulse_dependency def __init__( self, waveforms: dict[int, pulse.Instruction], diff --git a/qiskit/visualization/pulse_v2/generators/barrier.py b/qiskit/visualization/pulse_v2/generators/barrier.py index 968791c33710..85f8271cf142 100644 --- a/qiskit/visualization/pulse_v2/generators/barrier.py +++ b/qiskit/visualization/pulse_v2/generators/barrier.py @@ -40,10 +40,8 @@ def my_object_generator(data: BarrierInstruction, from typing import Dict, Any, List from qiskit.visualization.pulse_v2 import drawings, types, device_info -from qiskit.utils.deprecate_pulse import deprecate_pulse_dependency -@deprecate_pulse_dependency def gen_barrier( data: types.BarrierInstruction, formatter: Dict[str, Any], device: device_info.DrawerBackendInfo ) -> List[drawings.LineData]: diff --git a/qiskit/visualization/pulse_v2/generators/chart.py b/qiskit/visualization/pulse_v2/generators/chart.py index 4abe442ad871..26a92fe3695e 100644 --- a/qiskit/visualization/pulse_v2/generators/chart.py +++ b/qiskit/visualization/pulse_v2/generators/chart.py @@ -40,10 +40,8 @@ def my_object_generator(data: ChartAxis, from typing import Dict, Any, List from qiskit.visualization.pulse_v2 import drawings, types, device_info -from qiskit.utils.deprecate_pulse import deprecate_pulse_dependency -@deprecate_pulse_dependency def gen_baseline( data: types.ChartAxis, formatter: Dict[str, Any], device: device_info.DrawerBackendInfo ) -> List[drawings.LineData]: @@ -80,7 +78,6 @@ def gen_baseline( return [baseline] -@deprecate_pulse_dependency def gen_chart_name( data: types.ChartAxis, formatter: Dict[str, Any], device: device_info.DrawerBackendInfo ) -> List[drawings.TextData]: @@ -118,7 +115,6 @@ def gen_chart_name( return [text] -@deprecate_pulse_dependency def gen_chart_scale( data: types.ChartAxis, formatter: Dict[str, Any], device: device_info.DrawerBackendInfo ) -> List[drawings.TextData]: @@ -159,7 +155,6 @@ def gen_chart_scale( return [text] -@deprecate_pulse_dependency def gen_channel_freqs( data: types.ChartAxis, formatter: Dict[str, Any], device: device_info.DrawerBackendInfo ) -> List[drawings.TextData]: diff --git a/qiskit/visualization/pulse_v2/generators/frame.py b/qiskit/visualization/pulse_v2/generators/frame.py index 6e1ac11c1b01..8b71b8596bb4 100644 --- a/qiskit/visualization/pulse_v2/generators/frame.py +++ b/qiskit/visualization/pulse_v2/generators/frame.py @@ -44,10 +44,8 @@ def my_object_generator(data: PulseInstruction, from qiskit.pulse import instructions from qiskit.visualization.exceptions import VisualizationError from qiskit.visualization.pulse_v2 import drawings, types, device_info -from qiskit.utils.deprecate_pulse import deprecate_pulse_dependency -@deprecate_pulse_dependency def gen_formatted_phase( data: types.PulseInstruction, formatter: Dict[str, Any], device: device_info.DrawerBackendInfo ) -> List[drawings.TextData]: @@ -105,7 +103,6 @@ def gen_formatted_phase( return [text] -@deprecate_pulse_dependency def gen_formatted_freq_mhz( data: types.PulseInstruction, formatter: Dict[str, Any], device: device_info.DrawerBackendInfo ) -> List[drawings.TextData]: @@ -154,7 +151,6 @@ def gen_formatted_freq_mhz( return [text] -@deprecate_pulse_dependency def gen_formatted_frame_values( data: types.PulseInstruction, formatter: Dict[str, Any], device: device_info.DrawerBackendInfo ) -> List[drawings.TextData]: @@ -231,7 +227,6 @@ def gen_formatted_frame_values( return texts -@deprecate_pulse_dependency def gen_raw_operand_values_compact( data: types.PulseInstruction, formatter: Dict[str, Any], device: device_info.DrawerBackendInfo ) -> List[drawings.TextData]: @@ -287,7 +282,6 @@ def gen_raw_operand_values_compact( return [text] -@deprecate_pulse_dependency def gen_frame_symbol( data: types.PulseInstruction, formatter: Dict[str, Any], device: device_info.DrawerBackendInfo ) -> List[drawings.TextData]: diff --git a/qiskit/visualization/pulse_v2/generators/snapshot.py b/qiskit/visualization/pulse_v2/generators/snapshot.py index fe3956bbc131..d86c89997a02 100644 --- a/qiskit/visualization/pulse_v2/generators/snapshot.py +++ b/qiskit/visualization/pulse_v2/generators/snapshot.py @@ -40,10 +40,8 @@ def my_object_generator(data: SnapshotInstruction, from typing import Dict, Any, List from qiskit.visualization.pulse_v2 import drawings, types, device_info -from qiskit.utils.deprecate_pulse import deprecate_pulse_dependency -@deprecate_pulse_dependency def gen_snapshot_name( data: types.SnapshotInstruction, formatter: Dict[str, Any], @@ -84,7 +82,6 @@ def gen_snapshot_name( return [text] -@deprecate_pulse_dependency def gen_snapshot_symbol( data: types.SnapshotInstruction, formatter: Dict[str, Any], diff --git a/qiskit/visualization/pulse_v2/generators/waveform.py b/qiskit/visualization/pulse_v2/generators/waveform.py index 4493a8c1fe6c..e770f271c454 100644 --- a/qiskit/visualization/pulse_v2/generators/waveform.py +++ b/qiskit/visualization/pulse_v2/generators/waveform.py @@ -49,10 +49,8 @@ def my_object_generator(data: PulseInstruction, from qiskit.pulse import instructions, library from qiskit.visualization.exceptions import VisualizationError from qiskit.visualization.pulse_v2 import drawings, types, device_info -from qiskit.utils.deprecate_pulse import deprecate_pulse_dependency -@deprecate_pulse_dependency def gen_filled_waveform_stepwise( data: types.PulseInstruction, formatter: dict[str, Any], device: device_info.DrawerBackendInfo ) -> list[drawings.LineData | drawings.BoxData | drawings.TextData]: @@ -129,7 +127,6 @@ def gen_filled_waveform_stepwise( raise VisualizationError("Invalid data format is provided.") -@deprecate_pulse_dependency def gen_ibmq_latex_waveform_name( data: types.PulseInstruction, formatter: dict[str, Any], device: device_info.DrawerBackendInfo ) -> list[drawings.TextData]: @@ -238,7 +235,6 @@ def gen_ibmq_latex_waveform_name( return [text] -@deprecate_pulse_dependency def gen_waveform_max_value( data: types.PulseInstruction, formatter: dict[str, Any], device: device_info.DrawerBackendInfo ) -> list[drawings.TextData]: diff --git a/qiskit/visualization/pulse_v2/layouts.py b/qiskit/visualization/pulse_v2/layouts.py index 55a5a206fc28..13b42e394e94 100644 --- a/qiskit/visualization/pulse_v2/layouts.py +++ b/qiskit/visualization/pulse_v2/layouts.py @@ -83,10 +83,8 @@ def my_figure_title(program: Union[pulse.Waveform, pulse.Schedule], from qiskit import pulse from qiskit.visualization.pulse_v2 import types from qiskit.visualization.pulse_v2.device_info import DrawerBackendInfo -from qiskit.utils.deprecate_pulse import deprecate_pulse_dependency -@deprecate_pulse_dependency def channel_type_grouped_sort( channels: List[pulse.channels.Channel], formatter: Dict[str, Any], device: DrawerBackendInfo ) -> Iterator[Tuple[str, List[pulse.channels.Channel]]]: @@ -137,7 +135,6 @@ def channel_type_grouped_sort( yield chan.name.upper(), [chan] -@deprecate_pulse_dependency def channel_index_grouped_sort( channels: List[pulse.channels.Channel], formatter: Dict[str, Any], device: DrawerBackendInfo ) -> Iterator[Tuple[str, List[pulse.channels.Channel]]]: @@ -200,7 +197,6 @@ def channel_index_grouped_sort( yield chan.name.upper(), [chan] -@deprecate_pulse_dependency def channel_index_grouped_sort_u( channels: List[pulse.channels.Channel], formatter: Dict[str, Any], device: DrawerBackendInfo ) -> Iterator[Tuple[str, List[pulse.channels.Channel]]]: @@ -264,7 +260,6 @@ def channel_index_grouped_sort_u( yield chan.name.upper(), [chan] -@deprecate_pulse_dependency def qubit_index_sort( channels: List[pulse.channels.Channel], formatter: Dict[str, Any], device: DrawerBackendInfo ) -> Iterator[Tuple[str, List[pulse.channels.Channel]]]: @@ -308,7 +303,6 @@ def qubit_index_sort( yield f"Q{qind:d}", chans -@deprecate_pulse_dependency def time_map_in_ns( time_window: Tuple[int, int], axis_breaks: List[Tuple[int, int]], dt: Optional[float] = None ) -> types.HorizontalAxis: @@ -367,7 +361,6 @@ def time_map_in_ns( ) -@deprecate_pulse_dependency def detail_title(program: Union[pulse.Waveform, pulse.Schedule], device: DrawerBackendInfo) -> str: """Layout function for generating figure title. @@ -389,7 +382,6 @@ def detail_title(program: Union[pulse.Waveform, pulse.Schedule], device: DrawerB return ", ".join(title_str) -@deprecate_pulse_dependency def empty_title(program: Union[pulse.Waveform, pulse.Schedule], device: DrawerBackendInfo) -> str: """Layout function for generating an empty figure title.""" return "" diff --git a/qiskit/visualization/pulse_v2/plotters/base_plotter.py b/qiskit/visualization/pulse_v2/plotters/base_plotter.py index 3bfc352d8416..ee6f79235145 100644 --- a/qiskit/visualization/pulse_v2/plotters/base_plotter.py +++ b/qiskit/visualization/pulse_v2/plotters/base_plotter.py @@ -16,13 +16,11 @@ from typing import Any from qiskit.visualization.pulse_v2 import core -from qiskit.utils.deprecate_pulse import deprecate_pulse_dependency class BasePlotter(ABC): """Base class of Qiskit plotter.""" - @deprecate_pulse_dependency def __init__(self, canvas: core.DrawerCanvas): """Create new plotter. diff --git a/qiskit/visualization/pulse_v2/plotters/matplotlib.py b/qiskit/visualization/pulse_v2/plotters/matplotlib.py index deb01464fd0b..1788a1254894 100644 --- a/qiskit/visualization/pulse_v2/plotters/matplotlib.py +++ b/qiskit/visualization/pulse_v2/plotters/matplotlib.py @@ -23,7 +23,6 @@ from qiskit.visualization.pulse_v2 import core, drawings, types from qiskit.visualization.pulse_v2.plotters.base_plotter import BasePlotter from qiskit.visualization.utils import matplotlib_close_if_inline -from qiskit.utils.deprecate_pulse import deprecate_pulse_dependency class Mpl2DPlotter(BasePlotter): @@ -33,7 +32,6 @@ class Mpl2DPlotter(BasePlotter): Each chart is map to X-Y axis of the canvas. """ - @deprecate_pulse_dependency def __init__(self, canvas: core.DrawerCanvas, axis: Optional[plt.Axes] = None): """Create new plotter. diff --git a/qiskit/visualization/pulse_v2/stylesheet.py b/qiskit/visualization/pulse_v2/stylesheet.py index e550d6e8eb31..1a37756f4baa 100644 --- a/qiskit/visualization/pulse_v2/stylesheet.py +++ b/qiskit/visualization/pulse_v2/stylesheet.py @@ -33,13 +33,11 @@ from typing import Dict, Any, Mapping from qiskit.visualization.pulse_v2 import generators, layouts -from qiskit.utils.deprecate_pulse import deprecate_pulse_dependency class QiskitPulseStyle(dict): """Stylesheet for pulse drawer.""" - @deprecate_pulse_dependency def __init__(self): super().__init__() # to inform which stylesheet is applied. some plotter may not support specific style. @@ -95,7 +93,6 @@ class IQXStandard(dict): - Channels are sorted by index and control channels are added to the end. """ - @deprecate_pulse_dependency def __init__(self, **kwargs): super().__init__() style = { @@ -140,7 +137,6 @@ class IQXSimple(dict): - Channels are sorted by qubit index. """ - @deprecate_pulse_dependency def __init__(self, **kwargs): super().__init__() style = { @@ -185,7 +181,6 @@ class IQXDebugging(dict): - Channels are sorted by index and control channels are added to the end. """ - @deprecate_pulse_dependency def __init__(self, **kwargs): super().__init__() style = { diff --git a/releasenotes/notes/deprecate-pulse-package-07a621be1db7fa30.yaml b/releasenotes/notes/deprecate-pulse-package-07a621be1db7fa30.yaml new file mode 100644 index 000000000000..094106c2372c --- /dev/null +++ b/releasenotes/notes/deprecate-pulse-package-07a621be1db7fa30.yaml @@ -0,0 +1,76 @@ +--- +deprecations_pulse: + - | + The Qiskit Pulse package is being deprecated and will be removed in Qiskit version 2.0.0. Pulse-level + access is currently supported on a subset of Eagle devices but not on the latest Heron architecture + ones. Going forward, newer IBM Quantum architectures will not support pulse-level access as well. As a + consequence, supporting Pulse as a first-class citizen frontend in the Qiskit SDK itself makes little + sense going forward. The deprecation includes all pulse code in :mod:`qiskit.pulse` as well as functionality + dependant or related to pulse such as pulse visualization, serialization and custom calibration support. For + more details see the deprecation sections. + + The Pulse package as a whole, along with directly related components in Qiskit, will be moved to the + `Qiskit Dynamics `__ repository to further enable + pulse and low-level control simulation. +deprecations_circuits: + - | + As part of the Qiskit Pulse package deprecation, the following dependencies are deprecated as well: + * :attr:`qiskit.circuit.QuantumCircuit.calibrations` + * :meth:`qiskit.circuit.QuantumCircuit.has_calibration_for` + * :meth:`qiskit.circuit.QuantumCircuit.add_calibration` + * :attr:`qiskit.dagcircuit.DAGCircuit.calibrations` + * :meth:`qiskit.dagcircuit.DAGCircuit.has_calibration_for` + * :meth:`qiskit.dagcircuit.DAGCircuit.add_calibration` + * :attr:`qiskit.dagcircuit.DAGDependency.calibrations` +deprecations_qpy: + - | + As part of the Qiskit Pulse package deprecation, serializing a :class:`qiskit.pulse.ScheduleBlock`-based payloads + is being deprecated. In particular, passing :class:`qiskit.pulse.ScheduleBlock` objects to the `programs` argument in + the :func:`qiskit.qpy.dump` function is being deprecated. +deprecations_transpiler: + - | + As part of the Qiskit Pulse package deprecation, pulse-related aspects in the :class:`qiskit.transpiler.Target` class are + being deprecated. These include: + * :attr:`qiskit.transpiler.Target.calibration` + * :meth:`qiskit.transpiler.Target.update_from_instruction_schedule_map` + * :meth:`qiskit.transpiler.Target.has_calibration` + * :meth:`qiskit.transpiler.Target.get_calibration` + * :meth:`qiskit.transpiler.Target.instruction_schedule_map` + + In addition the following transpiler passer are also being deprecated: + * :class:`qiskit.transpiler.passes.PulseGates` + * :class:`qiskit.transpiler.passes.ValidatePulseGates` + * :class:`qiskit.transpiler.passes.RXCalibrationBuilder` + * :class:`qiskit.transpiler.passes.RZXCalibrationBuilder` + + Finally, the ability to generate a preset pass manager using custom calibrations by sending an object of + type :class:`qiskit.pulse.instruction_schedule_map.InstructionScheduleMap` to + :func:`qiskit.transpiler.generate_preset_pass_manager` is being deprecated as well. +deprecations_visualization: + - | + As part of the Qiskit Pulse package deprecation, pulse drawing via :meth:`qiskit.visualization.pulse_drawer` + is being deprecated. +deprecations_providers: + - | + As part of the Qiskit Pulse package deprecation, all pulse-related functionality in :class:`qiskit.providers.BackendV2` class + is being deprecated. This includes the following methods: + * :meth:`qiskit.providers.BackendV2.instruction_schedule_map` + * :meth:`qiskit.providers.BackendV2.drive_channel` + * :meth:`qiskit.providers.BackendV2.measure_channel` + * :meth:`qiskit.providers.BackendV2.acquire_channel` + * :meth:`qiskit.providers.BackendV2.control_channel` + + Consequently, the corresponding channel methods in the :class:`qiskit.providers.BackendV2Converter` and + :class:`qiskit.providers.fake_provider.GenericBackendV2` classes are being deprecated as well. +deprecations_misc: + - | + As part of the Qiskit Pulse package deprecation, the following functions and class are being + deprecated as well: + * :meth:`qiskit.compiler.schedule` + * :meth:`qiskit.compiler.sequence` + * :meth:`qiskit.assembler.assemble_schedules` + * :meth:`qiskit.scheduler.methods.as_soon_as_possible` + * :meth:`qiskit.scheduler.methods.as_late_as_possible` + * :meth:`qiskit.scheduler.schedule_circuit.schedule_circuit` + * :class:`qiskit.scheduler.ScheduleConfig` + From 3a08782fa0045d23bf221e62ca5750ca6d4db0f2 Mon Sep 17 00:00:00 2001 From: Eli Arbel Date: Wed, 9 Oct 2024 11:33:53 +0300 Subject: [PATCH 13/23] Warn about pulse gates serialization --- qiskit/qpy/interface.py | 10 ++++++++++ qiskit/utils/deprecate_pulse.py | 3 +++ 2 files changed, 13 insertions(+) diff --git a/qiskit/qpy/interface.py b/qiskit/qpy/interface.py index 138580c80d6f..41b27e9791d9 100644 --- a/qiskit/qpy/interface.py +++ b/qiskit/qpy/interface.py @@ -204,7 +204,10 @@ def dump( file_obj.write(header) common.write_type_key(file_obj, type_key) + pulse_gates = False for program in programs: + if type_key == type_keys.Program.CIRCUIT and program.calibrations: + pulse_gates = True writer( file_obj, program, @@ -213,6 +216,13 @@ def dump( version=version, ) + if pulse_gates: + warnings.warn( + category=DeprecationWarning, + message="Pulse gates serialization is deprecated as of Qiskit 1.3. " + "It will be removed in Qiskit 2.0.", + ) + def load( file_obj: BinaryIO, diff --git a/qiskit/utils/deprecate_pulse.py b/qiskit/utils/deprecate_pulse.py index 51fe3b5807da..71d70c1039d9 100644 --- a/qiskit/utils/deprecate_pulse.py +++ b/qiskit/utils/deprecate_pulse.py @@ -21,6 +21,7 @@ def deprecate_pulse_func(func): """Deprecation message for functions and classes""" return deprecate_func( since="1.3", + package_name="Qiskit", removal_timeline="in Qiskit 2.0", additional_msg="The entire Qiskit Pulse package is being deprecated " "and will be moved to the Qiskit Dynamics repository: " @@ -33,6 +34,7 @@ def deprecate_pulse_dependency(*args, **kwargs): decorator = deprecate_func( since="1.3", + package_name="Qiskit", removal_timeline="in Qiskit 2.0", additional_msg="The entire Qiskit Pulse package is being deprecated " "and this is a dependency on the package.", @@ -51,6 +53,7 @@ def deprecate_pulse_arg(arg_name, **kwargs): return deprecate_arg( name=arg_name, since="1.3", + package_name="Qiskit", removal_timeline="in Qiskit 2.0", additional_msg="The entire Qiskit Pulse package is being deprecated " "and this argument uses a dependency on the package.", From 081401ec52a7bd0bc763319020632db024809b84 Mon Sep 17 00:00:00 2001 From: Eli Arbel Date: Mon, 14 Oct 2024 16:41:45 +0300 Subject: [PATCH 14/23] Handle deprecation warnings in unit testing --- test/python/circuit/test_calibrations.py | 21 +- .../circuit/test_circuit_load_from_qpy.py | 18 +- .../python/circuit/test_circuit_operations.py | 9 +- .../python/circuit/test_circuit_properties.py | 104 +-- test/python/circuit/test_compose.py | 25 +- test/python/circuit/test_parameters.py | 112 ++- test/python/circuit/test_scheduled_circuit.py | 16 +- test/python/compiler/test_assembler.py | 535 ++++++------ test/python/compiler/test_disassembler.py | 226 +++--- test/python/compiler/test_scheduler.py | 41 +- test/python/compiler/test_sequencer.py | 28 +- test/python/compiler/test_transpiler.py | 227 +++--- test/python/converters/test_circuit_to_dag.py | 11 +- .../test_circuit_to_dagdependency.py | 11 +- .../test_circuit_to_dagdependency_v2.py | 8 +- test/python/dagcircuit/test_compose.py | 11 +- .../python/primitives/test_backend_sampler.py | 34 +- .../primitives/test_backend_sampler_v2.py | 7 +- test/python/primitives/test_primitive.py | 14 +- .../fake_provider/test_generic_backend_v2.py | 37 +- test/python/providers/test_backend_v2.py | 20 +- .../providers/test_backendconfiguration.py | 88 +- test/python/providers/test_fake_backends.py | 6 +- test/python/providers/test_pulse_defaults.py | 8 +- test/python/pulse/test_block.py | 10 + test/python/pulse/test_builder.py | 24 +- test/python/pulse/test_builder_v2.py | 55 +- test/python/pulse/test_calibration_entries.py | 18 +- test/python/pulse/test_channels.py | 9 + .../pulse/test_experiment_configurations.py | 2 + .../pulse/test_instruction_schedule_map.py | 16 +- test/python/pulse/test_instructions.py | 11 + test/python/pulse/test_macros.py | 77 +- test/python/pulse/test_parameter_manager.py | 8 + test/python/pulse/test_parser.py | 2 + test/python/pulse/test_pulse_lib.py | 41 +- test/python/pulse/test_reference.py | 4 + test/python/pulse/test_samplers.py | 2 + test/python/pulse/test_schedule.py | 9 + test/python/pulse/test_transforms.py | 15 + test/python/qobj/test_pulse_converter.py | 163 ++-- test/python/qpy/test_block_load_from_qpy.py | 399 +++++---- test/python/qpy/test_circuit_load_from_qpy.py | 14 +- test/python/scheduler/test_basic_scheduler.py | 767 ++++++++++-------- .../test_instruction_alignments.py | 58 +- .../transpiler/test_calibrationbuilder.py | 94 ++- .../transpiler/test_dynamical_decoupling.py | 38 +- test/python/transpiler/test_gate_direction.py | 9 +- .../transpiler/test_instruction_alignments.py | 38 +- .../transpiler/test_instruction_durations.py | 3 +- test/python/transpiler/test_passmanager.py | 3 +- .../transpiler/test_passmanager_config.py | 18 +- .../transpiler/test_preset_passmanagers.py | 19 +- .../python/transpiler/test_pulse_gate_pass.py | 215 ++--- test/python/transpiler/test_sabre_swap.py | 20 +- .../test_scheduling_padding_pass.py | 8 +- .../python/transpiler/test_stochastic_swap.py | 11 +- test/python/transpiler/test_target.py | 198 +++-- .../transpiler/test_unitary_synthesis.py | 17 +- test/python/transpiler/test_vf2_layout.py | 8 +- .../python/transpiler/test_vf2_post_layout.py | 20 +- test/python/utils/test_parallel.py | 6 +- .../visualization/pulse_v2/test_core.py | 5 + .../visualization/pulse_v2/test_drawings.py | 3 + .../visualization/pulse_v2/test_events.py | 2 + .../visualization/pulse_v2/test_generators.py | 11 + .../visualization/pulse_v2/test_layouts.py | 6 + test/python/visualization/test_gate_map.py | 10 +- test/utils/base.py | 7 - .../circuit/test_circuit_matplotlib_drawer.py | 74 +- 70 files changed, 2399 insertions(+), 1765 deletions(-) diff --git a/test/python/circuit/test_calibrations.py b/test/python/circuit/test_calibrations.py index cd0d4cb0b6cb..6df7302ee50e 100644 --- a/test/python/circuit/test_calibrations.py +++ b/test/python/circuit/test_calibrations.py @@ -27,29 +27,34 @@ def test_iadd(self): """Test that __iadd__ keeps the calibrations.""" qc_cal = QuantumCircuit(2) qc_cal.rzx(0.5, 0, 1) - qc_cal.add_calibration(RZXGate, (0, 1), params=[0.5], schedule=Schedule()) + with self.assertWarns(DeprecationWarning): + qc_cal.add_calibration(RZXGate, (0, 1), params=[0.5], schedule=Schedule()) qc = QuantumCircuit(2) qc &= qc_cal - self.assertEqual(qc.calibrations[RZXGate], {((0, 1), (0.5,)): Schedule(name="test")}) - self.assertEqual(qc_cal.calibrations, qc.calibrations) + with self.assertWarns(DeprecationWarning): + self.assertEqual(qc.calibrations[RZXGate], {((0, 1), (0.5,)): Schedule(name="test")}) + self.assertEqual(qc_cal.calibrations, qc.calibrations) def test_add(self): """Test that __add__ keeps the calibrations.""" qc_cal = QuantumCircuit(2) qc_cal.rzx(0.5, 0, 1) - qc_cal.add_calibration(RZXGate, (0, 1), params=[0.5], schedule=Schedule()) + with self.assertWarns(DeprecationWarning): + qc_cal.add_calibration(RZXGate, (0, 1), params=[0.5], schedule=Schedule()) qc = QuantumCircuit(2) & qc_cal - self.assertEqual(qc.calibrations[RZXGate], {((0, 1), (0.5,)): Schedule(name="test")}) - self.assertEqual(qc_cal.calibrations, qc.calibrations) + with self.assertWarns(DeprecationWarning): + self.assertEqual(qc.calibrations[RZXGate], {((0, 1), (0.5,)): Schedule(name="test")}) + self.assertEqual(qc_cal.calibrations, qc.calibrations) qc = qc_cal & QuantumCircuit(2) - self.assertEqual(qc.calibrations[RZXGate], {((0, 1), (0.5,)): Schedule(name="test")}) - self.assertEqual(qc_cal.calibrations, qc.calibrations) + with self.assertWarns(DeprecationWarning): + self.assertEqual(qc.calibrations[RZXGate], {((0, 1), (0.5,)): Schedule(name="test")}) + self.assertEqual(qc_cal.calibrations, qc.calibrations) if __name__ == "__main__": diff --git a/test/python/circuit/test_circuit_load_from_qpy.py b/test/python/circuit/test_circuit_load_from_qpy.py index db8663ace558..b9fdd2a10910 100644 --- a/test/python/circuit/test_circuit_load_from_qpy.py +++ b/test/python/circuit/test_circuit_load_from_qpy.py @@ -338,20 +338,25 @@ def test_bound_calibration_parameter(self): """ amp = Parameter("amp") - with pulse.builder.build() as sched: - pulse.builder.play(pulse.Constant(100, amp), pulse.DriveChannel(0)) + with self.assertWarns(DeprecationWarning): + with pulse.builder.build() as sched: + pulse.builder.play(pulse.Constant(100, amp), pulse.DriveChannel(0)) gate = Gate("custom", 1, [amp]) qc = QuantumCircuit(1) qc.append(gate, (0,)) - qc.add_calibration(gate, (0,), sched) + with self.assertWarns(DeprecationWarning): + qc.add_calibration(gate, (0,), sched) qc.assign_parameters({amp: 1 / 3}, inplace=True) qpy_file = io.BytesIO() - dump(qc, qpy_file) + with self.assertWarns(DeprecationWarning): + # qpy.dump warns for deprecations of pulse gate serialization + dump(qc, qpy_file) qpy_file.seek(0) - new_circ = load(qpy_file)[0] + with self.assertWarns(DeprecationWarning): + new_circ = load(qpy_file)[0] self.assertEqual(qc, new_circ) instruction = new_circ.data[0] cal_key = ( @@ -360,7 +365,8 @@ def test_bound_calibration_parameter(self): ) # Make sure that looking for a calibration based on the instruction's # parameters succeeds - self.assertIn(cal_key, new_circ.calibrations[gate.name]) + with self.assertWarns(DeprecationWarning): + self.assertIn(cal_key, new_circ.calibrations[gate.name]) def test_parameter_expression(self): """Test a circuit with a parameter expression.""" diff --git a/test/python/circuit/test_circuit_operations.py b/test/python/circuit/test_circuit_operations.py index f374f82504a6..2d1e136d4580 100644 --- a/test/python/circuit/test_circuit_operations.py +++ b/test/python/circuit/test_circuit_operations.py @@ -400,8 +400,10 @@ def test_copy_empty_like_circuit(self): qc.h(qr[0]) qc.measure(qr[0], cr[0]) qc.measure(qr[1], cr[1]) - sched = Schedule(Play(Gaussian(160, 0.1, 40), DriveChannel(0))) - qc.add_calibration("h", [0, 1], sched) + + with self.assertWarns(DeprecationWarning): + sched = Schedule(Play(Gaussian(160, 0.1, 40), DriveChannel(0))) + qc.add_calibration("h", [0, 1], sched) copied = qc.copy_empty_like() qc.clear() @@ -409,7 +411,8 @@ def test_copy_empty_like_circuit(self): self.assertEqual(qc.global_phase, copied.global_phase) self.assertEqual(qc.name, copied.name) self.assertEqual(qc.metadata, copied.metadata) - self.assertEqual(qc.calibrations, copied.calibrations) + with self.assertWarns(DeprecationWarning): + self.assertEqual(qc.calibrations, copied.calibrations) copied = qc.copy_empty_like("copy") self.assertEqual(copied.name, "copy") diff --git a/test/python/circuit/test_circuit_properties.py b/test/python/circuit/test_circuit_properties.py index d51dd0c75616..d87487639672 100644 --- a/test/python/circuit/test_circuit_properties.py +++ b/test/python/circuit/test_circuit_properties.py @@ -1179,88 +1179,98 @@ def test_calibrations_basis_gates(self): """Check if the calibrations for basis gates provided are added correctly.""" circ = QuantumCircuit(2) - with pulse.build() as q0_x180: - pulse.play(pulse.library.Gaussian(20, 1.0, 3.0), pulse.DriveChannel(0)) - with pulse.build() as q1_y90: - pulse.play(pulse.library.Gaussian(20, -1.0, 3.0), pulse.DriveChannel(1)) - - # Add calibration - circ.add_calibration(RXGate(3.14), [0], q0_x180) - circ.add_calibration(RYGate(1.57), [1], q1_y90) - - self.assertEqual(set(circ.calibrations.keys()), {"rx", "ry"}) - self.assertEqual(set(circ.calibrations["rx"].keys()), {((0,), (3.14,))}) - self.assertEqual(set(circ.calibrations["ry"].keys()), {((1,), (1.57,))}) - self.assertEqual( - circ.calibrations["rx"][((0,), (3.14,))].instructions, q0_x180.instructions - ) - self.assertEqual(circ.calibrations["ry"][((1,), (1.57,))].instructions, q1_y90.instructions) + with self.assertWarns(DeprecationWarning): + with pulse.build() as q0_x180: + pulse.play(pulse.library.Gaussian(20, 1.0, 3.0), pulse.DriveChannel(0)) + with pulse.build() as q1_y90: + pulse.play(pulse.library.Gaussian(20, -1.0, 3.0), pulse.DriveChannel(1)) + + # Add calibration + circ.add_calibration(RXGate(3.14), [0], q0_x180) + circ.add_calibration(RYGate(1.57), [1], q1_y90) + + self.assertEqual(set(circ.calibrations.keys()), {"rx", "ry"}) + self.assertEqual(set(circ.calibrations["rx"].keys()), {((0,), (3.14,))}) + self.assertEqual(set(circ.calibrations["ry"].keys()), {((1,), (1.57,))}) + self.assertEqual( + circ.calibrations["rx"][((0,), (3.14,))].instructions, q0_x180.instructions + ) + self.assertEqual( + circ.calibrations["ry"][((1,), (1.57,))].instructions, q1_y90.instructions + ) def test_calibrations_custom_gates(self): """Check if the calibrations for custom gates with params provided are added correctly.""" circ = QuantumCircuit(3) - with pulse.build() as q0_x180: - pulse.play(pulse.library.Gaussian(20, 1.0, 3.0), pulse.DriveChannel(0)) + with self.assertWarns(DeprecationWarning): + with pulse.build() as q0_x180: + pulse.play(pulse.library.Gaussian(20, 1.0, 3.0), pulse.DriveChannel(0)) - # Add calibrations with a custom gate 'rxt' - circ.add_calibration("rxt", [0], q0_x180, params=[1.57, 3.14, 4.71]) + # Add calibrations with a custom gate 'rxt' + circ.add_calibration("rxt", [0], q0_x180, params=[1.57, 3.14, 4.71]) - self.assertEqual(set(circ.calibrations.keys()), {"rxt"}) - self.assertEqual(set(circ.calibrations["rxt"].keys()), {((0,), (1.57, 3.14, 4.71))}) - self.assertEqual( - circ.calibrations["rxt"][((0,), (1.57, 3.14, 4.71))].instructions, q0_x180.instructions - ) + self.assertEqual(set(circ.calibrations.keys()), {"rxt"}) + self.assertEqual(set(circ.calibrations["rxt"].keys()), {((0,), (1.57, 3.14, 4.71))}) + self.assertEqual( + circ.calibrations["rxt"][((0,), (1.57, 3.14, 4.71))].instructions, + q0_x180.instructions, + ) def test_calibrations_no_params(self): """Check calibrations if the no params is provided with just gate name.""" circ = QuantumCircuit(3) - with pulse.build() as q0_x180: - pulse.play(pulse.library.Gaussian(20, 1.0, 3.0), pulse.DriveChannel(0)) + with self.assertWarns(DeprecationWarning): + with pulse.build() as q0_x180: + pulse.play(pulse.library.Gaussian(20, 1.0, 3.0), pulse.DriveChannel(0)) - circ.add_calibration("h", [0], q0_x180) + circ.add_calibration("h", [0], q0_x180) - self.assertEqual(set(circ.calibrations.keys()), {"h"}) - self.assertEqual(set(circ.calibrations["h"].keys()), {((0,), ())}) - self.assertEqual(circ.calibrations["h"][((0,), ())].instructions, q0_x180.instructions) + self.assertEqual(set(circ.calibrations.keys()), {"h"}) + self.assertEqual(set(circ.calibrations["h"].keys()), {((0,), ())}) + self.assertEqual(circ.calibrations["h"][((0,), ())].instructions, q0_x180.instructions) def test_has_calibration_for(self): """Test that `has_calibration_for` returns a correct answer.""" qc = QuantumCircuit(3) - with pulse.build() as q0_x180: - pulse.play(pulse.library.Gaussian(20, 1.0, 3.0), pulse.DriveChannel(0)) - qc.add_calibration("h", [0], q0_x180) + with self.assertWarns(DeprecationWarning): + with pulse.build() as q0_x180: + pulse.play(pulse.library.Gaussian(20, 1.0, 3.0), pulse.DriveChannel(0)) + qc.add_calibration("h", [0], q0_x180) qc.h(0) qc.h(1) - self.assertTrue(qc.has_calibration_for(qc.data[0])) - self.assertFalse(qc.has_calibration_for(qc.data[1])) + with self.assertWarns(DeprecationWarning): + self.assertTrue(qc.has_calibration_for(qc.data[0])) + self.assertFalse(qc.has_calibration_for(qc.data[1])) def test_has_calibration_for_legacy(self): """Test that `has_calibration_for` returns a correct answer when presented with a legacy 3 tuple.""" qc = QuantumCircuit(3) - with pulse.build() as q0_x180: - pulse.play(pulse.library.Gaussian(20, 1.0, 3.0), pulse.DriveChannel(0)) - qc.add_calibration("h", [0], q0_x180) + with self.assertWarns(DeprecationWarning): + with pulse.build() as q0_x180: + pulse.play(pulse.library.Gaussian(20, 1.0, 3.0), pulse.DriveChannel(0)) + qc.add_calibration("h", [0], q0_x180) qc.h(0) qc.h(1) - self.assertTrue( - qc.has_calibration_for( - (qc.data[0].operation, list(qc.data[0].qubits), list(qc.data[0].clbits)) + with self.assertWarns(DeprecationWarning): + self.assertTrue( + qc.has_calibration_for( + (qc.data[0].operation, list(qc.data[0].qubits), list(qc.data[0].clbits)) + ) ) - ) - self.assertFalse( - qc.has_calibration_for( - (qc.data[1].operation, list(qc.data[1].qubits), list(qc.data[1].clbits)) + self.assertFalse( + qc.has_calibration_for( + (qc.data[1].operation, list(qc.data[1].qubits), list(qc.data[1].clbits)) + ) ) - ) def test_metadata_copy_does_not_share_state(self): """Verify mutating the metadata of a circuit copy does not impact original.""" diff --git a/test/python/circuit/test_compose.py b/test/python/circuit/test_compose.py index 582bee082d99..0981b5f3ed79 100644 --- a/test/python/circuit/test_compose.py +++ b/test/python/circuit/test_compose.py @@ -576,21 +576,25 @@ def test_compose_gate(self): def test_compose_calibrations(self): """Test that composing two circuits updates calibrations.""" circ_left = QuantumCircuit(1) - circ_left.add_calibration("h", [0], None) circ_right = QuantumCircuit(1) - circ_right.add_calibration("rx", [0], None) + with self.assertWarns(DeprecationWarning): + circ_left.add_calibration("h", [0], None) + circ_right.add_calibration("rx", [0], None) circ = circ_left.compose(circ_right) - self.assertEqual(len(circ.calibrations), 2) - self.assertEqual(len(circ_left.calibrations), 1) + with self.assertWarns(DeprecationWarning): + self.assertEqual(len(circ.calibrations), 2) + self.assertEqual(len(circ_left.calibrations), 1) circ_left = QuantumCircuit(1) - circ_left.add_calibration("h", [0], None) circ_right = QuantumCircuit(1) - circ_right.add_calibration("h", [1], None) + with self.assertWarns(DeprecationWarning): + circ_left.add_calibration("h", [0], None) + circ_right.add_calibration("h", [1], None) circ = circ_left.compose(circ_right) - self.assertEqual(len(circ.calibrations), 1) - self.assertEqual(len(circ.calibrations["h"]), 2) - self.assertEqual(len(circ_left.calibrations), 1) + with self.assertWarns(DeprecationWarning): + self.assertEqual(len(circ.calibrations), 1) + self.assertEqual(len(circ.calibrations["h"]), 2) + self.assertEqual(len(circ_left.calibrations), 1) # Ensure that transpiled _calibration is defaultdict qc = QuantumCircuit(2, 2) @@ -598,7 +602,8 @@ def test_compose_calibrations(self): qc.cx(0, 1) qc.measure(0, 0) qc = transpile(qc, None, basis_gates=["h", "cx"], coupling_map=[[0, 1], [1, 0]]) - qc.add_calibration("cx", [0, 1], Schedule()) + with self.assertWarns(DeprecationWarning): + qc.add_calibration("cx", [0, 1], Schedule()) def test_compose_one_liner(self): """Test building a circuit in one line, for fun.""" diff --git a/test/python/circuit/test_parameters.py b/test/python/circuit/test_parameters.py index c10e274be791..e291eb415813 100644 --- a/test/python/circuit/test_parameters.py +++ b/test/python/circuit/test_parameters.py @@ -717,14 +717,15 @@ def test_calibration_assignment(self): circ.append(Gate("rxt", 1, [theta]), [0]) circ.measure(0, 0) - rxt_q0 = pulse.Schedule( - pulse.Play( - pulse.library.Gaussian(duration=128, sigma=16, amp=0.2 * theta / 3.14), - pulse.DriveChannel(0), + with self.assertWarns(DeprecationWarning): + rxt_q0 = pulse.Schedule( + pulse.Play( + pulse.library.Gaussian(duration=128, sigma=16, amp=0.2 * theta / 3.14), + pulse.DriveChannel(0), + ) ) - ) - circ.add_calibration("rxt", [0], rxt_q0, [theta]) + circ.add_calibration("rxt", [0], rxt_q0, [theta]) circ = circ.assign_parameters({theta: 3.14}) instruction = circ.data[0] @@ -733,9 +734,11 @@ def test_calibration_assignment(self): tuple(instruction.operation.params), ) self.assertEqual(cal_key, ((0,), (3.14,))) - # Make sure that key from instruction data matches the calibrations dictionary - self.assertIn(cal_key, circ.calibrations["rxt"]) - sched = circ.calibrations["rxt"][cal_key] + + with self.assertWarns(DeprecationWarning): + # Make sure that key from instruction data matches the calibrations dictionary + self.assertIn(cal_key, circ.calibrations["rxt"]) + sched = circ.calibrations["rxt"][cal_key] self.assertEqual(sched.instructions[0][1].pulse.amp, 0.2) def test_calibration_assignment_doesnt_mutate(self): @@ -745,19 +748,21 @@ def test_calibration_assignment_doesnt_mutate(self): circ.append(Gate("rxt", 1, [theta]), [0]) circ.measure(0, 0) - rxt_q0 = pulse.Schedule( - pulse.Play( - pulse.library.Gaussian(duration=128, sigma=16, amp=0.2 * theta / 3.14), - pulse.DriveChannel(0), + with self.assertWarns(DeprecationWarning): + rxt_q0 = pulse.Schedule( + pulse.Play( + pulse.library.Gaussian(duration=128, sigma=16, amp=0.2 * theta / 3.14), + pulse.DriveChannel(0), + ) ) - ) - circ.add_calibration("rxt", [0], rxt_q0, [theta]) + circ.add_calibration("rxt", [0], rxt_q0, [theta]) circ_copy = copy.deepcopy(circ) assigned_circ = circ.assign_parameters({theta: 3.14}) - self.assertEqual(circ.calibrations, circ_copy.calibrations) - self.assertNotEqual(assigned_circ.calibrations, circ.calibrations) + with self.assertWarns(DeprecationWarning): + self.assertEqual(circ.calibrations, circ_copy.calibrations) + self.assertNotEqual(assigned_circ.calibrations, circ.calibrations) def test_calibration_assignment_w_expressions(self): """That calibrations with multiple parameters are assigned correctly""" @@ -767,14 +772,15 @@ def test_calibration_assignment_w_expressions(self): circ.append(Gate("rxt", 1, [theta / 2, sigma]), [0]) circ.measure(0, 0) - rxt_q0 = pulse.Schedule( - pulse.Play( - pulse.library.Gaussian(duration=128, sigma=4 * sigma, amp=0.2 * theta / 3.14), - pulse.DriveChannel(0), + with self.assertWarns(DeprecationWarning): + rxt_q0 = pulse.Schedule( + pulse.Play( + pulse.library.Gaussian(duration=128, sigma=4 * sigma, amp=0.2 * theta / 3.14), + pulse.DriveChannel(0), + ) ) - ) - circ.add_calibration("rxt", [0], rxt_q0, [theta / 2, sigma]) + circ.add_calibration("rxt", [0], rxt_q0, [theta / 2, sigma]) circ = circ.assign_parameters({theta: 3.14, sigma: 4}) instruction = circ.data[0] @@ -783,9 +789,10 @@ def test_calibration_assignment_w_expressions(self): tuple(instruction.operation.params), ) self.assertEqual(cal_key, ((0,), (3.14 / 2, 4))) - # Make sure that key from instruction data matches the calibrations dictionary - self.assertIn(cal_key, circ.calibrations["rxt"]) - sched = circ.calibrations["rxt"][cal_key] + with self.assertWarns(DeprecationWarning): + # Make sure that key from instruction data matches the calibrations dictionary + self.assertIn(cal_key, circ.calibrations["rxt"]) + sched = circ.calibrations["rxt"][cal_key] self.assertEqual(sched.instructions[0][1].pulse.amp, 0.2) self.assertEqual(sched.instructions[0][1].pulse.sigma, 16) @@ -793,16 +800,19 @@ def test_substitution(self): """Test Parameter substitution (vs bind).""" alpha = Parameter("⍺") beta = Parameter("beta") - schedule = pulse.Schedule(pulse.ShiftPhase(alpha, pulse.DriveChannel(0))) + with self.assertWarns(DeprecationWarning): + schedule = pulse.Schedule(pulse.ShiftPhase(alpha, pulse.DriveChannel(0))) circ = QuantumCircuit(3, 3) circ.append(Gate("my_rz", 1, [alpha]), [0]) - circ.add_calibration("my_rz", [0], schedule, [alpha]) + with self.assertWarns(DeprecationWarning): + circ.add_calibration("my_rz", [0], schedule, [alpha]) circ = circ.assign_parameters({alpha: 2 * beta}) circ = circ.assign_parameters({beta: 1.57}) - cal_sched = circ.calibrations["my_rz"][((0,), (3.14,))] + with self.assertWarns(DeprecationWarning): + cal_sched = circ.calibrations["my_rz"][((0,), (3.14,))] self.assertEqual(float(cal_sched.instructions[0][1].phase), 3.14) def test_partial_assignment(self): @@ -812,14 +822,16 @@ def test_partial_assignment(self): gamma = Parameter("γ") phi = Parameter("ϕ") - with pulse.build() as my_cal: - pulse.set_frequency(alpha + beta, pulse.DriveChannel(0)) - pulse.shift_frequency(gamma + beta, pulse.DriveChannel(0)) - pulse.set_phase(phi, pulse.DriveChannel(1)) + with self.assertWarns(DeprecationWarning): + with pulse.build() as my_cal: + pulse.set_frequency(alpha + beta, pulse.DriveChannel(0)) + pulse.shift_frequency(gamma + beta, pulse.DriveChannel(0)) + pulse.set_phase(phi, pulse.DriveChannel(1)) circ = QuantumCircuit(2, 2) circ.append(Gate("custom", 2, [alpha, beta, gamma, phi]), [0, 1]) - circ.add_calibration("custom", [0, 1], my_cal, [alpha, beta, gamma, phi]) + with self.assertWarns(DeprecationWarning): + circ.add_calibration("custom", [0, 1], my_cal, [alpha, beta, gamma, phi]) # Partial bind delta = 1e9 @@ -828,22 +840,34 @@ def test_partial_assignment(self): phase = 3.14 / 4 circ = circ.assign_parameters({alpha: freq - delta}) - cal_sched = list(circ.calibrations["custom"].values())[0] - self.assertEqual(cal_sched.instructions[0][1].frequency, freq - delta + beta) + with self.assertWarns(DeprecationWarning): + cal_sched = list(circ.calibrations["custom"].values())[0] + with self.assertWarns(DeprecationWarning): + # instructions triggers conversion to Schedule + self.assertEqual(cal_sched.instructions[0][1].frequency, freq - delta + beta) circ = circ.assign_parameters({beta: delta}) - cal_sched = list(circ.calibrations["custom"].values())[0] - self.assertEqual(float(cal_sched.instructions[0][1].frequency), freq) - self.assertEqual(cal_sched.instructions[1][1].frequency, gamma + delta) + with self.assertWarns(DeprecationWarning): + cal_sched = list(circ.calibrations["custom"].values())[0] + with self.assertWarns(DeprecationWarning): + # instructions triggers conversion to Schedule + self.assertEqual(float(cal_sched.instructions[0][1].frequency), freq) + self.assertEqual(cal_sched.instructions[1][1].frequency, gamma + delta) circ = circ.assign_parameters({gamma: shift - delta}) - cal_sched = list(circ.calibrations["custom"].values())[0] - self.assertEqual(float(cal_sched.instructions[1][1].frequency), shift) + with self.assertWarns(DeprecationWarning): + cal_sched = list(circ.calibrations["custom"].values())[0] + with self.assertWarns(DeprecationWarning): + # instructions triggers conversion to Schedule + self.assertEqual(float(cal_sched.instructions[1][1].frequency), shift) + self.assertEqual(cal_sched.instructions[2][1].phase, phi) - self.assertEqual(cal_sched.instructions[2][1].phase, phi) circ = circ.assign_parameters({phi: phase}) - cal_sched = list(circ.calibrations["custom"].values())[0] - self.assertEqual(float(cal_sched.instructions[2][1].phase), phase) + with self.assertWarns(DeprecationWarning): + cal_sched = list(circ.calibrations["custom"].values())[0] + with self.assertWarns(DeprecationWarning): + # instructions triggers conversion to Schedule + self.assertEqual(float(cal_sched.instructions[2][1].phase), phase) def test_circuit_generation(self): """Test creating a series of circuits parametrically""" diff --git a/test/python/circuit/test_scheduled_circuit.py b/test/python/circuit/test_scheduled_circuit.py index ce5cd8213105..6348d31487bd 100644 --- a/test/python/circuit/test_scheduled_circuit.py +++ b/test/python/circuit/test_scheduled_circuit.py @@ -56,7 +56,8 @@ def test_schedule_circuit_when_backend_tells_dt(self): qc.h(0) # 195[dt] qc.h(1) # 210[dt] - backend = GenericBackendV2(2, calibrate_instructions=True, seed=42) + with self.assertWarns(DeprecationWarning): + backend = GenericBackendV2(2, calibrate_instructions=True, seed=42) sc = transpile(qc, backend, scheduling_method="alap", layout_method="trivial") self.assertEqual(sc.duration, 451095) @@ -355,12 +356,13 @@ def test_convert_duration_to_dt(self): """Test that circuit duration unit conversion is applied only when necessary. Tests fix for bug reported in PR #11782.""" - backend = GenericBackendV2(num_qubits=3, calibrate_instructions=True, seed=42) - schedule_config = ScheduleConfig( - inst_map=backend.target.instruction_schedule_map(), - meas_map=backend.meas_map, - dt=backend.dt, - ) + with self.assertWarns(DeprecationWarning): + backend = GenericBackendV2(num_qubits=3, calibrate_instructions=True, seed=42) + schedule_config = ScheduleConfig( + inst_map=backend.target.instruction_schedule_map(), + meas_map=backend.meas_map, + dt=backend.dt, + ) circ = QuantumCircuit(2) circ.cx(0, 1) diff --git a/test/python/compiler/test_assembler.py b/test/python/compiler/test_assembler.py index c333ce9ace22..33b09bc71848 100644 --- a/test/python/compiler/test_assembler.py +++ b/test/python/compiler/test_assembler.py @@ -71,12 +71,13 @@ def setUp(self): # lo test values self.default_qubit_lo_freq = [5e9 for _ in range(self.num_qubits)] self.default_meas_lo_freq = [6.7e9 for _ in range(self.num_qubits)] - self.user_lo_config_dict = { - pulse.DriveChannel(0): 5.55e9, - pulse.MeasureChannel(0): 6.64e9, - pulse.DriveChannel(3): 4.91e9, - pulse.MeasureChannel(4): 6.1e9, - } + with self.assertWarns(DeprecationWarning): + self.user_lo_config_dict = { + pulse.DriveChannel(0): 5.55e9, + pulse.MeasureChannel(0): 6.64e9, + pulse.DriveChannel(3): 4.91e9, + pulse.MeasureChannel(4): 6.1e9, + } self.user_lo_config = pulse.LoConfig(self.user_lo_config_dict) def test_assemble_single_circuit(self): @@ -541,17 +542,17 @@ def test_pulse_gates_single_circ(self): circ.append(RxGate(theta), [1]) circ = circ.assign_parameters({theta: 3.14}) - with pulse.build() as custom_h_schedule: - pulse.play(pulse.library.Drag(50, 0.15, 4, 2), pulse.DriveChannel(0)) + with self.assertWarns(DeprecationWarning): + with pulse.build() as custom_h_schedule: + pulse.play(pulse.library.Drag(50, 0.15, 4, 2), pulse.DriveChannel(0)) - with pulse.build() as x180: - pulse.play(pulse.library.Gaussian(50, 0.2, 5), pulse.DriveChannel(1)) + with pulse.build() as x180: + pulse.play(pulse.library.Gaussian(50, 0.2, 5), pulse.DriveChannel(1)) - circ.add_calibration("h", [0], custom_h_schedule) - circ.add_calibration(RxGate(3.14), [0], x180) - circ.add_calibration(RxGate(3.14), [1], x180) + circ.add_calibration("h", [0], custom_h_schedule) + circ.add_calibration(RxGate(3.14), [0], x180) + circ.add_calibration(RxGate(3.14), [1], x180) - with self.assertWarns(DeprecationWarning): qobj = assemble(circ, FakeOpenPulse2Q()) # Only one circuit, so everything is stored at the job level cals = qobj.config.calibrations @@ -568,31 +569,33 @@ def test_custom_pulse_gates_single_circ(self): circ = QuantumCircuit(2) circ.h(0) - with pulse.build() as custom_h_schedule: - pulse.play(pulse.library.Triangle(50, 0.1, 0.2), pulse.DriveChannel(0)) + with self.assertWarns(DeprecationWarning): + with pulse.build() as custom_h_schedule: + pulse.play(pulse.library.Triangle(50, 0.1, 0.2), pulse.DriveChannel(0)) - circ.add_calibration("h", [0], custom_h_schedule) + circ.add_calibration("h", [0], custom_h_schedule) - with self.assertWarns(DeprecationWarning): qobj = assemble(circ, FakeOpenPulse2Q()) lib = qobj.config.pulse_library self.assertEqual(len(lib), 1) - np.testing.assert_almost_equal( - lib[0].samples, pulse.library.Triangle(50, 0.1, 0.2).get_waveform().samples - ) + with self.assertWarns(DeprecationWarning): + np.testing.assert_almost_equal( + lib[0].samples, pulse.library.Triangle(50, 0.1, 0.2).get_waveform().samples + ) def test_pulse_gates_with_parameteric_pulses(self): """Test that pulse gates are assembled efficiently for backends that enable parametric pulses. """ - with pulse.build() as custom_h_schedule: - pulse.play(pulse.library.Drag(50, 0.15, 4, 2), pulse.DriveChannel(0)) + with self.assertWarns(DeprecationWarning): + with pulse.build() as custom_h_schedule: + pulse.play(pulse.library.Drag(50, 0.15, 4, 2), pulse.DriveChannel(0)) circ = QuantumCircuit(2) circ.h(0) - circ.add_calibration("h", [0], custom_h_schedule) with self.assertWarns(DeprecationWarning): + circ.add_calibration("h", [0], custom_h_schedule) backend = FakeOpenPulse2Q() backend.configuration().parametric_pulses = ["drag"] with self.assertWarns(DeprecationWarning): @@ -602,14 +605,16 @@ def test_pulse_gates_with_parameteric_pulses(self): def test_pulse_gates_multiple_circuits(self): """Test one circuit with cals and another without.""" - with pulse.build() as dummy_sched: - pulse.play(pulse.library.Drag(50, 0.15, 4, 2), pulse.DriveChannel(0)) + with self.assertWarns(DeprecationWarning): + with pulse.build() as dummy_sched: + pulse.play(pulse.library.Drag(50, 0.15, 4, 2), pulse.DriveChannel(0)) circ = QuantumCircuit(2) circ.h(0) circ.append(RxGate(3.14), [1]) - circ.add_calibration("h", [0], dummy_sched) - circ.add_calibration(RxGate(3.14), [1], dummy_sched) + with self.assertWarns(DeprecationWarning): + circ.add_calibration("h", [0], dummy_sched) + circ.add_calibration(RxGate(3.14), [1], dummy_sched) circ2 = QuantumCircuit(2) circ2.h(0) @@ -623,18 +628,21 @@ def test_pulse_gates_multiple_circuits(self): def test_pulse_gates_common_cals(self): """Test that common calibrations are added at the top level.""" - with pulse.build() as dummy_sched: - pulse.play(pulse.library.Drag(50, 0.15, 4, 2), pulse.DriveChannel(0)) + with self.assertWarns(DeprecationWarning): + with pulse.build() as dummy_sched: + pulse.play(pulse.library.Drag(50, 0.15, 4, 2), pulse.DriveChannel(0)) circ = QuantumCircuit(2) circ.h(0) circ.append(RxGate(3.14), [1]) - circ.add_calibration("h", [0], dummy_sched) - circ.add_calibration(RxGate(3.14), [1], dummy_sched) + with self.assertWarns(DeprecationWarning): + circ.add_calibration("h", [0], dummy_sched) + circ.add_calibration(RxGate(3.14), [1], dummy_sched) circ2 = QuantumCircuit(2) circ2.h(0) - circ2.add_calibration(RxGate(3.14), [1], dummy_sched) + with self.assertWarns(DeprecationWarning): + circ2.add_calibration(RxGate(3.14), [1], dummy_sched) with self.assertWarns(DeprecationWarning): qobj = assemble([circ, circ2], FakeOpenPulse2Q()) @@ -661,9 +669,9 @@ def test_pulse_gates_delay_only(self): """Test that a single delay gate is translated to an instruction.""" circ = QuantumCircuit(2) circ.append(Gate("test", 1, []), [0]) - test_sched = pulse.Delay(64, DriveChannel(0)) + pulse.Delay(160, DriveChannel(0)) - circ.add_calibration("test", [0], test_sched) with self.assertWarns(DeprecationWarning): + test_sched = pulse.Delay(64, DriveChannel(0)) + pulse.Delay(160, DriveChannel(0)) + circ.add_calibration("test", [0], test_sched) qobj = assemble(circ, FakeOpenPulse2Q()) self.assertEqual(len(qobj.config.calibrations.gates[0].instructions), 2) self.assertEqual( @@ -812,12 +820,13 @@ def test_assemble_single_circ_multi_lo_config(self): """Test assembling a single circuit, with multiple experiment level lo configs (frequency sweep). """ - user_lo_config_dict2 = { - pulse.DriveChannel(1): 5.55e9, - pulse.MeasureChannel(1): 6.64e9, - pulse.DriveChannel(4): 4.91e9, - pulse.MeasureChannel(3): 6.1e9, - } + with self.assertWarns(DeprecationWarning): + user_lo_config_dict2 = { + pulse.DriveChannel(1): 5.55e9, + pulse.MeasureChannel(1): 6.64e9, + pulse.DriveChannel(4): 4.91e9, + pulse.MeasureChannel(3): 6.1e9, + } user_lo_config2 = pulse.LoConfig(user_lo_config_dict2) with self.assertWarns(DeprecationWarning): qobj = assemble( @@ -844,12 +853,13 @@ def test_assemble_single_circ_multi_lo_config(self): def test_assemble_multi_circ_multi_lo_config(self): """Test assembling circuits, with the same number of experiment level lo configs (n:n setup).""" - user_lo_config_dict2 = { - pulse.DriveChannel(1): 5.55e9, - pulse.MeasureChannel(1): 6.64e9, - pulse.DriveChannel(4): 4.91e9, - pulse.MeasureChannel(3): 6.1e9, - } + with self.assertWarns(DeprecationWarning): + user_lo_config_dict2 = { + pulse.DriveChannel(1): 5.55e9, + pulse.MeasureChannel(1): 6.64e9, + pulse.DriveChannel(4): 4.91e9, + pulse.MeasureChannel(3): 6.1e9, + } user_lo_config2 = pulse.LoConfig(user_lo_config_dict2) with self.assertWarns(DeprecationWarning): qobj = assemble( @@ -908,18 +918,19 @@ def test_assemble_circ_lo_config_errors(self): some are missing or if default values are not provided. Also check that experiment level lo range is validated.""" # no defaults, but have drive/meas experiment level los for each qubit (no error) - full_lo_config_dict = { - pulse.DriveChannel(0): 4.85e9, - pulse.DriveChannel(1): 4.9e9, - pulse.DriveChannel(2): 4.95e9, - pulse.DriveChannel(3): 5e9, - pulse.DriveChannel(4): 5.05e9, - pulse.MeasureChannel(0): 6.8e9, - pulse.MeasureChannel(1): 6.85e9, - pulse.MeasureChannel(2): 6.9e9, - pulse.MeasureChannel(3): 6.95e9, - pulse.MeasureChannel(4): 7e9, - } + with self.assertWarns(DeprecationWarning): + full_lo_config_dict = { + pulse.DriveChannel(0): 4.85e9, + pulse.DriveChannel(1): 4.9e9, + pulse.DriveChannel(2): 4.95e9, + pulse.DriveChannel(3): 5e9, + pulse.DriveChannel(4): 5.05e9, + pulse.MeasureChannel(0): 6.8e9, + pulse.MeasureChannel(1): 6.85e9, + pulse.MeasureChannel(2): 6.9e9, + pulse.MeasureChannel(3): 6.95e9, + pulse.MeasureChannel(4): 7e9, + } with self.assertWarns(DeprecationWarning): qobj = assemble(self.circ, self.backend, schedule_los=full_lo_config_dict) @@ -930,15 +941,15 @@ def test_assemble_circ_lo_config_errors(self): # no defaults and missing experiment level drive lo raises missing_drive_lo_config_dict = copy.deepcopy(full_lo_config_dict) - missing_drive_lo_config_dict.pop(pulse.DriveChannel(0)) with self.assertWarns(DeprecationWarning): + missing_drive_lo_config_dict.pop(pulse.DriveChannel(0)) with self.assertRaises(QiskitError): qobj = assemble(self.circ, self.backend, schedule_los=missing_drive_lo_config_dict) # no defaults and missing experiment level meas lo raises missing_meas_lo_config_dict = copy.deepcopy(full_lo_config_dict) - missing_meas_lo_config_dict.pop(pulse.MeasureChannel(0)) with self.assertWarns(DeprecationWarning): + missing_meas_lo_config_dict.pop(pulse.MeasureChannel(0)) with self.assertRaises(QiskitError): qobj = assemble(self.circ, self.backend, schedule_los=missing_meas_lo_config_dict) @@ -948,8 +959,8 @@ def test_assemble_circ_lo_config_errors(self): meas_lo_range = [[freq - 5e6, freq + 5e6] for freq in lo_values[5:]] # out of range drive lo - full_lo_config_dict[pulse.DriveChannel(0)] -= 5.5e6 with self.assertWarns(DeprecationWarning): + full_lo_config_dict[pulse.DriveChannel(0)] -= 5.5e6 with self.assertRaises(QiskitError): qobj = assemble( self.circ, @@ -957,11 +968,11 @@ def test_assemble_circ_lo_config_errors(self): qubit_lo_range=qubit_lo_range, schedule_los=full_lo_config_dict, ) - full_lo_config_dict[pulse.DriveChannel(0)] += 5.5e6 # reset drive value + full_lo_config_dict[pulse.DriveChannel(0)] += 5.5e6 # reset drive value - # out of range meas lo - full_lo_config_dict[pulse.MeasureChannel(0)] += 5.5e6 with self.assertWarns(DeprecationWarning): + # out of range meas lo + full_lo_config_dict[pulse.MeasureChannel(0)] += 5.5e6 with self.assertRaises(QiskitError): qobj = assemble( self.circ, @@ -980,19 +991,20 @@ def setUp(self): self.backend = FakeOpenPulse2Q() self.backend_config = self.backend.configuration() - test_pulse = pulse.Waveform( - samples=np.array([0.02739068, 0.05, 0.05, 0.05, 0.02739068], dtype=np.complex128), - name="pulse0", - ) - - self.schedule = pulse.Schedule(name="fake_experiment") - self.schedule = self.schedule.insert(0, Play(test_pulse, self.backend_config.drive(0))) - for i in range(self.backend_config.n_qubits): - self.schedule = self.schedule.insert( - 5, Acquire(5, self.backend_config.acquire(i), MemorySlot(i)) + with self.assertWarns(DeprecationWarning): + test_pulse = pulse.Waveform( + samples=np.array([0.02739068, 0.05, 0.05, 0.05, 0.02739068], dtype=np.complex128), + name="pulse0", ) - self.user_lo_config_dict = {self.backend_config.drive(0): 4.91e9} + self.schedule = pulse.Schedule(name="fake_experiment") + self.schedule = self.schedule.insert(0, Play(test_pulse, self.backend_config.drive(0))) + for i in range(self.backend_config.n_qubits): + self.schedule = self.schedule.insert( + 5, Acquire(5, self.backend_config.acquire(i), MemorySlot(i)) + ) + + self.user_lo_config_dict = {self.backend_config.drive(0): 4.91e9} self.user_lo_config = pulse.LoConfig(self.user_lo_config_dict) self.default_qubit_lo_freq = [4.9e9, 5.0e9] @@ -1020,16 +1032,18 @@ def test_assemble_adds_schedule_metadata_to_experiment_header(self): def test_assemble_sample_pulse(self): """Test that the pulse lib and qobj instruction can be paired up.""" - schedule = pulse.Schedule() - schedule += pulse.Play( - pulse.Waveform([0.1] * 16, name="test0"), pulse.DriveChannel(0), name="test1" - ) - schedule += pulse.Play( - pulse.Waveform([0.1] * 16, name="test1"), pulse.DriveChannel(0), name="test2" - ) - schedule += pulse.Play( - pulse.Waveform([0.5] * 16, name="test0"), pulse.DriveChannel(0), name="test1" - ) + with self.assertWarns(DeprecationWarning): + schedule = pulse.Schedule() + schedule += pulse.Play( + pulse.Waveform([0.1] * 16, name="test0"), pulse.DriveChannel(0), name="test1" + ) + schedule += pulse.Play( + pulse.Waveform([0.1] * 16, name="test1"), pulse.DriveChannel(0), name="test2" + ) + schedule += pulse.Play( + pulse.Waveform([0.5] * 16, name="test0"), pulse.DriveChannel(0), name="test1" + ) + with self.assertWarns(DeprecationWarning): qobj = assemble( schedule, @@ -1172,9 +1186,10 @@ def test_assemble_multi_schedules_with_wrong_number_of_multi_lo_configs(self): def test_assemble_meas_map(self): """Test assembling a single schedule, no lo config.""" - schedule = Schedule(name="fake_experiment") - schedule = schedule.insert(5, Acquire(5, AcquireChannel(0), MemorySlot(0))) - schedule = schedule.insert(5, Acquire(5, AcquireChannel(1), MemorySlot(1))) + with self.assertWarns(DeprecationWarning): + schedule = Schedule(name="fake_experiment") + schedule = schedule.insert(5, Acquire(5, AcquireChannel(0), MemorySlot(0))) + schedule = schedule.insert(5, Acquire(5, AcquireChannel(1), MemorySlot(1))) with self.assertWarns(DeprecationWarning): qobj = assemble( @@ -1199,9 +1214,10 @@ def test_assemble_memory_slots(self): n_memoryslots = 10 # single acquisition - schedule = Acquire( - 5, self.backend_config.acquire(0), mem_slot=pulse.MemorySlot(n_memoryslots - 1) - ) + with self.assertWarns(DeprecationWarning): + schedule = Acquire( + 5, self.backend_config.acquire(0), mem_slot=pulse.MemorySlot(n_memoryslots - 1) + ) with self.assertWarns(DeprecationWarning): qobj = assemble( @@ -1216,15 +1232,17 @@ def test_assemble_memory_slots(self): self.assertEqual(qobj.experiments[0].header.memory_slots, n_memoryslots) # multiple acquisition - schedule = Acquire( - 5, self.backend_config.acquire(0), mem_slot=pulse.MemorySlot(n_memoryslots - 1) - ) - schedule = schedule.insert( - 10, - Acquire( + with self.assertWarns(DeprecationWarning): + schedule = Acquire( 5, self.backend_config.acquire(0), mem_slot=pulse.MemorySlot(n_memoryslots - 1) - ), - ) + ) + schedule = schedule.insert( + 10, + Acquire( + 5, self.backend_config.acquire(0), mem_slot=pulse.MemorySlot(n_memoryslots - 1) + ), + ) + with self.assertWarns(DeprecationWarning): qobj = assemble( schedule, @@ -1242,11 +1260,12 @@ def test_assemble_memory_slots_for_schedules(self): n_memoryslots = [10, 5, 7] schedules = [] - for n_memoryslot in n_memoryslots: - schedule = Acquire( - 5, self.backend_config.acquire(0), mem_slot=pulse.MemorySlot(n_memoryslot - 1) - ) - schedules.append(schedule) + with self.assertWarns(DeprecationWarning): + for n_memoryslot in n_memoryslots: + schedule = Acquire( + 5, self.backend_config.acquire(0), mem_slot=pulse.MemorySlot(n_memoryslot - 1) + ) + schedules.append(schedule) with self.assertWarns(DeprecationWarning): qobj = assemble( @@ -1263,13 +1282,14 @@ def test_assemble_memory_slots_for_schedules(self): def test_pulse_name_conflicts(self): """Test that pulse name conflicts can be resolved.""" - name_conflict_pulse = pulse.Waveform( - samples=np.array([0.02, 0.05, 0.05, 0.05, 0.02], dtype=np.complex128), name="pulse0" - ) + with self.assertWarns(DeprecationWarning): + name_conflict_pulse = pulse.Waveform( + samples=np.array([0.02, 0.05, 0.05, 0.05, 0.02], dtype=np.complex128), name="pulse0" + ) - self.schedule = self.schedule.insert( - 1, Play(name_conflict_pulse, self.backend_config.drive(1)) - ) + self.schedule = self.schedule.insert( + 1, Play(name_conflict_pulse, self.backend_config.drive(1)) + ) with self.assertWarns(DeprecationWarning): qobj = assemble( @@ -1287,15 +1307,19 @@ def test_pulse_name_conflicts_in_other_schedule(self): """Test two pulses with the same name in different schedule can be resolved.""" with self.assertWarns(DeprecationWarning): backend = Fake27QPulseV1() - defaults = backend.defaults() + with self.assertWarns(DeprecationWarning): + defaults = backend.defaults() schedules = [] - ch_d0 = pulse.DriveChannel(0) - for amp in (0.1, 0.2): - sched = Schedule() - sched += Play(pulse.Gaussian(duration=100, amp=amp, sigma=30, name="my_pulse"), ch_d0) - sched += measure(qubits=[0], backend=backend) << 100 - schedules.append(sched) + with self.assertWarns(DeprecationWarning): + ch_d0 = pulse.DriveChannel(0) + for amp in (0.1, 0.2): + sched = Schedule() + sched += Play( + pulse.Gaussian(duration=100, amp=amp, sigma=30, name="my_pulse"), ch_d0 + ) + sched += measure(qubits=[0], backend=backend) << 100 + schedules.append(sched) with self.assertWarns(DeprecationWarning): qobj = assemble( @@ -1309,8 +1333,9 @@ def test_pulse_name_conflicts_in_other_schedule(self): def test_assemble_with_delay(self): """Test that delay instruction is not ignored in assembly.""" - delay_schedule = pulse.Delay(10, self.backend_config.drive(0)) - delay_schedule += self.schedule + with self.assertWarns(DeprecationWarning): + delay_schedule = pulse.Delay(10, self.backend_config.drive(0)) + delay_schedule += self.schedule with self.assertWarns(DeprecationWarning): delay_qobj = assemble(delay_schedule, self.backend) @@ -1323,20 +1348,23 @@ def test_delay_removed_on_acq_ch(self): """Test that delay instructions on acquire channels are skipped on assembly with times shifted properly. """ - delay0 = pulse.Delay(5, self.backend_config.acquire(0)) - delay1 = pulse.Delay(7, self.backend_config.acquire(1)) + with self.assertWarns(DeprecationWarning): + delay0 = pulse.Delay(5, self.backend_config.acquire(0)) + delay1 = pulse.Delay(7, self.backend_config.acquire(1)) sched0 = delay0 - sched0 += self.schedule # includes ``Acquire`` instr - sched0 += delay1 + with self.assertWarns(DeprecationWarning): + sched0 += self.schedule # includes ``Acquire`` instr + sched0 += delay1 - sched1 = self.schedule # includes ``Acquire`` instr - sched1 += delay0 - sched1 += delay1 + with self.assertWarns(DeprecationWarning): + sched1 = self.schedule # includes ``Acquire`` instr + sched1 += delay0 + sched1 += delay1 - sched2 = delay0 - sched2 += delay1 - sched2 += self.schedule # includes ``Acquire`` instr + sched2 = delay0 + sched2 += delay1 + sched2 += self.schedule # includes ``Acquire`` instr with self.assertWarns(DeprecationWarning): delay_qobj = assemble([sched0, sched1, sched2], self.backend) @@ -1379,21 +1407,26 @@ def test_assemble_parametric(self): """Test that parametric pulses can be assembled properly into a PulseQobj.""" amp = [0.5, 0.6, 1, 0.2] angle = [np.pi / 2, 0.6, 0, 0] - sched = pulse.Schedule(name="test_parametric") - sched += Play( - pulse.Gaussian(duration=25, sigma=4, amp=amp[0], angle=angle[0]), DriveChannel(0) - ) - sched += Play( - pulse.Drag(duration=25, amp=amp[1], angle=angle[1], sigma=7.8, beta=4), DriveChannel(1) - ) - sched += Play(pulse.Constant(duration=25, amp=amp[2], angle=angle[2]), DriveChannel(2)) - sched += ( - Play( - pulse.GaussianSquare(duration=150, amp=amp[3], angle=angle[3], sigma=8, width=140), - MeasureChannel(0), + with self.assertWarns(DeprecationWarning): + sched = pulse.Schedule(name="test_parametric") + sched += Play( + pulse.Gaussian(duration=25, sigma=4, amp=amp[0], angle=angle[0]), DriveChannel(0) ) - << sched.duration - ) + sched += Play( + pulse.Drag(duration=25, amp=amp[1], angle=angle[1], sigma=7.8, beta=4), + DriveChannel(1), + ) + sched += Play(pulse.Constant(duration=25, amp=amp[2], angle=angle[2]), DriveChannel(2)) + sched += ( + Play( + pulse.GaussianSquare( + duration=150, amp=amp[3], angle=angle[3], sigma=8, width=140 + ), + MeasureChannel(0), + ) + << sched.duration + ) + with self.assertWarns(DeprecationWarning): backend = FakeOpenPulse3Q() backend.configuration().parametric_pulses = [ @@ -1436,11 +1469,12 @@ def test_assemble_parametric_unsupported(self): """Test that parametric pulses are translated to Waveform if they're not supported by the backend during assemble time. """ - sched = pulse.Schedule(name="test_parametric_to_sample_pulse") - sched += Play( - pulse.Drag(duration=25, amp=0.5, angle=-0.3, sigma=7.8, beta=4), DriveChannel(1) - ) - sched += Play(pulse.Constant(duration=25, amp=1), DriveChannel(2)) + with self.assertWarns(DeprecationWarning): + sched = pulse.Schedule(name="test_parametric_to_sample_pulse") + sched += Play( + pulse.Drag(duration=25, amp=0.5, angle=-0.3, sigma=7.8, beta=4), DriveChannel(1) + ) + sched += Play(pulse.Constant(duration=25, amp=1), DriveChannel(2)) with self.assertWarns(DeprecationWarning): backend = FakeOpenPulse3Q() @@ -1461,12 +1495,12 @@ def test_assemble_parametric_pulse_kwarg_with_backend_setting(self): qc = QuantumCircuit(1, 1) qc.x(0) qc.measure(0, 0) - with pulse.build(backend, name="x") as x_q0: - pulse.play(pulse.Gaussian(duration=128, amp=0.1, sigma=16), pulse.drive_channel(0)) + with self.assertWarns(DeprecationWarning): + with pulse.build(backend, name="x") as x_q0: + pulse.play(pulse.Gaussian(duration=128, amp=0.1, sigma=16), pulse.drive_channel(0)) - qc.add_calibration("x", (0,), x_q0) + qc.add_calibration("x", (0,), x_q0) - with self.assertWarns(DeprecationWarning): qobj = assemble(qc, backend, parametric_pulses=["gaussian"]) self.assertEqual(qobj.config.parametric_pulses, ["gaussian"]) @@ -1478,12 +1512,12 @@ def test_assemble_parametric_pulse_kwarg_empty_list_with_backend_setting(self): qc = QuantumCircuit(1, 1) qc.x(0) qc.measure(0, 0) - with pulse.build(backend, name="x") as x_q0: - pulse.play(pulse.Gaussian(duration=128, amp=0.1, sigma=16), pulse.drive_channel(0)) - - qc.add_calibration("x", (0,), x_q0) + with self.assertWarns(DeprecationWarning): + with pulse.build(backend, name="x") as x_q0: + pulse.play(pulse.Gaussian(duration=128, amp=0.1, sigma=16), pulse.drive_channel(0)) with self.assertWarns(DeprecationWarning): + qc.add_calibration("x", (0,), x_q0) qobj = assemble(qc, backend, parametric_pulses=[]) self.assertEqual(qobj.config.parametric_pulses, []) @@ -1582,13 +1616,14 @@ def test_assemble_with_individual_discriminators(self): disc_one = Discriminator("disc_one", test_params=True) disc_two = Discriminator("disc_two", test_params=False) - schedule = Schedule() - schedule = schedule.append( - Acquire(5, AcquireChannel(0), MemorySlot(0), discriminator=disc_one), - ) - schedule = schedule.append( - Acquire(5, AcquireChannel(1), MemorySlot(1), discriminator=disc_two), - ) + with self.assertWarns(DeprecationWarning): + schedule = Schedule() + schedule = schedule.append( + Acquire(5, AcquireChannel(0), MemorySlot(0), discriminator=disc_one), + ) + schedule = schedule.append( + Acquire(5, AcquireChannel(1), MemorySlot(1), discriminator=disc_two), + ) with self.assertWarns(DeprecationWarning): qobj = assemble( @@ -1609,13 +1644,14 @@ def test_assemble_with_single_discriminators(self): """Test that assembly works with both a single discriminator.""" disc_one = Discriminator("disc_one", test_params=True) - schedule = Schedule() - schedule = schedule.append( - Acquire(5, AcquireChannel(0), MemorySlot(0), discriminator=disc_one), - ) - schedule = schedule.append( - Acquire(5, AcquireChannel(1), MemorySlot(1)), - ) + with self.assertWarns(DeprecationWarning): + schedule = Schedule() + schedule = schedule.append( + Acquire(5, AcquireChannel(0), MemorySlot(0), discriminator=disc_one), + ) + schedule = schedule.append( + Acquire(5, AcquireChannel(1), MemorySlot(1)), + ) with self.assertWarns(DeprecationWarning): qobj = assemble( @@ -1636,10 +1672,11 @@ def test_assemble_with_unequal_discriminators(self): disc_one = Discriminator("disc_one", test_params=True) disc_two = Discriminator("disc_two", test_params=False) - schedule = Schedule() - schedule += Acquire(5, AcquireChannel(0), MemorySlot(0), discriminator=disc_one) - schedule += Acquire(5, AcquireChannel(1), MemorySlot(1), discriminator=disc_two) - schedule += Acquire(5, AcquireChannel(2), MemorySlot(2)) + with self.assertWarns(DeprecationWarning): + schedule = Schedule() + schedule += Acquire(5, AcquireChannel(0), MemorySlot(0), discriminator=disc_one) + schedule += Acquire(5, AcquireChannel(1), MemorySlot(1), discriminator=disc_two) + schedule += Acquire(5, AcquireChannel(2), MemorySlot(2)) with self.assertRaises(QiskitError), self.assertWarns(DeprecationWarning): assemble( @@ -1654,13 +1691,14 @@ def test_assemble_with_individual_kernels(self): disc_one = Kernel("disc_one", test_params=True) disc_two = Kernel("disc_two", test_params=False) - schedule = Schedule() - schedule = schedule.append( - Acquire(5, AcquireChannel(0), MemorySlot(0), kernel=disc_one), - ) - schedule = schedule.append( - Acquire(5, AcquireChannel(1), MemorySlot(1), kernel=disc_two), - ) + with self.assertWarns(DeprecationWarning): + schedule = Schedule() + schedule = schedule.append( + Acquire(5, AcquireChannel(0), MemorySlot(0), kernel=disc_one), + ) + schedule = schedule.append( + Acquire(5, AcquireChannel(1), MemorySlot(1), kernel=disc_two), + ) with self.assertWarns(DeprecationWarning): qobj = assemble( @@ -1681,13 +1719,14 @@ def test_assemble_with_single_kernels(self): """Test that assembly works with both a single kernel.""" disc_one = Kernel("disc_one", test_params=True) - schedule = Schedule() - schedule = schedule.append( - Acquire(5, AcquireChannel(0), MemorySlot(0), kernel=disc_one), - ) - schedule = schedule.append( - Acquire(5, AcquireChannel(1), MemorySlot(1)), - ) + with self.assertWarns(DeprecationWarning): + schedule = Schedule() + schedule = schedule.append( + Acquire(5, AcquireChannel(0), MemorySlot(0), kernel=disc_one), + ) + schedule = schedule.append( + Acquire(5, AcquireChannel(1), MemorySlot(1)), + ) with self.assertWarns(DeprecationWarning): qobj = assemble( @@ -1708,10 +1747,11 @@ def test_assemble_with_unequal_kernels(self): disc_one = Kernel("disc_one", test_params=True) disc_two = Kernel("disc_two", test_params=False) - schedule = Schedule() - schedule += Acquire(5, AcquireChannel(0), MemorySlot(0), kernel=disc_one) - schedule += Acquire(5, AcquireChannel(1), MemorySlot(1), kernel=disc_two) - schedule += Acquire(5, AcquireChannel(2), MemorySlot(2)) + with self.assertWarns(DeprecationWarning): + schedule = Schedule() + schedule += Acquire(5, AcquireChannel(0), MemorySlot(0), kernel=disc_one) + schedule += Acquire(5, AcquireChannel(1), MemorySlot(1), kernel=disc_two) + schedule += Acquire(5, AcquireChannel(2), MemorySlot(2)) with self.assertRaises(QiskitError), self.assertWarns(DeprecationWarning): assemble( @@ -1723,19 +1763,20 @@ def test_assemble_with_unequal_kernels(self): def test_assemble_single_instruction(self): """Test assembling schedules, no lo config.""" - inst = pulse.Play(pulse.Constant(100, 1.0), pulse.DriveChannel(0)) with self.assertWarns(DeprecationWarning): + inst = pulse.Play(pulse.Constant(100, 1.0), pulse.DriveChannel(0)) self.assertIsInstance(assemble(inst, self.backend), PulseQobj) def test_assemble_overlapping_time(self): """Test that assembly errors when qubits are measured in overlapping time.""" - schedule = Schedule() - schedule = schedule.append( - Acquire(5, AcquireChannel(0), MemorySlot(0)), - ) - schedule = schedule.append( - Acquire(5, AcquireChannel(1), MemorySlot(1)) << 1, - ) + with self.assertWarns(DeprecationWarning): + schedule = Schedule() + schedule = schedule.append( + Acquire(5, AcquireChannel(0), MemorySlot(0)), + ) + schedule = schedule.append( + Acquire(5, AcquireChannel(1), MemorySlot(1)) << 1, + ) with self.assertRaises(QiskitError): with self.assertWarns(DeprecationWarning): assemble( @@ -1748,11 +1789,12 @@ def test_assemble_overlapping_time(self): def test_assemble_meas_map_vs_insts(self): """Test that assembly errors when the qubits are measured in overlapping time and qubits are not in the first meas_map list.""" - schedule = Schedule() - schedule += Acquire(5, AcquireChannel(0), MemorySlot(0)) - schedule += Acquire(5, AcquireChannel(1), MemorySlot(1)) - schedule += Acquire(5, AcquireChannel(2), MemorySlot(2)) << 2 - schedule += Acquire(5, AcquireChannel(3), MemorySlot(3)) << 2 + with self.assertWarns(DeprecationWarning): + schedule = Schedule() + schedule += Acquire(5, AcquireChannel(0), MemorySlot(0)) + schedule += Acquire(5, AcquireChannel(1), MemorySlot(1)) + schedule += Acquire(5, AcquireChannel(2), MemorySlot(2)) << 2 + schedule += Acquire(5, AcquireChannel(3), MemorySlot(3)) << 2 with self.assertRaises(QiskitError): with self.assertWarns(DeprecationWarning): @@ -1766,13 +1808,14 @@ def test_assemble_meas_map_vs_insts(self): def test_assemble_non_overlapping_time_single_meas_map(self): """Test that assembly works when qubits are measured in non-overlapping time within the same measurement map list.""" - schedule = Schedule() - schedule = schedule.append( - Acquire(5, AcquireChannel(0), MemorySlot(0)), - ) - schedule = schedule.append( - Acquire(5, AcquireChannel(1), MemorySlot(1)) << 5, - ) + with self.assertWarns(DeprecationWarning): + schedule = Schedule() + schedule = schedule.append( + Acquire(5, AcquireChannel(0), MemorySlot(0)), + ) + schedule = schedule.append( + Acquire(5, AcquireChannel(1), MemorySlot(1)) << 5, + ) with self.assertWarns(DeprecationWarning): qobj = assemble( schedule, @@ -1784,13 +1827,14 @@ def test_assemble_non_overlapping_time_single_meas_map(self): def test_assemble_disjoint_time(self): """Test that assembly works when qubits are in disjoint meas map sets.""" - schedule = Schedule() - schedule = schedule.append( - Acquire(5, AcquireChannel(0), MemorySlot(0)), - ) - schedule = schedule.append( - Acquire(5, AcquireChannel(1), MemorySlot(1)) << 1, - ) + with self.assertWarns(DeprecationWarning): + schedule = Schedule() + schedule = schedule.append( + Acquire(5, AcquireChannel(0), MemorySlot(0)), + ) + schedule = schedule.append( + Acquire(5, AcquireChannel(1), MemorySlot(1)) << 1, + ) with self.assertWarns(DeprecationWarning): qobj = assemble( schedule, @@ -1803,16 +1847,17 @@ def test_assemble_disjoint_time(self): def test_assemble_valid_qubits(self): """Test that assembly works when qubits that are in the measurement map is measured.""" - schedule = Schedule() - schedule = schedule.append( - Acquire(5, AcquireChannel(1), MemorySlot(1)), - ) - schedule = schedule.append( - Acquire(5, AcquireChannel(2), MemorySlot(2)), - ) - schedule = schedule.append( - Acquire(5, AcquireChannel(3), MemorySlot(3)), - ) + with self.assertWarns(DeprecationWarning): + schedule = Schedule() + schedule = schedule.append( + Acquire(5, AcquireChannel(1), MemorySlot(1)), + ) + schedule = schedule.append( + Acquire(5, AcquireChannel(2), MemorySlot(2)), + ) + schedule = schedule.append( + Acquire(5, AcquireChannel(3), MemorySlot(3)), + ) with self.assertWarns(DeprecationWarning): qobj = assemble( schedule, @@ -1828,22 +1873,23 @@ class TestPulseAssemblerMissingKwargs(QiskitTestCase): def setUp(self): super().setUp() - self.schedule = pulse.Schedule(name="fake_experiment") - with self.assertWarns(DeprecationWarning): + self.schedule = pulse.Schedule(name="fake_experiment") self.backend = FakeOpenPulse2Q() + self.config = self.backend.configuration() self.defaults = self.backend.defaults() self.qubit_lo_freq = list(self.defaults.qubit_freq_est) self.meas_lo_freq = list(self.defaults.meas_freq_est) self.qubit_lo_range = self.config.qubit_lo_range self.meas_lo_range = self.config.meas_lo_range - self.schedule_los = { - pulse.DriveChannel(0): self.qubit_lo_freq[0], - pulse.DriveChannel(1): self.qubit_lo_freq[1], - pulse.MeasureChannel(0): self.meas_lo_freq[0], - pulse.MeasureChannel(1): self.meas_lo_freq[1], - } + with self.assertWarns(DeprecationWarning): + self.schedule_los = { + pulse.DriveChannel(0): self.qubit_lo_freq[0], + pulse.DriveChannel(1): self.qubit_lo_freq[1], + pulse.MeasureChannel(0): self.meas_lo_freq[0], + pulse.MeasureChannel(1): self.meas_lo_freq[1], + } self.meas_map = self.config.meas_map self.memory_slots = self.config.n_qubits @@ -1995,14 +2041,15 @@ def test_single_and_deprecated_acquire_styles(self): """Test that acquires are identically combined with Acquires that take a single channel.""" with self.assertWarns(DeprecationWarning): backend = FakeOpenPulse2Q() - new_style_schedule = Schedule() + new_style_schedule = Schedule() acq_dur = 1200 - for i in range(2): - new_style_schedule += Acquire(acq_dur, AcquireChannel(i), MemorySlot(i)) + with self.assertWarns(DeprecationWarning): + for i in range(2): + new_style_schedule += Acquire(acq_dur, AcquireChannel(i), MemorySlot(i)) - deprecated_style_schedule = Schedule() - for i in range(2): - deprecated_style_schedule += Acquire(1200, AcquireChannel(i), MemorySlot(i)) + deprecated_style_schedule = Schedule() + for i in range(2): + deprecated_style_schedule += Acquire(1200, AcquireChannel(i), MemorySlot(i)) # The Qobj IDs will be different with self.assertWarns(DeprecationWarning): diff --git a/test/python/compiler/test_disassembler.py b/test/python/compiler/test_disassembler.py index 0525b54e2107..805fac1178a1 100644 --- a/test/python/compiler/test_disassembler.py +++ b/test/python/compiler/test_disassembler.py @@ -319,8 +319,9 @@ def assertCircuitCalibrationsEqual(self, in_circuits, out_circuits): """Verify circuit calibrations are equivalent pre-assembly and post-disassembly""" self.assertEqual(len(in_circuits), len(out_circuits)) for in_qc, out_qc in zip(in_circuits, out_circuits): - in_cals = in_qc.calibrations - out_cals = out_qc.calibrations + with self.assertWarns(DeprecationWarning): + in_cals = in_qc.calibrations + out_cals = out_qc.calibrations self.assertEqual(in_cals.keys(), out_cals.keys()) for gate_name in in_cals: self.assertEqual(in_cals[gate_name].keys(), out_cals[gate_name].keys()) @@ -337,31 +338,33 @@ def test_single_circuit_calibrations(self): qc.rx(theta, 1) qc = qc.assign_parameters({theta: np.pi}) - with pulse.build() as h_sched: - pulse.play(pulse.library.Drag(1, 0.15, 4, 2), pulse.DriveChannel(0)) + with self.assertWarns(DeprecationWarning): + with pulse.build() as h_sched: + pulse.play(pulse.library.Drag(1, 0.15, 4, 2), pulse.DriveChannel(0)) - with pulse.build() as x180: - pulse.play(pulse.library.Gaussian(1, 0.2, 5), pulse.DriveChannel(0)) + with pulse.build() as x180: + pulse.play(pulse.library.Gaussian(1, 0.2, 5), pulse.DriveChannel(0)) - qc.add_calibration("h", [0], h_sched) - qc.add_calibration(RXGate(np.pi), [0], x180) + qc.add_calibration("h", [0], h_sched) + qc.add_calibration(RXGate(np.pi), [0], x180) with self.assertWarns(DeprecationWarning): qobj = assemble(qc, FakeOpenPulse2Q()) output_circuits, _, _ = disassemble(qobj) - self.assertCircuitCalibrationsEqual([qc], output_circuits) + self.assertCircuitCalibrationsEqual([qc], output_circuits) def test_parametric_pulse_circuit_calibrations(self): """Test that disassembler parses parametric pulses back to pulse gates.""" - with pulse.build() as h_sched: - pulse.play(pulse.library.Drag(50, 0.15, 4, 2), pulse.DriveChannel(0)) + with self.assertWarns(DeprecationWarning): + with pulse.build() as h_sched: + pulse.play(pulse.library.Drag(50, 0.15, 4, 2), pulse.DriveChannel(0)) qc = QuantumCircuit(2) qc.h(0) - qc.add_calibration("h", [0], h_sched) with self.assertWarns(DeprecationWarning): + qc.add_calibration("h", [0], h_sched) backend = FakeOpenPulse2Q() backend.configuration().parametric_pulses = ["drag"] @@ -369,27 +372,30 @@ def test_parametric_pulse_circuit_calibrations(self): output_circuits, _, _ = disassemble(qobj) out_qc = output_circuits[0] - self.assertCircuitCalibrationsEqual([qc], output_circuits) - self.assertTrue( - all( - qc_sched.instructions == out_qc_sched.instructions - for (_, qc_gate), (_, out_qc_gate) in zip( - qc.calibrations.items(), out_qc.calibrations.items() - ) - for qc_sched, out_qc_sched in zip(qc_gate.values(), out_qc_gate.values()) - ), - ) + with self.assertWarns(DeprecationWarning): + self.assertCircuitCalibrationsEqual([qc], output_circuits) + self.assertTrue( + all( + qc_sched.instructions == out_qc_sched.instructions + for (_, qc_gate), (_, out_qc_gate) in zip( + qc.calibrations.items(), out_qc.calibrations.items() + ) + for qc_sched, out_qc_sched in zip(qc_gate.values(), out_qc_gate.values()) + ), + ) def test_multi_circuit_uncommon_calibrations(self): """Test that disassembler parses uncommon calibrations (stored at QOBJ experiment-level).""" - with pulse.build() as sched: - pulse.play(pulse.library.Drag(50, 0.15, 4, 2), pulse.DriveChannel(0)) + with self.assertWarns(DeprecationWarning): + with pulse.build() as sched: + pulse.play(pulse.library.Drag(50, 0.15, 4, 2), pulse.DriveChannel(0)) qc_0 = QuantumCircuit(2) qc_0.h(0) qc_0.append(RXGate(np.pi), [1]) - qc_0.add_calibration("h", [0], sched) - qc_0.add_calibration(RXGate(np.pi), [1], sched) + with self.assertWarns(DeprecationWarning): + qc_0.add_calibration("h", [0], sched) + qc_0.add_calibration(RXGate(np.pi), [1], sched) qc_1 = QuantumCircuit(2) qc_1.h(0) @@ -399,57 +405,61 @@ def test_multi_circuit_uncommon_calibrations(self): qobj = assemble(circuits, FakeOpenPulse2Q()) output_circuits, _, _ = disassemble(qobj) - self.assertCircuitCalibrationsEqual(circuits, output_circuits) + self.assertCircuitCalibrationsEqual(circuits, output_circuits) def test_multi_circuit_common_calibrations(self): """Test that disassembler parses common calibrations (stored at QOBJ-level).""" - with pulse.build() as sched: - pulse.play(pulse.library.Drag(1, 0.15, 4, 2), pulse.DriveChannel(0)) + with self.assertWarns(DeprecationWarning): + with pulse.build() as sched: + pulse.play(pulse.library.Drag(1, 0.15, 4, 2), pulse.DriveChannel(0)) qc_0 = QuantumCircuit(2) qc_0.h(0) qc_0.append(RXGate(np.pi), [1]) - qc_0.add_calibration("h", [0], sched) - qc_0.add_calibration(RXGate(np.pi), [1], sched) + with self.assertWarns(DeprecationWarning): + qc_0.add_calibration("h", [0], sched) + qc_0.add_calibration(RXGate(np.pi), [1], sched) qc_1 = QuantumCircuit(2) qc_1.h(0) - qc_1.add_calibration(RXGate(np.pi), [1], sched) + with self.assertWarns(DeprecationWarning): + qc_1.add_calibration(RXGate(np.pi), [1], sched) circuits = [qc_0, qc_1] with self.assertWarns(DeprecationWarning): qobj = assemble(circuits, FakeOpenPulse2Q()) output_circuits, _, _ = disassemble(qobj) - self.assertCircuitCalibrationsEqual(circuits, output_circuits) + self.assertCircuitCalibrationsEqual(circuits, output_circuits) def test_single_circuit_delay_calibrations(self): """Test that disassembler parses delay instruction back to delay gate.""" qc = QuantumCircuit(2) qc.append(Gate("test", 1, []), [0]) - test_sched = pulse.Delay(64, pulse.DriveChannel(0)) + pulse.Delay( - 160, pulse.DriveChannel(0) - ) + with self.assertWarns(DeprecationWarning): + test_sched = pulse.Delay(64, pulse.DriveChannel(0)) + pulse.Delay( + 160, pulse.DriveChannel(0) + ) - qc.add_calibration("test", [0], test_sched) + qc.add_calibration("test", [0], test_sched) - with self.assertWarns(DeprecationWarning): qobj = assemble(qc, FakeOpenPulse2Q()) output_circuits, _, _ = disassemble(qobj) - self.assertEqual(len(qc.calibrations), len(output_circuits[0].calibrations)) - self.assertEqual(qc.calibrations.keys(), output_circuits[0].calibrations.keys()) - self.assertTrue( - all( - qc_cal.keys() == out_qc_cal.keys() - for qc_cal, out_qc_cal in zip( - qc.calibrations.values(), output_circuits[0].calibrations.values() + self.assertEqual(len(qc.calibrations), len(output_circuits[0].calibrations)) + self.assertEqual(qc.calibrations.keys(), output_circuits[0].calibrations.keys()) + self.assertTrue( + all( + qc_cal.keys() == out_qc_cal.keys() + for qc_cal, out_qc_cal in zip( + qc.calibrations.values(), output_circuits[0].calibrations.values() + ) ) ) - ) - self.assertEqual( - qc.calibrations["test"][((0,), ())], output_circuits[0].calibrations["test"][((0,), ())] - ) + self.assertEqual( + qc.calibrations["test"][((0,), ())], + output_circuits[0].calibrations["test"][((0,), ())], + ) class TestPulseScheduleDisassembler(QiskitTestCase): @@ -464,19 +474,20 @@ def setUp(self): def test_disassemble_single_schedule(self): """Test disassembling a single schedule.""" - d0 = pulse.DriveChannel(0) - d1 = pulse.DriveChannel(1) - with pulse.build(self.backend) as sched: - with pulse.align_right(): - pulse.play(pulse.library.Constant(10, 1.0), d0) - pulse.set_phase(1.0, d0) - pulse.shift_phase(3.11, d0) - pulse.set_frequency(1e9, d0) - pulse.shift_frequency(1e7, d0) - pulse.delay(20, d0) - pulse.delay(10, d1) - pulse.play(pulse.library.Constant(8, 0.1), d1) - pulse.measure_all() + with self.assertWarns(DeprecationWarning): + d0 = pulse.DriveChannel(0) + d1 = pulse.DriveChannel(1) + with pulse.build(self.backend) as sched: + with pulse.align_right(): + pulse.play(pulse.library.Constant(10, 1.0), d0) + pulse.set_phase(1.0, d0) + pulse.shift_phase(3.11, d0) + pulse.set_frequency(1e9, d0) + pulse.shift_frequency(1e7, d0) + pulse.delay(20, d0) + pulse.delay(10, d1) + pulse.play(pulse.library.Constant(8, 0.1), d1) + pulse.measure_all() with self.assertWarns(DeprecationWarning): qobj = assemble(sched, backend=self.backend, shots=2000) @@ -490,36 +501,38 @@ def test_disassemble_single_schedule(self): self.assertEqual(run_config_out.qubit_lo_freq, self.backend.defaults().qubit_freq_est) self.assertEqual(run_config_out.rep_time, 99) self.assertEqual(len(scheds), 1) - self.assertEqual(scheds[0], target_qobj_transform(sched)) + with self.assertWarns(DeprecationWarning): + self.assertEqual(scheds[0], target_qobj_transform(sched)) def test_disassemble_multiple_schedules(self): """Test disassembling multiple schedules, all should have the same config.""" - d0 = pulse.DriveChannel(0) - d1 = pulse.DriveChannel(1) - with pulse.build(self.backend) as sched0: - with pulse.align_right(): - pulse.play(pulse.library.Constant(10, 1.0), d0) - pulse.set_phase(1.0, d0) - pulse.shift_phase(3.11, d0) - pulse.set_frequency(1e9, d0) - pulse.shift_frequency(1e7, d0) - pulse.delay(20, d0) - pulse.delay(10, d1) - pulse.play(pulse.library.Constant(8, 0.1), d1) - pulse.measure_all() - - with pulse.build(self.backend) as sched1: - with pulse.align_right(): - pulse.play(pulse.library.Constant(8, 0.1), d0) - pulse.play(pulse.library.Waveform([0.0, 1.0]), d1) - pulse.set_phase(1.1, d0) - pulse.shift_phase(3.5, d0) - pulse.set_frequency(2e9, d0) - pulse.shift_frequency(3e7, d1) - pulse.delay(20, d1) - pulse.delay(10, d0) - pulse.play(pulse.library.Constant(8, 0.4), d1) - pulse.measure_all() + with self.assertWarns(DeprecationWarning): + d0 = pulse.DriveChannel(0) + d1 = pulse.DriveChannel(1) + with pulse.build(self.backend) as sched0: + with pulse.align_right(): + pulse.play(pulse.library.Constant(10, 1.0), d0) + pulse.set_phase(1.0, d0) + pulse.shift_phase(3.11, d0) + pulse.set_frequency(1e9, d0) + pulse.shift_frequency(1e7, d0) + pulse.delay(20, d0) + pulse.delay(10, d1) + pulse.play(pulse.library.Constant(8, 0.1), d1) + pulse.measure_all() + + with pulse.build(self.backend) as sched1: + with pulse.align_right(): + pulse.play(pulse.library.Constant(8, 0.1), d0) + pulse.play(pulse.library.Waveform([0.0, 1.0]), d1) + pulse.set_phase(1.1, d0) + pulse.shift_phase(3.5, d0) + pulse.set_frequency(2e9, d0) + pulse.shift_frequency(3e7, d1) + pulse.delay(20, d1) + pulse.delay(10, d0) + pulse.play(pulse.library.Constant(8, 0.4), d1) + pulse.measure_all() with self.assertWarns(DeprecationWarning): qobj = assemble([sched0, sched1], backend=self.backend, shots=2000) @@ -529,33 +542,36 @@ def test_disassemble_multiple_schedules(self): self.assertEqual(run_config_out.shots, 2000) self.assertEqual(run_config_out.memory, False) self.assertEqual(len(scheds), 2) - self.assertEqual(scheds[0], target_qobj_transform(sched0)) - self.assertEqual(scheds[1], target_qobj_transform(sched1)) + with self.assertWarns(DeprecationWarning): + self.assertEqual(scheds[0], target_qobj_transform(sched0)) + self.assertEqual(scheds[1], target_qobj_transform(sched1)) def test_disassemble_parametric_pulses(self): """Test disassembling multiple schedules all should have the same config.""" - d0 = pulse.DriveChannel(0) - with pulse.build(self.backend) as sched: - with pulse.align_right(): - pulse.play(pulse.library.Constant(10, 1.0), d0) - pulse.play(pulse.library.Gaussian(10, 1.0, 2.0), d0) - pulse.play(pulse.library.GaussianSquare(10, 1.0, 2.0, 3), d0) - pulse.play(pulse.library.Drag(10, 1.0, 2.0, 0.1), d0) + with self.assertWarns(DeprecationWarning): + d0 = pulse.DriveChannel(0) + with pulse.build(self.backend) as sched: + with pulse.align_right(): + pulse.play(pulse.library.Constant(10, 1.0), d0) + pulse.play(pulse.library.Gaussian(10, 1.0, 2.0), d0) + pulse.play(pulse.library.GaussianSquare(10, 1.0, 2.0, 3), d0) + pulse.play(pulse.library.Drag(10, 1.0, 2.0, 0.1), d0) with self.assertWarns(DeprecationWarning): qobj = assemble(sched, backend=self.backend, shots=2000) scheds, _, _ = disassemble(qobj) - self.assertEqual(scheds[0], target_qobj_transform(sched)) + self.assertEqual(scheds[0], target_qobj_transform(sched)) def test_disassemble_schedule_los(self): """Test disassembling schedule los.""" - d0 = pulse.DriveChannel(0) - m0 = pulse.MeasureChannel(0) - d1 = pulse.DriveChannel(1) - m1 = pulse.MeasureChannel(1) + with self.assertWarns(DeprecationWarning): + d0 = pulse.DriveChannel(0) + m0 = pulse.MeasureChannel(0) + d1 = pulse.DriveChannel(1) + m1 = pulse.MeasureChannel(1) - sched0 = pulse.Schedule() - sched1 = pulse.Schedule() + sched0 = pulse.Schedule() + sched1 = pulse.Schedule() schedule_los = [ {d0: 4.5e9, d1: 5e9, m0: 6e9, m1: 7e9}, diff --git a/test/python/compiler/test_scheduler.py b/test/python/compiler/test_scheduler.py index ad9b14b24c4a..c349bf054c3b 100644 --- a/test/python/compiler/test_scheduler.py +++ b/test/python/compiler/test_scheduler.py @@ -37,9 +37,10 @@ def setUp(self): self.circ2.cx(qr2[0], qr2[1]) self.circ2.measure(qr2, cr2) - self.backend = GenericBackendV2( - 3, calibrate_instructions=True, basis_gates=["cx", "u1", "u2", "u3"], seed=42 - ) + with self.assertWarns(DeprecationWarning): + self.backend = GenericBackendV2( + 3, calibrate_instructions=True, basis_gates=["cx", "u1", "u2", "u3"], seed=42 + ) def test_instruction_map_and_backend_not_supplied(self): """Test instruction map and backend not supplied.""" @@ -47,7 +48,8 @@ def test_instruction_map_and_backend_not_supplied(self): QiskitError, r"Must supply either a backend or InstructionScheduleMap for scheduling passes.", ): - schedule(self.circ) + with self.assertWarns(DeprecationWarning): + schedule(self.circ) def test_instruction_map_and_backend_defaults_unavailable(self): """Test backend defaults unavailable when backend is provided, but instruction map is not.""" @@ -57,7 +59,8 @@ def test_instruction_map_and_backend_defaults_unavailable(self): with self.assertRaisesRegex( QiskitError, r"The backend defaults are unavailable. The backend may not support pulse." ): - schedule(self.circ, self.backend) + with self.assertWarns(DeprecationWarning): + schedule(self.circ, self.backend) def test_measurement_map_and_backend_not_supplied(self): """Test measurement map and backend not supplied.""" @@ -65,11 +68,13 @@ def test_measurement_map_and_backend_not_supplied(self): QiskitError, r"Must supply either a backend or a meas_map for scheduling passes.", ): - schedule(self.circ, inst_map=InstructionScheduleMap()) + with self.assertWarns(DeprecationWarning): + schedule(self.circ, inst_map=InstructionScheduleMap()) def test_schedules_single_circuit(self): """Test scheduling of a single circuit.""" - circuit_schedule = schedule(self.circ, self.backend) + with self.assertWarns(DeprecationWarning): + circuit_schedule = schedule(self.circ, self.backend) self.assertIsInstance(circuit_schedule, Schedule) self.assertEqual(circuit_schedule.name, "circ") @@ -79,18 +84,20 @@ def test_schedules_multiple_circuits(self): self.enable_parallel_processing() circuits = [self.circ, self.circ2] - circuit_schedules = schedule(circuits, self.backend, method="asap") + with self.assertWarns(DeprecationWarning): + circuit_schedules = schedule(circuits, self.backend, method="asap") self.assertEqual(len(circuit_schedules), len(circuits)) circuit_one_schedule = circuit_schedules[0] circuit_two_schedule = circuit_schedules[1] - self.assertEqual( - circuit_one_schedule, - schedule(self.circ, self.backend, method="asap"), - ) - - self.assertEqual( - circuit_two_schedule, - schedule(self.circ2, self.backend, method="asap"), - ) + with self.assertWarns(DeprecationWarning): + self.assertEqual( + circuit_one_schedule, + schedule(self.circ, self.backend, method="asap"), + ) + + self.assertEqual( + circuit_two_schedule, + schedule(self.circ2, self.backend, method="asap"), + ) diff --git a/test/python/compiler/test_sequencer.py b/test/python/compiler/test_sequencer.py index ae75348a5cdf..3fcfc16674a6 100644 --- a/test/python/compiler/test_sequencer.py +++ b/test/python/compiler/test_sequencer.py @@ -34,7 +34,8 @@ def setUp(self): self.backend.configuration().timing_constraints = {} def test_sequence_empty(self): - self.assertEqual(sequence([], self.backend), []) + with self.assertWarns(DeprecationWarning): + self.assertEqual(sequence([], self.backend), []) def test_transpile_and_sequence_agree_with_schedule(self): qc = QuantumCircuit(2, name="bell") @@ -47,14 +48,17 @@ def test_transpile_and_sequence_agree_with_schedule(self): "stop supporting inputs of type `BackendV1`", ): sc = transpile(qc, self.backend, scheduling_method="alap") - actual = sequence(sc, self.backend) + with self.assertWarns(DeprecationWarning): + actual = sequence(sc, self.backend) with self.assertWarnsRegex( DeprecationWarning, expected_regex="The `transpile` function will " "stop supporting inputs of type `BackendV1`", ): expected = schedule(transpile(qc, self.backend), self.backend) - self.assertEqual(actual, pad(expected)) + with self.assertWarns(DeprecationWarning): + # pad adds Delay which is deprecated + self.assertEqual(actual, pad(expected)) def test_transpile_and_sequence_agree_with_schedule_for_circuit_with_delay(self): qc = QuantumCircuit(1, 1, name="t2") @@ -68,17 +72,19 @@ def test_transpile_and_sequence_agree_with_schedule_for_circuit_with_delay(self) "stop supporting inputs of type `BackendV1`", ): sc = transpile(qc, self.backend, scheduling_method="alap") - actual = sequence(sc, self.backend) + with self.assertWarns(DeprecationWarning): + actual = sequence(sc, self.backend) with self.assertWarnsRegex( DeprecationWarning, expected_regex="The `transpile` function will " "stop supporting inputs of type `BackendV1`", ): expected = schedule(transpile(qc, self.backend), self.backend) - self.assertEqual( - actual.exclude(instruction_types=[pulse.Delay]), - expected.exclude(instruction_types=[pulse.Delay]), - ) + with self.assertWarns(DeprecationWarning): + self.assertEqual( + actual.exclude(instruction_types=[pulse.Delay]), + expected.exclude(instruction_types=[pulse.Delay]), + ) @unittest.skip("not yet determined if delays on ancilla should be removed or not") def test_transpile_and_sequence_agree_with_schedule_for_circuits_without_measures(self): @@ -91,11 +97,13 @@ def test_transpile_and_sequence_agree_with_schedule_for_circuits_without_measure "stop supporting inputs of type `BackendV1`", ): sc = transpile(qc, self.backend, scheduling_method="alap") - actual = sequence(sc, self.backend) + with self.assertWarns(DeprecationWarning): + actual = sequence(sc, self.backend) with self.assertWarnsRegex( DeprecationWarning, expected_regex="The `transpile` function will " "stop supporting inputs of type `BackendV1`", ): - expected = schedule(transpile(qc, self.backend), self.backend) + with self.assertWarns(DeprecationWarning): + expected = schedule(transpile(qc, self.backend), self.backend) self.assertEqual(actual, pad(expected)) diff --git a/test/python/compiler/test_transpiler.py b/test/python/compiler/test_transpiler.py index 825dfd6bdfe7..5b4eafce3248 100644 --- a/test/python/compiler/test_transpiler.py +++ b/test/python/compiler/test_transpiler.py @@ -1305,14 +1305,15 @@ def test_transpiled_custom_gates_calibration(self): circ.append(custom_180, [0]) circ.append(custom_90, [1]) - with pulse.build() as q0_x180: - pulse.play(pulse.library.Gaussian(20, 1.0, 3.0), pulse.DriveChannel(0)) - with pulse.build() as q1_y90: - pulse.play(pulse.library.Gaussian(20, -1.0, 3.0), pulse.DriveChannel(1)) + with self.assertWarns(DeprecationWarning): + with pulse.build() as q0_x180: + pulse.play(pulse.library.Gaussian(20, 1.0, 3.0), pulse.DriveChannel(0)) + with pulse.build() as q1_y90: + pulse.play(pulse.library.Gaussian(20, -1.0, 3.0), pulse.DriveChannel(1)) - # Add calibration - circ.add_calibration(custom_180, [0], q0_x180) - circ.add_calibration(custom_90, [1], q1_y90) + # Add calibration + circ.add_calibration(custom_180, [0], q0_x180) + circ.add_calibration(custom_90, [1], q1_y90) transpiled_circuit = transpile( circ, @@ -1320,7 +1321,8 @@ def test_transpiled_custom_gates_calibration(self): layout_method="trivial", seed_transpiler=42, ) - self.assertEqual(transpiled_circuit.calibrations, circ.calibrations) + with self.assertWarns(DeprecationWarning): + self.assertEqual(transpiled_circuit.calibrations, circ.calibrations) self.assertEqual(list(transpiled_circuit.count_ops().keys()), ["mycustom"]) self.assertEqual(list(transpiled_circuit.count_ops().values()), [2]) @@ -1329,16 +1331,18 @@ def test_transpiled_basis_gates_calibrations(self): circ = QuantumCircuit(2) circ.h(0) - with pulse.build() as q0_x180: - pulse.play(pulse.library.Gaussian(20, 1.0, 3.0), pulse.DriveChannel(0)) + with self.assertWarns(DeprecationWarning): + with pulse.build() as q0_x180: + pulse.play(pulse.library.Gaussian(20, 1.0, 3.0), pulse.DriveChannel(0)) - # Add calibration - circ.add_calibration("h", [0], q0_x180) + # Add calibration + circ.add_calibration("h", [0], q0_x180) transpiled_circuit = transpile( circ, backend=GenericBackendV2(num_qubits=4, seed=42), seed_transpiler=42 ) - self.assertEqual(transpiled_circuit.calibrations, circ.calibrations) + with self.assertWarns(DeprecationWarning): + self.assertEqual(transpiled_circuit.calibrations, circ.calibrations) def test_transpile_calibrated_custom_gate_on_diff_qubit(self): """Test if the custom, non calibrated gate raises QiskitError.""" @@ -1347,11 +1351,12 @@ def test_transpile_calibrated_custom_gate_on_diff_qubit(self): circ = QuantumCircuit(2) circ.append(custom_180, [0]) - with pulse.build() as q0_x180: - pulse.play(pulse.library.Gaussian(20, 1.0, 3.0), pulse.DriveChannel(0)) + with self.assertWarns(DeprecationWarning): + with pulse.build() as q0_x180: + pulse.play(pulse.library.Gaussian(20, 1.0, 3.0), pulse.DriveChannel(0)) - # Add calibration - circ.add_calibration(custom_180, [1], q0_x180) + # Add calibration + circ.add_calibration(custom_180, [1], q0_x180) with self.assertRaises(QiskitError): transpile( @@ -1369,16 +1374,18 @@ def test_transpile_calibrated_nonbasis_gate_on_diff_qubit(self): circ.h(0) circ.h(1) - with pulse.build() as q0_x180: - pulse.play(pulse.library.Gaussian(20, 1.0, 3.0), pulse.DriveChannel(0)) + with self.assertWarns(DeprecationWarning): + with pulse.build() as q0_x180: + pulse.play(pulse.library.Gaussian(20, 1.0, 3.0), pulse.DriveChannel(0)) - # Add calibration - circ.add_calibration("h", [1], q0_x180) + # Add calibration + circ.add_calibration("h", [1], q0_x180) transpiled_circuit = transpile( circ, backend=GenericBackendV2(num_qubits=4), seed_transpiler=42, optimization_level=1 ) - self.assertEqual(transpiled_circuit.calibrations, circ.calibrations) + with self.assertWarns(DeprecationWarning): + self.assertEqual(transpiled_circuit.calibrations, circ.calibrations) self.assertEqual(set(transpiled_circuit.count_ops().keys()), {"rz", "sx", "h"}) def test_transpile_subset_of_calibrated_gates(self): @@ -1391,11 +1398,12 @@ def test_transpile_subset_of_calibrated_gates(self): circ.append(x_180, [0]) circ.h(1) - with pulse.build() as q0_x180: - pulse.play(pulse.library.Gaussian(20, 1.0, 3.0), pulse.DriveChannel(0)) + with self.assertWarns(DeprecationWarning): + with pulse.build() as q0_x180: + pulse.play(pulse.library.Gaussian(20, 1.0, 3.0), pulse.DriveChannel(0)) - circ.add_calibration(x_180, [0], q0_x180) - circ.add_calibration("h", [1], q0_x180) # 'h' is calibrated on qubit 1 + circ.add_calibration(x_180, [0], q0_x180) + circ.add_calibration("h", [1], q0_x180) # 'h' is calibrated on qubit 1 transpiled_circ = transpile( circ, @@ -1413,11 +1421,13 @@ def test_parameterized_calibrations_transpile(self): circ.append(Gate("rxt", 1, [2 * 3.14 * tau]), [0]) def q0_rxt(tau): - with pulse.build() as q0_rxt: - pulse.play(pulse.library.Gaussian(20, 0.4 * tau, 3.0), pulse.DriveChannel(0)) + with self.assertWarns(DeprecationWarning): + with pulse.build() as q0_rxt: + pulse.play(pulse.library.Gaussian(20, 0.4 * tau, 3.0), pulse.DriveChannel(0)) return q0_rxt - circ.add_calibration("rxt", [0], q0_rxt(tau), [2 * 3.14 * tau]) + with self.assertWarns(DeprecationWarning): + circ.add_calibration("rxt", [0], q0_rxt(tau), [2 * 3.14 * tau]) transpiled_circ = transpile( circ, @@ -1442,12 +1452,14 @@ def test_inst_durations_from_calibrations(self): qc = QuantumCircuit(2) qc.append(Gate("custom", 1, []), [0]) - with pulse.build() as cal: - pulse.play(pulse.library.Gaussian(20, 1.0, 3.0), pulse.DriveChannel(0)) - qc.add_calibration("custom", [0], cal) + with self.assertWarns(DeprecationWarning): + with pulse.build() as cal: + pulse.play(pulse.library.Gaussian(20, 1.0, 3.0), pulse.DriveChannel(0)) + qc.add_calibration("custom", [0], cal) out = transpile(qc, scheduling_method="alap", seed_transpiler=42) - self.assertEqual(out.duration, cal.duration) + with self.assertWarns(DeprecationWarning): + self.assertEqual(out.duration, cal.duration) @data(0, 1, 2, 3) def test_multiqubit_gates_calibrations(self, opt_level): @@ -1461,35 +1473,36 @@ def test_multiqubit_gates_calibrations(self, opt_level): circ.measure_all() backend = GenericBackendV2(num_qubits=6) - with pulse.build(backend=backend, name="custom") as my_schedule: - pulse.play( - pulse.library.Gaussian(duration=128, amp=0.1, sigma=16), pulse.drive_channel(0) - ) - pulse.play( - pulse.library.Gaussian(duration=128, amp=0.1, sigma=16), pulse.drive_channel(1) - ) - pulse.play( - pulse.library.Gaussian(duration=128, amp=0.1, sigma=16), pulse.drive_channel(2) - ) - pulse.play( - pulse.library.Gaussian(duration=128, amp=0.1, sigma=16), pulse.drive_channel(3) - ) - pulse.play( - pulse.library.Gaussian(duration=128, amp=0.1, sigma=16), pulse.drive_channel(4) - ) - pulse.play( - pulse.library.Gaussian(duration=128, amp=0.1, sigma=16), pulse.ControlChannel(1) - ) - pulse.play( - pulse.library.Gaussian(duration=128, amp=0.1, sigma=16), pulse.ControlChannel(2) - ) - pulse.play( - pulse.library.Gaussian(duration=128, amp=0.1, sigma=16), pulse.ControlChannel(3) - ) - pulse.play( - pulse.library.Gaussian(duration=128, amp=0.1, sigma=16), pulse.ControlChannel(4) - ) - circ.add_calibration("my_custom_gate", [0, 1, 2, 3, 4], my_schedule, []) + with self.assertWarns(DeprecationWarning): + with pulse.build(backend=backend, name="custom") as my_schedule: + pulse.play( + pulse.library.Gaussian(duration=128, amp=0.1, sigma=16), pulse.drive_channel(0) + ) + pulse.play( + pulse.library.Gaussian(duration=128, amp=0.1, sigma=16), pulse.drive_channel(1) + ) + pulse.play( + pulse.library.Gaussian(duration=128, amp=0.1, sigma=16), pulse.drive_channel(2) + ) + pulse.play( + pulse.library.Gaussian(duration=128, amp=0.1, sigma=16), pulse.drive_channel(3) + ) + pulse.play( + pulse.library.Gaussian(duration=128, amp=0.1, sigma=16), pulse.drive_channel(4) + ) + pulse.play( + pulse.library.Gaussian(duration=128, amp=0.1, sigma=16), pulse.ControlChannel(1) + ) + pulse.play( + pulse.library.Gaussian(duration=128, amp=0.1, sigma=16), pulse.ControlChannel(2) + ) + pulse.play( + pulse.library.Gaussian(duration=128, amp=0.1, sigma=16), pulse.ControlChannel(3) + ) + pulse.play( + pulse.library.Gaussian(duration=128, amp=0.1, sigma=16), pulse.ControlChannel(4) + ) + circ.add_calibration("my_custom_gate", [0, 1, 2, 3, 4], my_schedule, []) trans_circ = transpile( circ, backend=backend, @@ -1555,13 +1568,13 @@ def test_scheduling_timing_constraints(self): with self.assertWarns(DeprecationWarning): backend_v1 = Fake27QPulseV1() - backend_v2 = GenericBackendV2( - num_qubits=27, - calibrate_instructions=True, - control_flow=True, - coupling_map=MUMBAI_CMAP, - seed=42, - ) + backend_v2 = GenericBackendV2( + num_qubits=27, + calibrate_instructions=True, + control_flow=True, + coupling_map=MUMBAI_CMAP, + seed=42, + ) # the original timing constraints are granularity = min_length = 16 timing_constraints = TimingConstraints(granularity=32, min_length=64) error_msgs = { @@ -1575,15 +1588,19 @@ def test_scheduling_timing_constraints(self): qc.h(0) qc.cx(0, 1) qc.measure_all() - qc.add_calibration( - "h", [0], Schedule(Play(Gaussian(duration, 0.2, 4), DriveChannel(0))), [0, 0] - ) - qc.add_calibration( - "cx", - [0, 1], - Schedule(Play(Gaussian(duration, 0.2, 4), DriveChannel(1))), - [0, 0], - ) + with self.assertWarns(DeprecationWarning): + qc.add_calibration( + "h", + [0], + Schedule(Play(Gaussian(duration, 0.2, 4), DriveChannel(0))), + [0, 0], + ) + qc.add_calibration( + "cx", + [0, 1], + Schedule(Play(Gaussian(duration, 0.2, 4), DriveChannel(1))), + [0, 0], + ) with self.assertRaisesRegex(TranspilerError, error_msgs[duration]): with self.assertWarns(DeprecationWarning): _ = transpile( @@ -2777,6 +2794,8 @@ def test_parallel_dispatch_lazy_cal_loading(self): class TestAddCalibration(TransformationPass): """A fake pass to test lazy pulse qobj loading in parallel environment.""" + _outer_class = None + def __init__(self, target): """Instantiate with target.""" super().__init__() @@ -2784,21 +2803,24 @@ def __init__(self, target): def run(self, dag): """Run test pass that adds calibration of SX gate of qubit 0.""" - dag.add_calibration( - "sx", - qubits=(0,), - schedule=self.target["sx"][(0,)].calibration, # PulseQobj is parsed here - ) + with self._outer_class.assertWarns(DeprecationWarning): + dag.add_calibration( + "sx", + qubits=(0,), + schedule=self.target["sx"][(0,)].calibration, # PulseQobj is parsed here + ) return dag # Create backend with empty calibrations (PulseQobjEntries) - backend = GenericBackendV2( - num_qubits=4, - calibrate_instructions=False, - ) + with self.assertWarns(DeprecationWarning): + backend = GenericBackendV2( + num_qubits=4, + calibrate_instructions=False, + ) # This target has PulseQobj entries that provide a serialized schedule data pass_ = TestAddCalibration(backend.target) + pass_._outer_class = self # to be used for calling assertWarns within the pass pm = PassManager(passes=[pass_]) self.assertIsNone(backend.target["sx"][(0,)]._calibration._definition) @@ -2807,10 +2829,11 @@ def run(self, dag): qc_copied = [qc for _ in range(10)] qcs_cal_added = pm.run(qc_copied) - ref_cal = backend.target["sx"][(0,)].calibration - for qc_test in qcs_cal_added: - added_cal = qc_test.calibrations["sx"][((0,), ())] - self.assertEqual(added_cal, ref_cal) + with self.assertWarns(DeprecationWarning): + ref_cal = backend.target["sx"][(0,)].calibration + for qc_test in qcs_cal_added: + added_cal = qc_test.calibrations["sx"][((0,), ())] + self.assertEqual(added_cal, ref_cal) @data(0, 1, 2, 3) def test_parallel_singleton_conditional_gate(self, opt_level): @@ -2910,20 +2933,22 @@ def test_backend_and_custom_gate(self, opt_level): coupling_map=[[0, 1], [1, 0], [1, 2], [1, 3], [2, 1], [3, 1], [3, 4], [4, 3]], seed=42, ) - inst_map = InstructionScheduleMap() - inst_map.add("newgate", [0, 1], pulse.ScheduleBlock()) + with self.assertWarns(DeprecationWarning): + inst_map = InstructionScheduleMap() + inst_map.add("newgate", [0, 1], pulse.ScheduleBlock()) newgate = Gate("newgate", 2, []) circ = QuantumCircuit(2) circ.append(newgate, [0, 1]) - tqc = transpile( - circ, - backend, - inst_map=inst_map, - basis_gates=["newgate"], - optimization_level=opt_level, - seed_transpiler=42, - ) + with self.assertWarns(DeprecationWarning): + tqc = transpile( + circ, + backend, + inst_map=inst_map, + basis_gates=["newgate"], + optimization_level=opt_level, + seed_transpiler=42, + ) self.assertEqual(len(tqc.data), 1) self.assertEqual(tqc.data[0].operation, newgate) for x in tqc.data[0].qubits: diff --git a/test/python/converters/test_circuit_to_dag.py b/test/python/converters/test_circuit_to_dag.py index 0bded9c0f4a2..852cb324aa79 100644 --- a/test/python/converters/test_circuit_to_dag.py +++ b/test/python/converters/test_circuit_to_dag.py @@ -45,14 +45,17 @@ def test_circuit_and_dag(self): def test_calibrations(self): """Test that calibrations are properly copied over.""" circuit_in = QuantumCircuit(1) - circuit_in.add_calibration("h", [0], None) - self.assertEqual(len(circuit_in.calibrations), 1) + with self.assertWarns(DeprecationWarning): + circuit_in.add_calibration("h", [0], None) + self.assertEqual(len(circuit_in.calibrations), 1) dag = circuit_to_dag(circuit_in) - self.assertEqual(len(dag.calibrations), 1) + with self.assertWarns(DeprecationWarning): + self.assertEqual(len(dag.calibrations), 1) circuit_out = dag_to_circuit(dag) - self.assertEqual(len(circuit_out.calibrations), 1) + with self.assertWarns(DeprecationWarning): + self.assertEqual(len(circuit_out.calibrations), 1) def test_wires_from_expr_nodes_condition(self): """Test that the classical wires implied by an `Expr` node in a control-flow op's diff --git a/test/python/converters/test_circuit_to_dagdependency.py b/test/python/converters/test_circuit_to_dagdependency.py index 9d33192d50a1..65221e9cf2c1 100644 --- a/test/python/converters/test_circuit_to_dagdependency.py +++ b/test/python/converters/test_circuit_to_dagdependency.py @@ -62,14 +62,17 @@ def test_circuit_and_dag_canonical2(self): def test_calibrations(self): """Test that calibrations are properly copied over.""" circuit_in = QuantumCircuit(1) - circuit_in.add_calibration("h", [0], None) - self.assertEqual(len(circuit_in.calibrations), 1) + with self.assertWarns(DeprecationWarning): + circuit_in.add_calibration("h", [0], None) + self.assertEqual(len(circuit_in.calibrations), 1) dag_dependency = circuit_to_dagdependency(circuit_in) - self.assertEqual(len(dag_dependency.calibrations), 1) + with self.assertWarns(DeprecationWarning): + self.assertEqual(len(dag_dependency.calibrations), 1) circuit_out = dagdependency_to_circuit(dag_dependency) - self.assertEqual(len(circuit_out.calibrations), 1) + with self.assertWarns(DeprecationWarning): + self.assertEqual(len(circuit_out.calibrations), 1) def test_metadata(self): """Test circuit metadata is preservered through conversion.""" diff --git a/test/python/converters/test_circuit_to_dagdependency_v2.py b/test/python/converters/test_circuit_to_dagdependency_v2.py index edeea3a59fea..3323ca0e6768 100644 --- a/test/python/converters/test_circuit_to_dagdependency_v2.py +++ b/test/python/converters/test_circuit_to_dagdependency_v2.py @@ -44,14 +44,16 @@ def test_circuit_and_dag_canonical(self): def test_calibrations(self): """Test that calibrations are properly copied over.""" circuit_in = QuantumCircuit(1) - circuit_in.add_calibration("h", [0], None) - self.assertEqual(len(circuit_in.calibrations), 1) + with self.assertWarns(DeprecationWarning): + circuit_in.add_calibration("h", [0], None) + self.assertEqual(len(circuit_in.calibrations), 1) dag_dependency = _circuit_to_dagdependency_v2(circuit_in) self.assertEqual(len(dag_dependency.calibrations), 1) circuit_out = dagdependency_to_circuit(dag_dependency) - self.assertEqual(len(circuit_out.calibrations), 1) + with self.assertWarns(DeprecationWarning): + self.assertEqual(len(circuit_out.calibrations), 1) def test_metadata(self): """Test circuit metadata is preservered through conversion.""" diff --git a/test/python/dagcircuit/test_compose.py b/test/python/dagcircuit/test_compose.py index ff5014eacef7..27404cec05c2 100644 --- a/test/python/dagcircuit/test_compose.py +++ b/test/python/dagcircuit/test_compose.py @@ -630,15 +630,18 @@ def test_compose_calibrations(self): """Test that compose carries over the calibrations.""" dag_cal = QuantumCircuit(1) dag_cal.append(Gate("", 1, []), qargs=[0]) - dag_cal.add_calibration(Gate("", 1, []), [0], Schedule()) + with self.assertWarns(DeprecationWarning): + dag_cal.add_calibration(Gate("", 1, []), [0], Schedule()) empty_dag = circuit_to_dag(QuantumCircuit(1)) calibrated_dag = circuit_to_dag(dag_cal) composed_dag = empty_dag.compose(calibrated_dag, inplace=False) - cal = {"": {((0,), ()): Schedule(name="sched0")}} - self.assertEqual(composed_dag.calibrations, cal) - self.assertEqual(calibrated_dag.calibrations, cal) + with self.assertWarns(DeprecationWarning): + cal = {"": {((0,), ()): Schedule(name="sched0")}} + with self.assertWarns(DeprecationWarning): + self.assertEqual(composed_dag.calibrations, cal) + self.assertEqual(calibrated_dag.calibrations, cal) if __name__ == "__main__": diff --git a/test/python/primitives/test_backend_sampler.py b/test/python/primitives/test_backend_sampler.py index 27e438d30874..eb3b79f1b911 100644 --- a/test/python/primitives/test_backend_sampler.py +++ b/test/python/primitives/test_backend_sampler.py @@ -368,9 +368,10 @@ def max_circuits(self): def test_primitive_job_size_limit_backend_v1(self): """Test primitive respects backend's job size limit.""" - backend = GenericBackendV2( - 7, calibrate_instructions=True, basis_gates=["cx", "u1", "u2", "u3"], seed=42 - ) + with self.assertWarns(DeprecationWarning): + backend = GenericBackendV2( + 7, calibrate_instructions=True, basis_gates=["cx", "u1", "u2", "u3"], seed=42 + ) qc = QuantumCircuit(1) qc.measure_all() qc2 = QuantumCircuit(1) @@ -378,8 +379,8 @@ def test_primitive_job_size_limit_backend_v1(self): qc2.measure_all() with self.assertWarns(DeprecationWarning): sampler = BackendSampler(backend=backend) - result = sampler.run([qc, qc2]).result() - self.assertIsInstance(result, SamplerResult) + result = sampler.run([qc, qc2]).result() + self.assertIsInstance(result, SamplerResult) self.assertEqual(len(result.quasi_dists), 2) self.assertDictAlmostEqual(result.quasi_dists[0], {0: 1}, 0.1) @@ -408,9 +409,10 @@ def test_circuit_with_dynamic_circuit(self): def test_sequential_run(self): """Test sequential run.""" - backend = GenericBackendV2( - 7, calibrate_instructions=True, basis_gates=["cx", "u1", "u2", "u3"], seed=42 - ) + with self.assertWarns(DeprecationWarning): + backend = GenericBackendV2( + 7, calibrate_instructions=True, basis_gates=["cx", "u1", "u2", "u3"], seed=42 + ) qc = QuantumCircuit(1) qc.measure_all() qc2 = QuantumCircuit(1) @@ -458,10 +460,10 @@ def callback(msg): bound_counter = CallbackPass("bound_pass_manager", callback) bound_pass = PassManager(bound_counter) - backend = GenericBackendV2( - 7, calibrate_instructions=True, basis_gates=["cx", "u1", "u2", "u3"], seed=42 - ) with self.assertWarns(DeprecationWarning): + backend = GenericBackendV2( + 7, calibrate_instructions=True, basis_gates=["cx", "u1", "u2", "u3"], seed=42 + ) sampler = BackendSampler(backend=backend, bound_pass_manager=bound_pass) _ = sampler.run([self._circuit[0]]).result() expected = [ @@ -482,9 +484,13 @@ def callback(msg): # pylint: disable=function-redefined bound_counter = CallbackPass("bound_pass_manager", callback) bound_pass = PassManager(bound_counter) - backend = GenericBackendV2( - 7, calibrate_instructions=True, basis_gates=["cx", "u1", "u2", "u3"], seed=42 - ) + with self.assertWarns(DeprecationWarning): + backend = GenericBackendV2( + 7, + calibrate_instructions=True, + basis_gates=["cx", "u1", "u2", "u3"], + seed=42, + ) with self.assertWarns(DeprecationWarning): sampler = BackendSampler(backend=backend, bound_pass_manager=bound_pass) _ = sampler.run([self._circuit[0], self._circuit[0]]).result() diff --git a/test/python/primitives/test_backend_sampler_v2.py b/test/python/primitives/test_backend_sampler_v2.py index 372ae3a6715c..e66b594cc738 100644 --- a/test/python/primitives/test_backend_sampler_v2.py +++ b/test/python/primitives/test_backend_sampler_v2.py @@ -1371,9 +1371,10 @@ def max_circuits(self): def test_job_size_limit_backend_v1(self): """Test BackendSamplerV2 respects backend's job size limit.""" - backend = GenericBackendV2( - 2, calibrate_instructions=True, basis_gates=["cx", "u1", "u2", "u3"], seed=42 - ) + with self.assertWarns(DeprecationWarning): + backend = GenericBackendV2( + 2, calibrate_instructions=True, basis_gates=["cx", "u1", "u2", "u3"], seed=42 + ) qc = QuantumCircuit(1) qc.measure_all() qc2 = QuantumCircuit(1) diff --git a/test/python/primitives/test_primitive.py b/test/python/primitives/test_primitive.py index fb96081fa001..1e7d95819904 100644 --- a/test/python/primitives/test_primitive.py +++ b/test/python/primitives/test_primitive.py @@ -135,13 +135,15 @@ def test_func(n): with self.subTest("pulse circuit"): def test_with_scheduling(n): - custom_gate = pulse.Schedule(name="custom_x_gate") - custom_gate.insert( - 0, pulse.Play(pulse.Constant(160 * n, 0.1), pulse.DriveChannel(0)), inplace=True - ) - qc = QuantumCircuit(1) + with self.assertWarns(DeprecationWarning): + custom_gate = pulse.Schedule(name="custom_x_gate") + custom_gate.insert( + 0, pulse.Play(pulse.Constant(160 * n, 0.1), pulse.DriveChannel(0)), inplace=True + ) + qc = QuantumCircuit(1) qc.x(0) - qc.add_calibration("x", qubits=(0,), schedule=custom_gate) + with self.assertWarns(DeprecationWarning): + qc.add_calibration("x", qubits=(0,), schedule=custom_gate) backend = GenericBackendV2( num_qubits=2, basis_gates=["id", "u1", "u2", "u3", "cx"], seed=42 diff --git a/test/python/providers/fake_provider/test_generic_backend_v2.py b/test/python/providers/fake_provider/test_generic_backend_v2.py index 42f46b7d7851..d42a6dbf7e07 100644 --- a/test/python/providers/fake_provider/test_generic_backend_v2.py +++ b/test/python/providers/fake_provider/test_generic_backend_v2.py @@ -50,13 +50,14 @@ def test_ccx_2Q(self): def test_calibration_no_noise_info(self): """Test failing with a backend with calibration and no noise info""" with self.assertRaises(QiskitError): - GenericBackendV2( - num_qubits=2, - basis_gates=["ccx", "id"], - calibrate_instructions=True, - noise_info=False, - seed=42, - ) + with self.assertWarns(DeprecationWarning): + GenericBackendV2( + num_qubits=2, + basis_gates=["ccx", "id"], + calibrate_instructions=True, + noise_info=False, + seed=42, + ) def test_no_noise(self): """Test no noise info when parameter is false""" @@ -90,13 +91,14 @@ def test_no_noise_fully_connected(self): def test_no_info(self): """Test no noise info when parameter is false""" - backend = GenericBackendV2( - num_qubits=5, - coupling_map=CouplingMap.from_line(5), - noise_info=False, - pulse_channels=False, - seed=42, - ) + with self.assertWarns(DeprecationWarning): + backend = GenericBackendV2( + num_qubits=5, + coupling_map=CouplingMap.from_line(5), + noise_info=False, + pulse_channels=False, + seed=42, + ) qc = QuantumCircuit(5) qc.h(0) qc.cx(0, 1) @@ -110,9 +112,10 @@ def test_no_info(self): def test_no_pulse_channels(self): """Test no/empty pulse channels when parameter is false""" - backend = GenericBackendV2( - num_qubits=5, coupling_map=CouplingMap.from_line(5), pulse_channels=False, seed=42 - ) + with self.assertWarns(DeprecationWarning): + backend = GenericBackendV2( + num_qubits=5, coupling_map=CouplingMap.from_line(5), pulse_channels=False, seed=42 + ) qc = QuantumCircuit(5) qc.h(0) qc.cx(0, 1) diff --git a/test/python/providers/test_backend_v2.py b/test/python/providers/test_backend_v2.py index df5f7b9abdea..b3c5d3531ff1 100644 --- a/test/python/providers/test_backend_v2.py +++ b/test/python/providers/test_backend_v2.py @@ -208,24 +208,27 @@ def test_transpile_mumbai_target(self): def test_drive_channel(self, qubit): """Test getting drive channel with qubit index.""" backend = GenericBackendV2(num_qubits=5, seed=42) - chan = backend.drive_channel(qubit) - ref = channels.DriveChannel(qubit) + with self.assertWarns(DeprecationWarning): + chan = backend.drive_channel(qubit) + ref = channels.DriveChannel(qubit) self.assertEqual(chan, ref) @data(0, 1, 2, 3, 4) def test_measure_channel(self, qubit): """Test getting measure channel with qubit index.""" backend = GenericBackendV2(num_qubits=5, seed=42) - chan = backend.measure_channel(qubit) - ref = channels.MeasureChannel(qubit) + with self.assertWarns(DeprecationWarning): + chan = backend.measure_channel(qubit) + ref = channels.MeasureChannel(qubit) self.assertEqual(chan, ref) @data(0, 1, 2, 3, 4) def test_acquire_channel(self, qubit): """Test getting acquire channel with qubit index.""" backend = GenericBackendV2(num_qubits=5, seed=42) - chan = backend.acquire_channel(qubit) - ref = channels.AcquireChannel(qubit) + with self.assertWarns(DeprecationWarning): + chan = backend.acquire_channel(qubit) + ref = channels.AcquireChannel(qubit) self.assertEqual(chan, ref) @data((4, 3), (3, 4), (3, 2), (2, 3), (1, 2), (2, 1), (1, 0), (0, 1)) @@ -242,6 +245,7 @@ def test_control_channel(self, qubits): (0, 1): 0, } backend = GenericBackendV2(num_qubits=5, coupling_map=BOGOTA_CMAP, seed=42) - chan = backend.control_channel(qubits)[0] - ref = channels.ControlChannel(bogota_cr_channels_map[qubits]) + with self.assertWarns(DeprecationWarning): + chan = backend.control_channel(qubits)[0] + ref = channels.ControlChannel(bogota_cr_channels_map[qubits]) self.assertEqual(chan, ref) diff --git a/test/python/providers/test_backendconfiguration.py b/test/python/providers/test_backendconfiguration.py index 82bbd1c6847f..f3309fda4b40 100644 --- a/test/python/providers/test_backendconfiguration.py +++ b/test/python/providers/test_backendconfiguration.py @@ -70,64 +70,76 @@ def test_hamiltonian(self): def test_get_channels(self): """Test requesting channels from the system.""" - self.assertEqual(self.config.drive(0), DriveChannel(0)) - self.assertEqual(self.config.measure(1), MeasureChannel(1)) - self.assertEqual(self.config.acquire(0), AcquireChannel(0)) + + with self.assertWarns(DeprecationWarning): + self.assertEqual(self.config.drive(0), DriveChannel(0)) + self.assertEqual(self.config.measure(1), MeasureChannel(1)) + self.assertEqual(self.config.acquire(0), AcquireChannel(0)) with self.assertRaises(BackendConfigurationError): # Check that an error is raised if the system doesn't have that many qubits self.assertEqual(self.config.acquire(10), AcquireChannel(10)) - self.assertEqual(self.config.control(qubits=[0, 1]), [ControlChannel(0)]) + with self.assertWarns(DeprecationWarning): + self.assertEqual(self.config.control(qubits=[0, 1]), [ControlChannel(0)]) with self.assertRaises(BackendConfigurationError): # Check that an error is raised if key not found in self._qubit_channel_map self.config.control(qubits=(10, 1)) def test_get_channel_qubits(self): """Test to get all qubits operated on a given channel.""" - self.assertEqual(self.config.get_channel_qubits(channel=DriveChannel(0)), [0]) - self.assertEqual(self.config.get_channel_qubits(channel=ControlChannel(0)), [0, 1]) + with self.assertWarns(DeprecationWarning): + self.assertEqual(self.config.get_channel_qubits(channel=DriveChannel(0)), [0]) + self.assertEqual(self.config.get_channel_qubits(channel=ControlChannel(0)), [0, 1]) with self.assertWarns(DeprecationWarning): backend_3q = FakeOpenPulse3Q() - self.assertEqual(backend_3q.configuration().get_channel_qubits(ControlChannel(2)), [2, 1]) - self.assertEqual(backend_3q.configuration().get_channel_qubits(ControlChannel(1)), [1, 0]) + with self.assertWarns(DeprecationWarning): + self.assertEqual( + backend_3q.configuration().get_channel_qubits(ControlChannel(2)), [2, 1] + ) + self.assertEqual( + backend_3q.configuration().get_channel_qubits(ControlChannel(1)), [1, 0] + ) with self.assertRaises(BackendConfigurationError): - # Check that an error is raised if key not found in self._channel_qubit_map - self.config.get_channel_qubits(MeasureChannel(10)) + with self.assertWarns(DeprecationWarning): + # Check that an error is raised if key not found in self._channel_qubit_map + self.config.get_channel_qubits(MeasureChannel(10)) def test_get_qubit_channels(self): """Test to get all channels operated on a given qubit.""" - self.assertTrue( - self._test_lists_equal( - actual=self.config.get_qubit_channels(qubit=(1,)), - expected=[DriveChannel(1), MeasureChannel(1), AcquireChannel(1)], + with self.assertWarns(DeprecationWarning): + self.assertTrue( + self._test_lists_equal( + actual=self.config.get_qubit_channels(qubit=(1,)), + expected=[DriveChannel(1), MeasureChannel(1), AcquireChannel(1)], + ) ) - ) - self.assertTrue( - self._test_lists_equal( - actual=self.config.get_qubit_channels(qubit=1), - expected=[ - ControlChannel(0), - ControlChannel(1), - AcquireChannel(1), - DriveChannel(1), - MeasureChannel(1), - ], + with self.assertWarns(DeprecationWarning): + self.assertTrue( + self._test_lists_equal( + actual=self.config.get_qubit_channels(qubit=1), + expected=[ + ControlChannel(0), + ControlChannel(1), + AcquireChannel(1), + DriveChannel(1), + MeasureChannel(1), + ], + ) ) - ) with self.assertWarns(DeprecationWarning): backend_3q = FakeOpenPulse3Q() - self.assertTrue( - self._test_lists_equal( - actual=backend_3q.configuration().get_qubit_channels(1), - expected=[ - MeasureChannel(1), - ControlChannel(0), - ControlChannel(2), - AcquireChannel(1), - DriveChannel(1), - ControlChannel(1), - ], + self.assertTrue( + self._test_lists_equal( + actual=backend_3q.configuration().get_qubit_channels(1), + expected=[ + MeasureChannel(1), + ControlChannel(0), + ControlChannel(2), + AcquireChannel(1), + DriveChannel(1), + ControlChannel(1), + ], + ) ) - ) with self.assertRaises(BackendConfigurationError): # Check that an error is raised if key not found in self._channel_qubit_map self.config.get_qubit_channels(10) diff --git a/test/python/providers/test_fake_backends.py b/test/python/providers/test_fake_backends.py index 3df3e7d5893f..c03c31e55c65 100644 --- a/test/python/providers/test_fake_backends.py +++ b/test/python/providers/test_fake_backends.py @@ -764,7 +764,8 @@ def test_convert_to_target_control_flow(self): "switch_case", ] defaults = backend.defaults() - target = convert_to_target(configuration, properties, defaults) + with self.assertWarns(DeprecationWarning): + target = convert_to_target(configuration, properties, defaults) self.assertTrue(target.instruction_supported("if_else", ())) self.assertFalse(target.instruction_supported("while_loop", ())) self.assertTrue(target.instruction_supported("for_loop", ())) @@ -796,7 +797,8 @@ def test_convert_unrelated_supported_instructions(self): "switch_case", ] defaults = backend.defaults() - target = convert_to_target(configuration, properties, defaults) + with self.assertWarns(DeprecationWarning): + target = convert_to_target(configuration, properties, defaults) self.assertTrue(target.instruction_supported("if_else", ())) self.assertFalse(target.instruction_supported("while_loop", ())) self.assertTrue(target.instruction_supported("for_loop", ())) diff --git a/test/python/providers/test_pulse_defaults.py b/test/python/providers/test_pulse_defaults.py index 18f849255917..2d8fe5b7bf11 100644 --- a/test/python/providers/test_pulse_defaults.py +++ b/test/python/providers/test_pulse_defaults.py @@ -29,10 +29,10 @@ def setUp(self): with self.assertWarns(DeprecationWarning): # BackendV2 does not have defaults self.defs = FakeOpenPulse2Q().defaults() - backend = GenericBackendV2( - 2, calibrate_instructions=True, basis_gates=["cx", "u1", "u2", "u3"], seed=42 - ) - self.inst_map = backend.instruction_schedule_map + backend = GenericBackendV2( + 2, calibrate_instructions=True, basis_gates=["cx", "u1", "u2", "u3"], seed=42 + ) + self.inst_map = backend.instruction_schedule_map def test_buffer(self): """Test getting the buffer value.""" diff --git a/test/python/pulse/test_block.py b/test/python/pulse/test_block.py index c6a2c2384f64..652eba3ccf18 100644 --- a/test/python/pulse/test_block.py +++ b/test/python/pulse/test_block.py @@ -20,11 +20,14 @@ from qiskit.pulse.exceptions import PulseError from qiskit.providers.fake_provider import FakeOpenPulse2Q from test import QiskitTestCase # pylint: disable=wrong-import-order +from qiskit.utils.deprecate_pulse import decorate_test_methods, ignore_pulse_deprecation_warnings +@decorate_test_methods(ignore_pulse_deprecation_warnings) class BaseTestBlock(QiskitTestCase): """ScheduleBlock tests.""" + @ignore_pulse_deprecation_warnings def setUp(self): super().setUp() @@ -52,6 +55,7 @@ def assertScheduleEqual(self, target, reference): self.assertEqual(transforms.target_qobj_transform(target), reference) +@decorate_test_methods(ignore_pulse_deprecation_warnings) class TestTransformation(BaseTestBlock): """Test conversion of ScheduleBlock to Schedule.""" @@ -140,6 +144,7 @@ def test_nested_alignment(self): self.assertScheduleEqual(block_main, ref_sched) +@decorate_test_methods(ignore_pulse_deprecation_warnings) class TestBlockOperation(BaseTestBlock): """Test fundamental operation on schedule block. @@ -150,6 +155,7 @@ class TestBlockOperation(BaseTestBlock): This operation should be tested in `test.python.pulse.test_block.TestTransformation`. """ + @ignore_pulse_deprecation_warnings def setUp(self): super().setUp() @@ -372,6 +378,7 @@ def test_inherit_from(self): self.assertDictEqual(new_sched.metadata, ref_metadata) +@decorate_test_methods(ignore_pulse_deprecation_warnings) class TestBlockEquality(BaseTestBlock): """Test equality of blocks. @@ -611,9 +618,11 @@ def test_instruction_out_of_order_complex_not_equal(self): self.assertNotEqual(block2_a, block2_b) +@decorate_test_methods(ignore_pulse_deprecation_warnings) class TestParametrizedBlockOperation(BaseTestBlock): """Test fundamental operation with parametrization.""" + @ignore_pulse_deprecation_warnings def setUp(self): super().setUp() @@ -719,6 +728,7 @@ def test_parametrized_context(self): self.assertScheduleEqual(block, ref_sched) +@decorate_test_methods(ignore_pulse_deprecation_warnings) class TestBlockFilter(BaseTestBlock): """Test ScheduleBlock filtering methods.""" diff --git a/test/python/pulse/test_builder.py b/test/python/pulse/test_builder.py index 72a6de11ae08..9501d176c9e0 100644 --- a/test/python/pulse/test_builder.py +++ b/test/python/pulse/test_builder.py @@ -23,11 +23,14 @@ from qiskit.pulse import library, instructions from qiskit.pulse.exceptions import PulseError from test import QiskitTestCase # pylint: disable=wrong-import-order +from qiskit.utils.deprecate_pulse import decorate_test_methods, ignore_pulse_deprecation_warnings +@decorate_test_methods(ignore_pulse_deprecation_warnings) class TestBuilder(QiskitTestCase): """Test the pulse builder context.""" + @ignore_pulse_deprecation_warnings def setUp(self): super().setUp() with self.assertWarns(DeprecationWarning): @@ -44,6 +47,7 @@ def assertScheduleEqual(self, program, target): self.assertEqual(target_qobj_transform(program), target_qobj_transform(target)) +@decorate_test_methods(ignore_pulse_deprecation_warnings) class TestBuilderBase(TestBuilder): """Test builder base.""" @@ -132,6 +136,7 @@ def test_unknown_string_identifier(self): pass +@decorate_test_methods(ignore_pulse_deprecation_warnings) class TestContexts(TestBuilder): """Test builder contexts.""" @@ -255,6 +260,7 @@ def test_phase_compensated_frequency_offset(self): self.assertScheduleEqual(schedule, reference) +@decorate_test_methods(ignore_pulse_deprecation_warnings) class TestChannels(TestBuilder): """Test builder channels.""" @@ -279,6 +285,7 @@ def test_control_channel(self): self.assertEqual(pulse.control_channels(0, 1)[0], pulse.ControlChannel(0)) +@decorate_test_methods(ignore_pulse_deprecation_warnings) class TestInstructions(TestBuilder): """Test builder instructions.""" @@ -457,6 +464,7 @@ def test_snapshot(self): self.assertScheduleEqual(schedule, reference) +@decorate_test_methods(ignore_pulse_deprecation_warnings) class TestDirectives(TestBuilder): """Test builder directives.""" @@ -538,6 +546,7 @@ def test_trivial_barrier(self): self.assertEqual(schedule, pulse.ScheduleBlock()) +@decorate_test_methods(ignore_pulse_deprecation_warnings) class TestUtilities(TestBuilder): """Test builder utilities.""" @@ -627,6 +636,7 @@ def test_seconds_to_samples_array(self): np.testing.assert_allclose(pulse.seconds_to_samples(times), np.array([100, 200, 300])) +@decorate_test_methods(ignore_pulse_deprecation_warnings) class TestMacros(TestBuilder): """Test builder macros.""" @@ -694,7 +704,8 @@ def test_measure_all(self): backend = Fake127QPulseV1() num_qubits = backend.configuration().num_qubits with pulse.build(backend) as schedule: - regs = pulse.measure_all() + with self.assertWarns(DeprecationWarning): + regs = pulse.measure_all() reference = backend.defaults().instruction_schedule_map.get( "measure", list(range(num_qubits)) @@ -749,6 +760,7 @@ def test_delay_qubits(self): self.assertScheduleEqual(schedule, reference) +@decorate_test_methods(ignore_pulse_deprecation_warnings) class TestBuilderComposition(TestBuilder): """Test more sophisticated composite builder examples.""" @@ -772,7 +784,8 @@ def get_sched(qubit_idx: [int], backend): "stop supporting inputs of type `BackendV1`", ): transpiled = compiler.transpile(qc, backend=backend, optimization_level=1) - return compiler.schedule(transpiled, backend) + with self.assertWarns(DeprecationWarning): + return compiler.schedule(transpiled, backend) with pulse.build(self.backend) as schedule: with pulse.align_sequential(): @@ -798,7 +811,8 @@ def get_sched(qubit_idx: [int], backend): "stop supporting inputs of type `BackendV1`", ): single_u2_qc = compiler.transpile(single_u2_qc, self.backend, optimization_level=1) - single_u2_sched = compiler.schedule(single_u2_qc, self.backend) + with self.assertWarns(DeprecationWarning): + single_u2_sched = compiler.schedule(single_u2_qc, self.backend) # sequential context sequential_reference = pulse.Schedule() @@ -828,7 +842,8 @@ def get_sched(qubit_idx: [int], backend): "stop supporting inputs of type `BackendV1`", ): triple_u2_qc = compiler.transpile(triple_u2_qc, self.backend, optimization_level=1) - align_left_reference = compiler.schedule(triple_u2_qc, self.backend, method="alap") + with self.assertWarns(DeprecationWarning): + align_left_reference = compiler.schedule(triple_u2_qc, self.backend, method="alap") # measurement measure_reference = macros.measure( @@ -846,6 +861,7 @@ def get_sched(qubit_idx: [int], backend): self.assertScheduleEqual(schedule, reference) +@decorate_test_methods(ignore_pulse_deprecation_warnings) class TestSubroutineCall(TestBuilder): """Test for calling subroutine.""" diff --git a/test/python/pulse/test_builder_v2.py b/test/python/pulse/test_builder_v2.py index 79d3ac5b6020..29248f6179ca 100644 --- a/test/python/pulse/test_builder_v2.py +++ b/test/python/pulse/test_builder_v2.py @@ -22,18 +22,21 @@ from qiskit.providers.fake_provider import GenericBackendV2 from qiskit.pulse import instructions from test import QiskitTestCase # pylint: disable=wrong-import-order +from qiskit.utils.deprecate_pulse import decorate_test_methods, ignore_pulse_deprecation_warnings from ..legacy_cmaps import MUMBAI_CMAP +@decorate_test_methods(ignore_pulse_deprecation_warnings) class TestBuilderV2(QiskitTestCase): """Test the pulse builder context with backendV2.""" def setUp(self): super().setUp() - self.backend = GenericBackendV2( - num_qubits=27, coupling_map=MUMBAI_CMAP, calibrate_instructions=True, seed=42 - ) + with self.assertWarns(DeprecationWarning): + self.backend = GenericBackendV2( + num_qubits=27, coupling_map=MUMBAI_CMAP, calibrate_instructions=True, seed=42 + ) def assertScheduleEqual(self, program, target): """Assert an error when two pulse programs are not equal. @@ -43,6 +46,7 @@ def assertScheduleEqual(self, program, target): self.assertEqual(target_qobj_transform(program), target_qobj_transform(target)) +@decorate_test_methods(ignore_pulse_deprecation_warnings) class TestContextsV2(TestBuilderV2): """Test builder contexts.""" @@ -64,30 +68,36 @@ def test_phase_compensated_frequency_offset(self): self.assertScheduleEqual(schedule, reference) +@decorate_test_methods(ignore_pulse_deprecation_warnings) class TestChannelsV2(TestBuilderV2): """Test builder channels.""" def test_drive_channel(self): """Text context builder drive channel.""" with pulse.build(self.backend): - self.assertEqual(pulse.drive_channel(0), pulse.DriveChannel(0)) + with self.assertWarns(DeprecationWarning): + self.assertEqual(pulse.drive_channel(0), pulse.DriveChannel(0)) def test_measure_channel(self): """Text context builder measure channel.""" with pulse.build(self.backend): - self.assertEqual(pulse.measure_channel(0), pulse.MeasureChannel(0)) + with self.assertWarns(DeprecationWarning): + self.assertEqual(pulse.measure_channel(0), pulse.MeasureChannel(0)) def test_acquire_channel(self): """Text context builder acquire channel.""" - with pulse.build(self.backend): - self.assertEqual(pulse.acquire_channel(0), pulse.AcquireChannel(0)) + with self.assertWarns(DeprecationWarning): + with pulse.build(self.backend): + self.assertEqual(pulse.acquire_channel(0), pulse.AcquireChannel(0)) def test_control_channel(self): """Text context builder control channel.""" with pulse.build(self.backend): - self.assertEqual(pulse.control_channels(0, 1)[0], pulse.ControlChannel(0)) + with self.assertWarns(DeprecationWarning): + self.assertEqual(pulse.control_channels(0, 1)[0], pulse.ControlChannel(0)) +@decorate_test_methods(ignore_pulse_deprecation_warnings) class TestDirectivesV2(TestBuilderV2): """Test builder directives.""" @@ -100,7 +110,8 @@ def test_barrier_on_qubits(self): 2 """ with pulse.build(self.backend) as schedule: - pulse.barrier(0, 1) + with self.assertWarns(DeprecationWarning): + pulse.barrier(0, 1) reference = pulse.ScheduleBlock() reference += directives.RelativeBarrier( pulse.DriveChannel(0), @@ -119,6 +130,7 @@ def test_barrier_on_qubits(self): self.assertEqual(schedule, reference) +@decorate_test_methods(ignore_pulse_deprecation_warnings) class TestUtilitiesV2(TestBuilderV2): """Test builder utilities.""" @@ -130,7 +142,8 @@ def test_active_backend(self): def test_qubit_channels(self): """Test getting the qubit channels of the active builder's backend.""" with pulse.build(self.backend): - qubit_channels = pulse.qubit_channels(0) + with self.assertWarns(DeprecationWarning): + qubit_channels = pulse.qubit_channels(0) self.assertEqual( qubit_channels, @@ -187,6 +200,7 @@ def test_seconds_to_samples_array(self): np.testing.assert_allclose(pulse.seconds_to_samples(times), np.array([100, 200, 300])) +@decorate_test_methods(ignore_pulse_deprecation_warnings) class TestMacrosV2(TestBuilderV2): """Test builder macros with backendV2.""" @@ -195,12 +209,14 @@ def test_macro(self): @pulse.macro def nested(a): - pulse.play(pulse.Gaussian(100, a, 20), pulse.drive_channel(0)) + with self.assertWarns(DeprecationWarning): + pulse.play(pulse.Gaussian(100, a, 20), pulse.drive_channel(0)) return a * 2 @pulse.macro def test(): - pulse.play(pulse.Constant(100, 1.0), pulse.drive_channel(0)) + with self.assertWarns(DeprecationWarning): + pulse.play(pulse.Constant(100, 1.0), pulse.drive_channel(0)) output = nested(0.5) return output @@ -217,7 +233,8 @@ def test(): def test_measure(self): """Test utility function - measure with backendV2.""" with pulse.build(self.backend) as schedule: - reg = pulse.measure(0) + with self.assertWarns(DeprecationWarning): + reg = pulse.measure(0) self.assertEqual(reg, pulse.MemorySlot(0)) @@ -228,7 +245,8 @@ def test_measure(self): def test_measure_multi_qubits(self): """Test utility function - measure with multi qubits with backendV2.""" with pulse.build(self.backend) as schedule: - regs = pulse.measure([0, 1]) + with self.assertWarns(DeprecationWarning): + regs = pulse.measure([0, 1]) self.assertListEqual(regs, [pulse.MemorySlot(0), pulse.MemorySlot(1)]) @@ -241,7 +259,8 @@ def test_measure_multi_qubits(self): def test_measure_all(self): """Test utility function - measure with backendV2..""" with pulse.build(self.backend) as schedule: - regs = pulse.measure_all() + with self.assertWarns(DeprecationWarning): + regs = pulse.measure_all() self.assertEqual(regs, [pulse.MemorySlot(i) for i in range(self.backend.num_qubits)]) reference = macros.measure_all(self.backend) @@ -251,7 +270,8 @@ def test_measure_all(self): def test_delay_qubit(self): """Test delaying on a qubit macro.""" with pulse.build(self.backend) as schedule: - pulse.delay_qubits(10, 0) + with self.assertWarns(DeprecationWarning): + pulse.delay_qubits(10, 0) d0 = pulse.DriveChannel(0) m0 = pulse.MeasureChannel(0) @@ -271,7 +291,8 @@ def test_delay_qubit(self): def test_delay_qubits(self): """Test delaying on multiple qubits with backendV2 to make sure we don't insert delays twice.""" with pulse.build(self.backend) as schedule: - pulse.delay_qubits(10, 0, 1) + with self.assertWarns(DeprecationWarning): + pulse.delay_qubits(10, 0, 1) d0 = pulse.DriveChannel(0) d1 = pulse.DriveChannel(1) diff --git a/test/python/pulse/test_calibration_entries.py b/test/python/pulse/test_calibration_entries.py index cc31789ef683..6a112ab854d5 100644 --- a/test/python/pulse/test_calibration_entries.py +++ b/test/python/pulse/test_calibration_entries.py @@ -33,8 +33,10 @@ from qiskit.qobj.converters.pulse_instruction import QobjToInstructionConverter from qiskit.qobj.pulse_qobj import PulseLibraryItem, PulseQobjInstruction from test import QiskitTestCase # pylint: disable=wrong-import-order +from qiskit.utils.deprecate_pulse import decorate_test_methods, ignore_pulse_deprecation_warnings +@decorate_test_methods(ignore_pulse_deprecation_warnings) class TestSchedule(QiskitTestCase): """Test case for the ScheduleDef.""" @@ -181,6 +183,7 @@ def test_equality(self): self.assertNotEqual(entry1, entry2) +@decorate_test_methods(ignore_pulse_deprecation_warnings) class TestCallable(QiskitTestCase): """Test case for the CallableDef.""" @@ -276,6 +279,7 @@ def factory2(): self.assertNotEqual(entry1, entry2) +@decorate_test_methods(ignore_pulse_deprecation_warnings) class TestPulseQobj(QiskitTestCase): """Test case for the PulseQobjDef.""" @@ -421,13 +425,16 @@ def test_equality(self): ) ] - entry1 = PulseQobjDef(name="my_gate1") + with self.assertWarns(DeprecationWarning): + entry1 = PulseQobjDef(name="my_gate1") entry1.define(serialized_program1) - entry2 = PulseQobjDef(name="my_gate2") + with self.assertWarns(DeprecationWarning): + entry2 = PulseQobjDef(name="my_gate2") entry2.define(serialized_program2) - entry3 = PulseQobjDef(name="my_gate3") + with self.assertWarns(DeprecationWarning): + entry3 = PulseQobjDef(name="my_gate3") entry3.define(serialized_program1) self.assertEqual(entry1, entry3) @@ -450,7 +457,7 @@ def test_equality_with_schedule(self): parameters={"amp": 0.1, "duration": 10}, ) ] - entry1 = PulseQobjDef(name="qobj_entry") + entry1 = PulseQobjDef(name="qobj_entry") entry1.define(serialized_program) program = Schedule() @@ -483,7 +490,8 @@ def test_calibration_missing_waveform(self): ch="d0", ) ] - entry = PulseQobjDef(name="qobj_entry") + with self.assertWarns(DeprecationWarning): + entry = PulseQobjDef(name="qobj_entry") entry.define(serialized_program) # This is pulse qobj before parsing it diff --git a/test/python/pulse/test_channels.py b/test/python/pulse/test_channels.py index 59c4d15bf67b..ed104bd6b3a1 100644 --- a/test/python/pulse/test_channels.py +++ b/test/python/pulse/test_channels.py @@ -28,6 +28,7 @@ PulseError, ) from test import QiskitTestCase # pylint: disable=wrong-import-order +from qiskit.utils.deprecate_pulse import decorate_test_methods, ignore_pulse_deprecation_warnings class TestChannel(QiskitTestCase): @@ -48,6 +49,7 @@ def test_cannot_be_instantiated(self): PulseChannel(0) +@decorate_test_methods(ignore_pulse_deprecation_warnings) class TestAcquireChannel(QiskitTestCase): """AcquireChannel tests.""" @@ -69,6 +71,7 @@ def test_channel_hash(self): self.assertEqual(hash_1, hash_2) +@decorate_test_methods(ignore_pulse_deprecation_warnings) class TestClassicalIOChannel(QiskitTestCase): """Test base classical IO channel.""" @@ -78,6 +81,7 @@ def test_cannot_be_instantiated(self): ClassicalIOChannel(0) +@decorate_test_methods(ignore_pulse_deprecation_warnings) class TestMemorySlot(QiskitTestCase): """MemorySlot tests.""" @@ -97,6 +101,7 @@ def test_validation(self): MemorySlot(-1) +@decorate_test_methods(ignore_pulse_deprecation_warnings) class TestRegisterSlot(QiskitTestCase): """RegisterSlot tests.""" @@ -116,6 +121,7 @@ def test_validation(self): RegisterSlot(-1) +@decorate_test_methods(ignore_pulse_deprecation_warnings) class TestSnapshotChannel(QiskitTestCase): """SnapshotChannel tests.""" @@ -128,6 +134,7 @@ def test_default(self): self.assertTrue(isinstance(snapshot_channel, ClassicalIOChannel)) +@decorate_test_methods(ignore_pulse_deprecation_warnings) class TestDriveChannel(QiskitTestCase): """DriveChannel tests.""" @@ -146,6 +153,7 @@ def test_validation(self): DriveChannel(-1) +@decorate_test_methods(ignore_pulse_deprecation_warnings) class TestControlChannel(QiskitTestCase): """ControlChannel tests.""" @@ -164,6 +172,7 @@ def test_validation(self): ControlChannel(-1) +@decorate_test_methods(ignore_pulse_deprecation_warnings) class TestMeasureChannel(QiskitTestCase): """MeasureChannel tests.""" diff --git a/test/python/pulse/test_experiment_configurations.py b/test/python/pulse/test_experiment_configurations.py index 8d6a93b39eac..8702ba2d1cf5 100644 --- a/test/python/pulse/test_experiment_configurations.py +++ b/test/python/pulse/test_experiment_configurations.py @@ -18,6 +18,7 @@ from qiskit.pulse.exceptions import PulseError from qiskit.pulse import LoConfig, LoRange, Kernel, Discriminator from test import QiskitTestCase # pylint: disable=wrong-import-order +from qiskit.utils.deprecate_pulse import decorate_test_methods, ignore_pulse_deprecation_warnings class TestLoRange(QiskitTestCase): @@ -40,6 +41,7 @@ def test_properties_includes_and_eq(self): self.assertFalse(lo_range_1 == lo_range_3) +@decorate_test_methods(ignore_pulse_deprecation_warnings) class TestLoConfig(QiskitTestCase): """LoConfig tests.""" diff --git a/test/python/pulse/test_instruction_schedule_map.py b/test/python/pulse/test_instruction_schedule_map.py index d1610d7ebcc0..1b3d9e31cb6c 100644 --- a/test/python/pulse/test_instruction_schedule_map.py +++ b/test/python/pulse/test_instruction_schedule_map.py @@ -35,8 +35,10 @@ from qiskit.qobj.converters import QobjToInstructionConverter from qiskit.providers.fake_provider import FakeOpenPulse2Q, Fake7QPulseV1 from test import QiskitTestCase # pylint: disable=wrong-import-order +from qiskit.utils.deprecate_pulse import decorate_test_methods, ignore_pulse_deprecation_warnings +@decorate_test_methods(ignore_pulse_deprecation_warnings) class TestInstructionScheduleMap(QiskitTestCase): """Test the InstructionScheduleMap.""" @@ -537,7 +539,7 @@ def test_two_instmaps_equal(self): """Test eq method when two instmaps are identical.""" with self.assertWarns(DeprecationWarning): backend = Fake7QPulseV1() - instmap1 = backend.defaults().instruction_schedule_map + instmap1 = backend.defaults().instruction_schedule_map instmap2 = copy.deepcopy(instmap1) self.assertEqual(instmap1, instmap2) @@ -546,7 +548,7 @@ def test_two_instmaps_different(self): """Test eq method when two instmaps are not identical.""" with self.assertWarns(DeprecationWarning): backend = Fake7QPulseV1() - instmap1 = backend.defaults().instruction_schedule_map + instmap1 = backend.defaults().instruction_schedule_map instmap2 = copy.deepcopy(instmap1) # override one of instruction @@ -558,7 +560,7 @@ def test_instmap_picklable(self): """Test if instmap can be pickled.""" with self.assertWarns(DeprecationWarning): backend = Fake7QPulseV1() - instmap = backend.defaults().instruction_schedule_map + instmap = backend.defaults().instruction_schedule_map ser_obj = pickle.dumps(instmap) deser_instmap = pickle.loads(ser_obj) @@ -574,7 +576,7 @@ def test_instmap_picklable_with_arguments(self): """ with self.assertWarns(DeprecationWarning): backend = Fake7QPulseV1() - instmap = backend.defaults().instruction_schedule_map + instmap = backend.defaults().instruction_schedule_map param1 = Parameter("P1") param2 = Parameter("P2") @@ -596,7 +598,7 @@ def test_check_backend_provider_cals(self): """Test if schedules provided by backend provider is distinguishable.""" with self.assertWarns(DeprecationWarning): backend = FakeOpenPulse2Q() - instmap = backend.defaults().instruction_schedule_map + instmap = backend.defaults().instruction_schedule_map publisher = instmap.get("u1", (0,), P0=0).metadata["publisher"] self.assertEqual(publisher, CalibrationPublisher.BACKEND_PROVIDER) @@ -605,7 +607,7 @@ def test_check_user_cals(self): """Test if schedules provided by user is distinguishable.""" with self.assertWarns(DeprecationWarning): backend = FakeOpenPulse2Q() - instmap = backend.defaults().instruction_schedule_map + instmap = backend.defaults().instruction_schedule_map test_u1 = Schedule() test_u1 += ShiftPhase(Parameter("P0"), DriveChannel(0)) @@ -619,7 +621,7 @@ def test_has_custom_gate(self): """Test method to check custom gate.""" with self.assertWarns(DeprecationWarning): backend = FakeOpenPulse2Q() - instmap = backend.defaults().instruction_schedule_map + instmap = backend.defaults().instruction_schedule_map self.assertFalse(instmap.has_custom_gate()) diff --git a/test/python/pulse/test_instructions.py b/test/python/pulse/test_instructions.py index f0bdd165db08..1eaf0f928499 100644 --- a/test/python/pulse/test_instructions.py +++ b/test/python/pulse/test_instructions.py @@ -17,8 +17,10 @@ from qiskit import circuit from qiskit.pulse import channels, configuration, instructions, library, exceptions from test import QiskitTestCase # pylint: disable=wrong-import-order +from qiskit.utils.deprecate_pulse import decorate_test_methods, ignore_pulse_deprecation_warnings +@decorate_test_methods(ignore_pulse_deprecation_warnings) class TestAcquire(QiskitTestCase): """Acquisition tests.""" @@ -85,6 +87,7 @@ def test_instructions_hash(self): self.assertEqual(hash_1, hash_2) +@decorate_test_methods(ignore_pulse_deprecation_warnings) class TestDelay(QiskitTestCase): """Delay tests.""" @@ -121,6 +124,7 @@ def test_operator_delay(self): self.assertEqual(op_delay, op_identity) +@decorate_test_methods(ignore_pulse_deprecation_warnings) class TestSetFrequency(QiskitTestCase): """Set frequency tests.""" @@ -155,6 +159,7 @@ def test_parameter_expression(self): self.assertSetEqual(instr.parameters, {p1, p2}) +@decorate_test_methods(ignore_pulse_deprecation_warnings) class TestShiftFrequency(QiskitTestCase): """Shift frequency tests.""" @@ -191,6 +196,7 @@ def test_parameter_expression(self): self.assertSetEqual(instr.parameters, {p1, p2}) +@decorate_test_methods(ignore_pulse_deprecation_warnings) class TestSetPhase(QiskitTestCase): """Test the instruction construction.""" @@ -226,6 +232,7 @@ def test_parameter_expression(self): self.assertSetEqual(instr.parameters, {p1, p2}) +@decorate_test_methods(ignore_pulse_deprecation_warnings) class TestShiftPhase(QiskitTestCase): """Test the instruction construction.""" @@ -261,6 +268,7 @@ def test_parameter_expression(self): self.assertSetEqual(instr.parameters, {p1, p2}) +@decorate_test_methods(ignore_pulse_deprecation_warnings) class TestSnapshot(QiskitTestCase): """Snapshot tests.""" @@ -276,9 +284,11 @@ def test_default(self): self.assertEqual(repr(snapshot), "Snapshot(test_name, state, name='test_name')") +@decorate_test_methods(ignore_pulse_deprecation_warnings) class TestPlay(QiskitTestCase): """Play tests.""" + @ignore_pulse_deprecation_warnings def setUp(self): """Setup play tests.""" super().setUp() @@ -304,6 +314,7 @@ def test_play_non_pulse_ch_raises(self): instructions.Play(self.pulse_op, channels.AcquireChannel(0)) +@decorate_test_methods(ignore_pulse_deprecation_warnings) class TestDirectives(QiskitTestCase): """Test pulse directives.""" diff --git a/test/python/pulse/test_macros.py b/test/python/pulse/test_macros.py index 6d87320cf480..c1f0b93339ab 100644 --- a/test/python/pulse/test_macros.py +++ b/test/python/pulse/test_macros.py @@ -26,11 +26,14 @@ from qiskit.pulse.exceptions import PulseError from qiskit.providers.fake_provider import FakeOpenPulse2Q, Fake27QPulseV1, GenericBackendV2 from test import QiskitTestCase # pylint: disable=wrong-import-order +from qiskit.utils.deprecate_pulse import decorate_test_methods, ignore_pulse_deprecation_warnings +@decorate_test_methods(ignore_pulse_deprecation_warnings) class TestMeasure(QiskitTestCase): """Pulse measure macro.""" + @ignore_pulse_deprecation_warnings def setUp(self): super().setUp() with self.assertWarns(DeprecationWarning): @@ -38,11 +41,12 @@ def setUp(self): self.backend_v1 = Fake27QPulseV1() self.inst_map = self.backend.defaults().instruction_schedule_map - self.backend_v2 = GenericBackendV2( - num_qubits=27, - calibrate_instructions=self.backend_v1.defaults().instruction_schedule_map, - seed=42, - ) + with self.assertWarns(DeprecationWarning): + self.backend_v2 = GenericBackendV2( + num_qubits=27, + calibrate_instructions=self.backend_v1.defaults().instruction_schedule_map, + seed=42, + ) def test_measure(self): """Test macro - measure.""" @@ -101,19 +105,21 @@ def test_fail_measure(self): def test_measure_v2(self): """Test macro - measure with backendV2.""" sched = macros.measure(qubits=[0], backend=self.backend_v2) - expected = self.backend_v2.target.get_calibration("measure", (0,)).filter( - channels=[MeasureChannel(0), AcquireChannel(0)] - ) + with self.assertWarns(DeprecationWarning): + expected = self.backend_v2.target.get_calibration("measure", (0,)).filter( + channels=[MeasureChannel(0), AcquireChannel(0)] + ) self.assertEqual(sched.instructions, expected.instructions) def test_measure_v2_sched_with_qubit_mem_slots(self): """Test measure with backendV2 and custom qubit_mem_slots.""" sched = macros.measure(qubits=[0], backend=self.backend_v2, qubit_mem_slots={0: 2}) - expected = self.backend_v2.target.get_calibration("measure", (0,)).filter( - channels=[ - MeasureChannel(0), - ] - ) + with self.assertWarns(DeprecationWarning): + expected = self.backend_v2.target.get_calibration("measure", (0,)).filter( + channels=[ + MeasureChannel(0), + ] + ) measure_duration = expected.filter(instruction_types=[Play]).duration expected += Acquire(measure_duration, AcquireChannel(0), MemorySlot(2)) self.assertEqual(sched.instructions, expected.instructions) @@ -126,11 +132,12 @@ def test_measure_v2_sched_with_meas_map(self): sched_with_meas_map_dict = macros.measure( qubits=[0], backend=self.backend_v2, meas_map={0: [0, 1], 1: [0, 1]} ) - expected = self.backend_v2.target.get_calibration("measure", (0,)).filter( - channels=[ - MeasureChannel(0), - ] - ) + with self.assertWarns(DeprecationWarning): + expected = self.backend_v2.target.get_calibration("measure", (0,)).filter( + channels=[ + MeasureChannel(0), + ] + ) measure_duration = expected.filter(instruction_types=[Play]).duration expected += Acquire(measure_duration, AcquireChannel(0), MemorySlot(0)) self.assertEqual(sched_with_meas_map_list.instructions, expected.instructions) @@ -139,16 +146,17 @@ def test_measure_v2_sched_with_meas_map(self): def test_multiple_measure_v2(self): """Test macro - multiple qubit measure with backendV2.""" sched = macros.measure(qubits=[0, 1], backend=self.backend_v2) - expected = self.backend_v2.target.get_calibration("measure", (0,)).filter( - channels=[ - MeasureChannel(0), - ] - ) - expected += self.backend_v2.target.get_calibration("measure", (1,)).filter( - channels=[ - MeasureChannel(1), - ] - ) + with self.assertWarns(DeprecationWarning): + expected = self.backend_v2.target.get_calibration("measure", (0,)).filter( + channels=[ + MeasureChannel(0), + ] + ) + expected += self.backend_v2.target.get_calibration("measure", (1,)).filter( + channels=[ + MeasureChannel(1), + ] + ) measure_duration = expected.filter(instruction_types=[Play]).duration expected += Acquire(measure_duration, AcquireChannel(0), MemorySlot(0)) expected += Acquire(measure_duration, AcquireChannel(1), MemorySlot(1)) @@ -210,19 +218,22 @@ def test_output_with_multiple_measure_v1_and_measure_v2(self): self.assertEqual(sched_measure_v1.instructions, sched_measure_v2.instructions) +@decorate_test_methods(ignore_pulse_deprecation_warnings) class TestMeasureAll(QiskitTestCase): """Pulse measure all macro.""" + @ignore_pulse_deprecation_warnings def setUp(self): super().setUp() with self.assertWarns(DeprecationWarning): self.backend_v1 = FakeOpenPulse2Q() self.inst_map = self.backend_v1.defaults().instruction_schedule_map - self.backend_v2 = GenericBackendV2( - num_qubits=2, - calibrate_instructions=self.backend_v1.defaults().instruction_schedule_map, - seed=42, - ) + with self.assertWarns(DeprecationWarning): + self.backend_v2 = GenericBackendV2( + num_qubits=2, + calibrate_instructions=self.backend_v1.defaults().instruction_schedule_map, + seed=42, + ) def test_measure_all(self): """Test measure_all function.""" diff --git a/test/python/pulse/test_parameter_manager.py b/test/python/pulse/test_parameter_manager.py index 0b91aaeaab4a..32c0e5a9d907 100644 --- a/test/python/pulse/test_parameter_manager.py +++ b/test/python/pulse/test_parameter_manager.py @@ -27,11 +27,14 @@ from qiskit.pulse.transforms import AlignEquispaced, AlignLeft, inline_subroutines from qiskit.pulse.utils import format_parameter_value from test import QiskitTestCase # pylint: disable=wrong-import-order +from qiskit.utils.deprecate_pulse import decorate_test_methods, ignore_pulse_deprecation_warnings +@decorate_test_methods(ignore_pulse_deprecation_warnings) class ParameterTestBase(QiskitTestCase): """A base class for parameter manager unittest, providing test schedule.""" + @ignore_pulse_deprecation_warnings def setUp(self): """Just some useful, reusable Parameters, constants, schedules.""" super().setUp() @@ -100,6 +103,7 @@ def setUp(self): self.test_sched = long_schedule +@decorate_test_methods(ignore_pulse_deprecation_warnings) class TestParameterGetter(ParameterTestBase): """Test getting parameters.""" @@ -183,6 +187,7 @@ def test_get_parameter_from_complex_schedule(self): self.assertEqual(len(visitor.parameters), 17) +@decorate_test_methods(ignore_pulse_deprecation_warnings) class TestParameterSetter(ParameterTestBase): """Test setting parameters.""" @@ -451,6 +456,7 @@ def test_set_parameter_to_complex_schedule(self): self.assertEqual(assigned, ref_obj) +@decorate_test_methods(ignore_pulse_deprecation_warnings) class TestAssignFromProgram(QiskitTestCase): """Test managing parameters from programs. Parameter manager is implicitly called.""" @@ -554,6 +560,7 @@ def test_pulse_assignment_with_parameter_names(self): self.assertEqual(sched1.instructions[3][1].phase, 1.57) +@decorate_test_methods(ignore_pulse_deprecation_warnings) class TestScheduleTimeslots(QiskitTestCase): """Test for edge cases of timing overlap on parametrized channels. @@ -632,6 +639,7 @@ def test_cannot_build_schedule_with_unassigned_duration(self): @ddt.ddt +@decorate_test_methods(ignore_pulse_deprecation_warnings) class TestFormatParameter(QiskitTestCase): """Test format_parameter_value function.""" diff --git a/test/python/pulse/test_parser.py b/test/python/pulse/test_parser.py index 8fb491b9da74..d9a3f7dd9a7a 100644 --- a/test/python/pulse/test_parser.py +++ b/test/python/pulse/test_parser.py @@ -15,8 +15,10 @@ from qiskit.pulse.parser import parse_string_expr from qiskit.pulse.exceptions import PulseError from test import QiskitTestCase # pylint: disable=wrong-import-order +from qiskit.utils.deprecate_pulse import decorate_test_methods, ignore_pulse_deprecation_warnings +@decorate_test_methods(ignore_pulse_deprecation_warnings) class TestInstructionToQobjConverter(QiskitTestCase): """Expression parser test.""" diff --git a/test/python/pulse/test_pulse_lib.py b/test/python/pulse/test_pulse_lib.py index 9c57579d0bf1..fa60c2adb3e5 100644 --- a/test/python/pulse/test_pulse_lib.py +++ b/test/python/pulse/test_pulse_lib.py @@ -39,8 +39,10 @@ ) from qiskit.pulse import functional_pulse, PulseError from test import QiskitTestCase # pylint: disable=wrong-import-order +from qiskit.utils.deprecate_pulse import decorate_test_methods, ignore_pulse_deprecation_warnings +@decorate_test_methods(ignore_pulse_deprecation_warnings) class TestWaveform(QiskitTestCase): """Waveform tests.""" @@ -122,6 +124,7 @@ def test_pulse_limits(self): self.fail("Waveform incorrectly failed to approximately unit norm samples.") +@decorate_test_methods(ignore_pulse_deprecation_warnings) class TestSymbolicPulses(QiskitTestCase): """Tests for all subclasses of SymbolicPulse.""" @@ -789,46 +792,43 @@ def test_gaussian_deprecated_type_check(self): gaussian_pulse = Gaussian(160, 0.1, 40) self.assertTrue(isinstance(gaussian_pulse, SymbolicPulse)) - with self.assertWarns(PendingDeprecationWarning): - self.assertTrue(isinstance(gaussian_pulse, Gaussian)) - self.assertFalse(isinstance(gaussian_pulse, GaussianSquare)) - self.assertFalse(isinstance(gaussian_pulse, Drag)) - self.assertFalse(isinstance(gaussian_pulse, Constant)) + self.assertTrue(isinstance(gaussian_pulse, Gaussian)) + self.assertFalse(isinstance(gaussian_pulse, GaussianSquare)) + self.assertFalse(isinstance(gaussian_pulse, Drag)) + self.assertFalse(isinstance(gaussian_pulse, Constant)) def test_gaussian_square_deprecated_type_check(self): """Test isinstance check works with deprecation.""" gaussian_square_pulse = GaussianSquare(800, 0.1, 64, 544) self.assertTrue(isinstance(gaussian_square_pulse, SymbolicPulse)) - with self.assertWarns(PendingDeprecationWarning): - self.assertFalse(isinstance(gaussian_square_pulse, Gaussian)) - self.assertTrue(isinstance(gaussian_square_pulse, GaussianSquare)) - self.assertFalse(isinstance(gaussian_square_pulse, Drag)) - self.assertFalse(isinstance(gaussian_square_pulse, Constant)) + self.assertFalse(isinstance(gaussian_square_pulse, Gaussian)) + self.assertTrue(isinstance(gaussian_square_pulse, GaussianSquare)) + self.assertFalse(isinstance(gaussian_square_pulse, Drag)) + self.assertFalse(isinstance(gaussian_square_pulse, Constant)) def test_drag_deprecated_type_check(self): """Test isinstance check works with deprecation.""" drag_pulse = Drag(160, 0.1, 40, 1.5) self.assertTrue(isinstance(drag_pulse, SymbolicPulse)) - with self.assertWarns(PendingDeprecationWarning): - self.assertFalse(isinstance(drag_pulse, Gaussian)) - self.assertFalse(isinstance(drag_pulse, GaussianSquare)) - self.assertTrue(isinstance(drag_pulse, Drag)) - self.assertFalse(isinstance(drag_pulse, Constant)) + self.assertFalse(isinstance(drag_pulse, Gaussian)) + self.assertFalse(isinstance(drag_pulse, GaussianSquare)) + self.assertTrue(isinstance(drag_pulse, Drag)) + self.assertFalse(isinstance(drag_pulse, Constant)) def test_constant_deprecated_type_check(self): """Test isinstance check works with deprecation.""" constant_pulse = Constant(160, 0.1, 40, 1.5) self.assertTrue(isinstance(constant_pulse, SymbolicPulse)) - with self.assertWarns(PendingDeprecationWarning): - self.assertFalse(isinstance(constant_pulse, Gaussian)) - self.assertFalse(isinstance(constant_pulse, GaussianSquare)) - self.assertFalse(isinstance(constant_pulse, Drag)) - self.assertTrue(isinstance(constant_pulse, Constant)) + self.assertFalse(isinstance(constant_pulse, Gaussian)) + self.assertFalse(isinstance(constant_pulse, GaussianSquare)) + self.assertFalse(isinstance(constant_pulse, Drag)) + self.assertTrue(isinstance(constant_pulse, Constant)) +@decorate_test_methods(ignore_pulse_deprecation_warnings) class TestFunctionalPulse(QiskitTestCase): """Waveform tests.""" @@ -868,6 +868,7 @@ def local_gaussian(duration, amp, t0, sig): self.assertEqual(len(pulse_wf_inst.samples), _duration) +@decorate_test_methods(ignore_pulse_deprecation_warnings) class TestScalableSymbolicPulse(QiskitTestCase): """ScalableSymbolicPulse tests""" diff --git a/test/python/pulse/test_reference.py b/test/python/pulse/test_reference.py index 3d7603461756..94e4215d1b58 100644 --- a/test/python/pulse/test_reference.py +++ b/test/python/pulse/test_reference.py @@ -18,8 +18,10 @@ from qiskit.pulse import ScheduleBlock, builder from qiskit.pulse.transforms import inline_subroutines from test import QiskitTestCase # pylint: disable=wrong-import-order +from qiskit.utils.deprecate_pulse import decorate_test_methods, ignore_pulse_deprecation_warnings +@decorate_test_methods(ignore_pulse_deprecation_warnings) class TestReference(QiskitTestCase): """Test for basic behavior of reference mechanism.""" @@ -430,9 +432,11 @@ def test_assign_existing_reference(self): sched_z1.assign_references({("conflict_name",): sched_y1}) +@decorate_test_methods(ignore_pulse_deprecation_warnings) class TestSubroutineWithCXGate(QiskitTestCase): """Test called program scope with practical example of building fully parametrized CX gate.""" + @ignore_pulse_deprecation_warnings def setUp(self): super().setUp() diff --git a/test/python/pulse/test_samplers.py b/test/python/pulse/test_samplers.py index 4e6ab46737d6..59a8805c0c06 100644 --- a/test/python/pulse/test_samplers.py +++ b/test/python/pulse/test_samplers.py @@ -18,6 +18,7 @@ from qiskit.pulse import library from qiskit.pulse.library import samplers from test import QiskitTestCase # pylint: disable=wrong-import-order +from qiskit.utils.deprecate_pulse import decorate_test_methods, ignore_pulse_deprecation_warnings def linear(times: np.ndarray, m: float, b: float = 0.1) -> np.ndarray: @@ -32,6 +33,7 @@ def linear(times: np.ndarray, m: float, b: float = 0.1) -> np.ndarray: return m * times + b +@decorate_test_methods(ignore_pulse_deprecation_warnings) class TestSampler(QiskitTestCase): """Test continuous pulse function samplers.""" diff --git a/test/python/pulse/test_schedule.py b/test/python/pulse/test_schedule.py index 5e5676e7c2d9..0d96977aab5e 100644 --- a/test/python/pulse/test_schedule.py +++ b/test/python/pulse/test_schedule.py @@ -47,11 +47,14 @@ from qiskit.pulse.schedule import Schedule, _overlaps, _find_insertion_index from qiskit.providers.fake_provider import FakeOpenPulse2Q from test import QiskitTestCase # pylint: disable=wrong-import-order +from qiskit.utils.deprecate_pulse import decorate_test_methods, ignore_pulse_deprecation_warnings +@decorate_test_methods(ignore_pulse_deprecation_warnings) class BaseTestSchedule(QiskitTestCase): """Schedule tests.""" + @ignore_pulse_deprecation_warnings def setUp(self): super().setUp() @@ -65,6 +68,7 @@ def linear(duration, slope, intercept): self.config = FakeOpenPulse2Q().configuration() +@decorate_test_methods(ignore_pulse_deprecation_warnings) class TestScheduleBuilding(BaseTestSchedule): """Test construction of schedules.""" @@ -469,6 +473,7 @@ def test_inherit_from(self): self.assertDictEqual(new_sched.metadata, ref_metadata) +@decorate_test_methods(ignore_pulse_deprecation_warnings) class TestReplace(BaseTestSchedule): """Test schedule replacement.""" @@ -527,6 +532,7 @@ def test_replace_fails_on_overlap(self): sched.replace(old, new) +@decorate_test_methods(ignore_pulse_deprecation_warnings) class TestDelay(BaseTestSchedule): """Test Delay Instruction""" @@ -601,6 +607,7 @@ def test_delay_snapshot_channel(self): self.assertIsInstance(sched, Schedule) +@decorate_test_methods(ignore_pulse_deprecation_warnings) class TestScheduleFilter(BaseTestSchedule): """Test Schedule filtering methods""" @@ -882,6 +889,7 @@ def _filter_and_test_consistency(self, schedule: Schedule, *args, **kwargs): return filtered, excluded +@decorate_test_methods(ignore_pulse_deprecation_warnings) class TestScheduleEquality(BaseTestSchedule): """Test equality of schedules.""" @@ -945,6 +953,7 @@ def test_different_name_equal(self): ) +@decorate_test_methods(ignore_pulse_deprecation_warnings) class TestTimingUtils(QiskitTestCase): """Test the Schedule helper functions.""" diff --git a/test/python/pulse/test_transforms.py b/test/python/pulse/test_transforms.py index c16405cff4d1..fd7fd726d2ff 100644 --- a/test/python/pulse/test_transforms.py +++ b/test/python/pulse/test_transforms.py @@ -39,11 +39,14 @@ from qiskit.pulse.instructions import directives from qiskit.providers.fake_provider import FakeOpenPulse2Q from test import QiskitTestCase # pylint: disable=wrong-import-order +from qiskit.utils.deprecate_pulse import decorate_test_methods, ignore_pulse_deprecation_warnings +@decorate_test_methods(ignore_pulse_deprecation_warnings) class TestAlignMeasures(QiskitTestCase): """Test the helper function which aligns acquires.""" + @ignore_pulse_deprecation_warnings def setUp(self): super().setUp() with self.assertWarns(DeprecationWarning): @@ -198,9 +201,11 @@ def test_measurement_at_zero(self): self.assertEqual(time, 0) +@decorate_test_methods(ignore_pulse_deprecation_warnings) class TestAddImplicitAcquires(QiskitTestCase): """Test the helper function which makes implicit acquires explicit.""" + @ignore_pulse_deprecation_warnings def setUp(self): super().setUp() with self.assertWarns(DeprecationWarning): @@ -252,6 +257,7 @@ def test_multiple_acquires(self): self.assertEqual(sched.instructions, ((0, acq_q0), (2400, acq_q0))) +@decorate_test_methods(ignore_pulse_deprecation_warnings) class TestPad(QiskitTestCase): """Test padding of schedule with delays.""" @@ -388,6 +394,7 @@ def get_pulse_ids(schedules: List[Schedule]) -> Set[int]: return ids +@decorate_test_methods(ignore_pulse_deprecation_warnings) class TestCompressTransform(QiskitTestCase): """Compress function test.""" @@ -514,6 +521,7 @@ def test_multiple_schedules(self): self.assertEqual(len(compressed_pulse_ids), 2) +@decorate_test_methods(ignore_pulse_deprecation_warnings) class TestAlignSequential(QiskitTestCase): """Test sequential alignment transform.""" @@ -562,6 +570,7 @@ def test_align_sequential_with_barrier(self): self.assertEqual(schedule, reference) +@decorate_test_methods(ignore_pulse_deprecation_warnings) class TestAlignLeft(QiskitTestCase): """Test left alignment transform.""" @@ -625,6 +634,7 @@ def test_align_left_with_barrier(self): self.assertEqual(schedule, reference) +@decorate_test_methods(ignore_pulse_deprecation_warnings) class TestAlignRight(QiskitTestCase): """Test right alignment transform.""" @@ -689,6 +699,7 @@ def test_align_right_with_barrier(self): self.assertEqual(schedule, reference) +@decorate_test_methods(ignore_pulse_deprecation_warnings) class TestAlignEquispaced(QiskitTestCase): """Test equispaced alignment transform.""" @@ -767,6 +778,7 @@ def test_equispaced_with_multiple_channels_longer_duration(self): self.assertEqual(schedule, reference) +@decorate_test_methods(ignore_pulse_deprecation_warnings) class TestAlignFunc(QiskitTestCase): """Test callback alignment transform.""" @@ -812,6 +824,7 @@ def test_numerical_with_longer_duration(self): self.assertEqual(schedule, reference) +@decorate_test_methods(ignore_pulse_deprecation_warnings) class TestFlatten(QiskitTestCase): """Test flattening transform.""" @@ -861,6 +874,7 @@ def channels(self): return self.operands +@decorate_test_methods(ignore_pulse_deprecation_warnings) class TestRemoveDirectives(QiskitTestCase): """Test removing of directives.""" @@ -881,6 +895,7 @@ def test_remove_directives(self): self.assertEqual(schedule, reference) +@decorate_test_methods(ignore_pulse_deprecation_warnings) class TestRemoveTrivialBarriers(QiskitTestCase): """Test scheduling transforms.""" diff --git a/test/python/qobj/test_pulse_converter.py b/test/python/qobj/test_pulse_converter.py index 528d87244fe8..8f920eb96d80 100644 --- a/test/python/qobj/test_pulse_converter.py +++ b/test/python/qobj/test_pulse_converter.py @@ -68,7 +68,9 @@ def test_gaussian_pulse_instruction(self): angle = -0.7 with self.assertWarns(DeprecationWarning): converter = InstructionToQobjConverter(PulseQobjInstruction, meas_level=2) - instruction = Play(Gaussian(duration=25, sigma=15, amp=amp, angle=angle), DriveChannel(0)) + instruction = Play( + Gaussian(duration=25, sigma=15, amp=amp, angle=angle), DriveChannel(0) + ) with self.assertWarns(DeprecationWarning): valid_qobj = PulseQobjInstruction( name="parametric_pulse", @@ -85,10 +87,11 @@ def test_gaussian_square_pulse_instruction(self): converter = InstructionToQobjConverter(PulseQobjInstruction, meas_level=2) amp = 0.7 angle = -0.6 - instruction = Play( - GaussianSquare(duration=1500, sigma=15, amp=amp, width=1300, angle=angle), - MeasureChannel(1), - ) + with self.assertWarns(DeprecationWarning): + instruction = Play( + GaussianSquare(duration=1500, sigma=15, amp=amp, width=1300, angle=angle), + MeasureChannel(1), + ) with self.assertWarns(DeprecationWarning): valid_qobj = PulseQobjInstruction( @@ -109,7 +112,7 @@ def test_constant_pulse_instruction(self): """Test that parametric pulses are correctly converted to PulseQobjInstructions.""" with self.assertWarns(DeprecationWarning): converter = InstructionToQobjConverter(PulseQobjInstruction, meas_level=2) - instruction = Play(Constant(duration=25, amp=1, angle=np.pi), ControlChannel(2)) + instruction = Play(Constant(duration=25, amp=1, angle=np.pi), ControlChannel(2)) with self.assertWarns(DeprecationWarning): valid_qobj = PulseQobjInstruction( @@ -127,9 +130,9 @@ def test_drag_pulse_instruction(self): angle = -0.6 with self.assertWarns(DeprecationWarning): converter = InstructionToQobjConverter(PulseQobjInstruction, meas_level=2) - instruction = Play( - Drag(duration=25, sigma=15, amp=amp, angle=angle, beta=0.5), DriveChannel(0) - ) + instruction = Play( + Drag(duration=25, sigma=15, amp=amp, angle=angle, beta=0.5), DriveChannel(0) + ) with self.assertWarns(DeprecationWarning): valid_qobj = PulseQobjInstruction( @@ -188,16 +191,15 @@ def test_acquire(self): """Test converted qobj from AcquireInstruction.""" with self.assertWarns(DeprecationWarning): converter = InstructionToQobjConverter(PulseQobjInstruction, meas_level=2) - instruction = Acquire(10, AcquireChannel(0), MemorySlot(0), RegisterSlot(0)) - with self.assertWarns(DeprecationWarning): + instruction = Acquire(10, AcquireChannel(0), MemorySlot(0), RegisterSlot(0)) + valid_qobj = PulseQobjInstruction( name="acquire", t0=0, duration=10, qubits=[0], memory_slot=[0], register_slot=[0] ) self.assertEqual(converter(0, instruction), valid_qobj) - # without register - instruction = Acquire(10, AcquireChannel(0), MemorySlot(0)) - with self.assertWarns(DeprecationWarning): + # without register + instruction = Acquire(10, AcquireChannel(0), MemorySlot(0)) valid_qobj = PulseQobjInstruction( name="acquire", t0=0, duration=10, qubits=[0], memory_slot=[0] ) @@ -207,7 +209,7 @@ def test_snapshot(self): """Test converted qobj from Snapshot.""" with self.assertWarns(DeprecationWarning): converter = InstructionToQobjConverter(PulseQobjInstruction, meas_level=2) - instruction = Snapshot(label="label", snapshot_type="type") + instruction = Snapshot(label="label", snapshot_type="type") with self.assertWarns(DeprecationWarning): valid_qobj = PulseQobjInstruction(name="snapshot", t0=0, label="label", type="type") @@ -220,30 +222,31 @@ class TestQobjToInstructionConverter(QiskitTestCase): def setUp(self): super().setUp() - self.linear = Waveform(np.arange(0, 0.01), name="linear") with self.assertWarns(DeprecationWarning): + self.linear = Waveform(np.arange(0, 0.01), name="linear") self.pulse_library = [ PulseLibraryItem(name=self.linear.name, samples=self.linear.samples.tolist()) ] - self.converter = QobjToInstructionConverter(self.pulse_library, buffer=0) + with self.assertWarns(DeprecationWarning): + self.converter = QobjToInstructionConverter(self.pulse_library, buffer=0) self.num_qubits = 2 def test_drive_instruction(self): """Test converted qobj from PulseInstruction.""" - instruction = Play(self.linear, DriveChannel(0)) with self.assertWarns(DeprecationWarning): + instruction = Play(self.linear, DriveChannel(0)) qobj = PulseQobjInstruction(name="linear", ch="d0", t0=10) - converted_instruction = self.converter(qobj) - self.assertEqual(converted_instruction.instructions[0][-1], instruction) + converted_instruction = self.converter(qobj) + self.assertEqual(converted_instruction.instructions[0][-1], instruction) def test_parametric_pulses(self): """Test converted qobj from ParametricInstruction.""" - instruction = Play( - Gaussian(duration=25, sigma=15, amp=0.5, angle=np.pi / 2, name="pulse1"), - DriveChannel(0), - ) with self.assertWarns(DeprecationWarning): + instruction = Play( + Gaussian(duration=25, sigma=15, amp=0.5, angle=np.pi / 2, name="pulse1"), + DriveChannel(0), + ) qobj = PulseQobjInstruction( name="parametric_pulse", label="pulse1", @@ -252,7 +255,7 @@ def test_parametric_pulses(self): t0=0, parameters={"duration": 25, "sigma": 15, "amp": 0.5j}, ) - converted_instruction = self.converter(qobj) + converted_instruction = self.converter(qobj) self.assertEqual(converted_instruction.start_time, 0) self.assertEqual(converted_instruction.duration, 25) self.assertAlmostEqual(converted_instruction.instructions[0][-1], instruction) @@ -272,28 +275,28 @@ def test_parametric_pulses_no_label(self): t0=0, parameters={"duration": 25, "sigma": 15, "amp": -0.5 + 0.2j}, ) - converted_instruction = self.converter(qobj) + converted_instruction = self.converter(qobj) self.assertEqual(converted_instruction.instructions[0][-1].pulse.name, pulse_name) def test_frame_change(self): """Test converted qobj from ShiftPhase.""" with self.assertWarns(DeprecationWarning): qobj = PulseQobjInstruction(name="fc", ch="m0", t0=0, phase=0.1) - converted_instruction = self.converter(qobj) + converted_instruction = self.converter(qobj) - instruction = ShiftPhase(0.1, MeasureChannel(0)) + instruction = ShiftPhase(0.1, MeasureChannel(0)) self.assertEqual(converted_instruction.start_time, 0) self.assertEqual(converted_instruction.duration, 0) self.assertEqual(converted_instruction.instructions[0][-1], instruction) def test_parameterized_frame_change(self): """Test converted qobj from ShiftPhase.""" - instruction = ShiftPhase(4.0, MeasureChannel(0)) - shifted = instruction << 10 - with self.assertWarns(DeprecationWarning): + instruction = ShiftPhase(4.0, MeasureChannel(0)) + shifted = instruction << 10 + qobj = PulseQobjInstruction(name="fc", ch="m0", t0=10, phase="P1*2") - converted_instruction = self.converter(qobj) + converted_instruction = self.converter(qobj) self.assertIsInstance(converted_instruction, Schedule) @@ -308,9 +311,9 @@ def test_set_phase(self): """Test converted qobj from SetPhase.""" with self.assertWarns(DeprecationWarning): qobj = PulseQobjInstruction(name="setp", ch="m0", t0=0, phase=3.14) - converted_instruction = self.converter(qobj) + converted_instruction = self.converter(qobj) - instruction = SetPhase(3.14, MeasureChannel(0)) + instruction = SetPhase(3.14, MeasureChannel(0)) self.assertEqual(converted_instruction.start_time, 0) self.assertEqual(converted_instruction.duration, 0) self.assertEqual(converted_instruction.instructions[0][-1], instruction) @@ -319,24 +322,25 @@ def test_parameterized_set_phase(self): """Test converted qobj from SetPhase, with parameterized phase.""" with self.assertWarns(DeprecationWarning): qobj = PulseQobjInstruction(name="setp", ch="m0", t0=0, phase="p/2") - converted_instruction = self.converter(qobj) + converted_instruction = self.converter(qobj) self.assertIsInstance(converted_instruction, Schedule) bind_dict = {converted_instruction.get_parameters("p")[0]: 3.14} evaluated_instruction = converted_instruction.assign_parameters(bind_dict) - instruction = SetPhase(3.14 / 2, MeasureChannel(0)) + with self.assertWarns(DeprecationWarning): + instruction = SetPhase(3.14 / 2, MeasureChannel(0)) self.assertEqual(evaluated_instruction.start_time, 0) self.assertEqual(evaluated_instruction.duration, 0) self.assertEqual(evaluated_instruction.instructions[0][-1], instruction) def test_set_frequency(self): """Test converted qobj from SetFrequency.""" - instruction = SetFrequency(8.0e9, DriveChannel(0)) - with self.assertWarns(DeprecationWarning): + instruction = SetFrequency(8.0e9, DriveChannel(0)) + qobj = PulseQobjInstruction(name="setf", ch="d0", t0=0, frequency=8.0) - converted_instruction = self.converter(qobj) + converted_instruction = self.converter(qobj) self.assertEqual(converted_instruction.start_time, 0) self.assertEqual(converted_instruction.duration, 0) @@ -349,13 +353,15 @@ def test_parameterized_set_frequency(self): qobj = PulseQobjInstruction(name="setf", ch="d0", t0=2, frequency="f") self.assertTrue("frequency" in qobj.to_dict()) - converted_instruction = self.converter(qobj) + with self.assertWarns(DeprecationWarning): + converted_instruction = self.converter(qobj) self.assertIsInstance(converted_instruction, Schedule) bind_dict = {converted_instruction.get_parameters("f")[0]: 2.0} evaluated_instruction = converted_instruction.assign_parameters(bind_dict) - instruction = SetFrequency(2.0e9, DriveChannel(0)) + with self.assertWarns(DeprecationWarning): + instruction = SetFrequency(2.0e9, DriveChannel(0)) self.assertEqual(evaluated_instruction.start_time, 2) self.assertEqual(evaluated_instruction.duration, 2) @@ -363,11 +369,11 @@ def test_parameterized_set_frequency(self): def test_shift_frequency(self): """Test converted qobj from ShiftFrequency.""" - instruction = ShiftFrequency(8.0e9, DriveChannel(0)) - with self.assertWarns(DeprecationWarning): + instruction = ShiftFrequency(8.0e9, DriveChannel(0)) + qobj = PulseQobjInstruction(name="shiftf", ch="d0", t0=0, frequency=8.0) - converted_instruction = self.converter(qobj) + converted_instruction = self.converter(qobj) self.assertEqual(converted_instruction.start_time, 0) self.assertEqual(converted_instruction.duration, 0) @@ -380,13 +386,15 @@ def test_parameterized_shift_frequency(self): qobj = PulseQobjInstruction(name="shiftf", ch="d0", t0=1, frequency="f / 1000") self.assertTrue("frequency" in qobj.to_dict()) - converted_instruction = self.converter(qobj) + with self.assertWarns(DeprecationWarning): + converted_instruction = self.converter(qobj) self.assertIsInstance(converted_instruction, Schedule) bind_dict = {converted_instruction.get_parameters("f")[0]: 3.14} evaluated_instruction = converted_instruction.assign_parameters(bind_dict) - instruction = ShiftFrequency(3.14e6, DriveChannel(0)) + with self.assertWarns(DeprecationWarning): + instruction = ShiftFrequency(3.14e6, DriveChannel(0)) self.assertEqual(evaluated_instruction.start_time, 1) self.assertEqual(evaluated_instruction.duration, 1) @@ -394,11 +402,11 @@ def test_parameterized_shift_frequency(self): def test_delay(self): """Test converted qobj from Delay.""" - instruction = Delay(10, DriveChannel(0)) - with self.assertWarns(DeprecationWarning): + instruction = Delay(10, DriveChannel(0)) + qobj = PulseQobjInstruction(name="delay", ch="d0", t0=0, duration=10) - converted_instruction = self.converter(qobj) + converted_instruction = self.converter(qobj) self.assertTrue("delay" in qobj.to_dict().values()) self.assertEqual(converted_instruction.duration, instruction.duration) @@ -406,17 +414,17 @@ def test_delay(self): def test_acquire(self): """Test converted qobj from Acquire.""" - schedule = Schedule() - for i in range(self.num_qubits): - schedule |= Acquire( - 10, - AcquireChannel(i), - MemorySlot(i), - RegisterSlot(i), - kernel=Kernel(name="test_kern", test_params="test"), - discriminator=Discriminator(name="test_disc", test_params=1.0), - ) with self.assertWarns(DeprecationWarning): + schedule = Schedule() + for i in range(self.num_qubits): + schedule |= Acquire( + 10, + AcquireChannel(i), + MemorySlot(i), + RegisterSlot(i), + kernel=Kernel(name="test_kern", test_params="test"), + discriminator=Discriminator(name="test_disc", test_params=1.0), + ) qobj = PulseQobjInstruction( name="acquire", t0=0, @@ -429,7 +437,8 @@ def test_acquire(self): QobjMeasurementOption(name="test_disc", params={"test_params": 1.0}) ], ) - converted_instruction = self.converter(qobj) + with self.assertWarns(DeprecationWarning): + converted_instruction = self.converter(qobj) self.assertEqual(converted_instruction.start_time, 0) self.assertEqual(converted_instruction.duration, 10) @@ -437,16 +446,17 @@ def test_acquire(self): self.assertEqual( converted_instruction.instructions[0][-1].kernel.params, {"test_params": "test"} ) - self.assertEqual(converted_instruction.instructions[1][-1].channel, AcquireChannel(1)) + with self.assertWarns(DeprecationWarning): + self.assertEqual(converted_instruction.instructions[1][-1].channel, AcquireChannel(1)) def test_snapshot(self): """Test converted qobj from SnapShot.""" - instruction = Snapshot(label="label", snapshot_type="type") - shifted = instruction << 10 - with self.assertWarns(DeprecationWarning): + instruction = Snapshot(label="label", snapshot_type="type") + shifted = instruction << 10 + qobj = PulseQobjInstruction(name="snapshot", t0=10, label="label", type="type") - converted_instruction = self.converter(qobj) + converted_instruction = self.converter(qobj) self.assertEqual(converted_instruction.start_time, shifted.start_time) self.assertEqual(converted_instruction.duration, shifted.duration) @@ -459,27 +469,30 @@ def test_instruction_name_collision(self): PulseLibraryItem(name="pulse123", samples=[0.1, 0.1, 0.1]), PulseLibraryItem(name="pulse456", samples=[0.3, 0.3, 0.3]), ] - converter_of_backend_x = QobjToInstructionConverter(pulse_library_from_backend_x, buffer=0) + converter_of_backend_x = QobjToInstructionConverter( + pulse_library_from_backend_x, buffer=0 + ) - with self.assertWarns(DeprecationWarning): pulse_library_from_backend_y = [ PulseLibraryItem(name="pulse123", samples=[0.2, 0.2, 0.2]) ] - converter_of_backend_y = QobjToInstructionConverter(pulse_library_from_backend_y, buffer=0) + converter_of_backend_y = QobjToInstructionConverter( + pulse_library_from_backend_y, buffer=0 + ) - with self.assertWarns(DeprecationWarning): qobj1 = PulseQobjInstruction(name="pulse123", qubits=[0], t0=0, ch="d0") qobj2 = PulseQobjInstruction(name="pulse456", qubits=[0], t0=0, ch="d0") - sched_out_x = converter_of_backend_x(qobj1) - sched_out_y = converter_of_backend_y(qobj1) + sched_out_x = converter_of_backend_x(qobj1) + sched_out_y = converter_of_backend_y(qobj1) # pulse123 have different definition on backend-x and backend-y self.assertNotEqual(sched_out_x, sched_out_y) with self.assertRaises(QiskitError): - # This should not exist in backend-y command namespace. - converter_of_backend_y(qobj2) + with self.assertWarns(DeprecationWarning): + # This should not exist in backend-y command namespace. + converter_of_backend_y(qobj2) class TestLoConverter(QiskitTestCase): @@ -487,8 +500,8 @@ class TestLoConverter(QiskitTestCase): def test_qubit_los(self): """Test qubit channel configuration.""" - user_lo_config = LoConfig({DriveChannel(0): 1.3e9}) with self.assertWarns(DeprecationWarning): + user_lo_config = LoConfig({DriveChannel(0): 1.3e9}) converter = LoConfigConverter( PulseQobjExperimentConfig, [1.2e9], [3.4e9], [(0.0, 5e9)], [(0.0, 5e9)] ) @@ -499,8 +512,8 @@ def test_qubit_los(self): def test_meas_los(self): """Test measurement channel configuration.""" - user_lo_config = LoConfig({MeasureChannel(0): 3.5e9}) with self.assertWarns(DeprecationWarning): + user_lo_config = LoConfig({MeasureChannel(0): 3.5e9}) converter = LoConfigConverter( PulseQobjExperimentConfig, [1.2e9], [3.4e9], [(0.0, 5e9)], [(0.0, 5e9)] ) diff --git a/test/python/qpy/test_block_load_from_qpy.py b/test/python/qpy/test_block_load_from_qpy.py index 10c1b8eda1ee..9adc00dc72fc 100644 --- a/test/python/qpy/test_block_load_from_qpy.py +++ b/test/python/qpy/test_block_load_from_qpy.py @@ -49,7 +49,8 @@ class QpyScheduleTestCase(QiskitTestCase): def assert_roundtrip_equal(self, block, use_symengine=False): """QPY roundtrip equal test.""" qpy_file = io.BytesIO() - dump(block, qpy_file, use_symengine=use_symengine) + with self.assertWarns(DeprecationWarning): + dump(block, qpy_file, use_symengine=use_symengine) qpy_file.seek(0) new_block = load(qpy_file)[0] @@ -71,12 +72,13 @@ class TestLoadFromQPY(QpyScheduleTestCase): @unpack def test_library_pulse_play(self, envelope, channel, *params): """Test playing standard pulses.""" - with builder.build() as test_sched: - builder.play( - envelope(*params), - channel(0), - ) - self.assert_roundtrip_equal(test_sched) + with self.assertWarns(DeprecationWarning): + with builder.build() as test_sched: + builder.play( + envelope(*params), + channel(0), + ) + self.assert_roundtrip_equal(test_sched) def test_playing_custom_symbolic_pulse(self): """Test playing a custom user pulse.""" @@ -84,82 +86,92 @@ def test_playing_custom_symbolic_pulse(self): t, amp, freq = sym.symbols("t, amp, freq") sym_envelope = 2 * amp * (freq * t - sym.floor(1 / 2 + freq * t)) - my_pulse = SymbolicPulse( - pulse_type="Sawtooth", - duration=100, - parameters={"amp": 0.1, "freq": 0.05}, - envelope=sym_envelope, - name="pulse1", - ) - with builder.build() as test_sched: - builder.play(my_pulse, DriveChannel(0)) - self.assert_roundtrip_equal(test_sched) + with self.assertWarns(DeprecationWarning): + my_pulse = SymbolicPulse( + pulse_type="Sawtooth", + duration=100, + parameters={"amp": 0.1, "freq": 0.05}, + envelope=sym_envelope, + name="pulse1", + ) + with builder.build() as test_sched: + builder.play(my_pulse, DriveChannel(0)) + self.assert_roundtrip_equal(test_sched) def test_symbolic_amplitude_limit(self): """Test applying amplitude limit to symbolic pulse.""" - with builder.build() as test_sched: - builder.play( - Gaussian(160, 20, 40, limit_amplitude=False), - DriveChannel(0), - ) - self.assert_roundtrip_equal(test_sched) + with self.assertWarns(DeprecationWarning): + with builder.build() as test_sched: + builder.play( + Gaussian(160, 20, 40, limit_amplitude=False), + DriveChannel(0), + ) + self.assert_roundtrip_equal(test_sched) def test_waveform_amplitude_limit(self): """Test applying amplitude limit to waveform.""" - with builder.build() as test_sched: - builder.play( - Waveform([1, 2, 3, 4, 5], limit_amplitude=False), - DriveChannel(0), - ) - self.assert_roundtrip_equal(test_sched) + with self.assertWarns(DeprecationWarning): + with builder.build() as test_sched: + builder.play( + Waveform([1, 2, 3, 4, 5], limit_amplitude=False), + DriveChannel(0), + ) + self.assert_roundtrip_equal(test_sched) def test_playing_waveform(self): """Test playing waveform.""" # pylint: disable=invalid-name t = np.linspace(0, 1, 100) waveform = 0.1 * np.sin(2 * np.pi * t) - with builder.build() as test_sched: - builder.play(waveform, DriveChannel(0)) - self.assert_roundtrip_equal(test_sched) + with self.assertWarns(DeprecationWarning): + with builder.build() as test_sched: + builder.play(waveform, DriveChannel(0)) + self.assert_roundtrip_equal(test_sched) def test_phases(self): """Test phase.""" - with builder.build() as test_sched: - builder.shift_phase(0.1, DriveChannel(0)) - builder.set_phase(0.4, DriveChannel(1)) - self.assert_roundtrip_equal(test_sched) + with self.assertWarns(DeprecationWarning): + with builder.build() as test_sched: + builder.shift_phase(0.1, DriveChannel(0)) + builder.set_phase(0.4, DriveChannel(1)) + self.assert_roundtrip_equal(test_sched) def test_frequencies(self): """Test frequency.""" - with builder.build() as test_sched: - builder.shift_frequency(10e6, DriveChannel(0)) - builder.set_frequency(5e9, DriveChannel(1)) - self.assert_roundtrip_equal(test_sched) + with self.assertWarns(DeprecationWarning): + with builder.build() as test_sched: + builder.shift_frequency(10e6, DriveChannel(0)) + builder.set_frequency(5e9, DriveChannel(1)) + self.assert_roundtrip_equal(test_sched) def test_delay(self): """Test delay.""" - with builder.build() as test_sched: - builder.delay(100, DriveChannel(0)) - self.assert_roundtrip_equal(test_sched) + with self.assertWarns(DeprecationWarning): + with builder.build() as test_sched: + builder.delay(100, DriveChannel(0)) + self.assert_roundtrip_equal(test_sched) def test_barrier(self): """Test barrier.""" - with builder.build() as test_sched: - builder.barrier(DriveChannel(0), DriveChannel(1), ControlChannel(2)) - self.assert_roundtrip_equal(test_sched) + with self.assertWarns(DeprecationWarning): + with builder.build() as test_sched: + builder.barrier(DriveChannel(0), DriveChannel(1), ControlChannel(2)) + self.assert_roundtrip_equal(test_sched) def test_time_blockade(self): """Test time blockade.""" - with builder.build() as test_sched: - builder.append_instruction(TimeBlockade(10, DriveChannel(0))) - self.assert_roundtrip_equal(test_sched) + with self.assertWarns(DeprecationWarning): + with builder.build() as test_sched: + builder.append_instruction(TimeBlockade(10, DriveChannel(0))) + self.assert_roundtrip_equal(test_sched) def test_measure(self): """Test measurement.""" - with builder.build() as test_sched: - builder.acquire(100, AcquireChannel(0), MemorySlot(0)) - builder.acquire(100, AcquireChannel(1), RegisterSlot(1)) - self.assert_roundtrip_equal(test_sched) + with self.assertWarns(DeprecationWarning): + with builder.build() as test_sched: + builder.acquire(100, AcquireChannel(0), MemorySlot(0)) + builder.acquire(100, AcquireChannel(1), RegisterSlot(1)) + self.assert_roundtrip_equal(test_sched) @data( (0, Parameter("dur"), 0.1, 40), @@ -170,24 +182,26 @@ def test_measure(self): @unpack def test_parameterized(self, channel, *params): """Test playing parameterized pulse.""" - with builder.build() as test_sched: - builder.play(Gaussian(*params), DriveChannel(channel)) - self.assert_roundtrip_equal(test_sched) + with self.assertWarns(DeprecationWarning): + with builder.build() as test_sched: + builder.play(Gaussian(*params), DriveChannel(channel)) + self.assert_roundtrip_equal(test_sched) def test_nested_blocks(self): """Test nested blocks with different alignment contexts.""" - with builder.build() as test_sched: - with builder.align_equispaced(duration=1200): - with builder.align_left(): - builder.delay(100, DriveChannel(0)) - builder.delay(200, DriveChannel(1)) - with builder.align_right(): - builder.delay(100, DriveChannel(0)) - builder.delay(200, DriveChannel(1)) - with builder.align_sequential(): - builder.delay(100, DriveChannel(0)) - builder.delay(200, DriveChannel(1)) - self.assert_roundtrip_equal(test_sched) + with self.assertWarns(DeprecationWarning): + with builder.build() as test_sched: + with builder.align_equispaced(duration=1200): + with builder.align_left(): + builder.delay(100, DriveChannel(0)) + builder.delay(200, DriveChannel(1)) + with builder.align_right(): + builder.delay(100, DriveChannel(0)) + builder.delay(200, DriveChannel(1)) + with builder.align_sequential(): + builder.delay(100, DriveChannel(0)) + builder.delay(200, DriveChannel(1)) + self.assert_roundtrip_equal(test_sched) def test_called_schedule(self): """Test referenced pulse Schedule object. @@ -195,126 +209,136 @@ def test_called_schedule(self): Referenced object is naively converted into ScheduleBlock with TimeBlockade instructions. Thus referenced Schedule is still QPY compatible. """ - refsched = Schedule() - refsched.insert(20, Play(Constant(100, 0.1), DriveChannel(0))) - refsched.insert(50, Play(Constant(100, 0.1), DriveChannel(1))) + with self.assertWarns(DeprecationWarning): + refsched = Schedule() + refsched.insert(20, Play(Constant(100, 0.1), DriveChannel(0))) + refsched.insert(50, Play(Constant(100, 0.1), DriveChannel(1))) - with builder.build() as test_sched: - builder.call(refsched, name="test_ref") - self.assert_roundtrip_equal(test_sched) + with builder.build() as test_sched: + builder.call(refsched, name="test_ref") + self.assert_roundtrip_equal(test_sched) def test_unassigned_reference(self): """Test schedule with unassigned reference.""" - with builder.build() as test_sched: - builder.reference("custom1", "q0") - builder.reference("custom1", "q1") + with self.assertWarns(DeprecationWarning): + with builder.build() as test_sched: + builder.reference("custom1", "q0") + builder.reference("custom1", "q1") - self.assert_roundtrip_equal(test_sched) + self.assert_roundtrip_equal(test_sched) def test_partly_assigned_reference(self): """Test schedule with partly assigned reference.""" - with builder.build() as test_sched: - builder.reference("custom1", "q0") - builder.reference("custom1", "q1") + with self.assertWarns(DeprecationWarning): + with builder.build() as test_sched: + builder.reference("custom1", "q0") + builder.reference("custom1", "q1") - with builder.build() as sub_q0: - builder.delay(Parameter("duration"), DriveChannel(0)) + with builder.build() as sub_q0: + builder.delay(Parameter("duration"), DriveChannel(0)) test_sched.assign_references( {("custom1", "q0"): sub_q0}, inplace=True, ) - self.assert_roundtrip_equal(test_sched) + with self.assertWarns(DeprecationWarning): + self.assert_roundtrip_equal(test_sched) def test_nested_assigned_reference(self): """Test schedule with assigned reference for nested schedule.""" - with builder.build() as test_sched: - with builder.align_left(): - builder.reference("custom1", "q0") - builder.reference("custom1", "q1") + with self.assertWarns(DeprecationWarning): + with builder.build() as test_sched: + with builder.align_left(): + builder.reference("custom1", "q0") + builder.reference("custom1", "q1") - with builder.build() as sub_q0: - builder.delay(Parameter("duration"), DriveChannel(0)) + with builder.build() as sub_q0: + builder.delay(Parameter("duration"), DriveChannel(0)) - with builder.build() as sub_q1: - builder.delay(Parameter("duration"), DriveChannel(1)) + with builder.build() as sub_q1: + builder.delay(Parameter("duration"), DriveChannel(1)) test_sched.assign_references( {("custom1", "q0"): sub_q0, ("custom1", "q1"): sub_q1}, inplace=True, ) - self.assert_roundtrip_equal(test_sched) + with self.assertWarns(DeprecationWarning): + self.assert_roundtrip_equal(test_sched) def test_bell_schedule(self): """Test complex schedule to create a Bell state.""" - with builder.build() as test_sched: - with builder.align_sequential(): - # H - builder.shift_phase(-1.57, DriveChannel(0)) - builder.play(Drag(160, 0.05, 40, 1.3), DriveChannel(0)) - builder.shift_phase(-1.57, DriveChannel(0)) - # ECR - with builder.align_left(): - builder.play(GaussianSquare(800, 0.05, 64, 544), DriveChannel(1)) - builder.play(GaussianSquare(800, 0.22, 64, 544, 2), ControlChannel(0)) - builder.play(Drag(160, 0.1, 40, 1.5), DriveChannel(0)) - with builder.align_left(): - builder.play(GaussianSquare(800, -0.05, 64, 544), DriveChannel(1)) - builder.play(GaussianSquare(800, -0.22, 64, 544, 2), ControlChannel(0)) - builder.play(Drag(160, 0.1, 40, 1.5), DriveChannel(0)) - # Measure - with builder.align_left(): - builder.play(GaussianSquare(8000, 0.2, 64, 7744), MeasureChannel(0)) - builder.acquire(8000, AcquireChannel(0), MemorySlot(0)) - - self.assert_roundtrip_equal(test_sched) + with self.assertWarns(DeprecationWarning): + with builder.build() as test_sched: + with builder.align_sequential(): + # H + builder.shift_phase(-1.57, DriveChannel(0)) + builder.play(Drag(160, 0.05, 40, 1.3), DriveChannel(0)) + builder.shift_phase(-1.57, DriveChannel(0)) + # ECR + with builder.align_left(): + builder.play(GaussianSquare(800, 0.05, 64, 544), DriveChannel(1)) + builder.play(GaussianSquare(800, 0.22, 64, 544, 2), ControlChannel(0)) + builder.play(Drag(160, 0.1, 40, 1.5), DriveChannel(0)) + with builder.align_left(): + builder.play(GaussianSquare(800, -0.05, 64, 544), DriveChannel(1)) + builder.play(GaussianSquare(800, -0.22, 64, 544, 2), ControlChannel(0)) + builder.play(Drag(160, 0.1, 40, 1.5), DriveChannel(0)) + # Measure + with builder.align_left(): + builder.play(GaussianSquare(8000, 0.2, 64, 7744), MeasureChannel(0)) + builder.acquire(8000, AcquireChannel(0), MemorySlot(0)) + + self.assert_roundtrip_equal(test_sched) @unittest.skipUnless(_optional.HAS_SYMENGINE, "Symengine required for this test") def test_bell_schedule_use_symengine(self): """Test complex schedule to create a Bell state.""" - with builder.build() as test_sched: - with builder.align_sequential(): - # H - builder.shift_phase(-1.57, DriveChannel(0)) - builder.play(Drag(160, 0.05, 40, 1.3), DriveChannel(0)) - builder.shift_phase(-1.57, DriveChannel(0)) - # ECR - with builder.align_left(): - builder.play(GaussianSquare(800, 0.05, 64, 544), DriveChannel(1)) - builder.play(GaussianSquare(800, 0.22, 64, 544, 2), ControlChannel(0)) - builder.play(Drag(160, 0.1, 40, 1.5), DriveChannel(0)) - with builder.align_left(): - builder.play(GaussianSquare(800, -0.05, 64, 544), DriveChannel(1)) - builder.play(GaussianSquare(800, -0.22, 64, 544, 2), ControlChannel(0)) - builder.play(Drag(160, 0.1, 40, 1.5), DriveChannel(0)) - # Measure - with builder.align_left(): - builder.play(GaussianSquare(8000, 0.2, 64, 7744), MeasureChannel(0)) - builder.acquire(8000, AcquireChannel(0), MemorySlot(0)) - - self.assert_roundtrip_equal(test_sched, True) + with self.assertWarns(DeprecationWarning): + with builder.build() as test_sched: + with builder.align_sequential(): + # H + builder.shift_phase(-1.57, DriveChannel(0)) + builder.play(Drag(160, 0.05, 40, 1.3), DriveChannel(0)) + builder.shift_phase(-1.57, DriveChannel(0)) + # ECR + with builder.align_left(): + builder.play(GaussianSquare(800, 0.05, 64, 544), DriveChannel(1)) + builder.play(GaussianSquare(800, 0.22, 64, 544, 2), ControlChannel(0)) + builder.play(Drag(160, 0.1, 40, 1.5), DriveChannel(0)) + with builder.align_left(): + builder.play(GaussianSquare(800, -0.05, 64, 544), DriveChannel(1)) + builder.play(GaussianSquare(800, -0.22, 64, 544, 2), ControlChannel(0)) + builder.play(Drag(160, 0.1, 40, 1.5), DriveChannel(0)) + # Measure + with builder.align_left(): + builder.play(GaussianSquare(8000, 0.2, 64, 7744), MeasureChannel(0)) + builder.acquire(8000, AcquireChannel(0), MemorySlot(0)) + + self.assert_roundtrip_equal(test_sched, True) def test_with_acquire_instruction_with_kernel(self): """Test a schedblk with acquire instruction with kernel.""" kernel = Kernel( name="my_kernel", kernel={"real": np.ones(10), "imag": np.zeros(10)}, bias=[0, 0] ) - with builder.build() as test_sched: - builder.acquire(100, AcquireChannel(0), MemorySlot(0), kernel=kernel) + with self.assertWarns(DeprecationWarning): + with builder.build() as test_sched: + builder.acquire(100, AcquireChannel(0), MemorySlot(0), kernel=kernel) - self.assert_roundtrip_equal(test_sched) + self.assert_roundtrip_equal(test_sched) def test_with_acquire_instruction_with_discriminator(self): """Test a schedblk with acquire instruction with a discriminator.""" discriminator = Discriminator( name="my_discriminator", discriminator_type="linear", params=[1, 0] ) - with builder.build() as test_sched: - builder.acquire(100, AcquireChannel(0), MemorySlot(0), discriminator=discriminator) + with self.assertWarns(DeprecationWarning): + with builder.build() as test_sched: + builder.acquire(100, AcquireChannel(0), MemorySlot(0), discriminator=discriminator) - self.assert_roundtrip_equal(test_sched) + self.assert_roundtrip_equal(test_sched) class TestPulseGate(QpyScheduleTestCase): @@ -324,27 +348,31 @@ def test_1q_gate(self): """Test for single qubit pulse gate.""" mygate = Gate("mygate", 1, []) - with builder.build() as caldef: - builder.play(Constant(100, 0.1), DriveChannel(0)) + with self.assertWarns(DeprecationWarning): + with builder.build() as caldef: + builder.play(Constant(100, 0.1), DriveChannel(0)) qc = QuantumCircuit(2) qc.append(mygate, [0]) - qc.add_calibration(mygate, (0,), caldef) + with self.assertWarns(DeprecationWarning): + qc.add_calibration(mygate, (0,), caldef) - self.assert_roundtrip_equal(qc) + self.assert_roundtrip_equal(qc) def test_2q_gate(self): """Test for two qubit pulse gate.""" mygate = Gate("mygate", 2, []) - with builder.build() as caldef: - builder.play(Constant(100, 0.1), ControlChannel(0)) + with self.assertWarns(DeprecationWarning): + with builder.build() as caldef: + builder.play(Constant(100, 0.1), ControlChannel(0)) qc = QuantumCircuit(2) qc.append(mygate, [0, 1]) - qc.add_calibration(mygate, (0, 1), caldef) + with self.assertWarns(DeprecationWarning): + qc.add_calibration(mygate, (0, 1), caldef) - self.assert_roundtrip_equal(qc) + self.assert_roundtrip_equal(qc) def test_parameterized_gate(self): """Test for parameterized pulse gate.""" @@ -352,25 +380,29 @@ def test_parameterized_gate(self): angle = Parameter("angle") mygate = Gate("mygate", 2, [amp, angle]) - with builder.build() as caldef: - builder.play(Constant(100, amp * np.exp(1j * angle)), ControlChannel(0)) + with self.assertWarns(DeprecationWarning): + with builder.build() as caldef: + builder.play(Constant(100, amp * np.exp(1j * angle)), ControlChannel(0)) qc = QuantumCircuit(2) qc.append(mygate, [0, 1]) - qc.add_calibration(mygate, (0, 1), caldef) + with self.assertWarns(DeprecationWarning): + qc.add_calibration(mygate, (0, 1), caldef) - self.assert_roundtrip_equal(qc) + self.assert_roundtrip_equal(qc) def test_override(self): """Test for overriding standard gate with pulse gate.""" amp = Parameter("amp") - with builder.build() as caldef: - builder.play(Constant(100, amp), ControlChannel(0)) + with self.assertWarns(DeprecationWarning): + with builder.build() as caldef: + builder.play(Constant(100, amp), ControlChannel(0)) qc = QuantumCircuit(2) qc.rx(amp, 0) - qc.add_calibration("rx", (0,), caldef, [amp]) + with self.assertWarns(DeprecationWarning): + qc.add_calibration("rx", (0,), caldef, [amp]) self.assert_roundtrip_equal(qc) @@ -380,17 +412,19 @@ def test_multiple_calibrations(self): amp2 = Parameter("amp2") mygate = Gate("mygate", 1, [amp2]) - with builder.build() as caldef1: - builder.play(Constant(100, amp1), DriveChannel(0)) + with self.assertWarns(DeprecationWarning): + with builder.build() as caldef1: + builder.play(Constant(100, amp1), DriveChannel(0)) - with builder.build() as caldef2: - builder.play(Constant(100, amp2), DriveChannel(1)) + with builder.build() as caldef2: + builder.play(Constant(100, amp2), DriveChannel(1)) qc = QuantumCircuit(2) qc.rx(amp1, 0) qc.append(mygate, [1]) - qc.add_calibration("rx", (0,), caldef1, [amp1]) - qc.add_calibration(mygate, (1,), caldef2) + with self.assertWarns(DeprecationWarning): + qc.add_calibration("rx", (0,), caldef1, [amp1]) + qc.add_calibration(mygate, (1,), caldef2) self.assert_roundtrip_equal(qc) @@ -400,12 +434,14 @@ def test_with_acquire_instruction_with_kernel(self): name="my_kernel", kernel={"real": np.zeros(10), "imag": np.zeros(10)}, bias=[0, 0] ) - with builder.build() as sched: - builder.acquire(10, AcquireChannel(0), MemorySlot(0), kernel=kernel) + with self.assertWarns(DeprecationWarning): + with builder.build() as sched: + builder.acquire(10, AcquireChannel(0), MemorySlot(0), kernel=kernel) qc = QuantumCircuit(1, 1) qc.measure(0, 0) - qc.add_calibration("measure", (0,), sched) + with self.assertWarns(DeprecationWarning): + qc.add_calibration("measure", (0,), sched) self.assert_roundtrip_equal(qc) @@ -413,12 +449,14 @@ def test_with_acquire_instruction_with_discriminator(self): """Test a pulse gate with acquire instruction with discriminator.""" discriminator = Discriminator("my_discriminator") - with builder.build() as sched: - builder.acquire(10, AcquireChannel(0), MemorySlot(0), discriminator=discriminator) + with self.assertWarns(DeprecationWarning): + with builder.build() as sched: + builder.acquire(10, AcquireChannel(0), MemorySlot(0), discriminator=discriminator) qc = QuantumCircuit(1, 1) qc.measure(0, 0) - qc.add_calibration("measure", (0,), sched) + with self.assertWarns(DeprecationWarning): + qc.add_calibration("measure", (0,), sched) self.assert_roundtrip_equal(qc) @@ -433,15 +471,16 @@ def setUp(self): t, amp, freq = sym.symbols("t, amp, freq") sym_envelope = 2 * amp * (freq * t - sym.floor(1 / 2 + freq * t)) - my_pulse = SymbolicPulse( - pulse_type="Sawtooth", - duration=100, - parameters={"amp": 0.1, "freq": 0.05}, - envelope=sym_envelope, - name="pulse1", - ) - with builder.build() as test_sched: - builder.play(my_pulse, DriveChannel(0)) + with self.assertWarns(DeprecationWarning): + my_pulse = SymbolicPulse( + pulse_type="Sawtooth", + duration=100, + parameters={"amp": 0.1, "freq": 0.05}, + envelope=sym_envelope, + name="pulse1", + ) + with builder.build() as test_sched: + builder.play(my_pulse, DriveChannel(0)) self.test_sched = test_sched @@ -449,7 +488,9 @@ def setUp(self): def test_symengine_full_path(self): """Test use_symengine option for circuit with parameter expressions.""" qpy_file = io.BytesIO() - dump(self.test_sched, qpy_file, use_symengine=True) + with self.assertWarns(DeprecationWarning): + dump(self.test_sched, qpy_file, use_symengine=True) qpy_file.seek(0) - new_sched = load(qpy_file)[0] + with self.assertWarns(DeprecationWarning): + new_sched = load(qpy_file)[0] self.assertEqual(self.test_sched, new_sched) diff --git a/test/python/qpy/test_circuit_load_from_qpy.py b/test/python/qpy/test_circuit_load_from_qpy.py index 8f0cffb36a5f..e909f7ced455 100644 --- a/test/python/qpy/test_circuit_load_from_qpy.py +++ b/test/python/qpy/test_circuit_load_from_qpy.py @@ -69,24 +69,26 @@ def setUp(self): @data(0.1, 0.7, 1.5) def test_rzx_calibration(self, angle): """RZX builder calibration pass with echo.""" - pass_ = passes.RZXCalibrationBuilder(self.inst_map) + with self.assertWarns(DeprecationWarning): + pass_ = passes.RZXCalibrationBuilder(self.inst_map) pass_manager = PassManager(pass_) test_qc = QuantumCircuit(2) test_qc.rzx(angle, 0, 1) rzx_qc = pass_manager.run(test_qc) - - self.assert_roundtrip_equal(rzx_qc) + with self.assertWarns(DeprecationWarning): + self.assert_roundtrip_equal(rzx_qc) @data(0.1, 0.7, 1.5) def test_rzx_calibration_echo(self, angle): """RZX builder calibration pass without echo.""" - pass_ = passes.RZXCalibrationBuilderNoEcho(self.inst_map) + with self.assertWarns(DeprecationWarning): + pass_ = passes.RZXCalibrationBuilderNoEcho(self.inst_map) pass_manager = PassManager(pass_) test_qc = QuantumCircuit(2) test_qc.rzx(angle, 0, 1) rzx_qc = pass_manager.run(test_qc) - - self.assert_roundtrip_equal(rzx_qc) + with self.assertWarns(DeprecationWarning): + self.assert_roundtrip_equal(rzx_qc) class TestVersions(QpyCircuitTestCase): diff --git a/test/python/scheduler/test_basic_scheduler.py b/test/python/scheduler/test_basic_scheduler.py index 947a255ddf21..5adbb3fdc1ff 100644 --- a/test/python/scheduler/test_basic_scheduler.py +++ b/test/python/scheduler/test_basic_scheduler.py @@ -57,7 +57,8 @@ def test_unavailable_defaults(self): with self.assertWarns(DeprecationWarning): backend = FakeBackend(None) backend.defaults = backend.configuration - self.assertRaises(QiskitError, lambda: schedule(qc, backend)) + with self.assertWarns(DeprecationWarning): + self.assertRaises(QiskitError, lambda: schedule(qc, backend)) def test_alap_pass(self): """Test ALAP scheduling.""" @@ -79,15 +80,17 @@ def test_alap_pass(self): qc.barrier(q[0], [q[1]]) qc.cx(q[0], q[1]) qc.measure(q, c) - sched = schedule(qc, self.backend) + with self.assertWarns(DeprecationWarning): + sched = schedule(qc, self.backend) # X pulse on q0 should end at the start of the CNOT - expected = Schedule( - (2, self.inst_map.get("u2", [0], 3.14, 1.57)), - self.inst_map.get("u2", [1], 0.5, 0.25), - (2, self.inst_map.get("u2", [1], 0.5, 0.25)), - (4, self.inst_map.get("cx", [0, 1])), - (26, self.inst_map.get("measure", [0, 1])), - ) + with self.assertWarns(DeprecationWarning): + expected = Schedule( + (2, self.inst_map.get("u2", [0], 3.14, 1.57)), + self.inst_map.get("u2", [1], 0.5, 0.25), + (2, self.inst_map.get("u2", [1], 0.5, 0.25)), + (4, self.inst_map.get("cx", [0, 1])), + (26, self.inst_map.get("measure", [0, 1])), + ) for actual, expected in zip(sched.instructions, expected.instructions): self.assertEqual(actual[0], expected[0]) self.assertEqual(actual[1], expected[1]) @@ -97,8 +100,9 @@ def test_single_circuit_list_schedule(self): q = QuantumRegister(2) c = ClassicalRegister(2) qc = QuantumCircuit(q, c) - sched = schedule([qc], self.backend, method="alap") - expected = Schedule() + with self.assertWarns(DeprecationWarning): + sched = schedule([qc], self.backend, method="alap") + expected = Schedule() self.assertIsInstance(sched, list) self.assertEqual(sched[0].instructions, expected.instructions) @@ -110,10 +114,11 @@ def test_alap_with_barriers(self): qc.append(U2Gate(0, 0), [q[0]]) qc.barrier(q[0], q[1]) qc.append(U2Gate(0, 0), [q[1]]) - sched = schedule(qc, self.backend, method="alap") - expected = Schedule( - self.inst_map.get("u2", [0], 0, 0), (2, self.inst_map.get("u2", [1], 0, 0)) - ) + with self.assertWarns(DeprecationWarning): + sched = schedule(qc, self.backend, method="alap") + expected = Schedule( + self.inst_map.get("u2", [0], 0, 0), (2, self.inst_map.get("u2", [1], 0, 0)) + ) for actual, expected in zip(sched.instructions, expected.instructions): self.assertEqual(actual[0], expected[0]) self.assertEqual(actual[1], expected[1]) @@ -123,8 +128,9 @@ def test_empty_circuit_schedule(self): q = QuantumRegister(2) c = ClassicalRegister(2) qc = QuantumCircuit(q, c) - sched = schedule(qc, self.backend, method="alap") - expected = Schedule() + with self.assertWarns(DeprecationWarning): + sched = schedule(qc, self.backend, method="alap") + expected = Schedule() self.assertEqual(sched.instructions, expected.instructions) def test_alap_aligns_end(self): @@ -134,16 +140,18 @@ def test_alap_aligns_end(self): qc = QuantumCircuit(q, c) qc.append(U3Gate(0, 0, 0), [q[0]]) qc.append(U2Gate(0, 0), [q[1]]) - sched = schedule(qc, self.backend, method="alap") - expected_sched = Schedule( - (2, self.inst_map.get("u2", [1], 0, 0)), self.inst_map.get("u3", [0], 0, 0, 0) - ) + with self.assertWarns(DeprecationWarning): + sched = schedule(qc, self.backend, method="alap") + expected_sched = Schedule( + (2, self.inst_map.get("u2", [1], 0, 0)), self.inst_map.get("u3", [0], 0, 0, 0) + ) for actual, expected in zip(sched.instructions, expected_sched.instructions): self.assertEqual(actual[0], expected[0]) self.assertEqual(actual[1], expected[1]) - self.assertEqual( - sched.ch_duration(DriveChannel(0)), expected_sched.ch_duration(DriveChannel(1)) - ) + with self.assertWarns(DeprecationWarning): + self.assertEqual( + sched.ch_duration(DriveChannel(0)), expected_sched.ch_duration(DriveChannel(1)) + ) def test_asap_pass(self): """Test ASAP scheduling.""" @@ -165,15 +173,16 @@ def test_asap_pass(self): qc.barrier(q[0], q[1]) qc.cx(q[0], q[1]) qc.measure(q, c) - sched = schedule(qc, self.backend, method="as_soon_as_possible") - # X pulse on q0 should start at t=0 - expected = Schedule( - self.inst_map.get("u2", [0], 3.14, 1.57), - self.inst_map.get("u2", [1], 0.5, 0.25), - (2, self.inst_map.get("u2", [1], 0.5, 0.25)), - (4, self.inst_map.get("cx", [0, 1])), - (26, self.inst_map.get("measure", [0, 1])), - ) + with self.assertWarns(DeprecationWarning): + sched = schedule(qc, self.backend, method="as_soon_as_possible") + # X pulse on q0 should start at t=0 + expected = Schedule( + self.inst_map.get("u2", [0], 3.14, 1.57), + self.inst_map.get("u2", [1], 0.5, 0.25), + (2, self.inst_map.get("u2", [1], 0.5, 0.25)), + (4, self.inst_map.get("cx", [0, 1])), + (26, self.inst_map.get("measure", [0, 1])), + ) for actual, expected in zip(sched.instructions, expected.instructions): self.assertEqual(actual[0], expected[0]) self.assertEqual(actual[1], expected[1]) @@ -187,7 +196,8 @@ def test_alap_resource_respecting(self): qc = QuantumCircuit(q, c) qc.cx(q[0], q[1]) qc.append(U2Gate(0.5, 0.25), [q[1]]) - sched = schedule(qc, self.backend, method="as_late_as_possible") + with self.assertWarns(DeprecationWarning): + sched = schedule(qc, self.backend, method="as_late_as_possible") insts = sched.instructions self.assertEqual(insts[0][0], 0) self.assertEqual(insts[6][0], 22) @@ -196,7 +206,8 @@ def test_alap_resource_respecting(self): qc.cx(q[0], q[1]) qc.append(U2Gate(0.5, 0.25), [q[1]]) qc.measure(q, c) - sched = schedule(qc, self.backend, method="as_late_as_possible") + with self.assertWarns(DeprecationWarning): + sched = schedule(qc, self.backend, method="as_late_as_possible") self.assertEqual(sched.instructions[-1][0], 24) def test_inst_map_schedules_unaltered(self): @@ -205,8 +216,9 @@ def test_inst_map_schedules_unaltered(self): c = ClassicalRegister(2) qc = QuantumCircuit(q, c) qc.cx(q[0], q[1]) - sched1 = schedule(qc, self.backend, method="as_soon_as_possible") - sched2 = schedule(qc, self.backend, method="as_late_as_possible") + with self.assertWarns(DeprecationWarning): + sched1 = schedule(qc, self.backend, method="as_soon_as_possible") + sched2 = schedule(qc, self.backend, method="as_late_as_possible") for asap, alap in zip(sched1.instructions, sched2.instructions): self.assertEqual(asap[0], alap[0]) self.assertEqual(asap[1], alap[1]) @@ -233,14 +245,15 @@ def test_measure_combined(self): qc.measure(q[0], c[0]) qc.measure(q[1], c[1]) qc.measure(q[1], c[1]) - sched = schedule(qc, self.backend, method="as_soon_as_possible") - expected = Schedule( - self.inst_map.get("u2", [0], 3.14, 1.57), - (2, self.inst_map.get("cx", [0, 1])), - (24, self.inst_map.get("measure", [0, 1])), - (34, self.inst_map.get("measure", [0, 1]).filter(channels=[MeasureChannel(1)])), - (34, Acquire(10, AcquireChannel(1), MemorySlot(1))), - ) + with self.assertWarns(DeprecationWarning): + sched = schedule(qc, self.backend, method="as_soon_as_possible") + expected = Schedule( + self.inst_map.get("u2", [0], 3.14, 1.57), + (2, self.inst_map.get("cx", [0, 1])), + (24, self.inst_map.get("measure", [0, 1])), + (34, self.inst_map.get("measure", [0, 1]).filter(channels=[MeasureChannel(1)])), + (34, Acquire(10, AcquireChannel(1), MemorySlot(1))), + ) self.assertEqual(sched.instructions, expected.instructions) # @@ -266,15 +279,16 @@ def test_3q_schedule(self): qc.append(U2Gate(3.14, 1.57), [q[1]]) qc.cx(q[1], q[2]) qc.append(U2Gate(0.778, 0.122), [q[2]]) - sched = schedule(qc, backend) - expected = Schedule( - inst_map.get("cx", [0, 1]), - (22, inst_map.get("u2", [1], 3.14, 1.57)), - (22, inst_map.get("u2", [2], 0.778, 0.122)), - (24, inst_map.get("cx", [1, 2])), - (44, inst_map.get("u3", [0], 3.14, 1.57, 0)), - (46, inst_map.get("u2", [2], 0.778, 0.122)), - ) + with self.assertWarns(DeprecationWarning): + sched = schedule(qc, backend) + expected = Schedule( + inst_map.get("cx", [0, 1]), + (22, inst_map.get("u2", [1], 3.14, 1.57)), + (22, inst_map.get("u2", [2], 0.778, 0.122)), + (24, inst_map.get("cx", [1, 2])), + (44, inst_map.get("u3", [0], 3.14, 1.57, 0)), + (46, inst_map.get("u2", [2], 0.778, 0.122)), + ) for actual, expected in zip(sched.instructions, expected.instructions): self.assertEqual(actual[0], expected[0]) self.assertEqual(actual[1], expected[1]) @@ -287,8 +301,9 @@ def test_schedule_multi(self): qc0.cx(q[0], q[1]) qc1 = QuantumCircuit(q, c) qc1.cx(q[0], q[1]) - schedules = schedule([qc0, qc1], self.backend) - expected_insts = schedule(qc0, self.backend).instructions + with self.assertWarns(DeprecationWarning): + schedules = schedule([qc0, qc1], self.backend) + expected_insts = schedule(qc0, self.backend).instructions for actual, expected in zip(schedules[0].instructions, expected_insts): self.assertEqual(actual[0], expected[0]) self.assertEqual(actual[1], expected[1]) @@ -299,9 +314,11 @@ def test_circuit_name_kept(self): c = ClassicalRegister(2) qc = QuantumCircuit(q, c, name="CIRCNAME") qc.cx(q[0], q[1]) - sched = schedule(qc, self.backend, method="asap") + with self.assertWarns(DeprecationWarning): + sched = schedule(qc, self.backend, method="asap") self.assertEqual(sched.name, qc.name) - sched = schedule(qc, self.backend, method="alap") + with self.assertWarns(DeprecationWarning): + sched = schedule(qc, self.backend, method="alap") self.assertEqual(sched.name, qc.name) def test_can_add_gates_into_free_space(self): @@ -321,15 +338,16 @@ def test_can_add_gates_into_free_space(self): qc.append(U2Gate(0, 0), [qr[i]]) qc.append(U1Gate(3.14), [qr[i]]) qc.append(U2Gate(0, 0), [qr[i]]) - sched = schedule(qc, self.backend, method="alap") - expected = Schedule( - self.inst_map.get("u2", [0], 0, 0), - self.inst_map.get("u2", [1], 0, 0), - (2, self.inst_map.get("u1", [0], 3.14)), - (2, self.inst_map.get("u1", [1], 3.14)), - (2, self.inst_map.get("u2", [0], 0, 0)), - (2, self.inst_map.get("u2", [1], 0, 0)), - ) + with self.assertWarns(DeprecationWarning): + sched = schedule(qc, self.backend, method="alap") + expected = Schedule( + self.inst_map.get("u2", [0], 0, 0), + self.inst_map.get("u2", [1], 0, 0), + (2, self.inst_map.get("u1", [0], 3.14)), + (2, self.inst_map.get("u1", [1], 3.14)), + (2, self.inst_map.get("u2", [0], 0, 0)), + (2, self.inst_map.get("u2", [1], 0, 0)), + ) for actual, expected in zip(sched.instructions, expected.instructions): self.assertEqual(actual[0], expected[0]) self.assertEqual(actual[1], expected[1]) @@ -346,15 +364,16 @@ def test_barriers_in_middle(self): qc.append(U1Gate(3.14), [qr[i]]) qc.barrier(qr[i]) qc.append(U2Gate(0, 0), [qr[i]]) - sched = schedule(qc, self.backend, method="alap") - expected = Schedule( - self.inst_map.get("u2", [0], 0, 0), - self.inst_map.get("u2", [1], 0, 0), - (2, self.inst_map.get("u1", [0], 3.14)), - (2, self.inst_map.get("u1", [1], 3.14)), - (2, self.inst_map.get("u2", [0], 0, 0)), - (2, self.inst_map.get("u2", [1], 0, 0)), - ) + with self.assertWarns(DeprecationWarning): + sched = schedule(qc, self.backend, method="alap") + expected = Schedule( + self.inst_map.get("u2", [0], 0, 0), + self.inst_map.get("u2", [1], 0, 0), + (2, self.inst_map.get("u1", [0], 3.14)), + (2, self.inst_map.get("u1", [1], 3.14)), + (2, self.inst_map.get("u2", [0], 0, 0)), + (2, self.inst_map.get("u2", [1], 0, 0)), + ) for actual, expected in zip(sched.instructions, expected.instructions): self.assertEqual(actual[0], expected[0]) self.assertEqual(actual[1], expected[1]) @@ -364,11 +383,13 @@ def test_parametric_input(self): qr = QuantumRegister(1) qc = QuantumCircuit(qr) qc.append(Gate("gauss", 1, []), qargs=[qr[0]]) - custom_gauss = Schedule( - Play(Gaussian(duration=25, sigma=4, amp=0.5, angle=pi / 2), DriveChannel(0)) - ) + with self.assertWarns(DeprecationWarning): + custom_gauss = Schedule( + Play(Gaussian(duration=25, sigma=4, amp=0.5, angle=pi / 2), DriveChannel(0)) + ) self.inst_map.add("gauss", [0], custom_gauss) - sched = schedule(qc, self.backend, inst_map=self.inst_map) + with self.assertWarns(DeprecationWarning): + sched = schedule(qc, self.backend, inst_map=self.inst_map) self.assertEqual(sched.instructions[0], custom_gauss.instructions[0]) def test_pulse_gates(self): @@ -378,14 +399,20 @@ def test_pulse_gates(self): qc.append(U2Gate(0, 0), [q[0]]) qc.barrier(q[0], q[1]) qc.append(U2Gate(0, 0), [q[1]]) - qc.add_calibration("u2", [0], Schedule(Play(Gaussian(28, 0.2, 4), DriveChannel(0))), [0, 0]) - qc.add_calibration("u2", [1], Schedule(Play(Gaussian(28, 0.2, 4), DriveChannel(1))), [0, 0]) - - sched = schedule(qc, self.backend) - expected = Schedule( - Play(Gaussian(28, 0.2, 4), DriveChannel(0)), - (28, Schedule(Play(Gaussian(28, 0.2, 4), DriveChannel(1)))), - ) + with self.assertWarns(DeprecationWarning): + qc.add_calibration( + "u2", [0], Schedule(Play(Gaussian(28, 0.2, 4), DriveChannel(0))), [0, 0] + ) + qc.add_calibration( + "u2", [1], Schedule(Play(Gaussian(28, 0.2, 4), DriveChannel(1))), [0, 0] + ) + + with self.assertWarns(DeprecationWarning): + sched = schedule(qc, self.backend) + expected = Schedule( + Play(Gaussian(28, 0.2, 4), DriveChannel(0)), + (28, Schedule(Play(Gaussian(28, 0.2, 4), DriveChannel(1)))), + ) self.assertEqual(sched.instructions, expected.instructions) def test_calibrated_measurements(self): @@ -396,12 +423,13 @@ def test_calibrated_measurements(self): qc.append(U2Gate(0, 0), [q[0]]) qc.measure(q[0], c[0]) - meas_sched = Play(Gaussian(1200, 0.2, 4), MeasureChannel(0)) - meas_sched |= Acquire(1200, AcquireChannel(0), MemorySlot(0)) - qc.add_calibration("measure", [0], meas_sched) + with self.assertWarns(DeprecationWarning): + meas_sched = Play(Gaussian(1200, 0.2, 4), MeasureChannel(0)) + meas_sched |= Acquire(1200, AcquireChannel(0), MemorySlot(0)) + qc.add_calibration("measure", [0], meas_sched) - sched = schedule(qc, self.backend) - expected = Schedule(self.inst_map.get("u2", [0], 0, 0), (2, meas_sched)) + sched = schedule(qc, self.backend) + expected = Schedule(self.inst_map.get("u2", [0], 0, 0), (2, meas_sched)) self.assertEqual(sched.instructions, expected.instructions) def test_subset_calibrated_measurements(self): @@ -413,20 +441,23 @@ def test_subset_calibrated_measurements(self): qc.measure(2, 2) meas_scheds = [] for qubit in [0, 2]: - meas = Play(Gaussian(1200, 0.2, 4), MeasureChannel(qubit)) + Acquire( - 1200, AcquireChannel(qubit), MemorySlot(qubit) - ) + with self.assertWarns(DeprecationWarning): + meas = Play(Gaussian(1200, 0.2, 4), MeasureChannel(qubit)) + Acquire( + 1200, AcquireChannel(qubit), MemorySlot(qubit) + ) meas_scheds.append(meas) - qc.add_calibration("measure", [qubit], meas) + with self.assertWarns(DeprecationWarning): + qc.add_calibration("measure", [qubit], meas) with self.assertWarns(DeprecationWarning): backend = FakeOpenPulse3Q() - meas = macros.measure([1], backend) - meas = meas.exclude(channels=[AcquireChannel(0), AcquireChannel(2)]) + meas = macros.measure([1], backend) + meas = meas.exclude(channels=[AcquireChannel(0), AcquireChannel(2)]) with self.assertWarns(DeprecationWarning): backend = FakeOpenPulse3Q() - sched = schedule(qc, backend) - expected = Schedule(meas_scheds[0], meas_scheds[1], meas) + with self.assertWarns(DeprecationWarning): + sched = schedule(qc, backend) + expected = Schedule(meas_scheds[0], meas_scheds[1], meas) self.assertEqual(sched.instructions, expected.instructions) def test_clbits_of_calibrated_measurements(self): @@ -436,13 +467,16 @@ def test_clbits_of_calibrated_measurements(self): qc = QuantumCircuit(q, c) qc.measure(q[0], c[1]) - meas_sched = Play(Gaussian(1200, 0.2, 4), MeasureChannel(0)) - meas_sched |= Acquire(1200, AcquireChannel(0), MemorySlot(0)) - qc.add_calibration("measure", [0], meas_sched) + with self.assertWarns(DeprecationWarning): + meas_sched = Play(Gaussian(1200, 0.2, 4), MeasureChannel(0)) + meas_sched |= Acquire(1200, AcquireChannel(0), MemorySlot(0)) + qc.add_calibration("measure", [0], meas_sched) - sched = schedule(qc, self.backend) + with self.assertWarns(DeprecationWarning): + sched = schedule(qc, self.backend) # Doesn't use the calibrated schedule because the classical memory slots do not match - expected = Schedule(macros.measure([0], self.backend, qubit_mem_slots={0: 1})) + with self.assertWarns(DeprecationWarning): + expected = Schedule(macros.measure([0], self.backend, qubit_mem_slots={0: 1})) self.assertEqual(sched.instructions, expected.instructions) def test_metadata_is_preserved_alap(self): @@ -453,7 +487,8 @@ def test_metadata_is_preserved_alap(self): qc.barrier(q[0], q[1]) qc.append(U2Gate(0, 0), [q[1]]) qc.metadata = {"experiment_type": "gst", "execution_number": "1234"} - sched = schedule(qc, self.backend, method="alap") + with self.assertWarns(DeprecationWarning): + sched = schedule(qc, self.backend, method="alap") self.assertEqual({"experiment_type": "gst", "execution_number": "1234"}, sched.metadata) def test_metadata_is_preserved_asap(self): @@ -464,7 +499,8 @@ def test_metadata_is_preserved_asap(self): qc.barrier(q[0], q[1]) qc.append(U2Gate(0, 0), [q[1]]) qc.metadata = {"experiment_type": "gst", "execution_number": "1234"} - sched = schedule(qc, self.backend, method="asap") + with self.assertWarns(DeprecationWarning): + sched = schedule(qc, self.backend, method="asap") self.assertEqual({"experiment_type": "gst", "execution_number": "1234"}, sched.metadata) def test_scheduler_with_params_bound(self): @@ -472,10 +508,14 @@ def test_scheduler_with_params_bound(self): x = Parameter("x") qc = QuantumCircuit(2) qc.append(Gate("pulse_gate", 1, [x]), [0]) - expected_schedule = Schedule() - qc.add_calibration(gate="pulse_gate", qubits=[0], schedule=expected_schedule, params=[x]) + with self.assertWarns(DeprecationWarning): + expected_schedule = Schedule() + qc.add_calibration( + gate="pulse_gate", qubits=[0], schedule=expected_schedule, params=[x] + ) qc = qc.assign_parameters({x: 1}) - sched = schedule(qc, self.backend) + with self.assertWarns(DeprecationWarning): + sched = schedule(qc, self.backend) self.assertEqual(sched, expected_schedule) def test_scheduler_with_params_not_bound(self): @@ -483,30 +523,36 @@ def test_scheduler_with_params_not_bound(self): x = Parameter("amp") qc = QuantumCircuit(2) qc.append(Gate("pulse_gate", 1, [x]), [0]) - with build() as expected_schedule: - play(Gaussian(duration=160, amp=x, sigma=40), DriveChannel(0)) - qc.add_calibration(gate="pulse_gate", qubits=[0], schedule=expected_schedule, params=[x]) - sched = schedule(qc, self.backend) - self.assertEqual(sched, transforms.target_qobj_transform(expected_schedule)) + with self.assertWarns(DeprecationWarning): + with build() as expected_schedule: + play(Gaussian(duration=160, amp=x, sigma=40), DriveChannel(0)) + qc.add_calibration( + gate="pulse_gate", qubits=[0], schedule=expected_schedule, params=[x] + ) + sched = schedule(qc, self.backend) + self.assertEqual(sched, transforms.target_qobj_transform(expected_schedule)) def test_schedule_block_in_instmap(self): """Test schedule block in instmap can be scheduled.""" duration = Parameter("duration") - with build() as pulse_prog: - play(Gaussian(duration, 0.1, 10), DriveChannel(0)) + with self.assertWarns(DeprecationWarning): + with build() as pulse_prog: + play(Gaussian(duration, 0.1, 10), DriveChannel(0)) - instmap = InstructionScheduleMap() + instmap = InstructionScheduleMap() instmap.add("block_gate", (0,), pulse_prog, ["duration"]) qc = QuantumCircuit(1) qc.append(Gate("block_gate", 1, [duration]), [0]) qc.assign_parameters({duration: 100}, inplace=True) - sched = schedule(qc, self.backend, inst_map=instmap) + with self.assertWarns(DeprecationWarning): + sched = schedule(qc, self.backend, inst_map=instmap) - ref_sched = Schedule() - ref_sched += Play(Gaussian(100, 0.1, 10), DriveChannel(0)) + with self.assertWarns(DeprecationWarning): + ref_sched = Schedule() + ref_sched += Play(Gaussian(100, 0.1, 10), DriveChannel(0)) self.assertEqual(sched, ref_sched) @@ -516,8 +562,9 @@ class TestBasicScheduleV2(QiskitTestCase): def setUp(self): super().setUp() - self.backend = GenericBackendV2(num_qubits=3, calibrate_instructions=True, seed=42) - self.inst_map = self.backend.instruction_schedule_map + with self.assertWarns(DeprecationWarning): + self.backend = GenericBackendV2(num_qubits=3, calibrate_instructions=True, seed=42) + self.inst_map = self.backend.instruction_schedule_map # self.pulse_2_samples is the pulse sequence used to calibrate "measure" in # GenericBackendV2. See class construction for more details. self.pulse_2_samples = np.linspace(0, 1.0, 32, dtype=np.complex128) @@ -547,7 +594,8 @@ def test_alap_pass(self): qc.cx(q[0], q[1]) qc.measure(q, c) - sched = schedule(circuits=qc, backend=self.backend, method="alap") + with self.assertWarns(DeprecationWarning): + sched = schedule(circuits=qc, backend=self.backend, method="alap") # Since, the method of scheduling chosen here is 'as_late_as_possible' # so all the π/2 pulse here should be right shifted. @@ -560,30 +608,31 @@ def test_alap_pass(self): # cx pulse( pulse on drive channel, control channel) should start with a delay # of 16dt+16dt. # measure pulse should start with a delay of 16dt+16dt+64dt(64dt for cx gate). - expected = Schedule( - (0, self.inst_map.get("sx", [1])), - (0 + 16, self.inst_map.get("sx", [0])), # Right shifted because of alap. - (0 + 16, self.inst_map.get("sx", [1])), - (0 + 16 + 16, self.inst_map.get("cx", [0, 1])), - ( - 0 + 16 + 16 + 64, - Play( - Waveform(samples=self.pulse_2_samples, name="pulse_2"), - MeasureChannel(0), - name="pulse_2", + with self.assertWarns(DeprecationWarning): + expected = Schedule( + (0, self.inst_map.get("sx", [1])), + (0 + 16, self.inst_map.get("sx", [0])), # Right shifted because of alap. + (0 + 16, self.inst_map.get("sx", [1])), + (0 + 16 + 16, self.inst_map.get("cx", [0, 1])), + ( + 0 + 16 + 16 + 64, + Play( + Waveform(samples=self.pulse_2_samples, name="pulse_2"), + MeasureChannel(0), + name="pulse_2", + ), ), - ), - ( - 0 + 16 + 16 + 64, - Play( - Waveform(samples=self.pulse_2_samples, name="pulse_2"), - MeasureChannel(1), - name="pulse_2", + ( + 0 + 16 + 16 + 64, + Play( + Waveform(samples=self.pulse_2_samples, name="pulse_2"), + MeasureChannel(1), + name="pulse_2", + ), ), - ), - (0 + 16 + 16 + 64, Acquire(1792, AcquireChannel(0), MemorySlot(0))), - (0 + 16 + 16 + 64, Acquire(1792, AcquireChannel(1), MemorySlot(1))), - ) + (0 + 16 + 16 + 64, Acquire(1792, AcquireChannel(0), MemorySlot(0))), + (0 + 16 + 16 + 64, Acquire(1792, AcquireChannel(1), MemorySlot(1))), + ) for actual, expected in zip(sched.instructions, expected.instructions): self.assertEqual(actual[0], expected[0]) self.assertEqual(actual[1], expected[1]) @@ -593,8 +642,9 @@ def test_single_circuit_list_schedule(self): q = QuantumRegister(2) c = ClassicalRegister(2) qc = QuantumCircuit(q, c) - sched = schedule([qc], self.backend, method="alap") - expected = Schedule() + with self.assertWarns(DeprecationWarning): + sched = schedule([qc], self.backend, method="alap") + expected = Schedule() self.assertIsInstance(sched, list) self.assertEqual(sched[0].instructions, expected.instructions) @@ -615,10 +665,13 @@ def test_alap_with_barriers(self): qc.append(SXGate(), [q[0]]) qc.barrier(q[0], q[1]) qc.append(SXGate(), [q[1]]) - sched = schedule(qc, self.backend, method="alap") - # If there wasn't a barrier the π/2 pulse on q1 would have started from 0dt, but since, - # there is a barrier so the π/2 pulse on q1 should start with a delay of 160dt. - expected = Schedule((0, self.inst_map.get("sx", [0])), (16, self.inst_map.get("sx", [1]))) + with self.assertWarns(DeprecationWarning): + sched = schedule(qc, self.backend, method="alap") + # If there wasn't a barrier the π/2 pulse on q1 would have started from 0dt, but since, + # there is a barrier so the π/2 pulse on q1 should start with a delay of 160dt. + expected = Schedule( + (0, self.inst_map.get("sx", [0])), (16, self.inst_map.get("sx", [1])) + ) for actual, expected in zip(sched.instructions, expected.instructions): self.assertEqual(actual, expected) @@ -627,8 +680,9 @@ def test_empty_circuit_schedule(self): q = QuantumRegister(2) c = ClassicalRegister(2) qc = QuantumCircuit(q, c) - sched = schedule(qc, self.backend, method="alap") - expected = Schedule() + with self.assertWarns(DeprecationWarning): + sched = schedule(qc, self.backend, method="alap") + expected = Schedule() self.assertEqual(sched.instructions, expected.instructions) def test_alap_aligns_end(self): @@ -645,16 +699,18 @@ def test_alap_aligns_end(self): qc = QuantumCircuit(q, c) qc.sx(q[0]) qc.sx(q[1]) - sched = schedule(qc, self.backend, method="alap") - expected_sched = Schedule( - (0, self.inst_map.get("sx", [1])), (0, self.inst_map.get("sx", [0])) - ) + with self.assertWarns(DeprecationWarning): + sched = schedule(qc, self.backend, method="alap") + expected_sched = Schedule( + (0, self.inst_map.get("sx", [1])), (0, self.inst_map.get("sx", [0])) + ) for actual, expected in zip(sched.instructions, expected_sched.instructions): self.assertEqual(actual[0], expected[0]) self.assertEqual(actual[1], expected[1]) - self.assertEqual( - sched.ch_duration(DriveChannel(0)), expected_sched.ch_duration(DriveChannel(1)) - ) + with self.assertWarns(DeprecationWarning): + self.assertEqual( + sched.ch_duration(DriveChannel(0)), expected_sched.ch_duration(DriveChannel(1)) + ) def test_asap_pass(self): """Test ASAP scheduling.""" @@ -681,7 +737,8 @@ def test_asap_pass(self): qc.cx(q[0], q[1]) qc.measure(q, c) - sched = schedule(circuits=qc, backend=self.backend, method="asap") + with self.assertWarns(DeprecationWarning): + sched = schedule(circuits=qc, backend=self.backend, method="asap") # Since, the method of scheduling chosen here is 'as_soon_as_possible' # so all the π/2 pulse here should be left shifted. # @@ -693,30 +750,31 @@ def test_asap_pass(self): # cx pulse( pulse on drive channel, control channel) should start with a delay # of 16dt+16dt. # measure pulse should start with a delay of 16dt+16dt+64dt(64dt for cx gate). - expected = Schedule( - (0, self.inst_map.get("sx", [1])), - (0, self.inst_map.get("sx", [0])), # Left shifted because of asap. - (0 + 16, self.inst_map.get("sx", [1])), - (0 + 16 + 16, self.inst_map.get("cx", [0, 1])), - ( - 0 + 16 + 16 + 64, - Play( - Waveform(samples=self.pulse_2_samples, name="pulse_2"), - MeasureChannel(0), - name="pulse_2", + with self.assertWarns(DeprecationWarning): + expected = Schedule( + (0, self.inst_map.get("sx", [1])), + (0, self.inst_map.get("sx", [0])), # Left shifted because of asap. + (0 + 16, self.inst_map.get("sx", [1])), + (0 + 16 + 16, self.inst_map.get("cx", [0, 1])), + ( + 0 + 16 + 16 + 64, + Play( + Waveform(samples=self.pulse_2_samples, name="pulse_2"), + MeasureChannel(0), + name="pulse_2", + ), ), - ), - ( - 0 + 16 + 16 + 64, - Play( - Waveform(samples=self.pulse_2_samples, name="pulse_2"), - MeasureChannel(1), - name="pulse_2", + ( + 0 + 16 + 16 + 64, + Play( + Waveform(samples=self.pulse_2_samples, name="pulse_2"), + MeasureChannel(1), + name="pulse_2", + ), ), - ), - (0 + 16 + 16 + 64, Acquire(1792, AcquireChannel(0), MemorySlot(0))), - (0 + 16 + 16 + 64, Acquire(1792, AcquireChannel(1), MemorySlot(1))), - ) + (0 + 16 + 16 + 64, Acquire(1792, AcquireChannel(0), MemorySlot(0))), + (0 + 16 + 16 + 64, Acquire(1792, AcquireChannel(1), MemorySlot(1))), + ) for actual, expected in zip(sched.instructions, expected.instructions): self.assertEqual(actual[0], expected[0]) self.assertEqual(actual[1], expected[1]) @@ -730,7 +788,8 @@ def test_alap_resource_respecting(self): qc = QuantumCircuit(q, c) qc.cx(q[0], q[1]) qc.sx(q[1]) - sched = schedule(qc, self.backend, method="as_late_as_possible") + with self.assertWarns(DeprecationWarning): + sched = schedule(qc, self.backend, method="as_late_as_possible") insts = sched.instructions # This is ShiftPhase for the cx operation. @@ -745,7 +804,8 @@ def test_alap_resource_respecting(self): qc.cx(q[0], q[1]) qc.sx(q[1]) qc.measure(q, c) - sched = schedule(qc, self.backend, method="as_late_as_possible") + with self.assertWarns(DeprecationWarning): + sched = schedule(qc, self.backend, method="as_late_as_possible") # 64dt for cx operation + 16dt for sx operation # So, the pulses in MeasureChannel0 and 1 starts from 80dt. @@ -757,8 +817,9 @@ def test_inst_map_schedules_unaltered(self): c = ClassicalRegister(2) qc = QuantumCircuit(q, c) qc.cx(q[0], q[1]) - sched1 = schedule(qc, self.backend, method="as_soon_as_possible") - sched2 = schedule(qc, self.backend, method="as_late_as_possible") + with self.assertWarns(DeprecationWarning): + sched1 = schedule(qc, self.backend, method="as_soon_as_possible") + sched2 = schedule(qc, self.backend, method="as_late_as_possible") for asap, alap in zip(sched1.instructions, sched2.instructions): self.assertEqual(asap[0], alap[0]) self.assertEqual(asap[1], alap[1]) @@ -784,36 +845,37 @@ def test_measure_combined(self): qc.measure(q[1], c[1]) qc.measure(q[1], c[1]) - sched = schedule(qc, self.backend, method="as_soon_as_possible") - - expected_sched = Schedule( - # This is the schedule to implement sx gate. - (0, self.inst_map.get("sx", [0])), - # This is the schedule to implement cx gate - (0 + 16, self.inst_map.get("cx", [0, 1])), - # This is the schedule for the measurements on qubits 0 and 1 (combined) - ( - 0 + 16 + 64, - self.inst_map.get("measure", [0]).filter( - channels=[MeasureChannel(0), MeasureChannel(1)] + with self.assertWarns(DeprecationWarning): + sched = schedule(qc, self.backend, method="as_soon_as_possible") + + expected_sched = Schedule( + # This is the schedule to implement sx gate. + (0, self.inst_map.get("sx", [0])), + # This is the schedule to implement cx gate + (0 + 16, self.inst_map.get("cx", [0, 1])), + # This is the schedule for the measurements on qubits 0 and 1 (combined) + ( + 0 + 16 + 64, + self.inst_map.get("measure", [0]).filter( + channels=[MeasureChannel(0), MeasureChannel(1)] + ), + ), + ( + 0 + 16 + 64, + self.inst_map.get("measure", [0]).filter( + channels=[AcquireChannel(0), AcquireChannel(1)] + ), ), - ), - ( - 0 + 16 + 64, - self.inst_map.get("measure", [0]).filter( - channels=[AcquireChannel(0), AcquireChannel(1)] + # This is the schedule for the second measurement on qubit 1 + ( + 0 + 16 + 64 + 1792, + self.inst_map.get("measure", [1]).filter(channels=[MeasureChannel(1)]), ), - ), - # This is the schedule for the second measurement on qubit 1 - ( - 0 + 16 + 64 + 1792, - self.inst_map.get("measure", [1]).filter(channels=[MeasureChannel(1)]), - ), - ( - 0 + 16 + 64 + 1792, - self.inst_map.get("measure", [1]).filter(channels=[AcquireChannel(1)]), - ), - ) + ( + 0 + 16 + 64 + 1792, + self.inst_map.get("measure", [1]).filter(channels=[AcquireChannel(1)]), + ), + ) self.assertEqual(sched.instructions, expected_sched.instructions) def test_3q_schedule(self): @@ -838,15 +900,16 @@ def test_3q_schedule(self): qc.cx(q[1], q[2]) qc.sx(q[2]) - sched = schedule(qc, self.backend, method="asap") - expected = Schedule( - (0, self.inst_map.get("cx", [0, 1])), - (0, self.inst_map.get("sx", [2])), - (0 + 64, self.inst_map.get("sx", [0])), - (0 + 64, self.inst_map.get("x", [1])), - (0 + 64 + 16, self.inst_map.get("cx", [1, 2])), - (0 + 64 + 16 + 64, self.inst_map.get("sx", [2])), - ) + with self.assertWarns(DeprecationWarning): + sched = schedule(qc, self.backend, method="asap") + expected = Schedule( + (0, self.inst_map.get("cx", [0, 1])), + (0, self.inst_map.get("sx", [2])), + (0 + 64, self.inst_map.get("sx", [0])), + (0 + 64, self.inst_map.get("x", [1])), + (0 + 64 + 16, self.inst_map.get("cx", [1, 2])), + (0 + 64 + 16 + 64, self.inst_map.get("sx", [2])), + ) for actual, expected in zip(sched.instructions, expected.instructions): self.assertEqual(actual[0], expected[0]) self.assertEqual(actual[1], expected[1]) @@ -859,8 +922,9 @@ def test_schedule_multi(self): qc0.cx(q[0], q[1]) qc1 = QuantumCircuit(q, c) qc1.cx(q[0], q[1]) - schedules = schedule([qc0, qc1], self.backend) - expected_insts = schedule(qc0, self.backend).instructions + with self.assertWarns(DeprecationWarning): + schedules = schedule([qc0, qc1], self.backend) + expected_insts = schedule(qc0, self.backend).instructions for actual, expected in zip(schedules[0].instructions, expected_insts): self.assertEqual(actual[0], expected[0]) self.assertEqual(actual[1], expected[1]) @@ -871,9 +935,11 @@ def test_circuit_name_kept(self): c = ClassicalRegister(2) qc = QuantumCircuit(q, c, name="CIRCNAME") qc.cx(q[0], q[1]) - sched = schedule(qc, self.backend, method="asap") + with self.assertWarns(DeprecationWarning): + sched = schedule(qc, self.backend, method="asap") self.assertEqual(sched.name, qc.name) - sched = schedule(qc, self.backend, method="alap") + with self.assertWarns(DeprecationWarning): + sched = schedule(qc, self.backend, method="alap") self.assertEqual(sched.name, qc.name) def test_can_add_gates_into_free_space(self): @@ -893,15 +959,16 @@ def test_can_add_gates_into_free_space(self): qc.sx(qr[i]) qc.x(qr[i]) qc.sx(qr[i]) - sched = schedule(qc, self.backend, method="alap") - expected = Schedule( - (0, self.inst_map.get("sx", [0])), - (0, self.inst_map.get("sx", [1])), - (0 + 16, self.inst_map.get("x", [0])), - (0 + 16, self.inst_map.get("x", [1])), - (0 + 16 + 16, self.inst_map.get("sx", [0])), - (0 + 16 + 16, self.inst_map.get("sx", [1])), - ) + with self.assertWarns(DeprecationWarning): + sched = schedule(qc, self.backend, method="alap") + expected = Schedule( + (0, self.inst_map.get("sx", [0])), + (0, self.inst_map.get("sx", [1])), + (0 + 16, self.inst_map.get("x", [0])), + (0 + 16, self.inst_map.get("x", [1])), + (0 + 16 + 16, self.inst_map.get("sx", [0])), + (0 + 16 + 16, self.inst_map.get("sx", [1])), + ) for actual, expected in zip(sched.instructions, expected.instructions): self.assertEqual(actual[0], expected[0]) self.assertEqual(actual[1], expected[1]) @@ -918,15 +985,16 @@ def test_barriers_in_middle(self): qc.x(qr[i]) qc.barrier(qr[i]) qc.sx(qr[i]) - sched = schedule(qc, self.backend, method="alap") - expected = Schedule( - (0, self.inst_map.get("sx", [0])), - (0, self.inst_map.get("sx", [1])), - (0 + 16, self.inst_map.get("x", [0])), - (0 + 16, self.inst_map.get("x", [1])), - (0 + 16 + 16, self.inst_map.get("sx", [0])), - (0 + 16 + 16, self.inst_map.get("sx", [1])), - ) + with self.assertWarns(DeprecationWarning): + sched = schedule(qc, self.backend, method="alap") + expected = Schedule( + (0, self.inst_map.get("sx", [0])), + (0, self.inst_map.get("sx", [1])), + (0 + 16, self.inst_map.get("x", [0])), + (0 + 16, self.inst_map.get("x", [1])), + (0 + 16 + 16, self.inst_map.get("sx", [0])), + (0 + 16 + 16, self.inst_map.get("sx", [1])), + ) for actual, expected in zip(sched.instructions, expected.instructions): self.assertEqual(actual[0], expected[0]) self.assertEqual(actual[1], expected[1]) @@ -936,11 +1004,13 @@ def test_parametric_input(self): qr = QuantumRegister(1) qc = QuantumCircuit(qr) qc.append(Gate("gauss", 1, []), qargs=[qr[0]]) - custom_gauss = Schedule( - Play(Gaussian(duration=25, sigma=4, amp=0.5, angle=pi / 2), DriveChannel(0)) - ) + with self.assertWarns(DeprecationWarning): + custom_gauss = Schedule( + Play(Gaussian(duration=25, sigma=4, amp=0.5, angle=pi / 2), DriveChannel(0)) + ) self.inst_map.add("gauss", [0], custom_gauss) - sched = schedule(qc, self.backend, inst_map=self.inst_map) + with self.assertWarns(DeprecationWarning): + sched = schedule(qc, self.backend, inst_map=self.inst_map) self.assertEqual(sched.instructions[0], custom_gauss.instructions[0]) def test_pulse_gates(self): @@ -950,14 +1020,20 @@ def test_pulse_gates(self): qc.append(U2Gate(0, 0), [q[0]]) qc.barrier(q[0], q[1]) qc.append(U2Gate(0, 0), [q[1]]) - qc.add_calibration("u2", [0], Schedule(Play(Gaussian(28, 0.2, 4), DriveChannel(0))), [0, 0]) - qc.add_calibration("u2", [1], Schedule(Play(Gaussian(28, 0.2, 4), DriveChannel(1))), [0, 0]) - - sched = schedule(qc, self.backend) - expected = Schedule( - Play(Gaussian(28, 0.2, 4), DriveChannel(0)), - (28, Schedule(Play(Gaussian(28, 0.2, 4), DriveChannel(1)))), - ) + with self.assertWarns(DeprecationWarning): + qc.add_calibration( + "u2", [0], Schedule(Play(Gaussian(28, 0.2, 4), DriveChannel(0))), [0, 0] + ) + qc.add_calibration( + "u2", [1], Schedule(Play(Gaussian(28, 0.2, 4), DriveChannel(1))), [0, 0] + ) + + with self.assertWarns(DeprecationWarning): + sched = schedule(qc, self.backend) + expected = Schedule( + Play(Gaussian(28, 0.2, 4), DriveChannel(0)), + (28, Schedule(Play(Gaussian(28, 0.2, 4), DriveChannel(1)))), + ) self.assertEqual(sched.instructions, expected.instructions) def test_calibrated_measurements(self): @@ -968,22 +1044,23 @@ def test_calibrated_measurements(self): qc.sx(0) qc.measure(q[0], c[0]) - meas_sched = Play( - GaussianSquare( - duration=1472, - sigma=64, - width=1216, - amp=0.2400000000002, - angle=-0.247301694, - name="my_custom_calibration", - ), - MeasureChannel(0), - ) - meas_sched |= Acquire(1472, AcquireChannel(0), MemorySlot(0)) - qc.add_calibration("measure", [0], meas_sched) - - sched = schedule(qc, self.backend) - expected = Schedule(self.inst_map.get("sx", [0]), (16, meas_sched)) + with self.assertWarns(DeprecationWarning): + meas_sched = Play( + GaussianSquare( + duration=1472, + sigma=64, + width=1216, + amp=0.2400000000002, + angle=-0.247301694, + name="my_custom_calibration", + ), + MeasureChannel(0), + ) + meas_sched |= Acquire(1472, AcquireChannel(0), MemorySlot(0)) + qc.add_calibration("measure", [0], meas_sched) + + sched = schedule(qc, self.backend) + expected = Schedule(self.inst_map.get("sx", [0]), (16, meas_sched)) self.assertEqual(sched.instructions, expected.instructions) def test_subset_calibrated_measurements(self): @@ -994,17 +1071,19 @@ def test_subset_calibrated_measurements(self): qc.measure(1, 1) qc.measure(2, 2) meas_scheds = [] - for qubit in [0, 2]: - meas = Play(Gaussian(1200, 0.2, 4), MeasureChannel(qubit)) + Acquire( - 1200, AcquireChannel(qubit), MemorySlot(qubit) - ) - meas_scheds.append(meas) - qc.add_calibration("measure", [qubit], meas) - - meas = macros.measure(qubits=[1], backend=self.backend, qubit_mem_slots={0: 0, 1: 1}) - meas = meas.exclude(channels=[AcquireChannel(0), AcquireChannel(2)]) - sched = schedule(qc, self.backend) - expected = Schedule(meas_scheds[0], meas_scheds[1], meas) + with self.assertWarns(DeprecationWarning): + for qubit in [0, 2]: + meas = Play(Gaussian(1200, 0.2, 4), MeasureChannel(qubit)) + Acquire( + 1200, AcquireChannel(qubit), MemorySlot(qubit) + ) + meas_scheds.append(meas) + with self.assertWarns(DeprecationWarning): + qc.add_calibration("measure", [qubit], meas) + + meas = macros.measure(qubits=[1], backend=self.backend, qubit_mem_slots={0: 0, 1: 1}) + meas = meas.exclude(channels=[AcquireChannel(0), AcquireChannel(2)]) + sched = schedule(qc, self.backend) + expected = Schedule(meas_scheds[0], meas_scheds[1], meas) self.assertEqual(sched.instructions, expected.instructions) def test_clbits_of_calibrated_measurements(self): @@ -1014,13 +1093,14 @@ def test_clbits_of_calibrated_measurements(self): qc = QuantumCircuit(q, c) qc.measure(q[0], c[1]) - meas_sched = Play(Gaussian(1200, 0.2, 4), MeasureChannel(0)) - meas_sched |= Acquire(1200, AcquireChannel(0), MemorySlot(0)) - qc.add_calibration("measure", [0], meas_sched) + with self.assertWarns(DeprecationWarning): + meas_sched = Play(Gaussian(1200, 0.2, 4), MeasureChannel(0)) + meas_sched |= Acquire(1200, AcquireChannel(0), MemorySlot(0)) + qc.add_calibration("measure", [0], meas_sched) - sched = schedule(qc, self.backend) - # Doesn't use the calibrated schedule because the classical memory slots do not match - expected = Schedule(macros.measure([0], self.backend, qubit_mem_slots={0: 1})) + sched = schedule(qc, self.backend) + # Doesn't use the calibrated schedule because the classical memory slots do not match + expected = Schedule(macros.measure([0], self.backend, qubit_mem_slots={0: 1})) self.assertEqual(sched.instructions, expected.instructions) def test_metadata_is_preserved_alap(self): @@ -1031,7 +1111,8 @@ def test_metadata_is_preserved_alap(self): qc.barrier(q[0], q[1]) qc.sx(q[1]) qc.metadata = {"experiment_type": "gst", "execution_number": "1234"} - sched = schedule(qc, self.backend, method="alap") + with self.assertWarns(DeprecationWarning): + sched = schedule(qc, self.backend, method="alap") self.assertEqual({"experiment_type": "gst", "execution_number": "1234"}, sched.metadata) def test_metadata_is_preserved_asap(self): @@ -1042,7 +1123,8 @@ def test_metadata_is_preserved_asap(self): qc.barrier(q[0], q[1]) qc.sx(q[1]) qc.metadata = {"experiment_type": "gst", "execution_number": "1234"} - sched = schedule(qc, self.backend, method="asap") + with self.assertWarns(DeprecationWarning): + sched = schedule(qc, self.backend, method="asap") self.assertEqual({"experiment_type": "gst", "execution_number": "1234"}, sched.metadata) def test_scheduler_with_params_bound(self): @@ -1050,10 +1132,14 @@ def test_scheduler_with_params_bound(self): x = Parameter("x") qc = QuantumCircuit(2) qc.append(Gate("pulse_gate", 1, [x]), [0]) - expected_schedule = Schedule() - qc.add_calibration(gate="pulse_gate", qubits=[0], schedule=expected_schedule, params=[x]) + with self.assertWarns(DeprecationWarning): + expected_schedule = Schedule() + qc.add_calibration( + gate="pulse_gate", qubits=[0], schedule=expected_schedule, params=[x] + ) qc = qc.assign_parameters({x: 1}) - sched = schedule(qc, self.backend) + with self.assertWarns(DeprecationWarning): + sched = schedule(qc, self.backend) self.assertEqual(sched, expected_schedule) def test_scheduler_with_params_not_bound(self): @@ -1061,65 +1147,72 @@ def test_scheduler_with_params_not_bound(self): x = Parameter("amp") qc = QuantumCircuit(2) qc.append(Gate("pulse_gate", 1, [x]), [0]) - with build() as expected_schedule: - play(Gaussian(duration=160, amp=x, sigma=40), DriveChannel(0)) - qc.add_calibration(gate="pulse_gate", qubits=[0], schedule=expected_schedule, params=[x]) - sched = schedule(qc, self.backend) - self.assertEqual(sched, transforms.target_qobj_transform(expected_schedule)) + with self.assertWarns(DeprecationWarning): + with build() as expected_schedule: + play(Gaussian(duration=160, amp=x, sigma=40), DriveChannel(0)) + qc.add_calibration( + gate="pulse_gate", qubits=[0], schedule=expected_schedule, params=[x] + ) + sched = schedule(qc, self.backend) + with self.assertWarns(DeprecationWarning): + self.assertEqual(sched, transforms.target_qobj_transform(expected_schedule)) def test_schedule_block_in_instmap(self): """Test schedule block in instmap can be scheduled.""" duration = Parameter("duration") - with build() as pulse_prog: - play(Gaussian(duration, 0.1, 10), DriveChannel(0)) + with self.assertWarns(DeprecationWarning): + with build() as pulse_prog: + play(Gaussian(duration, 0.1, 10), DriveChannel(0)) - instmap = InstructionScheduleMap() + instmap = InstructionScheduleMap() instmap.add("block_gate", (0,), pulse_prog, ["duration"]) qc = QuantumCircuit(1) qc.append(Gate("block_gate", 1, [duration]), [0]) qc.assign_parameters({duration: 100}, inplace=True) - sched = schedule(qc, self.backend, inst_map=instmap) + with self.assertWarns(DeprecationWarning): + sched = schedule(qc, self.backend, inst_map=instmap) - ref_sched = Schedule() - ref_sched += Play(Gaussian(100, 0.1, 10), DriveChannel(0)) + ref_sched = Schedule() + ref_sched += Play(Gaussian(100, 0.1, 10), DriveChannel(0)) self.assertEqual(sched, ref_sched) def test_inst_sched_map_get_measure_0(self): """Test that Schedule returned by backend.instruction_schedule_map.get('measure', [0]) is actually Schedule for just qubit_0""" - sched_from_backend = self.backend.instruction_schedule_map.get("measure", [0]) - expected_sched = Schedule( - ( - 0, - Play( - Waveform(samples=self.pulse_2_samples, name="pulse_2"), - MeasureChannel(0), - name="pulse_2", + with self.assertWarns(DeprecationWarning): + sched_from_backend = self.backend.instruction_schedule_map.get("measure", [0]) + expected_sched = Schedule( + ( + 0, + Play( + Waveform(samples=self.pulse_2_samples, name="pulse_2"), + MeasureChannel(0), + name="pulse_2", + ), ), - ), - ( - 0, - Play( - Waveform(samples=self.pulse_2_samples, name="pulse_2"), - MeasureChannel(1), - name="pulse_2", + ( + 0, + Play( + Waveform(samples=self.pulse_2_samples, name="pulse_2"), + MeasureChannel(1), + name="pulse_2", + ), ), - ), - ( - 0, - Play( - Waveform(samples=self.pulse_2_samples, name="pulse_2"), - MeasureChannel(2), - name="pulse_2", + ( + 0, + Play( + Waveform(samples=self.pulse_2_samples, name="pulse_2"), + MeasureChannel(2), + name="pulse_2", + ), ), - ), - (0, Acquire(1792, AcquireChannel(0), MemorySlot(0))), - (0, Acquire(1792, AcquireChannel(1), MemorySlot(1))), - (0, Acquire(1792, AcquireChannel(2), MemorySlot(2))), - name="measure", - ) + (0, Acquire(1792, AcquireChannel(0), MemorySlot(0))), + (0, Acquire(1792, AcquireChannel(1), MemorySlot(1))), + (0, Acquire(1792, AcquireChannel(2), MemorySlot(2))), + name="measure", + ) self.assertEqual(sched_from_backend, expected_sched) diff --git a/test/python/transpiler/legacy_scheduling/test_instruction_alignments.py b/test/python/transpiler/legacy_scheduling/test_instruction_alignments.py index c95d65422d4b..3f093d18c517 100644 --- a/test/python/transpiler/legacy_scheduling/test_instruction_alignments.py +++ b/test/python/transpiler/legacy_scheduling/test_instruction_alignments.py @@ -332,21 +332,25 @@ class TestPulseGateValidation(QiskitTestCase): def setUp(self): super().setUp() - self.pulse_gate_validation_pass = ValidatePulseGates(granularity=16, min_length=64) + with self.assertWarns(DeprecationWarning): + self.pulse_gate_validation_pass = ValidatePulseGates(granularity=16, min_length=64) def test_invalid_pulse_duration(self): """Kill pass manager if invalid pulse gate is found.""" # this is invalid duration pulse # this will cause backend error since this doesn't fit with waveform memory chunk. - custom_gate = pulse.Schedule(name="custom_x_gate") - custom_gate.insert( - 0, pulse.Play(pulse.Constant(100, 0.1), pulse.DriveChannel(0)), inplace=True - ) + + with self.assertWarns(DeprecationWarning): + custom_gate = pulse.Schedule(name="custom_x_gate") + custom_gate.insert( + 0, pulse.Play(pulse.Constant(100, 0.1), pulse.DriveChannel(0)), inplace=True + ) circuit = QuantumCircuit(1) circuit.x(0) - circuit.add_calibration("x", qubits=(0,), schedule=custom_gate) + with self.assertWarns(DeprecationWarning): + circuit.add_calibration("x", qubits=(0,), schedule=custom_gate) with self.assertRaises(TranspilerError): self.pulse_gate_validation_pass(circuit) @@ -356,14 +360,16 @@ def test_short_pulse_duration(self): # this is invalid duration pulse # this will cause backend error since this doesn't fit with waveform memory chunk. - custom_gate = pulse.Schedule(name="custom_x_gate") - custom_gate.insert( - 0, pulse.Play(pulse.Constant(32, 0.1), pulse.DriveChannel(0)), inplace=True - ) + with self.assertWarns(DeprecationWarning): + custom_gate = pulse.Schedule(name="custom_x_gate") + custom_gate.insert( + 0, pulse.Play(pulse.Constant(32, 0.1), pulse.DriveChannel(0)), inplace=True + ) circuit = QuantumCircuit(1) circuit.x(0) - circuit.add_calibration("x", qubits=(0,), schedule=custom_gate) + with self.assertWarns(DeprecationWarning): + circuit.add_calibration("x", qubits=(0,), schedule=custom_gate) with self.assertRaises(TranspilerError): self.pulse_gate_validation_pass(circuit) @@ -374,17 +380,19 @@ def test_short_pulse_duration_multiple_pulse(self): # this is invalid duration pulse # however total gate schedule length is 64, which accidentally satisfies the constraints # this should fail in the validation - custom_gate = pulse.Schedule(name="custom_x_gate") - custom_gate.insert( - 0, pulse.Play(pulse.Constant(32, 0.1), pulse.DriveChannel(0)), inplace=True - ) - custom_gate.insert( - 32, pulse.Play(pulse.Constant(32, 0.1), pulse.DriveChannel(0)), inplace=True - ) + with self.assertWarns(DeprecationWarning): + custom_gate = pulse.Schedule(name="custom_x_gate") + custom_gate.insert( + 0, pulse.Play(pulse.Constant(32, 0.1), pulse.DriveChannel(0)), inplace=True + ) + custom_gate.insert( + 32, pulse.Play(pulse.Constant(32, 0.1), pulse.DriveChannel(0)), inplace=True + ) circuit = QuantumCircuit(1) circuit.x(0) - circuit.add_calibration("x", qubits=(0,), schedule=custom_gate) + with self.assertWarns(DeprecationWarning): + circuit.add_calibration("x", qubits=(0,), schedule=custom_gate) with self.assertRaises(TranspilerError): self.pulse_gate_validation_pass(circuit) @@ -393,14 +401,16 @@ def test_valid_pulse_duration(self): """No error raises if valid calibration is provided.""" # this is valid duration pulse - custom_gate = pulse.Schedule(name="custom_x_gate") - custom_gate.insert( - 0, pulse.Play(pulse.Constant(160, 0.1), pulse.DriveChannel(0)), inplace=True - ) + with self.assertWarns(DeprecationWarning): + custom_gate = pulse.Schedule(name="custom_x_gate") + custom_gate.insert( + 0, pulse.Play(pulse.Constant(160, 0.1), pulse.DriveChannel(0)), inplace=True + ) circuit = QuantumCircuit(1) circuit.x(0) - circuit.add_calibration("x", qubits=(0,), schedule=custom_gate) + with self.assertWarns(DeprecationWarning): + circuit.add_calibration("x", qubits=(0,), schedule=custom_gate) # just not raise an error self.pulse_gate_validation_pass(circuit) diff --git a/test/python/transpiler/test_calibrationbuilder.py b/test/python/transpiler/test_calibrationbuilder.py index 90676a38a586..bd874a50954e 100644 --- a/test/python/transpiler/test_calibrationbuilder.py +++ b/test/python/transpiler/test_calibrationbuilder.py @@ -45,8 +45,10 @@ RXCalibrationBuilder, ) from test import QiskitTestCase # pylint: disable=wrong-import-order +from qiskit.utils.deprecate_pulse import decorate_test_methods, ignore_pulse_deprecation_warnings +@decorate_test_methods(ignore_pulse_deprecation_warnings) class TestCalibrationBuilder(QiskitTestCase): """Test the Calibration Builder.""" @@ -103,6 +105,7 @@ def d1m_play(self, cr_schedule): @ddt +@decorate_test_methods(ignore_pulse_deprecation_warnings) class TestRZXCalibrationBuilder(TestCalibrationBuilder): """Test RZXCalibrationBuilder.""" @@ -185,8 +188,9 @@ def build_reverse( rz_qc_q1 = QuantumCircuit(2) rz_qc_q1.rz(pi / 2, 1) - rz_sched_q0 = schedule(rz_qc_q0, backend) - rz_sched_q1 = schedule(rz_qc_q1, backend) + with self.assertWarns(DeprecationWarning): + rz_sched_q0 = schedule(rz_qc_q0, backend) + rz_sched_q1 = schedule(rz_qc_q1, backend) with builder.build( backend, @@ -270,7 +274,7 @@ def test_rzx_calibration_cr_pulse_stretch(self, theta: float): # TODO this tests does not work with BackendV2/GenericBackendV2 # https://github.com/Qiskit/qiskit/issues/12834 backend = Fake27QPulseV1() - inst_map = backend.defaults().instruction_schedule_map + inst_map = backend.defaults().instruction_schedule_map cr_schedule = inst_map.get("cx", (0, 1)) with builder.build() as test_sched: RZXCalibrationBuilder.rescale_cr_inst(self.u0p_play(cr_schedule), theta) @@ -284,7 +288,7 @@ def test_rzx_calibration_rotary_pulse_stretch(self, theta: float): """Test that rotary pulse durations are computed correctly.""" with self.assertWarns(DeprecationWarning): backend = Fake27QPulseV1() - inst_map = backend.defaults().instruction_schedule_map + inst_map = backend.defaults().instruction_schedule_map cr_schedule = inst_map.get("cx", (0, 1)) with builder.build() as test_sched: RZXCalibrationBuilder.rescale_cr_inst(self.d1p_play(cr_schedule), theta) @@ -302,15 +306,16 @@ def test_raise(self): dag = circuit_to_dag(qc) with self.assertWarns(DeprecationWarning): backend = Fake7QPulseV1() - # The error is raised when calibrations in multi-qubit - # gates are not detected. - # We force this by removing the 'cx' entries from the - # instruction schedule map. - inst_map = backend.defaults().instruction_schedule_map + # The error is raised when calibrations in multi-qubit + # gates are not detected. + # We force this by removing the 'cx' entries from the + # instruction schedule map. + inst_map = backend.defaults().instruction_schedule_map for qubits in inst_map.qubits_with_instruction("cx"): inst_map.remove("cx", qubits) inst_map = backend.defaults().instruction_schedule_map - _pass = RZXCalibrationBuilder(inst_map) + with self.assertWarns(DeprecationWarning): + _pass = RZXCalibrationBuilder(inst_map) qubit_map = {qubit: i for i, qubit in enumerate(dag.qubits)} with self.assertRaises(QiskitError): @@ -328,8 +333,8 @@ def test_ecr_cx_forward(self): with self.assertWarns(DeprecationWarning): backend = Fake27QPulseV1() - inst_map = backend.defaults().instruction_schedule_map - _pass = RZXCalibrationBuilder(inst_map) + inst_map = backend.defaults().instruction_schedule_map + _pass = RZXCalibrationBuilder(inst_map) test_qc = PassManager(_pass).run(qc) cr_schedule = inst_map.get("cx", (0, 1)) @@ -342,7 +347,8 @@ def test_ecr_cx_forward(self): self.d1m_play(cr_schedule), ) - self.assertEqual(schedule(test_qc, backend), target_qobj_transform(ref_sched)) + with self.assertWarns(DeprecationWarning): + self.assertEqual(schedule(test_qc, backend), target_qobj_transform(ref_sched)) def test_ecr_cx_reverse(self): """Test that correct pulse sequence is generated for non-native CR pair.""" @@ -354,8 +360,8 @@ def test_ecr_cx_reverse(self): with self.assertWarns(DeprecationWarning): backend = Fake27QPulseV1() - inst_map = backend.defaults().instruction_schedule_map - _pass = RZXCalibrationBuilder(inst_map) + inst_map = backend.defaults().instruction_schedule_map + _pass = RZXCalibrationBuilder(inst_map) test_qc = PassManager(_pass).run(qc) cr_schedule = inst_map.get("cx", (0, 1)) @@ -368,7 +374,8 @@ def test_ecr_cx_reverse(self): self.d1m_play(cr_schedule), ) - self.assertEqual(schedule(test_qc, backend), target_qobj_transform(ref_sched)) + with self.assertWarns(DeprecationWarning): + self.assertEqual(schedule(test_qc, backend), target_qobj_transform(ref_sched)) def test_pass_alive_with_dcx_ish(self): """Test if the pass is not terminated by error with direct CX input.""" @@ -381,20 +388,23 @@ def test_pass_alive_with_dcx_ish(self): compensation_tone = Waveform(0.1 * np.ones(800, dtype=complex)) cx_sched.insert(0, Play(compensation_tone, DriveChannel(0)), inplace=True) - inst_map = InstructionScheduleMap() + with self.assertWarns(DeprecationWarning): + inst_map = InstructionScheduleMap() inst_map.add("cx", (1, 0), schedule=cx_sched) theta = pi / 3 rzx_qc = circuit.QuantumCircuit(2) rzx_qc.rzx(theta, 1, 0) - pass_ = RZXCalibrationBuilder(instruction_schedule_map=inst_map) + with self.assertWarns(DeprecationWarning): + pass_ = RZXCalibrationBuilder(instruction_schedule_map=inst_map) with self.assertWarns(UserWarning): # User warning that says q0 q1 is invalid cal_qc = PassManager(pass_).run(rzx_qc) self.assertEqual(cal_qc, rzx_qc) +@decorate_test_methods(ignore_pulse_deprecation_warnings) class TestRZXCalibrationBuilderNoEcho(TestCalibrationBuilder): """Test RZXCalibrationBuilderNoEcho.""" @@ -442,9 +452,9 @@ def test_ecr_cx_forward(self): with self.assertWarns(DeprecationWarning): backend = Fake27QPulseV1() - inst_map = backend.defaults().instruction_schedule_map + inst_map = backend.defaults().instruction_schedule_map - _pass = RZXCalibrationBuilderNoEcho(inst_map) + _pass = RZXCalibrationBuilderNoEcho(inst_map) test_qc = PassManager(_pass).run(qc) cr_schedule = inst_map.get("cx", (0, 1)) @@ -454,7 +464,8 @@ def test_ecr_cx_forward(self): self.d1p_play(cr_schedule), ) - self.assertEqual(schedule(test_qc, backend), target_qobj_transform(ref_sched)) + with self.assertWarns(DeprecationWarning): + self.assertEqual(schedule(test_qc, backend), target_qobj_transform(ref_sched)) # # TODO - write test for forward ECR native pulse # def test_ecr_forward(self): @@ -470,14 +481,16 @@ def test_pass_alive_with_dcx_ish(self): compensation_tone = Waveform(0.1 * np.ones(800, dtype=complex)) cx_sched.insert(0, Play(compensation_tone, DriveChannel(0)), inplace=True) - inst_map = InstructionScheduleMap() + with self.assertWarns(DeprecationWarning): + inst_map = InstructionScheduleMap() inst_map.add("cx", (1, 0), schedule=cx_sched) theta = pi / 3 rzx_qc = circuit.QuantumCircuit(2) rzx_qc.rzx(theta, 1, 0) - pass_ = RZXCalibrationBuilderNoEcho(instruction_schedule_map=inst_map) + with self.assertWarns(DeprecationWarning): + pass_ = RZXCalibrationBuilderNoEcho(instruction_schedule_map=inst_map) with self.assertWarns(UserWarning): # User warning that says q0 q1 is invalid cal_qc = PassManager(pass_).run(rzx_qc) @@ -485,6 +498,7 @@ def test_pass_alive_with_dcx_ish(self): @ddt +@decorate_test_methods(ignore_pulse_deprecation_warnings) class TestRXCalibrationBuilder(QiskitTestCase): """Test RXCalibrationBuilder.""" @@ -495,7 +509,8 @@ def compute_correct_rx_amplitude(self, rx_theta: float, sx_amp: float): def test_not_supported_if_no_sx_schedule(self): """Test that supported() returns False when the target does not have SX calibration.""" empty_target = Target() - tp = RXCalibrationBuilder(empty_target) + with self.assertWarns(DeprecationWarning): + tp = RXCalibrationBuilder(empty_target) qubits = (0,) node_op = DAGOpNode(RXGate(0.5), qubits, []) self.assertFalse(tp.supported(node_op, qubits)) @@ -505,8 +520,9 @@ def test_not_supported_if_sx_not_drag(self): target = Target() with builder.build() as square_sx_cal: builder.play(Square(amp=0.1, duration=160, phase=0), DriveChannel(0)) - target.add_instruction(SXGate(), {(0,): InstructionProperties(calibration=square_sx_cal)}) - tp = RXCalibrationBuilder(target) + with self.assertWarns(DeprecationWarning): + target.add_instruction(SXGate(), {(0,): InstructionProperties(calibration=square_sx_cal)}) + tp = RXCalibrationBuilder(target) qubits = (0,) node_op = DAGOpNode(RXGate(0.5), qubits, []) self.assertFalse(tp.supported(node_op, qubits)) @@ -517,7 +533,8 @@ def test_raises_error_when_rotation_angle_not_assigned(self): The QiskitError occurs while trying to typecast the Parameter into a float. """ backend = GenericBackendV2(num_qubits=5, seed=42) - tp = RXCalibrationBuilder(backend.target) + with self.assertWarns(DeprecationWarning): + tp = RXCalibrationBuilder(backend.target) qubits = (0,) rx = RXGate(Parameter("theta")) with self.assertRaises(QiskitError): @@ -538,12 +555,13 @@ def test_pulse_schedule(self, theta: float): ), DriveChannel(0), ) - dummy_target.add_instruction( - SXGate(), {(0,): InstructionProperties(calibration=dummy_sx_cal)} - ) - tp = RXCalibrationBuilder(dummy_target) - test = tp.get_calibration(RXGate(theta), qubits=(0,)) + with self.assertWarns(DeprecationWarning): + dummy_target.add_instruction( + SXGate(), {(0,): InstructionProperties(calibration=dummy_sx_cal)} + ) + tp = RXCalibrationBuilder(dummy_target) + test = tp.get_calibration(RXGate(theta), qubits=(0,)) with builder.build(backend=backend) as correct_rx_schedule: builder.play( @@ -577,12 +595,15 @@ def test_with_normalizerxangles(self): ), inplace=True, ) - ism = InstructionScheduleMap() + with self.assertWarns(DeprecationWarning): + ism = InstructionScheduleMap() ism.add("sx", (0,), sched) - backend = GenericBackendV2(num_qubits=5, calibrate_instructions=ism, seed=42) + with self.assertWarns(DeprecationWarning): + backend = GenericBackendV2(num_qubits=5, calibrate_instructions=ism, seed=42) # NormalizeRXAngle pass should also be included because it's a required pass. - pm = PassManager(RXCalibrationBuilder(backend.target)) + with self.assertWarns(DeprecationWarning): + pm = PassManager(RXCalibrationBuilder(backend.target)) qc = QuantumCircuit(1) qc.rx(np.pi / 3, 0) @@ -592,4 +613,5 @@ def test_with_normalizerxangles(self): # Only RX(pi/3) should get a rx calibration. # The others should be converted to SX and X tc = pm.run(qc) - self.assertEqual(len(tc.calibrations["rx"]), 1) + with self.assertWarns(DeprecationWarning): + self.assertEqual(len(tc.calibrations["rx"]), 1) diff --git a/test/python/transpiler/test_dynamical_decoupling.py b/test/python/transpiler/test_dynamical_decoupling.py index 38c5c3c2d4ab..d56595cd639a 100644 --- a/test/python/transpiler/test_dynamical_decoupling.py +++ b/test/python/transpiler/test_dynamical_decoupling.py @@ -374,11 +374,13 @@ def test_insert_dd_with_pulse_gate_calibrations(self): # Change duration to 100 from the 50 in self.durations to make sure # gate duration is used correctly. - with pulse.builder.build() as x_sched: - pulse.builder.delay(100, pulse.DriveChannel(0)) + with self.assertWarns(DeprecationWarning): + with pulse.builder.build() as x_sched: + pulse.builder.delay(100, pulse.DriveChannel(0)) circ_in = self.ghz4.measure_all(inplace=False) - circ_in.add_calibration(XGate(), (0,), x_sched) + with self.assertWarns(DeprecationWarning): + circ_in.add_calibration(XGate(), (0,), x_sched) ghz4_dd = pm.run(circ_in) @@ -397,7 +399,8 @@ def test_insert_dd_with_pulse_gate_calibrations(self): expected = expected.compose(Delay(300), [1]) expected.measure_all() - expected.add_calibration(XGate(), (0,), x_sched) + with self.assertWarns(DeprecationWarning): + expected.add_calibration(XGate(), (0,), x_sched) self.assertEqual(ghz4_dd, expected) @@ -430,11 +433,12 @@ def test_insert_dd_with_pulse_gate_calibrations_with_parmas(self): # Change duration to 100 from the 50 in self.durations to make sure # gate duration is used correctly. amp = Parameter("amp") - with pulse.builder.build() as sched: - pulse.builder.play( - pulse.Gaussian(100, amp=amp, sigma=10.0), - pulse.DriveChannel(0), - ) + with self.assertWarns(DeprecationWarning): + with pulse.builder.build() as sched: + pulse.builder.play( + pulse.Gaussian(100, amp=amp, sigma=10.0), + pulse.DriveChannel(0), + ) class Echo(Gate): """Dummy Gate subclass for testing @@ -457,7 +461,8 @@ def __array__(self, dtype=None, copy=None): echo = Echo("echo", 1, [amp, 10.0]) circ_in = self.ghz4.measure_all(inplace=False) - circ_in.add_calibration(echo, (0,), sched) + with self.assertWarns(DeprecationWarning): + circ_in.add_calibration(echo, (0,), sched) dd_sequence = [echo, echo] pm = PassManager( @@ -484,7 +489,8 @@ def __array__(self, dtype=None, copy=None): expected = expected.compose(Delay(300), [1]) expected.measure_all() - expected.add_calibration(echo, (0,), sched) + with self.assertWarns(DeprecationWarning): + expected.add_calibration(echo, (0,), sched) self.assertEqual(ghz4_dd, expected) @@ -857,10 +863,14 @@ def test_dd_with_calibrations_with_parameters(self, param_value): rx_duration = int(param_value * 1000) - with pulse.build() as rx: - pulse.play(pulse.Gaussian(rx_duration, 0.1, rx_duration // 4), pulse.DriveChannel(1)) + with self.assertWarns(DeprecationWarning): + with pulse.build() as rx: + pulse.play( + pulse.Gaussian(rx_duration, 0.1, rx_duration // 4), pulse.DriveChannel(1) + ) - circ.add_calibration("rx", (1,), rx, params=[param_value]) + with self.assertWarns(DeprecationWarning): + circ.add_calibration("rx", (1,), rx, params=[param_value]) durations = InstructionDurations([("x", None, 100), ("cx", None, 300)]) diff --git a/test/python/transpiler/test_gate_direction.py b/test/python/transpiler/test_gate_direction.py index 569a210f8a9d..c22ad4d58b41 100644 --- a/test/python/transpiler/test_gate_direction.py +++ b/test/python/transpiler/test_gate_direction.py @@ -496,7 +496,8 @@ def test_target_cannot_flip_message_calibrated(self): gate = Gate("my_2q_gate", 2, []) circuit = QuantumCircuit(2) circuit.append(gate, (1, 0)) - circuit.add_calibration(gate, (0, 1), pulse.ScheduleBlock()) + with self.assertWarns(DeprecationWarning): + circuit.add_calibration(gate, (0, 1), pulse.ScheduleBlock()) pass_ = GateDirection(None, target) with self.assertRaisesRegex(TranspilerError, "'my_2q_gate' would be supported.*"): @@ -524,7 +525,8 @@ def test_allows_calibrated_gates_coupling_map(self): gate = Gate("my_2q_gate", 2, []) circuit = QuantumCircuit(2) circuit.append(gate, (0, 1)) - circuit.add_calibration(gate, (0, 1), pulse.ScheduleBlock()) + with self.assertWarns(DeprecationWarning): + circuit.add_calibration(gate, (0, 1), pulse.ScheduleBlock()) pass_ = GateDirection(cm) self.assertEqual(pass_(circuit), circuit) @@ -538,7 +540,8 @@ def test_allows_calibrated_gates_target(self): gate = Gate("my_2q_gate", 2, []) circuit = QuantumCircuit(2) circuit.append(gate, (0, 1)) - circuit.add_calibration(gate, (0, 1), pulse.ScheduleBlock()) + with self.assertWarns(DeprecationWarning): + circuit.add_calibration(gate, (0, 1), pulse.ScheduleBlock()) pass_ = GateDirection(None, target) self.assertEqual(pass_(circuit), circuit) diff --git a/test/python/transpiler/test_instruction_alignments.py b/test/python/transpiler/test_instruction_alignments.py index 1431449779b3..74d5cc5e825e 100644 --- a/test/python/transpiler/test_instruction_alignments.py +++ b/test/python/transpiler/test_instruction_alignments.py @@ -17,8 +17,10 @@ from qiskit.transpiler.exceptions import TranspilerError from qiskit.transpiler.passes import ValidatePulseGates from test import QiskitTestCase # pylint: disable=wrong-import-order +from qiskit.utils.deprecate_pulse import decorate_test_methods, ignore_pulse_deprecation_warnings +@decorate_test_methods(ignore_pulse_deprecation_warnings) class TestPulseGateValidation(QiskitTestCase): """A test for pulse gate validation pass.""" @@ -27,16 +29,19 @@ def test_invalid_pulse_duration(self): # this is invalid duration pulse # this will cause backend error since this doesn't fit with waveform memory chunk. - custom_gate = pulse.Schedule(name="custom_x_gate") - custom_gate.insert( - 0, pulse.Play(pulse.Constant(100, 0.1), pulse.DriveChannel(0)), inplace=True - ) + with self.assertWarns(DeprecationWarning): + custom_gate = pulse.Schedule(name="custom_x_gate") + custom_gate.insert( + 0, pulse.Play(pulse.Constant(100, 0.1), pulse.DriveChannel(0)), inplace=True + ) circuit = QuantumCircuit(1) circuit.x(0) - circuit.add_calibration("x", qubits=(0,), schedule=custom_gate) + with self.assertWarns(DeprecationWarning): + circuit.add_calibration("x", qubits=(0,), schedule=custom_gate) - pm = PassManager(ValidatePulseGates(granularity=16, min_length=64)) + with self.assertWarns(DeprecationWarning): + pm = PassManager(ValidatePulseGates(granularity=16, min_length=64)) with self.assertRaises(TranspilerError): pm.run(circuit) @@ -52,9 +57,11 @@ def test_short_pulse_duration(self): circuit = QuantumCircuit(1) circuit.x(0) - circuit.add_calibration("x", qubits=(0,), schedule=custom_gate) + with self.assertWarns(DeprecationWarning): + circuit.add_calibration("x", qubits=(0,), schedule=custom_gate) - pm = PassManager(ValidatePulseGates(granularity=16, min_length=64)) + with self.assertWarns(DeprecationWarning): + pm = PassManager(ValidatePulseGates(granularity=16, min_length=64)) with self.assertRaises(TranspilerError): pm.run(circuit) @@ -74,9 +81,11 @@ def test_short_pulse_duration_multiple_pulse(self): circuit = QuantumCircuit(1) circuit.x(0) - circuit.add_calibration("x", qubits=(0,), schedule=custom_gate) + with self.assertWarns(DeprecationWarning): + circuit.add_calibration("x", qubits=(0,), schedule=custom_gate) - pm = PassManager(ValidatePulseGates(granularity=16, min_length=64)) + with self.assertWarns(DeprecationWarning): + pm = PassManager(ValidatePulseGates(granularity=16, min_length=64)) with self.assertRaises(TranspilerError): pm.run(circuit) @@ -91,10 +100,12 @@ def test_valid_pulse_duration(self): circuit = QuantumCircuit(1) circuit.x(0) - circuit.add_calibration("x", qubits=(0,), schedule=custom_gate) + with self.assertWarns(DeprecationWarning): + circuit.add_calibration("x", qubits=(0,), schedule=custom_gate) # just not raise an error - pm = PassManager(ValidatePulseGates(granularity=16, min_length=64)) + with self.assertWarns(DeprecationWarning): + pm = PassManager(ValidatePulseGates(granularity=16, min_length=64)) pm.run(circuit) def test_no_calibration(self): @@ -104,5 +115,6 @@ def test_no_calibration(self): circuit.x(0) # just not raise an error - pm = PassManager(ValidatePulseGates(granularity=16, min_length=64)) + with self.assertWarns(DeprecationWarning): + pm = PassManager(ValidatePulseGates(granularity=16, min_length=64)) pm.run(circuit) diff --git a/test/python/transpiler/test_instruction_durations.py b/test/python/transpiler/test_instruction_durations.py index c59d0ff2a6cc..d9a3ef2b1773 100644 --- a/test/python/transpiler/test_instruction_durations.py +++ b/test/python/transpiler/test_instruction_durations.py @@ -96,7 +96,8 @@ def test_fail_if_get_unbounded_duration_with_unit_conversion_when_dt_is_not_prov def test_from_backend_with_backendv2(self): """Test if `from_backend()` method allows using BackendV2""" - backend = GenericBackendV2(num_qubits=4, calibrate_instructions=True, seed=42) + with self.assertWarns(DeprecationWarning): + backend = GenericBackendV2(num_qubits=4, calibrate_instructions=True, seed=42) inst_durations = InstructionDurations.from_backend(backend) self.assertEqual(inst_durations, backend.target.durations()) self.assertIsInstance(inst_durations, InstructionDurations) diff --git a/test/python/transpiler/test_passmanager.py b/test/python/transpiler/test_passmanager.py index 60375a820655..6764745facd3 100644 --- a/test/python/transpiler/test_passmanager.py +++ b/test/python/transpiler/test_passmanager.py @@ -106,7 +106,8 @@ def callback(**kwargs): calls.append(out_dict) passmanager = PassManager() - passmanager.append(RXCalibrationBuilder()) + with self.assertWarns(DeprecationWarning): + passmanager.append(RXCalibrationBuilder()) passmanager.run(circuit, callback=callback) self.assertEqual(len(calls), 2) self.assertEqual(len(calls[0]), 5) diff --git a/test/python/transpiler/test_passmanager_config.py b/test/python/transpiler/test_passmanager_config.py index 569f67738a16..85cbb7909aef 100644 --- a/test/python/transpiler/test_passmanager_config.py +++ b/test/python/transpiler/test_passmanager_config.py @@ -45,7 +45,8 @@ def test_config_from_backend_v2(self): backend = GenericBackendV2(num_qubits=27, seed=42) config = PassManagerConfig.from_backend(backend) self.assertEqual(config.basis_gates, backend.operation_names) - self.assertEqual(config.inst_map, backend.instruction_schedule_map) + with self.assertWarns(DeprecationWarning): + self.assertEqual(config.inst_map, backend.instruction_schedule_map) self.assertEqual(config.coupling_map.get_edges(), backend.coupling_map.get_edges()) def test_invalid_backend(self): @@ -86,13 +87,14 @@ def test_from_backend_and_user(self): qr = QuantumRegister(4, "qr") initial_layout = [None, qr[0], qr[1], qr[2], None, qr[3]] - backend = GenericBackendV2( - num_qubits=20, - coupling_map=ALMADEN_CMAP, - basis_gates=["id", "u1", "u2", "u3", "cx"], - calibrate_instructions=None, - seed=42, - ) + with self.assertWarns(DeprecationWarning): + backend = GenericBackendV2( + num_qubits=20, + coupling_map=ALMADEN_CMAP, + basis_gates=["id", "u1", "u2", "u3", "cx"], + calibrate_instructions=None, + seed=42, + ) config = PassManagerConfig.from_backend( backend, basis_gates=["user_gate"], initial_layout=initial_layout ) diff --git a/test/python/transpiler/test_preset_passmanagers.py b/test/python/transpiler/test_preset_passmanagers.py index b762d84032bb..00fd8944061c 100644 --- a/test/python/transpiler/test_preset_passmanagers.py +++ b/test/python/transpiler/test_preset_passmanagers.py @@ -1316,15 +1316,16 @@ def test_default_optimization_level_target_first_pos_arg(self): def test_with_no_backend(self, optimization_level): """Test a passmanager is constructed with no backend and optimization level.""" target = GenericBackendV2(num_qubits=7, coupling_map=LAGOS_CMAP, seed=42) - pm = generate_preset_pass_manager( - optimization_level, - coupling_map=target.coupling_map, - basis_gates=target.operation_names, - inst_map=target.instruction_schedule_map, - instruction_durations=target.instruction_durations, - timing_constraints=target.target.timing_constraints(), - target=target.target, - ) + with self.assertWarns(DeprecationWarning): + pm = generate_preset_pass_manager( + optimization_level, + coupling_map=target.coupling_map, + basis_gates=target.operation_names, + inst_map=target.instruction_schedule_map, + instruction_durations=target.instruction_durations, + timing_constraints=target.target.timing_constraints(), + target=target.target, + ) self.assertIsInstance(pm, PassManager) @data(0, 1, 2, 3) diff --git a/test/python/transpiler/test_pulse_gate_pass.py b/test/python/transpiler/test_pulse_gate_pass.py index 1dd42d662860..844f262c3dff 100644 --- a/test/python/transpiler/test_pulse_gate_pass.py +++ b/test/python/transpiler/test_pulse_gate_pass.py @@ -19,14 +19,16 @@ from qiskit.providers.models.backendconfiguration import GateConfig from qiskit.quantum_info.random import random_unitary from test import QiskitTestCase # pylint: disable=wrong-import-order - +from qiskit.utils.deprecate_pulse import decorate_test_methods, ignore_pulse_deprecation_warnings from ..legacy_cmaps import BOGOTA_CMAP @ddt.ddt +@decorate_test_methods(ignore_pulse_deprecation_warnings) class TestPulseGate(QiskitTestCase): """Integration test of pulse gate pass with custom backend.""" + @ignore_pulse_deprecation_warnings def setUp(self): super().setUp() @@ -78,14 +80,16 @@ def test_transpile_with_bare_backend(self): transpiled_qc = transpile(qc, backend, initial_layout=[0, 1]) ref_calibration = {} - self.assertDictEqual(transpiled_qc.calibrations, ref_calibration) + with self.assertWarns(DeprecationWarning): + self.assertDictEqual(transpiled_qc.calibrations, ref_calibration) def test_transpile_with_backend_target(self): """Test transpile without custom calibrations from target.""" - target = GenericBackendV2( - num_qubits=5, coupling_map=BOGOTA_CMAP, calibrate_instructions=True, seed=42 - ).target + with self.assertWarns(DeprecationWarning): + target = GenericBackendV2( + num_qubits=5, coupling_map=BOGOTA_CMAP, calibrate_instructions=True, seed=42 + ).target qc = circuit.QuantumCircuit(2) qc.sx(0) @@ -97,15 +101,16 @@ def test_transpile_with_backend_target(self): transpiled_qc = transpile(qc, initial_layout=[0, 1], target=target) ref_calibration = {} - self.assertDictEqual(transpiled_qc.calibrations, ref_calibration) + with self.assertWarns(DeprecationWarning): + self.assertDictEqual(transpiled_qc.calibrations, ref_calibration) def test_transpile_with_custom_basis_gate(self): """Test transpile with custom calibrations.""" with self.assertWarns(DeprecationWarning): # TODO Move this test to backendV2 backend = Fake27QPulseV1() - backend.defaults().instruction_schedule_map.add("sx", (0,), self.custom_sx_q0) - backend.defaults().instruction_schedule_map.add("sx", (1,), self.custom_sx_q1) + backend.defaults().instruction_schedule_map.add("sx", (0,), self.custom_sx_q0) + backend.defaults().instruction_schedule_map.add("sx", (1,), self.custom_sx_q1) # Remove timing constraints to avoid triggering # scheduling passes. backend.configuration().timing_constraints = {} @@ -130,21 +135,22 @@ def test_transpile_with_custom_basis_gate(self): ((1,), ()): self.custom_sx_q1, } } - self.assertDictEqual(transpiled_qc.calibrations, ref_calibration) + with self.assertWarns(DeprecationWarning): + self.assertDictEqual(transpiled_qc.calibrations, ref_calibration) def test_transpile_with_custom_basis_gate_in_target(self): """Test transpile with custom calibrations.""" with self.assertWarns(DeprecationWarning): backend_pulse = Fake27QPulseV1() - target = GenericBackendV2( - num_qubits=5, - coupling_map=BOGOTA_CMAP, - calibrate_instructions=backend_pulse.defaults().instruction_schedule_map, - seed=42, - ).target + target = GenericBackendV2( + num_qubits=5, + coupling_map=BOGOTA_CMAP, + calibrate_instructions=backend_pulse.defaults().instruction_schedule_map, + seed=42, + ).target - target["sx"][(0,)].calibration = self.custom_sx_q0 - target["sx"][(1,)].calibration = self.custom_sx_q1 + target["sx"][(0,)].calibration = self.custom_sx_q0 + target["sx"][(1,)].calibration = self.custom_sx_q1 qc = circuit.QuantumCircuit(2) qc.sx(0) @@ -161,14 +167,15 @@ def test_transpile_with_custom_basis_gate_in_target(self): ((1,), ()): self.custom_sx_q1, } } - self.assertDictEqual(transpiled_qc.calibrations, ref_calibration) + with self.assertWarns(DeprecationWarning): + self.assertDictEqual(transpiled_qc.calibrations, ref_calibration) def test_transpile_with_instmap(self): """Test providing instruction schedule map.""" with self.assertWarns(DeprecationWarning): # TODO Move this test to backendV2 backend = Fake27QPulseV1() - instmap = backend.defaults().instruction_schedule_map + instmap = backend.defaults().instruction_schedule_map instmap.add("sx", (0,), self.custom_sx_q0) instmap.add("sx", (1,), self.custom_sx_q1) @@ -200,19 +207,20 @@ def test_transpile_with_instmap(self): ((1,), ()): self.custom_sx_q1, } } - self.assertDictEqual(transpiled_qc.calibrations, ref_calibration) + with self.assertWarns(DeprecationWarning): + self.assertDictEqual(transpiled_qc.calibrations, ref_calibration) def test_transpile_with_custom_gate(self): """Test providing non-basis gate.""" with self.assertWarns(DeprecationWarning): # TODO Move this test to backendV2 backend = Fake27QPulseV1() - backend.defaults().instruction_schedule_map.add( - "my_gate", (0,), self.my_gate_q0, arguments=["P0"] - ) - backend.defaults().instruction_schedule_map.add( - "my_gate", (1,), self.my_gate_q1, arguments=["P0"] - ) + backend.defaults().instruction_schedule_map.add( + "my_gate", (0,), self.my_gate_q0, arguments=["P0"] + ) + backend.defaults().instruction_schedule_map.add( + "my_gate", (1,), self.my_gate_q1, arguments=["P0"] + ) # Add gate to backend configuration backend.configuration().basis_gates.append("my_gate") with self.assertWarns(DeprecationWarning): @@ -244,16 +252,17 @@ def test_transpile_with_custom_gate(self): ((1,), (2.0,)): my_gate_q1_2_0, } } - self.assertDictEqual(transpiled_qc.calibrations, ref_calibration) + with self.assertWarns(DeprecationWarning): + self.assertDictEqual(transpiled_qc.calibrations, ref_calibration) def test_transpile_with_parameterized_custom_gate(self): """Test providing non-basis gate, which is kept parameterized throughout transpile.""" with self.assertWarns(DeprecationWarning): # TODO convert this to BackendV2/Target backend = Fake27QPulseV1() - backend.defaults().instruction_schedule_map.add( - "my_gate", (0,), self.my_gate_q0, arguments=["P0"] - ) + backend.defaults().instruction_schedule_map.add( + "my_gate", (0,), self.my_gate_q0, arguments=["P0"] + ) # Add gate to backend configuration backend.configuration().basis_gates.append("my_gate") with self.assertWarns(DeprecationWarning): @@ -283,16 +292,17 @@ def test_transpile_with_parameterized_custom_gate(self): ((0,), (param,)): my_gate_q0_p, } } - self.assertDictEqual(transpiled_qc.calibrations, ref_calibration) + with self.assertWarns(DeprecationWarning): + self.assertDictEqual(transpiled_qc.calibrations, ref_calibration) def test_transpile_with_multiple_circuits(self): """Test transpile with multiple circuits with custom gate.""" with self.assertWarns(DeprecationWarning): # TODO move this test to backendV2 backend = Fake27QPulseV1() - backend.defaults().instruction_schedule_map.add( - "my_gate", (0,), self.my_gate_q0, arguments=["P0"] - ) + backend.defaults().instruction_schedule_map.add( + "my_gate", (0,), self.my_gate_q0, arguments=["P0"] + ) # Add gate to backend configuration backend.configuration().basis_gates.append("my_gate") with self.assertWarns(DeprecationWarning): @@ -323,16 +333,17 @@ def test_transpile_with_multiple_circuits(self): {self.sched_param: param}, inplace=False ) ref_calibration = {"my_gate": {((0,), (param,)): my_gate_q0_x}} - self.assertDictEqual(transpiled_qc.calibrations, ref_calibration) + with self.assertWarns(DeprecationWarning): + self.assertDictEqual(transpiled_qc.calibrations, ref_calibration) def test_multiple_instructions_with_different_parameters(self): """Test adding many instruction with different parameter binding.""" with self.assertWarns(DeprecationWarning): # TODO Move this test to backendV2 backend = Fake27QPulseV1() - backend.defaults().instruction_schedule_map.add( - "my_gate", (0,), self.my_gate_q0, arguments=["P0"] - ) + backend.defaults().instruction_schedule_map.add( + "my_gate", (0,), self.my_gate_q0, arguments=["P0"] + ) # Add gate to backend configuration backend.configuration().basis_gates.append("my_gate") with self.assertWarns(DeprecationWarning): @@ -367,14 +378,15 @@ def test_multiple_instructions_with_different_parameters(self): ((0,), (3.0,)): my_gate_q0_3_0, } } - self.assertDictEqual(transpiled_qc.calibrations, ref_calibration) + with self.assertWarns(DeprecationWarning): + self.assertDictEqual(transpiled_qc.calibrations, ref_calibration) def test_transpile_with_different_qubit(self): """Test transpile with qubit without custom gate.""" with self.assertWarns(DeprecationWarning): # TODO Move this test to backendV2 backend = Fake27QPulseV1() - backend.defaults().instruction_schedule_map.add("sx", (0,), self.custom_sx_q0) + backend.defaults().instruction_schedule_map.add("sx", (0,), self.custom_sx_q0) # Remove timing constraints to avoid triggering # scheduling passes. backend.configuration().timing_constraints = {} @@ -390,7 +402,8 @@ def test_transpile_with_different_qubit(self): ): transpiled_qc = transpile(qc, backend, initial_layout=[3]) - self.assertDictEqual(transpiled_qc.calibrations, {}) + with self.assertWarns(DeprecationWarning): + self.assertDictEqual(transpiled_qc.calibrations, {}) @ddt.data(0, 1, 2, 3) def test_transpile_with_both_instmap_and_empty_target(self, opt_level): @@ -401,7 +414,7 @@ def test_transpile_with_both_instmap_and_empty_target(self, opt_level): """ with self.assertWarns(DeprecationWarning): backend = Fake27QPulseV1() - instmap = backend.defaults().instruction_schedule_map + instmap = backend.defaults().instruction_schedule_map instmap.add("sx", (0,), self.custom_sx_q0) instmap.add("sx", (1,), self.custom_sx_q1) instmap.add("cx", (0, 1), self.custom_cx_q01) @@ -409,25 +422,26 @@ def test_transpile_with_both_instmap_and_empty_target(self, opt_level): with self.assertWarns(DeprecationWarning): backend_pulse = Fake27QPulseV1() # This doesn't have custom schedule definition - target = GenericBackendV2( - num_qubits=5, - coupling_map=BOGOTA_CMAP, - calibrate_instructions=backend_pulse.defaults().instruction_schedule_map, - seed=42, - ).target + target = GenericBackendV2( + num_qubits=5, + coupling_map=BOGOTA_CMAP, + calibrate_instructions=backend_pulse.defaults().instruction_schedule_map, + seed=42, + ).target qc = circuit.QuantumCircuit(2) qc.append(random_unitary(4, seed=123), [0, 1]) qc.measure_all() - transpiled_qc = transpile( - qc, - optimization_level=opt_level, - basis_gates=["sx", "rz", "x", "cx"], - inst_map=instmap, - target=target, - initial_layout=[0, 1], - ) + with self.assertWarns(DeprecationWarning): + transpiled_qc = transpile( + qc, + optimization_level=opt_level, + basis_gates=["sx", "rz", "x", "cx"], + inst_map=instmap, + target=target, + initial_layout=[0, 1], + ) ref_calibration = { "sx": { ((0,), ()): self.custom_sx_q0, @@ -437,7 +451,8 @@ def test_transpile_with_both_instmap_and_empty_target(self, opt_level): ((0, 1), ()): self.custom_cx_q01, }, } - self.assertDictEqual(transpiled_qc.calibrations, ref_calibration) + with self.assertWarns(DeprecationWarning): + self.assertDictEqual(transpiled_qc.calibrations, ref_calibration) @ddt.data(0, 1, 2, 3) def test_transpile_with_instmap_with_v2backend(self, opt_level): @@ -448,7 +463,7 @@ def test_transpile_with_instmap_with_v2backend(self, opt_level): with self.assertWarns(DeprecationWarning): backend = Fake27QPulseV1() - instmap = backend.defaults().instruction_schedule_map + instmap = backend.defaults().instruction_schedule_map instmap.add("sx", (0,), self.custom_sx_q0) instmap.add("sx", (1,), self.custom_sx_q1) instmap.add("cx", (0, 1), self.custom_cx_q01) @@ -460,19 +475,20 @@ def test_transpile_with_instmap_with_v2backend(self, opt_level): with self.assertWarns(DeprecationWarning): backend_pulse = Fake27QPulseV1() - backend = GenericBackendV2( - num_qubits=5, - calibrate_instructions=backend_pulse.defaults().instruction_schedule_map, - seed=42, - ) - - transpiled_qc = transpile( - qc, - backend, - optimization_level=opt_level, - inst_map=instmap, - initial_layout=[0, 1], - ) + backend = GenericBackendV2( + num_qubits=5, + calibrate_instructions=backend_pulse.defaults().instruction_schedule_map, + seed=42, + ) + + with self.assertWarns(DeprecationWarning): + transpiled_qc = transpile( + qc, + backend, + optimization_level=opt_level, + inst_map=instmap, + initial_layout=[0, 1], + ) ref_calibration = { "sx": { ((0,), ()): self.custom_sx_q0, @@ -482,7 +498,8 @@ def test_transpile_with_instmap_with_v2backend(self, opt_level): ((0, 1), ()): self.custom_cx_q01, }, } - self.assertDictEqual(transpiled_qc.calibrations, ref_calibration) + with self.assertWarns(DeprecationWarning): + self.assertDictEqual(transpiled_qc.calibrations, ref_calibration) @ddt.data(0, 1, 2, 3) def test_transpile_with_instmap_with_v2backend_with_custom_gate(self, opt_level): @@ -498,7 +515,7 @@ def test_transpile_with_instmap_with_v2backend_with_custom_gate(self, opt_level) pulse.play(pulse.Constant(100, 0.4), pulse.DriveChannel(0)) with self.assertWarns(DeprecationWarning): backend = Fake27QPulseV1() - instmap = backend.defaults().instruction_schedule_map + instmap = backend.defaults().instruction_schedule_map instmap.add("rabi12", (0,), rabi12) gate = circuit.Gate("rabi12", 1, []) @@ -506,20 +523,22 @@ def test_transpile_with_instmap_with_v2backend_with_custom_gate(self, opt_level) qc.append(gate, [0]) qc.measure_all() - backend = GenericBackendV2(num_qubits=5, calibrate_instructions=True, seed=42) - transpiled_qc = transpile( - qc, - backend, - optimization_level=opt_level, - inst_map=instmap, - initial_layout=[0], - ) + with self.assertWarns(DeprecationWarning): + backend = GenericBackendV2(num_qubits=5, calibrate_instructions=True, seed=42) + transpiled_qc = transpile( + qc, + backend, + optimization_level=opt_level, + inst_map=instmap, + initial_layout=[0], + ) ref_calibration = { "rabi12": { ((0,), ()): rabi12, } } - self.assertDictEqual(transpiled_qc.calibrations, ref_calibration) + with self.assertWarns(DeprecationWarning): + self.assertDictEqual(transpiled_qc.calibrations, ref_calibration) def test_transpile_with_instmap_not_mutate_backend(self): """Do not override default backend target when transpile with inst map. @@ -529,28 +548,30 @@ def test_transpile_with_instmap_not_mutate_backend(self): This should not override the source object since the same backend may be used for future transpile without intention of instruction overriding. """ - backend = GenericBackendV2(num_qubits=5, calibrate_instructions=True, seed=42) - original_sx0 = backend.target["sx"][(0,)].calibration + with self.assertWarns(DeprecationWarning): + backend = GenericBackendV2(num_qubits=5, calibrate_instructions=True, seed=42) + original_sx0 = backend.target["sx"][(0,)].calibration with self.assertWarns(DeprecationWarning): backend_pulse = Fake27QPulseV1() - instmap = backend_pulse.defaults().instruction_schedule_map + instmap = backend_pulse.defaults().instruction_schedule_map instmap.add("sx", (0,), self.custom_sx_q0) qc = circuit.QuantumCircuit(1) qc.sx(0) qc.measure_all() - transpiled_qc = transpile( - qc, - backend, - inst_map=instmap, - initial_layout=[0], - ) - self.assertTrue(transpiled_qc.has_calibration_for(transpiled_qc.data[0])) - - self.assertEqual( - backend.target["sx"][(0,)].calibration, - original_sx0, - ) + with self.assertWarns(DeprecationWarning): + transpiled_qc = transpile( + qc, + backend, + inst_map=instmap, + initial_layout=[0], + ) + self.assertTrue(transpiled_qc.has_calibration_for(transpiled_qc.data[0])) + + self.assertEqual( + backend.target["sx"][(0,)].calibration, + original_sx0, + ) diff --git a/test/python/transpiler/test_sabre_swap.py b/test/python/transpiler/test_sabre_swap.py index 856b5ff09f5b..28c73b49b93c 100644 --- a/test/python/transpiler/test_sabre_swap.py +++ b/test/python/transpiler/test_sabre_swap.py @@ -13,7 +13,7 @@ """Test the Sabre Swap pass""" import unittest - +import warnings import itertools import ddt @@ -1327,13 +1327,17 @@ class TestSabreSwapRandomCircuitValidOutput(QiskitTestCase): @classmethod def setUpClass(cls): super().setUpClass() - cls.backend = GenericBackendV2( - num_qubits=27, - calibrate_instructions=True, - control_flow=True, - coupling_map=MUMBAI_CMAP, - seed=42, - ) + with warnings.catch_warnings(): + # Catch warnings since self.assertWarns cannot be used here. + # The `calibrate_instructions` argument is deprecated in Qiksit 1.3 + warnings.simplefilter("ignore", category=DeprecationWarning) + cls.backend = GenericBackendV2( + num_qubits=27, + calibrate_instructions=True, + control_flow=True, + coupling_map=MUMBAI_CMAP, + seed=42, + ) cls.coupling_edge_set = {tuple(x) for x in cls.backend.coupling_map} cls.basis_gates = set(cls.backend.operation_names) diff --git a/test/python/transpiler/test_scheduling_padding_pass.py b/test/python/transpiler/test_scheduling_padding_pass.py index f2f4f6a24bc6..a1ae04d5e68e 100644 --- a/test/python/transpiler/test_scheduling_padding_pass.py +++ b/test/python/transpiler/test_scheduling_padding_pass.py @@ -794,8 +794,9 @@ def test_scheduling_with_calibration(self): qc.x(1) qc.cx(0, 1) - xsched = Schedule(Play(Constant(300, 0.1), DriveChannel(0))) - qc.add_calibration("x", (0,), xsched) + with self.assertWarns(DeprecationWarning): + xsched = Schedule(Play(Constant(300, 0.1), DriveChannel(0))) + qc.add_calibration("x", (0,), xsched) durations = InstructionDurations([("x", None, 160), ("cx", None, 600)]) pm = PassManager([ASAPScheduleAnalysis(durations), PadDelay()]) @@ -808,7 +809,8 @@ def test_scheduling_with_calibration(self): expected.x(1) expected.delay(160, 0) expected.cx(0, 1) - expected.add_calibration("x", (0,), xsched) + with self.assertWarns(DeprecationWarning): + expected.add_calibration("x", (0,), xsched) self.assertEqual(expected, scheduled) diff --git a/test/python/transpiler/test_stochastic_swap.py b/test/python/transpiler/test_stochastic_swap.py index ee5d8a1dad31..7e4dfe63de3c 100644 --- a/test/python/transpiler/test_stochastic_swap.py +++ b/test/python/transpiler/test_stochastic_swap.py @@ -13,6 +13,7 @@ """Test the Stochastic Swap pass""" import unittest +import warnings import numpy.random @@ -1527,9 +1528,13 @@ class TestStochasticSwapRandomCircuitValidOutput(QiskitTestCase): @classmethod def setUpClass(cls): super().setUpClass() - cls.backend = GenericBackendV2( - num_qubits=27, calibrate_instructions=True, control_flow=True, seed=42 - ) + with warnings.catch_warnings(): + # Catch warnings since self.assertWarns cannot be used here. + # The `calibrate_instructions` argument is deprecated in Qiksit 1.3 + warnings.simplefilter("ignore", category=DeprecationWarning) + cls.backend = GenericBackendV2( + num_qubits=27, calibrate_instructions=True, control_flow=True, seed=42 + ) cls.coupling_edge_set = {tuple(x) for x in cls.backend.coupling_map} cls.basis_gates = set(cls.backend.operation_names) diff --git a/test/python/transpiler/test_target.py b/test/python/transpiler/test_target.py index 928cd09c8dd1..eeb700995ff8 100644 --- a/test/python/transpiler/test_target.py +++ b/test/python/transpiler/test_target.py @@ -1173,22 +1173,24 @@ def setUp(self): self.pulse_target = Target( dt=3e-7, granularity=2, min_length=4, pulse_alignment=8, acquire_alignment=8 ) - with pulse.build(name="sx_q0") as self.custom_sx_q0: - pulse.play(pulse.Constant(100, 0.1), pulse.DriveChannel(0)) - with pulse.build(name="sx_q1") as self.custom_sx_q1: - pulse.play(pulse.Constant(100, 0.2), pulse.DriveChannel(1)) - sx_props = { - (0,): InstructionProperties( - duration=35.5e-9, error=0.000413, calibration=self.custom_sx_q0 - ), - (1,): InstructionProperties( - duration=35.5e-9, error=0.000502, calibration=self.custom_sx_q1 - ), - } + with self.assertWarns(DeprecationWarning): + with pulse.build(name="sx_q0") as self.custom_sx_q0: + pulse.play(pulse.Constant(100, 0.1), pulse.DriveChannel(0)) + with pulse.build(name="sx_q1") as self.custom_sx_q1: + pulse.play(pulse.Constant(100, 0.2), pulse.DriveChannel(1)) + sx_props = { + (0,): InstructionProperties( + duration=35.5e-9, error=0.000413, calibration=self.custom_sx_q0 + ), + (1,): InstructionProperties( + duration=35.5e-9, error=0.000502, calibration=self.custom_sx_q1 + ), + } self.pulse_target.add_instruction(SXGate(), sx_props) def test_instruction_schedule_map(self): - inst_map = self.pulse_target.instruction_schedule_map() + with self.assertWarns(DeprecationWarning): + inst_map = self.pulse_target.instruction_schedule_map() self.assertIn("sx", inst_map.instructions) self.assertEqual(inst_map.qubits_with_instruction("sx"), [0, 1]) self.assertTrue("sx" in inst_map.qubit_instructions(0)) @@ -1209,8 +1211,9 @@ def test_instruction_schedule_map_ideal_sim_backend(self): Measure(), ]: ideal_sim_target.add_instruction(inst, {None: None}) - inst_map = ideal_sim_target.instruction_schedule_map() - self.assertEqual(InstructionScheduleMap(), inst_map) + with self.assertWarns(DeprecationWarning): + inst_map = ideal_sim_target.instruction_schedule_map() + self.assertEqual(InstructionScheduleMap(), inst_map) def test_str(self): expected = """Target @@ -1230,36 +1233,43 @@ def test_str(self): def test_update_from_instruction_schedule_map_add_instruction(self): target = Target() - inst_map = InstructionScheduleMap() + with self.assertWarns(DeprecationWarning): + inst_map = InstructionScheduleMap() inst_map.add("sx", 0, self.custom_sx_q0) inst_map.add("sx", 1, self.custom_sx_q1) - target.update_from_instruction_schedule_map(inst_map, {"sx": SXGate()}) - self.assertEqual(inst_map, target.instruction_schedule_map()) + with self.assertWarns(DeprecationWarning): + target.update_from_instruction_schedule_map(inst_map, {"sx": SXGate()}) + self.assertEqual(inst_map, target.instruction_schedule_map()) def test_update_from_instruction_schedule_map_with_schedule_parameter(self): self.pulse_target.dt = None - inst_map = InstructionScheduleMap() + with self.assertWarns(DeprecationWarning): + inst_map = InstructionScheduleMap() duration = Parameter("duration") - with pulse.build(name="sx_q0") as custom_sx: - pulse.play(pulse.Constant(duration, 0.2), pulse.DriveChannel(0)) + with self.assertWarns(DeprecationWarning): + with pulse.build(name="sx_q0") as custom_sx: + pulse.play(pulse.Constant(duration, 0.2), pulse.DriveChannel(0)) inst_map.add("sx", 0, custom_sx, ["duration"]) target = Target(dt=3e-7) - target.update_from_instruction_schedule_map(inst_map, {"sx": SXGate()}) - self.assertEqual(inst_map, target.instruction_schedule_map()) + with self.assertWarns(DeprecationWarning): + target.update_from_instruction_schedule_map(inst_map, {"sx": SXGate()}) + self.assertEqual(inst_map, target.instruction_schedule_map()) def test_update_from_instruction_schedule_map_update_schedule(self): self.pulse_target.dt = None - inst_map = InstructionScheduleMap() - with pulse.build(name="sx_q1") as custom_sx: - pulse.play(pulse.Constant(1000, 0.2), pulse.DriveChannel(1)) + with self.assertWarns(DeprecationWarning): + inst_map = InstructionScheduleMap() + with pulse.build(name="sx_q1") as custom_sx: + pulse.play(pulse.Constant(1000, 0.2), pulse.DriveChannel(1)) inst_map.add("sx", 0, self.custom_sx_q0) inst_map.add("sx", 1, custom_sx) - self.pulse_target.update_from_instruction_schedule_map(inst_map, {"sx": SXGate()}) - self.assertEqual(inst_map, self.pulse_target.instruction_schedule_map()) + with self.assertWarns(DeprecationWarning): + self.pulse_target.update_from_instruction_schedule_map(inst_map, {"sx": SXGate()}) + self.assertEqual(inst_map, self.pulse_target.instruction_schedule_map()) # Calibration doesn't change for q0 self.assertEqual(self.pulse_target["sx"][(0,)].duration, 35.5e-9) self.assertEqual(self.pulse_target["sx"][(0,)].error, 0.000413) @@ -1269,31 +1279,37 @@ def test_update_from_instruction_schedule_map_update_schedule(self): def test_update_from_instruction_schedule_map_new_instruction_no_name_map(self): target = Target() - inst_map = InstructionScheduleMap() + with self.assertWarns(DeprecationWarning): + inst_map = InstructionScheduleMap() inst_map.add("sx", 0, self.custom_sx_q0) inst_map.add("sx", 1, self.custom_sx_q1) - target.update_from_instruction_schedule_map(inst_map) - self.assertEqual(target["sx"][(0,)].calibration, self.custom_sx_q0) - self.assertEqual(target["sx"][(1,)].calibration, self.custom_sx_q1) + with self.assertWarns(DeprecationWarning): + target.update_from_instruction_schedule_map(inst_map) + self.assertEqual(target["sx"][(0,)].calibration, self.custom_sx_q0) + self.assertEqual(target["sx"][(1,)].calibration, self.custom_sx_q1) def test_update_from_instruction_schedule_map_new_qarg_raises(self): - inst_map = InstructionScheduleMap() + with self.assertWarns(DeprecationWarning): + inst_map = InstructionScheduleMap() inst_map.add("sx", 0, self.custom_sx_q0) inst_map.add("sx", 1, self.custom_sx_q1) inst_map.add("sx", 2, self.custom_sx_q1) - self.pulse_target.update_from_instruction_schedule_map(inst_map) + with self.assertWarns(DeprecationWarning): + self.pulse_target.update_from_instruction_schedule_map(inst_map) self.assertFalse(self.pulse_target.instruction_supported("sx", (2,))) def test_update_from_instruction_schedule_map_with_dt_set(self): - inst_map = InstructionScheduleMap() - with pulse.build(name="sx_q1") as custom_sx: - pulse.play(pulse.Constant(1000, 0.2), pulse.DriveChannel(1)) + with self.assertWarns(DeprecationWarning): + inst_map = InstructionScheduleMap() + with pulse.build(name="sx_q1") as custom_sx: + pulse.play(pulse.Constant(1000, 0.2), pulse.DriveChannel(1)) inst_map.add("sx", 0, self.custom_sx_q0) inst_map.add("sx", 1, custom_sx) self.pulse_target.dt = 1.0 - self.pulse_target.update_from_instruction_schedule_map(inst_map, {"sx": SXGate()}) - self.assertEqual(inst_map, self.pulse_target.instruction_schedule_map()) + with self.assertWarns(DeprecationWarning): + self.pulse_target.update_from_instruction_schedule_map(inst_map, {"sx": SXGate()}) + self.assertEqual(inst_map, self.pulse_target.instruction_schedule_map()) self.assertEqual(self.pulse_target["sx"][(1,)].duration, 1000.0) self.assertIsNone(self.pulse_target["sx"][(1,)].error) # This is an edge case. @@ -1303,18 +1319,20 @@ def test_update_from_instruction_schedule_map_with_dt_set(self): self.assertEqual(self.pulse_target["sx"][(0,)].error, 0.000413) def test_update_from_instruction_schedule_map_with_error_dict(self): - inst_map = InstructionScheduleMap() - with pulse.build(name="sx_q1") as custom_sx: - pulse.play(pulse.Constant(1000, 0.2), pulse.DriveChannel(1)) + with self.assertWarns(DeprecationWarning): + inst_map = InstructionScheduleMap() + with pulse.build(name="sx_q1") as custom_sx: + pulse.play(pulse.Constant(1000, 0.2), pulse.DriveChannel(1)) inst_map.add("sx", 0, self.custom_sx_q0) inst_map.add("sx", 1, custom_sx) self.pulse_target.dt = 1.0 error_dict = {"sx": {(1,): 1.0}} - self.pulse_target.update_from_instruction_schedule_map( - inst_map, {"sx": SXGate()}, error_dict=error_dict - ) + with self.assertWarns(DeprecationWarning): + self.pulse_target.update_from_instruction_schedule_map( + inst_map, {"sx": SXGate()}, error_dict=error_dict + ) self.assertEqual(self.pulse_target["sx"][(1,)].error, 1.0) self.assertEqual(self.pulse_target["sx"][(0,)].error, 0.000413) @@ -1330,33 +1348,39 @@ def test_timing_constraints(self): ) def test_default_instmap_has_no_custom_gate(self): - backend = GenericBackendV2(num_qubits=27, calibrate_instructions=True) + with self.assertWarns(DeprecationWarning): + backend = GenericBackendV2(num_qubits=27, calibrate_instructions=True) target = backend.target # This copies .calibration of InstructionProperties of each instruction # This must not convert PulseQobj to Schedule during this. # See qiskit-terra/#9595 - inst_map = target.instruction_schedule_map() + with self.assertWarns(DeprecationWarning): + inst_map = target.instruction_schedule_map() self.assertFalse(inst_map.has_custom_gate()) # Get pulse schedule. This generates Schedule provided by backend. - sched = inst_map.get("sx", (0,)) + with self.assertWarns(DeprecationWarning): + sched = inst_map.get("sx", (0,)) self.assertEqual(sched.metadata["publisher"], CalibrationPublisher.BACKEND_PROVIDER) self.assertFalse(inst_map.has_custom_gate()) # Update target with custom instruction. This is user provided schedule. - new_prop = InstructionProperties( - duration=self.custom_sx_q0.duration, - error=None, - calibration=self.custom_sx_q0, - ) + with self.assertWarns(DeprecationWarning): + new_prop = InstructionProperties( + duration=self.custom_sx_q0.duration, + error=None, + calibration=self.custom_sx_q0, + ) target.update_instruction_properties(instruction="sx", qargs=(0,), properties=new_prop) - inst_map = target.instruction_schedule_map() + with self.assertWarns(DeprecationWarning): + inst_map = target.instruction_schedule_map() self.assertTrue(inst_map.has_custom_gate()) empty = InstructionProperties() target.update_instruction_properties(instruction="sx", qargs=(0,), properties=empty) - inst_map = target.instruction_schedule_map() + with self.assertWarns(DeprecationWarning): + inst_map = target.instruction_schedule_map() self.assertFalse(inst_map.has_custom_gate()) def test_get_empty_target_calibration(self): @@ -1364,7 +1388,8 @@ def test_get_empty_target_calibration(self): properties = {(0,): InstructionProperties(duration=100, error=0.1)} target.add_instruction(XGate(), properties) - self.assertIsNone(target["x"][(0,)].calibration) + with self.assertWarns(DeprecationWarning): + self.assertIsNone(target["x"][(0,)].calibration) def test_has_calibration(self): target = Target() @@ -1374,22 +1399,25 @@ def test_has_calibration(self): } target.add_instruction(XGate(), properties) - # Test false for properties with no calibration - self.assertFalse(target.has_calibration("x", (0,))) - # Test false for no properties - self.assertFalse(target.has_calibration("x", (1,))) + with self.assertWarns(DeprecationWarning): + # Test false for properties with no calibration + self.assertFalse(target.has_calibration("x", (0,))) + # Test false for no properties + self.assertFalse(target.has_calibration("x", (1,))) - properties = { - (0,): InstructionProperties( - duration=self.custom_sx_q0.duration, - error=None, - calibration=self.custom_sx_q0, - ) - } + with self.assertWarns(DeprecationWarning): + properties = { + (0,): InstructionProperties( + duration=self.custom_sx_q0.duration, + error=None, + calibration=self.custom_sx_q0, + ) + } target.add_instruction(SXGate(), properties) # Test true for properties with calibration - self.assertTrue(target.has_calibration("sx", (0,))) + with self.assertWarns(DeprecationWarning): + self.assertTrue(target.has_calibration("sx", (0,))) def test_loading_legacy_ugate_instmap(self): # This is typical IBM backend situation. @@ -1400,9 +1428,10 @@ def test_loading_legacy_ugate_instmap(self): # Target is implicitly updated with inst map when it is set in transpile. # If u gates are not excluded, they may appear in the transpiled circuit. # These gates are no longer supported by hardware. - entry = ScheduleDef() - entry.define(pulse.Schedule(name="fake_u3"), user_provided=False) # backend provided - instmap = InstructionScheduleMap() + with self.assertWarns(DeprecationWarning): + entry = ScheduleDef() + entry.define(pulse.Schedule(name="fake_u3"), user_provided=False) # backend provided + instmap = InstructionScheduleMap() instmap._add("u3", (0,), entry) # Today's standard IBM backend target with sx, rz basis @@ -1412,7 +1441,8 @@ def test_loading_legacy_ugate_instmap(self): target.add_instruction(Measure(), {(0,): InstructionProperties()}) names_before = set(target.operation_names) - target.update_from_instruction_schedule_map(instmap) + with self.assertWarns(DeprecationWarning): + target.update_from_instruction_schedule_map(instmap) names_after = set(target.operation_names) # Otherwise u3 and sx-rz basis conflict in 1q decomposition. @@ -1971,18 +2001,20 @@ def test_inst_map(self): fake_backend = Fake7QPulseV1() config = fake_backend.configuration() properties = fake_backend.properties() - defaults = fake_backend.defaults() + with self.assertWarns(DeprecationWarning): + defaults = fake_backend.defaults() constraints = TimingConstraints(**config.timing_constraints) - target = Target.from_configuration( - basis_gates=config.basis_gates, - num_qubits=config.num_qubits, - coupling_map=CouplingMap(config.coupling_map), - backend_properties=properties, - dt=config.dt, - inst_map=defaults.instruction_schedule_map, - timing_constraints=constraints, - ) - self.assertIsNotNone(target["sx"][(0,)].calibration) + with self.assertWarns(DeprecationWarning): + target = Target.from_configuration( + basis_gates=config.basis_gates, + num_qubits=config.num_qubits, + coupling_map=CouplingMap(config.coupling_map), + backend_properties=properties, + dt=config.dt, + inst_map=defaults.instruction_schedule_map, + timing_constraints=constraints, + ) + self.assertIsNotNone(target["sx"][(0,)].calibration) self.assertEqual(target.granularity, constraints.granularity) self.assertEqual(target.min_length, constraints.min_length) self.assertEqual(target.pulse_alignment, constraints.pulse_alignment) diff --git a/test/python/transpiler/test_unitary_synthesis.py b/test/python/transpiler/test_unitary_synthesis.py index 4abf6511d8d2..665f8b296bb5 100644 --- a/test/python/transpiler/test_unitary_synthesis.py +++ b/test/python/transpiler/test_unitary_synthesis.py @@ -675,14 +675,15 @@ def test_coupling_map_unequal_durations(self, opt): qr = QuantumRegister(2) circ = QuantumCircuit(qr) circ.append(random_unitary(4, seed=1), [1, 0]) - backend = GenericBackendV2( - num_qubits=5, - coupling_map=YORKTOWN_CMAP, - basis_gates=["id", "rz", "sx", "x", "cx", "reset"], - calibrate_instructions=True, - pulse_channels=True, - seed=42, - ) + with self.assertWarns(DeprecationWarning): + backend = GenericBackendV2( + num_qubits=5, + coupling_map=YORKTOWN_CMAP, + basis_gates=["id", "rz", "sx", "x", "cx", "reset"], + calibrate_instructions=True, + pulse_channels=True, + seed=42, + ) tqc = transpile( circ, backend=backend, diff --git a/test/python/transpiler/test_vf2_layout.py b/test/python/transpiler/test_vf2_layout.py index 4e4844f5f701..1f7bb1aacc98 100644 --- a/test/python/transpiler/test_vf2_layout.py +++ b/test/python/transpiler/test_vf2_layout.py @@ -53,8 +53,9 @@ def assertLayout(self, dag, coupling_map, property_set, strict_direction=False): def run(dag, wire_map): for gate in dag.two_qubit_ops(): - if dag.has_calibration_for(gate) or isinstance(gate.op, ControlFlowOp): - continue + with self.assertWarns(DeprecationWarning): + if dag.has_calibration_for(gate) or isinstance(gate.op, ControlFlowOp): + continue physical_q0 = wire_map[gate.qargs[0]] physical_q1 = wire_map[gate.qargs[1]] @@ -711,7 +712,8 @@ def test_reasonable_limits_for_simple_layouts_v1(self): def test_reasonable_limits_for_simple_layouts(self): """Test that the default trials is set to a reasonable number.""" - backend = GenericBackendV2(27, calibrate_instructions=True, seed=42) + with self.assertWarns(DeprecationWarning): + backend = GenericBackendV2(27, calibrate_instructions=True, seed=42) qc = QuantumCircuit(5) qc.cx(2, 3) qc.cx(0, 1) diff --git a/test/python/transpiler/test_vf2_post_layout.py b/test/python/transpiler/test_vf2_post_layout.py index 5acdd3ba6ebc..592987e62dbf 100644 --- a/test/python/transpiler/test_vf2_post_layout.py +++ b/test/python/transpiler/test_vf2_post_layout.py @@ -46,8 +46,9 @@ def assertLayout(self, dag, coupling_map, property_set): def run(dag, wire_map): for gate in dag.two_qubit_ops(): - if dag.has_calibration_for(gate) or isinstance(gate.op, ControlFlowOp): - continue + with self.assertWarns(DeprecationWarning): + if dag.has_calibration_for(gate) or isinstance(gate.op, ControlFlowOp): + continue physical_q0 = wire_map[gate.qargs[0]] physical_q1 = wire_map[gate.qargs[1]] self.assertTrue((physical_q0, physical_q1) in edges) @@ -71,8 +72,9 @@ def assertLayoutV2(self, dag, target, property_set): def run(dag, wire_map): for gate in dag.two_qubit_ops(): - if dag.has_calibration_for(gate) or isinstance(gate.op, ControlFlowOp): - continue + with self.assertWarns(DeprecationWarning): + if dag.has_calibration_for(gate) or isinstance(gate.op, ControlFlowOp): + continue physical_q0 = wire_map[gate.qargs[0]] physical_q1 = wire_map[gate.qargs[1]] qargs = (physical_q0, physical_q1) @@ -552,8 +554,9 @@ def assertLayout(self, dag, coupling_map, property_set): layout = property_set["post_layout"] for gate in dag.two_qubit_ops(): - if dag.has_calibration_for(gate): - continue + with self.assertWarns(DeprecationWarning): + if dag.has_calibration_for(gate): + continue physical_q0 = layout[gate.qargs[0]] physical_q1 = layout[gate.qargs[1]] self.assertTrue(coupling_map.graph.has_edge(physical_q0, physical_q1)) @@ -567,8 +570,9 @@ def assertLayoutV2(self, dag, target, property_set): layout = property_set["post_layout"] for gate in dag.two_qubit_ops(): - if dag.has_calibration_for(gate): - continue + with self.assertWarns(DeprecationWarning): + if dag.has_calibration_for(gate): + continue physical_q0 = layout[gate.qargs[0]] physical_q1 = layout[gate.qargs[1]] qargs = (physical_q0, physical_q1) diff --git a/test/python/utils/test_parallel.py b/test/python/utils/test_parallel.py index 13a4e9b11c2a..f6de443b7b03 100644 --- a/test/python/utils/test_parallel.py +++ b/test/python/utils/test_parallel.py @@ -13,6 +13,7 @@ """Tests for qiskit/tools/parallel""" import os import time +import warnings from unittest.mock import patch @@ -36,7 +37,10 @@ def _build_simple_circuit(_): def _build_simple_schedule(_): - return Schedule() + with warnings.catch_warnings(): + warnings.simplefilter("ignore", category=DeprecationWarning) + # `Schedule` is deprecated in Qiskit 1.3 + return Schedule() class TestGetPlatformParallelDefault(QiskitTestCase): diff --git a/test/python/visualization/pulse_v2/test_core.py b/test/python/visualization/pulse_v2/test_core.py index 5855bbafae4a..8c677e554dd9 100644 --- a/test/python/visualization/pulse_v2/test_core.py +++ b/test/python/visualization/pulse_v2/test_core.py @@ -19,11 +19,14 @@ from qiskit.visualization.exceptions import VisualizationError from qiskit.visualization.pulse_v2 import core, stylesheet, device_info, drawings, types, layouts from test import QiskitTestCase # pylint: disable=wrong-import-order +from qiskit.utils.deprecate_pulse import decorate_test_methods, ignore_pulse_deprecation_warnings +@decorate_test_methods(ignore_pulse_deprecation_warnings) class TestChart(QiskitTestCase): """Tests for chart.""" + @ignore_pulse_deprecation_warnings def setUp(self) -> None: super().setUp() @@ -228,9 +231,11 @@ def test_update(self): self.assertEqual(chart.scale, 2.0) +@decorate_test_methods(ignore_pulse_deprecation_warnings) class TestDrawCanvas(QiskitTestCase): """Tests for draw canvas.""" + @ignore_pulse_deprecation_warnings def setUp(self) -> None: super().setUp() self.style = stylesheet.QiskitPulseStyle() diff --git a/test/python/visualization/pulse_v2/test_drawings.py b/test/python/visualization/pulse_v2/test_drawings.py index 0e07decdd4b3..d0766fc4f9bb 100644 --- a/test/python/visualization/pulse_v2/test_drawings.py +++ b/test/python/visualization/pulse_v2/test_drawings.py @@ -15,11 +15,14 @@ from qiskit import pulse from qiskit.visualization.pulse_v2 import drawings, types from test import QiskitTestCase # pylint: disable=wrong-import-order +from qiskit.utils.deprecate_pulse import decorate_test_methods, ignore_pulse_deprecation_warnings +@decorate_test_methods(ignore_pulse_deprecation_warnings) class TestDrawingObjects(QiskitTestCase): """Tests for DrawingObjects.""" + @ignore_pulse_deprecation_warnings def setUp(self) -> None: """Setup.""" super().setUp() diff --git a/test/python/visualization/pulse_v2/test_events.py b/test/python/visualization/pulse_v2/test_events.py index fbef9d3de807..74fbf00f325c 100644 --- a/test/python/visualization/pulse_v2/test_events.py +++ b/test/python/visualization/pulse_v2/test_events.py @@ -15,8 +15,10 @@ from qiskit import pulse, circuit from qiskit.visualization.pulse_v2 import events from test import QiskitTestCase # pylint: disable=wrong-import-order +from qiskit.utils.deprecate_pulse import decorate_test_methods, ignore_pulse_deprecation_warnings +@decorate_test_methods(ignore_pulse_deprecation_warnings) class TestChannelEvents(QiskitTestCase): """Tests for ChannelEvents.""" diff --git a/test/python/visualization/pulse_v2/test_generators.py b/test/python/visualization/pulse_v2/test_generators.py index c5f5e8da98ac..749ec4ab3488 100644 --- a/test/python/visualization/pulse_v2/test_generators.py +++ b/test/python/visualization/pulse_v2/test_generators.py @@ -20,6 +20,7 @@ from qiskit.visualization.pulse_v2 import drawings, types, stylesheet, device_info from qiskit.visualization.pulse_v2.generators import barrier, chart, frame, snapshot, waveform from test import QiskitTestCase # pylint: disable=wrong-import-order +from qiskit.utils.deprecate_pulse import decorate_test_methods, ignore_pulse_deprecation_warnings def create_instruction(inst, phase, freq, t0, dt, is_opaque=False): @@ -28,9 +29,11 @@ def create_instruction(inst, phase, freq, t0, dt, is_opaque=False): return types.PulseInstruction(t0=t0, dt=dt, frame=frame_info, inst=inst, is_opaque=is_opaque) +@decorate_test_methods(ignore_pulse_deprecation_warnings) class TestWaveformGenerators(QiskitTestCase): """Tests for waveform generators.""" + @ignore_pulse_deprecation_warnings def setUp(self) -> None: super().setUp() style = stylesheet.QiskitPulseStyle() @@ -400,9 +403,11 @@ def test_gen_filled_waveform_stepwise_opaque(self): self.assertEqual(objs[1].text, "Gaussian(amp)") +@decorate_test_methods(ignore_pulse_deprecation_warnings) class TestChartGenerators(QiskitTestCase): """Tests for chart info generators.""" + @ignore_pulse_deprecation_warnings def setUp(self) -> None: super().setUp() style = stylesheet.QiskitPulseStyle() @@ -532,9 +537,11 @@ def test_gen_frequency_info(self): self.assertDictEqual(obj.styles, ref_style) +@decorate_test_methods(ignore_pulse_deprecation_warnings) class TestFrameGenerators(QiskitTestCase): """Tests for frame info generators.""" + @ignore_pulse_deprecation_warnings def setUp(self) -> None: super().setUp() style = stylesheet.QiskitPulseStyle() @@ -736,9 +743,11 @@ def gen_frame_symbol_with_parameters(self): self.assertDictEqual(obj.meta, ref_meta) +@decorate_test_methods(ignore_pulse_deprecation_warnings) class TestSnapshotGenerators(QiskitTestCase): """Tests for snapshot generators.""" + @ignore_pulse_deprecation_warnings def setUp(self) -> None: super().setUp() style = stylesheet.QiskitPulseStyle() @@ -830,9 +839,11 @@ def gen_snapshot_symbol(self): self.assertDictEqual(obj.styles, ref_style) +@decorate_test_methods(ignore_pulse_deprecation_warnings) class TestBarrierGenerators(QiskitTestCase): """Tests for barrier generators.""" + @ignore_pulse_deprecation_warnings def setUp(self) -> None: super().setUp() style = stylesheet.QiskitPulseStyle() diff --git a/test/python/visualization/pulse_v2/test_layouts.py b/test/python/visualization/pulse_v2/test_layouts.py index d6a868956fa3..3985f1dd9318 100644 --- a/test/python/visualization/pulse_v2/test_layouts.py +++ b/test/python/visualization/pulse_v2/test_layouts.py @@ -15,11 +15,14 @@ from qiskit import pulse from qiskit.visualization.pulse_v2 import layouts, device_info from test import QiskitTestCase # pylint: disable=wrong-import-order +from qiskit.utils.deprecate_pulse import decorate_test_methods, ignore_pulse_deprecation_warnings +@decorate_test_methods(ignore_pulse_deprecation_warnings) class TestChannelArrangement(QiskitTestCase): """Tests for channel mapping functions.""" + @ignore_pulse_deprecation_warnings def setUp(self) -> None: super().setUp() self.channels = [ @@ -180,6 +183,7 @@ def test_channel_qubit_index_sort(self): self.assertListEqual(list(out_layout), ref) +@decorate_test_methods(ignore_pulse_deprecation_warnings) class TestHorizontalAxis(QiskitTestCase): """Tests for horizontal axis mapping functions.""" @@ -226,9 +230,11 @@ def test_time_map_in_without_dt(self): self.assertEqual(haxis.label, "System cycle time (dt)") +@decorate_test_methods(ignore_pulse_deprecation_warnings) class TestFigureTitle(QiskitTestCase): """Tests for figure title generation.""" + @ignore_pulse_deprecation_warnings def setUp(self) -> None: super().setUp() self.device = device_info.OpenPulseBackendInfo(name="test_backend", dt=1e-9) diff --git a/test/python/visualization/test_gate_map.py b/test/python/visualization/test_gate_map.py index fcac1e71c400..d2d589574103 100644 --- a/test/python/visualization/test_gate_map.py +++ b/test/python/visualization/test_gate_map.py @@ -109,7 +109,6 @@ def test_plot_error_map_backend_v1(self): """Test plotting error map with fake backend v1.""" backend = GenericBackendV2( num_qubits=27, - pulse_channels=True, coupling_map=MUMBAI_CMAP, ) img_ref = path_to_diagram_reference("fake_27_q_error.png") @@ -128,7 +127,6 @@ def test_plot_error_map_backend_v2(self): coupling_map = MUMBAI_CMAP backend = GenericBackendV2( num_qubits=27, - pulse_channels=True, coupling_map=coupling_map, ) img_ref = path_to_diagram_reference("fake_27_q_v2_error.png") @@ -145,9 +143,7 @@ def test_plot_error_map_backend_v2(self): def test_plot_error_map_over_100_qubit(self): """Test plotting error map with large fake backend.""" coupling_map = KYOTO_CMAP - backend = GenericBackendV2( - num_qubits=127, coupling_map=coupling_map, pulse_channels=True, seed=42 - ) + backend = GenericBackendV2(num_qubits=127, coupling_map=coupling_map, seed=42) img_ref = path_to_diagram_reference("fake_127_q_error.png") fig = plot_error_map(backend) with BytesIO() as img_buffer: @@ -447,9 +443,7 @@ def test_plot_error_map_over_100_qubit_backend_v2(self): [126, 112], [126, 125], ] - backend = GenericBackendV2( - num_qubits=127, coupling_map=coupling_map, pulse_channels=True, seed=42 - ) + backend = GenericBackendV2(num_qubits=127, coupling_map=coupling_map, seed=42) img_ref = path_to_diagram_reference("fake_127_q_v2_error.png") fig = plot_error_map(backend) with BytesIO() as img_buffer: diff --git a/test/utils/base.py b/test/utils/base.py index f4aad29f8e9c..dded6bbda2b2 100644 --- a/test/utils/base.py +++ b/test/utils/base.py @@ -176,13 +176,6 @@ def setUpClass(cls): module="qiskit.providers.fake_provider.fake_backend", ) - # Safe to remove once Pulse is removed in Qiskit 2.0 - warnings.filterwarnings( - "ignore", - category=DeprecationWarning, - message=".*The entire Qiskit Pulse package is being deprecated.*", - ) - allow_DeprecationWarning_message = [ r"The property ``qiskit\.circuit\.bit\.Bit\.(register|index)`` is deprecated.*", ] diff --git a/test/visual/mpl/circuit/test_circuit_matplotlib_drawer.py b/test/visual/mpl/circuit/test_circuit_matplotlib_drawer.py index 9e3dd5cc48eb..4da725c4b5d6 100644 --- a/test/visual/mpl/circuit/test_circuit_matplotlib_drawer.py +++ b/test/visual/mpl/circuit/test_circuit_matplotlib_drawer.py @@ -124,12 +124,13 @@ def test_calibrations(self): from qiskit import pulse - with pulse.build(name="hadamard") as h_q0: - pulse.play( - pulse.library.Gaussian(duration=128, amp=0.1, sigma=16), pulse.DriveChannel(0) - ) + with self.assertWarns(DeprecationWarning): + with pulse.build(name="hadamard") as h_q0: + pulse.play( + pulse.library.Gaussian(duration=128, amp=0.1, sigma=16), pulse.DriveChannel(0) + ) - circuit.add_calibration("h", [0], h_q0) + circuit.add_calibration("h", [0], h_q0) fname = "calibrations.png" self.circuit_drawer(circuit, output="mpl", filename=fname) @@ -154,19 +155,20 @@ def test_calibrations_with_control_gates(self): from qiskit import pulse - with pulse.build(name="cnot") as cx_q01: - pulse.play( - pulse.library.Gaussian(duration=128, amp=0.1, sigma=16), pulse.DriveChannel(1) - ) + with self.assertWarns(DeprecationWarning): + with pulse.build(name="cnot") as cx_q01: + pulse.play( + pulse.library.Gaussian(duration=128, amp=0.1, sigma=16), pulse.DriveChannel(1) + ) - circuit.add_calibration("cx", [0, 1], cx_q01) + circuit.add_calibration("cx", [0, 1], cx_q01) - with pulse.build(name="ch") as ch_q01: - pulse.play( - pulse.library.Gaussian(duration=128, amp=0.1, sigma=16), pulse.DriveChannel(1) - ) + with pulse.build(name="ch") as ch_q01: + pulse.play( + pulse.library.Gaussian(duration=128, amp=0.1, sigma=16), pulse.DriveChannel(1) + ) - circuit.add_calibration("ch", [0, 1], ch_q01) + circuit.add_calibration("ch", [0, 1], ch_q01) fname = "calibrations_with_control_gates.png" self.circuit_drawer(circuit, output="mpl", filename=fname) @@ -191,19 +193,20 @@ def test_calibrations_with_swap_and_reset(self): from qiskit import pulse - with pulse.build(name="swap") as swap_q01: - pulse.play( - pulse.library.Gaussian(duration=128, amp=0.1, sigma=16), pulse.DriveChannel(1) - ) + with self.assertWarns(DeprecationWarning): + with pulse.build(name="swap") as swap_q01: + pulse.play( + pulse.library.Gaussian(duration=128, amp=0.1, sigma=16), pulse.DriveChannel(1) + ) - circuit.add_calibration("swap", [0, 1], swap_q01) + circuit.add_calibration("swap", [0, 1], swap_q01) - with pulse.build(name="reset") as reset_q0: - pulse.play( - pulse.library.Gaussian(duration=128, amp=0.1, sigma=16), pulse.DriveChannel(1) - ) + with pulse.build(name="reset") as reset_q0: + pulse.play( + pulse.library.Gaussian(duration=128, amp=0.1, sigma=16), pulse.DriveChannel(1) + ) - circuit.add_calibration("reset", [0], reset_q0) + circuit.add_calibration("reset", [0], reset_q0) fname = "calibrations_with_swap_and_reset.png" self.circuit_drawer(circuit, output="mpl", filename=fname) @@ -227,19 +230,20 @@ def test_calibrations_with_rzz_and_rxx(self): from qiskit import pulse - with pulse.build(name="rzz") as rzz_q01: - pulse.play( - pulse.library.Gaussian(duration=128, amp=0.1, sigma=16), pulse.DriveChannel(1) - ) + with self.assertWarns(DeprecationWarning): + with pulse.build(name="rzz") as rzz_q01: + pulse.play( + pulse.library.Gaussian(duration=128, amp=0.1, sigma=16), pulse.DriveChannel(1) + ) - circuit.add_calibration("rzz", [0, 1], rzz_q01) + circuit.add_calibration("rzz", [0, 1], rzz_q01) - with pulse.build(name="rxx") as rxx_q01: - pulse.play( - pulse.library.Gaussian(duration=128, amp=0.1, sigma=16), pulse.DriveChannel(1) - ) + with pulse.build(name="rxx") as rxx_q01: + pulse.play( + pulse.library.Gaussian(duration=128, amp=0.1, sigma=16), pulse.DriveChannel(1) + ) - circuit.add_calibration("rxx", [0, 1], rxx_q01) + circuit.add_calibration("rxx", [0, 1], rxx_q01) fname = "calibrations_with_rzz_and_rxx.png" self.circuit_drawer(circuit, output="mpl", filename=fname) From 5a9a9280a9f0d45e56eea53a846ca472319da3bb Mon Sep 17 00:00:00 2001 From: Eli Arbel Date: Mon, 14 Oct 2024 18:38:49 +0300 Subject: [PATCH 15/23] Add alternative privates paths & refine deprecations --- crates/circuit/src/converters.rs | 5 +- crates/circuit/src/dag_circuit.rs | 25 ++++++++- qiskit/circuit/quantumcircuit.py | 26 ++++++++-- qiskit/compiler/transpiler.py | 2 +- qiskit/converters/circuit_to_dagdependency.py | 2 +- .../converters/circuit_to_dagdependency_v2.py | 2 +- qiskit/converters/dag_to_circuit.py | 2 +- qiskit/converters/dag_to_dagdependency.py | 2 +- qiskit/converters/dag_to_dagdependency_v2.py | 2 +- qiskit/converters/dagdependency_to_circuit.py | 7 ++- qiskit/converters/dagdependency_to_dag.py | 7 ++- qiskit/dagcircuit/dagdependency.py | 14 ++++- qiskit/providers/backend.py | 7 ++- qiskit/providers/backend_compat.py | 17 ++++++- qiskit/pulse/macros.py | 2 +- qiskit/qobj/converters/pulse_instruction.py | 10 ++-- qiskit/qpy/binary_io/circuits.py | 6 ++- qiskit/qpy/binary_io/schedules.py | 2 + qiskit/qpy/interface.py | 12 ++++- qiskit/transpiler/basepasses.py | 2 +- .../passes/basis/basis_translator.py | 8 +-- .../passes/basis/unroll_3q_or_more.py | 2 +- .../passes/basis/unroll_custom_definitions.py | 2 +- .../passes/calibration/pulse_gate.py | 4 +- .../passes/calibration/rx_builder.py | 12 ++--- .../passes/calibration/rzx_builder.py | 2 +- .../optimization/optimize_1q_decomposition.py | 6 +-- qiskit/transpiler/passes/scheduling/alap.py | 2 +- qiskit/transpiler/passes/scheduling/asap.py | 2 +- .../passes/scheduling/base_scheduler.py | 4 +- .../passes/scheduling/padding/base_padding.py | 2 +- .../padding/dynamical_decoupling.py | 2 +- .../scheduling/scheduling/base_scheduler.py | 2 +- .../passes/scheduling/time_unit_conversion.py | 2 +- .../passes/synthesis/high_level_synthesis.py | 2 +- .../transpiler/passes/utils/gate_direction.py | 6 +-- qiskit/transpiler/passmanager_config.py | 2 +- .../transpiler/preset_passmanagers/common.py | 2 +- .../generate_preset_pass_manager.py | 6 +-- qiskit/transpiler/target.py | 51 +++++++++++++++---- qiskit/visualization/circuit/matplotlib.py | 2 +- 41 files changed, 203 insertions(+), 74 deletions(-) diff --git a/crates/circuit/src/converters.rs b/crates/circuit/src/converters.rs index 37ba83ae5173..dea366d02ff6 100644 --- a/crates/circuit/src/converters.rs +++ b/crates/circuit/src/converters.rs @@ -47,7 +47,10 @@ impl<'py> FromPyObject<'py> for QuantumCircuitData<'py> { Ok(QuantumCircuitData { data: data_borrowed, name: ob.getattr(intern!(py, "name")).ok(), - calibrations: ob.getattr(intern!(py, "calibrations"))?.extract().ok(), + calibrations: ob + .getattr(intern!(py, "_calibrations_prop"))? + .extract() + .ok(), metadata: ob.getattr(intern!(py, "metadata")).ok(), qregs: ob .getattr(intern!(py, "qregs")) diff --git a/crates/circuit/src/dag_circuit.rs b/crates/circuit/src/dag_circuit.rs index 2e9598ff80df..3fcab91e16bf 100644 --- a/crates/circuit/src/dag_circuit.rs +++ b/crates/circuit/src/dag_circuit.rs @@ -569,7 +569,7 @@ impl DAGCircuit { let out_dict = PyDict::new_bound(py); out_dict.set_item("name", self.name.as_ref().map(|x| x.clone_ref(py)))?; out_dict.set_item("metadata", self.metadata.as_ref().map(|x| x.clone_ref(py)))?; - out_dict.set_item("calibrations", self.calibrations.clone())?; + out_dict.set_item("_calibrations_prop", self.calibrations.clone())?; out_dict.set_item("qregs", self.qregs.clone_ref(py))?; out_dict.set_item("cregs", self.cregs.clone_ref(py))?; out_dict.set_item("global_phase", self.global_phase.clone())?; @@ -648,7 +648,10 @@ impl DAGCircuit { let dict_state = state.downcast_bound::(py)?; self.name = dict_state.get_item("name")?.unwrap().extract()?; self.metadata = dict_state.get_item("metadata")?.unwrap().extract()?; - self.calibrations = dict_state.get_item("calibrations")?.unwrap().extract()?; + self.calibrations = dict_state + .get_item("_calibrations_prop")? + .unwrap() + .extract()?; self.qregs = dict_state.get_item("qregs")?.unwrap().extract()?; self.cregs = dict_state.get_item("cregs")?.unwrap().extract()?; self.global_phase = dict_state.get_item("global_phase")?.unwrap().extract()?; @@ -893,6 +896,20 @@ impl DAGCircuit { self.calibrations = calibrations; } + // This is an alternative and Python-private path to 'get_calibration' to avoid + // deprecation warnings + #[getter(_calibrations_prop)] + fn get_calibrations_prop(&self) -> HashMap> { + self.calibrations.clone() + } + + // This is an alternative and Python-private path to 'set_calibration' to avoid + // deprecation warnings + #[setter(_calibrations_prop)] + fn set_calibrations_prop(&mut self, calibrations: HashMap>) { + self.calibrations = calibrations; + } + /// Register a low-level, custom pulse definition for the given gate. /// /// Args: @@ -982,6 +999,10 @@ def _format(operand): "method ``qiskit.dagcircuit.dagcircuit.DAGCircuit.has_calibration_for``", ); + self._has_calibration_for(py, node) + } + + fn _has_calibration_for(&self, py: Python, node: PyRef) -> PyResult { if !self .calibrations .contains_key(node.instruction.operation.name()) diff --git a/qiskit/circuit/quantumcircuit.py b/qiskit/circuit/quantumcircuit.py index 0338783b5ed2..379de4c82faa 100644 --- a/qiskit/circuit/quantumcircuit.py +++ b/qiskit/circuit/quantumcircuit.py @@ -1348,7 +1348,7 @@ def calibrations(self) -> dict: The custom pulse definition of a given gate is of the form ``{'gate_name': {(qubits, params): schedule}}`` """ - return dict(self._calibrations) + return self._calibrations_prop @calibrations.setter @deprecate_pulse_dependency(is_property=True) @@ -1359,6 +1359,18 @@ def calibrations(self, calibrations: dict): calibrations (dict): A dictionary of input in the format ``{'gate_name': {(qubits, gate_params): schedule}}`` """ + self._calibrations_prop = calibrations + + @property + def _calibrations_prop(self) -> dict: + """An alternative private path to the `calibrations` property for avoiding deprecation warnings. + """ + return dict(self._calibrations) + + @_calibrations_prop.setter + def _calibrations_prop(self, calibrations: dict): + """An alternative private path to the `calibrations` property for avoiding deprecation warnings. + """ self._calibrations = defaultdict(dict, calibrations) @deprecate_pulse_dependency @@ -1366,12 +1378,18 @@ def has_calibration_for(self, instruction: CircuitInstruction | tuple): """Return True if the circuit has a calibration defined for the instruction context. In this case, the operation does not need to be translated to the device basis. """ + + return self._has_calibration_for(instruction) + + def _has_calibration_for(self, instruction: CircuitInstruction | tuple): + """An alternative private path to the `has_calibration_for` method for avoiding deprecation warnings. + """ if isinstance(instruction, CircuitInstruction): operation = instruction.operation qubits = instruction.qubits else: operation, qubits, _ = instruction - if not self.calibrations or operation.name not in self.calibrations: + if not self._calibrations_prop or operation.name not in self._calibrations_prop: return False qubits = tuple(self.qubits.index(qubit) for qubit in qubits) params = [] @@ -1381,7 +1399,7 @@ def has_calibration_for(self, instruction: CircuitInstruction | tuple): else: params.append(p) params = tuple(params) - return (qubits, params) in self.calibrations[operation.name] + return (qubits, params) in self._calibrations_prop[operation.name] @property def metadata(self) -> dict: @@ -2022,7 +2040,7 @@ def replace_var(var: expr.Var, cache: Mapping[expr.Var, expr.Var]) -> expr.Var: ) edge_map.update(zip(other.clbits, dest._cbit_argument_conversion(clbits))) - for gate, cals in other.calibrations.items(): + for gate, cals in other._calibrations_prop.items(): dest._calibrations[gate].update(cals) dest.duration = None diff --git a/qiskit/compiler/transpiler.py b/qiskit/compiler/transpiler.py index ff2925c40b31..2b17d8bbae12 100644 --- a/qiskit/compiler/transpiler.py +++ b/qiskit/compiler/transpiler.py @@ -39,7 +39,7 @@ _CircuitT = TypeVar("_CircuitT", bound=Union[QuantumCircuit, List[QuantumCircuit]]) -@deprecate_pulse_arg("inst_map") +@deprecate_pulse_arg("inst_map", predicate=lambda inst_map: inst_map is not None) def transpile( # pylint: disable=too-many-return-statements circuits: _CircuitT, backend: Optional[Backend] = None, diff --git a/qiskit/converters/circuit_to_dagdependency.py b/qiskit/converters/circuit_to_dagdependency.py index 7095d4773112..e617cf30c4fd 100644 --- a/qiskit/converters/circuit_to_dagdependency.py +++ b/qiskit/converters/circuit_to_dagdependency.py @@ -46,6 +46,6 @@ def circuit_to_dagdependency(circuit, create_preds_and_succs=True): dagdependency._add_predecessors() dagdependency._add_successors() - dagdependency.calibrations = circuit.calibrations + dagdependency._calibrations = circuit._calibrations_prop return dagdependency diff --git a/qiskit/converters/circuit_to_dagdependency_v2.py b/qiskit/converters/circuit_to_dagdependency_v2.py index 4852fdda56af..f55a0cf6716c 100644 --- a/qiskit/converters/circuit_to_dagdependency_v2.py +++ b/qiskit/converters/circuit_to_dagdependency_v2.py @@ -27,7 +27,7 @@ def _circuit_to_dagdependency_v2(circuit): dagdependency = _DAGDependencyV2() dagdependency.name = circuit.name dagdependency.metadata = circuit.metadata - dagdependency.calibrations = circuit.calibrations + dagdependency._calibrations = circuit._calibrations_prop dagdependency.global_phase = circuit.global_phase dagdependency.add_qubits(circuit.qubits) diff --git a/qiskit/converters/dag_to_circuit.py b/qiskit/converters/dag_to_circuit.py index 3350ebc5ab34..6ffa74527aa3 100644 --- a/qiskit/converters/dag_to_circuit.py +++ b/qiskit/converters/dag_to_circuit.py @@ -70,7 +70,7 @@ def dag_to_circuit(dag, copy_operations=True): for var in dag.iter_declared_vars(): circuit.add_uninitialized_var(var) circuit.metadata = dag.metadata - circuit.calibrations = dag.calibrations + circuit._calibrations_prop = dag._calibrations_prop circuit._data = circuit_data diff --git a/qiskit/converters/dag_to_dagdependency.py b/qiskit/converters/dag_to_dagdependency.py index dc0c3c289842..19fb70a31bd6 100644 --- a/qiskit/converters/dag_to_dagdependency.py +++ b/qiskit/converters/dag_to_dagdependency.py @@ -50,6 +50,6 @@ def dag_to_dagdependency(dag, create_preds_and_succs=True): # copy metadata dagdependency.global_phase = dag.global_phase - dagdependency.calibrations = dag.calibrations + dagdependency._calibrations_prop = dag._calibrations_prop return dagdependency diff --git a/qiskit/converters/dag_to_dagdependency_v2.py b/qiskit/converters/dag_to_dagdependency_v2.py index 5beb83b1177e..29eb12300f00 100644 --- a/qiskit/converters/dag_to_dagdependency_v2.py +++ b/qiskit/converters/dag_to_dagdependency_v2.py @@ -27,7 +27,7 @@ def _dag_to_dagdependency_v2(dag): dagdependency.name = dag.name dagdependency.metadata = dag.metadata dagdependency.global_phase = dag.global_phase - dagdependency.calibrations = dag.calibrations + dagdependency.calibrations = dag._calibrations_prop dagdependency.add_qubits(dag.qubits) dagdependency.add_clbits(dag.clbits) diff --git a/qiskit/converters/dagdependency_to_circuit.py b/qiskit/converters/dagdependency_to_circuit.py index 2c9a0d4389cb..29d2ac45838b 100644 --- a/qiskit/converters/dagdependency_to_circuit.py +++ b/qiskit/converters/dagdependency_to_circuit.py @@ -12,6 +12,7 @@ """Helper function for converting a dag dependency to a circuit""" from qiskit.circuit import QuantumCircuit, CircuitInstruction +from qiskit.dagcircuit.dagdependency import DAGDependency def dagdependency_to_circuit(dagdependency): @@ -34,7 +35,11 @@ def dagdependency_to_circuit(dagdependency): ) circuit.metadata = dagdependency.metadata - circuit.calibrations = dagdependency.calibrations + if isinstance(dagdependency, DAGDependency): + circuit._calibrations_prop = dagdependency._calibrations_prop + else: + # This can be _DAGDependencyV2 + circuit._calibrations_prop = dagdependency.calibrations for node in dagdependency.topological_nodes(): circuit._append(CircuitInstruction(node.op.copy(), node.qargs, node.cargs)) diff --git a/qiskit/converters/dagdependency_to_dag.py b/qiskit/converters/dagdependency_to_dag.py index 440f5920eb0c..3b500d82c884 100644 --- a/qiskit/converters/dagdependency_to_dag.py +++ b/qiskit/converters/dagdependency_to_dag.py @@ -12,6 +12,7 @@ """Helper function for converting a dag dependency to a dag circuit""" from qiskit.dagcircuit.dagcircuit import DAGCircuit +from qiskit.dagcircuit.dagdependency import DAGDependency def dagdependency_to_dag(dagdependency): @@ -44,6 +45,10 @@ def dagdependency_to_dag(dagdependency): # copy metadata dagcircuit.global_phase = dagdependency.global_phase - dagcircuit.calibrations = dagdependency.calibrations + if isinstance(dagdependency, DAGDependency): + dagcircuit._calibrations_prop = dagdependency._calibrations_prop + else: + # This can be _DAGDependencyV2 + dagcircuit._calibrations_prop = dagdependency.calibrations return dagcircuit diff --git a/qiskit/dagcircuit/dagdependency.py b/qiskit/dagcircuit/dagdependency.py index d012aa2f92d6..876cfd3c8017 100644 --- a/qiskit/dagcircuit/dagdependency.py +++ b/qiskit/dagcircuit/dagdependency.py @@ -154,7 +154,7 @@ def calibrations(self) -> dict[str, dict[tuple, Schedule]]: The custom pulse definition of a given gate is of the form ``{'gate_name': {(qubits, params): schedule}}``. """ - return dict(self._calibrations) + return self._calibrations_prop @calibrations.setter @deprecate_pulse_dependency(is_property=True) @@ -165,6 +165,18 @@ def calibrations(self, calibrations: dict[str, dict[tuple, Schedule]]): calibrations (dict): A dictionary of input in the format {'gate_name': {(qubits, gate_params): schedule}} """ + self._calibrations_prop = calibrations + + @property + def _calibrations_prop(self) -> dict[str, dict[tuple, Schedule]]: + """An alternative path to be used internally to avoid deprecation warnings + """ + return dict(self._calibrations) + + @_calibrations_prop.setter + def _calibrations_prop(self, calibrations: dict[str, dict[tuple, Schedule]]): + """An alternative path to be used internally to avoid deprecation warnings + """ self._calibrations = defaultdict(dict, calibrations) def to_retworkx(self): diff --git a/qiskit/providers/backend.py b/qiskit/providers/backend.py index 8d22eb86c5c5..4f46b6a51029 100644 --- a/qiskit/providers/backend.py +++ b/qiskit/providers/backend.py @@ -490,7 +490,12 @@ def meas_map(self) -> List[List[int]]: def instruction_schedule_map(self): """Return the :class:`~qiskit.pulse.InstructionScheduleMap` for the instructions defined in this backend's target.""" - return self.target.instruction_schedule_map() + return self._instruction_schedule_map + + @property + def _instruction_schedule_map(self): + """An alternative private path to be used internally to avoid pulse deprecation warnings.""" + return self.target._get_instruction_schedule_map() def qubit_properties( self, qubit: Union[int, List[int]] diff --git a/qiskit/providers/backend_compat.py b/qiskit/providers/backend_compat.py index b0a9cdd0b8ab..6971f8b8328b 100644 --- a/qiskit/providers/backend_compat.py +++ b/qiskit/providers/backend_compat.py @@ -59,7 +59,20 @@ def convert_to_target( Returns: A ``Target`` instance. """ + return _convert_to_target( + configuration, properties, defaults, custom_name_mapping, add_delay, filter_faulty + ) + +def _convert_to_target( + configuration: BackendConfiguration, + properties: BackendProperties = None, + defaults: PulseDefaults = None, + custom_name_mapping: Optional[Dict[str, Any]] = None, + add_delay: bool = True, + filter_faulty: bool = True, +): + """An alternative private path to avoid pulse deprecations""" # importing packages where they are needed, to avoid cyclic-import. # pylint: disable=cyclic-import from qiskit.transpiler.target import ( @@ -268,7 +281,7 @@ def _get_value(prop_dict, prop_name): entry = inst_sched_map._get_calibration_entry(name, qubits) try: - prop_name_map[name][qubits].calibration = entry + prop_name_map[name][qubits]._calibration_prop = entry except AttributeError: # if instruction properties are "None", add entry prop_name_map[name].update({qubits: InstructionProperties(None, None, entry)}) @@ -413,7 +426,7 @@ def target(self): :rtype: Target """ if self._target is None: - self._target = convert_to_target( + self._target = _convert_to_target( configuration=self._config, properties=self._properties, defaults=self._defaults, diff --git a/qiskit/pulse/macros.py b/qiskit/pulse/macros.py index 3a39932e5b10..a01441dfc2f2 100644 --- a/qiskit/pulse/macros.py +++ b/qiskit/pulse/macros.py @@ -194,7 +194,7 @@ def _measure_v2( for measure_qubit in meas_group: try: if measure_qubit in qubits: - default_sched = target.get_calibration(measure_name, (measure_qubit,)).filter( + default_sched = target._get_calibration(measure_name, (measure_qubit,)).filter( channels=[ channels.MeasureChannel(measure_qubit), channels.AcquireChannel(measure_qubit), diff --git a/qiskit/qobj/converters/pulse_instruction.py b/qiskit/qobj/converters/pulse_instruction.py index e17036210d57..3a0947f34f09 100644 --- a/qiskit/qobj/converters/pulse_instruction.py +++ b/qiskit/qobj/converters/pulse_instruction.py @@ -31,6 +31,7 @@ from qiskit.qobj import QobjMeasurementOption, PulseLibraryItem, PulseQobjInstruction from qiskit.qobj.utils import MeasLevel from qiskit.utils import deprecate_func +from qiskit.utils.deprecate_pulse import deprecate_pulse_dependency class ParametricPulseShapes(Enum): @@ -87,9 +88,9 @@ class InstructionToQobjConverter: This converter converts the Qiskit Pulse in-memory representation into the transfer layer format to submit the data from client to the server. - The transfer layer format must be the text representation that coforms to + The transfer layer format must be the text representation that conforms to the `OpenPulse specification`__. - Extention to the OpenPulse can be achieved by subclassing this this with + Extension to the OpenPulse can be achieved by subclassing this this with extra methods corresponding to each augmented instruction. For example, .. code-block:: python @@ -509,9 +510,9 @@ class QobjToInstructionConverter: This converter converts data from transfer layer into the in-memory representation of the front-end of Qiskit Pulse. - The transfer layer format must be the text representation that coforms to + The transfer layer format must be the text representation that conforms to the `OpenPulse specification`__. - Extention to the OpenPulse can be achieved by subclassing this this with + Extension to the OpenPulse can be achieved by subclassing this this with extra methods corresponding to each augmented instruction. For example, .. code-block:: python @@ -532,6 +533,7 @@ def _convert_new_inst(self, instruction): __chan_regex__ = re.compile(r"([a-zA-Z]+)(\d+)") + @deprecate_pulse_dependency def __init__( self, pulse_library: Optional[List[PulseLibraryItem]] = None, diff --git a/qiskit/qpy/binary_io/circuits.py b/qiskit/qpy/binary_io/circuits.py index 142639a4e164..3fe1834db6ef 100644 --- a/qiskit/qpy/binary_io/circuits.py +++ b/qiskit/qpy/binary_io/circuits.py @@ -1310,7 +1310,7 @@ def write_circuit( instruction_buffer.close() # Write calibrations - _write_calibrations(file_obj, circuit.calibrations, metadata_serializer, version=version) + _write_calibrations(file_obj, circuit._calibrations_prop, metadata_serializer, version=version) _write_layout(file_obj, circuit) @@ -1440,7 +1440,9 @@ def read_circuit(file_obj, version, metadata_deserializer=None, use_symengine=Fa # Read calibrations if version >= 5: - circ.calibrations = _read_calibrations(file_obj, version, vectors, metadata_deserializer) + circ._calibrations_prop = _read_calibrations( + file_obj, version, vectors, metadata_deserializer + ) for vec_name, (vector, initialized_params) in vectors.items(): if len(initialized_params) != len(vector): diff --git a/qiskit/qpy/binary_io/schedules.py b/qiskit/qpy/binary_io/schedules.py index 1bf86d254186..4afddb29992a 100644 --- a/qiskit/qpy/binary_io/schedules.py +++ b/qiskit/qpy/binary_io/schedules.py @@ -28,6 +28,7 @@ from qiskit.qpy.binary_io import value from qiskit.qpy.exceptions import QpyError from qiskit.pulse.configuration import Kernel, Discriminator +from qiskit.utils.deprecate_pulse import ignore_pulse_deprecation_warnings def _read_channel(file_obj, version): @@ -510,6 +511,7 @@ def _dumps_reference_item(schedule, metadata_serializer, version): return type_key, data_bytes +@ignore_pulse_deprecation_warnings def read_schedule_block(file_obj, version, metadata_deserializer=None, use_symengine=False): """Read a single ScheduleBlock from the file like object. diff --git a/qiskit/qpy/interface.py b/qiskit/qpy/interface.py index 21aa5af63ec6..b5abd2ea9b6b 100644 --- a/qiskit/qpy/interface.py +++ b/qiskit/qpy/interface.py @@ -25,7 +25,7 @@ from qiskit.pulse import ScheduleBlock from qiskit.exceptions import QiskitError from qiskit.qpy import formats, common, binary_io, type_keys -from qiskit.qpy.exceptions import QpyError +from qiskit.qpy.exceptions import QPYLoadingDeprecatedFeatureWarning, QpyError from qiskit.version import __version__ from qiskit.utils.deprecate_pulse import deprecate_pulse_arg @@ -217,7 +217,7 @@ def dump( pulse_gates = False for program in programs: - if type_key == type_keys.Program.CIRCUIT and program.calibrations: + if type_key == type_keys.Program.CIRCUIT and program._calibrations_prop: pulse_gates = True writer( file_obj, @@ -348,6 +348,14 @@ def load( loader = binary_io.read_circuit elif type_key == type_keys.Program.SCHEDULE_BLOCK: loader = binary_io.read_schedule_block + warnings.warn( + category=QPYLoadingDeprecatedFeatureWarning, + message="Pulse gates deserialization is deprecated as of Qiskit 1.3 and " + "will be removed in Qiskit 2.0. This is part of the deprecation plan for " + "the entire Qiskit Pulse package. Once Pulse is removed, `ScheduleBlock` " + "sections will be ignored when loading QPY files with pulse data." + ) + else: raise TypeError(f"Invalid payload format data kind '{type_key}'.") diff --git a/qiskit/transpiler/basepasses.py b/qiskit/transpiler/basepasses.py index 396f5cf49344..b4993915c1cc 100644 --- a/qiskit/transpiler/basepasses.py +++ b/qiskit/transpiler/basepasses.py @@ -201,7 +201,7 @@ def execute( if state.workflow_status.previous_run == RunState.SUCCESS: if isinstance(new_dag, DAGCircuit): # Copy calibration data from the original program - new_dag.calibrations = passmanager_ir.calibrations + new_dag._calibrations_prop = passmanager_ir._calibrations_prop else: raise TranspilerError( "Transformation passes should return a transformed dag." diff --git a/qiskit/transpiler/passes/basis/basis_translator.py b/qiskit/transpiler/passes/basis/basis_translator.py index a1d3e7f0d39c..c75bff1a6ebc 100644 --- a/qiskit/transpiler/passes/basis/basis_translator.py +++ b/qiskit/transpiler/passes/basis/basis_translator.py @@ -276,7 +276,7 @@ def apply_translation(dag, wire_map): out_dag.apply_operation_back(node.op, node.qargs, node.cargs, check=False) continue - if dag.has_calibration_for(node): + if dag._has_calibration_for(node): out_dag.apply_operation_back(node.op, node.qargs, node.cargs, check=False) continue if qubit_set in extra_instr_map: @@ -383,7 +383,7 @@ def _extract_basis(self, circuit): @_extract_basis.register def _(self, dag: DAGCircuit): for node in dag.op_nodes(): - if not dag.has_calibration_for(node) and len(node.qargs) >= self._min_qubits: + if not dag._has_calibration_for(node) and len(node.qargs) >= self._min_qubits: yield (node.name, node.num_qubits) if node.name in CONTROL_FLOW_OP_NAMES: for block in node.op.blocks: @@ -394,7 +394,7 @@ def _(self, circ: QuantumCircuit): for instruction in circ.data: operation = instruction.operation if ( - not circ.has_calibration_for(instruction) + not circ._has_calibration_for(instruction) and len(instruction.qubits) >= self._min_qubits ): yield (operation.name, operation.num_qubits) @@ -411,7 +411,7 @@ def _extract_basis_target( qargs_local_source_basis = defaultdict(set) for node in dag.op_nodes(): qargs = tuple(qarg_indices[bit] for bit in node.qargs) - if dag.has_calibration_for(node) or len(node.qargs) < self._min_qubits: + if dag._has_calibration_for(node) or len(node.qargs) < self._min_qubits: continue # Treat the instruction as on an incomplete basis if the qargs are in the # qargs_with_non_global_operation dictionary or if any of the qubits in qargs diff --git a/qiskit/transpiler/passes/basis/unroll_3q_or_more.py b/qiskit/transpiler/passes/basis/unroll_3q_or_more.py index 0c6d780f052a..885009a23e03 100644 --- a/qiskit/transpiler/passes/basis/unroll_3q_or_more.py +++ b/qiskit/transpiler/passes/basis/unroll_3q_or_more.py @@ -54,7 +54,7 @@ def run(self, dag): QiskitError: if a 3q+ gate is not decomposable """ for node in dag.multi_qubit_ops(): - if dag.has_calibration_for(node): + if dag._has_calibration_for(node): continue if isinstance(node.op, ControlFlowOp): diff --git a/qiskit/transpiler/passes/basis/unroll_custom_definitions.py b/qiskit/transpiler/passes/basis/unroll_custom_definitions.py index 51e116033bb6..11ba6afcd1b3 100644 --- a/qiskit/transpiler/passes/basis/unroll_custom_definitions.py +++ b/qiskit/transpiler/passes/basis/unroll_custom_definitions.py @@ -74,7 +74,7 @@ def run(self, dag): if getattr(node.op, "_directive", False): continue - if dag.has_calibration_for(node) or len(node.qargs) < self._min_qubits: + if dag._has_calibration_for(node) or len(node.qargs) < self._min_qubits: continue controlled_gate_open_ctrl = isinstance(node.op, ControlledGate) and node.op._open_ctrl diff --git a/qiskit/transpiler/passes/calibration/pulse_gate.py b/qiskit/transpiler/passes/calibration/pulse_gate.py index dfdb9f754e9a..f5b56ad0f359 100644 --- a/qiskit/transpiler/passes/calibration/pulse_gate.py +++ b/qiskit/transpiler/passes/calibration/pulse_gate.py @@ -82,7 +82,7 @@ def supported(self, node_op: CircuitInst, qubits: List) -> bool: Returns: Return ``True`` is calibration can be provided. """ - return self.target.has_calibration(node_op.name, tuple(qubits)) + return self.target._has_calibration(node_op.name, tuple(qubits)) def get_calibration(self, node_op: CircuitInst, qubits: List) -> Union[Schedule, ScheduleBlock]: """Gets the calibrated schedule for the given instruction and qubits. @@ -97,4 +97,4 @@ def get_calibration(self, node_op: CircuitInst, qubits: List) -> Union[Schedule, Raises: TranspilerError: When node is parameterized and calibration is raw schedule object. """ - return self.target.get_calibration(node_op.name, tuple(qubits), *node_op.params) + return self.target._get_calibration(node_op.name, tuple(qubits), *node_op.params) diff --git a/qiskit/transpiler/passes/calibration/rx_builder.py b/qiskit/transpiler/passes/calibration/rx_builder.py index ade2893b2bd4..0d263669d316 100644 --- a/qiskit/transpiler/passes/calibration/rx_builder.py +++ b/qiskit/transpiler/passes/calibration/rx_builder.py @@ -101,13 +101,13 @@ def supported(self, node_op: Instruction, qubits: list) -> bool: """ return ( isinstance(node_op, RXGate) - and self.target.has_calibration("sx", tuple(qubits)) - and (len(self.target.get_calibration("sx", tuple(qubits)).instructions) == 1) + and self.target._has_calibration("sx", tuple(qubits)) + and (len(self.target._get_calibration("sx", tuple(qubits)).instructions) == 1) and isinstance( - self.target.get_calibration("sx", tuple(qubits)).instructions[0][1].pulse, + self.target._get_calibration("sx", tuple(qubits)).instructions[0][1].pulse, ScalableSymbolicPulse, ) - and self.target.get_calibration("sx", tuple(qubits)).instructions[0][1].pulse.pulse_type + and self.target._get_calibration("sx", tuple(qubits)).instructions[0][1].pulse.pulse_type == "Drag" ) @@ -124,13 +124,13 @@ def get_calibration(self, node_op: Instruction, qubits: list) -> Union[Schedule, raise QiskitError("Target rotation angle is not assigned.") from ex params = ( - self.target.get_calibration("sx", tuple(qubits)) + self.target._get_calibration("sx", tuple(qubits)) .instructions[0][1] .pulse.parameters.copy() ) new_rx_sched = _create_rx_sched( rx_angle=angle, - channel=self.target.get_calibration("sx", tuple(qubits)).channels[0], + channel=self.target._get_calibration("sx", tuple(qubits)).channels[0], duration=params["duration"], amp=params["amp"], sigma=params["sigma"], diff --git a/qiskit/transpiler/passes/calibration/rzx_builder.py b/qiskit/transpiler/passes/calibration/rzx_builder.py index 5c88e5fe88e3..b3e7dc132290 100644 --- a/qiskit/transpiler/passes/calibration/rzx_builder.py +++ b/qiskit/transpiler/passes/calibration/rzx_builder.py @@ -91,7 +91,7 @@ def __init__( self._inst_map = instruction_schedule_map self._verbose = verbose if target: - self._inst_map = target.instruction_schedule_map() + self._inst_map = target._instruction_schedule_map() if self._inst_map is None: raise QiskitError("Calibrations can only be added to Pulse-enabled backends") diff --git a/qiskit/transpiler/passes/optimization/optimize_1q_decomposition.py b/qiskit/transpiler/passes/optimization/optimize_1q_decomposition.py index eadff1bfe867..55232ac1be20 100644 --- a/qiskit/transpiler/passes/optimization/optimize_1q_decomposition.py +++ b/qiskit/transpiler/passes/optimization/optimize_1q_decomposition.py @@ -170,13 +170,13 @@ def _substitution_checks( return False # do we even have calibrations? - has_cals_p = dag.calibrations is not None and len(dag.calibrations) > 0 + has_cals_p = dag._calibrations_prop is not None and len(dag._calibrations_prop) > 0 # does this run have uncalibrated gates? - uncalibrated_p = not has_cals_p or any(not dag.has_calibration_for(g) for g in old_run) + uncalibrated_p = not has_cals_p or any(not dag._has_calibration_for(g) for g in old_run) # does this run have gates not in the image of ._decomposers _and_ uncalibrated? if basis is not None: uncalibrated_and_not_basis_p = any( - g.name not in basis and (not has_cals_p or not dag.has_calibration_for(g)) + g.name not in basis and (not has_cals_p or not dag._has_calibration_for(g)) for g in old_run ) else: diff --git a/qiskit/transpiler/passes/scheduling/alap.py b/qiskit/transpiler/passes/scheduling/alap.py index 10ae623c4659..cdbdd4654f3c 100644 --- a/qiskit/transpiler/passes/scheduling/alap.py +++ b/qiskit/transpiler/passes/scheduling/alap.py @@ -144,7 +144,7 @@ def run(self, dag): new_dag.name = dag.name new_dag.metadata = dag.metadata - new_dag.calibrations = dag.calibrations + new_dag._calibrations_prop = dag._calibrations_prop # set circuit duration and unit to indicate it is scheduled new_dag.duration = circuit_duration diff --git a/qiskit/transpiler/passes/scheduling/asap.py b/qiskit/transpiler/passes/scheduling/asap.py index b1e559718143..13ff58b1b0f0 100644 --- a/qiskit/transpiler/passes/scheduling/asap.py +++ b/qiskit/transpiler/passes/scheduling/asap.py @@ -167,7 +167,7 @@ def run(self, dag): new_dag.name = dag.name new_dag.metadata = dag.metadata - new_dag.calibrations = dag.calibrations + new_dag._calibrations_prop = dag._calibrations_prop # set circuit duration and unit to indicate it is scheduled new_dag.duration = circuit_duration diff --git a/qiskit/transpiler/passes/scheduling/base_scheduler.py b/qiskit/transpiler/passes/scheduling/base_scheduler.py index fe6d0e16cb76..57073a3c0c14 100644 --- a/qiskit/transpiler/passes/scheduling/base_scheduler.py +++ b/qiskit/transpiler/passes/scheduling/base_scheduler.py @@ -264,10 +264,10 @@ def _get_node_duration( """A helper method to get duration from node or calibration.""" indices = [dag.find_bit(qarg).index for qarg in node.qargs] - if dag.has_calibration_for(node): + if dag._has_calibration_for(node): # If node has calibration, this value should be the highest priority cal_key = tuple(indices), tuple(float(p) for p in node.op.params) - duration = dag.calibrations[node.op.name][cal_key].duration + duration = dag._calibrations_prop[node.op.name][cal_key].duration else: duration = node.op.duration diff --git a/qiskit/transpiler/passes/scheduling/padding/base_padding.py b/qiskit/transpiler/passes/scheduling/padding/base_padding.py index 4ce17e7bc261..e8876920aa03 100644 --- a/qiskit/transpiler/passes/scheduling/padding/base_padding.py +++ b/qiskit/transpiler/passes/scheduling/padding/base_padding.py @@ -99,7 +99,7 @@ def run(self, dag: DAGCircuit): new_dag.name = dag.name new_dag.metadata = dag.metadata new_dag.unit = self.property_set["time_unit"] - new_dag.calibrations = dag.calibrations + new_dag._calibrations_prop = dag._calibrations_prop new_dag.global_phase = dag.global_phase idle_after = {bit: 0 for bit in dag.qubits} diff --git a/qiskit/transpiler/passes/scheduling/padding/dynamical_decoupling.py b/qiskit/transpiler/passes/scheduling/padding/dynamical_decoupling.py index 2217d32f847c..9f001ea86ee9 100644 --- a/qiskit/transpiler/passes/scheduling/padding/dynamical_decoupling.py +++ b/qiskit/transpiler/passes/scheduling/padding/dynamical_decoupling.py @@ -187,7 +187,7 @@ def _update_inst_durations(self, dag): """ circ_durations = InstructionDurations() - if dag.calibrations: + if dag._calibrations_prop: cal_durations = [] for gate, gate_cals in dag.calibrations.items(): for (qubits, parameters), schedule in gate_cals.items(): diff --git a/qiskit/transpiler/passes/scheduling/scheduling/base_scheduler.py b/qiskit/transpiler/passes/scheduling/scheduling/base_scheduler.py index d9f3d77f2915..f1a67a92b60f 100644 --- a/qiskit/transpiler/passes/scheduling/scheduling/base_scheduler.py +++ b/qiskit/transpiler/passes/scheduling/scheduling/base_scheduler.py @@ -64,7 +64,7 @@ def _get_node_duration( """A helper method to get duration from node or calibration.""" indices = [dag.find_bit(qarg).index for qarg in node.qargs] - if dag.has_calibration_for(node): + if dag._has_calibration_for(node): # If node has calibration, this value should be the highest priority cal_key = tuple(indices), tuple(float(p) for p in node.op.params) duration = dag.calibrations[node.op.name][cal_key].duration diff --git a/qiskit/transpiler/passes/scheduling/time_unit_conversion.py b/qiskit/transpiler/passes/scheduling/time_unit_conversion.py index f4f70210b785..eeb2768b5a5b 100644 --- a/qiskit/transpiler/passes/scheduling/time_unit_conversion.py +++ b/qiskit/transpiler/passes/scheduling/time_unit_conversion.py @@ -121,7 +121,7 @@ def _update_inst_durations(self, dag): """ circ_durations = InstructionDurations() - if dag.calibrations: + if dag._calibrations_prop: cal_durations = [] for gate, gate_cals in dag.calibrations.items(): for (qubits, parameters), schedule in gate_cals.items(): diff --git a/qiskit/transpiler/passes/synthesis/high_level_synthesis.py b/qiskit/transpiler/passes/synthesis/high_level_synthesis.py index 733d5465fd0a..8bdd0a761edf 100644 --- a/qiskit/transpiler/passes/synthesis/high_level_synthesis.py +++ b/qiskit/transpiler/passes/synthesis/high_level_synthesis.py @@ -646,7 +646,7 @@ def _definitely_skip_node( node (which is _most_ nodes).""" if ( - dag.has_calibration_for(node) + dag._has_calibration_for(node) or len(node.qargs) < self._min_qubits or node.is_directive() ): diff --git a/qiskit/transpiler/passes/utils/gate_direction.py b/qiskit/transpiler/passes/utils/gate_direction.py index 8ea77f7ccd46..198eb34c501f 100644 --- a/qiskit/transpiler/passes/utils/gate_direction.py +++ b/qiskit/transpiler/passes/utils/gate_direction.py @@ -192,7 +192,7 @@ def _run_coupling_map(self, dag, wire_map, edges=None): continue if len(node.qargs) != 2: continue - if dag.has_calibration_for(node): + if dag._has_calibration_for(node): continue qargs = (wire_map[node.qargs[0]], wire_map[node.qargs[1]]) if qargs not in edges and (qargs[1], qargs[0]) not in edges: @@ -239,7 +239,7 @@ def _run_target(self, dag, wire_map): continue if len(node.qargs) != 2: continue - if dag.has_calibration_for(node): + if dag._has_calibration_for(node): continue qargs = (wire_map[node.qargs[0]], wire_map[node.qargs[1]]) swapped = (qargs[1], qargs[0]) @@ -311,7 +311,7 @@ def _run_target(self, dag, wire_map): ) elif self.target.instruction_supported(node.name, qargs): continue - elif self.target.instruction_supported(node.name, swapped) or dag.has_calibration_for( + elif self.target.instruction_supported(node.name, swapped) or dag._has_calibration_for( _swap_node_qargs(node) ): raise TranspilerError( diff --git a/qiskit/transpiler/passmanager_config.py b/qiskit/transpiler/passmanager_config.py index 0ebbff430301..baf4482a3b05 100644 --- a/qiskit/transpiler/passmanager_config.py +++ b/qiskit/transpiler/passmanager_config.py @@ -160,7 +160,7 @@ def from_backend(cls, backend, _skip_target=False, **pass_manager_options): if defaults is not None: res.inst_map = defaults.instruction_schedule_map else: - res.inst_map = backend.instruction_schedule_map + res.inst_map = backend._instruction_schedule_map if res.coupling_map is None: if backend_version < 2: cmap_edge_list = getattr(config, "coupling_map", None) diff --git a/qiskit/transpiler/preset_passmanagers/common.py b/qiskit/transpiler/preset_passmanagers/common.py index 556435a9d420..25d21880bd23 100644 --- a/qiskit/transpiler/preset_passmanagers/common.py +++ b/qiskit/transpiler/preset_passmanagers/common.py @@ -530,7 +530,7 @@ def generate_translation_passmanager( return PassManager(unroll) -@deprecate_pulse_arg("inst_map") +@deprecate_pulse_arg("inst_map", predicate=lambda inst_map: inst_map is not None) def generate_scheduling( instruction_durations, scheduling_method, timing_constraints, inst_map, target=None ): diff --git a/qiskit/transpiler/preset_passmanagers/generate_preset_pass_manager.py b/qiskit/transpiler/preset_passmanagers/generate_preset_pass_manager.py index 564de5415a60..779a3512faab 100644 --- a/qiskit/transpiler/preset_passmanagers/generate_preset_pass_manager.py +++ b/qiskit/transpiler/preset_passmanagers/generate_preset_pass_manager.py @@ -37,7 +37,7 @@ from .level3 import level_3_pass_manager -@deprecate_pulse_arg("inst_map") +@deprecate_pulse_arg("inst_map", predicate=lambda inst_map: inst_map is not None) def generate_preset_pass_manager( optimization_level=2, backend=None, @@ -341,7 +341,7 @@ def generate_preset_pass_manager( if instruction_durations is None: instruction_durations = target.durations() if inst_map is None: - inst_map = target.instruction_schedule_map() + inst_map = target._get_instruction_schedule_map() if timing_constraints is None: timing_constraints = target.timing_constraints() if backend_properties is None: @@ -454,7 +454,7 @@ def _parse_basis_gates(basis_gates, backend, inst_map, skip_target): def _parse_inst_map(inst_map, backend): # try getting inst_map from user, else backend if inst_map is None and backend is not None: - inst_map = backend.target.instruction_schedule_map() + inst_map = backend.target._get_instruction_schedule_map() return inst_map diff --git a/qiskit/transpiler/target.py b/qiskit/transpiler/target.py index 433bb9819ee4..4ab5a0fd4b0e 100644 --- a/qiskit/transpiler/target.py +++ b/qiskit/transpiler/target.py @@ -87,7 +87,7 @@ def __new__( # pylint: disable=keyword-arg-before-vararg cls, duration, error ) - @deprecate_pulse_arg("calibration") + @deprecate_pulse_arg("calibration", predicate=lambda cals: cals is not None) def __init__( self, duration: float | None = None, # pylint: disable=unused-argument @@ -105,7 +105,7 @@ def __init__( """ super().__init__() self._calibration: CalibrationEntry | None = None - self.calibration = calibration + self._calibration_prop = calibration @property @deprecate_pulse_dependency(is_property=True) @@ -136,13 +136,23 @@ def calibration(self): use own definition to compile the circuit down to the execution format. """ - if self._calibration is None: - return None - return self._calibration.get_schedule() + return self._calibration_prop @calibration.setter @deprecate_pulse_dependency(is_property=True) def calibration(self, calibration: Schedule | ScheduleBlock | CalibrationEntry): + self._calibration_prop = calibration + + @property + def _calibration_prop(self): + if self._calibration is None: + return None + with warnings.catch_warnings(action="ignore", category=DeprecationWarning): + # Clean this alternative path from deprecation warning emitted by `get_schedule` + return self._calibration.get_schedule() + + @_calibration_prop.setter + def _calibration_prop(self, calibration: Schedule | ScheduleBlock | CalibrationEntry): if isinstance(calibration, (Schedule, ScheduleBlock)): new_entry = ScheduleDef() new_entry.define(calibration, user_provided=True) @@ -157,11 +167,11 @@ def __repr__(self): ) def __getstate__(self) -> tuple: - return (super().__getstate__(), self.calibration, self._calibration) + return (super().__getstate__(), self._calibration_prop, self._calibration) def __setstate__(self, state: tuple): super().__setstate__(state[0]) - self.calibration = state[1] + self._calibration_prop = state[1] self._calibration = state[2] @@ -618,9 +628,16 @@ def instruction_schedule_map(self): InstructionScheduleMap: The instruction schedule map for the instructions in this target with a pulse schedule defined. """ + return self._get_instruction_schedule_map() + + def _get_instruction_schedule_map(self): if self._instruction_schedule_map is not None: return self._instruction_schedule_map - out_inst_schedule_map = InstructionScheduleMap() + with warnings.catch_warnings(action='ignore', category=DeprecationWarning): + # `InstructionScheduleMap` is deprecated in Qiskit 1.3 but we want this alternative + # path to be clean of deprecation warnings + out_inst_schedule_map = InstructionScheduleMap() + for instruction, qargs in self._gate_map.items(): for qarg, properties in qargs.items(): # Directly getting CalibrationEntry not to invoke .get_schedule(). @@ -647,6 +664,13 @@ def has_calibration( Returns: Returns ``True`` if the calibration is supported and ``False`` if it isn't. """ + return self._has_calibration(operation_name, qargs) + + def _has_calibration( + self, + operation_name: str, + qargs: tuple[int, ...], + ) -> bool: qargs = tuple(qargs) if operation_name not in self._gate_map: return False @@ -676,7 +700,16 @@ def get_calibration( Returns: Calibrated pulse schedule of corresponding instruction. """ - if not self.has_calibration(operation_name, qargs): + return self._get_calibration(operation_name, qargs, *args, *kwargs) + + def _get_calibration( + self, + operation_name: str, + qargs: tuple[int, ...], + *args: ParameterValueType, + **kwargs: ParameterValueType, + ) -> Schedule | ScheduleBlock: + if not self._has_calibration(operation_name, qargs): raise KeyError( f"Calibration of instruction {operation_name} for qubit {qargs} is not defined." ) diff --git a/qiskit/visualization/circuit/matplotlib.py b/qiskit/visualization/circuit/matplotlib.py index 9c4fa25309fc..62e1e0e7b156 100644 --- a/qiskit/visualization/circuit/matplotlib.py +++ b/qiskit/visualization/circuit/matplotlib.py @@ -135,7 +135,7 @@ def __init__( self._initial_state = initial_state self._global_phase = self._circuit.global_phase - self._calibrations = self._circuit.calibrations + self._calibrations = self._circuit._calibrations_prop self._expr_len = expr_len self._cregbundle = cregbundle From b46c24e765931c0e90199e2b0a25f60a7c8fa12e Mon Sep 17 00:00:00 2001 From: Eli Arbel Date: Mon, 14 Oct 2024 18:43:02 +0300 Subject: [PATCH 16/23] Catch pulse deprecation warnings in certain methods This commit adds `warnings.catch_warnings` blocks to some methods which are not directly deprecated but otherwise use classes or methods which are being deprecated. Adding this filter to specific methods which are used in common workflow, e.g. transpilation and for which we don't want pulse deprecations to be emitted if pulse is not used directly by the user. --- .../fake_provider/fake_pulse_backend.py | 6 +- .../fake_provider/generic_backend_v2.py | 63 +++++++++-------- qiskit/pulse/calibration_entries.py | 4 +- qiskit/pulse/instruction_schedule_map.py | 4 +- .../passes/calibration/rzx_builder.py | 69 +++++++++++-------- .../scheduling/alignments/check_durations.py | 2 +- .../passes/scheduling/dynamical_decoupling.py | 14 ++-- .../padding/dynamical_decoupling.py | 17 +++-- .../scheduling/scheduling/base_scheduler.py | 5 +- .../passes/scheduling/time_unit_conversion.py | 10 ++- .../preset_passmanagers/builtin_plugins.py | 28 +++++--- 11 files changed, 139 insertions(+), 83 deletions(-) diff --git a/qiskit/providers/fake_provider/fake_pulse_backend.py b/qiskit/providers/fake_provider/fake_pulse_backend.py index bf772d339bc7..5bffeb473771 100644 --- a/qiskit/providers/fake_provider/fake_pulse_backend.py +++ b/qiskit/providers/fake_provider/fake_pulse_backend.py @@ -14,6 +14,8 @@ Fake backend abstract class for mock backends supporting OpenPulse. """ +import warnings + from qiskit.exceptions import QiskitError from qiskit.providers.models.backendconfiguration import PulseBackendConfiguration from qiskit.providers.models.pulsedefaults import PulseDefaults @@ -30,7 +32,9 @@ class FakePulseBackend(FakeQasmBackend): def defaults(self): """Returns a snapshot of device defaults""" if not self._defaults: - self._set_defaults_from_json() + with warnings.catch_warnings(action='ignore', category=DeprecationWarning): + # Filter deprecation warnings emitted from Qiskit Pulse + self._set_defaults_from_json() return self._defaults def _set_defaults_from_json(self): diff --git a/qiskit/providers/fake_provider/generic_backend_v2.py b/qiskit/providers/fake_provider/generic_backend_v2.py index e6c308fcc3d0..533238a188c2 100644 --- a/qiskit/providers/fake_provider/generic_backend_v2.py +++ b/qiskit/providers/fake_provider/generic_backend_v2.py @@ -651,14 +651,16 @@ def meas_map(self) -> list[list[int]]: return self._target.concurrent_measurements def _build_default_channels(self) -> None: - channels_map = { - "acquire": {(i,): [pulse.AcquireChannel(i)] for i in range(self.num_qubits)}, - "drive": {(i,): [pulse.DriveChannel(i)] for i in range(self.num_qubits)}, - "measure": {(i,): [pulse.MeasureChannel(i)] for i in range(self.num_qubits)}, - "control": { - (edge): [pulse.ControlChannel(i)] for i, edge in enumerate(self._coupling_map) - }, - } + with warnings.catch_warnings(action='ignore', category=DeprecationWarning): + # Prevent pulse deprecation warnings from being emitted + channels_map = { + "acquire": {(i,): [pulse.AcquireChannel(i)] for i in range(self.num_qubits)}, + "drive": {(i,): [pulse.DriveChannel(i)] for i in range(self.num_qubits)}, + "measure": {(i,): [pulse.MeasureChannel(i)] for i in range(self.num_qubits)}, + "control": { + (edge): [pulse.ControlChannel(i)] for i, edge in enumerate(self._coupling_map) + }, + } setattr(self, "channels_map", channels_map) def _get_noise_defaults(self, name: str, num_qubits: int) -> tuple: @@ -870,27 +872,32 @@ def _add_noisy_instruction_to_target( duration, error = ( noise_params if len(noise_params) == 2 - else (self._rng.uniform(*noise_params[:2]), self._rng.uniform(*noise_params[2:])) - ) - if ( - calibration_inst_map is not None - and instruction.name not in ["reset", "delay"] - and qarg in calibration_inst_map.qubits_with_instruction(instruction.name) - ): - # Do NOT call .get method. This parses Qobj immediately. - # This operation is computationally expensive and should be bypassed. - calibration_entry = calibration_inst_map._get_calibration_entry( - instruction.name, qargs + else ( + self._rng.uniform(*noise_params[:2]), + self._rng.uniform(*noise_params[2:]), ) - else: - calibration_entry = None - if duration is not None and len(noise_params) > 2: - # Ensure exact conversion of duration from seconds to dt - dt = _QUBIT_PROPERTIES["dt"] - rounded_duration = round(duration / dt) * dt - # Clamp rounded duration to be between min and max values - duration = max(noise_params[0], min(rounded_duration, noise_params[1])) - props.update({qargs: InstructionProperties(duration, error, calibration_entry)}) + ) + with warnings.catch_warnings(action='ignore', category=DeprecationWarning): + # Prevent pulse deprecations from being emitted + if ( + calibration_inst_map is not None + and instruction.name not in ["reset", "delay"] + and qarg in calibration_inst_map.qubits_with_instruction(instruction.name) + ): + # Do NOT call .get method. This parses Qobj immediately. + # This operation is computationally expensive and should be bypassed. + calibration_entry = calibration_inst_map._get_calibration_entry( + instruction.name, qargs + ) + else: + calibration_entry = None + if duration is not None and len(noise_params) > 2: + # Ensure exact conversion of duration from seconds to dt + dt = _QUBIT_PROPERTIES["dt"] + rounded_duration = round(duration / dt) * dt + # Clamp rounded duration to be between min and max values + duration = max(noise_params[0], min(rounded_duration, noise_params[1])) + props.update({qargs: InstructionProperties(duration, error, calibration_entry)}) self._target.add_instruction(instruction, props) # The "measure" instruction calibrations need to be added qubit by qubit, once the diff --git a/qiskit/pulse/calibration_entries.py b/qiskit/pulse/calibration_entries.py index 8a5ba1b6e3d6..f2774bdc8474 100644 --- a/qiskit/pulse/calibration_entries.py +++ b/qiskit/pulse/calibration_entries.py @@ -321,7 +321,9 @@ def __init__( def _build_schedule(self): """Build pulse schedule from cmd-def sequence.""" - schedule = Schedule(name=self._name) + with warnings.catch_warnings(action='ignore', category=DeprecationWarning): + # `Schedule` is being deprecated in Qiskit 1.3 + schedule = Schedule(name=self._name) try: for qobj_inst in self._source: for qiskit_inst in self._converter._get_sequences(qobj_inst): diff --git a/qiskit/pulse/instruction_schedule_map.py b/qiskit/pulse/instruction_schedule_map.py index 23e90df665fa..4a038d0d7190 100644 --- a/qiskit/pulse/instruction_schedule_map.py +++ b/qiskit/pulse/instruction_schedule_map.py @@ -356,7 +356,9 @@ def get_parameters( instruction = _get_instruction_string(instruction) self.assert_has(instruction, qubits) - signature = self._map[instruction][_to_tuple(qubits)].get_signature() + with warnings.catch_warnings(action='ignore', category=DeprecationWarning): + # Prevent `get_signature` from emitting pulse package deprecation warnings + signature = self._map[instruction][_to_tuple(qubits)].get_signature() return tuple(signature.parameters.keys()) def __str__(self): diff --git a/qiskit/transpiler/passes/calibration/rzx_builder.py b/qiskit/transpiler/passes/calibration/rzx_builder.py index b3e7dc132290..a5651f2acf20 100644 --- a/qiskit/transpiler/passes/calibration/rzx_builder.py +++ b/qiskit/transpiler/passes/calibration/rzx_builder.py @@ -204,15 +204,19 @@ def get_calibration(self, node_op: CircuitInst, qubits: list) -> Schedule | Sche # The CR instruction is in the forward (native) direction if cal_type in [CRCalType.ECR_CX_FORWARD, CRCalType.ECR_FORWARD]: - xgate = self._inst_map.get("x", qubits[0]) - with builder.build( - default_alignment="sequential", name=f"rzx({theta:.3f})" - ) as rzx_theta_native: - for cr_tone, comp_tone in zip(cr_tones, comp_tones): - with builder.align_left(): - self.rescale_cr_inst(cr_tone, theta) - self.rescale_cr_inst(comp_tone, theta) - builder.call(xgate) + with warnings.catch_warnings(action='ignore', category=DeprecationWarning): + # `InstructionScheduleMap.get` and the pulse builder emit deprecation warnings + # as they use classes and methods which are deprecated in Qiskit 1.3 as part of the + # Qiskit Pulse deprecation + xgate = self._inst_map.get("x", qubits[0]) + with builder.build( + default_alignment="sequential", name=f"rzx({theta:.3f})" + ) as rzx_theta_native: + for cr_tone, comp_tone in zip(cr_tones, comp_tones): + with builder.align_left(): + self.rescale_cr_inst(cr_tone, theta) + self.rescale_cr_inst(comp_tone, theta) + builder.call(xgate) return rzx_theta_native # The direction is not native. Add Hadamard gates to flip the direction. @@ -299,11 +303,14 @@ def get_calibration(self, node_op: CircuitInst, qubits: list) -> Schedule | Sche # RZXCalibrationNoEcho only good for forward CR direction if cal_type in [CRCalType.ECR_CX_FORWARD, CRCalType.ECR_FORWARD]: - with builder.build(default_alignment="left", name=f"rzx({theta:.3f})") as rzx_theta: - stretched_dur = self.rescale_cr_inst(cr_tones[0], 2 * theta) - self.rescale_cr_inst(comp_tones[0], 2 * theta) - # Placeholder to make pulse gate work - builder.delay(stretched_dur, DriveChannel(qubits[0])) + with warnings.catch_warnings(action='ignore', category=DeprecationWarning): + # Pulse builder emits deprecation warnings as part of the + # Qiskit Pulse deprecation + with builder.build(default_alignment="left", name=f"rzx({theta:.3f})") as rzx_theta: + stretched_dur = self.rescale_cr_inst(cr_tones[0], 2 * theta) + self.rescale_cr_inst(comp_tones[0], 2 * theta) + # Placeholder to make pulse gate work + builder.delay(stretched_dur, DriveChannel(qubits[0])) return rzx_theta raise QiskitError("RZXCalibrationBuilderNoEcho only supports hardware-native RZX gates.") @@ -349,22 +356,26 @@ def _check_calibration_type( QiskitError: Unknown calibration type is detected. """ cal_type = None - if inst_sched_map.has("cx", qubits): - cr_sched = inst_sched_map.get("cx", qubits=qubits) - elif inst_sched_map.has("ecr", qubits): - cr_sched = inst_sched_map.get("ecr", qubits=qubits) - cal_type = CRCalType.ECR_FORWARD - elif inst_sched_map.has("ecr", tuple(reversed(qubits))): - cr_sched = inst_sched_map.get("ecr", tuple(reversed(qubits))) - cal_type = CRCalType.ECR_REVERSE - else: - raise QiskitError( - f"Native direction cannot be determined: operation on qubits {qubits} " - f"for the following instruction schedule map:\n{inst_sched_map}" - ) + with warnings.catch_warnings(action='ignore', category=DeprecationWarning): + # `InstructionScheduleMap.get` and `filter_instructions` emit deprecation warnings + # as they use classes and methods which are deprecated in Qiskit 1.3 as part of the + # Qiskit Pulse deprecation + if inst_sched_map.has("cx", qubits): + cr_sched = inst_sched_map.get("cx", qubits=qubits) + elif inst_sched_map.has("ecr", qubits): + cr_sched = inst_sched_map.get("ecr", qubits=qubits) + cal_type = CRCalType.ECR_FORWARD + elif inst_sched_map.has("ecr", tuple(reversed(qubits))): + cr_sched = inst_sched_map.get("ecr", tuple(reversed(qubits))) + cal_type = CRCalType.ECR_REVERSE + else: + raise QiskitError( + f"Native direction cannot be determined: operation on qubits {qubits} " + f"for the following instruction schedule map:\n{inst_sched_map}" + ) - cr_tones = [t[1] for t in filter_instructions(cr_sched, [_filter_cr_tone]).instructions] - comp_tones = [t[1] for t in filter_instructions(cr_sched, [_filter_comp_tone]).instructions] + cr_tones = [t[1] for t in filter_instructions(cr_sched, [_filter_cr_tone]).instructions] + comp_tones = [t[1] for t in filter_instructions(cr_sched, [_filter_comp_tone]).instructions] if cal_type is None: if len(comp_tones) == 0: diff --git a/qiskit/transpiler/passes/scheduling/alignments/check_durations.py b/qiskit/transpiler/passes/scheduling/alignments/check_durations.py index 46fdb1f5160b..3edfdf7ec741 100644 --- a/qiskit/transpiler/passes/scheduling/alignments/check_durations.py +++ b/qiskit/transpiler/passes/scheduling/alignments/check_durations.py @@ -70,7 +70,7 @@ def run(self, dag: DAGCircuit): return # Check custom gate durations - for inst_defs in dag.calibrations.values(): + for inst_defs in dag._calibrations_prop.values(): for caldef in inst_defs.values(): dur = caldef.duration if not (dur % self.acquire_align == 0 and dur % self.pulse_align == 0): diff --git a/qiskit/transpiler/passes/scheduling/dynamical_decoupling.py b/qiskit/transpiler/passes/scheduling/dynamical_decoupling.py index a4695c24439c..29c49c897e3e 100644 --- a/qiskit/transpiler/passes/scheduling/dynamical_decoupling.py +++ b/qiskit/transpiler/passes/scheduling/dynamical_decoupling.py @@ -13,6 +13,7 @@ """Dynamical Decoupling insertion pass.""" import itertools +import warnings import numpy as np from qiskit.circuit import Gate, Delay, Reset @@ -288,12 +289,15 @@ def _update_inst_durations(self, dag): """ circ_durations = InstructionDurations() - if dag.calibrations: + if dag._calibrations_prop: cal_durations = [] - for gate, gate_cals in dag.calibrations.items(): - for (qubits, parameters), schedule in gate_cals.items(): - cal_durations.append((gate, qubits, parameters, schedule.duration)) - circ_durations.update(cal_durations, circ_durations.dt) + with warnings.catch_warnings(action='ignore', category=DeprecationWarning): + # `schedule.duration` emits pulse deprecation warnings which we don't want + # to see here + for gate, gate_cals in dag._calibrations_prop.items(): + for (qubits, parameters), schedule in gate_cals.items(): + cal_durations.append((gate, qubits, parameters, schedule.duration)) + circ_durations.update(cal_durations, circ_durations.dt) if self._durations is not None: circ_durations.update(self._durations, getattr(self._durations, "dt", None)) diff --git a/qiskit/transpiler/passes/scheduling/padding/dynamical_decoupling.py b/qiskit/transpiler/passes/scheduling/padding/dynamical_decoupling.py index 9f001ea86ee9..ea917f3975a7 100644 --- a/qiskit/transpiler/passes/scheduling/padding/dynamical_decoupling.py +++ b/qiskit/transpiler/passes/scheduling/padding/dynamical_decoupling.py @@ -14,6 +14,7 @@ from __future__ import annotations import logging +import warnings import numpy as np from qiskit.circuit import Gate, ParameterExpression, Qubit @@ -189,9 +190,12 @@ def _update_inst_durations(self, dag): if dag._calibrations_prop: cal_durations = [] - for gate, gate_cals in dag.calibrations.items(): - for (qubits, parameters), schedule in gate_cals.items(): - cal_durations.append((gate, qubits, parameters, schedule.duration)) + with warnings.catch_warnings(action='ignore', category=DeprecationWarning): + # `schedule.duration` emits pulse deprecation warnings which we don't want + # to see here + for gate, gate_cals in dag._calibrations_prop.items(): + for (qubits, parameters), schedule in gate_cals.items(): + cal_durations.append((gate, qubits, parameters, schedule.duration)) circ_durations.update(cal_durations, circ_durations.dt) if self._durations is not None: @@ -252,7 +256,12 @@ def _pre_runhook(self, dag: DAGCircuit): try: # Check calibration. params = self._resolve_params(gate) - gate_length = dag.calibrations[gate.name][((physical_index,), params)].duration + with warnings.catch_warnings(action='ignore', category=DeprecationWarning): + # `schedule.duration` emits pulse deprecation warnings which we don't want + # to see here + gate_length = dag._calibrations_prop[gate.name][ + ((physical_index,), params) + ].duration if gate_length % self._alignment != 0: # This is necessary to implement lightweight scheduling logic for this pass. # Usually the pulse alignment constraint and pulse data chunk size take diff --git a/qiskit/transpiler/passes/scheduling/scheduling/base_scheduler.py b/qiskit/transpiler/passes/scheduling/scheduling/base_scheduler.py index f1a67a92b60f..4e31cf560f5a 100644 --- a/qiskit/transpiler/passes/scheduling/scheduling/base_scheduler.py +++ b/qiskit/transpiler/passes/scheduling/scheduling/base_scheduler.py @@ -67,7 +67,10 @@ def _get_node_duration( if dag._has_calibration_for(node): # If node has calibration, this value should be the highest priority cal_key = tuple(indices), tuple(float(p) for p in node.op.params) - duration = dag.calibrations[node.op.name][cal_key].duration + with warnings.catch_warnings(action='ignore', category=DeprecationWarning): + # `schedule.duration` emits pulse deprecation warnings which we don't want + # to see here + duration = dag._calibrations_prop[node.op.name][cal_key].duration # Note that node duration is updated (but this is analysis pass) op = node.op.to_mutable() diff --git a/qiskit/transpiler/passes/scheduling/time_unit_conversion.py b/qiskit/transpiler/passes/scheduling/time_unit_conversion.py index eeb2768b5a5b..75518ba630c2 100644 --- a/qiskit/transpiler/passes/scheduling/time_unit_conversion.py +++ b/qiskit/transpiler/passes/scheduling/time_unit_conversion.py @@ -12,6 +12,7 @@ """Unify time unit in circuit for scheduling and following passes.""" from typing import Set +import warnings from qiskit.circuit import Delay from qiskit.dagcircuit import DAGCircuit @@ -123,9 +124,12 @@ def _update_inst_durations(self, dag): if dag._calibrations_prop: cal_durations = [] - for gate, gate_cals in dag.calibrations.items(): - for (qubits, parameters), schedule in gate_cals.items(): - cal_durations.append((gate, qubits, parameters, schedule.duration)) + with warnings.catch_warnings(action='ignore', category=DeprecationWarning): + # `schedule.duration` emits pulse deprecation warnings which we don't want + # to see here + for gate, gate_cals in dag._calibrations_prop.items(): + for (qubits, parameters), schedule in gate_cals.items(): + cal_durations.append((gate, qubits, parameters, schedule.duration)) circ_durations.update(cal_durations, circ_durations.dt) if self._durations_provided: diff --git a/qiskit/transpiler/preset_passmanagers/builtin_plugins.py b/qiskit/transpiler/preset_passmanagers/builtin_plugins.py index 68e266a09e70..459de0bf01ab 100644 --- a/qiskit/transpiler/preset_passmanagers/builtin_plugins.py +++ b/qiskit/transpiler/preset_passmanagers/builtin_plugins.py @@ -13,6 +13,7 @@ """Built-in transpiler stage plugins for preset pass managers.""" import os +import warnings from qiskit.transpiler.passes.optimization.split_2q_unitaries import Split2QUnitaries from qiskit.transpiler.passmanager import PassManager @@ -676,9 +677,12 @@ def pass_manager(self, pass_manager_config, optimization_level=None) -> PassMana inst_map = pass_manager_config.inst_map target = pass_manager_config.target - return common.generate_scheduling( - instruction_durations, scheduling_method, timing_constraints, inst_map, target - ) + with warnings.catch_warnings(action="ignore", category=DeprecationWarning): + # Passing `inst_map` to `generate_scheduling` is deprecated in Qiskit 1.3 + # so filtering these warning when building pass managers + return common.generate_scheduling( + instruction_durations, scheduling_method, timing_constraints, inst_map, target + ) class AsapSchedulingPassManager(PassManagerStagePlugin): @@ -693,9 +697,12 @@ def pass_manager(self, pass_manager_config, optimization_level=None) -> PassMana inst_map = pass_manager_config.inst_map target = pass_manager_config.target - return common.generate_scheduling( - instruction_durations, scheduling_method, timing_constraints, inst_map, target - ) + with warnings.catch_warnings(action="ignore", category=DeprecationWarning): + # Passing `inst_map` to `generate_scheduling` is deprecated in Qiskit 1.3 + # so filtering these warning when building pass managers + return common.generate_scheduling( + instruction_durations, scheduling_method, timing_constraints, inst_map, target + ) class DefaultSchedulingPassManager(PassManagerStagePlugin): @@ -710,9 +717,12 @@ def pass_manager(self, pass_manager_config, optimization_level=None) -> PassMana inst_map = pass_manager_config.inst_map target = pass_manager_config.target - return common.generate_scheduling( - instruction_durations, scheduling_method, timing_constraints, inst_map, target - ) + with warnings.catch_warnings(action="ignore", category=DeprecationWarning): + # Passing `inst_map` to `generate_scheduling` is deprecated in Qiskit 1.3 + # so filtering these warning when building pass managers + return common.generate_scheduling( + instruction_durations, scheduling_method, timing_constraints, inst_map, target + ) class DefaultLayoutPassManager(PassManagerStagePlugin): From 9a426790f28d15244d274f496ea9b89fc7133b3e Mon Sep 17 00:00:00 2001 From: Eli Arbel Date: Mon, 14 Oct 2024 18:47:23 +0300 Subject: [PATCH 17/23] Misc changes to pulse deprecation functions and release notes --- qiskit/utils/deprecate_pulse.py | 32 ++++++++++++++++++- ...recate-pulse-package-07a621be1db7fa30.yaml | 8 ++--- 2 files changed, 35 insertions(+), 5 deletions(-) diff --git a/qiskit/utils/deprecate_pulse.py b/qiskit/utils/deprecate_pulse.py index 71d70c1039d9..adac7bdb1167 100644 --- a/qiskit/utils/deprecate_pulse.py +++ b/qiskit/utils/deprecate_pulse.py @@ -14,6 +14,9 @@ Deprecation functions for Qiskit Pulse. To be removed in Qiskit 2.0. """ +import warnings +import functools + from qiskit.utils.deprecation import deprecate_func, deprecate_arg @@ -31,7 +34,6 @@ def deprecate_pulse_func(func): def deprecate_pulse_dependency(*args, **kwargs): """Deprecation message for functions and classes which use or depend on Pulse""" - decorator = deprecate_func( since="1.3", package_name="Qiskit", @@ -59,3 +61,31 @@ def deprecate_pulse_arg(arg_name, **kwargs): "and this argument uses a dependency on the package.", **kwargs, ) + + +def ignore_pulse_deprecation_warnings(func): + """Ignore deprecation warnings emitted from the pulse package""" + + @functools.wraps(func) + def wrapper(*args, **kwargs): + with warnings.catch_warnings(): + warnings.filterwarnings( + "ignore", category=DeprecationWarning, + message="The (.*) ``qiskit.pulse" + ) + return func(*args, **kwargs) + + return wrapper + + +def decorate_test_methods(decorator): + """Put a given decorator on all the decorated class methods whose name starts with `test_`""" + + def cls_wrapper(cls): + for attr in dir(cls): + if attr.startswith("test_") and callable(object.__getattribute__(cls, attr)): + setattr(cls, attr, decorator(object.__getattribute__(cls, attr))) + + return cls + + return cls_wrapper diff --git a/releasenotes/notes/deprecate-pulse-package-07a621be1db7fa30.yaml b/releasenotes/notes/deprecate-pulse-package-07a621be1db7fa30.yaml index 094106c2372c..26ff3c1f5a89 100644 --- a/releasenotes/notes/deprecate-pulse-package-07a621be1db7fa30.yaml +++ b/releasenotes/notes/deprecate-pulse-package-07a621be1db7fa30.yaml @@ -1,10 +1,10 @@ --- -deprecations_pulse: +deprecations: - | The Qiskit Pulse package is being deprecated and will be removed in Qiskit version 2.0.0. Pulse-level - access is currently supported on a subset of Eagle devices but not on the latest Heron architecture - ones. Going forward, newer IBM Quantum architectures will not support pulse-level access as well. As a - consequence, supporting Pulse as a first-class citizen frontend in the Qiskit SDK itself makes little + access is currently supported only on a subset of Eagle devices and not supported on the Heron architecture + ones. Furthermore, newer IBM Quantum architectures will not support pulse-level access as well. + As a consequence, supporting Pulse as a first-class citizen frontend in the Qiskit SDK itself makes little sense going forward. The deprecation includes all pulse code in :mod:`qiskit.pulse` as well as functionality dependant or related to pulse such as pulse visualization, serialization and custom calibration support. For more details see the deprecation sections. From 3b2f8a3faea7ce0b36392a0731418148ec382b1c Mon Sep 17 00:00:00 2001 From: Eli Arbel Date: Mon, 14 Oct 2024 23:02:22 +0300 Subject: [PATCH 18/23] Fix lint issues --- qiskit/circuit/quantumcircuit.py | 12 ++--- qiskit/converters/dagdependency_to_circuit.py | 3 +- qiskit/dagcircuit/dagdependency.py | 6 +-- .../fake_provider/fake_pulse_backend.py | 2 +- .../fake_provider/generic_backend_v2.py | 4 +- qiskit/pulse/calibration_entries.py | 2 +- qiskit/pulse/instruction_schedule_map.py | 2 +- qiskit/qpy/interface.py | 2 +- .../passes/calibration/rx_builder.py | 4 +- .../passes/calibration/rzx_builder.py | 6 +-- .../passes/scheduling/dynamical_decoupling.py | 4 +- .../padding/dynamical_decoupling.py | 4 +- .../scheduling/scheduling/base_scheduler.py | 2 +- .../passes/scheduling/time_unit_conversion.py | 2 +- qiskit/transpiler/target.py | 2 +- qiskit/utils/deprecate_pulse.py | 3 +- ...recate-pulse-package-07a621be1db7fa30.yaml | 54 ++++++++++--------- .../circuit/test_circuit_load_from_qpy.py | 4 +- test/python/compiler/test_assembler.py | 3 +- test/python/primitives/test_primitive.py | 4 +- test/python/qpy/test_block_load_from_qpy.py | 39 +++++++++++--- .../transpiler/test_calibrationbuilder.py | 4 +- .../python/transpiler/test_pulse_gate_pass.py | 2 +- test/python/transpiler/test_target.py | 3 +- 24 files changed, 100 insertions(+), 73 deletions(-) diff --git a/qiskit/circuit/quantumcircuit.py b/qiskit/circuit/quantumcircuit.py index 379de4c82faa..a3f55e112ba0 100644 --- a/qiskit/circuit/quantumcircuit.py +++ b/qiskit/circuit/quantumcircuit.py @@ -1363,14 +1363,14 @@ def calibrations(self, calibrations: dict): @property def _calibrations_prop(self) -> dict: - """An alternative private path to the `calibrations` property for avoiding deprecation warnings. - """ + """An alternative private path to the `calibrations` property for + avoiding deprecation warnings.""" return dict(self._calibrations) @_calibrations_prop.setter def _calibrations_prop(self, calibrations: dict): - """An alternative private path to the `calibrations` property for avoiding deprecation warnings. - """ + """An alternative private path to the `calibrations` property for + avoiding deprecation warnings.""" self._calibrations = defaultdict(dict, calibrations) @deprecate_pulse_dependency @@ -1382,8 +1382,8 @@ def has_calibration_for(self, instruction: CircuitInstruction | tuple): return self._has_calibration_for(instruction) def _has_calibration_for(self, instruction: CircuitInstruction | tuple): - """An alternative private path to the `has_calibration_for` method for avoiding deprecation warnings. - """ + """An alternative private path to the `has_calibration_for` method for + avoiding deprecation warnings.""" if isinstance(instruction, CircuitInstruction): operation = instruction.operation qubits = instruction.qubits diff --git a/qiskit/converters/dagdependency_to_circuit.py b/qiskit/converters/dagdependency_to_circuit.py index 29d2ac45838b..541207d175d2 100644 --- a/qiskit/converters/dagdependency_to_circuit.py +++ b/qiskit/converters/dagdependency_to_circuit.py @@ -12,7 +12,6 @@ """Helper function for converting a dag dependency to a circuit""" from qiskit.circuit import QuantumCircuit, CircuitInstruction -from qiskit.dagcircuit.dagdependency import DAGDependency def dagdependency_to_circuit(dagdependency): @@ -35,7 +34,7 @@ def dagdependency_to_circuit(dagdependency): ) circuit.metadata = dagdependency.metadata - if isinstance(dagdependency, DAGDependency): + if hasattr(dagdependency, "_calibrations_prop"): circuit._calibrations_prop = dagdependency._calibrations_prop else: # This can be _DAGDependencyV2 diff --git a/qiskit/dagcircuit/dagdependency.py b/qiskit/dagcircuit/dagdependency.py index 876cfd3c8017..c4b6a05720e8 100644 --- a/qiskit/dagcircuit/dagdependency.py +++ b/qiskit/dagcircuit/dagdependency.py @@ -169,14 +169,12 @@ def calibrations(self, calibrations: dict[str, dict[tuple, Schedule]]): @property def _calibrations_prop(self) -> dict[str, dict[tuple, Schedule]]: - """An alternative path to be used internally to avoid deprecation warnings - """ + """An alternative path to be used internally to avoid deprecation warnings""" return dict(self._calibrations) @_calibrations_prop.setter def _calibrations_prop(self, calibrations: dict[str, dict[tuple, Schedule]]): - """An alternative path to be used internally to avoid deprecation warnings - """ + """An alternative path to be used internally to avoid deprecation warnings""" self._calibrations = defaultdict(dict, calibrations) def to_retworkx(self): diff --git a/qiskit/providers/fake_provider/fake_pulse_backend.py b/qiskit/providers/fake_provider/fake_pulse_backend.py index 5bffeb473771..563c8e1fe322 100644 --- a/qiskit/providers/fake_provider/fake_pulse_backend.py +++ b/qiskit/providers/fake_provider/fake_pulse_backend.py @@ -32,7 +32,7 @@ class FakePulseBackend(FakeQasmBackend): def defaults(self): """Returns a snapshot of device defaults""" if not self._defaults: - with warnings.catch_warnings(action='ignore', category=DeprecationWarning): + with warnings.catch_warnings(action="ignore", category=DeprecationWarning): # Filter deprecation warnings emitted from Qiskit Pulse self._set_defaults_from_json() return self._defaults diff --git a/qiskit/providers/fake_provider/generic_backend_v2.py b/qiskit/providers/fake_provider/generic_backend_v2.py index 533238a188c2..883b37b065d2 100644 --- a/qiskit/providers/fake_provider/generic_backend_v2.py +++ b/qiskit/providers/fake_provider/generic_backend_v2.py @@ -651,7 +651,7 @@ def meas_map(self) -> list[list[int]]: return self._target.concurrent_measurements def _build_default_channels(self) -> None: - with warnings.catch_warnings(action='ignore', category=DeprecationWarning): + with warnings.catch_warnings(action="ignore", category=DeprecationWarning): # Prevent pulse deprecation warnings from being emitted channels_map = { "acquire": {(i,): [pulse.AcquireChannel(i)] for i in range(self.num_qubits)}, @@ -877,7 +877,7 @@ def _add_noisy_instruction_to_target( self._rng.uniform(*noise_params[2:]), ) ) - with warnings.catch_warnings(action='ignore', category=DeprecationWarning): + with warnings.catch_warnings(action="ignore", category=DeprecationWarning): # Prevent pulse deprecations from being emitted if ( calibration_inst_map is not None diff --git a/qiskit/pulse/calibration_entries.py b/qiskit/pulse/calibration_entries.py index f2774bdc8474..318bc78009ea 100644 --- a/qiskit/pulse/calibration_entries.py +++ b/qiskit/pulse/calibration_entries.py @@ -321,7 +321,7 @@ def __init__( def _build_schedule(self): """Build pulse schedule from cmd-def sequence.""" - with warnings.catch_warnings(action='ignore', category=DeprecationWarning): + with warnings.catch_warnings(action="ignore", category=DeprecationWarning): # `Schedule` is being deprecated in Qiskit 1.3 schedule = Schedule(name=self._name) try: diff --git a/qiskit/pulse/instruction_schedule_map.py b/qiskit/pulse/instruction_schedule_map.py index 4a038d0d7190..e3a1c62e7ffe 100644 --- a/qiskit/pulse/instruction_schedule_map.py +++ b/qiskit/pulse/instruction_schedule_map.py @@ -356,7 +356,7 @@ def get_parameters( instruction = _get_instruction_string(instruction) self.assert_has(instruction, qubits) - with warnings.catch_warnings(action='ignore', category=DeprecationWarning): + with warnings.catch_warnings(action="ignore", category=DeprecationWarning): # Prevent `get_signature` from emitting pulse package deprecation warnings signature = self._map[instruction][_to_tuple(qubits)].get_signature() return tuple(signature.parameters.keys()) diff --git a/qiskit/qpy/interface.py b/qiskit/qpy/interface.py index b5abd2ea9b6b..688064625fb7 100644 --- a/qiskit/qpy/interface.py +++ b/qiskit/qpy/interface.py @@ -353,7 +353,7 @@ def load( message="Pulse gates deserialization is deprecated as of Qiskit 1.3 and " "will be removed in Qiskit 2.0. This is part of the deprecation plan for " "the entire Qiskit Pulse package. Once Pulse is removed, `ScheduleBlock` " - "sections will be ignored when loading QPY files with pulse data." + "sections will be ignored when loading QPY files with pulse data.", ) else: diff --git a/qiskit/transpiler/passes/calibration/rx_builder.py b/qiskit/transpiler/passes/calibration/rx_builder.py index 0d263669d316..8543badc1289 100644 --- a/qiskit/transpiler/passes/calibration/rx_builder.py +++ b/qiskit/transpiler/passes/calibration/rx_builder.py @@ -107,7 +107,9 @@ def supported(self, node_op: Instruction, qubits: list) -> bool: self.target._get_calibration("sx", tuple(qubits)).instructions[0][1].pulse, ScalableSymbolicPulse, ) - and self.target._get_calibration("sx", tuple(qubits)).instructions[0][1].pulse.pulse_type + and self.target._get_calibration("sx", tuple(qubits)) + .instructions[0][1] + .pulse.pulse_type == "Drag" ) diff --git a/qiskit/transpiler/passes/calibration/rzx_builder.py b/qiskit/transpiler/passes/calibration/rzx_builder.py index a5651f2acf20..3e9c90ca1ded 100644 --- a/qiskit/transpiler/passes/calibration/rzx_builder.py +++ b/qiskit/transpiler/passes/calibration/rzx_builder.py @@ -204,7 +204,7 @@ def get_calibration(self, node_op: CircuitInst, qubits: list) -> Schedule | Sche # The CR instruction is in the forward (native) direction if cal_type in [CRCalType.ECR_CX_FORWARD, CRCalType.ECR_FORWARD]: - with warnings.catch_warnings(action='ignore', category=DeprecationWarning): + with warnings.catch_warnings(action="ignore", category=DeprecationWarning): # `InstructionScheduleMap.get` and the pulse builder emit deprecation warnings # as they use classes and methods which are deprecated in Qiskit 1.3 as part of the # Qiskit Pulse deprecation @@ -303,7 +303,7 @@ def get_calibration(self, node_op: CircuitInst, qubits: list) -> Schedule | Sche # RZXCalibrationNoEcho only good for forward CR direction if cal_type in [CRCalType.ECR_CX_FORWARD, CRCalType.ECR_FORWARD]: - with warnings.catch_warnings(action='ignore', category=DeprecationWarning): + with warnings.catch_warnings(action="ignore", category=DeprecationWarning): # Pulse builder emits deprecation warnings as part of the # Qiskit Pulse deprecation with builder.build(default_alignment="left", name=f"rzx({theta:.3f})") as rzx_theta: @@ -356,7 +356,7 @@ def _check_calibration_type( QiskitError: Unknown calibration type is detected. """ cal_type = None - with warnings.catch_warnings(action='ignore', category=DeprecationWarning): + with warnings.catch_warnings(action="ignore", category=DeprecationWarning): # `InstructionScheduleMap.get` and `filter_instructions` emit deprecation warnings # as they use classes and methods which are deprecated in Qiskit 1.3 as part of the # Qiskit Pulse deprecation diff --git a/qiskit/transpiler/passes/scheduling/dynamical_decoupling.py b/qiskit/transpiler/passes/scheduling/dynamical_decoupling.py index 29c49c897e3e..45b86894e29a 100644 --- a/qiskit/transpiler/passes/scheduling/dynamical_decoupling.py +++ b/qiskit/transpiler/passes/scheduling/dynamical_decoupling.py @@ -291,13 +291,13 @@ def _update_inst_durations(self, dag): if dag._calibrations_prop: cal_durations = [] - with warnings.catch_warnings(action='ignore', category=DeprecationWarning): + with warnings.catch_warnings(action="ignore", category=DeprecationWarning): # `schedule.duration` emits pulse deprecation warnings which we don't want # to see here for gate, gate_cals in dag._calibrations_prop.items(): for (qubits, parameters), schedule in gate_cals.items(): cal_durations.append((gate, qubits, parameters, schedule.duration)) - circ_durations.update(cal_durations, circ_durations.dt) + circ_durations.update(cal_durations, circ_durations.dt) if self._durations is not None: circ_durations.update(self._durations, getattr(self._durations, "dt", None)) diff --git a/qiskit/transpiler/passes/scheduling/padding/dynamical_decoupling.py b/qiskit/transpiler/passes/scheduling/padding/dynamical_decoupling.py index ea917f3975a7..996445804bc0 100644 --- a/qiskit/transpiler/passes/scheduling/padding/dynamical_decoupling.py +++ b/qiskit/transpiler/passes/scheduling/padding/dynamical_decoupling.py @@ -190,7 +190,7 @@ def _update_inst_durations(self, dag): if dag._calibrations_prop: cal_durations = [] - with warnings.catch_warnings(action='ignore', category=DeprecationWarning): + with warnings.catch_warnings(action="ignore", category=DeprecationWarning): # `schedule.duration` emits pulse deprecation warnings which we don't want # to see here for gate, gate_cals in dag._calibrations_prop.items(): @@ -256,7 +256,7 @@ def _pre_runhook(self, dag: DAGCircuit): try: # Check calibration. params = self._resolve_params(gate) - with warnings.catch_warnings(action='ignore', category=DeprecationWarning): + with warnings.catch_warnings(action="ignore", category=DeprecationWarning): # `schedule.duration` emits pulse deprecation warnings which we don't want # to see here gate_length = dag._calibrations_prop[gate.name][ diff --git a/qiskit/transpiler/passes/scheduling/scheduling/base_scheduler.py b/qiskit/transpiler/passes/scheduling/scheduling/base_scheduler.py index 4e31cf560f5a..3b10fac04256 100644 --- a/qiskit/transpiler/passes/scheduling/scheduling/base_scheduler.py +++ b/qiskit/transpiler/passes/scheduling/scheduling/base_scheduler.py @@ -67,7 +67,7 @@ def _get_node_duration( if dag._has_calibration_for(node): # If node has calibration, this value should be the highest priority cal_key = tuple(indices), tuple(float(p) for p in node.op.params) - with warnings.catch_warnings(action='ignore', category=DeprecationWarning): + with warnings.catch_warnings(action="ignore", category=DeprecationWarning): # `schedule.duration` emits pulse deprecation warnings which we don't want # to see here duration = dag._calibrations_prop[node.op.name][cal_key].duration diff --git a/qiskit/transpiler/passes/scheduling/time_unit_conversion.py b/qiskit/transpiler/passes/scheduling/time_unit_conversion.py index 75518ba630c2..1f7d72134168 100644 --- a/qiskit/transpiler/passes/scheduling/time_unit_conversion.py +++ b/qiskit/transpiler/passes/scheduling/time_unit_conversion.py @@ -124,7 +124,7 @@ def _update_inst_durations(self, dag): if dag._calibrations_prop: cal_durations = [] - with warnings.catch_warnings(action='ignore', category=DeprecationWarning): + with warnings.catch_warnings(action="ignore", category=DeprecationWarning): # `schedule.duration` emits pulse deprecation warnings which we don't want # to see here for gate, gate_cals in dag._calibrations_prop.items(): diff --git a/qiskit/transpiler/target.py b/qiskit/transpiler/target.py index 4ab5a0fd4b0e..1e5f9960bd35 100644 --- a/qiskit/transpiler/target.py +++ b/qiskit/transpiler/target.py @@ -633,7 +633,7 @@ def instruction_schedule_map(self): def _get_instruction_schedule_map(self): if self._instruction_schedule_map is not None: return self._instruction_schedule_map - with warnings.catch_warnings(action='ignore', category=DeprecationWarning): + with warnings.catch_warnings(action="ignore", category=DeprecationWarning): # `InstructionScheduleMap` is deprecated in Qiskit 1.3 but we want this alternative # path to be clean of deprecation warnings out_inst_schedule_map = InstructionScheduleMap() diff --git a/qiskit/utils/deprecate_pulse.py b/qiskit/utils/deprecate_pulse.py index adac7bdb1167..86e577fd5dd8 100644 --- a/qiskit/utils/deprecate_pulse.py +++ b/qiskit/utils/deprecate_pulse.py @@ -70,8 +70,7 @@ def ignore_pulse_deprecation_warnings(func): def wrapper(*args, **kwargs): with warnings.catch_warnings(): warnings.filterwarnings( - "ignore", category=DeprecationWarning, - message="The (.*) ``qiskit.pulse" + "ignore", category=DeprecationWarning, message="The (.*) ``qiskit.pulse" ) return func(*args, **kwargs) diff --git a/releasenotes/notes/deprecate-pulse-package-07a621be1db7fa30.yaml b/releasenotes/notes/deprecate-pulse-package-07a621be1db7fa30.yaml index 26ff3c1f5a89..b14a0e1767bb 100644 --- a/releasenotes/notes/deprecate-pulse-package-07a621be1db7fa30.yaml +++ b/releasenotes/notes/deprecate-pulse-package-07a621be1db7fa30.yaml @@ -29,43 +29,48 @@ deprecations_qpy: the :func:`qiskit.qpy.dump` function is being deprecated. deprecations_transpiler: - | - As part of the Qiskit Pulse package deprecation, pulse-related aspects in the :class:`qiskit.transpiler.Target` class are - being deprecated. These include: - * :attr:`qiskit.transpiler.Target.calibration` - * :meth:`qiskit.transpiler.Target.update_from_instruction_schedule_map` - * :meth:`qiskit.transpiler.Target.has_calibration` - * :meth:`qiskit.transpiler.Target.get_calibration` - * :meth:`qiskit.transpiler.Target.instruction_schedule_map` + As part of the Qiskit Pulse package deprecation, pulse-related aspects in the :class:`qiskit.transpiler.Target` class are being deprecated. These include: + * :attr:`~qiskit.transpiler.Target.calibration` + * :meth:`~qiskit.transpiler.Target.update_from_instruction_schedule_map` + * :meth:`~qiskit.transpiler.Target.has_calibration` + * :meth:`~qiskit.transpiler.Target.get_calibration` + * :meth:`~qiskit.transpiler.Target.instruction_schedule_map` In addition the following transpiler passer are also being deprecated: - * :class:`qiskit.transpiler.passes.PulseGates` - * :class:`qiskit.transpiler.passes.ValidatePulseGates` - * :class:`qiskit.transpiler.passes.RXCalibrationBuilder` - * :class:`qiskit.transpiler.passes.RZXCalibrationBuilder` - - Finally, the ability to generate a preset pass manager using custom calibrations by sending an object of - type :class:`qiskit.pulse.instruction_schedule_map.InstructionScheduleMap` to - :func:`qiskit.transpiler.generate_preset_pass_manager` is being deprecated as well. + * :class:`~qiskit.transpiler.passes.PulseGates` + * :class:`~qiskit.transpiler.passes.ValidatePulseGates` + * :class:`~qiskit.transpiler.passes.RXCalibrationBuilder` + * :class:`~qiskit.transpiler.passes.RZXCalibrationBuilder` + - | + The `inst_map` argument in :func:`~qiskit.transpiler.generate_preset_pass_manager`, + :meth:`~transpiler.target.Target.from_configuration` and :func:`~qiskit.transpiler.preset_passmanagers.common.generate_scheduling` + is being deprecated. + - | + The `calibration` argument in :func:`~qiskit.transpiler.target.InstructionProperties` initializer methods is being + deprecated. deprecations_visualization: - | As part of the Qiskit Pulse package deprecation, pulse drawing via :meth:`qiskit.visualization.pulse_drawer` is being deprecated. deprecations_providers: - | - As part of the Qiskit Pulse package deprecation, all pulse-related functionality in :class:`qiskit.providers.BackendV2` class - is being deprecated. This includes the following methods: - * :meth:`qiskit.providers.BackendV2.instruction_schedule_map` - * :meth:`qiskit.providers.BackendV2.drive_channel` - * :meth:`qiskit.providers.BackendV2.measure_channel` - * :meth:`qiskit.providers.BackendV2.acquire_channel` - * :meth:`qiskit.providers.BackendV2.control_channel` + As part of the Qiskit Pulse package deprecation, all pulse-related functionality in :class:`qiskit.providers.BackendV2` class is being deprecated. This includes the following methods: + * :meth:`~qiskit.providers.BackendV2.instruction_schedule_map` + * :meth:`~qiskit.providers.BackendV2.drive_channel` + * :meth:`~qiskit.providers.BackendV2.measure_channel` + * :meth:`~qiskit.providers.BackendV2.acquire_channel` + * :meth:`~qiskit.providers.BackendV2.control_channel` Consequently, the corresponding channel methods in the :class:`qiskit.providers.BackendV2Converter` and :class:`qiskit.providers.fake_provider.GenericBackendV2` classes are being deprecated as well. + + In addition, the `pulse_channels` and `calibrate_instructions` arguments in the :class:`~qiskit.providers.BackendV2` + initializer method are being deprecated. + - | + The `defaults` argument is being deprecated from the :func:`qiskit.providers.backend_compat.convert_to_target` function. deprecations_misc: - | - As part of the Qiskit Pulse package deprecation, the following functions and class are being - deprecated as well: + As part of the Qiskit Pulse package deprecation, the following functions and class are being deprecated as well: * :meth:`qiskit.compiler.schedule` * :meth:`qiskit.compiler.sequence` * :meth:`qiskit.assembler.assemble_schedules` @@ -73,4 +78,3 @@ deprecations_misc: * :meth:`qiskit.scheduler.methods.as_late_as_possible` * :meth:`qiskit.scheduler.schedule_circuit.schedule_circuit` * :class:`qiskit.scheduler.ScheduleConfig` - diff --git a/test/python/circuit/test_circuit_load_from_qpy.py b/test/python/circuit/test_circuit_load_from_qpy.py index b9fdd2a10910..0a0a25034240 100644 --- a/test/python/circuit/test_circuit_load_from_qpy.py +++ b/test/python/circuit/test_circuit_load_from_qpy.py @@ -56,6 +56,7 @@ from qiskit.circuit.instruction import Instruction from qiskit.circuit.parameter import Parameter from qiskit.circuit.parametervector import ParameterVector +from qiskit.qpy.exceptions import QPYLoadingDeprecatedFeatureWarning from qiskit.synthesis import LieTrotter, SuzukiTrotter from qiskit.qpy import dump, load, UnsupportedFeatureForVersion, QPY_COMPATIBILITY_VERSION from qiskit.quantum_info import Pauli, SparsePauliOp, Clifford @@ -355,8 +356,7 @@ def test_bound_calibration_parameter(self): # qpy.dump warns for deprecations of pulse gate serialization dump(qc, qpy_file) qpy_file.seek(0) - with self.assertWarns(DeprecationWarning): - new_circ = load(qpy_file)[0] + new_circ = load(qpy_file)[0] self.assertEqual(qc, new_circ) instruction = new_circ.data[0] cal_key = ( diff --git a/test/python/compiler/test_assembler.py b/test/python/compiler/test_assembler.py index 33b09bc71848..b384d8b9267f 100644 --- a/test/python/compiler/test_assembler.py +++ b/test/python/compiler/test_assembler.py @@ -1307,8 +1307,7 @@ def test_pulse_name_conflicts_in_other_schedule(self): """Test two pulses with the same name in different schedule can be resolved.""" with self.assertWarns(DeprecationWarning): backend = Fake27QPulseV1() - with self.assertWarns(DeprecationWarning): - defaults = backend.defaults() + defaults = backend.defaults() schedules = [] with self.assertWarns(DeprecationWarning): diff --git a/test/python/primitives/test_primitive.py b/test/python/primitives/test_primitive.py index 1e7d95819904..fc0118564f3d 100644 --- a/test/python/primitives/test_primitive.py +++ b/test/python/primitives/test_primitive.py @@ -138,7 +138,9 @@ def test_with_scheduling(n): with self.assertWarns(DeprecationWarning): custom_gate = pulse.Schedule(name="custom_x_gate") custom_gate.insert( - 0, pulse.Play(pulse.Constant(160 * n, 0.1), pulse.DriveChannel(0)), inplace=True + 0, + pulse.Play(pulse.Constant(160 * n, 0.1), pulse.DriveChannel(0)), + inplace=True, ) qc = QuantumCircuit(1) qc.x(0) diff --git a/test/python/qpy/test_block_load_from_qpy.py b/test/python/qpy/test_block_load_from_qpy.py index 9adc00dc72fc..a8897993ac32 100644 --- a/test/python/qpy/test_block_load_from_qpy.py +++ b/test/python/qpy/test_block_load_from_qpy.py @@ -14,6 +14,7 @@ import io import unittest +import warnings from ddt import ddt, data, unpack import numpy as np import symengine as sym @@ -38,6 +39,7 @@ from qiskit.pulse.instructions import Play, TimeBlockade from qiskit.circuit import Parameter, QuantumCircuit, Gate from qiskit.qpy import dump, load +from qiskit.qpy.exceptions import QPYLoadingDeprecatedFeatureWarning from qiskit.utils import optionals as _optional from qiskit.pulse.configuration import Kernel, Discriminator from test import QiskitTestCase # pylint: disable=wrong-import-order @@ -78,6 +80,7 @@ def test_library_pulse_play(self, envelope, channel, *params): envelope(*params), channel(0), ) + with self.assertWarns(QPYLoadingDeprecatedFeatureWarning): self.assert_roundtrip_equal(test_sched) def test_playing_custom_symbolic_pulse(self): @@ -96,6 +99,7 @@ def test_playing_custom_symbolic_pulse(self): ) with builder.build() as test_sched: builder.play(my_pulse, DriveChannel(0)) + with self.assertWarns(QPYLoadingDeprecatedFeatureWarning): self.assert_roundtrip_equal(test_sched) def test_symbolic_amplitude_limit(self): @@ -106,6 +110,7 @@ def test_symbolic_amplitude_limit(self): Gaussian(160, 20, 40, limit_amplitude=False), DriveChannel(0), ) + with self.assertWarns(QPYLoadingDeprecatedFeatureWarning): self.assert_roundtrip_equal(test_sched) def test_waveform_amplitude_limit(self): @@ -116,6 +121,7 @@ def test_waveform_amplitude_limit(self): Waveform([1, 2, 3, 4, 5], limit_amplitude=False), DriveChannel(0), ) + with self.assertWarns(QPYLoadingDeprecatedFeatureWarning): self.assert_roundtrip_equal(test_sched) def test_playing_waveform(self): @@ -126,6 +132,7 @@ def test_playing_waveform(self): with self.assertWarns(DeprecationWarning): with builder.build() as test_sched: builder.play(waveform, DriveChannel(0)) + with self.assertWarns(QPYLoadingDeprecatedFeatureWarning): self.assert_roundtrip_equal(test_sched) def test_phases(self): @@ -134,6 +141,7 @@ def test_phases(self): with builder.build() as test_sched: builder.shift_phase(0.1, DriveChannel(0)) builder.set_phase(0.4, DriveChannel(1)) + with self.assertWarns(QPYLoadingDeprecatedFeatureWarning): self.assert_roundtrip_equal(test_sched) def test_frequencies(self): @@ -142,6 +150,7 @@ def test_frequencies(self): with builder.build() as test_sched: builder.shift_frequency(10e6, DriveChannel(0)) builder.set_frequency(5e9, DriveChannel(1)) + with self.assertWarns(QPYLoadingDeprecatedFeatureWarning): self.assert_roundtrip_equal(test_sched) def test_delay(self): @@ -149,6 +158,7 @@ def test_delay(self): with self.assertWarns(DeprecationWarning): with builder.build() as test_sched: builder.delay(100, DriveChannel(0)) + with self.assertWarns(QPYLoadingDeprecatedFeatureWarning): self.assert_roundtrip_equal(test_sched) def test_barrier(self): @@ -156,6 +166,7 @@ def test_barrier(self): with self.assertWarns(DeprecationWarning): with builder.build() as test_sched: builder.barrier(DriveChannel(0), DriveChannel(1), ControlChannel(2)) + with self.assertWarns(QPYLoadingDeprecatedFeatureWarning): self.assert_roundtrip_equal(test_sched) def test_time_blockade(self): @@ -163,6 +174,7 @@ def test_time_blockade(self): with self.assertWarns(DeprecationWarning): with builder.build() as test_sched: builder.append_instruction(TimeBlockade(10, DriveChannel(0))) + with self.assertWarns(QPYLoadingDeprecatedFeatureWarning): self.assert_roundtrip_equal(test_sched) def test_measure(self): @@ -171,6 +183,7 @@ def test_measure(self): with builder.build() as test_sched: builder.acquire(100, AcquireChannel(0), MemorySlot(0)) builder.acquire(100, AcquireChannel(1), RegisterSlot(1)) + with self.assertWarns(QPYLoadingDeprecatedFeatureWarning): self.assert_roundtrip_equal(test_sched) @data( @@ -185,6 +198,7 @@ def test_parameterized(self, channel, *params): with self.assertWarns(DeprecationWarning): with builder.build() as test_sched: builder.play(Gaussian(*params), DriveChannel(channel)) + with self.assertWarns(QPYLoadingDeprecatedFeatureWarning): self.assert_roundtrip_equal(test_sched) def test_nested_blocks(self): @@ -201,6 +215,7 @@ def test_nested_blocks(self): with builder.align_sequential(): builder.delay(100, DriveChannel(0)) builder.delay(200, DriveChannel(1)) + with self.assertWarns(QPYLoadingDeprecatedFeatureWarning): self.assert_roundtrip_equal(test_sched) def test_called_schedule(self): @@ -216,6 +231,7 @@ def test_called_schedule(self): with builder.build() as test_sched: builder.call(refsched, name="test_ref") + with self.assertWarns(QPYLoadingDeprecatedFeatureWarning): self.assert_roundtrip_equal(test_sched) def test_unassigned_reference(self): @@ -225,7 +241,9 @@ def test_unassigned_reference(self): builder.reference("custom1", "q0") builder.reference("custom1", "q1") - self.assert_roundtrip_equal(test_sched) + with warnings.catch_warnings(action="ignore", category=DeprecationWarning): + with self.assertWarns(QPYLoadingDeprecatedFeatureWarning): + self.assert_roundtrip_equal(test_sched) def test_partly_assigned_reference(self): """Test schedule with partly assigned reference.""" @@ -242,8 +260,9 @@ def test_partly_assigned_reference(self): inplace=True, ) - with self.assertWarns(DeprecationWarning): - self.assert_roundtrip_equal(test_sched) + with warnings.catch_warnings(action="ignore", category=DeprecationWarning): + with self.assertWarns(QPYLoadingDeprecatedFeatureWarning): + self.assert_roundtrip_equal(test_sched) def test_nested_assigned_reference(self): """Test schedule with assigned reference for nested schedule.""" @@ -264,7 +283,7 @@ def test_nested_assigned_reference(self): inplace=True, ) - with self.assertWarns(DeprecationWarning): + with self.assertWarns(QPYLoadingDeprecatedFeatureWarning): self.assert_roundtrip_equal(test_sched) def test_bell_schedule(self): @@ -290,6 +309,7 @@ def test_bell_schedule(self): builder.play(GaussianSquare(8000, 0.2, 64, 7744), MeasureChannel(0)) builder.acquire(8000, AcquireChannel(0), MemorySlot(0)) + with self.assertWarns(QPYLoadingDeprecatedFeatureWarning): self.assert_roundtrip_equal(test_sched) @unittest.skipUnless(_optional.HAS_SYMENGINE, "Symengine required for this test") @@ -316,6 +336,7 @@ def test_bell_schedule_use_symengine(self): builder.play(GaussianSquare(8000, 0.2, 64, 7744), MeasureChannel(0)) builder.acquire(8000, AcquireChannel(0), MemorySlot(0)) + with self.assertWarns(QPYLoadingDeprecatedFeatureWarning): self.assert_roundtrip_equal(test_sched, True) def test_with_acquire_instruction_with_kernel(self): @@ -327,6 +348,7 @@ def test_with_acquire_instruction_with_kernel(self): with builder.build() as test_sched: builder.acquire(100, AcquireChannel(0), MemorySlot(0), kernel=kernel) + with self.assertWarns(QPYLoadingDeprecatedFeatureWarning): self.assert_roundtrip_equal(test_sched) def test_with_acquire_instruction_with_discriminator(self): @@ -338,6 +360,7 @@ def test_with_acquire_instruction_with_discriminator(self): with builder.build() as test_sched: builder.acquire(100, AcquireChannel(0), MemorySlot(0), discriminator=discriminator) + with self.assertWarns(QPYLoadingDeprecatedFeatureWarning): self.assert_roundtrip_equal(test_sched) @@ -357,7 +380,7 @@ def test_1q_gate(self): with self.assertWarns(DeprecationWarning): qc.add_calibration(mygate, (0,), caldef) - self.assert_roundtrip_equal(qc) + self.assert_roundtrip_equal(qc) def test_2q_gate(self): """Test for two qubit pulse gate.""" @@ -372,7 +395,7 @@ def test_2q_gate(self): with self.assertWarns(DeprecationWarning): qc.add_calibration(mygate, (0, 1), caldef) - self.assert_roundtrip_equal(qc) + self.assert_roundtrip_equal(qc) def test_parameterized_gate(self): """Test for parameterized pulse gate.""" @@ -389,7 +412,7 @@ def test_parameterized_gate(self): with self.assertWarns(DeprecationWarning): qc.add_calibration(mygate, (0, 1), caldef) - self.assert_roundtrip_equal(qc) + self.assert_roundtrip_equal(qc) def test_override(self): """Test for overriding standard gate with pulse gate.""" @@ -491,6 +514,6 @@ def test_symengine_full_path(self): with self.assertWarns(DeprecationWarning): dump(self.test_sched, qpy_file, use_symengine=True) qpy_file.seek(0) - with self.assertWarns(DeprecationWarning): + with self.assertWarns(QPYLoadingDeprecatedFeatureWarning): new_sched = load(qpy_file)[0] self.assertEqual(self.test_sched, new_sched) diff --git a/test/python/transpiler/test_calibrationbuilder.py b/test/python/transpiler/test_calibrationbuilder.py index bd874a50954e..04bc8aef00da 100644 --- a/test/python/transpiler/test_calibrationbuilder.py +++ b/test/python/transpiler/test_calibrationbuilder.py @@ -521,7 +521,9 @@ def test_not_supported_if_sx_not_drag(self): with builder.build() as square_sx_cal: builder.play(Square(amp=0.1, duration=160, phase=0), DriveChannel(0)) with self.assertWarns(DeprecationWarning): - target.add_instruction(SXGate(), {(0,): InstructionProperties(calibration=square_sx_cal)}) + target.add_instruction( + SXGate(), {(0,): InstructionProperties(calibration=square_sx_cal)} + ) tp = RXCalibrationBuilder(target) qubits = (0,) node_op = DAGOpNode(RXGate(0.5), qubits, []) diff --git a/test/python/transpiler/test_pulse_gate_pass.py b/test/python/transpiler/test_pulse_gate_pass.py index 844f262c3dff..e617f64d8859 100644 --- a/test/python/transpiler/test_pulse_gate_pass.py +++ b/test/python/transpiler/test_pulse_gate_pass.py @@ -421,7 +421,7 @@ def test_transpile_with_both_instmap_and_empty_target(self, opt_level): with self.assertWarns(DeprecationWarning): backend_pulse = Fake27QPulseV1() - # This doesn't have custom schedule definition + # This doesn't have custom schedule definition target = GenericBackendV2( num_qubits=5, coupling_map=BOGOTA_CMAP, diff --git a/test/python/transpiler/test_target.py b/test/python/transpiler/test_target.py index eeb700995ff8..fc9eb2a6923c 100644 --- a/test/python/transpiler/test_target.py +++ b/test/python/transpiler/test_target.py @@ -2001,8 +2001,7 @@ def test_inst_map(self): fake_backend = Fake7QPulseV1() config = fake_backend.configuration() properties = fake_backend.properties() - with self.assertWarns(DeprecationWarning): - defaults = fake_backend.defaults() + defaults = fake_backend.defaults() constraints = TimingConstraints(**config.timing_constraints) with self.assertWarns(DeprecationWarning): target = Target.from_configuration( From f73a5b0dad16e6d292354dbb0c84bbf6a6a56791 Mon Sep 17 00:00:00 2001 From: Eli Arbel Date: Tue, 15 Oct 2024 11:58:08 +0300 Subject: [PATCH 19/23] Fix CI failure with Python 3.10 in `catch_warnings` --- qiskit/providers/fake_provider/fake_pulse_backend.py | 3 ++- qiskit/providers/fake_provider/generic_backend_v2.py | 6 ++++-- qiskit/pulse/calibration_entries.py | 3 ++- qiskit/pulse/instruction_schedule_map.py | 3 ++- qiskit/transpiler/passes/calibration/rzx_builder.py | 9 ++++++--- .../transpiler/passes/scheduling/dynamical_decoupling.py | 3 ++- .../passes/scheduling/padding/dynamical_decoupling.py | 6 ++++-- .../passes/scheduling/scheduling/base_scheduler.py | 3 ++- .../transpiler/passes/scheduling/time_unit_conversion.py | 3 ++- qiskit/transpiler/preset_passmanagers/builtin_plugins.py | 9 ++++++--- qiskit/transpiler/target.py | 6 ++++-- test/python/circuit/test_circuit_load_from_qpy.py | 1 - test/python/qpy/test_block_load_from_qpy.py | 6 ++++-- 13 files changed, 40 insertions(+), 21 deletions(-) diff --git a/qiskit/providers/fake_provider/fake_pulse_backend.py b/qiskit/providers/fake_provider/fake_pulse_backend.py index 563c8e1fe322..65d5fe61df98 100644 --- a/qiskit/providers/fake_provider/fake_pulse_backend.py +++ b/qiskit/providers/fake_provider/fake_pulse_backend.py @@ -32,7 +32,8 @@ class FakePulseBackend(FakeQasmBackend): def defaults(self): """Returns a snapshot of device defaults""" if not self._defaults: - with warnings.catch_warnings(action="ignore", category=DeprecationWarning): + with warnings.catch_warnings(): + warnings.simplefilter(action="ignore", category=DeprecationWarning) # Filter deprecation warnings emitted from Qiskit Pulse self._set_defaults_from_json() return self._defaults diff --git a/qiskit/providers/fake_provider/generic_backend_v2.py b/qiskit/providers/fake_provider/generic_backend_v2.py index 883b37b065d2..afb2c6b2bf82 100644 --- a/qiskit/providers/fake_provider/generic_backend_v2.py +++ b/qiskit/providers/fake_provider/generic_backend_v2.py @@ -651,7 +651,8 @@ def meas_map(self) -> list[list[int]]: return self._target.concurrent_measurements def _build_default_channels(self) -> None: - with warnings.catch_warnings(action="ignore", category=DeprecationWarning): + with warnings.catch_warnings(): + warnings.simplefilter(action="ignore", category=DeprecationWarning) # Prevent pulse deprecation warnings from being emitted channels_map = { "acquire": {(i,): [pulse.AcquireChannel(i)] for i in range(self.num_qubits)}, @@ -877,7 +878,8 @@ def _add_noisy_instruction_to_target( self._rng.uniform(*noise_params[2:]), ) ) - with warnings.catch_warnings(action="ignore", category=DeprecationWarning): + with warnings.catch_warnings(): + warnings.simplefilter(action="ignore", category=DeprecationWarning) # Prevent pulse deprecations from being emitted if ( calibration_inst_map is not None diff --git a/qiskit/pulse/calibration_entries.py b/qiskit/pulse/calibration_entries.py index 318bc78009ea..f0c0e4497fa1 100644 --- a/qiskit/pulse/calibration_entries.py +++ b/qiskit/pulse/calibration_entries.py @@ -321,7 +321,8 @@ def __init__( def _build_schedule(self): """Build pulse schedule from cmd-def sequence.""" - with warnings.catch_warnings(action="ignore", category=DeprecationWarning): + with warnings.catch_warnings(): + warnings.simplefilter(action="ignore", category=DeprecationWarning) # `Schedule` is being deprecated in Qiskit 1.3 schedule = Schedule(name=self._name) try: diff --git a/qiskit/pulse/instruction_schedule_map.py b/qiskit/pulse/instruction_schedule_map.py index e3a1c62e7ffe..2815a9897db0 100644 --- a/qiskit/pulse/instruction_schedule_map.py +++ b/qiskit/pulse/instruction_schedule_map.py @@ -356,7 +356,8 @@ def get_parameters( instruction = _get_instruction_string(instruction) self.assert_has(instruction, qubits) - with warnings.catch_warnings(action="ignore", category=DeprecationWarning): + with warnings.catch_warnings(): + warnings.simplefilter(action="ignore", category=DeprecationWarning) # Prevent `get_signature` from emitting pulse package deprecation warnings signature = self._map[instruction][_to_tuple(qubits)].get_signature() return tuple(signature.parameters.keys()) diff --git a/qiskit/transpiler/passes/calibration/rzx_builder.py b/qiskit/transpiler/passes/calibration/rzx_builder.py index 3e9c90ca1ded..72cf347db9bb 100644 --- a/qiskit/transpiler/passes/calibration/rzx_builder.py +++ b/qiskit/transpiler/passes/calibration/rzx_builder.py @@ -204,7 +204,8 @@ def get_calibration(self, node_op: CircuitInst, qubits: list) -> Schedule | Sche # The CR instruction is in the forward (native) direction if cal_type in [CRCalType.ECR_CX_FORWARD, CRCalType.ECR_FORWARD]: - with warnings.catch_warnings(action="ignore", category=DeprecationWarning): + with warnings.catch_warnings(): + warnings.simplefilter(action="ignore", category=DeprecationWarning) # `InstructionScheduleMap.get` and the pulse builder emit deprecation warnings # as they use classes and methods which are deprecated in Qiskit 1.3 as part of the # Qiskit Pulse deprecation @@ -303,7 +304,8 @@ def get_calibration(self, node_op: CircuitInst, qubits: list) -> Schedule | Sche # RZXCalibrationNoEcho only good for forward CR direction if cal_type in [CRCalType.ECR_CX_FORWARD, CRCalType.ECR_FORWARD]: - with warnings.catch_warnings(action="ignore", category=DeprecationWarning): + with warnings.catch_warnings(): + warnings.simplefilter(action="ignore", category=DeprecationWarning) # Pulse builder emits deprecation warnings as part of the # Qiskit Pulse deprecation with builder.build(default_alignment="left", name=f"rzx({theta:.3f})") as rzx_theta: @@ -356,7 +358,8 @@ def _check_calibration_type( QiskitError: Unknown calibration type is detected. """ cal_type = None - with warnings.catch_warnings(action="ignore", category=DeprecationWarning): + with warnings.catch_warnings(): + warnings.simplefilter(action="ignore", category=DeprecationWarning) # `InstructionScheduleMap.get` and `filter_instructions` emit deprecation warnings # as they use classes and methods which are deprecated in Qiskit 1.3 as part of the # Qiskit Pulse deprecation diff --git a/qiskit/transpiler/passes/scheduling/dynamical_decoupling.py b/qiskit/transpiler/passes/scheduling/dynamical_decoupling.py index 45b86894e29a..7ae27ddf03d0 100644 --- a/qiskit/transpiler/passes/scheduling/dynamical_decoupling.py +++ b/qiskit/transpiler/passes/scheduling/dynamical_decoupling.py @@ -291,7 +291,8 @@ def _update_inst_durations(self, dag): if dag._calibrations_prop: cal_durations = [] - with warnings.catch_warnings(action="ignore", category=DeprecationWarning): + with warnings.catch_warnings(): + warnings.simplefilter(action="ignore", category=DeprecationWarning) # `schedule.duration` emits pulse deprecation warnings which we don't want # to see here for gate, gate_cals in dag._calibrations_prop.items(): diff --git a/qiskit/transpiler/passes/scheduling/padding/dynamical_decoupling.py b/qiskit/transpiler/passes/scheduling/padding/dynamical_decoupling.py index 996445804bc0..0a692a85621b 100644 --- a/qiskit/transpiler/passes/scheduling/padding/dynamical_decoupling.py +++ b/qiskit/transpiler/passes/scheduling/padding/dynamical_decoupling.py @@ -190,7 +190,8 @@ def _update_inst_durations(self, dag): if dag._calibrations_prop: cal_durations = [] - with warnings.catch_warnings(action="ignore", category=DeprecationWarning): + with warnings.catch_warnings(): + warnings.simplefilter(action="ignore", category=DeprecationWarning) # `schedule.duration` emits pulse deprecation warnings which we don't want # to see here for gate, gate_cals in dag._calibrations_prop.items(): @@ -256,7 +257,8 @@ def _pre_runhook(self, dag: DAGCircuit): try: # Check calibration. params = self._resolve_params(gate) - with warnings.catch_warnings(action="ignore", category=DeprecationWarning): + with warnings.catch_warnings(): + warnings.simplefilter(action="ignore", category=DeprecationWarning) # `schedule.duration` emits pulse deprecation warnings which we don't want # to see here gate_length = dag._calibrations_prop[gate.name][ diff --git a/qiskit/transpiler/passes/scheduling/scheduling/base_scheduler.py b/qiskit/transpiler/passes/scheduling/scheduling/base_scheduler.py index 3b10fac04256..4c21a210c1c0 100644 --- a/qiskit/transpiler/passes/scheduling/scheduling/base_scheduler.py +++ b/qiskit/transpiler/passes/scheduling/scheduling/base_scheduler.py @@ -67,7 +67,8 @@ def _get_node_duration( if dag._has_calibration_for(node): # If node has calibration, this value should be the highest priority cal_key = tuple(indices), tuple(float(p) for p in node.op.params) - with warnings.catch_warnings(action="ignore", category=DeprecationWarning): + with warnings.catch_warnings(): + warnings.simplefilter(action="ignore", category=DeprecationWarning) # `schedule.duration` emits pulse deprecation warnings which we don't want # to see here duration = dag._calibrations_prop[node.op.name][cal_key].duration diff --git a/qiskit/transpiler/passes/scheduling/time_unit_conversion.py b/qiskit/transpiler/passes/scheduling/time_unit_conversion.py index 1f7d72134168..8bb743ce6b3e 100644 --- a/qiskit/transpiler/passes/scheduling/time_unit_conversion.py +++ b/qiskit/transpiler/passes/scheduling/time_unit_conversion.py @@ -124,7 +124,8 @@ def _update_inst_durations(self, dag): if dag._calibrations_prop: cal_durations = [] - with warnings.catch_warnings(action="ignore", category=DeprecationWarning): + with warnings.catch_warnings(): + warnings.simplefilter(action="ignore", category=DeprecationWarning) # `schedule.duration` emits pulse deprecation warnings which we don't want # to see here for gate, gate_cals in dag._calibrations_prop.items(): diff --git a/qiskit/transpiler/preset_passmanagers/builtin_plugins.py b/qiskit/transpiler/preset_passmanagers/builtin_plugins.py index 459de0bf01ab..9301588c0744 100644 --- a/qiskit/transpiler/preset_passmanagers/builtin_plugins.py +++ b/qiskit/transpiler/preset_passmanagers/builtin_plugins.py @@ -677,7 +677,8 @@ def pass_manager(self, pass_manager_config, optimization_level=None) -> PassMana inst_map = pass_manager_config.inst_map target = pass_manager_config.target - with warnings.catch_warnings(action="ignore", category=DeprecationWarning): + with warnings.catch_warnings(): + warnings.simplefilter(action="ignore", category=DeprecationWarning) # Passing `inst_map` to `generate_scheduling` is deprecated in Qiskit 1.3 # so filtering these warning when building pass managers return common.generate_scheduling( @@ -697,7 +698,8 @@ def pass_manager(self, pass_manager_config, optimization_level=None) -> PassMana inst_map = pass_manager_config.inst_map target = pass_manager_config.target - with warnings.catch_warnings(action="ignore", category=DeprecationWarning): + with warnings.catch_warnings(): + warnings.simplefilter(action="ignore", category=DeprecationWarning) # Passing `inst_map` to `generate_scheduling` is deprecated in Qiskit 1.3 # so filtering these warning when building pass managers return common.generate_scheduling( @@ -717,7 +719,8 @@ def pass_manager(self, pass_manager_config, optimization_level=None) -> PassMana inst_map = pass_manager_config.inst_map target = pass_manager_config.target - with warnings.catch_warnings(action="ignore", category=DeprecationWarning): + with warnings.catch_warnings(): + warnings.simplefilter(action="ignore", category=DeprecationWarning) # Passing `inst_map` to `generate_scheduling` is deprecated in Qiskit 1.3 # so filtering these warning when building pass managers return common.generate_scheduling( diff --git a/qiskit/transpiler/target.py b/qiskit/transpiler/target.py index 1e5f9960bd35..1edc89013572 100644 --- a/qiskit/transpiler/target.py +++ b/qiskit/transpiler/target.py @@ -147,7 +147,8 @@ def calibration(self, calibration: Schedule | ScheduleBlock | CalibrationEntry): def _calibration_prop(self): if self._calibration is None: return None - with warnings.catch_warnings(action="ignore", category=DeprecationWarning): + with warnings.catch_warnings(): + warnings.simplefilter(action="ignore", category=DeprecationWarning) # Clean this alternative path from deprecation warning emitted by `get_schedule` return self._calibration.get_schedule() @@ -633,7 +634,8 @@ def instruction_schedule_map(self): def _get_instruction_schedule_map(self): if self._instruction_schedule_map is not None: return self._instruction_schedule_map - with warnings.catch_warnings(action="ignore", category=DeprecationWarning): + with warnings.catch_warnings(): + warnings.simplefilter(action="ignore", category=DeprecationWarning) # `InstructionScheduleMap` is deprecated in Qiskit 1.3 but we want this alternative # path to be clean of deprecation warnings out_inst_schedule_map = InstructionScheduleMap() diff --git a/test/python/circuit/test_circuit_load_from_qpy.py b/test/python/circuit/test_circuit_load_from_qpy.py index 0a0a25034240..5e45d0671021 100644 --- a/test/python/circuit/test_circuit_load_from_qpy.py +++ b/test/python/circuit/test_circuit_load_from_qpy.py @@ -56,7 +56,6 @@ from qiskit.circuit.instruction import Instruction from qiskit.circuit.parameter import Parameter from qiskit.circuit.parametervector import ParameterVector -from qiskit.qpy.exceptions import QPYLoadingDeprecatedFeatureWarning from qiskit.synthesis import LieTrotter, SuzukiTrotter from qiskit.qpy import dump, load, UnsupportedFeatureForVersion, QPY_COMPATIBILITY_VERSION from qiskit.quantum_info import Pauli, SparsePauliOp, Clifford diff --git a/test/python/qpy/test_block_load_from_qpy.py b/test/python/qpy/test_block_load_from_qpy.py index a8897993ac32..6085618e8362 100644 --- a/test/python/qpy/test_block_load_from_qpy.py +++ b/test/python/qpy/test_block_load_from_qpy.py @@ -241,7 +241,8 @@ def test_unassigned_reference(self): builder.reference("custom1", "q0") builder.reference("custom1", "q1") - with warnings.catch_warnings(action="ignore", category=DeprecationWarning): + with warnings.catch_warnings(): + warnings.simplefilter(action="ignore", category=DeprecationWarning) with self.assertWarns(QPYLoadingDeprecatedFeatureWarning): self.assert_roundtrip_equal(test_sched) @@ -260,7 +261,8 @@ def test_partly_assigned_reference(self): inplace=True, ) - with warnings.catch_warnings(action="ignore", category=DeprecationWarning): + with warnings.catch_warnings(): + warnings.simplefilter(action="ignore", category=DeprecationWarning) with self.assertWarns(QPYLoadingDeprecatedFeatureWarning): self.assert_roundtrip_equal(test_sched) From f78a957431792ea18d66f73eeac90c9a81b10e38 Mon Sep 17 00:00:00 2001 From: Eli Arbel <46826214+eliarbel@users.noreply.github.com> Date: Tue, 15 Oct 2024 16:45:16 +0300 Subject: [PATCH 20/23] Update releasenotes/notes/deprecate-pulse-package-07a621be1db7fa30.yaml MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Elena Peña Tapia <57907331+ElePT@users.noreply.github.com> --- .../notes/deprecate-pulse-package-07a621be1db7fa30.yaml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/releasenotes/notes/deprecate-pulse-package-07a621be1db7fa30.yaml b/releasenotes/notes/deprecate-pulse-package-07a621be1db7fa30.yaml index b14a0e1767bb..65f86d9d299f 100644 --- a/releasenotes/notes/deprecate-pulse-package-07a621be1db7fa30.yaml +++ b/releasenotes/notes/deprecate-pulse-package-07a621be1db7fa30.yaml @@ -1,9 +1,8 @@ --- deprecations: - | - The Qiskit Pulse package is being deprecated and will be removed in Qiskit version 2.0.0. Pulse-level - access is currently supported only on a subset of Eagle devices and not supported on the Heron architecture - ones. Furthermore, newer IBM Quantum architectures will not support pulse-level access as well. + The Qiskit Pulse package is being deprecated and will be removed in Qiskit 2.0.0. Pulse-level + access is currently only supported on a subset of Eagle devices and not supported on the Heron architecture. Furthermore, newer IBM Quantum architectures will not support pulse-level access. As a consequence, supporting Pulse as a first-class citizen frontend in the Qiskit SDK itself makes little sense going forward. The deprecation includes all pulse code in :mod:`qiskit.pulse` as well as functionality dependant or related to pulse such as pulse visualization, serialization and custom calibration support. For From 040119438c9f95b7a11a383a5d7aa8ce73fdad0c Mon Sep 17 00:00:00 2001 From: Eli Arbel Date: Thu, 17 Oct 2024 15:50:54 +0300 Subject: [PATCH 21/23] Indicate explicitly dependency removal or move to Dynamics --- qiskit/compiler/scheduler.py | 2 +- qiskit/compiler/sequencer.py | 2 +- qiskit/scheduler/config.py | 2 +- qiskit/scheduler/methods/basic.py | 4 +- qiskit/scheduler/schedule_circuit.py | 2 +- qiskit/scheduler/sequence.py | 2 +- qiskit/utils/deprecate_pulse.py | 57 ++++++++++++++++------ qiskit/visualization/pulse_v2/interface.py | 2 +- 8 files changed, 50 insertions(+), 23 deletions(-) diff --git a/qiskit/compiler/scheduler.py b/qiskit/compiler/scheduler.py index 5e55b7df1ca2..9004dc24fd11 100644 --- a/qiskit/compiler/scheduler.py +++ b/qiskit/compiler/scheduler.py @@ -36,7 +36,7 @@ def _log_schedule_time(start_time, end_time): logger.info(log_msg) -@deprecate_pulse_dependency +@deprecate_pulse_dependency(moving_to_dynamics=True) def schedule( circuits: Union[QuantumCircuit, List[QuantumCircuit]], backend: Optional[Backend] = None, diff --git a/qiskit/compiler/sequencer.py b/qiskit/compiler/sequencer.py index 3678f97ac969..5a381918417b 100644 --- a/qiskit/compiler/sequencer.py +++ b/qiskit/compiler/sequencer.py @@ -24,7 +24,7 @@ from qiskit.utils.deprecate_pulse import deprecate_pulse_dependency -@deprecate_pulse_dependency +@deprecate_pulse_dependency(moving_to_dynamics=True) def sequence( scheduled_circuits: Union[QuantumCircuit, List[QuantumCircuit]], backend: Optional[Backend] = None, diff --git a/qiskit/scheduler/config.py b/qiskit/scheduler/config.py index f104bf88a510..a1c5ba9a2c59 100644 --- a/qiskit/scheduler/config.py +++ b/qiskit/scheduler/config.py @@ -22,7 +22,7 @@ class ScheduleConfig: """Configuration for pulse scheduling.""" - @deprecate_pulse_dependency + @deprecate_pulse_dependency(moving_to_dynamics=True) def __init__(self, inst_map: InstructionScheduleMap, meas_map: List[List[int]], dt: float): """ Container for information needed to schedule a QuantumCircuit into a pulse Schedule. diff --git a/qiskit/scheduler/methods/basic.py b/qiskit/scheduler/methods/basic.py index 48339bbe1b95..b08f0f866ab0 100644 --- a/qiskit/scheduler/methods/basic.py +++ b/qiskit/scheduler/methods/basic.py @@ -26,7 +26,7 @@ from qiskit.utils.deprecate_pulse import deprecate_pulse_dependency -@deprecate_pulse_dependency +@deprecate_pulse_dependency(moving_to_dynamics=True) def as_soon_as_possible( circuit: QuantumCircuit, schedule_config: ScheduleConfig, @@ -80,7 +80,7 @@ def update_times(inst_qubits: List[int], time: int = 0) -> None: return schedule -@deprecate_pulse_dependency +@deprecate_pulse_dependency(moving_to_dynamics=True) def as_late_as_possible( circuit: QuantumCircuit, schedule_config: ScheduleConfig, diff --git a/qiskit/scheduler/schedule_circuit.py b/qiskit/scheduler/schedule_circuit.py index 3d74ffe3b5a8..2cc32a8a7b3c 100644 --- a/qiskit/scheduler/schedule_circuit.py +++ b/qiskit/scheduler/schedule_circuit.py @@ -23,7 +23,7 @@ from qiskit.utils.deprecate_pulse import deprecate_pulse_dependency -@deprecate_pulse_dependency +@deprecate_pulse_dependency(moving_to_dynamics=True) def schedule_circuit( circuit: QuantumCircuit, schedule_config: ScheduleConfig, diff --git a/qiskit/scheduler/sequence.py b/qiskit/scheduler/sequence.py index e05cac33a57c..7f69f5f65a6a 100644 --- a/qiskit/scheduler/sequence.py +++ b/qiskit/scheduler/sequence.py @@ -28,7 +28,7 @@ from qiskit.utils.deprecate_pulse import deprecate_pulse_dependency -@deprecate_pulse_dependency +@deprecate_pulse_dependency(moving_to_dynamics=True) def sequence( scheduled_circuit: QuantumCircuit, schedule_config: ScheduleConfig, diff --git a/qiskit/utils/deprecate_pulse.py b/qiskit/utils/deprecate_pulse.py index 86e577fd5dd8..437c128212a2 100644 --- a/qiskit/utils/deprecate_pulse.py +++ b/qiskit/utils/deprecate_pulse.py @@ -32,25 +32,52 @@ def deprecate_pulse_func(func): )(func) -def deprecate_pulse_dependency(*args, **kwargs): - """Deprecation message for functions and classes which use or depend on Pulse""" - decorator = deprecate_func( - since="1.3", - package_name="Qiskit", - removal_timeline="in Qiskit 2.0", - additional_msg="The entire Qiskit Pulse package is being deprecated " - "and this is a dependency on the package.", - **kwargs, - ) +def deprecate_pulse_dependency(*args, moving_to_dynamics: bool = False, **kwargs): + """Deprecation message for functions and classes which use or depend on Pulse + + moving_to_dynamics: set to True if the dependency is moving to Qiskit Dynamics. This affects + the deprecation message being printed, namely saying explicitly whether the dependency will + be moved to Qiskit Dynamics or whether it will just be removed without an alternative. + """ + + def msg_handler(func): + fully_qual_name = format(f"{func.__module__}.{func.__qualname__}") + if ".__init__" in fully_qual_name: # Deprecating a class' vis it __init__ method + fully_qual_name = fully_qual_name[:-9] + elif "is_property" not in kwargs: # Deprecating either a function or a method + fully_qual_name += "()" + + message = ( + "The entire Qiskit Pulse package is being deprecated and will be moved to the Qiskit " + "Dynamics repository: https://github.com/qiskit-community/qiskit-dynamics." + + ( + format(f" Note that ``{fully_qual_name}`` will be moved as well.") + if moving_to_dynamics + else format( + f" Note that once removed, ``{fully_qual_name}`` will have no alternative in Qiskit." + ) + ) + ) + + decorator = deprecate_func( + since="1.3", + package_name="Qiskit", + removal_timeline="in Qiskit 2.0", + additional_msg=message, + **kwargs, + )(func) + + # Taken when `deprecate_pulse_dependency` is used with no arguments and with empty parentheses, + # in which case the decorated function is passed + + return decorator - # Taken when `deprecate_pulse_dependency` is used with no arguments and with empty parentheses, - # in which case the decorated function is passed if args: - return decorator(args[0]) - return decorator + return msg_handler(args[0]) + return msg_handler -def deprecate_pulse_arg(arg_name, **kwargs): +def deprecate_pulse_arg(arg_name: str, **kwargs): """Deprecation message for arguments related to Pulse""" return deprecate_arg( name=arg_name, diff --git a/qiskit/visualization/pulse_v2/interface.py b/qiskit/visualization/pulse_v2/interface.py index 089dbcfad90b..6feb4bc83339 100644 --- a/qiskit/visualization/pulse_v2/interface.py +++ b/qiskit/visualization/pulse_v2/interface.py @@ -31,7 +31,7 @@ from qiskit.utils.deprecate_pulse import deprecate_pulse_dependency -@deprecate_pulse_dependency +@deprecate_pulse_dependency(moving_to_dynamics=True) @deprecate_arg("show_barrier", new_alias="plot_barrier", since="1.1.0", pending=True) def draw( program: Union[Waveform, SymbolicPulse, Schedule, ScheduleBlock], From f80e67763f6a47849bde8e096beb0bc1e6342bea Mon Sep 17 00:00:00 2001 From: Eli Arbel Date: Mon, 21 Oct 2024 23:26:42 +0300 Subject: [PATCH 22/23] Fix unit test failure The inner class `TestAddCalibration` in `test_transpiler.py::TestTranspilerParallel` calls a deprecated functionality. In an attempt to use `self.assertWarns` inside the inner class, a reference to the outer class was stored as a class attribute of `TestAddCalibration`. dill got confused as to how to serialize the outer class which derives from `QiskitTestCase`. So switched to using `warnings.catch_warnnigs` instead in the inner class to avoid this reference of the outer class in the serialized inner class. --- test/python/compiler/test_transpiler.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/python/compiler/test_transpiler.py b/test/python/compiler/test_transpiler.py index ec4d084bfcaf..38991b63a63e 100644 --- a/test/python/compiler/test_transpiler.py +++ b/test/python/compiler/test_transpiler.py @@ -19,6 +19,7 @@ import sys from logging import StreamHandler, getLogger from unittest.mock import patch +import warnings import numpy as np import rustworkx as rx from ddt import data, ddt, unpack @@ -2794,8 +2795,6 @@ def test_parallel_dispatch_lazy_cal_loading(self): class TestAddCalibration(TransformationPass): """A fake pass to test lazy pulse qobj loading in parallel environment.""" - _outer_class = None - def __init__(self, target): """Instantiate with target.""" super().__init__() @@ -2803,7 +2802,9 @@ def __init__(self, target): def run(self, dag): """Run test pass that adds calibration of SX gate of qubit 0.""" - with self._outer_class.assertWarns(DeprecationWarning): + with warnings.catch_warnings(): + warnings.simplefilter("ignore", category=DeprecationWarning) + # DAGCircuit.add_calibration() is deprecated but we can't use self.assertWarns() here dag.add_calibration( "sx", qubits=(0,), @@ -2820,7 +2821,6 @@ def run(self, dag): # This target has PulseQobj entries that provide a serialized schedule data pass_ = TestAddCalibration(backend.target) - pass_._outer_class = self # to be used for calling assertWarns within the pass pm = PassManager(passes=[pass_]) self.assertIsNone(backend.target["sx"][(0,)]._calibration._definition) From 66cbae488490aaaa64fade074a290db1b8e0772f Mon Sep 17 00:00:00 2001 From: Eli Arbel Date: Wed, 23 Oct 2024 00:00:53 +0300 Subject: [PATCH 23/23] Standardize docstring of `deprecate_pulse_dependency` --- qiskit/utils/deprecate_pulse.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/qiskit/utils/deprecate_pulse.py b/qiskit/utils/deprecate_pulse.py index 437c128212a2..376e3e06c8f1 100644 --- a/qiskit/utils/deprecate_pulse.py +++ b/qiskit/utils/deprecate_pulse.py @@ -33,11 +33,13 @@ def deprecate_pulse_func(func): def deprecate_pulse_dependency(*args, moving_to_dynamics: bool = False, **kwargs): + # pylint: disable=missing-param-doc """Deprecation message for functions and classes which use or depend on Pulse - moving_to_dynamics: set to True if the dependency is moving to Qiskit Dynamics. This affects - the deprecation message being printed, namely saying explicitly whether the dependency will - be moved to Qiskit Dynamics or whether it will just be removed without an alternative. + Args: + moving_to_dynamics: set to True if the dependency is moving to Qiskit Dynamics. This affects + the deprecation message being printed, namely saying explicitly whether the dependency will + be moved to Qiskit Dynamics or whether it will just be removed without an alternative. """ def msg_handler(func):