From 2e99d5af4c8f299617b571380e8549014b52371a Mon Sep 17 00:00:00 2001 From: Luciano Bello Date: Mon, 24 Jun 2024 22:06:18 +0200 Subject: [PATCH 01/51] deprecate qobj and assemble --- qiskit/compiler/assembler.py | 8 + qiskit/qobj/common.py | 9 + qiskit/qobj/converters/lo_config.py | 8 + qiskit/qobj/converters/pulse_instruction.py | 9 + qiskit/qobj/pulse_qobj.py | 52 +++ qiskit/qobj/qasm_qobj.py | 52 +++ qiskit/qobj/utils.py | 9 + test/python/qobj/test_pulse_converter.py | 310 ++++++++------ test/python/qobj/test_qobj.py | 427 ++++++++++---------- test/python/qobj/test_qobj_identifiers.py | 3 +- 10 files changed, 548 insertions(+), 339 deletions(-) diff --git a/qiskit/compiler/assembler.py b/qiskit/compiler/assembler.py index 522e1c503ddf..4417c0666fb4 100644 --- a/qiskit/compiler/assembler.py +++ b/qiskit/compiler/assembler.py @@ -29,6 +29,7 @@ from qiskit.pulse.channels import PulseChannel from qiskit.qobj import QasmQobj, PulseQobj, QobjHeader from qiskit.qobj.utils import MeasLevel, MeasReturnType +from qiskit.utils import deprecate_func logger = logging.getLogger(__name__) @@ -39,6 +40,13 @@ def _log_assembly_time(start_time, end_time): # TODO: parallelize over the experiments (serialize each separately, then add global header/config) +@deprecate_func( + since="1.2", + removal_timeline="in the 2.0 release", + additional_msg="The function assemble is being deprecated " + "as they are not necessary for BackendV2. If user still need Qobj, that probably " + "means that they are using a backend based on the deprecated BackendV1 class.", +) def assemble( experiments: Union[ QuantumCircuit, diff --git a/qiskit/qobj/common.py b/qiskit/qobj/common.py index 9b219e5ba8d0..f9abb32282b5 100644 --- a/qiskit/qobj/common.py +++ b/qiskit/qobj/common.py @@ -13,6 +13,8 @@ """Module providing definitions of common Qobj classes.""" from types import SimpleNamespace +from qiskit.utils import deprecate_func + class QobjDictField(SimpleNamespace): """A class used to represent a dictionary field in Qobj @@ -21,6 +23,13 @@ class QobjDictField(SimpleNamespace): previously constructed using marshmallow. """ + @deprecate_func( + since="1.2", + removal_timeline="in the 2.0 release", + additional_msg="The full Qobj module is being deprecated, including QobjDictField subclasses, " + "as they are not necessary for BackendV2. If user still need Qobj, that probably " + "means that they are using a backend based on the deprecated BackendV1 class.", + ) def __init__(self, **kwargs): """Instantiate a new Qobj dict field object. diff --git a/qiskit/qobj/converters/lo_config.py b/qiskit/qobj/converters/lo_config.py index e06ff11a8c93..a76df3991f05 100644 --- a/qiskit/qobj/converters/lo_config.py +++ b/qiskit/qobj/converters/lo_config.py @@ -15,6 +15,7 @@ from qiskit.pulse.channels import DriveChannel, MeasureChannel from qiskit.pulse.configuration import LoConfig from qiskit.exceptions import QiskitError +from qiskit.utils import deprecate_func class LoConfigConverter: @@ -23,6 +24,13 @@ class LoConfigConverter: ``get_qubit_los`` and ``get_meas_los`` to align with your backend. """ + @deprecate_func( + since="1.2", + removal_timeline="in the 2.0 release", + additional_msg="The full Qobj module is being deprecated, including LoConfigConverter class, " + "as they are not necessary for BackendV2. If user still need Qobj, that probably " + "means that they are using a backend based on the deprecated BackendV1 class.", + ) def __init__( self, qobj_model, diff --git a/qiskit/qobj/converters/pulse_instruction.py b/qiskit/qobj/converters/pulse_instruction.py index 8f34ee0855ac..45f82a9c7d50 100644 --- a/qiskit/qobj/converters/pulse_instruction.py +++ b/qiskit/qobj/converters/pulse_instruction.py @@ -30,6 +30,7 @@ from qiskit.pulse.schedule import Schedule from qiskit.qobj import QobjMeasurementOption, PulseLibraryItem, PulseQobjInstruction from qiskit.qobj.utils import MeasLevel +from qiskit.utils import deprecate_func class ParametricPulseShapes(Enum): @@ -107,6 +108,14 @@ def _convert_NewInstruction(self, instruction, time_offset): where ``NewInstruction`` must be a class name of Qiskit Pulse instruction. """ + @deprecate_func( + since="1.2", + removal_timeline="in the 2.0 release", + additional_msg="The full Qobj module is being deprecated, including InstructionToQobjConverter " + "class, " + "as they are not necessary for BackendV2. If user still need Qobj, that probably " + "means that they are using a backend based on the deprecated BackendV1 class.", + ) def __init__( self, qobj_model: PulseQobjInstruction, diff --git a/qiskit/qobj/pulse_qobj.py b/qiskit/qobj/pulse_qobj.py index 3552d83ada84..0de59f894dc6 100644 --- a/qiskit/qobj/pulse_qobj.py +++ b/qiskit/qobj/pulse_qobj.py @@ -23,11 +23,20 @@ from qiskit.qobj.common import QobjDictField from qiskit.qobj.common import QobjHeader from qiskit.qobj.common import QobjExperimentHeader +from qiskit.utils import deprecate_func class QobjMeasurementOption: """An individual measurement option.""" + @deprecate_func( + since="1.2", + removal_timeline="in the 2.0 release", + additional_msg="The full Qobj module is being deprecated, including QobjMeasurementOption " + "class, " + "as they are not necessary for BackendV2. If user still need Qobj, that probably " + "means that they are using a backend based on the deprecated BackendV1 class.", + ) def __init__(self, name, params=None): """Instantiate a new QobjMeasurementOption object. @@ -89,6 +98,13 @@ class PulseQobjInstruction: "parameters", ] + @deprecate_func( + since="1.2", + removal_timeline="in the 2.0 release", + additional_msg="The full Qobj module is being deprecated, including PulseQobjInstruction class, " + "as they are not necessary for BackendV2. If user still need Qobj, that probably " + "means that they are using a backend based on the deprecated BackendV1 class.", + ) def __init__( self, name, @@ -282,6 +298,13 @@ def _to_complex(value: Union[List[float], complex]) -> complex: class PulseQobjConfig(QobjDictField): """A configuration for a Pulse Qobj.""" + @deprecate_func( + since="1.2", + removal_timeline="in the 2.0 release", + additional_msg="The full Qobj module is being deprecated, including PulseQobjConfig class, " + "as they are not necessary for BackendV2. If user still need Qobj, that probably " + "means that they are using a backend based on the deprecated BackendV1 class.", + ) def __init__( self, meas_level, @@ -383,6 +406,13 @@ class PulseQobjExperiment: experiment as part of a larger Pulse Qobj. """ + @deprecate_func( + since="1.2", + removal_timeline="in the 2.0 release", + additional_msg="The full Qobj module is being deprecated, including PulseQobjExperiment class, " + "as they are not necessary for BackendV2. If user still need Qobj, that probably " + "means that they are using a backend based on the deprecated BackendV1 class.", + ) def __init__(self, instructions, config=None, header=None): """Instantiate a PulseQobjExperiment. @@ -473,6 +503,14 @@ def __eq__(self, other): class PulseQobjExperimentConfig(QobjDictField): """A config for a single Pulse experiment in the qobj.""" + @deprecate_func( + since="1.2", + removal_timeline="in the 2.0 release", + additional_msg="The full Qobj module is being deprecated, including PulseQobjExperimentConfig " + "class, " + "as they are not necessary for BackendV2. If user still need Qobj, that probably " + "means that they are using a backend based on the deprecated BackendV1 class.", + ) def __init__(self, qubit_lo_freq=None, meas_lo_freq=None, **kwargs): """Instantiate a PulseQobjExperimentConfig object. @@ -492,6 +530,13 @@ def __init__(self, qubit_lo_freq=None, meas_lo_freq=None, **kwargs): class PulseLibraryItem: """An item in a pulse library.""" + @deprecate_func( + since="1.2", + removal_timeline="in the 2.0 release", + additional_msg="The full Qobj module is being deprecated, including PulseLibraryItem class, " + "as they are not necessary for BackendV2. If user still need Qobj, that probably " + "means that they are using a backend based on the deprecated BackendV1 class.", + ) def __init__(self, name, samples): """Instantiate a pulse library item. @@ -542,6 +587,13 @@ def __eq__(self, other): class PulseQobj: """A Pulse Qobj.""" + @deprecate_func( + since="1.2", + removal_timeline="in the 2.0 release", + additional_msg="The full Qobj module is being deprecated, including PulseQobj class, " + "as they are not necessary for BackendV2. If user still need Qobj, that probably " + "means that they are using a backend based on the deprecated BackendV1 class.", + ) def __init__(self, qobj_id, config, experiments, header=None): """Instantiate a new Pulse Qobj Object. diff --git a/qiskit/qobj/qasm_qobj.py b/qiskit/qobj/qasm_qobj.py index 88d775b3b773..b9b78bcb4ec1 100644 --- a/qiskit/qobj/qasm_qobj.py +++ b/qiskit/qobj/qasm_qobj.py @@ -18,11 +18,19 @@ from qiskit.circuit.parameterexpression import ParameterExpression from qiskit.qobj.pulse_qobj import PulseQobjInstruction, PulseLibraryItem from qiskit.qobj.common import QobjDictField, QobjHeader +from qiskit.utils import deprecate_func class QasmQobjInstruction: """A class representing a single instruction in an QasmQobj Experiment.""" + @deprecate_func( + since="1.2", + removal_timeline="in the 2.0 release", + additional_msg="The full Qobj module is being deprecated, including PulseQobj class, " + "as they are not necessary for BackendV2. If user still need Qobj, that probably " + "means that they are using a backend based on the deprecated BackendV1 class.", + ) def __init__( self, name, @@ -200,6 +208,13 @@ class QasmQobjExperiment: part of a larger OpenQASM 2 qobj. """ + @deprecate_func( + since="1.2", + removal_timeline="in the 2.0 release", + additional_msg="The full Qobj module is being deprecated, including QasmQobjExperiment class, " + "as they are not necessary for BackendV2. If user still need Qobj, that probably " + "means that they are using a backend based on the deprecated BackendV1 class.", + ) def __init__(self, config=None, header=None, instructions=None): """Instantiate a QasmQobjExperiment. @@ -276,6 +291,13 @@ def __eq__(self, other): class QasmQobjConfig(SimpleNamespace): """A configuration for an OpenQASM 2 Qobj.""" + @deprecate_func( + since="1.2", + removal_timeline="in the 2.0 release", + additional_msg="The full Qobj module is being deprecated, including QasmQobjConfig class, " + "as they are not necessary for BackendV2. If user still need Qobj, that probably " + "means that they are using a backend based on the deprecated BackendV1 class.", + ) def __init__( self, shots=None, @@ -410,6 +432,14 @@ class QasmQobjExperimentHeader(QobjDictField): class QasmQobjExperimentConfig(QobjDictField): """Configuration for a single OpenQASM 2 experiment in the qobj.""" + @deprecate_func( + since="1.2", + removal_timeline="in the 2.0 release", + additional_msg="The full Qobj module is being deprecated, including QasmQobjExperimentConfig " + "class, " + "as they are not necessary for BackendV2. If user still need Qobj, that probably " + "means that they are using a backend based on the deprecated BackendV1 class.", + ) def __init__(self, calibrations=None, qubit_lo_freq=None, meas_lo_freq=None, **kwargs): """ Args: @@ -446,6 +476,14 @@ class QasmExperimentCalibrations: GateCalibrations. """ + @deprecate_func( + since="1.2", + removal_timeline="in the 2.0 release", + additional_msg="The full Qobj module is being deprecated, including QasmExperimentCalibrations " + "class, " + "as they are not necessary for BackendV2. If user still need Qobj, that probably " + "means that they are using a backend based on the deprecated BackendV1 class.", + ) def __init__(self, gates): """ Initialize a container for calibrations. @@ -486,6 +524,13 @@ class GateCalibration: """Each calibration specifies a unique gate by name, qubits and params, and contains the Pulse instructions to implement it.""" + @deprecate_func( + since="1.2", + removal_timeline="in the 2.0 release", + additional_msg="The full Qobj module is being deprecated, including GateCalibration class, " + "as they are not necessary for BackendV2. If user still need Qobj, that probably " + "means that they are using a backend based on the deprecated BackendV1 class.", + ) def __init__(self, name, qubits, params, instructions): """ Initialize a single gate calibration. Instructions may reference waveforms which should be @@ -541,6 +586,13 @@ def from_dict(cls, data): class QasmQobj: """An OpenQASM 2 Qobj.""" + @deprecate_func( + since="1.2", + removal_timeline="in the 2.0 release", + additional_msg="The full Qobj module is being deprecated, including QasmQobj class, " + "as they are not necessary for BackendV2. If user still need Qobj, that probably " + "means that they are using a backend based on the deprecated BackendV1 class.", + ) def __init__(self, qobj_id=None, config=None, experiments=None, header=None): """Instantiate a new OpenQASM 2 Qobj Object. diff --git a/qiskit/qobj/utils.py b/qiskit/qobj/utils.py index a689fc01e7e7..1d3b6bd84300 100644 --- a/qiskit/qobj/utils.py +++ b/qiskit/qobj/utils.py @@ -14,7 +14,16 @@ from enum import Enum, IntEnum +from qiskit.utils import deprecate_func + +@deprecate_func( + since="1.2", + removal_timeline="in the 2.0 release", + additional_msg="The full Qobj module is being deprecated, including QobjType class, " + "as they are not necessary for BackendV2. If user still need Qobj, that probably " + "means that they are using a backend based on the deprecated BackendV1 class.", +) class QobjType(str, Enum): """Qobj.type allowed values.""" diff --git a/test/python/qobj/test_pulse_converter.py b/test/python/qobj/test_pulse_converter.py index cacbde2cd8b5..528d87244fe8 100644 --- a/test/python/qobj/test_pulse_converter.py +++ b/test/python/qobj/test_pulse_converter.py @@ -56,29 +56,33 @@ class TestInstructionToQobjConverter(QiskitTestCase): def test_drive_instruction(self): """Test converted qobj from Play.""" - converter = InstructionToQobjConverter(PulseQobjInstruction, meas_level=2) - instruction = Play(Waveform(np.arange(0, 0.01), name="linear"), DriveChannel(0)) - valid_qobj = PulseQobjInstruction(name="linear", ch="d0", t0=0) - self.assertEqual(converter(0, instruction), valid_qobj) + with self.assertWarns(DeprecationWarning): + converter = InstructionToQobjConverter(PulseQobjInstruction, meas_level=2) + instruction = Play(Waveform(np.arange(0, 0.01), name="linear"), DriveChannel(0)) + valid_qobj = PulseQobjInstruction(name="linear", ch="d0", t0=0) + self.assertEqual(converter(0, instruction), valid_qobj) def test_gaussian_pulse_instruction(self): """Test that parametric pulses are correctly converted to PulseQobjInstructions.""" amp = 0.3 angle = -0.7 - converter = InstructionToQobjConverter(PulseQobjInstruction, meas_level=2) + with self.assertWarns(DeprecationWarning): + converter = InstructionToQobjConverter(PulseQobjInstruction, meas_level=2) instruction = Play(Gaussian(duration=25, sigma=15, amp=amp, angle=angle), DriveChannel(0)) - valid_qobj = PulseQobjInstruction( - name="parametric_pulse", - pulse_shape="gaussian", - ch="d0", - t0=0, - parameters={"duration": 25, "sigma": 15, "amp": amp * np.exp(1j * angle)}, - ) - self.assertEqual(converter(0, instruction), valid_qobj) + with self.assertWarns(DeprecationWarning): + valid_qobj = PulseQobjInstruction( + name="parametric_pulse", + pulse_shape="gaussian", + ch="d0", + t0=0, + parameters={"duration": 25, "sigma": 15, "amp": amp * np.exp(1j * angle)}, + ) + self.assertEqual(converter(0, instruction), valid_qobj) def test_gaussian_square_pulse_instruction(self): """Test that parametric pulses are correctly converted to PulseQobjInstructions.""" - converter = InstructionToQobjConverter(PulseQobjInstruction, meas_level=2) + with self.assertWarns(DeprecationWarning): + converter = InstructionToQobjConverter(PulseQobjInstruction, meas_level=2) amp = 0.7 angle = -0.6 instruction = Play( @@ -86,110 +90,129 @@ def test_gaussian_square_pulse_instruction(self): MeasureChannel(1), ) - valid_qobj = PulseQobjInstruction( - name="parametric_pulse", - pulse_shape="gaussian_square", - ch="m1", - t0=10, - parameters={ - "duration": 1500, - "sigma": 15, - "amp": amp * np.exp(1j * angle), - "width": 1300, - }, - ) - self.assertEqual(converter(10, instruction), valid_qobj) + with self.assertWarns(DeprecationWarning): + valid_qobj = PulseQobjInstruction( + name="parametric_pulse", + pulse_shape="gaussian_square", + ch="m1", + t0=10, + parameters={ + "duration": 1500, + "sigma": 15, + "amp": amp * np.exp(1j * angle), + "width": 1300, + }, + ) + self.assertEqual(converter(10, instruction), valid_qobj) def test_constant_pulse_instruction(self): """Test that parametric pulses are correctly converted to PulseQobjInstructions.""" - converter = InstructionToQobjConverter(PulseQobjInstruction, meas_level=2) + with self.assertWarns(DeprecationWarning): + converter = InstructionToQobjConverter(PulseQobjInstruction, meas_level=2) instruction = Play(Constant(duration=25, amp=1, angle=np.pi), ControlChannel(2)) - valid_qobj = PulseQobjInstruction( - name="parametric_pulse", - pulse_shape="constant", - ch="u2", - t0=20, - parameters={"duration": 25, "amp": 1 * np.exp(1j * np.pi)}, - ) - self.assertEqual(converter(20, instruction), valid_qobj) + with self.assertWarns(DeprecationWarning): + valid_qobj = PulseQobjInstruction( + name="parametric_pulse", + pulse_shape="constant", + ch="u2", + t0=20, + parameters={"duration": 25, "amp": 1 * np.exp(1j * np.pi)}, + ) + self.assertEqual(converter(20, instruction), valid_qobj) def test_drag_pulse_instruction(self): """Test that parametric pulses are correctly converted to PulseQobjInstructions.""" amp = 0.7 angle = -0.6 - converter = InstructionToQobjConverter(PulseQobjInstruction, meas_level=2) + 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) ) - valid_qobj = PulseQobjInstruction( - name="parametric_pulse", - pulse_shape="drag", - ch="d0", - t0=30, - parameters={"duration": 25, "sigma": 15, "amp": amp * np.exp(1j * angle), "beta": 0.5}, - ) - self.assertEqual(converter(30, instruction), valid_qobj) + with self.assertWarns(DeprecationWarning): + valid_qobj = PulseQobjInstruction( + name="parametric_pulse", + pulse_shape="drag", + ch="d0", + t0=30, + parameters={ + "duration": 25, + "sigma": 15, + "amp": amp * np.exp(1j * angle), + "beta": 0.5, + }, + ) + self.assertEqual(converter(30, instruction), valid_qobj) def test_frame_change(self): """Test converted qobj from ShiftPhase.""" - converter = InstructionToQobjConverter(PulseQobjInstruction, meas_level=2) - valid_qobj = PulseQobjInstruction(name="fc", ch="d0", t0=0, phase=0.1) - instruction = ShiftPhase(0.1, DriveChannel(0)) - self.assertEqual(converter(0, instruction), valid_qobj) + with self.assertWarns(DeprecationWarning): + converter = InstructionToQobjConverter(PulseQobjInstruction, meas_level=2) + valid_qobj = PulseQobjInstruction(name="fc", ch="d0", t0=0, phase=0.1) + instruction = ShiftPhase(0.1, DriveChannel(0)) + self.assertEqual(converter(0, instruction), valid_qobj) def test_set_phase(self): """Test converted qobj from ShiftPhase.""" - converter = InstructionToQobjConverter(PulseQobjInstruction, meas_level=2) - instruction = SetPhase(3.14, DriveChannel(0)) + with self.assertWarns(DeprecationWarning): + converter = InstructionToQobjConverter(PulseQobjInstruction, meas_level=2) + instruction = SetPhase(3.14, DriveChannel(0)) - valid_qobj = PulseQobjInstruction(name="setp", ch="d0", t0=0, phase=3.14) + valid_qobj = PulseQobjInstruction(name="setp", ch="d0", t0=0, phase=3.14) - self.assertEqual(converter(0, instruction), valid_qobj) + self.assertEqual(converter(0, instruction), valid_qobj) def test_set_frequency(self): """Test converted qobj from SetFrequency.""" - converter = InstructionToQobjConverter(PulseQobjInstruction, meas_level=2) - instruction = SetFrequency(8.0e9, DriveChannel(0)) + with self.assertWarns(DeprecationWarning): + converter = InstructionToQobjConverter(PulseQobjInstruction, meas_level=2) + instruction = SetFrequency(8.0e9, DriveChannel(0)) - valid_qobj = PulseQobjInstruction(name="setf", ch="d0", t0=0, frequency=8.0) + valid_qobj = PulseQobjInstruction(name="setf", ch="d0", t0=0, frequency=8.0) - self.assertEqual(converter(0, instruction), valid_qobj) + self.assertEqual(converter(0, instruction), valid_qobj) def test_shift_frequency(self): """Test converted qobj from ShiftFrequency.""" - converter = InstructionToQobjConverter(PulseQobjInstruction, meas_level=2) - instruction = ShiftFrequency(8.0e9, DriveChannel(0)) + with self.assertWarns(DeprecationWarning): + converter = InstructionToQobjConverter(PulseQobjInstruction, meas_level=2) + instruction = ShiftFrequency(8.0e9, DriveChannel(0)) - valid_qobj = PulseQobjInstruction(name="shiftf", ch="d0", t0=0, frequency=8.0) + valid_qobj = PulseQobjInstruction(name="shiftf", ch="d0", t0=0, frequency=8.0) - self.assertEqual(converter(0, instruction), valid_qobj) + self.assertEqual(converter(0, instruction), valid_qobj) def test_acquire(self): """Test converted qobj from AcquireInstruction.""" - converter = InstructionToQobjConverter(PulseQobjInstruction, meas_level=2) + with self.assertWarns(DeprecationWarning): + converter = InstructionToQobjConverter(PulseQobjInstruction, meas_level=2) 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) + with self.assertWarns(DeprecationWarning): + 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)) - valid_qobj = PulseQobjInstruction( - name="acquire", t0=0, duration=10, qubits=[0], memory_slot=[0] - ) - self.assertEqual(converter(0, instruction), valid_qobj) + with self.assertWarns(DeprecationWarning): + valid_qobj = PulseQobjInstruction( + name="acquire", t0=0, duration=10, qubits=[0], memory_slot=[0] + ) + self.assertEqual(converter(0, instruction), valid_qobj) def test_snapshot(self): """Test converted qobj from Snapshot.""" - converter = InstructionToQobjConverter(PulseQobjInstruction, meas_level=2) + with self.assertWarns(DeprecationWarning): + converter = InstructionToQobjConverter(PulseQobjInstruction, meas_level=2) instruction = Snapshot(label="label", snapshot_type="type") - valid_qobj = PulseQobjInstruction(name="snapshot", t0=0, label="label", type="type") + with self.assertWarns(DeprecationWarning): + valid_qobj = PulseQobjInstruction(name="snapshot", t0=0, label="label", type="type") - self.assertEqual(converter(0, instruction), valid_qobj) + self.assertEqual(converter(0, instruction), valid_qobj) class TestQobjToInstructionConverter(QiskitTestCase): @@ -198,9 +221,10 @@ class TestQobjToInstructionConverter(QiskitTestCase): def setUp(self): super().setUp() self.linear = Waveform(np.arange(0, 0.01), name="linear") - self.pulse_library = [ - PulseLibraryItem(name=self.linear.name, samples=self.linear.samples.tolist()) - ] + with self.assertWarns(DeprecationWarning): + self.pulse_library = [ + PulseLibraryItem(name=self.linear.name, samples=self.linear.samples.tolist()) + ] self.converter = QobjToInstructionConverter(self.pulse_library, buffer=0) self.num_qubits = 2 @@ -208,7 +232,8 @@ def setUp(self): def test_drive_instruction(self): """Test converted qobj from PulseInstruction.""" instruction = Play(self.linear, DriveChannel(0)) - qobj = PulseQobjInstruction(name="linear", ch="d0", t0=10) + with self.assertWarns(DeprecationWarning): + qobj = PulseQobjInstruction(name="linear", ch="d0", t0=10) converted_instruction = self.converter(qobj) self.assertEqual(converted_instruction.instructions[0][-1], instruction) @@ -218,14 +243,15 @@ def test_parametric_pulses(self): Gaussian(duration=25, sigma=15, amp=0.5, angle=np.pi / 2, name="pulse1"), DriveChannel(0), ) - qobj = PulseQobjInstruction( - name="parametric_pulse", - label="pulse1", - pulse_shape="gaussian", - ch="d0", - t0=0, - parameters={"duration": 25, "sigma": 15, "amp": 0.5j}, - ) + with self.assertWarns(DeprecationWarning): + qobj = PulseQobjInstruction( + name="parametric_pulse", + label="pulse1", + pulse_shape="gaussian", + ch="d0", + t0=0, + parameters={"duration": 25, "sigma": 15, "amp": 0.5j}, + ) converted_instruction = self.converter(qobj) self.assertEqual(converted_instruction.start_time, 0) self.assertEqual(converted_instruction.duration, 25) @@ -238,19 +264,21 @@ def test_parametric_pulses_no_label(self): short_pulse_id = hashlib.md5(base_str.encode("utf-8")).hexdigest()[:4] pulse_name = f"gaussian_{short_pulse_id}" - qobj = PulseQobjInstruction( - name="parametric_pulse", - pulse_shape="gaussian", - ch="d0", - t0=0, - parameters={"duration": 25, "sigma": 15, "amp": -0.5 + 0.2j}, - ) + with self.assertWarns(DeprecationWarning): + qobj = PulseQobjInstruction( + name="parametric_pulse", + pulse_shape="gaussian", + ch="d0", + t0=0, + parameters={"duration": 25, "sigma": 15, "amp": -0.5 + 0.2j}, + ) 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.""" - qobj = PulseQobjInstruction(name="fc", ch="m0", t0=0, phase=0.1) + with self.assertWarns(DeprecationWarning): + qobj = PulseQobjInstruction(name="fc", ch="m0", t0=0, phase=0.1) converted_instruction = self.converter(qobj) instruction = ShiftPhase(0.1, MeasureChannel(0)) @@ -263,7 +291,8 @@ def test_parameterized_frame_change(self): instruction = ShiftPhase(4.0, MeasureChannel(0)) shifted = instruction << 10 - qobj = PulseQobjInstruction(name="fc", ch="m0", t0=10, phase="P1*2") + with self.assertWarns(DeprecationWarning): + qobj = PulseQobjInstruction(name="fc", ch="m0", t0=10, phase="P1*2") converted_instruction = self.converter(qobj) self.assertIsInstance(converted_instruction, Schedule) @@ -277,7 +306,8 @@ def test_parameterized_frame_change(self): def test_set_phase(self): """Test converted qobj from SetPhase.""" - qobj = PulseQobjInstruction(name="setp", ch="m0", t0=0, phase=3.14) + with self.assertWarns(DeprecationWarning): + qobj = PulseQobjInstruction(name="setp", ch="m0", t0=0, phase=3.14) converted_instruction = self.converter(qobj) instruction = SetPhase(3.14, MeasureChannel(0)) @@ -287,7 +317,8 @@ def test_set_phase(self): def test_parameterized_set_phase(self): """Test converted qobj from SetPhase, with parameterized phase.""" - qobj = PulseQobjInstruction(name="setp", ch="m0", t0=0, phase="p/2") + with self.assertWarns(DeprecationWarning): + qobj = PulseQobjInstruction(name="setp", ch="m0", t0=0, phase="p/2") converted_instruction = self.converter(qobj) self.assertIsInstance(converted_instruction, Schedule) @@ -303,7 +334,8 @@ def test_set_frequency(self): """Test converted qobj from SetFrequency.""" instruction = SetFrequency(8.0e9, DriveChannel(0)) - qobj = PulseQobjInstruction(name="setf", ch="d0", t0=0, frequency=8.0) + with self.assertWarns(DeprecationWarning): + qobj = PulseQobjInstruction(name="setf", ch="d0", t0=0, frequency=8.0) converted_instruction = self.converter(qobj) self.assertEqual(converted_instruction.start_time, 0) @@ -313,7 +345,8 @@ def test_set_frequency(self): def test_parameterized_set_frequency(self): """Test converted qobj from SetFrequency, when passing a parameterized frequency.""" - qobj = PulseQobjInstruction(name="setf", ch="d0", t0=2, frequency="f") + with self.assertWarns(DeprecationWarning): + qobj = PulseQobjInstruction(name="setf", ch="d0", t0=2, frequency="f") self.assertTrue("frequency" in qobj.to_dict()) converted_instruction = self.converter(qobj) @@ -332,7 +365,8 @@ def test_shift_frequency(self): """Test converted qobj from ShiftFrequency.""" instruction = ShiftFrequency(8.0e9, DriveChannel(0)) - qobj = PulseQobjInstruction(name="shiftf", ch="d0", t0=0, frequency=8.0) + with self.assertWarns(DeprecationWarning): + qobj = PulseQobjInstruction(name="shiftf", ch="d0", t0=0, frequency=8.0) converted_instruction = self.converter(qobj) self.assertEqual(converted_instruction.start_time, 0) @@ -342,9 +376,8 @@ def test_shift_frequency(self): def test_parameterized_shift_frequency(self): """Test converted qobj from ShiftFrequency, with a parameterized frequency.""" - instruction = ShiftFrequency(8.0e9, DriveChannel(0)) - - qobj = PulseQobjInstruction(name="shiftf", ch="d0", t0=1, frequency="f / 1000") + with self.assertWarns(DeprecationWarning): + qobj = PulseQobjInstruction(name="shiftf", ch="d0", t0=1, frequency="f / 1000") self.assertTrue("frequency" in qobj.to_dict()) converted_instruction = self.converter(qobj) @@ -363,7 +396,8 @@ def test_delay(self): """Test converted qobj from Delay.""" instruction = Delay(10, DriveChannel(0)) - qobj = PulseQobjInstruction(name="delay", ch="d0", t0=0, duration=10) + with self.assertWarns(DeprecationWarning): + qobj = PulseQobjInstruction(name="delay", ch="d0", t0=0, duration=10) converted_instruction = self.converter(qobj) self.assertTrue("delay" in qobj.to_dict().values()) @@ -382,17 +416,19 @@ def test_acquire(self): kernel=Kernel(name="test_kern", test_params="test"), discriminator=Discriminator(name="test_disc", test_params=1.0), ) - - qobj = PulseQobjInstruction( - name="acquire", - t0=0, - duration=10, - qubits=[0, 1], - memory_slot=[0, 1], - register_slot=[0, 1], - kernels=[QobjMeasurementOption(name="test_kern", params={"test_params": "test"})], - discriminators=[QobjMeasurementOption(name="test_disc", params={"test_params": 1.0})], - ) + with self.assertWarns(DeprecationWarning): + qobj = PulseQobjInstruction( + name="acquire", + t0=0, + duration=10, + qubits=[0, 1], + memory_slot=[0, 1], + register_slot=[0, 1], + kernels=[QobjMeasurementOption(name="test_kern", params={"test_params": "test"})], + discriminators=[ + QobjMeasurementOption(name="test_disc", params={"test_params": 1.0}) + ], + ) converted_instruction = self.converter(qobj) self.assertEqual(converted_instruction.start_time, 0) @@ -408,7 +444,8 @@ def test_snapshot(self): instruction = Snapshot(label="label", snapshot_type="type") shifted = instruction << 10 - qobj = PulseQobjInstruction(name="snapshot", t0=10, label="label", type="type") + with self.assertWarns(DeprecationWarning): + qobj = PulseQobjInstruction(name="snapshot", t0=10, label="label", type="type") converted_instruction = self.converter(qobj) self.assertEqual(converted_instruction.start_time, shifted.start_time) @@ -417,17 +454,22 @@ def test_snapshot(self): def test_instruction_name_collision(self): """Avoid command name collision of pulse library items.""" - pulse_library_from_backend_x = [ - PulseLibraryItem(name="pulse123", samples=[0.1, 0.1, 0.1]), - PulseLibraryItem(name="pulse456", samples=[0.3, 0.3, 0.3]), - ] + with self.assertWarns(DeprecationWarning): + pulse_library_from_backend_x = [ + 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) - pulse_library_from_backend_y = [PulseLibraryItem(name="pulse123", samples=[0.2, 0.2, 0.2])] + 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) - qobj1 = PulseQobjInstruction(name="pulse123", qubits=[0], t0=0, ch="d0") - qobj2 = PulseQobjInstruction(name="pulse456", qubits=[0], t0=0, ch="d0") + 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) @@ -446,21 +488,23 @@ class TestLoConverter(QiskitTestCase): def test_qubit_los(self): """Test qubit channel configuration.""" user_lo_config = LoConfig({DriveChannel(0): 1.3e9}) - converter = LoConfigConverter( - PulseQobjExperimentConfig, [1.2e9], [3.4e9], [(0.0, 5e9)], [(0.0, 5e9)] - ) - - valid_qobj = PulseQobjExperimentConfig(qubit_lo_freq=[1.3]) + with self.assertWarns(DeprecationWarning): + converter = LoConfigConverter( + PulseQobjExperimentConfig, [1.2e9], [3.4e9], [(0.0, 5e9)], [(0.0, 5e9)] + ) + valid_qobj = PulseQobjExperimentConfig(qubit_lo_freq=[1.3]) - self.assertEqual(converter(user_lo_config), valid_qobj) + with self.assertWarns(DeprecationWarning): + self.assertEqual(converter(user_lo_config), valid_qobj) def test_meas_los(self): """Test measurement channel configuration.""" user_lo_config = LoConfig({MeasureChannel(0): 3.5e9}) - converter = LoConfigConverter( - PulseQobjExperimentConfig, [1.2e9], [3.4e9], [(0.0, 5e9)], [(0.0, 5e9)] - ) + with self.assertWarns(DeprecationWarning): + converter = LoConfigConverter( + PulseQobjExperimentConfig, [1.2e9], [3.4e9], [(0.0, 5e9)], [(0.0, 5e9)] + ) - valid_qobj = PulseQobjExperimentConfig(meas_lo_freq=[3.5]) + valid_qobj = PulseQobjExperimentConfig(meas_lo_freq=[3.5]) - self.assertEqual(converter(user_lo_config), valid_qobj) + self.assertEqual(converter(user_lo_config), valid_qobj) diff --git a/test/python/qobj/test_qobj.py b/test/python/qobj/test_qobj.py index c0b96a1bda5e..ae59d6de00a5 100644 --- a/test/python/qobj/test_qobj.py +++ b/test/python/qobj/test_qobj.py @@ -41,19 +41,20 @@ class TestQASMQobj(QiskitTestCase): def setUp(self): super().setUp() - self.valid_qobj = QasmQobj( - qobj_id="12345", - header=QobjHeader(), - config=QasmQobjConfig(shots=1024, memory_slots=2), - experiments=[ - QasmQobjExperiment( - instructions=[ - QasmQobjInstruction(name="u1", qubits=[1], params=[0.4]), - QasmQobjInstruction(name="u2", qubits=[1], params=[0.4, 0.2]), - ] - ) - ], - ) + with self.assertWarns(DeprecationWarning): + self.valid_qobj = QasmQobj( + qobj_id="12345", + header=QobjHeader(), + config=QasmQobjConfig(shots=1024, memory_slots=2), + experiments=[ + QasmQobjExperiment( + instructions=[ + QasmQobjInstruction(name="u1", qubits=[1], params=[0.4]), + QasmQobjInstruction(name="u2", qubits=[1], params=[0.4, 0.2]), + ] + ) + ], + ) self.valid_dict = { "qobj_id": "12345", @@ -70,55 +71,59 @@ def setUp(self): } ], } - - self.bad_qobj = copy.deepcopy(self.valid_qobj) + with self.assertWarns(DeprecationWarning): + self.bad_qobj = copy.deepcopy(self.valid_qobj) self.bad_qobj.experiments = [] def test_from_dict_per_class(self): """Test Qobj and its subclass representations given a dictionary.""" - test_parameters = { - QasmQobj: (self.valid_qobj, self.valid_dict), - QasmQobjConfig: ( - QasmQobjConfig(shots=1, memory_slots=2), - {"shots": 1, "memory_slots": 2}, - ), - QasmQobjExperiment: ( - QasmQobjExperiment( - instructions=[QasmQobjInstruction(name="u1", qubits=[1], params=[0.4])] + with self.assertWarns(DeprecationWarning): + test_parameters = { + QasmQobj: (self.valid_qobj, self.valid_dict), + QasmQobjConfig: ( + QasmQobjConfig(shots=1, memory_slots=2), + {"shots": 1, "memory_slots": 2}, ), - {"instructions": [{"name": "u1", "qubits": [1], "params": [0.4]}]}, - ), - QasmQobjInstruction: ( - QasmQobjInstruction(name="u1", qubits=[1], params=[0.4]), - {"name": "u1", "qubits": [1], "params": [0.4]}, - ), - } + QasmQobjExperiment: ( + QasmQobjExperiment( + instructions=[QasmQobjInstruction(name="u1", qubits=[1], params=[0.4])] + ), + {"instructions": [{"name": "u1", "qubits": [1], "params": [0.4]}]}, + ), + QasmQobjInstruction: ( + QasmQobjInstruction(name="u1", qubits=[1], params=[0.4]), + {"name": "u1", "qubits": [1], "params": [0.4]}, + ), + } for qobj_class, (qobj_item, expected_dict) in test_parameters.items(): with self.subTest(msg=str(qobj_class)): - self.assertEqual(qobj_item, qobj_class.from_dict(expected_dict)) + with self.assertWarns(DeprecationWarning): + qobj = qobj_class.from_dict(expected_dict) + self.assertEqual(qobj_item, qobj) def test_snapshot_instruction_to_dict(self): """Test snapshot instruction to dict.""" - valid_qobj = QasmQobj( - qobj_id="12345", - header=QobjHeader(), - config=QasmQobjConfig(shots=1024, memory_slots=2), - experiments=[ - QasmQobjExperiment( - instructions=[ - QasmQobjInstruction(name="u1", qubits=[1], params=[0.4]), - QasmQobjInstruction(name="u2", qubits=[1], params=[0.4, 0.2]), - QasmQobjInstruction( - name="snapshot", - qubits=[1], - snapshot_type="statevector", - label="my_snap", - ), - ] - ) - ], - ) + with self.assertWarns(DeprecationWarning): + valid_qobj = QasmQobj( + qobj_id="12345", + header=QobjHeader(), + config=QasmQobjConfig(shots=1024, memory_slots=2), + experiments=[ + QasmQobjExperiment( + instructions=[ + QasmQobjInstruction(name="u1", qubits=[1], params=[0.4]), + QasmQobjInstruction(name="u2", qubits=[1], params=[0.4, 0.2]), + QasmQobjInstruction( + name="snapshot", + qubits=[1], + snapshot_type="statevector", + label="my_snap", + ), + ] + ) + ], + ) res = valid_qobj.to_dict() expected_dict = { "qobj_id": "12345", @@ -147,25 +152,26 @@ def test_snapshot_instruction_to_dict(self): def test_snapshot_instruction_from_dict(self): """Test snapshot instruction from dict.""" - expected_qobj = QasmQobj( - qobj_id="12345", - header=QobjHeader(), - config=QasmQobjConfig(shots=1024, memory_slots=2), - experiments=[ - QasmQobjExperiment( - instructions=[ - QasmQobjInstruction(name="u1", qubits=[1], params=[0.4]), - QasmQobjInstruction(name="u2", qubits=[1], params=[0.4, 0.2]), - QasmQobjInstruction( - name="snapshot", - qubits=[1], - snapshot_type="statevector", - label="my_snap", - ), - ] - ) - ], - ) + with self.assertWarns(DeprecationWarning): + expected_qobj = QasmQobj( + qobj_id="12345", + header=QobjHeader(), + config=QasmQobjConfig(shots=1024, memory_slots=2), + experiments=[ + QasmQobjExperiment( + instructions=[ + QasmQobjInstruction(name="u1", qubits=[1], params=[0.4]), + QasmQobjInstruction(name="u2", qubits=[1], params=[0.4, 0.2]), + QasmQobjInstruction( + name="snapshot", + qubits=[1], + snapshot_type="statevector", + label="my_snap", + ), + ] + ) + ], + ) qobj_dict = { "qobj_id": "12345", "type": "QASM", @@ -187,7 +193,9 @@ def test_snapshot_instruction_from_dict(self): } ], } - self.assertEqual(expected_qobj, QasmQobj.from_dict(qobj_dict)) + with self.assertWarns(DeprecationWarning): + qobj = QasmQobj.from_dict(qobj_dict) + self.assertEqual(expected_qobj, qobj) def test_change_qobj_after_compile(self): """Test modifying Qobj parameters after compile.""" @@ -202,7 +210,8 @@ def test_change_qobj_after_compile(self): qc1.measure(qr, cr) qc2.measure(qr, cr) circuits = [qc1, qc2] - qobj1 = assemble(circuits, shots=1024, seed=88) + with self.assertWarns(DeprecationWarning): + qobj1 = assemble(circuits, shots=1024, seed=88) qobj1.experiments[0].config.shots = 50 qobj1.experiments[1].config.shots = 1 self.assertTrue(qobj1.experiments[0].config.shots == 50) @@ -211,27 +220,28 @@ def test_change_qobj_after_compile(self): def test_gate_calibrations_to_dict(self): """Test gate calibrations to dict.""" - - pulse_library = [PulseLibraryItem(name="test", samples=[1j, 1j])] - valid_qobj = QasmQobj( - qobj_id="12345", - header=QobjHeader(), - config=QasmQobjConfig(shots=1024, memory_slots=2, pulse_library=pulse_library), - experiments=[ - QasmQobjExperiment( - instructions=[QasmQobjInstruction(name="u1", qubits=[1], params=[0.4])], - config=QasmQobjConfig( - calibrations=QasmExperimentCalibrations( - gates=[ - GateCalibration( - name="u1", qubits=[1], params=[0.4], instructions=[] - ) - ] - ) - ), - ) - ], - ) + with self.assertWarns(DeprecationWarning): + pulse_library = [PulseLibraryItem(name="test", samples=[1j, 1j])] + with self.assertWarns(DeprecationWarning): + valid_qobj = QasmQobj( + qobj_id="12345", + header=QobjHeader(), + config=QasmQobjConfig(shots=1024, memory_slots=2, pulse_library=pulse_library), + experiments=[ + QasmQobjExperiment( + instructions=[QasmQobjInstruction(name="u1", qubits=[1], params=[0.4])], + config=QasmQobjConfig( + calibrations=QasmExperimentCalibrations( + gates=[ + GateCalibration( + name="u1", qubits=[1], params=[0.4], instructions=[] + ) + ] + ) + ), + ) + ], + ) res = valid_qobj.to_dict() expected_dict = { "qobj_id": "12345", @@ -265,48 +275,51 @@ class TestPulseQobj(QiskitTestCase): def setUp(self): super().setUp() - self.valid_qobj = PulseQobj( - qobj_id="12345", - header=QobjHeader(), - config=PulseQobjConfig( - shots=1024, - memory_slots=2, - meas_level=1, - memory_slot_size=8192, - meas_return="avg", - pulse_library=[ - PulseLibraryItem(name="pulse0", samples=[0.0 + 0.0j, 0.5 + 0.0j, 0.0 + 0.0j]) + with self.assertWarns(DeprecationWarning): + self.valid_qobj = PulseQobj( + qobj_id="12345", + header=QobjHeader(), + config=PulseQobjConfig( + shots=1024, + memory_slots=2, + meas_level=1, + memory_slot_size=8192, + meas_return="avg", + pulse_library=[ + PulseLibraryItem( + name="pulse0", samples=[0.0 + 0.0j, 0.5 + 0.0j, 0.0 + 0.0j] + ) + ], + qubit_lo_freq=[4.9], + meas_lo_freq=[6.9], + rep_time=1000, + ), + experiments=[ + PulseQobjExperiment( + instructions=[ + PulseQobjInstruction(name="pulse0", t0=0, ch="d0"), + PulseQobjInstruction(name="fc", t0=5, ch="d0", phase=1.57), + PulseQobjInstruction(name="fc", t0=5, ch="d0", phase=0.0), + PulseQobjInstruction(name="fc", t0=5, ch="d0", phase="P1"), + PulseQobjInstruction(name="setp", t0=10, ch="d0", phase=3.14), + PulseQobjInstruction(name="setf", t0=10, ch="d0", frequency=8.0), + PulseQobjInstruction(name="shiftf", t0=10, ch="d0", frequency=4.0), + PulseQobjInstruction( + name="acquire", + t0=15, + duration=5, + qubits=[0], + memory_slot=[0], + kernels=[ + QobjMeasurementOption( + name="boxcar", params={"start_window": 0, "stop_window": 5} + ) + ], + ), + ] + ) ], - qubit_lo_freq=[4.9], - meas_lo_freq=[6.9], - rep_time=1000, - ), - experiments=[ - PulseQobjExperiment( - instructions=[ - PulseQobjInstruction(name="pulse0", t0=0, ch="d0"), - PulseQobjInstruction(name="fc", t0=5, ch="d0", phase=1.57), - PulseQobjInstruction(name="fc", t0=5, ch="d0", phase=0.0), - PulseQobjInstruction(name="fc", t0=5, ch="d0", phase="P1"), - PulseQobjInstruction(name="setp", t0=10, ch="d0", phase=3.14), - PulseQobjInstruction(name="setf", t0=10, ch="d0", frequency=8.0), - PulseQobjInstruction(name="shiftf", t0=10, ch="d0", frequency=4.0), - PulseQobjInstruction( - name="acquire", - t0=15, - duration=5, - qubits=[0], - memory_slot=[0], - kernels=[ - QobjMeasurementOption( - name="boxcar", params={"start_window": 0, "stop_window": 5} - ) - ], - ), - ] - ) - ], - ) + ) self.valid_dict = { "qobj_id": "12345", "type": "PULSE", @@ -350,87 +363,91 @@ def setUp(self): def test_from_dict_per_class(self): """Test converting to Qobj and its subclass representations given a dictionary.""" - test_parameters = { - PulseQobj: (self.valid_qobj, self.valid_dict), - PulseQobjConfig: ( - PulseQobjConfig( - meas_level=1, - memory_slot_size=8192, - meas_return="avg", - pulse_library=[PulseLibraryItem(name="pulse0", samples=[0.1 + 0.0j])], - qubit_lo_freq=[4.9], - meas_lo_freq=[6.9], - rep_time=1000, + with self.assertWarns(DeprecationWarning): + test_parameters = { + PulseQobj: (self.valid_qobj, self.valid_dict), + PulseQobjConfig: ( + PulseQobjConfig( + meas_level=1, + memory_slot_size=8192, + meas_return="avg", + pulse_library=[PulseLibraryItem(name="pulse0", samples=[0.1 + 0.0j])], + qubit_lo_freq=[4.9], + meas_lo_freq=[6.9], + rep_time=1000, + ), + { + "meas_level": 1, + "memory_slot_size": 8192, + "meas_return": "avg", + "pulse_library": [{"name": "pulse0", "samples": [0.1 + 0j]}], + "qubit_lo_freq": [4.9], + "meas_lo_freq": [6.9], + "rep_time": 1000, + }, ), - { - "meas_level": 1, - "memory_slot_size": 8192, - "meas_return": "avg", - "pulse_library": [{"name": "pulse0", "samples": [0.1 + 0j]}], - "qubit_lo_freq": [4.9], - "meas_lo_freq": [6.9], - "rep_time": 1000, - }, - ), - PulseLibraryItem: ( - PulseLibraryItem(name="pulse0", samples=[0.1 + 0.0j]), - {"name": "pulse0", "samples": [0.1 + 0j]}, - ), - PulseQobjExperiment: ( - PulseQobjExperiment( - instructions=[PulseQobjInstruction(name="pulse0", t0=0, ch="d0")] + PulseLibraryItem: ( + PulseLibraryItem(name="pulse0", samples=[0.1 + 0.0j]), + {"name": "pulse0", "samples": [0.1 + 0j]}, ), - {"instructions": [{"name": "pulse0", "t0": 0, "ch": "d0"}]}, - ), - PulseQobjInstruction: ( - PulseQobjInstruction(name="pulse0", t0=0, ch="d0"), - {"name": "pulse0", "t0": 0, "ch": "d0"}, - ), - } + PulseQobjExperiment: ( + PulseQobjExperiment( + instructions=[PulseQobjInstruction(name="pulse0", t0=0, ch="d0")] + ), + {"instructions": [{"name": "pulse0", "t0": 0, "ch": "d0"}]}, + ), + PulseQobjInstruction: ( + PulseQobjInstruction(name="pulse0", t0=0, ch="d0"), + {"name": "pulse0", "t0": 0, "ch": "d0"}, + ), + } for qobj_class, (qobj_item, expected_dict) in test_parameters.items(): with self.subTest(msg=str(qobj_class)): - self.assertEqual(qobj_item, qobj_class.from_dict(expected_dict)) + with self.assertWarns(DeprecationWarning): + qobj = qobj_class.from_dict(expected_dict) + self.assertEqual(qobj_item, qobj) def test_to_dict_per_class(self): """Test converting from Qobj and its subclass representations given a dictionary.""" - test_parameters = { - PulseQobj: (self.valid_qobj, self.valid_dict), - PulseQobjConfig: ( - PulseQobjConfig( - meas_level=1, - memory_slot_size=8192, - meas_return="avg", - pulse_library=[PulseLibraryItem(name="pulse0", samples=[0.1 + 0.0j])], - qubit_lo_freq=[4.9], - meas_lo_freq=[6.9], - rep_time=1000, + with self.assertWarns(DeprecationWarning): + test_parameters = { + PulseQobj: (self.valid_qobj, self.valid_dict), + PulseQobjConfig: ( + PulseQobjConfig( + meas_level=1, + memory_slot_size=8192, + meas_return="avg", + pulse_library=[PulseLibraryItem(name="pulse0", samples=[0.1 + 0.0j])], + qubit_lo_freq=[4.9], + meas_lo_freq=[6.9], + rep_time=1000, + ), + { + "meas_level": 1, + "memory_slot_size": 8192, + "meas_return": "avg", + "pulse_library": [{"name": "pulse0", "samples": [0.1 + 0j]}], + "qubit_lo_freq": [4.9], + "meas_lo_freq": [6.9], + "rep_time": 1000, + }, ), - { - "meas_level": 1, - "memory_slot_size": 8192, - "meas_return": "avg", - "pulse_library": [{"name": "pulse0", "samples": [0.1 + 0j]}], - "qubit_lo_freq": [4.9], - "meas_lo_freq": [6.9], - "rep_time": 1000, - }, - ), - PulseLibraryItem: ( - PulseLibraryItem(name="pulse0", samples=[0.1 + 0.0j]), - {"name": "pulse0", "samples": [0.1 + 0j]}, - ), - PulseQobjExperiment: ( - PulseQobjExperiment( - instructions=[PulseQobjInstruction(name="pulse0", t0=0, ch="d0")] + PulseLibraryItem: ( + PulseLibraryItem(name="pulse0", samples=[0.1 + 0.0j]), + {"name": "pulse0", "samples": [0.1 + 0j]}, ), - {"instructions": [{"name": "pulse0", "t0": 0, "ch": "d0"}]}, - ), - PulseQobjInstruction: ( - PulseQobjInstruction(name="pulse0", t0=0, ch="d0"), - {"name": "pulse0", "t0": 0, "ch": "d0"}, - ), - } + PulseQobjExperiment: ( + PulseQobjExperiment( + instructions=[PulseQobjInstruction(name="pulse0", t0=0, ch="d0")] + ), + {"instructions": [{"name": "pulse0", "t0": 0, "ch": "d0"}]}, + ), + PulseQobjInstruction: ( + PulseQobjInstruction(name="pulse0", t0=0, ch="d0"), + {"name": "pulse0", "t0": 0, "ch": "d0"}, + ), + } for qobj_class, (qobj_item, expected_dict) in test_parameters.items(): with self.subTest(msg=str(qobj_class)): diff --git a/test/python/qobj/test_qobj_identifiers.py b/test/python/qobj/test_qobj_identifiers.py index d319aa4611de..84eb58a1d782 100644 --- a/test/python/qobj/test_qobj_identifiers.py +++ b/test/python/qobj/test_qobj_identifiers.py @@ -36,7 +36,8 @@ def setUp(self): self.circuits = [qc] def test_qobj_identifiers(self): - qobj = assemble(self.circuits) + with self.assertWarns(DeprecationWarning): + qobj = assemble(self.circuits) exp = qobj.experiments[0] self.assertIn(self.qr_name, (x[0] for x in exp.header.qubit_labels)) self.assertIn(self.cr_name, (x[0] for x in exp.header.clbit_labels)) From 76e6dd598401756632bf388ab62f01c1caa2a0cf Mon Sep 17 00:00:00 2001 From: Luciano Bello Date: Mon, 24 Jun 2024 22:12:51 +0200 Subject: [PATCH 02/51] reno --- releasenotes/notes/qobj_assemble-f745a12fd88ba9fb.yaml | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 releasenotes/notes/qobj_assemble-f745a12fd88ba9fb.yaml diff --git a/releasenotes/notes/qobj_assemble-f745a12fd88ba9fb.yaml b/releasenotes/notes/qobj_assemble-f745a12fd88ba9fb.yaml new file mode 100644 index 000000000000..8817020e742a --- /dev/null +++ b/releasenotes/notes/qobj_assemble-f745a12fd88ba9fb.yaml @@ -0,0 +1,4 @@ +--- +deprecations_providers: + - | + With the deprecation of BackendV1, the Qobj structure is not necessary and it is deprecated. Hence, the related tools such as the function assemble are also deprecated. From a39842550b6aa2a80905d2c3c9d23c956e2071d3 Mon Sep 17 00:00:00 2001 From: Luciano Bello Date: Thu, 27 Jun 2024 16:19:55 +0200 Subject: [PATCH 03/51] shallow deprecation of assemble --- qiskit/assembler/assemble_circuits.py | 142 +++++++++++------- qiskit/circuit/instruction.py | 17 ++- qiskit/compiler/assembler.py | 85 +++++++++-- .../basic_provider/basic_simulator.py | 4 +- qiskit/qobj/common.py | 2 +- qiskit/result/models.py | 5 +- qiskit/result/result.py | 4 +- 7 files changed, 186 insertions(+), 73 deletions(-) diff --git a/qiskit/assembler/assemble_circuits.py b/qiskit/assembler/assemble_circuits.py index a3d9b6bbb549..13187089d631 100644 --- a/qiskit/assembler/assemble_circuits.py +++ b/qiskit/assembler/assemble_circuits.py @@ -12,6 +12,7 @@ """Assemble function for converting a list of circuits into a qobj.""" import copy +import warnings from collections import defaultdict from typing import Dict, List, Optional, Tuple @@ -35,6 +36,7 @@ QobjHeader, ) from qiskit.utils.parallel import parallel_map +from qiskit.utils import deprecate_func PulseLibrary = Dict[str, List[complex]] @@ -87,20 +89,24 @@ def _assemble_circuit( metadata = circuit.metadata if metadata is None: metadata = {} - header = QobjExperimentHeader( - qubit_labels=qubit_labels, - n_qubits=num_qubits, - qreg_sizes=qreg_sizes, - clbit_labels=clbit_labels, - memory_slots=memory_slots, - creg_sizes=creg_sizes, - name=circuit.name, - global_phase=float(circuit.global_phase), - metadata=metadata, - ) + with warnings.catch_warnings(): + warnings.simplefilter("ignore", category=DeprecationWarning) + header = QobjExperimentHeader( + qubit_labels=qubit_labels, + n_qubits=num_qubits, + qreg_sizes=qreg_sizes, + clbit_labels=clbit_labels, + memory_slots=memory_slots, + creg_sizes=creg_sizes, + name=circuit.name, + global_phase=float(circuit.global_phase), + metadata=metadata, + ) # TODO: why do we need n_qubits and memory_slots in both the header and the config - config = QasmQobjExperimentConfig(n_qubits=num_qubits, memory_slots=memory_slots) + with warnings.catch_warnings(): + warnings.simplefilter("ignore", category=DeprecationWarning) + config = QasmQobjExperimentConfig(n_qubits=num_qubits, memory_slots=memory_slots) calibrations, pulse_library = _assemble_pulse_gates(circuit, run_config) if calibrations: config.calibrations = calibrations @@ -118,7 +124,7 @@ def _assemble_circuit( instructions = [] for op_context in circuit.data: - instruction = op_context.operation.assemble() + instruction = op_context.operation._assemble() # Add register attributes to the instruction qargs = op_context.qubits @@ -166,10 +172,12 @@ def _assemble_circuit( del instruction._condition instructions.append(instruction) - return ( - QasmQobjExperiment(instructions=instructions, header=header, config=config), - pulse_library, - ) + with warnings.catch_warnings(): + warnings.simplefilter("ignore", category=DeprecationWarning) + return ( + QasmQobjExperiment(instructions=instructions, header=header, config=config), + pulse_library, + ) def _assemble_pulse_gates( @@ -299,41 +307,9 @@ def _configure_experiment_los( return experiments -def assemble_circuits( +def _assemble_circuits( circuits: List[QuantumCircuit], run_config: RunConfig, qobj_id: int, qobj_header: QobjHeader ) -> QasmQobj: - """Assembles a list of circuits into a qobj that can be run on the backend. - - Args: - circuits: circuit(s) to assemble - run_config: configuration of the runtime environment - qobj_id: identifier for the generated qobj - qobj_header: header to pass to the results - - Returns: - The qobj to be run on the backends - - Examples: - - .. code-block:: python - - from qiskit.circuit import QuantumRegister, ClassicalRegister, QuantumCircuit - from qiskit.assembler import assemble_circuits - from qiskit.assembler.run_config import RunConfig - # Build a circuit to convert into a Qobj - q = QuantumRegister(2) - c = ClassicalRegister(2) - qc = QuantumCircuit(q, c) - qc.h(q[0]) - qc.cx(q[0], q[1]) - qc.measure(q, c) - # Assemble a Qobj from the input circuit - qobj = assemble_circuits(circuits=[qc], - qobj_id="custom-id", - qobj_header=[], - run_config=RunConfig(shots=2000, memory=True, init_qubits=True)) - """ - # assemble the circuit experiments experiments_and_pulse_libs = parallel_map(_assemble_circuit, circuits, [run_config]) experiments = [] pulse_library = {} @@ -346,10 +322,16 @@ def assemble_circuits( experiments, calibrations = _extract_common_calibrations(experiments) # configure LO freqs per circuit - lo_converter = converters.LoConfigConverter(QasmQobjExperimentConfig, **run_config.to_dict()) + with warnings.catch_warnings(): + warnings.simplefilter("ignore", category=DeprecationWarning) + lo_converter = converters.LoConfigConverter( + QasmQobjExperimentConfig, **run_config.to_dict() + ) experiments = _configure_experiment_los(experiments, lo_converter, run_config) - qobj_config = QasmQobjConfig() + with warnings.catch_warnings(): + warnings.simplefilter("ignore", category=DeprecationWarning) + qobj_config = QasmQobjConfig() if run_config: qobj_config_dict = run_config.to_dict() @@ -379,7 +361,9 @@ def assemble_circuits( if m_los: qobj_config_dict["meas_lo_freq"] = [freq / 1e9 for freq in m_los] - qobj_config = QasmQobjConfig(**qobj_config_dict) + with warnings.catch_warnings(): + warnings.simplefilter("ignore", category=DeprecationWarning) + qobj_config = QasmQobjConfig(**qobj_config_dict) qubit_sizes = [] memory_slot_sizes = [] @@ -402,7 +386,53 @@ def assemble_circuits( if calibrations and calibrations.gates: qobj_config.calibrations = calibrations + with warnings.catch_warnings(): + warnings.simplefilter("ignore", category=DeprecationWarning) + return QasmQobj( + qobj_id=qobj_id, config=qobj_config, experiments=experiments, header=qobj_header + ) - return QasmQobj( - qobj_id=qobj_id, config=qobj_config, experiments=experiments, header=qobj_header - ) + +@deprecate_func( + since="1.2", + removal_timeline="in the 2.0 release", + additional_msg="The function assemble_circuits is being deprecated " + "as they are not necessary for BackendV2. If user still need Qobj, that probably " + "means that they are using a backend based on the deprecated BackendV1 class.", +) +def assemble_circuits( + circuits: List[QuantumCircuit], run_config: RunConfig, qobj_id: int, qobj_header: QobjHeader +) -> QasmQobj: + """Assembles a list of circuits into a qobj that can be run on the backend. + + Args: + circuits: circuit(s) to assemble + run_config: configuration of the runtime environment + qobj_id: identifier for the generated qobj + qobj_header: header to pass to the results + + Returns: + The qobj to be run on the backends + + Examples: + + .. code-block:: python + + from qiskit.circuit import QuantumRegister, ClassicalRegister, QuantumCircuit + from qiskit.assembler import assemble_circuits + from qiskit.assembler.run_config import RunConfig + # Build a circuit to convert into a Qobj + q = QuantumRegister(2) + c = ClassicalRegister(2) + qc = QuantumCircuit(q, c) + qc.h(q[0]) + qc.cx(q[0], q[1]) + qc.measure(q, c) + # Assemble a Qobj from the input circuit + qobj = assemble_circuits(circuits=[qc], + qobj_id="custom-id", + qobj_header=[], + run_config=RunConfig(shots=2000, memory=True, init_qubits=True)) + """ + # assemble the circuit experiments + return _assemble_circuits(circuits, run_config, qobj_id, qobj_header) diff --git a/qiskit/circuit/instruction.py b/qiskit/circuit/instruction.py index 1b5fca3f738b..2e1ae9ae7235 100644 --- a/qiskit/circuit/instruction.py +++ b/qiskit/circuit/instruction.py @@ -34,6 +34,7 @@ from __future__ import annotations import copy +import warnings from itertools import zip_longest import math from typing import List, Type @@ -47,7 +48,7 @@ from qiskit.circuit.operation import Operation from qiskit.circuit.annotated_operation import AnnotatedOperation, InverseModifier - +from qiskit.utils import deprecate_func _CUTOFF_PRECISION = 1e-10 @@ -358,9 +359,21 @@ def unit(self, unit): """Set the time unit of duration.""" self._unit = unit + @deprecate_func( + since="1.2", + removal_timeline="in the 2.0 release", + additional_msg="The method assemble is being deprecated " + "as it is not necessary for BackendV2. If user still need Qobj, that probably " + "means that they are using a backend based on the deprecated BackendV1 class.", + ) def assemble(self): """Assemble a QasmQobjInstruction""" - instruction = QasmQobjInstruction(name=self.name) + return self._assemble() + + def _assemble(self): + with warnings.catch_warnings(): + warnings.simplefilter("ignore", category=DeprecationWarning) + instruction = QasmQobjInstruction(name=self.name) # Evaluate parameters if self.params: params = [x.evalf(x) if hasattr(x, "evalf") else x for x in self.params] diff --git a/qiskit/compiler/assembler.py b/qiskit/compiler/assembler.py index 4417c0666fb4..3b6b22e11b86 100644 --- a/qiskit/compiler/assembler.py +++ b/qiskit/compiler/assembler.py @@ -20,7 +20,7 @@ import numpy as np -from qiskit.assembler import assemble_circuits, assemble_schedules +from qiskit.assembler import assemble_schedules from qiskit.assembler.run_config import RunConfig from qiskit.circuit import Parameter, QuantumCircuit, Qubit from qiskit.exceptions import QiskitError @@ -30,6 +30,7 @@ from qiskit.qobj import QasmQobj, PulseQobj, QobjHeader from qiskit.qobj.utils import MeasLevel, MeasReturnType from qiskit.utils import deprecate_func +from qiskit.assembler.assemble_circuits import _assemble_circuits logger = logging.getLogger(__name__) @@ -89,7 +90,7 @@ def assemble( to create ``Qobj`` "experiments". It further annotates the experiment payload with header and configurations. - NOTE: Backend.options is not used within assemble. The required values + NOTE: ``Backend.options`` is not used within assemble. The required values (previously given by backend.set_options) should be manually extracted from options and supplied directly when calling. @@ -161,27 +162,91 @@ def assemble( Raises: QiskitError: if the input cannot be interpreted as either circuits or schedules """ - start_time = time() - experiments = experiments if isinstance(experiments, list) else [experiments] - pulse_qobj = any(isinstance(exp, (ScheduleBlock, Schedule, Instruction)) for exp in experiments) - qobj_id, qobj_header, run_config_common_dict = _parse_common_args( + return _assemble( + experiments, backend, qobj_id, qobj_header, shots, memory, seed_simulator, - init_qubits, - rep_delay, qubit_lo_freq, meas_lo_freq, qubit_lo_range, meas_lo_range, schedule_los, - pulse_qobj=pulse_qobj, + meas_level, + meas_return, + meas_map, + memory_slot_size, + rep_time, + rep_delay, + parameter_binds, + parametric_pulses, + init_qubits, **run_config, ) + +def _assemble( + experiments: Union[ + QuantumCircuit, + List[QuantumCircuit], + Schedule, + List[Schedule], + ScheduleBlock, + List[ScheduleBlock], + ], + backend: Optional[Backend] = None, + qobj_id: Optional[str] = None, + qobj_header: Optional[Union[QobjHeader, Dict]] = None, + shots: Optional[int] = None, + memory: Optional[bool] = False, + seed_simulator: Optional[int] = None, + qubit_lo_freq: Optional[List[float]] = None, + meas_lo_freq: Optional[List[float]] = None, + qubit_lo_range: Optional[List[float]] = None, + meas_lo_range: Optional[List[float]] = None, + schedule_los: Optional[ + Union[ + List[Union[Dict[PulseChannel, float], LoConfig]], + Union[Dict[PulseChannel, float], LoConfig], + ] + ] = None, + meas_level: Union[int, MeasLevel] = MeasLevel.CLASSIFIED, + meas_return: Union[str, MeasReturnType] = MeasReturnType.AVERAGE, + meas_map: Optional[List[List[Qubit]]] = None, + memory_slot_size: int = 100, + rep_time: Optional[int] = None, + rep_delay: Optional[float] = None, + parameter_binds: Optional[List[Dict[Parameter, float]]] = None, + parametric_pulses: Optional[List[str]] = None, + init_qubits: bool = True, + **run_config: Dict, +) -> Union[QasmQobj, PulseQobj]: + start_time = time() + experiments = experiments if isinstance(experiments, list) else [experiments] + pulse_qobj = any(isinstance(exp, (ScheduleBlock, Schedule, Instruction)) for exp in experiments) + with warnings.catch_warnings(): + warnings.simplefilter("ignore", category=DeprecationWarning) + qobj_id, qobj_header, run_config_common_dict = _parse_common_args( + backend, + qobj_id, + qobj_header, + shots, + memory, + seed_simulator, + init_qubits, + rep_delay, + qubit_lo_freq, + meas_lo_freq, + qubit_lo_range, + meas_lo_range, + schedule_los, + pulse_qobj=pulse_qobj, + **run_config, + ) + # assemble either circuits or schedules if all(isinstance(exp, QuantumCircuit) for exp in experiments): run_config = _parse_circuit_args( @@ -199,7 +264,7 @@ def assemble( ) end_time = time() _log_assembly_time(start_time, end_time) - return assemble_circuits( + return _assemble_circuits( circuits=bound_experiments, qobj_id=qobj_id, qobj_header=qobj_header, diff --git a/qiskit/providers/basic_provider/basic_simulator.py b/qiskit/providers/basic_provider/basic_simulator.py index 9971bf36725c..1d1205294677 100644 --- a/qiskit/providers/basic_provider/basic_simulator.py +++ b/qiskit/providers/basic_provider/basic_simulator.py @@ -525,7 +525,7 @@ def run( } """ # TODO: replace assemble with new run flow - from qiskit.compiler import assemble + from qiskit.compiler.assembler import _assemble out_options = {} for key, value in backend_options.items(): @@ -535,7 +535,7 @@ def run( ) else: out_options[key] = value - qobj = assemble(run_input, self, **out_options) + qobj = _assemble(run_input, self, **out_options) qobj_options = qobj.config self._set_options(qobj_config=qobj_options, backend_options=backend_options) job_id = str(uuid.uuid4()) diff --git a/qiskit/qobj/common.py b/qiskit/qobj/common.py index f9abb32282b5..9a3fdd4e20e2 100644 --- a/qiskit/qobj/common.py +++ b/qiskit/qobj/common.py @@ -26,7 +26,7 @@ class QobjDictField(SimpleNamespace): @deprecate_func( since="1.2", removal_timeline="in the 2.0 release", - additional_msg="The full Qobj module is being deprecated, including QobjDictField subclasses, " + additional_msg="The full Qobj module is being deprecated, including QobjDictField's subclasses, " "as they are not necessary for BackendV2. If user still need Qobj, that probably " "means that they are using a backend based on the deprecated BackendV1 class.", ) diff --git a/qiskit/result/models.py b/qiskit/result/models.py index 83d9e4e78d5f..3eabbdd2f14f 100644 --- a/qiskit/result/models.py +++ b/qiskit/result/models.py @@ -13,6 +13,7 @@ """Schema and helper models for schema-conformant Results.""" import copy +import warnings from qiskit.qobj.utils import MeasReturnType, MeasLevel from qiskit.qobj import QobjExperimentHeader @@ -223,7 +224,9 @@ def from_dict(cls, data): in_data = copy.copy(data) data_obj = ExperimentResultData.from_dict(in_data.pop("data")) if "header" in in_data: - in_data["header"] = QobjExperimentHeader.from_dict(in_data.pop("header")) + with warnings.catch_warnings(): + warnings.simplefilter("ignore", category=DeprecationWarning) + in_data["header"] = QobjExperimentHeader.from_dict(in_data.pop("header")) shots = in_data.pop("shots") success = in_data.pop("success") diff --git a/qiskit/result/result.py b/qiskit/result/result.py index 7df365785166..1f8519c4b469 100644 --- a/qiskit/result/result.py +++ b/qiskit/result/result.py @@ -125,7 +125,9 @@ def from_dict(cls, data): in_data = copy.copy(data) in_data["results"] = [ExperimentResult.from_dict(x) for x in in_data.pop("results")] if in_data.get("header") is not None: - in_data["header"] = QobjHeader.from_dict(in_data.pop("header")) + with warnings.catch_warnings(): + warnings.simplefilter("ignore", category=DeprecationWarning) + in_data["header"] = QobjHeader.from_dict(in_data.pop("header")) return cls(**in_data) def data(self, experiment=None): From 6d96cc8a6d3d317eb33045f9deffd79db9ff90da Mon Sep 17 00:00:00 2001 From: Luciano Bello Date: Thu, 27 Jun 2024 16:42:30 +0200 Subject: [PATCH 04/51] test.python.compiler.test_disassembler --- qiskit/assembler/disassemble.py | 8 ++ test/benchmarks/assembler.py | 2 + test/python/compiler/test_disassembler.py | 134 +++++++++++++--------- 3 files changed, 90 insertions(+), 54 deletions(-) diff --git a/qiskit/assembler/disassemble.py b/qiskit/assembler/disassemble.py index 127bbd35eb26..8f296a42d9bf 100644 --- a/qiskit/assembler/disassemble.py +++ b/qiskit/assembler/disassemble.py @@ -23,6 +23,7 @@ from qiskit.qobj import PulseQobjInstruction from qiskit.qobj.converters import QobjToInstructionConverter +from qiskit.utils import deprecate_func # A ``CircuitModule`` is a representation of a circuit execution on the backend. # It is currently a list of quantum circuits to execute, a run Qobj dictionary @@ -37,6 +38,13 @@ PulseModule = NewType("PulseModule", Tuple[List[pulse.Schedule], Dict[str, Any], Dict[str, Any]]) +@deprecate_func( + since="1.2", + removal_timeline="in the 2.0 release", + additional_msg="The function disassemble is being deprecated " + "as they are not necessary for BackendV2. If user still need Qobj, that probably " + "means that they are using a backend based on the deprecated BackendV1 class.", +) def disassemble(qobj) -> Union[CircuitModule, PulseModule]: """Disassemble a qobj and return the circuits or pulse schedules, run_config, and user header. diff --git a/test/benchmarks/assembler.py b/test/benchmarks/assembler.py index 3899c05e92bb..03d349088c86 100644 --- a/test/benchmarks/assembler.py +++ b/test/benchmarks/assembler.py @@ -46,4 +46,6 @@ def setup(self, n_qubits, depth, number_of_circuits): self.qobj = assemble(self.circuits) def time_disassemble_circuit(self, _, __, ___): + # TODO: QObj is getting deprecated. Remove once that happens + # https://github.com/Qiskit/qiskit/pull/12649 disassemble(self.qobj) diff --git a/test/python/compiler/test_disassembler.py b/test/python/compiler/test_disassembler.py index e575c021adca..0525b54e2107 100644 --- a/test/python/compiler/test_disassembler.py +++ b/test/python/compiler/test_disassembler.py @@ -10,7 +10,9 @@ # copyright notice, and modified files need to carry a notice indicating # that they have been altered from the originals. -"""Assembler Test.""" +"""Assembler Test. +FULLY REMOVE ONCE Qobj, assemble AND disassemble ARE REMOVED. +""" import unittest @@ -55,14 +57,15 @@ def test_disassemble_single_circuit(self): qubit_lo_freq = [5e9, 5e9] meas_lo_freq = [6.7e9, 6.7e9] - qobj = assemble( - circ, - shots=2000, - memory=True, - qubit_lo_freq=qubit_lo_freq, - meas_lo_freq=meas_lo_freq, - ) - circuits, run_config_out, headers = disassemble(qobj) + with self.assertWarns(DeprecationWarning): + qobj = assemble( + circ, + shots=2000, + memory=True, + qubit_lo_freq=qubit_lo_freq, + meas_lo_freq=meas_lo_freq, + ) + circuits, run_config_out, headers = disassemble(qobj) run_config_out = RunConfig(**run_config_out) self.assertEqual(run_config_out.n_qubits, 2) self.assertEqual(run_config_out.memory_slots, 2) @@ -91,8 +94,9 @@ def test_disassemble_multiple_circuits(self): circ1.cx(qr1[0], qr1[2]) circ1.measure(qr1, qc1) - qobj = assemble([circ0, circ1], shots=100, memory=False, seed=6) - circuits, run_config_out, headers = disassemble(qobj) + with self.assertWarns(DeprecationWarning): + qobj = assemble([circ0, circ1], shots=100, memory=False, seed=6) + circuits, run_config_out, headers = disassemble(qobj) run_config_out = RunConfig(**run_config_out) self.assertEqual(run_config_out.n_qubits, 3) self.assertEqual(run_config_out.memory_slots, 3) @@ -113,8 +117,9 @@ def test_disassemble_no_run_config(self): circ.cx(qr[0], qr[1]) circ.measure(qr, qc) - qobj = assemble(circ) - circuits, run_config_out, headers = disassemble(qobj) + with self.assertWarns(DeprecationWarning): + qobj = assemble(circ) + circuits, run_config_out, headers = disassemble(qobj) run_config_out = RunConfig(**run_config_out) self.assertEqual(run_config_out.n_qubits, 2) self.assertEqual(run_config_out.memory_slots, 2) @@ -128,8 +133,9 @@ def test_disassemble_initialize(self): circ = QuantumCircuit(q, name="circ") circ.initialize([1 / np.sqrt(2), 0, 0, 1 / np.sqrt(2)], q[:]) - qobj = assemble(circ) - circuits, run_config_out, header = disassemble(qobj) + with self.assertWarns(DeprecationWarning): + qobj = assemble(circ) + circuits, run_config_out, header = disassemble(qobj) run_config_out = RunConfig(**run_config_out) self.assertEqual(run_config_out.n_qubits, 2) self.assertEqual(run_config_out.memory_slots, 0) @@ -142,8 +148,9 @@ def test_disassemble_isometry(self): q = QuantumRegister(2, name="q") circ = QuantumCircuit(q, name="circ") circ.append(Isometry(qi.random_unitary(4).data, 0, 0), circ.qubits) - qobj = assemble(circ) - circuits, run_config_out, header = disassemble(qobj) + with self.assertWarns(DeprecationWarning): + qobj = assemble(circ) + circuits, run_config_out, header = disassemble(qobj) run_config_out = RunConfig(**run_config_out) self.assertEqual(run_config_out.n_qubits, 2) self.assertEqual(run_config_out.memory_slots, 0) @@ -166,8 +173,9 @@ def test_opaque_instruction(self): c = ClassicalRegister(4, name="c") circ = QuantumCircuit(q, c, name="circ") circ.append(opaque_inst, [q[0], q[2], q[5], q[3]], [c[3], c[0]]) - qobj = assemble(circ) - circuits, run_config_out, header = disassemble(qobj) + with self.assertWarns(DeprecationWarning): + qobj = assemble(circ) + circuits, run_config_out, header = disassemble(qobj) run_config_out = RunConfig(**run_config_out) self.assertEqual(run_config_out.n_qubits, 6) self.assertEqual(run_config_out.memory_slots, 4) @@ -184,8 +192,9 @@ def test_circuit_with_conditionals(self): qc.measure(qr[0], cr1) # Measure not required for a later conditional qc.measure(qr[1], cr2[1]) # Measure required for a later conditional qc.h(qr[1]).c_if(cr2, 3) - qobj = assemble(qc) - circuits, run_config_out, header = disassemble(qobj) + with self.assertWarns(DeprecationWarning): + qobj = assemble(qc) + circuits, run_config_out, header = disassemble(qobj) run_config_out = RunConfig(**run_config_out) self.assertEqual(run_config_out.n_qubits, 2) self.assertEqual(run_config_out.memory_slots, 3) @@ -199,8 +208,9 @@ def test_circuit_with_simple_conditional(self): cr = ClassicalRegister(1) qc = QuantumCircuit(qr, cr) qc.h(qr[0]).c_if(cr, 1) - qobj = assemble(qc) - circuits, run_config_out, header = disassemble(qobj) + with self.assertWarns(DeprecationWarning): + qobj = assemble(qc) + circuits, run_config_out, header = disassemble(qobj) run_config_out = RunConfig(**run_config_out) self.assertEqual(run_config_out.n_qubits, 1) self.assertEqual(run_config_out.memory_slots, 1) @@ -219,8 +229,10 @@ def test_circuit_with_single_bit_conditions(self): cr = ClassicalRegister(2) qc = QuantumCircuit(qr, cr) qc.h(qr[0]).c_if(cr[0], 1) - qobj = assemble(qc) - circuits, run_config_out, header = disassemble(qobj) + + with self.assertWarns(DeprecationWarning): + qobj = assemble(qc) + circuits, run_config_out, header = disassemble(qobj) run_config_out = RunConfig(**run_config_out) self.assertEqual(run_config_out.n_qubits, len(qr)) self.assertEqual(run_config_out.memory_slots, len(cr)) @@ -234,8 +246,9 @@ def test_circuit_with_mcx(self): cr = ClassicalRegister(5) qc = QuantumCircuit(qr, cr) qc.mcx([0, 1, 2], 4) - qobj = assemble(qc) - circuits, run_config_out, header = disassemble(qobj) + with self.assertWarns(DeprecationWarning): + qobj = assemble(qc) + circuits, run_config_out, header = disassemble(qobj) run_config_out = RunConfig(**run_config_out) self.assertEqual(run_config_out.n_qubits, 5) self.assertEqual(run_config_out.memory_slots, 5) @@ -257,8 +270,9 @@ def test_multiple_conditionals_multiple_registers(self): qc.cx(qr[1], qr[0]).c_if(cr3, 14) qc.ccx(qr[0], qr[2], qr[1]).c_if(cr4, 1) qc.h(qr).c_if(cr1, 3) - qobj = assemble(qc) - circuits, run_config_out, header = disassemble(qobj) + with self.assertWarns(DeprecationWarning): + qobj = assemble(qc) + circuits, run_config_out, header = disassemble(qobj) run_config_out = RunConfig(**run_config_out) self.assertEqual(run_config_out.n_qubits, 3) self.assertEqual(run_config_out.memory_slots, 15) @@ -272,8 +286,9 @@ def test_circuit_with_bit_conditional_1(self): cr = ClassicalRegister(2) qc = QuantumCircuit(qr, cr) qc.h(qr[0]).c_if(cr[1], True) - qobj = assemble(qc) - circuits, run_config_out, header = disassemble(qobj) + with self.assertWarns(DeprecationWarning): + qobj = assemble(qc) + circuits, run_config_out, header = disassemble(qobj) run_config_out = RunConfig(**run_config_out) self.assertEqual(run_config_out.n_qubits, 2) self.assertEqual(run_config_out.memory_slots, 2) @@ -290,8 +305,9 @@ def test_circuit_with_bit_conditional_2(self): qc.h(qr[0]).c_if(cr1[1], False) qc.h(qr[1]).c_if(cr[0], True) qc.cx(qr[0], qr[1]).c_if(cr1[0], False) - qobj = assemble(qc) - circuits, run_config_out, header = disassemble(qobj) + with self.assertWarns(DeprecationWarning): + qobj = assemble(qc) + circuits, run_config_out, header = disassemble(qobj) run_config_out = RunConfig(**run_config_out) self.assertEqual(run_config_out.n_qubits, 2) self.assertEqual(run_config_out.memory_slots, 4) @@ -330,8 +346,9 @@ def test_single_circuit_calibrations(self): qc.add_calibration("h", [0], h_sched) qc.add_calibration(RXGate(np.pi), [0], x180) - qobj = assemble(qc, FakeOpenPulse2Q()) - output_circuits, _, _ = disassemble(qobj) + with self.assertWarns(DeprecationWarning): + qobj = assemble(qc, FakeOpenPulse2Q()) + output_circuits, _, _ = disassemble(qobj) self.assertCircuitCalibrationsEqual([qc], output_circuits) @@ -344,11 +361,12 @@ def test_parametric_pulse_circuit_calibrations(self): qc.h(0) qc.add_calibration("h", [0], h_sched) - backend = FakeOpenPulse2Q() - backend.configuration().parametric_pulses = ["drag"] + with self.assertWarns(DeprecationWarning): + backend = FakeOpenPulse2Q() + backend.configuration().parametric_pulses = ["drag"] - qobj = assemble(qc, backend) - output_circuits, _, _ = disassemble(qobj) + qobj = assemble(qc, backend) + output_circuits, _, _ = disassemble(qobj) out_qc = output_circuits[0] self.assertCircuitCalibrationsEqual([qc], output_circuits) @@ -377,8 +395,9 @@ def test_multi_circuit_uncommon_calibrations(self): qc_1.h(0) circuits = [qc_0, qc_1] - qobj = assemble(circuits, FakeOpenPulse2Q()) - output_circuits, _, _ = disassemble(qobj) + with self.assertWarns(DeprecationWarning): + qobj = assemble(circuits, FakeOpenPulse2Q()) + output_circuits, _, _ = disassemble(qobj) self.assertCircuitCalibrationsEqual(circuits, output_circuits) @@ -398,8 +417,9 @@ def test_multi_circuit_common_calibrations(self): qc_1.add_calibration(RXGate(np.pi), [1], sched) circuits = [qc_0, qc_1] - qobj = assemble(circuits, FakeOpenPulse2Q()) - output_circuits, _, _ = disassemble(qobj) + with self.assertWarns(DeprecationWarning): + qobj = assemble(circuits, FakeOpenPulse2Q()) + output_circuits, _, _ = disassemble(qobj) self.assertCircuitCalibrationsEqual(circuits, output_circuits) @@ -413,8 +433,9 @@ def test_single_circuit_delay_calibrations(self): qc.add_calibration("test", [0], test_sched) - qobj = assemble(qc, FakeOpenPulse2Q()) - output_circuits, _, _ = disassemble(qobj) + 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()) @@ -436,7 +457,8 @@ class TestPulseScheduleDisassembler(QiskitTestCase): def setUp(self): super().setUp() - self.backend = FakeOpenPulse2Q() + with self.assertWarns(DeprecationWarning): + self.backend = FakeOpenPulse2Q() self.backend_config = self.backend.configuration() self.backend_config.parametric_pulses = ["constant", "gaussian", "gaussian_square", "drag"] @@ -456,8 +478,9 @@ def test_disassemble_single_schedule(self): pulse.play(pulse.library.Constant(8, 0.1), d1) pulse.measure_all() - qobj = assemble(sched, backend=self.backend, shots=2000) - scheds, run_config_out, _ = disassemble(qobj) + with self.assertWarns(DeprecationWarning): + qobj = assemble(sched, backend=self.backend, shots=2000) + scheds, run_config_out, _ = disassemble(qobj) run_config_out = RunConfig(**run_config_out) self.assertEqual(run_config_out.memory_slots, 2) self.assertEqual(run_config_out.shots, 2000) @@ -498,8 +521,9 @@ def test_disassemble_multiple_schedules(self): pulse.play(pulse.library.Constant(8, 0.4), d1) pulse.measure_all() - qobj = assemble([sched0, sched1], backend=self.backend, shots=2000) - scheds, run_config_out, _ = disassemble(qobj) + with self.assertWarns(DeprecationWarning): + qobj = assemble([sched0, sched1], backend=self.backend, shots=2000) + scheds, run_config_out, _ = disassemble(qobj) run_config_out = RunConfig(**run_config_out) self.assertEqual(run_config_out.memory_slots, 2) self.assertEqual(run_config_out.shots, 2000) @@ -518,8 +542,9 @@ def test_disassemble_parametric_pulses(self): 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) - qobj = assemble(sched, backend=self.backend, shots=2000) - scheds, _, _ = disassemble(qobj) + with self.assertWarns(DeprecationWarning): + qobj = assemble(sched, backend=self.backend, shots=2000) + scheds, _, _ = disassemble(qobj) self.assertEqual(scheds[0], target_qobj_transform(sched)) def test_disassemble_schedule_los(self): @@ -536,8 +561,9 @@ def test_disassemble_schedule_los(self): {d0: 4.5e9, d1: 5e9, m0: 6e9, m1: 7e9}, {d0: 5e9, d1: 4.5e9, m0: 7e9, m1: 6e9}, ] - qobj = assemble([sched0, sched1], backend=self.backend, schedule_los=schedule_los) - _, run_config_out, _ = disassemble(qobj) + with self.assertWarns(DeprecationWarning): + qobj = assemble([sched0, sched1], backend=self.backend, schedule_los=schedule_los) + _, run_config_out, _ = disassemble(qobj) run_config_out = RunConfig(**run_config_out) self.assertEqual(run_config_out.schedule_los, schedule_los) From e0a39995a091e9ca8314132cc7cc4f14b96d289a Mon Sep 17 00:00:00 2001 From: Luciano Bello Date: Fri, 28 Jun 2024 12:39:12 +0200 Subject: [PATCH 05/51] fakebackend pulse --- qiskit/providers/fake_provider/fake_backend.py | 3 +++ qiskit/providers/models/pulsedefaults.py | 11 +++++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/qiskit/providers/fake_provider/fake_backend.py b/qiskit/providers/fake_provider/fake_backend.py index 4a638f315574..5523d123e073 100644 --- a/qiskit/providers/fake_provider/fake_backend.py +++ b/qiskit/providers/fake_provider/fake_backend.py @@ -120,6 +120,9 @@ def properties(self): @classmethod def _default_options(cls): + # with warnings.catch_warnings(): + # Remove this + # warnings.simplefilter("ignore", category=DeprecationWarning) if _optionals.HAS_AER: from qiskit_aer import QasmSimulator diff --git a/qiskit/providers/models/pulsedefaults.py b/qiskit/providers/models/pulsedefaults.py index 7c1864bad9ee..4edfc5f2c065 100644 --- a/qiskit/providers/models/pulsedefaults.py +++ b/qiskit/providers/models/pulsedefaults.py @@ -12,6 +12,7 @@ """Model and schema for pulse defaults.""" +import warnings from typing import Any, Dict, List from qiskit.pulse.instruction_schedule_map import InstructionScheduleMap, PulseQobjDef @@ -282,10 +283,12 @@ def from_dict(cls, data): in_data = {} for key, value in data.items(): if key in schema: - if isinstance(value, list): - in_data[key] = list(map(schema[key].from_dict, value)) - else: - in_data[key] = schema[key].from_dict(value) + with warnings.catch_warnings(): + warnings.simplefilter("ignore", category=DeprecationWarning) + if isinstance(value, list): + in_data[key] = list(map(schema[key].from_dict, value)) + else: + in_data[key] = schema[key].from_dict(value) else: in_data[key] = value From 79f67c2fb7ad1eac7801fd01d08461548b7be309 Mon Sep 17 00:00:00 2001 From: Luciano Bello Date: Fri, 28 Jun 2024 13:20:35 +0200 Subject: [PATCH 06/51] test.python.circuit.test_parameters --- test/python/circuit/test_parameters.py | 53 ++++++++++++++++++++++---- 1 file changed, 45 insertions(+), 8 deletions(-) diff --git a/test/python/circuit/test_parameters.py b/test/python/circuit/test_parameters.py index f580416eccf5..d977aa30089f 100644 --- a/test/python/circuit/test_parameters.py +++ b/test/python/circuit/test_parameters.py @@ -793,7 +793,8 @@ def test_circuit_generation(self): theta_list = numpy.linspace(0, numpy.pi, 20) for theta_i in theta_list: circs.append(qc_aer.assign_parameters({theta: theta_i})) - qobj = assemble(circs) + with self.assertWarns(DeprecationWarning): + qobj = assemble(circs) for index, theta_i in enumerate(theta_list): res = float(qobj.experiments[index].instructions[0].params[0]) self.assertTrue(math.isclose(res, theta_i), f"{res} != {theta_i}") @@ -980,8 +981,9 @@ def test_parameter_equality_to_expression(self, ptype): self.assertEqual(hash(x1), hash(x1_expr)) self.assertEqual(hash(x2), hash(x2_expr)) - def test_binding_parameterized_circuits_built_in_multiproc(self): - """Verify subcircuits built in a subprocess can still be bound.""" + def test_binding_parameterized_circuits_built_in_multiproc_(self): + """Verify subcircuits built in a subprocess can still be bound. + REMOVE this test once assemble is REMOVED""" # ref: https://github.com/Qiskit/qiskit-terra/issues/2429 num_processes = 4 @@ -1001,11 +1003,12 @@ def test_binding_parameterized_circuits_built_in_multiproc(self): parameter_values = [{x: 1.0 for x in parameters}] - qobj = assemble( - circuit, - backend=BasicSimulator(), - parameter_binds=parameter_values, - ) + with self.assertWarns(DeprecationWarning): + qobj = assemble( + circuit, + backend=BasicSimulator(), + parameter_binds=parameter_values, + ) self.assertEqual(len(qobj.experiments), 1) self.assertEqual(len(qobj.experiments[0].instructions), 4) @@ -1018,6 +1021,40 @@ def test_binding_parameterized_circuits_built_in_multiproc(self): ) ) + def test_binding_parameterized_circuits_built_in_multiproc(self): + """Verify subcircuits built in a subprocess can still be bound. + REMOVE this test once assemble is REMOVED""" + # ref: https://github.com/Qiskit/qiskit-terra/issues/2429 + + num_processes = 4 + + qr = QuantumRegister(3) + cr = ClassicalRegister(3) + + circuit = QuantumCircuit(qr, cr) + parameters = [Parameter(f"x{i}") for i in range(num_processes)] + + results = parallel_map( + _construct_circuit, parameters, task_args=(qr,), num_processes=num_processes + ) + + for qc in results: + circuit.compose(qc, inplace=True) + + parameter_values = {x: 1.0 for x in parameters} + + bind_circuit = circuit.assign_parameters(parameter_values) + + self.assertEqual(len(bind_circuit.data), 4) + self.assertTrue( + all( + len(inst.operation.params) == 1 + and isinstance(inst.operation.params[0], float) + and float(inst.operation.params[0]) == 1 + for inst in bind_circuit.data + ) + ) + def test_transpiling_multiple_parameterized_circuits(self): """Verify several parameterized circuits can be transpiled at once.""" # ref: https://github.com/Qiskit/qiskit-terra/issues/2864 From 2bba185b99ae1fbaeccd8540a609f2671bf4ddc1 Mon Sep 17 00:00:00 2001 From: Luciano Bello Date: Fri, 28 Jun 2024 17:26:52 +0200 Subject: [PATCH 07/51] PulseQobjInstruction is used by GenericBackendV2 --- .../fake_provider/generic_backend_v2.py | 47 +++++++++++-------- test/python/circuit/test_diagonal_gate.py | 12 +++-- test/python/circuit/test_hamiltonian_gate.py | 6 ++- 3 files changed, 39 insertions(+), 26 deletions(-) diff --git a/qiskit/providers/fake_provider/generic_backend_v2.py b/qiskit/providers/fake_provider/generic_backend_v2.py index 214754080e57..f20ac772eac1 100644 --- a/qiskit/providers/fake_provider/generic_backend_v2.py +++ b/qiskit/providers/fake_provider/generic_backend_v2.py @@ -253,27 +253,36 @@ def _get_calibration_sequence( # Note that the calibration pulses are different for # 1q gates vs 2q gates vs measurement instructions. if inst == "measure": - sequence = [ - PulseQobjInstruction( - name="acquire", - duration=1792, - t0=0, - qubits=qargs, - memory_slot=qargs, - ) - ] + [PulseQobjInstruction(name=pulse_library[1].name, ch=f"m{i}", t0=0) for i in qargs] - return sequence - if num_qubits == 1: + with warnings.catch_warnings(): + warnings.simplefilter("ignore", category=DeprecationWarning) + # TODO move away from deprecated PulseQobjInstruction + sequence = [ + PulseQobjInstruction( + name="acquire", + duration=1792, + t0=0, + qubits=qargs, + memory_slot=qargs, + ) + ] + [ + PulseQobjInstruction(name=pulse_library[1].name, ch=f"m{i}", t0=0) + for i in qargs + ] + return sequence + with warnings.catch_warnings(): + warnings.simplefilter("ignore", category=DeprecationWarning) + # TODO: move away from deprecated PulseQobjInstruction + if num_qubits == 1: + return [ + PulseQobjInstruction(name="fc", ch=f"u{qargs[0]}", t0=0, phase="-P0"), + PulseQobjInstruction(name=pulse_library[0].name, ch=f"d{qargs[0]}", t0=0), + ] return [ - PulseQobjInstruction(name="fc", ch=f"u{qargs[0]}", t0=0, phase="-P0"), - PulseQobjInstruction(name=pulse_library[0].name, ch=f"d{qargs[0]}", t0=0), + PulseQobjInstruction(name=pulse_library[1].name, ch=f"d{qargs[0]}", t0=0), + PulseQobjInstruction(name=pulse_library[2].name, ch=f"u{qargs[0]}", t0=0), + PulseQobjInstruction(name=pulse_library[1].name, ch=f"d{qargs[1]}", t0=0), + PulseQobjInstruction(name="fc", ch=f"d{qargs[1]}", t0=0, phase=2.1), ] - return [ - PulseQobjInstruction(name=pulse_library[1].name, ch=f"d{qargs[0]}", t0=0), - PulseQobjInstruction(name=pulse_library[2].name, ch=f"u{qargs[0]}", t0=0), - PulseQobjInstruction(name=pulse_library[1].name, ch=f"d{qargs[1]}", t0=0), - PulseQobjInstruction(name="fc", ch=f"d{qargs[1]}", t0=0, phase=2.1), - ] def _generate_calibration_defaults(self) -> PulseDefaults: """Generate pulse calibration defaults as specified with `self._calibrate_instructions`. diff --git a/test/python/circuit/test_diagonal_gate.py b/test/python/circuit/test_diagonal_gate.py index 57a5d5966c7e..de8d53e12d3b 100644 --- a/test/python/circuit/test_diagonal_gate.py +++ b/test/python/circuit/test_diagonal_gate.py @@ -75,11 +75,13 @@ def test_npcomplex_params_conversion(self): all(isinstance(p, complex) and not isinstance(p, np.number) for p in params) ) - qobj = assemble(qc) - params = qobj.experiments[0].instructions[0].params - self.assertTrue( - all(isinstance(p, complex) and not isinstance(p, np.number) for p in params) - ) + with self.assertWarns(DeprecationWarning): + # REMOVE this assertion (not the full test) once ASSEMBLE is removed. + qobj = assemble(qc) + params = qobj.experiments[0].instructions[0].params + self.assertTrue( + all(isinstance(p, complex) and not isinstance(p, np.number) for p in params) + ) def _get_diag_gate_matrix(diag): diff --git a/test/python/circuit/test_hamiltonian_gate.py b/test/python/circuit/test_hamiltonian_gate.py index 46aee007b158..60fb1e9a90a9 100644 --- a/test/python/circuit/test_hamiltonian_gate.py +++ b/test/python/circuit/test_hamiltonian_gate.py @@ -131,7 +131,8 @@ def test_3q_hamiltonian(self): np.testing.assert_almost_equal(dnode.op.to_matrix(), 1j * matrix.data) def test_qobj_with_hamiltonian(self): - """test qobj output with hamiltonian""" + """test qobj output with hamiltonian + REMOVE once Qobj gets removed""" qr = QuantumRegister(4) qc = QuantumCircuit(qr) qc.rx(np.pi / 4, qr[0]) @@ -141,7 +142,8 @@ def test_qobj_with_hamiltonian(self): qc.append(uni, [qr[0], qr[1], qr[3]]) qc.cx(qr[3], qr[2]) qc = qc.assign_parameters({theta: np.pi / 2}) - qobj = qiskit.compiler.assemble(qc) + with self.assertWarns(DeprecationWarning): + qobj = qiskit.compiler.assemble(qc) instr = qobj.experiments[0].instructions[1] self.assertEqual(instr.name, "hamiltonian") # Also test label From b809acebfea83d9a13ff08087f976268bf2a13c0 Mon Sep 17 00:00:00 2001 From: Luciano Bello Date: Fri, 28 Jun 2024 20:00:41 +0200 Subject: [PATCH 08/51] test.python.scheduler.test_basic_scheduler --- .../fake_provider/fake_openpulse_2q.py | 299 ++++++------ .../fake_provider/fake_openpulse_3q.py | 442 +++++++++--------- .../transpiler/test_preset_passmanagers.py | 14 +- 3 files changed, 385 insertions(+), 370 deletions(-) diff --git a/qiskit/providers/fake_provider/fake_openpulse_2q.py b/qiskit/providers/fake_provider/fake_openpulse_2q.py index caa0f53e7a38..f2b5b02f5229 100644 --- a/qiskit/providers/fake_provider/fake_openpulse_2q.py +++ b/qiskit/providers/fake_provider/fake_openpulse_2q.py @@ -14,6 +14,7 @@ Fake backend supporting OpenPulse. """ import datetime +import warnings from qiskit.providers.models import ( GateConfig, @@ -126,152 +127,158 @@ def __init__(self): description="A fake test backend with pulse defaults", ) - self._defaults = PulseDefaults.from_dict( - { - "qubit_freq_est": [4.9, 5.0], - "meas_freq_est": [6.5, 6.6], - "buffer": 10, - "pulse_library": [ - {"name": "x90p_d0", "samples": 2 * [0.1 + 0j]}, - {"name": "x90p_d1", "samples": 2 * [0.1 + 0j]}, - {"name": "x90m_d0", "samples": 2 * [-0.1 + 0j]}, - {"name": "x90m_d1", "samples": 2 * [-0.1 + 0j]}, - {"name": "y90p_d0", "samples": 2 * [0.1j]}, - {"name": "y90p_d1", "samples": 2 * [0.1j]}, - {"name": "xp_d0", "samples": 2 * [0.2 + 0j]}, - {"name": "ym_d0", "samples": 2 * [-0.2j]}, - {"name": "cr90p_u0", "samples": 9 * [0.1 + 0j]}, - {"name": "cr90m_u0", "samples": 9 * [-0.1 + 0j]}, - {"name": "measure_m0", "samples": 10 * [0.1 + 0j]}, - {"name": "measure_m1", "samples": 10 * [0.1 + 0j]}, - ], - "cmd_def": [ - Command.from_dict( - { - "name": "u1", - "qubits": [0], - "sequence": [ - PulseQobjInstruction( - name="fc", ch="d0", t0=0, phase="-P0" - ).to_dict() - ], - } - ).to_dict(), - Command.from_dict( - { - "name": "u1", - "qubits": [1], - "sequence": [ - PulseQobjInstruction( - name="fc", ch="d1", t0=0, phase="-P0" - ).to_dict() - ], - } - ).to_dict(), - Command.from_dict( - { - "name": "u2", - "qubits": [0], - "sequence": [ - PulseQobjInstruction( - name="fc", ch="d0", t0=0, phase="-P1" - ).to_dict(), - PulseQobjInstruction(name="y90p_d0", ch="d0", t0=0).to_dict(), - PulseQobjInstruction( - name="fc", ch="d0", t0=2, phase="-P0" - ).to_dict(), - ], - } - ).to_dict(), - Command.from_dict( - { - "name": "u2", - "qubits": [1], - "sequence": [ - PulseQobjInstruction( - name="fc", ch="d1", t0=0, phase="-P1" - ).to_dict(), - PulseQobjInstruction(name="y90p_d1", ch="d1", t0=0).to_dict(), - PulseQobjInstruction( - name="fc", ch="d1", t0=2, phase="-P0" - ).to_dict(), - ], - } - ).to_dict(), - Command.from_dict( - { - "name": "u3", - "qubits": [0], - "sequence": [ - PulseQobjInstruction( - name="fc", ch="d0", t0=0, phase="-P2" - ).to_dict(), - PulseQobjInstruction(name="x90p_d0", ch="d0", t0=0).to_dict(), - PulseQobjInstruction( - name="fc", ch="d0", t0=2, phase="-P0" - ).to_dict(), - PulseQobjInstruction(name="x90m_d0", ch="d0", t0=2).to_dict(), - PulseQobjInstruction( - name="fc", ch="d0", t0=4, phase="-P1" - ).to_dict(), - ], - } - ).to_dict(), - Command.from_dict( - { - "name": "u3", - "qubits": [1], - "sequence": [ - PulseQobjInstruction( - name="fc", ch="d1", t0=0, phase="-P2" - ).to_dict(), - PulseQobjInstruction(name="x90p_d1", ch="d1", t0=0).to_dict(), - PulseQobjInstruction( - name="fc", ch="d1", t0=2, phase="-P0" - ).to_dict(), - PulseQobjInstruction(name="x90m_d1", ch="d1", t0=2).to_dict(), - PulseQobjInstruction( - name="fc", ch="d1", t0=4, phase="-P1" - ).to_dict(), - ], - } - ).to_dict(), - Command.from_dict( - { - "name": "cx", - "qubits": [0, 1], - "sequence": [ - PulseQobjInstruction( - name="fc", ch="d0", t0=0, phase=1.57 - ).to_dict(), - PulseQobjInstruction(name="ym_d0", ch="d0", t0=0).to_dict(), - PulseQobjInstruction(name="xp_d0", ch="d0", t0=11).to_dict(), - PulseQobjInstruction(name="x90p_d1", ch="d1", t0=0).to_dict(), - PulseQobjInstruction(name="cr90p_u0", ch="u0", t0=2).to_dict(), - PulseQobjInstruction(name="cr90m_u0", ch="u0", t0=13).to_dict(), - ], - } - ).to_dict(), - Command.from_dict( - { - "name": "measure", - "qubits": [0, 1], - "sequence": [ - PulseQobjInstruction(name="measure_m0", ch="m0", t0=0).to_dict(), - PulseQobjInstruction(name="measure_m1", ch="m1", t0=0).to_dict(), - PulseQobjInstruction( - name="acquire", - duration=10, - t0=0, - qubits=[0, 1], - memory_slot=[0, 1], - ).to_dict(), - ], - } - ).to_dict(), - ], - } - ) + with warnings.catch_warnings(): + warnings.simplefilter("ignore", category=DeprecationWarning) + self._defaults = PulseDefaults.from_dict( + { + "qubit_freq_est": [4.9, 5.0], + "meas_freq_est": [6.5, 6.6], + "buffer": 10, + "pulse_library": [ + {"name": "x90p_d0", "samples": 2 * [0.1 + 0j]}, + {"name": "x90p_d1", "samples": 2 * [0.1 + 0j]}, + {"name": "x90m_d0", "samples": 2 * [-0.1 + 0j]}, + {"name": "x90m_d1", "samples": 2 * [-0.1 + 0j]}, + {"name": "y90p_d0", "samples": 2 * [0.1j]}, + {"name": "y90p_d1", "samples": 2 * [0.1j]}, + {"name": "xp_d0", "samples": 2 * [0.2 + 0j]}, + {"name": "ym_d0", "samples": 2 * [-0.2j]}, + {"name": "cr90p_u0", "samples": 9 * [0.1 + 0j]}, + {"name": "cr90m_u0", "samples": 9 * [-0.1 + 0j]}, + {"name": "measure_m0", "samples": 10 * [0.1 + 0j]}, + {"name": "measure_m1", "samples": 10 * [0.1 + 0j]}, + ], + "cmd_def": [ + Command.from_dict( + { + "name": "u1", + "qubits": [0], + "sequence": [ + PulseQobjInstruction( + name="fc", ch="d0", t0=0, phase="-P0" + ).to_dict() + ], + } + ).to_dict(), + Command.from_dict( + { + "name": "u1", + "qubits": [1], + "sequence": [ + PulseQobjInstruction( + name="fc", ch="d1", t0=0, phase="-P0" + ).to_dict() + ], + } + ).to_dict(), + Command.from_dict( + { + "name": "u2", + "qubits": [0], + "sequence": [ + PulseQobjInstruction( + name="fc", ch="d0", t0=0, phase="-P1" + ).to_dict(), + PulseQobjInstruction(name="y90p_d0", ch="d0", t0=0).to_dict(), + PulseQobjInstruction( + name="fc", ch="d0", t0=2, phase="-P0" + ).to_dict(), + ], + } + ).to_dict(), + Command.from_dict( + { + "name": "u2", + "qubits": [1], + "sequence": [ + PulseQobjInstruction( + name="fc", ch="d1", t0=0, phase="-P1" + ).to_dict(), + PulseQobjInstruction(name="y90p_d1", ch="d1", t0=0).to_dict(), + PulseQobjInstruction( + name="fc", ch="d1", t0=2, phase="-P0" + ).to_dict(), + ], + } + ).to_dict(), + Command.from_dict( + { + "name": "u3", + "qubits": [0], + "sequence": [ + PulseQobjInstruction( + name="fc", ch="d0", t0=0, phase="-P2" + ).to_dict(), + PulseQobjInstruction(name="x90p_d0", ch="d0", t0=0).to_dict(), + PulseQobjInstruction( + name="fc", ch="d0", t0=2, phase="-P0" + ).to_dict(), + PulseQobjInstruction(name="x90m_d0", ch="d0", t0=2).to_dict(), + PulseQobjInstruction( + name="fc", ch="d0", t0=4, phase="-P1" + ).to_dict(), + ], + } + ).to_dict(), + Command.from_dict( + { + "name": "u3", + "qubits": [1], + "sequence": [ + PulseQobjInstruction( + name="fc", ch="d1", t0=0, phase="-P2" + ).to_dict(), + PulseQobjInstruction(name="x90p_d1", ch="d1", t0=0).to_dict(), + PulseQobjInstruction( + name="fc", ch="d1", t0=2, phase="-P0" + ).to_dict(), + PulseQobjInstruction(name="x90m_d1", ch="d1", t0=2).to_dict(), + PulseQobjInstruction( + name="fc", ch="d1", t0=4, phase="-P1" + ).to_dict(), + ], + } + ).to_dict(), + Command.from_dict( + { + "name": "cx", + "qubits": [0, 1], + "sequence": [ + PulseQobjInstruction( + name="fc", ch="d0", t0=0, phase=1.57 + ).to_dict(), + PulseQobjInstruction(name="ym_d0", ch="d0", t0=0).to_dict(), + PulseQobjInstruction(name="xp_d0", ch="d0", t0=11).to_dict(), + PulseQobjInstruction(name="x90p_d1", ch="d1", t0=0).to_dict(), + PulseQobjInstruction(name="cr90p_u0", ch="u0", t0=2).to_dict(), + PulseQobjInstruction(name="cr90m_u0", ch="u0", t0=13).to_dict(), + ], + } + ).to_dict(), + Command.from_dict( + { + "name": "measure", + "qubits": [0, 1], + "sequence": [ + PulseQobjInstruction( + name="measure_m0", ch="m0", t0=0 + ).to_dict(), + PulseQobjInstruction( + name="measure_m1", ch="m1", t0=0 + ).to_dict(), + PulseQobjInstruction( + name="acquire", + duration=10, + t0=0, + qubits=[0, 1], + memory_slot=[0, 1], + ).to_dict(), + ], + } + ).to_dict(), + ], + } + ) mock_time = datetime.datetime.now() dt = 1.3333 diff --git a/qiskit/providers/fake_provider/fake_openpulse_3q.py b/qiskit/providers/fake_provider/fake_openpulse_3q.py index 8d2529a68a2a..161fc5fbb4d4 100644 --- a/qiskit/providers/fake_provider/fake_openpulse_3q.py +++ b/qiskit/providers/fake_provider/fake_openpulse_3q.py @@ -13,6 +13,7 @@ """ Fake backend supporting OpenPulse. """ +import warnings from qiskit.providers.models import ( GateConfig, @@ -109,223 +110,230 @@ def __init__(self): }, }, ) - - self._defaults = PulseDefaults.from_dict( - { - "qubit_freq_est": [4.9, 5.0, 4.8], - "meas_freq_est": [6.5, 6.6, 6.4], - "buffer": 10, - "pulse_library": [ - {"name": "x90p_d0", "samples": 2 * [0.1 + 0j]}, - {"name": "x90p_d1", "samples": 2 * [0.1 + 0j]}, - {"name": "x90p_d2", "samples": 2 * [0.1 + 0j]}, - {"name": "x90m_d0", "samples": 2 * [-0.1 + 0j]}, - {"name": "x90m_d1", "samples": 2 * [-0.1 + 0j]}, - {"name": "x90m_d2", "samples": 2 * [-0.1 + 0j]}, - {"name": "y90p_d0", "samples": 2 * [0.1j]}, - {"name": "y90p_d1", "samples": 2 * [0.1j]}, - {"name": "y90p_d2", "samples": 2 * [0.1j]}, - {"name": "xp_d0", "samples": 2 * [0.2 + 0j]}, - {"name": "ym_d0", "samples": 2 * [-0.2j]}, - {"name": "xp_d1", "samples": 2 * [0.2 + 0j]}, - {"name": "ym_d1", "samples": 2 * [-0.2j]}, - {"name": "cr90p_u0", "samples": 9 * [0.1 + 0j]}, - {"name": "cr90m_u0", "samples": 9 * [-0.1 + 0j]}, - {"name": "cr90p_u1", "samples": 9 * [0.1 + 0j]}, - {"name": "cr90m_u1", "samples": 9 * [-0.1 + 0j]}, - {"name": "measure_m0", "samples": 10 * [0.1 + 0j]}, - {"name": "measure_m1", "samples": 10 * [0.1 + 0j]}, - {"name": "measure_m2", "samples": 10 * [0.1 + 0j]}, - ], - "cmd_def": [ - Command.from_dict( - { - "name": "u1", - "qubits": [0], - "sequence": [ - PulseQobjInstruction( - name="fc", ch="d0", t0=0, phase="-P0" - ).to_dict() - ], - } - ).to_dict(), - Command.from_dict( - { - "name": "u1", - "qubits": [1], - "sequence": [ - PulseQobjInstruction( - name="fc", ch="d1", t0=0, phase="-P0" - ).to_dict() - ], - } - ).to_dict(), - Command.from_dict( - { - "name": "u1", - "qubits": [2], - "sequence": [ - PulseQobjInstruction( - name="fc", ch="d2", t0=0, phase="-P0" - ).to_dict() - ], - } - ).to_dict(), - Command.from_dict( - { - "name": "u2", - "qubits": [0], - "sequence": [ - PulseQobjInstruction( - name="fc", ch="d0", t0=0, phase="-P1" - ).to_dict(), - PulseQobjInstruction(name="y90p_d0", ch="d0", t0=0).to_dict(), - PulseQobjInstruction( - name="fc", ch="d0", t0=2, phase="-P0" - ).to_dict(), - ], - } - ).to_dict(), - Command.from_dict( - { - "name": "u2", - "qubits": [1], - "sequence": [ - PulseQobjInstruction( - name="fc", ch="d1", t0=0, phase="-P1" - ).to_dict(), - PulseQobjInstruction(name="y90p_d1", ch="d1", t0=0).to_dict(), - PulseQobjInstruction( - name="fc", ch="d1", t0=2, phase="-P0" - ).to_dict(), - ], - } - ).to_dict(), - Command.from_dict( - { - "name": "u2", - "qubits": [2], - "sequence": [ - PulseQobjInstruction( - name="fc", ch="d2", t0=0, phase="-P1" - ).to_dict(), - PulseQobjInstruction(name="y90p_d2", ch="d2", t0=0).to_dict(), - PulseQobjInstruction( - name="fc", ch="d2", t0=2, phase="-P0" - ).to_dict(), - ], - } - ).to_dict(), - Command.from_dict( - { - "name": "u3", - "qubits": [0], - "sequence": [ - PulseQobjInstruction( - name="fc", ch="d0", t0=0, phase="-P2" - ).to_dict(), - PulseQobjInstruction(name="x90p_d0", ch="d0", t0=0).to_dict(), - PulseQobjInstruction( - name="fc", ch="d0", t0=2, phase="-P0" - ).to_dict(), - PulseQobjInstruction(name="x90m_d0", ch="d0", t0=2).to_dict(), - PulseQobjInstruction( - name="fc", ch="d0", t0=4, phase="-P1" - ).to_dict(), - ], - } - ).to_dict(), - Command.from_dict( - { - "name": "u3", - "qubits": [1], - "sequence": [ - PulseQobjInstruction( - name="fc", ch="d1", t0=0, phase="-P2" - ).to_dict(), - PulseQobjInstruction(name="x90p_d1", ch="d1", t0=0).to_dict(), - PulseQobjInstruction( - name="fc", ch="d1", t0=2, phase="-P0" - ).to_dict(), - PulseQobjInstruction(name="x90m_d1", ch="d1", t0=2).to_dict(), - PulseQobjInstruction( - name="fc", ch="d1", t0=4, phase="-P1" - ).to_dict(), - ], - } - ).to_dict(), - Command.from_dict( - { - "name": "u3", - "qubits": [2], - "sequence": [ - PulseQobjInstruction( - name="fc", ch="d2", t0=0, phase="-P2" - ).to_dict(), - PulseQobjInstruction(name="x90p_d2", ch="d2", t0=0).to_dict(), - PulseQobjInstruction( - name="fc", ch="d2", t0=2, phase="-P0" - ).to_dict(), - PulseQobjInstruction(name="x90m_d2", ch="d2", t0=2).to_dict(), - PulseQobjInstruction( - name="fc", ch="d2", t0=4, phase="-P1" - ).to_dict(), - ], - } - ).to_dict(), - Command.from_dict( - { - "name": "cx", - "qubits": [0, 1], - "sequence": [ - PulseQobjInstruction( - name="fc", ch="d0", t0=0, phase=1.57 - ).to_dict(), - PulseQobjInstruction(name="ym_d0", ch="d0", t0=0).to_dict(), - PulseQobjInstruction(name="xp_d0", ch="d0", t0=11).to_dict(), - PulseQobjInstruction(name="x90p_d1", ch="d1", t0=0).to_dict(), - PulseQobjInstruction(name="cr90p_u0", ch="u0", t0=2).to_dict(), - PulseQobjInstruction(name="cr90m_u0", ch="u0", t0=13).to_dict(), - ], - } - ).to_dict(), - Command.from_dict( - { - "name": "cx", - "qubits": [1, 2], - "sequence": [ - PulseQobjInstruction( - name="fc", ch="d1", t0=0, phase=1.57 - ).to_dict(), - PulseQobjInstruction(name="ym_d1", ch="d1", t0=0).to_dict(), - PulseQobjInstruction(name="xp_d1", ch="d1", t0=11).to_dict(), - PulseQobjInstruction(name="x90p_d2", ch="d2", t0=0).to_dict(), - PulseQobjInstruction(name="cr90p_u1", ch="u1", t0=2).to_dict(), - PulseQobjInstruction(name="cr90m_u1", ch="u1", t0=13).to_dict(), - ], - } - ).to_dict(), - Command.from_dict( - { - "name": "measure", - "qubits": [0, 1, 2], - "sequence": [ - PulseQobjInstruction(name="measure_m0", ch="m0", t0=0).to_dict(), - PulseQobjInstruction(name="measure_m1", ch="m1", t0=0).to_dict(), - PulseQobjInstruction(name="measure_m2", ch="m2", t0=0).to_dict(), - PulseQobjInstruction( - name="acquire", - duration=10, - t0=0, - qubits=[0, 1, 2], - memory_slot=[0, 1, 2], - ).to_dict(), - ], - } - ).to_dict(), - ], - } - ) + with warnings.catch_warnings(): + warnings.simplefilter("ignore", category=DeprecationWarning) + self._defaults = PulseDefaults.from_dict( + { + "qubit_freq_est": [4.9, 5.0, 4.8], + "meas_freq_est": [6.5, 6.6, 6.4], + "buffer": 10, + "pulse_library": [ + {"name": "x90p_d0", "samples": 2 * [0.1 + 0j]}, + {"name": "x90p_d1", "samples": 2 * [0.1 + 0j]}, + {"name": "x90p_d2", "samples": 2 * [0.1 + 0j]}, + {"name": "x90m_d0", "samples": 2 * [-0.1 + 0j]}, + {"name": "x90m_d1", "samples": 2 * [-0.1 + 0j]}, + {"name": "x90m_d2", "samples": 2 * [-0.1 + 0j]}, + {"name": "y90p_d0", "samples": 2 * [0.1j]}, + {"name": "y90p_d1", "samples": 2 * [0.1j]}, + {"name": "y90p_d2", "samples": 2 * [0.1j]}, + {"name": "xp_d0", "samples": 2 * [0.2 + 0j]}, + {"name": "ym_d0", "samples": 2 * [-0.2j]}, + {"name": "xp_d1", "samples": 2 * [0.2 + 0j]}, + {"name": "ym_d1", "samples": 2 * [-0.2j]}, + {"name": "cr90p_u0", "samples": 9 * [0.1 + 0j]}, + {"name": "cr90m_u0", "samples": 9 * [-0.1 + 0j]}, + {"name": "cr90p_u1", "samples": 9 * [0.1 + 0j]}, + {"name": "cr90m_u1", "samples": 9 * [-0.1 + 0j]}, + {"name": "measure_m0", "samples": 10 * [0.1 + 0j]}, + {"name": "measure_m1", "samples": 10 * [0.1 + 0j]}, + {"name": "measure_m2", "samples": 10 * [0.1 + 0j]}, + ], + "cmd_def": [ + Command.from_dict( + { + "name": "u1", + "qubits": [0], + "sequence": [ + PulseQobjInstruction( + name="fc", ch="d0", t0=0, phase="-P0" + ).to_dict() + ], + } + ).to_dict(), + Command.from_dict( + { + "name": "u1", + "qubits": [1], + "sequence": [ + PulseQobjInstruction( + name="fc", ch="d1", t0=0, phase="-P0" + ).to_dict() + ], + } + ).to_dict(), + Command.from_dict( + { + "name": "u1", + "qubits": [2], + "sequence": [ + PulseQobjInstruction( + name="fc", ch="d2", t0=0, phase="-P0" + ).to_dict() + ], + } + ).to_dict(), + Command.from_dict( + { + "name": "u2", + "qubits": [0], + "sequence": [ + PulseQobjInstruction( + name="fc", ch="d0", t0=0, phase="-P1" + ).to_dict(), + PulseQobjInstruction(name="y90p_d0", ch="d0", t0=0).to_dict(), + PulseQobjInstruction( + name="fc", ch="d0", t0=2, phase="-P0" + ).to_dict(), + ], + } + ).to_dict(), + Command.from_dict( + { + "name": "u2", + "qubits": [1], + "sequence": [ + PulseQobjInstruction( + name="fc", ch="d1", t0=0, phase="-P1" + ).to_dict(), + PulseQobjInstruction(name="y90p_d1", ch="d1", t0=0).to_dict(), + PulseQobjInstruction( + name="fc", ch="d1", t0=2, phase="-P0" + ).to_dict(), + ], + } + ).to_dict(), + Command.from_dict( + { + "name": "u2", + "qubits": [2], + "sequence": [ + PulseQobjInstruction( + name="fc", ch="d2", t0=0, phase="-P1" + ).to_dict(), + PulseQobjInstruction(name="y90p_d2", ch="d2", t0=0).to_dict(), + PulseQobjInstruction( + name="fc", ch="d2", t0=2, phase="-P0" + ).to_dict(), + ], + } + ).to_dict(), + Command.from_dict( + { + "name": "u3", + "qubits": [0], + "sequence": [ + PulseQobjInstruction( + name="fc", ch="d0", t0=0, phase="-P2" + ).to_dict(), + PulseQobjInstruction(name="x90p_d0", ch="d0", t0=0).to_dict(), + PulseQobjInstruction( + name="fc", ch="d0", t0=2, phase="-P0" + ).to_dict(), + PulseQobjInstruction(name="x90m_d0", ch="d0", t0=2).to_dict(), + PulseQobjInstruction( + name="fc", ch="d0", t0=4, phase="-P1" + ).to_dict(), + ], + } + ).to_dict(), + Command.from_dict( + { + "name": "u3", + "qubits": [1], + "sequence": [ + PulseQobjInstruction( + name="fc", ch="d1", t0=0, phase="-P2" + ).to_dict(), + PulseQobjInstruction(name="x90p_d1", ch="d1", t0=0).to_dict(), + PulseQobjInstruction( + name="fc", ch="d1", t0=2, phase="-P0" + ).to_dict(), + PulseQobjInstruction(name="x90m_d1", ch="d1", t0=2).to_dict(), + PulseQobjInstruction( + name="fc", ch="d1", t0=4, phase="-P1" + ).to_dict(), + ], + } + ).to_dict(), + Command.from_dict( + { + "name": "u3", + "qubits": [2], + "sequence": [ + PulseQobjInstruction( + name="fc", ch="d2", t0=0, phase="-P2" + ).to_dict(), + PulseQobjInstruction(name="x90p_d2", ch="d2", t0=0).to_dict(), + PulseQobjInstruction( + name="fc", ch="d2", t0=2, phase="-P0" + ).to_dict(), + PulseQobjInstruction(name="x90m_d2", ch="d2", t0=2).to_dict(), + PulseQobjInstruction( + name="fc", ch="d2", t0=4, phase="-P1" + ).to_dict(), + ], + } + ).to_dict(), + Command.from_dict( + { + "name": "cx", + "qubits": [0, 1], + "sequence": [ + PulseQobjInstruction( + name="fc", ch="d0", t0=0, phase=1.57 + ).to_dict(), + PulseQobjInstruction(name="ym_d0", ch="d0", t0=0).to_dict(), + PulseQobjInstruction(name="xp_d0", ch="d0", t0=11).to_dict(), + PulseQobjInstruction(name="x90p_d1", ch="d1", t0=0).to_dict(), + PulseQobjInstruction(name="cr90p_u0", ch="u0", t0=2).to_dict(), + PulseQobjInstruction(name="cr90m_u0", ch="u0", t0=13).to_dict(), + ], + } + ).to_dict(), + Command.from_dict( + { + "name": "cx", + "qubits": [1, 2], + "sequence": [ + PulseQobjInstruction( + name="fc", ch="d1", t0=0, phase=1.57 + ).to_dict(), + PulseQobjInstruction(name="ym_d1", ch="d1", t0=0).to_dict(), + PulseQobjInstruction(name="xp_d1", ch="d1", t0=11).to_dict(), + PulseQobjInstruction(name="x90p_d2", ch="d2", t0=0).to_dict(), + PulseQobjInstruction(name="cr90p_u1", ch="u1", t0=2).to_dict(), + PulseQobjInstruction(name="cr90m_u1", ch="u1", t0=13).to_dict(), + ], + } + ).to_dict(), + Command.from_dict( + { + "name": "measure", + "qubits": [0, 1, 2], + "sequence": [ + PulseQobjInstruction( + name="measure_m0", ch="m0", t0=0 + ).to_dict(), + PulseQobjInstruction( + name="measure_m1", ch="m1", t0=0 + ).to_dict(), + PulseQobjInstruction( + name="measure_m2", ch="m2", t0=0 + ).to_dict(), + PulseQobjInstruction( + name="acquire", + duration=10, + t0=0, + qubits=[0, 1, 2], + memory_slot=[0, 1, 2], + ).to_dict(), + ], + } + ).to_dict(), + ], + } + ) super().__init__(configuration) def defaults(self): # pylint: disable=missing-function-docstring diff --git a/test/python/transpiler/test_preset_passmanagers.py b/test/python/transpiler/test_preset_passmanagers.py index ee85dc34ffd6..32d39304b44e 100644 --- a/test/python/transpiler/test_preset_passmanagers.py +++ b/test/python/transpiler/test_preset_passmanagers.py @@ -21,7 +21,7 @@ from qiskit import QuantumCircuit, ClassicalRegister, QuantumRegister from qiskit.circuit import Qubit, Gate, ControlFlowOp, ForLoopOp -from qiskit.compiler import transpile, assemble +from qiskit.compiler import transpile from qiskit.transpiler import CouplingMap, Layout, PassManager, TranspilerError, Target from qiskit.circuit.library import U2Gate, U3Gate, QuantumVolume, CXGate, CZGate, XGate from qiskit.transpiler.passes import ( @@ -684,15 +684,15 @@ def test_layout_1711(self, level): } backend = GenericBackendV2(num_qubits=16, coupling_map=RUESCHLIKON_CMAP, seed=42) qc_b = transpile(qc, backend, initial_layout=initial_layout, optimization_level=level) - qobj = assemble(qc_b) self.assertEqual(qc_b._layout.initial_layout._p2v, final_layout) - compiled_ops = qobj.experiments[0].instructions - for operation in compiled_ops: - if operation.name == "cx": - self.assertIn(tuple(operation.qubits), backend.coupling_map) - self.assertIn(operation.qubits, [[15, 0], [15, 2]]) + for inst in qc_b.data: + if inst.operation.name == "cx": + self.assertIn( + tuple(qc_b.find_bit(bit).index for bit in inst.qubits), backend.coupling_map + ) + self.assertIn([qc_b.find_bit(bit).index for bit in inst.qubits], [[15, 0], [15, 2]]) @data(0, 1, 2, 3) def test_layout_2532(self, level): From e5c5b43d1e9b97c33093a1d42a767c92aa65deb0 Mon Sep 17 00:00:00 2001 From: Luciano Bello Date: Fri, 28 Jun 2024 20:26:29 +0200 Subject: [PATCH 09/51] test.python.result.test_result --- test/python/result/test_result.py | 150 +++++++++++++++++++----------- 1 file changed, 95 insertions(+), 55 deletions(-) diff --git a/test/python/result/test_result.py b/test/python/result/test_result.py index ff1f4cbf29a0..89539487158c 100644 --- a/test/python/result/test_result.py +++ b/test/python/result/test_result.py @@ -42,7 +42,8 @@ def generate_qiskit_result(self): memory = [hex(ii) for ii in range(8)] counts = {m: 1 for m in memory} data_1 = models.ExperimentResultData(counts=counts, memory=memory) - exp_result_header_1 = QobjExperimentHeader(creg_sizes=[["c0", 4]], memory_slots=4) + with self.assertWarns(DeprecationWarning): + exp_result_header_1 = QobjExperimentHeader(creg_sizes=[["c0", 4]], memory_slots=4) exp_result_1 = models.ExperimentResult( shots=8, success=True, data=data_1, header=exp_result_header_1 ) @@ -67,9 +68,10 @@ def test_counts_header(self): raw_counts = {"0x0": 4, "0x2": 10} processed_counts = {"0 0 00": 4, "0 0 10": 10} data = models.ExperimentResultData(counts=raw_counts) - exp_result_header = QobjExperimentHeader( - creg_sizes=[["c0", 2], ["c0", 1], ["c1", 1]], memory_slots=4 - ) + with self.assertWarns(DeprecationWarning): + exp_result_header = QobjExperimentHeader( + creg_sizes=[["c0", 2], ["c0", 1], ["c1", 1]], memory_slots=4 + ) exp_result = models.ExperimentResult( shots=14, success=True, meas_level=2, data=data, header=exp_result_header ) @@ -82,9 +84,10 @@ def test_counts_by_name(self): raw_counts = {"0x0": 4, "0x2": 10} processed_counts = {"0 0 00": 4, "0 0 10": 10} data = models.ExperimentResultData(counts=raw_counts) - exp_result_header = QobjExperimentHeader( - creg_sizes=[["c0", 2], ["c0", 1], ["c1", 1]], memory_slots=4, name="a_name" - ) + with self.assertWarns(DeprecationWarning): + exp_result_header = QobjExperimentHeader( + creg_sizes=[["c0", 2], ["c0", 1], ["c1", 1]], memory_slots=4, name="a_name" + ) exp_result = models.ExperimentResult( shots=14, success=True, meas_level=2, data=data, header=exp_result_header ) @@ -95,7 +98,8 @@ def test_counts_by_name(self): def test_counts_duplicate_name(self): """Test results containing multiple entries of a single name will warn.""" data = models.ExperimentResultData(counts={}) - exp_result_header = QobjExperimentHeader(name="foo") + with self.assertWarns(DeprecationWarning): + exp_result_header = QobjExperimentHeader(name="foo") exp_result = models.ExperimentResult( shots=14, success=True, data=data, header=exp_result_header ) @@ -108,9 +112,10 @@ def test_result_repr(self): """Test that repr is constructed correctly for a results object.""" raw_counts = {"0x0": 4, "0x2": 10} data = models.ExperimentResultData(counts=raw_counts) - exp_result_header = QobjExperimentHeader( - creg_sizes=[["c0", 2], ["c0", 1], ["c1", 1]], memory_slots=4 - ) + with self.assertWarns(DeprecationWarning): + exp_result_header = QobjExperimentHeader( + creg_sizes=[["c0", 2], ["c0", 1], ["c1", 1]], memory_slots=4 + ) exp_result = models.ExperimentResult( shots=14, success=True, meas_level=2, data=data, header=exp_result_header ) @@ -137,7 +142,8 @@ def test_multiple_circuits_counts(self): raw_counts_1 = {"0x0": 5, "0x3": 12, "0x5": 9, "0xD": 6, "0xE": 2} processed_counts_1 = {"0000": 5, "0011": 12, "0101": 9, "1101": 6, "1110": 2} data_1 = models.ExperimentResultData(counts=raw_counts_1) - exp_result_header_1 = QobjExperimentHeader(creg_sizes=[["c0", 4]], memory_slots=4) + with self.assertWarns(DeprecationWarning): + exp_result_header_1 = QobjExperimentHeader(creg_sizes=[["c0", 4]], memory_slots=4) exp_result_1 = models.ExperimentResult( shots=14, success=True, meas_level=2, data=data_1, header=exp_result_header_1 ) @@ -145,7 +151,8 @@ def test_multiple_circuits_counts(self): raw_counts_2 = {"0x1": 0, "0x4": 3, "0x6": 6, "0xA": 1, "0xB": 2} processed_counts_2 = {"0001": 0, "0100": 3, "0110": 6, "1010": 1, "1011": 2} data_2 = models.ExperimentResultData(counts=raw_counts_2) - exp_result_header_2 = QobjExperimentHeader(creg_sizes=[["c0", 4]], memory_slots=4) + with self.assertWarns(DeprecationWarning): + exp_result_header_2 = QobjExperimentHeader(creg_sizes=[["c0", 4]], memory_slots=4) exp_result_2 = models.ExperimentResult( shots=14, success=True, meas_level=2, data=data_2, header=exp_result_header_2 ) @@ -153,7 +160,8 @@ def test_multiple_circuits_counts(self): raw_counts_3 = {"0xC": 27, "0xF": 20} processed_counts_3 = {"1100": 27, "1111": 20} data_3 = models.ExperimentResultData(counts=raw_counts_3) - exp_result_header_3 = QobjExperimentHeader(creg_sizes=[["c0", 4]], memory_slots=4) + with self.assertWarns(DeprecationWarning): + exp_result_header_3 = QobjExperimentHeader(creg_sizes=[["c0", 4]], memory_slots=4) exp_result_3 = models.ExperimentResult( shots=14, success=True, meas_level=2, data=data_3, header=exp_result_header_3 ) @@ -172,7 +180,8 @@ def test_marginal_counts(self): """Test that counts are marginalized correctly.""" raw_counts = {"0x0": 4, "0x1": 7, "0x2": 10, "0x6": 5, "0x9": 11, "0xD": 9, "0xE": 8} data = models.ExperimentResultData(counts=raw_counts) - exp_result_header = QobjExperimentHeader(creg_sizes=[["c0", 4]], memory_slots=4) + with self.assertWarns(DeprecationWarning): + exp_result_header = QobjExperimentHeader(creg_sizes=[["c0", 4]], memory_slots=4) exp_result = models.ExperimentResult( shots=54, success=True, data=data, header=exp_result_header ) @@ -186,7 +195,8 @@ def test_marginal_distribution(self): """Test that counts are marginalized correctly.""" raw_counts = {"0x0": 4, "0x1": 7, "0x2": 10, "0x6": 5, "0x9": 11, "0xD": 9, "0xE": 8} data = models.ExperimentResultData(counts=raw_counts) - exp_result_header = QobjExperimentHeader(creg_sizes=[["c0", 4]], memory_slots=4) + with self.assertWarns(DeprecationWarning): + exp_result_header = QobjExperimentHeader(creg_sizes=[["c0", 4]], memory_slots=4) exp_result = models.ExperimentResult( shots=54, success=True, data=data, header=exp_result_header ) @@ -200,7 +210,10 @@ def test_marginal_distribution(self): self.assertEqual(marginal_distribution(result.get_counts(), [1, 0]), expected_reverse) # test with register spacing, bitstrings are in form of "00 00" for register split data = models.ExperimentResultData(counts=raw_counts) - exp_result_header = QobjExperimentHeader(creg_sizes=[["c0", 2], ["c1", 2]], memory_slots=4) + with self.assertWarns(DeprecationWarning): + exp_result_header = QobjExperimentHeader( + creg_sizes=[["c0", 2], ["c1", 2]], memory_slots=4 + ) exp_result = models.ExperimentResult( shots=54, success=True, data=data, header=exp_result_header ) @@ -214,14 +227,16 @@ def test_marginal_counts_result(self): """Test that a Result object containing counts marginalizes correctly.""" raw_counts_1 = {"0x0": 4, "0x1": 7, "0x2": 10, "0x6": 5, "0x9": 11, "0xD": 9, "0xE": 8} data_1 = models.ExperimentResultData(counts=raw_counts_1) - exp_result_header_1 = QobjExperimentHeader(creg_sizes=[["c0", 4]], memory_slots=4) + with self.assertWarns(DeprecationWarning): + exp_result_header_1 = QobjExperimentHeader(creg_sizes=[["c0", 4]], memory_slots=4) exp_result_1 = models.ExperimentResult( shots=54, success=True, data=data_1, header=exp_result_header_1 ) raw_counts_2 = {"0x2": 5, "0x3": 8} data_2 = models.ExperimentResultData(counts=raw_counts_2) - exp_result_header_2 = QobjExperimentHeader(creg_sizes=[["c0", 2]], memory_slots=2) + with self.assertWarns(DeprecationWarning): + exp_result_header_2 = QobjExperimentHeader(creg_sizes=[["c0", 2]], memory_slots=2) exp_result_2 = models.ExperimentResult( shots=13, success=True, data=data_2, header=exp_result_header_2 ) @@ -240,14 +255,20 @@ def test_marginal_counts_result(self): "1110": 8, } - self.assertEqual(marginal_counts(result, [0, 1]).get_counts(0), expected_marginal_counts_1) - self.assertEqual(marginal_counts(result, [0]).get_counts(1), expected_marginal_counts_2) - self.assertEqual(marginal_counts(result, None).get_counts(0), expected_marginal_counts_none) + with self.assertWarns(DeprecationWarning): + self.assertEqual( + marginal_counts(result, [0, 1]).get_counts(0), expected_marginal_counts_1 + ) + self.assertEqual(marginal_counts(result, [0]).get_counts(1), expected_marginal_counts_2) + self.assertEqual( + marginal_counts(result, None).get_counts(0), expected_marginal_counts_none + ) def test_marginal_counts_result_memory(self): """Test that a Result object containing memory marginalizes correctly.""" result = self.generate_qiskit_result() - marginal_result = marginal_counts(result, indices=[0]) + with self.assertWarns(DeprecationWarning): + marginal_result = marginal_counts(result, indices=[0]) marginal_memory = marginal_result.results[0].data.memory self.assertEqual(marginal_memory, [hex(ii % 2) for ii in range(8)]) @@ -255,7 +276,8 @@ def test_marginal_counts_result_memory_nonzero_indices(self): """Test that a Result object containing memory marginalizes correctly.""" result = self.generate_qiskit_result() index = 2 - marginal_result = marginal_counts(result, indices=[index]) + with self.assertWarns(DeprecationWarning): + marginal_result = marginal_counts(result, indices=[index]) marginal_memory = marginal_result.results[0].data.memory mask = 1 << index expected = [hex((ii & mask) >> index) for ii in range(8)] @@ -266,7 +288,8 @@ def test_marginal_counts_result_memory_indices_None(self): result = self.generate_qiskit_result() memory = "should not be touched" result.results[0].data.memory = memory - marginal_result = marginal_counts(result, indices=None) + with self.assertWarns(DeprecationWarning): + marginal_result = marginal_counts(result, indices=None) marginal_memory = marginal_result.results[0].data.memory self.assertEqual(marginal_memory, memory) @@ -297,17 +320,20 @@ def test_marginal_counts_result_marginalize_memory(self): self.assertTrue(hasattr(marginal_result.results[0].data, "memory")) result = self.generate_qiskit_result() - marginal_result = marginal_counts( - result, indices=[0], inplace=False, marginalize_memory=False - ) + with self.assertWarns(DeprecationWarning): + marginal_result = marginal_counts( + result, indices=[0], inplace=False, marginalize_memory=False + ) self.assertFalse(hasattr(marginal_result.results[0].data, "memory")) - marginal_result = marginal_counts( - result, indices=[0], inplace=False, marginalize_memory=None - ) + with self.assertWarns(DeprecationWarning): + marginal_result = marginal_counts( + result, indices=[0], inplace=False, marginalize_memory=None + ) self.assertTrue(hasattr(marginal_result.results[0].data, "memory")) - marginal_result = marginal_counts( - result, indices=[0], inplace=False, marginalize_memory=True - ) + with self.assertWarns(DeprecationWarning): + marginal_result = marginal_counts( + result, indices=[0], inplace=False, marginalize_memory=True + ) self.assertTrue(hasattr(marginal_result.results[0].data, "memory")) def test_marginal_counts_result_inplace(self): @@ -323,7 +349,10 @@ def test_marginal_counts_result_creg_sizes(self): """Test that marginal_counts with Result input properly changes creg_sizes.""" raw_counts = {"0x0": 4, "0x1": 7, "0x2": 10, "0x6": 5, "0x9": 11, "0xD": 9, "0xE": 8} data = models.ExperimentResultData(counts=raw_counts) - exp_result_header = QobjExperimentHeader(creg_sizes=[["c0", 1], ["c1", 3]], memory_slots=4) + with self.assertWarns(DeprecationWarning): + exp_result_header = QobjExperimentHeader( + creg_sizes=[["c0", 1], ["c1", 3]], memory_slots=4 + ) exp_result = models.ExperimentResult( shots=54, success=True, data=data, header=exp_result_header ) @@ -333,7 +362,8 @@ def test_marginal_counts_result_creg_sizes(self): expected_marginal_counts = {"0 0": 14, "0 1": 18, "1 0": 13, "1 1": 9} expected_creg_sizes = [["c0", 1], ["c1", 1]] expected_memory_slots = 2 - marginal_counts_result = marginal_counts(result, [0, 2]) + with self.assertWarns(DeprecationWarning): + marginal_counts_result = marginal_counts(result, [0, 2]) self.assertEqual(marginal_counts_result.results[0].header.creg_sizes, expected_creg_sizes) self.assertEqual( marginal_counts_result.results[0].header.memory_slots, expected_memory_slots @@ -344,9 +374,10 @@ def test_marginal_counts_result_format(self): """Test that marginal_counts with format_marginal true properly formats output.""" raw_counts_1 = {"0x0": 4, "0x1": 7, "0x2": 10, "0x6": 5, "0x9": 11, "0xD": 9, "0x12": 8} data_1 = models.ExperimentResultData(counts=raw_counts_1) - exp_result_header_1 = QobjExperimentHeader( - creg_sizes=[["c0", 2], ["c1", 3]], memory_slots=5 - ) + with self.assertWarns(DeprecationWarning): + exp_result_header_1 = QobjExperimentHeader( + creg_sizes=[["c0", 2], ["c1", 3]], memory_slots=5 + ) exp_result_1 = models.ExperimentResult( shots=54, success=True, data=data_1, header=exp_result_header_1 ) @@ -369,14 +400,16 @@ def test_marginal_counts_inplace_true(self): """Test marginal_counts(Result, inplace = True)""" raw_counts_1 = {"0x0": 4, "0x1": 7, "0x2": 10, "0x6": 5, "0x9": 11, "0xD": 9, "0xE": 8} data_1 = models.ExperimentResultData(counts=raw_counts_1) - exp_result_header_1 = QobjExperimentHeader(creg_sizes=[["c0", 4]], memory_slots=4) + with self.assertWarns(DeprecationWarning): + exp_result_header_1 = QobjExperimentHeader(creg_sizes=[["c0", 4]], memory_slots=4) exp_result_1 = models.ExperimentResult( shots=54, success=True, data=data_1, header=exp_result_header_1 ) raw_counts_2 = {"0x2": 5, "0x3": 8} data_2 = models.ExperimentResultData(counts=raw_counts_2) - exp_result_header_2 = QobjExperimentHeader(creg_sizes=[["c0", 2]], memory_slots=2) + with self.assertWarns(DeprecationWarning): + exp_result_header_2 = QobjExperimentHeader(creg_sizes=[["c0", 2]], memory_slots=2) exp_result_2 = models.ExperimentResult( shots=13, success=True, data=data_2, header=exp_result_header_2 ) @@ -394,14 +427,16 @@ def test_marginal_counts_inplace_false(self): """Test marginal_counts(Result, inplace=False)""" raw_counts_1 = {"0x0": 4, "0x1": 7, "0x2": 10, "0x6": 5, "0x9": 11, "0xD": 9, "0xE": 8} data_1 = models.ExperimentResultData(counts=raw_counts_1) - exp_result_header_1 = QobjExperimentHeader(creg_sizes=[["c0", 4]], memory_slots=4) + with self.assertWarns(DeprecationWarning): + exp_result_header_1 = QobjExperimentHeader(creg_sizes=[["c0", 4]], memory_slots=4) exp_result_1 = models.ExperimentResult( shots=54, success=True, data=data_1, header=exp_result_header_1 ) raw_counts_2 = {"0x2": 5, "0x3": 8} data_2 = models.ExperimentResultData(counts=raw_counts_2) - exp_result_header_2 = QobjExperimentHeader(creg_sizes=[["c0", 2]], memory_slots=2) + with self.assertWarns(DeprecationWarning): + exp_result_header_2 = QobjExperimentHeader(creg_sizes=[["c0", 2]], memory_slots=2) exp_result_2 = models.ExperimentResult( shots=13, success=True, data=data_2, header=exp_result_header_2 ) @@ -410,9 +445,10 @@ def test_marginal_counts_inplace_false(self): expected_marginal_counts = {"0": 27, "1": 27} - self.assertEqual( - marginal_counts(result, [0], inplace=False).get_counts(0), expected_marginal_counts - ) + with self.assertWarns(DeprecationWarning): + self.assertEqual( + marginal_counts(result, [0], inplace=False).get_counts(0), expected_marginal_counts + ) self.assertNotEqual(result.get_counts(0), expected_marginal_counts) def test_marginal_counts_with_dict(self): @@ -465,9 +501,10 @@ def test_memory_counts_header(self): "0 0 10", ] data = models.ExperimentResultData(memory=raw_memory) - exp_result_header = QobjExperimentHeader( - creg_sizes=[["c0", 2], ["c0", 1], ["c1", 1]], memory_slots=4 - ) + with self.assertWarns(DeprecationWarning): + exp_result_header = QobjExperimentHeader( + creg_sizes=[["c0", 2], ["c0", 1], ["c1", 1]], memory_slots=4 + ) exp_result = models.ExperimentResult( shots=14, success=True, meas_level=2, memory=True, data=data, header=exp_result_header ) @@ -703,9 +740,10 @@ def test_counts_name_out(self): """Test that fails when get_count is called with a nonexistent name.""" raw_counts = {"0x0": 4, "0x2": 10} data = models.ExperimentResultData(counts=raw_counts) - exp_result_header = QobjExperimentHeader( - creg_sizes=[["c0", 2], ["c0", 1], ["c1", 1]], memory_slots=4, name="a_name" - ) + with self.assertWarns(DeprecationWarning): + exp_result_header = QobjExperimentHeader( + creg_sizes=[["c0", 2], ["c0", 1], ["c1", 1]], memory_slots=4, name="a_name" + ) exp_result = models.ExperimentResult( shots=14, success=True, meas_level=2, data=data, header=exp_result_header ) @@ -736,13 +774,15 @@ def test_marginal_counts_no_cregs(self): """Test that marginal_counts without cregs See qiskit-terra/6430.""" raw_counts_1 = {"0x0": 4, "0x1": 7, "0x2": 10, "0x6": 5, "0x9": 11, "0xD": 9, "0x12": 8} data_1 = models.ExperimentResultData(counts=raw_counts_1) - exp_result_header_1 = QobjExperimentHeader(memory_slots=5) + with self.assertWarns(DeprecationWarning): + exp_result_header_1 = QobjExperimentHeader(memory_slots=5) exp_result_1 = models.ExperimentResult( shots=54, success=True, data=data_1, header=exp_result_header_1 ) result = Result(results=[exp_result_1], **self.base_result_args) - _ = marginal_counts(result, indices=[0]) - marginal_counts_result = marginal_counts(result, indices=[0]) + with self.assertWarns(DeprecationWarning): + _ = marginal_counts(result, indices=[0]) + marginal_counts_result = marginal_counts(result, indices=[0]) self.assertEqual(marginal_counts_result.get_counts(), {"0": 27, "1": 27}) From 7edd883ba39113e738ce0a97f841610339052aa3 Mon Sep 17 00:00:00 2001 From: Luciano Bello Date: Fri, 28 Jun 2024 20:31:25 +0200 Subject: [PATCH 10/51] test.python.pulse.test_calibration_entries --- test/python/pulse/test_calibration_entries.py | 168 +++++++++--------- 1 file changed, 87 insertions(+), 81 deletions(-) diff --git a/test/python/pulse/test_calibration_entries.py b/test/python/pulse/test_calibration_entries.py index 20e6773d2fd2..cc31789ef683 100644 --- a/test/python/pulse/test_calibration_entries.py +++ b/test/python/pulse/test_calibration_entries.py @@ -281,29 +281,31 @@ class TestPulseQobj(QiskitTestCase): def setUp(self): super().setUp() - self.converter = QobjToInstructionConverter( - pulse_library=[ - PulseLibraryItem(name="waveform", samples=[0.3, 0.1, 0.2, 0.2, 0.3]), - ] - ) + with self.assertWarns(DeprecationWarning): + self.converter = QobjToInstructionConverter( + pulse_library=[ + PulseLibraryItem(name="waveform", samples=[0.3, 0.1, 0.2, 0.2, 0.3]), + ] + ) def test_add_qobj(self): """Basic test PulseQobj format.""" - serialized_program = [ - PulseQobjInstruction( - name="parametric_pulse", - t0=0, - ch="d0", - label="TestPulse", - pulse_shape="constant", - parameters={"amp": 0.1 + 0j, "duration": 10}, - ), - PulseQobjInstruction( - name="waveform", - t0=20, - ch="d0", - ), - ] + with self.assertWarns(DeprecationWarning): + serialized_program = [ + PulseQobjInstruction( + name="parametric_pulse", + t0=0, + ch="d0", + label="TestPulse", + pulse_shape="constant", + parameters={"amp": 0.1 + 0j, "duration": 10}, + ), + PulseQobjInstruction( + name="waveform", + t0=20, + ch="d0", + ), + ] entry = PulseQobjDef(converter=self.converter, name="my_gate") entry.define(serialized_program) @@ -328,13 +330,14 @@ def test_add_qobj(self): def test_missing_waveform(self): """Test incomplete Qobj should raise warning and calibration returns None.""" - serialized_program = [ - PulseQobjInstruction( - name="waveform_123456", - t0=20, - ch="d0", - ), - ] + with self.assertWarns(DeprecationWarning): + serialized_program = [ + PulseQobjInstruction( + name="waveform_123456", + t0=20, + ch="d0", + ), + ] entry = PulseQobjDef(converter=self.converter, name="my_gate") entry.define(serialized_program) @@ -355,22 +358,23 @@ def test_parameterized_qobj(self): Note that pulse parameter cannot be parameterized by convention. """ - serialized_program = [ - PulseQobjInstruction( - name="parametric_pulse", - t0=0, - ch="d0", - label="TestPulse", - pulse_shape="constant", - parameters={"amp": 0.1, "duration": 10}, - ), - PulseQobjInstruction( - name="fc", - t0=0, - ch="d0", - phase="P1", - ), - ] + with self.assertWarns(DeprecationWarning): + serialized_program = [ + PulseQobjInstruction( + name="parametric_pulse", + t0=0, + ch="d0", + label="TestPulse", + pulse_shape="constant", + parameters={"amp": 0.1, "duration": 10}, + ), + PulseQobjInstruction( + name="fc", + t0=0, + ch="d0", + phase="P1", + ), + ] entry = PulseQobjDef(converter=self.converter, name="my_gate") entry.define(serialized_program) @@ -395,27 +399,27 @@ def test_parameterized_qobj(self): def test_equality(self): """Test equality evaluation between the pulse qobj entries.""" - serialized_program1 = [ - PulseQobjInstruction( - name="parametric_pulse", - t0=0, - ch="d0", - label="TestPulse", - pulse_shape="constant", - parameters={"amp": 0.1, "duration": 10}, - ) - ] - - serialized_program2 = [ - PulseQobjInstruction( - name="parametric_pulse", - t0=0, - ch="d0", - label="TestPulse", - pulse_shape="constant", - parameters={"amp": 0.2, "duration": 10}, - ) - ] + with self.assertWarns(DeprecationWarning): + serialized_program1 = [ + PulseQobjInstruction( + name="parametric_pulse", + t0=0, + ch="d0", + label="TestPulse", + pulse_shape="constant", + parameters={"amp": 0.1, "duration": 10}, + ) + ] + serialized_program2 = [ + PulseQobjInstruction( + name="parametric_pulse", + t0=0, + ch="d0", + label="TestPulse", + pulse_shape="constant", + parameters={"amp": 0.2, "duration": 10}, + ) + ] entry1 = PulseQobjDef(name="my_gate1") entry1.define(serialized_program1) @@ -435,16 +439,17 @@ def test_equality_with_schedule(self): Because the pulse qobj entry is a subclass of the schedule entry, these instances can be compared by the generated definition, i.e. Schedule. """ - serialized_program = [ - PulseQobjInstruction( - name="parametric_pulse", - t0=0, - ch="d0", - label="TestPulse", - pulse_shape="constant", - parameters={"amp": 0.1, "duration": 10}, - ) - ] + with self.assertWarns(DeprecationWarning): + serialized_program = [ + PulseQobjInstruction( + name="parametric_pulse", + t0=0, + ch="d0", + label="TestPulse", + pulse_shape="constant", + parameters={"amp": 0.1, "duration": 10}, + ) + ] entry1 = PulseQobjDef(name="qobj_entry") entry1.define(serialized_program) @@ -470,13 +475,14 @@ def test_calibration_missing_waveform(self): In this situation, parsed calibration data must become None, instead of raising an error. """ - serialized_program = [ - PulseQobjInstruction( - name="SomeMissingPulse", - t0=0, - ch="d0", - ) - ] + with self.assertWarns(DeprecationWarning): + serialized_program = [ + PulseQobjInstruction( + name="SomeMissingPulse", + t0=0, + ch="d0", + ) + ] entry = PulseQobjDef(name="qobj_entry") entry.define(serialized_program) From b5e8b2871e4e41667f1b48114854ffeffa87cbc9 Mon Sep 17 00:00:00 2001 From: Luciano Bello Date: Fri, 28 Jun 2024 22:17:09 +0200 Subject: [PATCH 11/51] test.python.compiler.test_assembler --- test/python/compiler/test_assembler.py | 977 ++++++++++++++----------- 1 file changed, 542 insertions(+), 435 deletions(-) diff --git a/test/python/compiler/test_assembler.py b/test/python/compiler/test_assembler.py index 1a6e5b6b8fe5..ff1f86f228db 100644 --- a/test/python/compiler/test_assembler.py +++ b/test/python/compiler/test_assembler.py @@ -80,7 +80,8 @@ def setUp(self): def test_assemble_single_circuit(self): """Test assembling a single circuit.""" - qobj = assemble(self.circ, shots=2000, memory=True) + with self.assertWarns(DeprecationWarning): + qobj = assemble(self.circ, shots=2000, memory=True) self.assertIsInstance(qobj, QasmQobj) self.assertEqual(qobj.config.shots, 2000) @@ -105,7 +106,8 @@ def test_assemble_multiple_circuits(self): circ1.cx(qr1[0], qr1[2]) circ1.measure(qr1, qc1) - qobj = assemble([circ0, circ1], shots=100, memory=False, seed_simulator=6) + with self.assertWarns(DeprecationWarning): + qobj = assemble([circ0, circ1], shots=100, memory=False, seed_simulator=6) self.assertIsInstance(qobj, QasmQobj) self.assertEqual(qobj.config.seed_simulator, 6) @@ -116,29 +118,34 @@ def test_assemble_multiple_circuits(self): def test_assemble_no_run_config(self): """Test assembling with no run_config, relying on default.""" - qobj = assemble(self.circ) + with self.assertWarns(DeprecationWarning): + qobj = assemble(self.circ) self.assertIsInstance(qobj, QasmQobj) self.assertEqual(qobj.config.shots, 1024) def test_shots_greater_than_max_shots(self): """Test assembling with shots greater than max shots""" - self.assertRaises(QiskitError, assemble, self.backend, shots=1024000) + with self.assertWarns(DeprecationWarning): + self.assertRaises(QiskitError, assemble, self.backend, shots=1024000) def test_shots_not_of_type_int(self): """Test assembling with shots having type other than int""" - self.assertRaises(QiskitError, assemble, self.backend, shots="1024") + with self.assertWarns(DeprecationWarning): + self.assertRaises(QiskitError, assemble, self.backend, shots="1024") def test_shots_of_type_numpy_int64(self): """Test assembling with shots having type numpy.int64""" - qobj = assemble(self.circ, shots=np.int64(2048)) + with self.assertWarns(DeprecationWarning): + qobj = assemble(self.circ, shots=np.int64(2048)) self.assertEqual(qobj.config.shots, 2048) def test_default_shots_greater_than_max_shots(self): """Test assembling with default shots greater than max shots""" self.backend_config.max_shots = 5 - qobj = assemble(self.circ, self.backend) + with self.assertWarns(DeprecationWarning): + qobj = assemble(self.circ, self.backend) self.assertIsInstance(qobj, QasmQobj) self.assertEqual(qobj.config.shots, 5) @@ -149,7 +156,8 @@ def test_assemble_initialize(self): circ = QuantumCircuit(q, name="circ") circ.initialize([1 / np.sqrt(2), 0, 0, 1 / np.sqrt(2)], q[:]) - qobj = assemble(circ) + with self.assertWarns(DeprecationWarning): + qobj = assemble(circ) self.assertIsInstance(qobj, QasmQobj) self.assertEqual(qobj.experiments[0].instructions[0].name, "initialize") @@ -159,14 +167,16 @@ def test_assemble_initialize(self): def test_assemble_meas_level_meas_return(self): """Test assembling a circuit schedule with `meas_level`.""" - qobj = assemble(self.circ, meas_level=1, meas_return="single") + with self.assertWarns(DeprecationWarning): + qobj = assemble(self.circ, meas_level=1, meas_return="single") self.assertIsInstance(qobj, QasmQobj) self.assertEqual(qobj.config.meas_level, 1) self.assertEqual(qobj.config.meas_return, "single") # no meas_level set - qobj = assemble(self.circ) + with self.assertWarns(DeprecationWarning): + qobj = assemble(self.circ) self.assertIsInstance(qobj, QasmQobj) self.assertEqual(qobj.config.meas_level, 2) @@ -181,12 +191,14 @@ def test_assemble_backend_rep_delays(self): # dynamic rep rates off setattr(self.backend_config, "dynamic_reprate_enabled", False) - qobj = assemble(self.circ, self.backend) + with self.assertWarns(DeprecationWarning): + qobj = assemble(self.circ, self.backend) self.assertEqual(hasattr(qobj.config, "rep_delay"), False) # dynamic rep rates on setattr(self.backend_config, "dynamic_reprate_enabled", True) - qobj = assemble(self.circ, self.backend) + with self.assertWarns(DeprecationWarning): + qobj = assemble(self.circ, self.backend) self.assertEqual(qobj.config.rep_delay, default_rep_delay * 1e6) def test_assemble_user_rep_time_delay(self): @@ -198,22 +210,26 @@ def test_assemble_user_rep_time_delay(self): # dynamic rep rates off (no default so shouldn't be in qobj config) setattr(self.backend_config, "dynamic_reprate_enabled", False) - qobj = assemble(self.circ, self.backend, rep_delay=rep_delay) + with self.assertWarns(DeprecationWarning): + qobj = assemble(self.circ, self.backend, rep_delay=rep_delay) self.assertEqual(hasattr(qobj.config, "rep_delay"), False) # turn on dynamic rep rates, rep_delay should be set setattr(self.backend_config, "dynamic_reprate_enabled", True) - qobj = assemble(self.circ, self.backend, rep_delay=rep_delay) + with self.assertWarns(DeprecationWarning): + qobj = assemble(self.circ, self.backend, rep_delay=rep_delay) self.assertEqual(qobj.config.rep_delay, 2.2) # test ``rep_delay=0`` - qobj = assemble(self.circ, self.backend, rep_delay=0) + with self.assertWarns(DeprecationWarning): + qobj = assemble(self.circ, self.backend, rep_delay=0) self.assertEqual(qobj.config.rep_delay, 0) # use ``rep_delay`` outside of ``rep_delay_range``` rep_delay_large = 5.0e-6 - with self.assertRaises(QiskitError): - assemble(self.circ, self.backend, rep_delay=rep_delay_large) + with self.assertWarns(DeprecationWarning): + with self.assertRaises(QiskitError): + assemble(self.circ, self.backend, rep_delay=rep_delay_large) def test_assemble_opaque_inst(self): """Test opaque instruction is assembled as-is""" @@ -223,7 +239,8 @@ def test_assemble_opaque_inst(self): circ = QuantumCircuit(q, c, name="circ") circ.append(opaque_inst, [q[0], q[2], q[5], q[3]], [c[3], c[0]]) - qobj = assemble(circ) + with self.assertWarns(DeprecationWarning): + qobj = assemble(circ) self.assertIsInstance(qobj, QasmQobj) self.assertEqual(len(qobj.experiments[0].instructions), 1) @@ -245,7 +262,8 @@ def test_assemble_unroll_parametervector(self): qc.assign_parameters({pv1: [0.1, 0.2, 0.3], pv2: [0.4, 0.5, 0.6]}) - qobj = assemble(qc, parameter_binds=[{pv1: [0.1, 0.2, 0.3], pv2: [0.4, 0.5, 0.6]}]) + with self.assertWarns(DeprecationWarning): + qobj = assemble(qc, parameter_binds=[{pv1: [0.1, 0.2, 0.3], pv2: [0.4, 0.5, 0.6]}]) self.assertIsInstance(qobj, QasmQobj) self.assertEqual(qobj.experiments[0].instructions[0].params[0], 0.100000000000000) @@ -267,7 +285,8 @@ def test_measure_to_registers_when_conditionals(self): qc.measure(qr[1], cr2[1]) # Measure required for a later conditional qc.h(qr[1]).c_if(cr2, 3) - qobj = assemble(qc) + with self.assertWarns(DeprecationWarning): + qobj = assemble(qc) first_measure, second_measure = ( op for op in qobj.experiments[0].instructions if op.name == "measure" @@ -286,7 +305,8 @@ def test_convert_to_bfunc_plus_conditional(self): qc.h(qr[0]).c_if(cr, 1) - qobj = assemble(qc) + with self.assertWarns(DeprecationWarning): + qobj = assemble(qc) bfunc_op, h_op = qobj.experiments[0].instructions @@ -306,7 +326,8 @@ def test_convert_to_bfunc_plus_conditional_onebit(self): qc.h(qr[0]).c_if(cr[2], 1) - qobj = assemble(qc) + with self.assertWarns(DeprecationWarning): + qobj = assemble(qc) inst_set = qobj.experiments[0].instructions [bfunc_op, h_op] = inst_set @@ -331,7 +352,8 @@ def test_resize_value_to_register(self): qc.h(qr[0]).c_if(cr2, 2) - qobj = assemble(qc) + with self.assertWarns(DeprecationWarning): + qobj = assemble(qc) bfunc_op, h_op = qobj.experiments[0].instructions @@ -363,23 +385,24 @@ def test_assemble_circuits_raises_for_bind_circuit_mismatch(self): full_bind_args = {"parameter_binds": [{x: 1, y: 1}, {x: 0, y: 0}]} inconsistent_bind_args = {"parameter_binds": [{x: 1}, {x: 0, y: 0}]} - # Raise when parameters passed for non-parametric circuit - self.assertRaises(QiskitError, assemble, full_bound_circ, **partial_bind_args) + with self.assertWarns(DeprecationWarning): + # Raise when parameters passed for non-parametric circuit + self.assertRaises(QiskitError, assemble, full_bound_circ, **partial_bind_args) - # Raise when no parameters passed for parametric circuit - self.assertRaises(QiskitError, assemble, partial_param_circ) - self.assertRaises(QiskitError, assemble, full_param_circ) + # Raise when no parameters passed for parametric circuit + self.assertRaises(QiskitError, assemble, partial_param_circ) + self.assertRaises(QiskitError, assemble, full_param_circ) - # Raise when circuit has more parameters than run_config - self.assertRaises(QiskitError, assemble, full_param_circ, **partial_bind_args) + # Raise when circuit has more parameters than run_config + self.assertRaises(QiskitError, assemble, full_param_circ, **partial_bind_args) - # Raise when not all circuits have all parameters - self.assertRaises( - QiskitError, assemble, [full_param_circ, partial_param_circ], **full_bind_args - ) + # Raise when not all circuits have all parameters + self.assertRaises( + QiskitError, assemble, [full_param_circ, partial_param_circ], **full_bind_args + ) - # Raise when not all binds have all circuit params - self.assertRaises(QiskitError, assemble, full_param_circ, **inconsistent_bind_args) + # Raise when not all binds have all circuit params + self.assertRaises(QiskitError, assemble, full_param_circ, **inconsistent_bind_args) def test_assemble_circuits_rases_for_bind_mismatch_over_expressions(self): """Verify assemble_circuits raises for invalid binds for circuit including @@ -395,11 +418,13 @@ def test_assemble_circuits_rases_for_bind_mismatch_over_expressions(self): partial_bind_args = {"parameter_binds": [{x: 1}, {x: 0}]} - # Raise when no parameters passed for parametric circuit - self.assertRaises(QiskitError, assemble, expr_circ) + with self.assertWarns(DeprecationWarning): + # Raise when no parameters passed for parametric circuit + self.assertRaises(QiskitError, assemble, expr_circ) - # Raise when circuit has more parameters than run_config - self.assertRaises(QiskitError, assemble, expr_circ, **partial_bind_args) + with self.assertWarns(DeprecationWarning): + # Raise when circuit has more parameters than run_config + self.assertRaises(QiskitError, assemble, expr_circ, **partial_bind_args) def test_assemble_circuits_binds_parameters(self): """Verify assemble_circuits applies parameter bindings and output circuits are bound.""" @@ -422,7 +447,8 @@ def test_assemble_circuits_binds_parameters(self): bind_args = {"parameter_binds": [{x: 0, y: 0}, {x: 1, y: 0}, {x: 1, y: 1}]} - qobj = assemble([qc1, qc2, qc3], **bind_args) + with self.assertWarns(DeprecationWarning): + qobj = assemble([qc1, qc2, qc3], **bind_args) self.assertEqual(len(qobj.experiments), 9) self.assertEqual( @@ -451,17 +477,20 @@ def _qobj_inst_params(expt_no, inst_no): def test_init_qubits_default(self): """Check that the init_qubits=None assemble option is passed on to the qobj.""" - qobj = assemble(self.circ) + with self.assertWarns(DeprecationWarning): + qobj = assemble(self.circ) self.assertEqual(qobj.config.init_qubits, True) def test_init_qubits_true(self): """Check that the init_qubits=True assemble option is passed on to the qobj.""" - qobj = assemble(self.circ, init_qubits=True) + with self.assertWarns(DeprecationWarning): + qobj = assemble(self.circ, init_qubits=True) self.assertEqual(qobj.config.init_qubits, True) def test_init_qubits_false(self): """Check that the init_qubits=False assemble option is passed on to the qobj.""" - qobj = assemble(self.circ, init_qubits=False) + with self.assertWarns(DeprecationWarning): + qobj = assemble(self.circ, init_qubits=False) self.assertEqual(qobj.config.init_qubits, False) def test_circuit_with_global_phase(self): @@ -471,7 +500,8 @@ def test_circuit_with_global_phase(self): circ.cx(0, 1) circ.measure_all() circ.global_phase = 0.3 * np.pi - qobj = assemble([circ, self.circ]) + with self.assertWarns(DeprecationWarning): + qobj = assemble([circ, self.circ]) self.assertEqual(getattr(qobj.experiments[1].header, "global_phase"), 0) self.assertEqual(getattr(qobj.experiments[0].header, "global_phase"), 0.3 * np.pi) @@ -493,10 +523,12 @@ def _define(self): gate = TestGate() circ = QuantumCircuit(1) circ.append(gate, [0]) - qobj = assemble([circ]) + with self.assertWarns(DeprecationWarning): + qobj = assemble([circ]) self.assertEqual(getattr(qobj.experiments[0].header, "global_phase"), 0) circ.global_phase = np.pi / 2 - qobj = assemble([circ]) + with self.assertWarns(DeprecationWarning): + qobj = assemble([circ]) self.assertEqual(getattr(qobj.experiments[0].header, "global_phase"), np.pi / 2) def test_pulse_gates_single_circ(self): @@ -518,7 +550,8 @@ def test_pulse_gates_single_circ(self): circ.add_calibration(RxGate(3.14), [0], x180) circ.add_calibration(RxGate(3.14), [1], x180) - qobj = assemble(circ, FakeOpenPulse2Q()) + with self.assertWarns(DeprecationWarning): + qobj = assemble(circ, FakeOpenPulse2Q()) # Only one circuit, so everything is stored at the job level cals = qobj.config.calibrations lib = qobj.config.pulse_library @@ -539,7 +572,8 @@ def test_custom_pulse_gates_single_circ(self): circ.add_calibration("h", [0], custom_h_schedule) - qobj = assemble(circ, FakeOpenPulse2Q()) + with self.assertWarns(DeprecationWarning): + qobj = assemble(circ, FakeOpenPulse2Q()) lib = qobj.config.pulse_library self.assertEqual(len(lib), 1) np.testing.assert_almost_equal( @@ -559,7 +593,8 @@ def test_pulse_gates_with_parameteric_pulses(self): backend = FakeOpenPulse2Q() backend.configuration().parametric_pulses = ["drag"] - qobj = assemble(circ, backend) + with self.assertWarns(DeprecationWarning): + qobj = assemble(circ, backend) self.assertFalse(hasattr(qobj.config, "pulse_library")) self.assertTrue(hasattr(qobj.config, "calibrations")) @@ -577,7 +612,8 @@ def test_pulse_gates_multiple_circuits(self): circ2 = QuantumCircuit(2) circ2.h(0) - qobj = assemble([circ, circ2], FakeOpenPulse2Q()) + with self.assertWarns(DeprecationWarning): + qobj = assemble([circ, circ2], FakeOpenPulse2Q()) self.assertEqual(len(qobj.config.pulse_library), 1) self.assertEqual(len(qobj.experiments[0].config.calibrations.gates), 2) self.assertFalse(hasattr(qobj.config, "calibrations")) @@ -598,7 +634,8 @@ def test_pulse_gates_common_cals(self): circ2.h(0) circ2.add_calibration(RxGate(3.14), [1], dummy_sched) - qobj = assemble([circ, circ2], FakeOpenPulse2Q()) + with self.assertWarns(DeprecationWarning): + qobj = assemble([circ, circ2], FakeOpenPulse2Q()) # Identical pulses are only added once self.assertEqual(len(qobj.config.pulse_library), 1) # Identical calibrations are only added once @@ -611,7 +648,8 @@ def test_pulse_gates_common_cals(self): def test_assemble_adds_circuit_metadata_to_experiment_header(self): """Verify that any circuit metadata is added to the experiment header.""" circ = QuantumCircuit(2, metadata={"experiment_type": "gst", "execution_number": "1234"}) - qobj = assemble(circ, shots=100, memory=False, seed_simulator=6) + with self.assertWarns(DeprecationWarning): + qobj = assemble(circ, shots=100, memory=False, seed_simulator=6) self.assertEqual( qobj.experiments[0].header.metadata, {"experiment_type": "gst", "execution_number": "1234"}, @@ -623,7 +661,8 @@ def test_pulse_gates_delay_only(self): 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) - qobj = assemble(circ, FakeOpenPulse2Q()) + with self.assertWarns(DeprecationWarning): + qobj = assemble(circ, FakeOpenPulse2Q()) self.assertEqual(len(qobj.config.calibrations.gates[0].instructions), 2) self.assertEqual( qobj.config.calibrations.gates[0].instructions[1].to_dict(), @@ -633,12 +672,13 @@ def test_pulse_gates_delay_only(self): def test_job_qubit_meas_los_no_range(self): """Test that adding job qubit/meas lo freq lists are assembled into the qobj.config, w/ out any lo range.""" - qobj = assemble( - self.circ, - backend=self.backend, - qubit_lo_freq=self.default_qubit_lo_freq, - meas_lo_freq=self.default_meas_lo_freq, - ) + with self.assertWarns(DeprecationWarning): + qobj = assemble( + self.circ, + backend=self.backend, + qubit_lo_freq=self.default_qubit_lo_freq, + meas_lo_freq=self.default_meas_lo_freq, + ) # convert to ghz qubit_lo_freq_ghz = [freq / 1e9 for freq in self.default_qubit_lo_freq] @@ -653,73 +693,79 @@ def test_job_lo_errors(self): meas_lo_range = [[freq - 5e6, freq + 5e6] for freq in self.default_meas_lo_freq] # lo range not a nested list - with self.assertRaises(QiskitError): - assemble( - self.circ, - backend=self.backend, - qubit_lo_freq=self.default_qubit_lo_freq, - meas_lo_freq=self.default_meas_lo_freq, - qubit_lo_range=[4.995e9 for i in range(self.num_qubits)], - meas_lo_range=meas_lo_range, - ) + with self.assertWarns(DeprecationWarning): + with self.assertRaises(QiskitError): + assemble( + self.circ, + backend=self.backend, + qubit_lo_freq=self.default_qubit_lo_freq, + meas_lo_freq=self.default_meas_lo_freq, + qubit_lo_range=[4.995e9 for i in range(self.num_qubits)], + meas_lo_range=meas_lo_range, + ) # qubit lo range inner list not 2d - with self.assertRaises(QiskitError): - assemble( - self.circ, - backend=self.backend, - qubit_lo_freq=self.default_qubit_lo_freq, - meas_lo_freq=self.default_meas_lo_freq, - qubit_lo_range=qubit_lo_range, - meas_lo_range=[[6.695e9] for i in range(self.num_qubits)], - ) + with self.assertWarns(DeprecationWarning): + with self.assertRaises(QiskitError): + assemble( + self.circ, + backend=self.backend, + qubit_lo_freq=self.default_qubit_lo_freq, + meas_lo_freq=self.default_meas_lo_freq, + qubit_lo_range=qubit_lo_range, + meas_lo_range=[[6.695e9] for i in range(self.num_qubits)], + ) # meas lo range inner list not 2d - with self.assertRaises(QiskitError): - assemble( - self.circ, - backend=self.backend, - qubit_lo_freq=self.default_qubit_lo_freq, - meas_lo_freq=self.default_meas_lo_freq, - qubit_lo_range=qubit_lo_range, - meas_lo_range=[[6.695e9] for i in range(self.num_qubits)], - ) + with self.assertWarns(DeprecationWarning): + with self.assertRaises(QiskitError): + assemble( + self.circ, + backend=self.backend, + qubit_lo_freq=self.default_qubit_lo_freq, + meas_lo_freq=self.default_meas_lo_freq, + qubit_lo_range=qubit_lo_range, + meas_lo_range=[[6.695e9] for i in range(self.num_qubits)], + ) # qubit lo out of range - with self.assertRaises(QiskitError): - assemble( - self.circ, - backend=self.backend, - qubit_lo_freq=self.default_qubit_lo_freq, - meas_lo_freq=self.default_meas_lo_freq, - qubit_lo_range=[[5.005e9, 5.010e9] for i in range(self.num_qubits)], - meas_lo_range=meas_lo_range, - ) + with self.assertWarns(DeprecationWarning): + with self.assertRaises(QiskitError): + assemble( + self.circ, + backend=self.backend, + qubit_lo_freq=self.default_qubit_lo_freq, + meas_lo_freq=self.default_meas_lo_freq, + qubit_lo_range=[[5.005e9, 5.010e9] for i in range(self.num_qubits)], + meas_lo_range=meas_lo_range, + ) # meas lo out of range - with self.assertRaises(QiskitError): - assemble( - self.circ, - backend=self.backend, - qubit_lo_freq=self.default_qubit_lo_freq, - meas_lo_freq=self.default_meas_lo_freq, - qubit_lo_range=qubit_lo_range, - meas_lo_range=[[6.705e9, 6.710e9] for i in range(self.num_qubits)], - ) + with self.assertWarns(DeprecationWarning): + with self.assertRaises(QiskitError): + assemble( + self.circ, + backend=self.backend, + qubit_lo_freq=self.default_qubit_lo_freq, + meas_lo_freq=self.default_meas_lo_freq, + qubit_lo_range=qubit_lo_range, + meas_lo_range=[[6.705e9, 6.710e9] for i in range(self.num_qubits)], + ) def test_job_qubit_meas_los_w_range(self): """Test that adding job qubit/meas lo freq lists are assembled into the qobj.config, w/ lo ranges input. Verify that lo ranges do not enter into the config.""" qubit_lo_range = [[freq - 5e6, freq + 5e6] for freq in self.default_qubit_lo_freq] meas_lo_range = [[freq - 5e6, freq + 5e6] for freq in self.default_meas_lo_freq] - qobj = assemble( - self.circ, - backend=self.backend, - qubit_lo_freq=self.default_qubit_lo_freq, - meas_lo_freq=self.default_meas_lo_freq, - qubit_lo_range=qubit_lo_range, - meas_lo_range=meas_lo_range, - ) + with self.assertWarns(DeprecationWarning): + qobj = assemble( + self.circ, + backend=self.backend, + qubit_lo_freq=self.default_qubit_lo_freq, + meas_lo_freq=self.default_meas_lo_freq, + qubit_lo_range=qubit_lo_range, + meas_lo_range=meas_lo_range, + ) # convert to ghz qubit_lo_freq_ghz = [freq / 1e9 for freq in self.default_qubit_lo_freq] @@ -731,13 +777,14 @@ def test_job_qubit_meas_los_w_range(self): def test_assemble_single_circ_single_lo_config(self): """Test assembling a single circuit, with a single experiment level lo config.""" - qobj = assemble( - self.circ, - self.backend, - qubit_lo_freq=self.default_qubit_lo_freq, - meas_lo_freq=self.default_meas_lo_freq, - schedule_los=self.user_lo_config, - ) + with self.assertWarns(DeprecationWarning): + qobj = assemble( + self.circ, + self.backend, + qubit_lo_freq=self.default_qubit_lo_freq, + meas_lo_freq=self.default_meas_lo_freq, + schedule_los=self.user_lo_config, + ) self.assertListEqual(qobj.config.qubit_lo_freq, [5.55, 5, 5, 4.91, 5]) self.assertListEqual(qobj.config.meas_lo_freq, [6.64, 6.7, 6.7, 6.7, 6.1]) @@ -746,13 +793,14 @@ def test_assemble_single_circ_single_lo_config(self): def test_assemble_single_circ_single_lo_config_dict(self): """Test assembling a single circuit, with a single experiment level lo config supplied as dictionary.""" - qobj = assemble( - self.circ, - self.backend, - qubit_lo_freq=self.default_qubit_lo_freq, - meas_lo_freq=self.default_meas_lo_freq, - schedule_los=self.user_lo_config_dict, - ) + with self.assertWarns(DeprecationWarning): + qobj = assemble( + self.circ, + self.backend, + qubit_lo_freq=self.default_qubit_lo_freq, + meas_lo_freq=self.default_meas_lo_freq, + schedule_los=self.user_lo_config_dict, + ) self.assertListEqual(qobj.config.qubit_lo_freq, [5.55, 5, 5, 4.91, 5]) self.assertListEqual(qobj.config.meas_lo_freq, [6.64, 6.7, 6.7, 6.7, 6.1]) @@ -769,13 +817,14 @@ def test_assemble_single_circ_multi_lo_config(self): pulse.MeasureChannel(3): 6.1e9, } user_lo_config2 = pulse.LoConfig(user_lo_config_dict2) - qobj = assemble( - self.circ, - self.backend, - qubit_lo_freq=self.default_qubit_lo_freq, - meas_lo_freq=self.default_meas_lo_freq, - schedule_los=[self.user_lo_config, user_lo_config2], - ) + with self.assertWarns(DeprecationWarning): + qobj = assemble( + self.circ, + self.backend, + qubit_lo_freq=self.default_qubit_lo_freq, + meas_lo_freq=self.default_meas_lo_freq, + schedule_los=[self.user_lo_config, user_lo_config2], + ) qubit_lo_freq_ghz = [freq / 1e9 for freq in self.default_qubit_lo_freq] meas_lo_freq_ghz = [freq / 1e9 for freq in self.default_meas_lo_freq] @@ -800,13 +849,14 @@ def test_assemble_multi_circ_multi_lo_config(self): pulse.MeasureChannel(3): 6.1e9, } user_lo_config2 = pulse.LoConfig(user_lo_config_dict2) - qobj = assemble( - [self.circ, self.circ], - self.backend, - qubit_lo_freq=self.default_qubit_lo_freq, - meas_lo_freq=self.default_meas_lo_freq, - schedule_los=[self.user_lo_config, user_lo_config2], - ) + with self.assertWarns(DeprecationWarning): + qobj = assemble( + [self.circ, self.circ], + self.backend, + qubit_lo_freq=self.default_qubit_lo_freq, + meas_lo_freq=self.default_meas_lo_freq, + schedule_los=[self.user_lo_config, user_lo_config2], + ) qubit_lo_freq_ghz = [freq / 1e9 for freq in self.default_qubit_lo_freq] meas_lo_freq_ghz = [freq / 1e9 for freq in self.default_meas_lo_freq] @@ -824,13 +874,14 @@ def test_assemble_multi_circ_multi_lo_config(self): def test_assemble_multi_circ_single_lo_config(self): """Test assembling multiple circuits, with a single experiment level lo config (should override job level).""" - qobj = assemble( - [self.circ, self.circ], - self.backend, - qubit_lo_freq=self.default_qubit_lo_freq, - meas_lo_freq=self.default_meas_lo_freq, - schedule_los=self.user_lo_config, - ) + with self.assertWarns(DeprecationWarning): + qobj = assemble( + [self.circ, self.circ], + self.backend, + qubit_lo_freq=self.default_qubit_lo_freq, + meas_lo_freq=self.default_meas_lo_freq, + schedule_los=self.user_lo_config, + ) self.assertListEqual(qobj.config.qubit_lo_freq, [5.55, 5, 5, 4.91, 5]) self.assertListEqual(qobj.config.meas_lo_freq, [6.64, 6.7, 6.7, 6.7, 6.1]) @@ -840,14 +891,15 @@ def test_assemble_multi_circ_wrong_number_of_multi_lo_configs(self): """Test assembling circuits, with a different number of experiment level lo configs (n:m setup). """ - with self.assertRaises(QiskitError): - assemble( - [self.circ, self.circ, self.circ], - self.backend, - qubit_lo_freq=self.default_qubit_lo_freq, - meas_lo_freq=self.default_meas_lo_freq, - schedule_los=[self.user_lo_config, self.user_lo_config], - ) + with self.assertWarns(DeprecationWarning): + with self.assertRaises(QiskitError): + assemble( + [self.circ, self.circ, self.circ], + self.backend, + qubit_lo_freq=self.default_qubit_lo_freq, + meas_lo_freq=self.default_meas_lo_freq, + schedule_los=[self.user_lo_config, self.user_lo_config], + ) def test_assemble_circ_lo_config_errors(self): """Test that lo config errors are raised properly if experiment level los are provided and @@ -867,7 +919,8 @@ def test_assemble_circ_lo_config_errors(self): pulse.MeasureChannel(4): 7e9, } - qobj = assemble(self.circ, self.backend, schedule_los=full_lo_config_dict) + with self.assertWarns(DeprecationWarning): + qobj = assemble(self.circ, self.backend, schedule_los=full_lo_config_dict) self.assertListEqual(qobj.config.qubit_lo_freq, [4.85, 4.9, 4.95, 5, 5.05]) self.assertListEqual(qobj.config.meas_lo_freq, [6.8, 6.85, 6.9, 6.95, 7]) @@ -876,14 +929,16 @@ 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.assertRaises(QiskitError): - qobj = assemble(self.circ, self.backend, schedule_los=missing_drive_lo_config_dict) + with self.assertWarns(DeprecationWarning): + 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.assertRaises(QiskitError): - qobj = assemble(self.circ, self.backend, schedule_los=missing_meas_lo_config_dict) + with self.assertWarns(DeprecationWarning): + with self.assertRaises(QiskitError): + qobj = assemble(self.circ, self.backend, schedule_los=missing_meas_lo_config_dict) # verify lo ranges are checked at experiment level lo_values = list(full_lo_config_dict.values()) @@ -892,24 +947,26 @@ def test_assemble_circ_lo_config_errors(self): # out of range drive lo full_lo_config_dict[pulse.DriveChannel(0)] -= 5.5e6 - with self.assertRaises(QiskitError): - qobj = assemble( - self.circ, - self.backend, - qubit_lo_range=qubit_lo_range, - schedule_los=full_lo_config_dict, - ) + with self.assertWarns(DeprecationWarning): + with self.assertRaises(QiskitError): + qobj = assemble( + self.circ, + self.backend, + qubit_lo_range=qubit_lo_range, + schedule_los=full_lo_config_dict, + ) 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.assertRaises(QiskitError): - qobj = assemble( - self.circ, - self.backend, - meas_lo_range=meas_lo_range, - schedule_los=full_lo_config_dict, - ) + with self.assertWarns(DeprecationWarning): + with self.assertRaises(QiskitError): + qobj = assemble( + self.circ, + self.backend, + meas_lo_range=meas_lo_range, + schedule_los=full_lo_config_dict, + ) class TestPulseAssembler(QiskitTestCase): @@ -945,13 +1002,14 @@ def setUp(self): def test_assemble_adds_schedule_metadata_to_experiment_header(self): """Verify that any circuit metadata is added to the experiment header.""" self.schedule.metadata = {"experiment_type": "gst", "execution_number": "1234"} - qobj = assemble( - self.schedule, - shots=100, - qubit_lo_freq=self.default_qubit_lo_freq, - meas_lo_freq=self.default_meas_lo_freq, - schedule_los=[], - ) + with self.assertWarns(DeprecationWarning): + qobj = assemble( + self.schedule, + shots=100, + qubit_lo_freq=self.default_qubit_lo_freq, + meas_lo_freq=self.default_meas_lo_freq, + schedule_los=[], + ) self.assertEqual( qobj.experiments[0].header.metadata, {"experiment_type": "gst", "execution_number": "1234"}, @@ -969,14 +1027,15 @@ def test_assemble_sample_pulse(self): schedule += pulse.Play( pulse.Waveform([0.5] * 16, name="test0"), pulse.DriveChannel(0), name="test1" ) - qobj = assemble( - schedule, - qobj_header=self.header, - qubit_lo_freq=self.default_qubit_lo_freq, - meas_lo_freq=self.default_meas_lo_freq, - schedule_los=[], - **self.config, - ) + with self.assertWarns(DeprecationWarning): + qobj = assemble( + schedule, + qobj_header=self.header, + qubit_lo_freq=self.default_qubit_lo_freq, + meas_lo_freq=self.default_meas_lo_freq, + schedule_los=[], + **self.config, + ) test_dict = qobj.to_dict() experiment = test_dict["experiments"][0] @@ -994,14 +1053,15 @@ def test_assemble_sample_pulse(self): def test_assemble_single_schedule_without_lo_config(self): """Test assembling a single schedule, no lo config.""" - qobj = assemble( - self.schedule, - qobj_header=self.header, - qubit_lo_freq=self.default_qubit_lo_freq, - meas_lo_freq=self.default_meas_lo_freq, - schedule_los=[], - **self.config, - ) + with self.assertWarns(DeprecationWarning): + qobj = assemble( + self.schedule, + qobj_header=self.header, + qubit_lo_freq=self.default_qubit_lo_freq, + meas_lo_freq=self.default_meas_lo_freq, + schedule_los=[], + **self.config, + ) test_dict = qobj.to_dict() self.assertListEqual(test_dict["config"]["qubit_lo_freq"], [4.9, 5.0]) @@ -1010,13 +1070,14 @@ def test_assemble_single_schedule_without_lo_config(self): def test_assemble_multi_schedules_without_lo_config(self): """Test assembling schedules, no lo config.""" - qobj = assemble( - [self.schedule, self.schedule], - qobj_header=self.header, - qubit_lo_freq=self.default_qubit_lo_freq, - meas_lo_freq=self.default_meas_lo_freq, - **self.config, - ) + with self.assertWarns(DeprecationWarning): + qobj = assemble( + [self.schedule, self.schedule], + qobj_header=self.header, + qubit_lo_freq=self.default_qubit_lo_freq, + meas_lo_freq=self.default_meas_lo_freq, + **self.config, + ) test_dict = qobj.to_dict() self.assertListEqual(test_dict["config"]["qubit_lo_freq"], [4.9, 5.0]) @@ -1025,14 +1086,15 @@ def test_assemble_multi_schedules_without_lo_config(self): def test_assemble_single_schedule_with_lo_config(self): """Test assembling a single schedule, with a single lo config.""" - qobj = assemble( - self.schedule, - qobj_header=self.header, - qubit_lo_freq=self.default_qubit_lo_freq, - meas_lo_freq=self.default_meas_lo_freq, - schedule_los=self.user_lo_config, - **self.config, - ) + with self.assertWarns(DeprecationWarning): + qobj = assemble( + self.schedule, + qobj_header=self.header, + qubit_lo_freq=self.default_qubit_lo_freq, + meas_lo_freq=self.default_meas_lo_freq, + schedule_los=self.user_lo_config, + **self.config, + ) test_dict = qobj.to_dict() self.assertListEqual(test_dict["config"]["qubit_lo_freq"], [4.91, 5.0]) @@ -1041,14 +1103,15 @@ def test_assemble_single_schedule_with_lo_config(self): def test_assemble_single_schedule_with_lo_config_dict(self): """Test assembling a single schedule, with a single lo config supplied as dictionary.""" - qobj = assemble( - self.schedule, - qobj_header=self.header, - qubit_lo_freq=self.default_qubit_lo_freq, - meas_lo_freq=self.default_meas_lo_freq, - schedule_los=self.user_lo_config_dict, - **self.config, - ) + with self.assertWarns(DeprecationWarning): + qobj = assemble( + self.schedule, + qobj_header=self.header, + qubit_lo_freq=self.default_qubit_lo_freq, + meas_lo_freq=self.default_meas_lo_freq, + schedule_los=self.user_lo_config_dict, + **self.config, + ) test_dict = qobj.to_dict() self.assertListEqual(test_dict["config"]["qubit_lo_freq"], [4.91, 5.0]) @@ -1057,14 +1120,15 @@ def test_assemble_single_schedule_with_lo_config_dict(self): def test_assemble_single_schedule_with_multi_lo_configs(self): """Test assembling a single schedule, with multiple lo configs (frequency sweep).""" - qobj = assemble( - self.schedule, - qobj_header=self.header, - qubit_lo_freq=self.default_qubit_lo_freq, - meas_lo_freq=self.default_meas_lo_freq, - schedule_los=[self.user_lo_config, self.user_lo_config], - **self.config, - ) + with self.assertWarns(DeprecationWarning): + qobj = assemble( + self.schedule, + qobj_header=self.header, + qubit_lo_freq=self.default_qubit_lo_freq, + meas_lo_freq=self.default_meas_lo_freq, + schedule_los=[self.user_lo_config, self.user_lo_config], + **self.config, + ) test_dict = qobj.to_dict() self.assertListEqual(test_dict["config"]["qubit_lo_freq"], [4.9, 5.0]) @@ -1074,14 +1138,15 @@ def test_assemble_single_schedule_with_multi_lo_configs(self): def test_assemble_multi_schedules_with_multi_lo_configs(self): """Test assembling schedules, with the same number of lo configs (n:n setup).""" - qobj = assemble( - [self.schedule, self.schedule], - qobj_header=self.header, - qubit_lo_freq=self.default_qubit_lo_freq, - meas_lo_freq=self.default_meas_lo_freq, - schedule_los=[self.user_lo_config, self.user_lo_config], - **self.config, - ) + with self.assertWarns(DeprecationWarning): + qobj = assemble( + [self.schedule, self.schedule], + qobj_header=self.header, + qubit_lo_freq=self.default_qubit_lo_freq, + meas_lo_freq=self.default_meas_lo_freq, + schedule_los=[self.user_lo_config, self.user_lo_config], + **self.config, + ) test_dict = qobj.to_dict() self.assertListEqual(test_dict["config"]["qubit_lo_freq"], [4.9, 5.0]) @@ -1092,14 +1157,15 @@ def test_assemble_multi_schedules_with_multi_lo_configs(self): def test_assemble_multi_schedules_with_wrong_number_of_multi_lo_configs(self): """Test assembling schedules, with a different number of lo configs (n:m setup).""" with self.assertRaises(QiskitError): - assemble( - [self.schedule, self.schedule, self.schedule], - qobj_header=self.header, - qubit_lo_freq=self.default_qubit_lo_freq, - meas_lo_freq=self.default_meas_lo_freq, - schedule_los=[self.user_lo_config, self.user_lo_config], - **self.config, - ) + with self.assertWarns(DeprecationWarning): + assemble( + [self.schedule, self.schedule, self.schedule], + qobj_header=self.header, + qubit_lo_freq=self.default_qubit_lo_freq, + meas_lo_freq=self.default_meas_lo_freq, + schedule_los=[self.user_lo_config, self.user_lo_config], + **self.config, + ) def test_assemble_meas_map(self): """Test assembling a single schedule, no lo config.""" @@ -1107,20 +1173,22 @@ def test_assemble_meas_map(self): schedule = schedule.insert(5, Acquire(5, AcquireChannel(0), MemorySlot(0))) schedule = schedule.insert(5, Acquire(5, AcquireChannel(1), MemorySlot(1))) - qobj = assemble( - schedule, - qubit_lo_freq=self.default_qubit_lo_freq, - meas_lo_freq=self.default_meas_lo_freq, - meas_map=[[0], [1]], - ) + with self.assertWarns(DeprecationWarning): + qobj = assemble( + schedule, + qubit_lo_freq=self.default_qubit_lo_freq, + meas_lo_freq=self.default_meas_lo_freq, + meas_map=[[0], [1]], + ) self.assertIsInstance(qobj, PulseQobj) - qobj = assemble( - schedule, - qubit_lo_freq=self.default_qubit_lo_freq, - meas_lo_freq=self.default_meas_lo_freq, - meas_map=[[0, 1, 2]], - ) + with self.assertWarns(DeprecationWarning): + qobj = assemble( + schedule, + qubit_lo_freq=self.default_qubit_lo_freq, + meas_lo_freq=self.default_meas_lo_freq, + meas_map=[[0, 1, 2]], + ) self.assertIsInstance(qobj, PulseQobj) def test_assemble_memory_slots(self): @@ -1132,12 +1200,13 @@ def test_assemble_memory_slots(self): 5, self.backend_config.acquire(0), mem_slot=pulse.MemorySlot(n_memoryslots - 1) ) - qobj = assemble( - schedule, - qubit_lo_freq=self.default_qubit_lo_freq, - meas_lo_freq=self.default_meas_lo_freq, - meas_map=[[0], [1]], - ) + with self.assertWarns(DeprecationWarning): + qobj = assemble( + schedule, + qubit_lo_freq=self.default_qubit_lo_freq, + meas_lo_freq=self.default_meas_lo_freq, + meas_map=[[0], [1]], + ) self.assertEqual(qobj.config.memory_slots, n_memoryslots) # this should be in experimental header as well @@ -1153,13 +1222,13 @@ def test_assemble_memory_slots(self): 5, self.backend_config.acquire(0), mem_slot=pulse.MemorySlot(n_memoryslots - 1) ), ) - - qobj = assemble( - schedule, - qubit_lo_freq=self.default_qubit_lo_freq, - meas_lo_freq=self.default_meas_lo_freq, - meas_map=[[0], [1]], - ) + with self.assertWarns(DeprecationWarning): + qobj = assemble( + schedule, + qubit_lo_freq=self.default_qubit_lo_freq, + meas_lo_freq=self.default_meas_lo_freq, + meas_map=[[0], [1]], + ) self.assertEqual(qobj.config.memory_slots, n_memoryslots) # this should be in experimental header as well @@ -1176,12 +1245,13 @@ def test_assemble_memory_slots_for_schedules(self): ) schedules.append(schedule) - qobj = assemble( - schedules, - qubit_lo_freq=self.default_qubit_lo_freq, - meas_lo_freq=self.default_meas_lo_freq, - meas_map=[[0], [1]], - ) + with self.assertWarns(DeprecationWarning): + qobj = assemble( + schedules, + qubit_lo_freq=self.default_qubit_lo_freq, + meas_lo_freq=self.default_meas_lo_freq, + meas_map=[[0], [1]], + ) self.assertEqual(qobj.config.memory_slots, max(n_memoryslots)) self.assertEqual(qobj.experiments[0].header.memory_slots, n_memoryslots[0]) @@ -1198,14 +1268,15 @@ def test_pulse_name_conflicts(self): 1, Play(name_conflict_pulse, self.backend_config.drive(1)) ) - qobj = assemble( - self.schedule, - qobj_header=self.header, - qubit_lo_freq=self.default_qubit_lo_freq, - meas_lo_freq=self.default_meas_lo_freq, - schedule_los=[], - **self.config, - ) + with self.assertWarns(DeprecationWarning): + qobj = assemble( + self.schedule, + qobj_header=self.header, + qubit_lo_freq=self.default_qubit_lo_freq, + meas_lo_freq=self.default_meas_lo_freq, + schedule_los=[], + **self.config, + ) self.assertNotEqual(qobj.config.pulse_library[0].name, qobj.config.pulse_library[1].name) @@ -1222,9 +1293,12 @@ def test_pulse_name_conflicts_in_other_schedule(self): sched += measure(qubits=[0], backend=backend) << 100 schedules.append(sched) - qobj = assemble( - schedules, qubit_lo_freq=defaults.qubit_freq_est, meas_lo_freq=defaults.meas_freq_est - ) + with self.assertWarns(DeprecationWarning): + qobj = assemble( + schedules, + qubit_lo_freq=defaults.qubit_freq_est, + meas_lo_freq=defaults.meas_freq_est, + ) # two user pulses and one measurement pulse should be contained self.assertEqual(len(qobj.config.pulse_library), 3) @@ -1233,7 +1307,9 @@ 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 - delay_qobj = assemble(delay_schedule, self.backend) + + with self.assertWarns(DeprecationWarning): + delay_qobj = assemble(delay_schedule, self.backend) self.assertEqual(delay_qobj.experiments[0].instructions[0].name, "delay") self.assertEqual(delay_qobj.experiments[0].instructions[0].duration, 10) @@ -1258,7 +1334,8 @@ def test_delay_removed_on_acq_ch(self): sched2 += delay1 sched2 += self.schedule # includes ``Acquire`` instr - delay_qobj = assemble([sched0, sched1, sched2], self.backend) + with self.assertWarns(DeprecationWarning): + delay_qobj = assemble([sched0, sched1, sched2], self.backend) # check that no delay instrs occur on acquire channels is_acq_delay = False @@ -1279,15 +1356,16 @@ def test_delay_removed_on_acq_ch(self): def test_assemble_schedule_enum(self): """Test assembling a schedule with enum input values to assemble.""" - qobj = assemble( - self.schedule, - qobj_header=self.header, - qubit_lo_freq=self.default_qubit_lo_freq, - meas_lo_freq=self.default_meas_lo_freq, - schedule_los=[], - meas_level=MeasLevel.CLASSIFIED, - meas_return=MeasReturnType.AVERAGE, - ) + with self.assertWarns(DeprecationWarning): + qobj = assemble( + self.schedule, + qobj_header=self.header, + qubit_lo_freq=self.default_qubit_lo_freq, + meas_lo_freq=self.default_meas_lo_freq, + schedule_los=[], + meas_level=MeasLevel.CLASSIFIED, + meas_return=MeasReturnType.AVERAGE, + ) test_dict = qobj.to_dict() self.assertEqual(test_dict["config"]["meas_return"], "avg") @@ -1319,7 +1397,8 @@ def test_assemble_parametric(self): "gaussian_square", "constant", ] - qobj = assemble(sched, backend) + with self.assertWarns(DeprecationWarning): + qobj = assemble(sched, backend) self.assertEqual(qobj.config.pulse_library, []) qobj_insts = qobj.experiments[0].instructions @@ -1361,7 +1440,8 @@ def test_assemble_parametric_unsupported(self): backend = FakeOpenPulse3Q() backend.configuration().parametric_pulses = ["something_extra"] - qobj = assemble(sched, backend) + with self.assertWarns(DeprecationWarning): + qobj = assemble(sched, backend) self.assertNotEqual(qobj.config.pulse_library, []) qobj_insts = qobj.experiments[0].instructions @@ -1379,7 +1459,8 @@ def test_assemble_parametric_pulse_kwarg_with_backend_setting(self): qc.add_calibration("x", (0,), x_q0) - qobj = assemble(qc, backend, parametric_pulses=["gaussian"]) + with self.assertWarns(DeprecationWarning): + qobj = assemble(qc, backend, parametric_pulses=["gaussian"]) self.assertEqual(qobj.config.parametric_pulses, ["gaussian"]) def test_assemble_parametric_pulse_kwarg_empty_list_with_backend_setting(self): @@ -1394,22 +1475,26 @@ def test_assemble_parametric_pulse_kwarg_empty_list_with_backend_setting(self): qc.add_calibration("x", (0,), x_q0) - qobj = assemble(qc, backend, parametric_pulses=[]) + with self.assertWarns(DeprecationWarning): + qobj = assemble(qc, backend, parametric_pulses=[]) self.assertEqual(qobj.config.parametric_pulses, []) def test_init_qubits_default(self): """Check that the init_qubits=None assemble option is passed on to the qobj.""" - qobj = assemble(self.schedule, self.backend) + with self.assertWarns(DeprecationWarning): + qobj = assemble(self.schedule, self.backend) self.assertEqual(qobj.config.init_qubits, True) def test_init_qubits_true(self): """Check that the init_qubits=True assemble option is passed on to the qobj.""" - qobj = assemble(self.schedule, self.backend, init_qubits=True) + with self.assertWarns(DeprecationWarning): + qobj = assemble(self.schedule, self.backend, init_qubits=True) self.assertEqual(qobj.config.init_qubits, True) def test_init_qubits_false(self): """Check that the init_qubits=False assemble option is passed on to the qobj.""" - qobj = assemble(self.schedule, self.backend, init_qubits=False) + with self.assertWarns(DeprecationWarning): + qobj = assemble(self.schedule, self.backend, init_qubits=False) self.assertEqual(qobj.config.init_qubits, False) def test_assemble_backend_rep_times_delays(self): @@ -1423,14 +1508,15 @@ def test_assemble_backend_rep_times_delays(self): setattr(self.backend_config, "default_rep_delay", default_rep_delay) # dynamic rep rates off - qobj = assemble(self.schedule, self.backend) + with self.assertWarns(DeprecationWarning): + qobj = assemble(self.schedule, self.backend) self.assertEqual(qobj.config.rep_time, int(rep_times[0] * 1e6)) self.assertEqual(hasattr(qobj.config, "rep_delay"), False) # dynamic rep rates on setattr(self.backend_config, "dynamic_reprate_enabled", True) # RuntimeWarning bc ``rep_time`` is specified`` when dynamic rep rates not enabled - with self.assertWarns(RuntimeWarning): + with self.assertWarns(DeprecationWarning): qobj = assemble(self.schedule, self.backend) self.assertEqual(qobj.config.rep_time, int(rep_times[0] * 1e6)) self.assertEqual(qobj.config.rep_delay, default_rep_delay * 1e6) @@ -1445,7 +1531,7 @@ def test_assemble_user_rep_time_delay(self): # dynamic rep rates off # RuntimeWarning bc using ``rep_delay`` when dynamic rep rates off - with self.assertWarns(RuntimeWarning): + with self.assertWarns(DeprecationWarning): qobj = assemble(self.schedule, self.backend, **self.config) self.assertEqual(qobj.config.rep_time, int(rep_time * 1e6)) self.assertEqual(hasattr(qobj.config, "rep_delay"), False) @@ -1454,7 +1540,7 @@ def test_assemble_user_rep_time_delay(self): # RuntimeWarning bc using ``rep_time`` when dynamic rep rates are enabled del self.config["rep_delay"] setattr(self.backend_config, "dynamic_reprate_enabled", True) - with self.assertWarns(RuntimeWarning): + with self.assertWarns(DeprecationWarning): qobj = assemble(self.schedule, self.backend, **self.config) self.assertEqual(qobj.config.rep_time, int(rep_time * 1e6)) self.assertEqual(hasattr(qobj.config, "rep_delay"), False) @@ -1466,19 +1552,21 @@ def test_assemble_user_rep_time_delay(self): setattr(self.backend_config, "rep_delay_range", [0, 3.0e-6]) setattr(self.backend_config, "default_rep_delay", 2.2e-6) del self.config["rep_time"] - qobj = assemble(self.schedule, self.backend, **self.config) + with self.assertWarns(DeprecationWarning): + qobj = assemble(self.schedule, self.backend, **self.config) self.assertEqual(qobj.config.rep_time, int(rep_times[0] * 1e6)) self.assertEqual(qobj.config.rep_delay, 2.2) # use qobj ``default_rep_delay`` self.config["rep_delay"] = 1.5e-6 - qobj = assemble(self.schedule, self.backend, **self.config) + with self.assertWarns(DeprecationWarning): + qobj = assemble(self.schedule, self.backend, **self.config) self.assertEqual(qobj.config.rep_time, int(rep_times[0] * 1e6)) self.assertEqual(qobj.config.rep_delay, 1.5) # use ``rep_delay`` outside of ``rep_delay_range self.config["rep_delay"] = 5.0e-6 - with self.assertRaises(QiskitError): + with self.assertRaises(DeprecationWarning): assemble(self.schedule, self.backend, **self.config) def test_assemble_with_individual_discriminators(self): @@ -1494,12 +1582,13 @@ def test_assemble_with_individual_discriminators(self): Acquire(5, AcquireChannel(1), MemorySlot(1), discriminator=disc_two), ) - qobj = assemble( - schedule, - qubit_lo_freq=self.default_qubit_lo_freq, - meas_lo_freq=self.default_meas_lo_freq, - meas_map=[[0, 1]], - ) + with self.assertWarns(DeprecationWarning): + qobj = assemble( + schedule, + qubit_lo_freq=self.default_qubit_lo_freq, + meas_lo_freq=self.default_meas_lo_freq, + meas_map=[[0, 1]], + ) qobj_discriminators = qobj.experiments[0].instructions[0].discriminators self.assertEqual(len(qobj_discriminators), 2) @@ -1520,12 +1609,13 @@ def test_assemble_with_single_discriminators(self): Acquire(5, AcquireChannel(1), MemorySlot(1)), ) - qobj = assemble( - schedule, - qubit_lo_freq=self.default_qubit_lo_freq, - meas_lo_freq=self.default_meas_lo_freq, - meas_map=[[0, 1]], - ) + with self.assertWarns(DeprecationWarning): + qobj = assemble( + schedule, + qubit_lo_freq=self.default_qubit_lo_freq, + meas_lo_freq=self.default_meas_lo_freq, + meas_map=[[0, 1]], + ) qobj_discriminators = qobj.experiments[0].instructions[0].discriminators self.assertEqual(len(qobj_discriminators), 1) @@ -1543,7 +1633,7 @@ def test_assemble_with_unequal_discriminators(self): schedule += Acquire(5, AcquireChannel(1), MemorySlot(1), discriminator=disc_two) schedule += Acquire(5, AcquireChannel(2), MemorySlot(2)) - with self.assertRaises(QiskitError): + with self.assertRaises(QiskitError), self.assertWarns(DeprecationWarning): assemble( schedule, qubit_lo_freq=self.default_qubit_lo_freq, @@ -1564,12 +1654,13 @@ def test_assemble_with_individual_kernels(self): Acquire(5, AcquireChannel(1), MemorySlot(1), kernel=disc_two), ) - qobj = assemble( - schedule, - qubit_lo_freq=self.default_qubit_lo_freq, - meas_lo_freq=self.default_meas_lo_freq, - meas_map=[[0, 1]], - ) + with self.assertWarns(DeprecationWarning): + qobj = assemble( + schedule, + qubit_lo_freq=self.default_qubit_lo_freq, + meas_lo_freq=self.default_meas_lo_freq, + meas_map=[[0, 1]], + ) qobj_kernels = qobj.experiments[0].instructions[0].kernels self.assertEqual(len(qobj_kernels), 2) @@ -1590,12 +1681,13 @@ def test_assemble_with_single_kernels(self): Acquire(5, AcquireChannel(1), MemorySlot(1)), ) - qobj = assemble( - schedule, - qubit_lo_freq=self.default_qubit_lo_freq, - meas_lo_freq=self.default_meas_lo_freq, - meas_map=[[0, 1]], - ) + with self.assertWarns(DeprecationWarning): + qobj = assemble( + schedule, + qubit_lo_freq=self.default_qubit_lo_freq, + meas_lo_freq=self.default_meas_lo_freq, + meas_map=[[0, 1]], + ) qobj_kernels = qobj.experiments[0].instructions[0].kernels self.assertEqual(len(qobj_kernels), 1) @@ -1613,7 +1705,7 @@ def test_assemble_with_unequal_kernels(self): schedule += Acquire(5, AcquireChannel(1), MemorySlot(1), kernel=disc_two) schedule += Acquire(5, AcquireChannel(2), MemorySlot(2)) - with self.assertRaises(QiskitError): + with self.assertRaises(QiskitError), self.assertWarns(DeprecationWarning): assemble( schedule, qubit_lo_freq=self.default_qubit_lo_freq, @@ -1624,7 +1716,8 @@ 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)) - self.assertIsInstance(assemble(inst, self.backend), PulseQobj) + with self.assertWarns(DeprecationWarning): + self.assertIsInstance(assemble(inst, self.backend), PulseQobj) def test_assemble_overlapping_time(self): """Test that assembly errors when qubits are measured in overlapping time.""" @@ -1636,12 +1729,13 @@ def test_assemble_overlapping_time(self): Acquire(5, AcquireChannel(1), MemorySlot(1)) << 1, ) with self.assertRaises(QiskitError): - assemble( - schedule, - qubit_lo_freq=self.default_qubit_lo_freq, - meas_lo_freq=self.default_meas_lo_freq, - meas_map=[[0, 1]], - ) + with self.assertWarns(DeprecationWarning): + assemble( + schedule, + qubit_lo_freq=self.default_qubit_lo_freq, + meas_lo_freq=self.default_meas_lo_freq, + meas_map=[[0, 1]], + ) def test_assemble_meas_map_vs_insts(self): """Test that assembly errors when the qubits are measured in overlapping time @@ -1653,12 +1747,13 @@ def test_assemble_meas_map_vs_insts(self): schedule += Acquire(5, AcquireChannel(3), MemorySlot(3)) << 2 with self.assertRaises(QiskitError): - assemble( - schedule, - qubit_lo_freq=self.default_qubit_lo_freq, - meas_lo_freq=self.default_meas_lo_freq, - meas_map=[[0], [1, 2], [3]], - ) + with self.assertWarns(DeprecationWarning): + assemble( + schedule, + qubit_lo_freq=self.default_qubit_lo_freq, + meas_lo_freq=self.default_meas_lo_freq, + meas_map=[[0], [1, 2], [3]], + ) def test_assemble_non_overlapping_time_single_meas_map(self): """Test that assembly works when qubits are measured in non-overlapping @@ -1670,12 +1765,13 @@ def test_assemble_non_overlapping_time_single_meas_map(self): schedule = schedule.append( Acquire(5, AcquireChannel(1), MemorySlot(1)) << 5, ) - qobj = assemble( - schedule, - qubit_lo_freq=self.default_qubit_lo_freq, - meas_lo_freq=self.default_meas_lo_freq, - meas_map=[[0, 1]], - ) + with self.assertWarns(DeprecationWarning): + qobj = assemble( + schedule, + qubit_lo_freq=self.default_qubit_lo_freq, + meas_lo_freq=self.default_meas_lo_freq, + meas_map=[[0, 1]], + ) self.assertIsInstance(qobj, PulseQobj) def test_assemble_disjoint_time(self): @@ -1687,12 +1783,13 @@ def test_assemble_disjoint_time(self): schedule = schedule.append( Acquire(5, AcquireChannel(1), MemorySlot(1)) << 1, ) - qobj = assemble( - schedule, - qubit_lo_freq=self.default_qubit_lo_freq, - meas_lo_freq=self.default_meas_lo_freq, - meas_map=[[0, 2], [1, 3]], - ) + with self.assertWarns(DeprecationWarning): + qobj = assemble( + schedule, + qubit_lo_freq=self.default_qubit_lo_freq, + meas_lo_freq=self.default_meas_lo_freq, + meas_map=[[0, 2], [1, 3]], + ) self.assertIsInstance(qobj, PulseQobj) def test_assemble_valid_qubits(self): @@ -1708,12 +1805,13 @@ def test_assemble_valid_qubits(self): schedule = schedule.append( Acquire(5, AcquireChannel(3), MemorySlot(3)), ) - qobj = assemble( - schedule, - qubit_lo_freq=self.default_qubit_lo_freq, - meas_lo_freq=self.default_meas_lo_freq, - meas_map=[[0, 1, 2], [3]], - ) + with self.assertWarns(DeprecationWarning): + qobj = assemble( + schedule, + qubit_lo_freq=self.default_qubit_lo_freq, + meas_lo_freq=self.default_meas_lo_freq, + meas_map=[[0, 1, 2], [3]], + ) self.assertIsInstance(qobj, PulseQobj) @@ -1746,24 +1844,26 @@ def setUp(self): def test_defaults(self): """Test defaults work.""" - qobj = assemble( - self.schedule, - qubit_lo_freq=self.qubit_lo_freq, - meas_lo_freq=self.meas_lo_freq, - qubit_lo_range=self.qubit_lo_range, - meas_lo_range=self.meas_lo_range, - schedule_los=self.schedule_los, - meas_map=self.meas_map, - memory_slots=self.memory_slots, - rep_time=self.rep_time, - rep_delay=self.rep_delay, - ) + with self.assertWarns(DeprecationWarning): + qobj = assemble( + self.schedule, + qubit_lo_freq=self.qubit_lo_freq, + meas_lo_freq=self.meas_lo_freq, + qubit_lo_range=self.qubit_lo_range, + meas_lo_range=self.meas_lo_range, + schedule_los=self.schedule_los, + meas_map=self.meas_map, + memory_slots=self.memory_slots, + rep_time=self.rep_time, + rep_delay=self.rep_delay, + ) self.assertIsInstance(qobj, PulseQobj) def test_missing_qubit_lo_freq(self): """Test error raised if qubit_lo_freq missing.""" - with self.assertRaises(QiskitError): + with self.assertRaises(QiskitError), self.assertWarns(DeprecationWarning): + assemble( self.schedule, qubit_lo_freq=None, @@ -1779,7 +1879,7 @@ def test_missing_qubit_lo_freq(self): def test_missing_meas_lo_freq(self): """Test error raised if meas_lo_freq missing.""" - with self.assertRaises(QiskitError): + with self.assertRaises(QiskitError), self.assertWarns(DeprecationWarning): assemble( self.schedule, qubit_lo_freq=self.qubit_lo_freq, @@ -1794,74 +1894,78 @@ def test_missing_meas_lo_freq(self): def test_missing_memory_slots(self): """Test error is not raised if memory_slots are missing.""" - qobj = assemble( - self.schedule, - qubit_lo_freq=self.qubit_lo_freq, - meas_lo_freq=self.meas_lo_freq, - qubit_lo_range=self.qubit_lo_range, - meas_lo_range=self.meas_lo_range, - schedule_los=self.schedule_los, - meas_map=self.meas_map, - memory_slots=None, - rep_time=self.rep_time, - rep_delay=self.rep_delay, - ) + with self.assertWarns(DeprecationWarning): + qobj = assemble( + self.schedule, + qubit_lo_freq=self.qubit_lo_freq, + meas_lo_freq=self.meas_lo_freq, + qubit_lo_range=self.qubit_lo_range, + meas_lo_range=self.meas_lo_range, + schedule_los=self.schedule_los, + meas_map=self.meas_map, + memory_slots=None, + rep_time=self.rep_time, + rep_delay=self.rep_delay, + ) self.assertIsInstance(qobj, PulseQobj) def test_missing_rep_time_and_delay(self): """Test qobj is valid if rep_time and rep_delay are missing.""" - qobj = assemble( - self.schedule, - qubit_lo_freq=self.qubit_lo_freq, - meas_lo_freq=self.meas_lo_freq, - qubit_lo_range=self.qubit_lo_range, - meas_lo_range=self.meas_lo_range, - schedule_los=self.schedule_los, - meas_map=self.meas_map, - memory_slots=None, - rep_time=None, - rep_delay=None, - ) + with self.assertWarns(DeprecationWarning): + qobj = assemble( + self.schedule, + qubit_lo_freq=self.qubit_lo_freq, + meas_lo_freq=self.meas_lo_freq, + qubit_lo_range=self.qubit_lo_range, + meas_lo_range=self.meas_lo_range, + schedule_los=self.schedule_los, + meas_map=self.meas_map, + memory_slots=None, + rep_time=None, + rep_delay=None, + ) self.assertEqual(hasattr(qobj, "rep_time"), False) self.assertEqual(hasattr(qobj, "rep_delay"), False) def test_missing_meas_map(self): """Test that assembly still works if meas_map is missing.""" - qobj = assemble( - self.schedule, - qubit_lo_freq=self.qubit_lo_freq, - meas_lo_freq=self.meas_lo_freq, - qubit_lo_range=self.qubit_lo_range, - meas_lo_range=self.meas_lo_range, - schedule_los=self.schedule_los, - meas_map=None, - memory_slots=self.memory_slots, - rep_time=self.rep_time, - rep_delay=self.rep_delay, - ) + with self.assertWarns(DeprecationWarning): + qobj = assemble( + self.schedule, + qubit_lo_freq=self.qubit_lo_freq, + meas_lo_freq=self.meas_lo_freq, + qubit_lo_range=self.qubit_lo_range, + meas_lo_range=self.meas_lo_range, + schedule_los=self.schedule_los, + meas_map=None, + memory_slots=self.memory_slots, + rep_time=self.rep_time, + rep_delay=self.rep_delay, + ) self.assertIsInstance(qobj, PulseQobj) def test_missing_lo_ranges(self): """Test that assembly still works if lo_ranges are missing.""" - qobj = assemble( - self.schedule, - qubit_lo_freq=self.qubit_lo_freq, - meas_lo_freq=self.meas_lo_freq, - qubit_lo_range=None, - meas_lo_range=None, - schedule_los=self.schedule_los, - meas_map=self.meas_map, - memory_slots=self.memory_slots, - rep_time=self.rep_time, - rep_delay=self.rep_delay, - ) + with self.assertWarns(DeprecationWarning): + qobj = assemble( + self.schedule, + qubit_lo_freq=self.qubit_lo_freq, + meas_lo_freq=self.meas_lo_freq, + qubit_lo_range=None, + meas_lo_range=None, + schedule_los=self.schedule_los, + meas_map=self.meas_map, + memory_slots=self.memory_slots, + rep_time=self.rep_time, + rep_delay=self.rep_delay, + ) self.assertIsInstance(qobj, PulseQobj) def test_unsupported_meas_level(self): """Test that assembly raises an error if meas_level is not supported""" backend = FakeOpenPulse2Q() backend.configuration().meas_levels = [1, 2] - with self.assertRaises(QiskitError): + with self.assertRaises(QiskitError), self.assertWarns(DeprecationWarning): assemble( self.schedule, backend, @@ -1890,10 +1994,12 @@ def test_single_and_deprecated_acquire_styles(self): deprecated_style_schedule += Acquire(1200, AcquireChannel(i), MemorySlot(i)) # The Qobj IDs will be different - n_qobj = assemble(new_style_schedule, backend) + with self.assertWarns(DeprecationWarning): + n_qobj = assemble(new_style_schedule, backend) n_qobj.qobj_id = None n_qobj.experiments[0].header.name = None - d_qobj = assemble(deprecated_style_schedule, backend) + with self.assertWarns(DeprecationWarning): + d_qobj = assemble(deprecated_style_schedule, backend) d_qobj.qobj_id = None d_qobj.experiments[0].header.name = None self.assertEqual(n_qobj, d_qobj) @@ -1924,7 +2030,8 @@ def setUp(self): def assertAssembleLog(self, log_msg): """Runs assemble and checks for logs containing specified message""" - assemble(self.circuit, shots=2000, memory=True) + with self.assertWarns(DeprecationWarning): + assemble(self.circuit, shots=2000, memory=True) self.output.seek(0) # Filter unrelated log lines output_lines = self.output.readlines() From a2ee3b3689cf2b53f0f67ba0ffd472687a2dccf3 Mon Sep 17 00:00:00 2001 From: Luciano Bello Date: Mon, 1 Jul 2024 08:29:29 +0200 Subject: [PATCH 12/51] test.python.transpiler.test_star_prerouting --- test/python/transpiler/test_star_prerouting.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/test/python/transpiler/test_star_prerouting.py b/test/python/transpiler/test_star_prerouting.py index ddc8096eefd7..c09d4a717a28 100644 --- a/test/python/transpiler/test_star_prerouting.py +++ b/test/python/transpiler/test_star_prerouting.py @@ -15,6 +15,8 @@ """Test the StarPreRouting pass""" import unittest +import warnings + from test import QiskitTestCase import ddt @@ -258,8 +260,11 @@ def test_100q_grid_full_path(self, opt_level): ) pm.init += StarPreRouting() result = pm.run(qc) - counts_before = AerSimulator().run(qc).result().get_counts() - counts_after = AerSimulator().run(result).result().get_counts() + with warnings.catch_warnings(): + # TODO remove this catch once Aer stops using qiskit.qobj.common.QobjDictField` + warnings.simplefilter("ignore", category=DeprecationWarning) + counts_before = AerSimulator().run(qc).result().get_counts() + counts_after = AerSimulator().run(result).result().get_counts() self.assertEqual(counts_before, counts_after) def test_10q_bv_no_barrier(self): @@ -298,8 +303,11 @@ def test_100q_grid_full_path_no_barrier(self, opt_level): ) pm.init += StarPreRouting() result = pm.run(qc) - counts_before = AerSimulator().run(qc).result().get_counts() - counts_after = AerSimulator().run(result).result().get_counts() + with warnings.catch_warnings(): + # TODO remove this catch once Aer stops using qiskit.qobj.common.QobjDictField` + warnings.simplefilter("ignore", category=DeprecationWarning) + counts_before = AerSimulator().run(qc).result().get_counts() + counts_after = AerSimulator().run(result).result().get_counts() self.assertEqual(counts_before, counts_after) def test_hadamard_ordering(self): From 8a56629bff59adb3154d7b7fa7a4d8cefd268bdc Mon Sep 17 00:00:00 2001 From: Luciano Bello Date: Mon, 1 Jul 2024 10:41:20 +0200 Subject: [PATCH 13/51] test.python.pulse.test_instruction_schedule_map --- test/python/pulse/test_instruction_schedule_map.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/test/python/pulse/test_instruction_schedule_map.py b/test/python/pulse/test_instruction_schedule_map.py index 67628ba845ae..3ef2ccaa38e5 100644 --- a/test/python/pulse/test_instruction_schedule_map.py +++ b/test/python/pulse/test_instruction_schedule_map.py @@ -305,12 +305,13 @@ def test_pop_gate(self): def test_sequenced_parameterized_schedule(self): """Test parameterized schedule consists of multiple instruction.""" - converter = QobjToInstructionConverter([], buffer=0) - qobjs = [ - PulseQobjInstruction(name="fc", ch="d0", t0=10, phase="P1"), - PulseQobjInstruction(name="fc", ch="d0", t0=20, phase="P2"), - PulseQobjInstruction(name="fc", ch="d0", t0=30, phase="P3"), - ] + with self.assertWarns(DeprecationWarning): + converter = QobjToInstructionConverter([], buffer=0) + qobjs = [ + PulseQobjInstruction(name="fc", ch="d0", t0=10, phase="P1"), + PulseQobjInstruction(name="fc", ch="d0", t0=20, phase="P2"), + PulseQobjInstruction(name="fc", ch="d0", t0=30, phase="P3"), + ] converted_instruction = [converter(qobj) for qobj in qobjs] inst_map = InstructionScheduleMap() From 249ccb7b0f7c17ddd77385185c0981c8ecb79ea1 Mon Sep 17 00:00:00 2001 From: Luciano Bello Date: Mon, 1 Jul 2024 10:45:42 +0200 Subject: [PATCH 14/51] test.python.providers.basic_provider.test_basic_simulator --- qiskit/assembler/assemble_circuits.py | 17 ++++++++++------- .../basic_provider/test_basic_simulator.py | 3 +-- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/qiskit/assembler/assemble_circuits.py b/qiskit/assembler/assemble_circuits.py index 13187089d631..6c6aa37fc602 100644 --- a/qiskit/assembler/assemble_circuits.py +++ b/qiskit/assembler/assemble_circuits.py @@ -157,13 +157,16 @@ def _assemble_circuit( ] conditional_reg_idx = memory_slots + max_conditional_idx - conversion_bfunc = QasmQobjInstruction( - name="bfunc", - mask="0x%X" % mask, # pylint: disable=consider-using-f-string - relation="==", - val="0x%X" % val, # pylint: disable=consider-using-f-string - register=conditional_reg_idx, - ) + with warnings.catch_warnings(): + # TODO remove this catch once Aer stops using _assemble + warnings.simplefilter("ignore", category=DeprecationWarning) + conversion_bfunc = QasmQobjInstruction( + name="bfunc", + mask="0x%X" % mask, # pylint: disable=consider-using-f-string + relation="==", + val="0x%X" % val, # pylint: disable=consider-using-f-string + register=conditional_reg_idx, + ) instructions.append(conversion_bfunc) instruction.conditional = conditional_reg_idx max_conditional_idx += 1 diff --git a/test/python/providers/basic_provider/test_basic_simulator.py b/test/python/providers/basic_provider/test_basic_simulator.py index 282b23c1b2a5..57dd67dfd3c3 100644 --- a/test/python/providers/basic_provider/test_basic_simulator.py +++ b/test/python/providers/basic_provider/test_basic_simulator.py @@ -17,7 +17,7 @@ import numpy as np from qiskit import ClassicalRegister, QuantumCircuit, QuantumRegister -from qiskit.compiler import transpile, assemble +from qiskit.compiler import transpile from qiskit.providers.basic_provider import BasicSimulator from qiskit.qasm2 import dumps from test import QiskitTestCase # pylint: disable=wrong-import-order @@ -47,7 +47,6 @@ def setUp(self): qcirc = QuantumCircuit.from_qasm_file(qasm_filename) qcirc.name = "test" self.transpiled_circuit = transpile(qcirc, backend=self.backend) - self.qobj = assemble(self.transpiled_circuit, shots=1000, seed_simulator=self.seed) def test_basic_simulator_single_shot(self): """Test single shot run.""" From e48d295ec3f49afb1a22404668c87edbaacc4b35 Mon Sep 17 00:00:00 2001 From: Luciano Bello Date: Mon, 1 Jul 2024 10:53:14 +0200 Subject: [PATCH 15/51] test.python.primitives.test_backend_sampler_v2 --- qiskit/primitives/backend_estimator.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/qiskit/primitives/backend_estimator.py b/qiskit/primitives/backend_estimator.py index 8446c870b1fd..a41deca6e801 100644 --- a/qiskit/primitives/backend_estimator.py +++ b/qiskit/primitives/backend_estimator.py @@ -15,6 +15,7 @@ from __future__ import annotations +import warnings from collections.abc import Sequence from itertools import accumulate @@ -67,14 +68,17 @@ def _run_circuits( max_circuits = backend.max_circuits else: raise RuntimeError("Backend version not supported") - if max_circuits: - jobs = [ - backend.run(circuits[pos : pos + max_circuits], **run_options) - for pos in range(0, len(circuits), max_circuits) - ] - result = [x.result() for x in jobs] - else: - result = [backend.run(circuits, **run_options).result()] + with warnings.catch_warnings(): + # TODO remove this catch once Aer stops using QobjDictField + warnings.simplefilter("ignore", category=DeprecationWarning) + if max_circuits: + jobs = [ + backend.run(circuits[pos : pos + max_circuits], **run_options) + for pos in range(0, len(circuits), max_circuits) + ] + result = [x.result() for x in jobs] + else: + result = [backend.run(circuits, **run_options).result()] return result, metadata From 50a350a73da93aaaee5bdd430d232a2696854272 Mon Sep 17 00:00:00 2001 From: Luciano Bello Date: Mon, 1 Jul 2024 10:55:15 +0200 Subject: [PATCH 16/51] test.python.compiler.test_disassembler --- test/python/compiler/test_disassembler.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/python/compiler/test_disassembler.py b/test/python/compiler/test_disassembler.py index 0525b54e2107..e5d0fd73a79c 100644 --- a/test/python/compiler/test_disassembler.py +++ b/test/python/compiler/test_disassembler.py @@ -457,8 +457,7 @@ class TestPulseScheduleDisassembler(QiskitTestCase): def setUp(self): super().setUp() - with self.assertWarns(DeprecationWarning): - self.backend = FakeOpenPulse2Q() + self.backend = FakeOpenPulse2Q() self.backend_config = self.backend.configuration() self.backend_config.parametric_pulses = ["constant", "gaussian", "gaussian_square", "drag"] From fefb2946ad3db444833317ce57e84e00ae3df959 Mon Sep 17 00:00:00 2001 From: Luciano Bello Date: Mon, 1 Jul 2024 15:07:08 +0200 Subject: [PATCH 17/51] test.python.compiler.test_compiler --- test/python/compiler/test_compiler.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/test/python/compiler/test_compiler.py b/test/python/compiler/test_compiler.py index 7ebfe1f13343..1479fde88cec 100644 --- a/test/python/compiler/test_compiler.py +++ b/test/python/compiler/test_compiler.py @@ -197,7 +197,8 @@ def test_parallel_compile(self): qc.cx(qr[0], qr[k]) qc.measure(qr[5], cr[0]) qlist = [qc for k in range(10)] - qobj = assemble(transpile(qlist, backend=backend)) + with self.assertWarns(DeprecationWarning): + qobj = assemble(transpile(qlist, backend=backend)) self.assertEqual(len(qobj.experiments), 10) def test_no_conflict_backend_passmanager(self): @@ -240,7 +241,8 @@ def test_compile_single_qubit(self): circuit2 = transpile( circuit, backend=None, coupling_map=cmap, basis_gates=["u2"], initial_layout=layout ) - qobj = assemble(circuit2) + with self.assertWarns(DeprecationWarning): + qobj = assemble(circuit2) compiled_instruction = qobj.experiments[0].instructions[0] @@ -504,7 +506,8 @@ def test_yzy_zyz_cases(self): circ1.cx(qr[0], qr[1]) circ1.rz(0.7, qr[1]) circ1.rx(1.570796, qr[1]) - qobj1 = assemble(transpile(circ1, backend)) + with self.assertWarns(DeprecationWarning): + qobj1 = assemble(transpile(circ1, backend)) self.assertIsInstance(qobj1, QasmQobj) circ2 = QuantumCircuit(qr) @@ -512,7 +515,8 @@ def test_yzy_zyz_cases(self): circ2.h(qr[0]) circ2.s(qr[0]) circ2.h(qr[0]) - qobj2 = assemble(transpile(circ2, backend)) + with self.assertWarns(DeprecationWarning): + qobj2 = assemble(transpile(circ2, backend)) self.assertIsInstance(qobj2, QasmQobj) From da38a7240b59db87475acfd973bf8474a3b53564 Mon Sep 17 00:00:00 2001 From: Luciano Bello Date: Mon, 1 Jul 2024 15:09:58 +0200 Subject: [PATCH 18/51] test.python.circuit.test_scheduled_circuit --- test/python/circuit/test_scheduled_circuit.py | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/test/python/circuit/test_scheduled_circuit.py b/test/python/circuit/test_scheduled_circuit.py index ec4bc72ffd06..c3b3158d7b85 100644 --- a/test/python/circuit/test_scheduled_circuit.py +++ b/test/python/circuit/test_scheduled_circuit.py @@ -66,11 +66,6 @@ def test_schedule_circuit_when_backend_tells_dt(self): self.assertEqual(sc.data[4].operation.name, "delay") self.assertEqual(sc.data[4].operation.duration, 450450) self.assertEqual(sc.data[4].operation.unit, "dt") - qobj = assemble(sc, self.backend_with_dt) - self.assertEqual(qobj.experiments[0].instructions[0].name, "delay") - self.assertEqual(qobj.experiments[0].instructions[0].params[0], 450450) - self.assertEqual(qobj.experiments[0].instructions[4].name, "delay") - self.assertEqual(qobj.experiments[0].instructions[4].params[0], 450450) def test_schedule_circuit_when_transpile_option_tells_dt(self): """dt is known to transpiler by transpile option""" @@ -119,7 +114,7 @@ def test_schedule_circuit_in_sec_when_no_one_tells_dt(self): self.assertEqual(sc.data[4].operation.name, "delay") self.assertAlmostEqual(sc.data[4].operation.duration, 1.0e-4 + 1.0e-7) self.assertEqual(sc.data[4].operation.unit, "s") - with self.assertRaises(QiskitError): + with self.assertRaises(DeprecationWarning): assemble(sc, self.backend_without_dt) def test_cannot_schedule_circuit_with_mixed_SI_and_dt_when_no_one_tells_dt(self): @@ -377,7 +372,8 @@ def test_transpile_and_assemble_delay_circuit_for_simulator(self): qc.delay(100, 0, "ns") circ = transpile(qc, self.simulator_backend) self.assertEqual(circ.duration, None) # not scheduled - qobj = assemble(circ, self.simulator_backend) + with self.assertWarns(DeprecationWarning): + qobj = assemble(circ, self.simulator_backend) self.assertEqual(qobj.experiments[0].instructions[0].name, "delay") self.assertEqual(qobj.experiments[0].instructions[0].params[0], 1e-7) @@ -389,7 +385,8 @@ def test_transpile_and_assemble_t1_circuit_for_simulator(self): qc.measure(0, 0) circ = transpile(qc, self.simulator_backend) self.assertEqual(circ.duration, None) # not scheduled - qobj = assemble(circ, self.simulator_backend) + with self.assertWarns(DeprecationWarning): + qobj = assemble(circ, self.simulator_backend) self.assertEqual(qobj.experiments[0].instructions[1].name, "delay") self.assertAlmostEqual(qobj.experiments[0].instructions[1].params[0], 1e-7) @@ -415,7 +412,8 @@ def test_can_transpile_and_assemble_circuits_with_assigning_parameters_inbetween qc.measure(0, 0) circ = transpile(qc, self.backend_with_dt) circ = circ.assign_parameters({idle_dur: 0.1}) - qobj = assemble(circ, self.backend_with_dt) + with self.assertWarns(DeprecationWarning): + qobj = assemble(circ, self.backend_with_dt) self.assertEqual(qobj.experiments[0].instructions[1].name, "delay") self.assertEqual(qobj.experiments[0].instructions[1].params[0], 450) @@ -440,7 +438,7 @@ def test_fail_to_assemble_circuits_with_unbounded_parameters(self): qc.delay(idle_dur, 0, "us") qc.measure(0, 0) qc = transpile(qc, self.backend_with_dt) - with self.assertRaises(QiskitError): + with self.assertRaises(DeprecationWarning): assemble(qc, self.backend_with_dt) @data("asap", "alap") From a4180087ab7b7734c126fe8319d0e18249d73e69 Mon Sep 17 00:00:00 2001 From: Luciano Bello Date: Mon, 1 Jul 2024 15:18:47 +0200 Subject: [PATCH 19/51] test.python.providers.test_fake_backends --- test/python/providers/test_fake_backends.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/test/python/providers/test_fake_backends.py b/test/python/providers/test_fake_backends.py index d5c5507b3b8e..76d96c946028 100644 --- a/test/python/providers/test_fake_backends.py +++ b/test/python/providers/test_fake_backends.py @@ -17,6 +17,7 @@ import itertools import operator import unittest +import warnings from test import combine from ddt import ddt, data @@ -112,7 +113,10 @@ def test_circuit_on_fake_backend_v2(self, backend, optimization_level): ), seed_simulator=42, ) - result = job.result() + with warnings.catch_warnings(): + # TODO remove this catch once Aer stops using QobjDictField + warnings.simplefilter("ignore", category=DeprecationWarning) + result = job.result() counts = result.get_counts() max_count = max(counts.items(), key=operator.itemgetter(1))[0] self.assertEqual(max_count, "11") @@ -134,7 +138,10 @@ def test_circuit_on_fake_backend(self, backend, optimization_level): ), seed_simulator=42, ) - result = job.result() + with warnings.catch_warnings(): + # TODO remove this catch once Aer stops using QobjDictField + warnings.simplefilter("ignore", category=DeprecationWarning) + result = job.result() counts = result.get_counts() max_count = max(counts.items(), key=operator.itemgetter(1))[0] self.assertEqual(max_count, "11") @@ -142,7 +149,8 @@ def test_circuit_on_fake_backend(self, backend, optimization_level): def test_qobj_failure(self): backend = BACKENDS[-1] tqc = transpile(self.circuit, backend) - qobj = assemble(tqc, backend) + with self.assertWarns(DeprecationWarning): + qobj = assemble(tqc, backend) with self.assertRaises(QiskitError): backend.run(qobj) @@ -226,7 +234,10 @@ def test_converter(self, opt_level): self.assertIsInstance(backend_v2, BackendV2) res = transpile(self.circuit, backend_v2, optimization_level=opt_level) job = backend_v2.run(res) - result = job.result() + with warnings.catch_warnings(): + # TODO remove this catch once Aer stops using QobjDictField + warnings.simplefilter("ignore", category=DeprecationWarning) + result = job.result() counts = result.get_counts() max_count = max(counts.items(), key=operator.itemgetter(1))[0] self.assertEqual(max_count, "11") From a3f0c795835408ae00cdde903104dbe0de662f33 Mon Sep 17 00:00:00 2001 From: Luciano Bello Date: Mon, 1 Jul 2024 17:53:52 +0200 Subject: [PATCH 20/51] test.python.circuit.test_unitary --- test/python/circuit/test_initializer.py | 3 ++- test/python/circuit/test_unitary.py | 6 ++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/test/python/circuit/test_initializer.py b/test/python/circuit/test_initializer.py index 122a4e4afe9a..a37c51f48184 100644 --- a/test/python/circuit/test_initializer.py +++ b/test/python/circuit/test_initializer.py @@ -481,7 +481,8 @@ def test_init(self): all(isinstance(p, complex) and not isinstance(p, np.number) for p in params) ) - qobj = assemble(qc) + with self.assertWarns(DeprecationWarning): + qobj = assemble(qc) params = qobj.experiments[0].instructions[0].params self.assertTrue( all(isinstance(p, complex) and not isinstance(p, np.number) for p in params) diff --git a/test/python/circuit/test_unitary.py b/test/python/circuit/test_unitary.py index c5c9344ad7ed..63edbdaffbf9 100644 --- a/test/python/circuit/test_unitary.py +++ b/test/python/circuit/test_unitary.py @@ -168,7 +168,8 @@ def test_qobj_with_unitary_matrix(self): uni = UnitaryGate(matrix) qc.append(uni, [qr[0], qr[1], qr[3]]) qc.cx(qr[3], qr[2]) - qobj = qiskit.compiler.assemble(qc) + with self.assertWarns(DeprecationWarning): + qobj = qiskit.compiler.assemble(qc) instr = qobj.experiments[0].instructions[1] self.assertEqual(instr.name, "unitary") assert_allclose(numpy.array(instr.params[0]).astype(numpy.complex64), matrix) @@ -197,7 +198,8 @@ def test_labeled_unitary(self): matrix = numpy.kron(sigmax, sigmay) uni = UnitaryGate(matrix, label="xy") qc.append(uni, [qr[0], qr[1]]) - qobj = qiskit.compiler.assemble(qc) + with self.assertWarns(DeprecationWarning): + qobj = qiskit.compiler.assemble(qc) instr = qobj.experiments[0].instructions[0] self.assertEqual(instr.name, "unitary") self.assertEqual(instr.label, "xy") From 2c99f288ec451c1b4a40a3bb04dba8954dd62d22 Mon Sep 17 00:00:00 2001 From: Luciano Bello Date: Mon, 1 Jul 2024 18:23:23 +0200 Subject: [PATCH 21/51] test.python.transpiler.test_sabre_swap --- test/python/compiler/test_transpiler.py | 6 +++++- test/python/transpiler/test_sabre_swap.py | 12 ++++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/test/python/compiler/test_transpiler.py b/test/python/compiler/test_transpiler.py index 77b63a3098bc..72f813ae6dfd 100644 --- a/test/python/compiler/test_transpiler.py +++ b/test/python/compiler/test_transpiler.py @@ -17,6 +17,7 @@ import math import os import sys +import warnings from logging import StreamHandler, getLogger from unittest.mock import patch import numpy as np @@ -2638,7 +2639,10 @@ def test_parallel_dispatch(self, opt_level): tqc = transpile( qlist, backend=backend, optimization_level=opt_level, seed_transpiler=424242 ) - result = backend.run(tqc, seed_simulator=4242424242, shots=1000).result() + with warnings.catch_warnings(): + # TODO remove this catch once Aer stops using QobjDictField + warnings.simplefilter("ignore", category=DeprecationWarning) + result = backend.run(tqc, seed_simulator=4242424242, shots=1000).result() counts = result.get_counts() for count in counts: self.assertTrue(math.isclose(count["00000"], 500, rel_tol=0.1)) diff --git a/test/python/transpiler/test_sabre_swap.py b/test/python/transpiler/test_sabre_swap.py index b1effdae7d8b..e403627c3daa 100644 --- a/test/python/transpiler/test_sabre_swap.py +++ b/test/python/transpiler/test_sabre_swap.py @@ -15,6 +15,8 @@ import unittest import itertools +import warnings + import ddt import numpy.random @@ -278,10 +280,12 @@ def test_no_infinite_loop(self, method): from qiskit_aer import Aer - with self.assertWarns(DeprecationWarning): - sim = Aer.get_backend("aer_simulator") - in_results = sim.run(qc, shots=4096).result().get_counts() - out_results = sim.run(routed, shots=4096).result().get_counts() + sim = Aer.get_backend("aer_simulator") + with warnings.catch_warnings(): + # TODO remove this catch once Aer stops using QobjDictField + warnings.simplefilter("ignore", category=DeprecationWarning) + in_results = sim.run(qc, shots=4096).result().get_counts() + out_results = sim.run(routed, shots=4096).result().get_counts() self.assertEqual(set(in_results), set(out_results)) def test_classical_condition(self): From 51244030e904e16198298314d0f22e38177486a9 Mon Sep 17 00:00:00 2001 From: Luciano Bello Date: Mon, 1 Jul 2024 18:25:24 +0200 Subject: [PATCH 22/51] test.python.providers.fake_provider.test_fake_backends --- .../providers/fake_provider/test_fake_backends.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/test/python/providers/fake_provider/test_fake_backends.py b/test/python/providers/fake_provider/test_fake_backends.py index c12be3584fc2..b2c8b6532ab2 100644 --- a/test/python/providers/fake_provider/test_fake_backends.py +++ b/test/python/providers/fake_provider/test_fake_backends.py @@ -13,6 +13,7 @@ """Test of generated fake backends.""" import math import unittest +import warnings from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit, transpile from qiskit.providers.fake_provider import Fake5QV1, GenericBackendV2 @@ -45,7 +46,10 @@ def test_fake_backends_get_kwargs(self): qc.measure_all() trans_qc = transpile(qc, backend) - raw_counts = backend.run(trans_qc, shots=1000).result().get_counts() + with warnings.catch_warnings(): + # TODO remove this catch once Aer stops using QobjDictField + warnings.simplefilter("ignore", category=DeprecationWarning) + raw_counts = backend.run(trans_qc, shots=1000).result().get_counts() self.assertEqual(sum(raw_counts.values()), 1000) @@ -57,6 +61,9 @@ def test_fake_backend_v2_noise_model_always_present(self): qc = QuantumCircuit(1) qc.x(0) qc.measure_all() - res = backend.run(qc, shots=1000).result().get_counts() + with warnings.catch_warnings(): + # TODO remove this catch once Aer stops using QobjDictField + warnings.simplefilter("ignore", category=DeprecationWarning) + res = backend.run(qc, shots=1000).result().get_counts() # Assert noise was present and result wasn't ideal self.assertNotEqual(res, {"1": 1000}) From 884d3942a2e6d9bc4463f7e28a2e406f107193b9 Mon Sep 17 00:00:00 2001 From: Luciano Bello Date: Mon, 1 Jul 2024 19:08:47 +0200 Subject: [PATCH 23/51] Aer using Provider ABC --- .../fake_provider/test_generic_backend_v2.py | 7 ++++++- test/python/transpiler/test_sabre_swap.py | 12 ++++++++---- 2 files changed, 14 insertions(+), 5 deletions(-) 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 cd7c611b2212..fd11b8a2eab6 100644 --- a/test/python/providers/fake_provider/test_generic_backend_v2.py +++ b/test/python/providers/fake_provider/test_generic_backend_v2.py @@ -13,6 +13,7 @@ """ Test of GenericBackendV2 backend""" import math +import warnings from qiskit import ClassicalRegister, QuantumCircuit, QuantumRegister, transpile from qiskit.providers.fake_provider import GenericBackendV2 @@ -116,7 +117,11 @@ def test_run(self): backend = GenericBackendV2(num_qubits=5, basis_gates=["cx", "id", "rz", "sx", "x"]) tqc = transpile(qc, backend=backend, optimization_level=3, seed_transpiler=42) - result = backend.run(tqc, seed_simulator=42, shots=1000).result() + with warnings.catch_warnings(): + # TODO remove this catch once Aer stops using Provider ABC + # https://github.com/Qiskit/qiskit-aer/pull/2184 + warnings.simplefilter("ignore", category=DeprecationWarning) + result = backend.run(tqc, seed_simulator=42, shots=1000).result() counts = result.get_counts() self.assertTrue(math.isclose(counts["00000"], 500, rel_tol=0.1)) diff --git a/test/python/transpiler/test_sabre_swap.py b/test/python/transpiler/test_sabre_swap.py index e403627c3daa..74932767f9e2 100644 --- a/test/python/transpiler/test_sabre_swap.py +++ b/test/python/transpiler/test_sabre_swap.py @@ -275,15 +275,19 @@ def test_no_infinite_loop(self, method): # Assert that the same keys are produced by a simulation - this is a test that the inserted # swaps route the qubits correctly. - if not optionals.HAS_AER: - return + with warnings.catch_warnings(): + # TODO remove Aer stops using Provider Qiskit class + warnings.simplefilter("ignore", category=DeprecationWarning) + if not optionals.HAS_AER: + return from qiskit_aer import Aer - sim = Aer.get_backend("aer_simulator") with warnings.catch_warnings(): - # TODO remove this catch once Aer stops using QobjDictField + # TODO remove this catch once Aer stops using QobjDictField and Provider ABC + # https://github.com/Qiskit/qiskit-aer/pull/2184 warnings.simplefilter("ignore", category=DeprecationWarning) + sim = Aer.get_backend("aer_simulator") in_results = sim.run(qc, shots=4096).result().get_counts() out_results = sim.run(routed, shots=4096).result().get_counts() self.assertEqual(set(in_results), set(out_results)) From ada3d38935897c53058ab732d6c48ade0165a65f Mon Sep 17 00:00:00 2001 From: Luciano Bello Date: Tue, 2 Jul 2024 11:17:57 +0200 Subject: [PATCH 24/51] aer warnings --- qiskit/providers/fake_provider/fake_backend.py | 5 ++++- test/python/providers/test_fake_backends.py | 16 ++++++++-------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/qiskit/providers/fake_provider/fake_backend.py b/qiskit/providers/fake_provider/fake_backend.py index 5523d123e073..0de65b09622d 100644 --- a/qiskit/providers/fake_provider/fake_backend.py +++ b/qiskit/providers/fake_provider/fake_backend.py @@ -58,7 +58,10 @@ def _setup_sim(self): self.sim = AerSimulator() if self.properties(): - noise_model = NoiseModel.from_backend(self) + with warnings.catch_warnings(): + # TODO remove this catch once Aer stops Treating CircuitInstruction as an iterable + warnings.simplefilter("ignore", category=DeprecationWarning) + noise_model = NoiseModel.from_backend(self) self.sim.set_options(noise_model=noise_model) # Update fake backend default options too to avoid overwriting # it when run() is called diff --git a/test/python/providers/test_fake_backends.py b/test/python/providers/test_fake_backends.py index 76d96c946028..a5e67e4025ee 100644 --- a/test/python/providers/test_fake_backends.py +++ b/test/python/providers/test_fake_backends.py @@ -105,17 +105,17 @@ def setUpClass(cls): optimization_level=[0, 1, 2, 3], ) def test_circuit_on_fake_backend_v2(self, backend, optimization_level): - if not optionals.HAS_AER and backend.num_qubits > 20: - self.skipTest(f"Unable to run fake_backend {backend.name} without qiskit-aer") - job = backend.run( - transpile( - self.circuit, backend, seed_transpiler=42, optimization_level=optimization_level - ), - seed_simulator=42, - ) with warnings.catch_warnings(): # TODO remove this catch once Aer stops using QobjDictField warnings.simplefilter("ignore", category=DeprecationWarning) + if not optionals.HAS_AER and backend.num_qubits > 20: + self.skipTest(f"Unable to run fake_backend {backend.name} without qiskit-aer") + job = backend.run( + transpile( + self.circuit, backend, seed_transpiler=42, optimization_level=optimization_level + ), + seed_simulator=42, + ) result = job.result() counts = result.get_counts() max_count = max(counts.items(), key=operator.itemgetter(1))[0] From 593fabb60906eed51a1d2744d78a8b9204935f45 Mon Sep 17 00:00:00 2001 From: Luciano Bello Date: Tue, 2 Jul 2024 17:08:29 +0200 Subject: [PATCH 25/51] reno --- qiskit/providers/fake_provider/fake_backend.py | 3 --- .../notes/deprecate_assemble-67486b4d0a8d4f96.yaml | 10 ++++++++++ releasenotes/notes/qobj_assemble-f745a12fd88ba9fb.yaml | 4 ---- 3 files changed, 10 insertions(+), 7 deletions(-) create mode 100644 releasenotes/notes/deprecate_assemble-67486b4d0a8d4f96.yaml delete mode 100644 releasenotes/notes/qobj_assemble-f745a12fd88ba9fb.yaml diff --git a/qiskit/providers/fake_provider/fake_backend.py b/qiskit/providers/fake_provider/fake_backend.py index 0de65b09622d..5fbd0de5da61 100644 --- a/qiskit/providers/fake_provider/fake_backend.py +++ b/qiskit/providers/fake_provider/fake_backend.py @@ -123,9 +123,6 @@ def properties(self): @classmethod def _default_options(cls): - # with warnings.catch_warnings(): - # Remove this - # warnings.simplefilter("ignore", category=DeprecationWarning) if _optionals.HAS_AER: from qiskit_aer import QasmSimulator diff --git a/releasenotes/notes/deprecate_assemble-67486b4d0a8d4f96.yaml b/releasenotes/notes/deprecate_assemble-67486b4d0a8d4f96.yaml new file mode 100644 index 000000000000..3c99d84ce84d --- /dev/null +++ b/releasenotes/notes/deprecate_assemble-67486b4d0a8d4f96.yaml @@ -0,0 +1,10 @@ +--- +deprecations_providers: + - | + The structures related to Qobj are now deprecated. Interacting with remote backends should be done via QPY or + OpenQASM instead. +deprecations_transpiler: + - | + The function `assemble` is now deprecated as the Oobj structure is not needed any more. The function was used, + among other things, to create a Qobj. It was also used for binding parameter and that functionality is now + fully covered by :meth:`.assign_parameters`. diff --git a/releasenotes/notes/qobj_assemble-f745a12fd88ba9fb.yaml b/releasenotes/notes/qobj_assemble-f745a12fd88ba9fb.yaml deleted file mode 100644 index 8817020e742a..000000000000 --- a/releasenotes/notes/qobj_assemble-f745a12fd88ba9fb.yaml +++ /dev/null @@ -1,4 +0,0 @@ ---- -deprecations_providers: - - | - With the deprecation of BackendV1, the Qobj structure is not necessary and it is deprecated. Hence, the related tools such as the function assemble are also deprecated. From 1d781b0129ad2fce826253b2bc6bc45fcf0f24f6 Mon Sep 17 00:00:00 2001 From: Luciano Bello Date: Wed, 3 Jul 2024 11:02:42 +0200 Subject: [PATCH 26/51] another pass on reno --- releasenotes/notes/deprecate_assemble-67486b4d0a8d4f96.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/releasenotes/notes/deprecate_assemble-67486b4d0a8d4f96.yaml b/releasenotes/notes/deprecate_assemble-67486b4d0a8d4f96.yaml index 3c99d84ce84d..94044a361bb9 100644 --- a/releasenotes/notes/deprecate_assemble-67486b4d0a8d4f96.yaml +++ b/releasenotes/notes/deprecate_assemble-67486b4d0a8d4f96.yaml @@ -5,6 +5,6 @@ deprecations_providers: OpenQASM instead. deprecations_transpiler: - | - The function `assemble` is now deprecated as the Oobj structure is not needed any more. The function was used, + The function `assemble` is now deprecated as the Qobj structure is not needed any more. The function was used, among other things, to create a Qobj. It was also used for binding parameter and that functionality is now - fully covered by :meth:`.assign_parameters`. + fully covered by :meth:`~.QuantumCircuit.assign_parameters`. From 621e72ad3b84d5949bb4a5b8f0de879aea46e028 Mon Sep 17 00:00:00 2001 From: Luciano Bello Date: Wed, 3 Jul 2024 14:45:59 +0200 Subject: [PATCH 27/51] test.python.pulse --- qiskit/assembler/assemble_circuits.py | 4 ++-- qiskit/providers/fake_provider/fake_backend.py | 18 +++++++++++++----- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/qiskit/assembler/assemble_circuits.py b/qiskit/assembler/assemble_circuits.py index 6c6aa37fc602..4e2439ca525b 100644 --- a/qiskit/assembler/assemble_circuits.py +++ b/qiskit/assembler/assemble_circuits.py @@ -326,14 +326,14 @@ def _assemble_circuits( # configure LO freqs per circuit with warnings.catch_warnings(): - warnings.simplefilter("ignore", category=DeprecationWarning) + # warnings.simplefilter("ignore", category=DeprecationWarning) lo_converter = converters.LoConfigConverter( QasmQobjExperimentConfig, **run_config.to_dict() ) experiments = _configure_experiment_los(experiments, lo_converter, run_config) with warnings.catch_warnings(): - warnings.simplefilter("ignore", category=DeprecationWarning) + # warnings.simplefilter("ignore", category=DeprecationWarning) qobj_config = QasmQobjConfig() if run_config: qobj_config_dict = run_config.to_dict() diff --git a/qiskit/providers/fake_provider/fake_backend.py b/qiskit/providers/fake_provider/fake_backend.py index 5fbd0de5da61..240c8e343edf 100644 --- a/qiskit/providers/fake_provider/fake_backend.py +++ b/qiskit/providers/fake_provider/fake_backend.py @@ -123,12 +123,20 @@ def properties(self): @classmethod def _default_options(cls): - if _optionals.HAS_AER: - from qiskit_aer import QasmSimulator + with warnings.catch_warnings(): + # Remove once https://github.com/Qiskit/qiskit-aer/issues/2178 gets closed. + warnings.filterwarnings( + "ignore", + category=DeprecationWarning, + module="qiskit", + message=".+abstract Provider and ProviderV1.+", + ) + if _optionals.HAS_AER: + from qiskit_aer import QasmSimulator - return QasmSimulator._default_options() - else: - return basic_provider.BasicSimulator._default_options() + return QasmSimulator._default_options() + else: + return basic_provider.BasicSimulator._default_options() def run(self, run_input, **kwargs): """Main job in simulator""" From 3898c7705c321998a2b6ba10368c392357fc8d2a Mon Sep 17 00:00:00 2001 From: Luciano Bello Date: Wed, 3 Jul 2024 15:11:07 +0200 Subject: [PATCH 28/51] test.python.compiler.test_compiler --- qiskit/assembler/assemble_circuits.py | 4 ++-- qiskit/result/result.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/qiskit/assembler/assemble_circuits.py b/qiskit/assembler/assemble_circuits.py index 4e2439ca525b..3a8a84bfc431 100644 --- a/qiskit/assembler/assemble_circuits.py +++ b/qiskit/assembler/assemble_circuits.py @@ -326,14 +326,14 @@ def _assemble_circuits( # configure LO freqs per circuit with warnings.catch_warnings(): - # warnings.simplefilter("ignore", category=DeprecationWarning) + warnings.filterwarnings("ignore", category=DeprecationWarning, module="qiskit") lo_converter = converters.LoConfigConverter( QasmQobjExperimentConfig, **run_config.to_dict() ) experiments = _configure_experiment_los(experiments, lo_converter, run_config) with warnings.catch_warnings(): - # warnings.simplefilter("ignore", category=DeprecationWarning) + warnings.filterwarnings("ignore", category=DeprecationWarning, module="qiskit") qobj_config = QasmQobjConfig() if run_config: qobj_config_dict = run_config.to_dict() diff --git a/qiskit/result/result.py b/qiskit/result/result.py index 1f8519c4b469..4a5a928f06d5 100644 --- a/qiskit/result/result.py +++ b/qiskit/result/result.py @@ -126,7 +126,7 @@ def from_dict(cls, data): in_data["results"] = [ExperimentResult.from_dict(x) for x in in_data.pop("results")] if in_data.get("header") is not None: with warnings.catch_warnings(): - warnings.simplefilter("ignore", category=DeprecationWarning) + warnings.filterwarnings("ignore", category=DeprecationWarning, module="qiskit") in_data["header"] = QobjHeader.from_dict(in_data.pop("header")) return cls(**in_data) From c2f2fdb3de97a6f5a44c8a6ba73442e75f99b106 Mon Sep 17 00:00:00 2001 From: Luciano Bello Date: Wed, 3 Jul 2024 16:05:02 +0200 Subject: [PATCH 29/51] add module to fiterwarning --- qiskit/assembler/assemble_circuits.py | 19 ++++++++++++------- qiskit/circuit/instruction.py | 3 ++- qiskit/compiler/assembler.py | 3 ++- qiskit/primitives/backend_estimator.py | 2 +- .../providers/fake_provider/fake_backend.py | 2 +- .../fake_provider/fake_openpulse_2q.py | 3 ++- .../fake_provider/fake_openpulse_3q.py | 3 ++- .../fake_provider/generic_backend_v2.py | 10 +++++----- qiskit/providers/models/pulsedefaults.py | 5 +++-- qiskit/result/models.py | 3 ++- test/python/compiler/test_transpiler.py | 2 +- .../fake_provider/test_fake_backends.py | 9 +++++---- .../fake_provider/test_generic_backend_v2.py | 2 +- test/python/providers/test_fake_backends.py | 18 +++++++++--------- test/python/transpiler/test_sabre_swap.py | 4 ++-- .../python/transpiler/test_star_prerouting.py | 4 ++-- 16 files changed, 52 insertions(+), 40 deletions(-) diff --git a/qiskit/assembler/assemble_circuits.py b/qiskit/assembler/assemble_circuits.py index 3a8a84bfc431..a8d7a78cfc4c 100644 --- a/qiskit/assembler/assemble_circuits.py +++ b/qiskit/assembler/assemble_circuits.py @@ -90,7 +90,8 @@ def _assemble_circuit( if metadata is None: metadata = {} with warnings.catch_warnings(): - warnings.simplefilter("ignore", category=DeprecationWarning) + # The class QobjExperimentHeader is deprecated + warnings.filterwarnings("ignore", category=DeprecationWarning, module="qiskit") header = QobjExperimentHeader( qubit_labels=qubit_labels, n_qubits=num_qubits, @@ -105,7 +106,8 @@ def _assemble_circuit( # TODO: why do we need n_qubits and memory_slots in both the header and the config with warnings.catch_warnings(): - warnings.simplefilter("ignore", category=DeprecationWarning) + # The class QasmQobjExperimentConfig is deprecated + warnings.filterwarnings("ignore", category=DeprecationWarning, module="qiskit") config = QasmQobjExperimentConfig(n_qubits=num_qubits, memory_slots=memory_slots) calibrations, pulse_library = _assemble_pulse_gates(circuit, run_config) if calibrations: @@ -158,8 +160,8 @@ def _assemble_circuit( conditional_reg_idx = memory_slots + max_conditional_idx with warnings.catch_warnings(): - # TODO remove this catch once Aer stops using _assemble - warnings.simplefilter("ignore", category=DeprecationWarning) + # The class QasmQobjInstruction is deprecated + warnings.filterwarnings("ignore", category=DeprecationWarning, module="qiskit") conversion_bfunc = QasmQobjInstruction( name="bfunc", mask="0x%X" % mask, # pylint: disable=consider-using-f-string @@ -176,7 +178,8 @@ def _assemble_circuit( instructions.append(instruction) with warnings.catch_warnings(): - warnings.simplefilter("ignore", category=DeprecationWarning) + # The class QasmQobjExperiment is deprecated + warnings.filterwarnings("ignore", category=DeprecationWarning, module="qiskit") return ( QasmQobjExperiment(instructions=instructions, header=header, config=config), pulse_library, @@ -365,7 +368,8 @@ def _assemble_circuits( qobj_config_dict["meas_lo_freq"] = [freq / 1e9 for freq in m_los] with warnings.catch_warnings(): - warnings.simplefilter("ignore", category=DeprecationWarning) + # The class QasmQobjConfig is deprecated + warnings.filterwarnings("ignore", category=DeprecationWarning, module="qiskit") qobj_config = QasmQobjConfig(**qobj_config_dict) qubit_sizes = [] @@ -390,7 +394,8 @@ def _assemble_circuits( if calibrations and calibrations.gates: qobj_config.calibrations = calibrations with warnings.catch_warnings(): - warnings.simplefilter("ignore", category=DeprecationWarning) + # The class QasmQobj is deprecated + warnings.filterwarnings("ignore", category=DeprecationWarning, module="qiskit") return QasmQobj( qobj_id=qobj_id, config=qobj_config, experiments=experiments, header=qobj_header ) diff --git a/qiskit/circuit/instruction.py b/qiskit/circuit/instruction.py index 2e1ae9ae7235..30796fa08ad2 100644 --- a/qiskit/circuit/instruction.py +++ b/qiskit/circuit/instruction.py @@ -372,7 +372,8 @@ def assemble(self): def _assemble(self): with warnings.catch_warnings(): - warnings.simplefilter("ignore", category=DeprecationWarning) + # The class QasmQobjInstruction is deprecated + warnings.filterwarnings("ignore", category=DeprecationWarning, module="qiskit") instruction = QasmQobjInstruction(name=self.name) # Evaluate parameters if self.params: diff --git a/qiskit/compiler/assembler.py b/qiskit/compiler/assembler.py index 3b6b22e11b86..0446735a5089 100644 --- a/qiskit/compiler/assembler.py +++ b/qiskit/compiler/assembler.py @@ -228,7 +228,8 @@ def _assemble( experiments = experiments if isinstance(experiments, list) else [experiments] pulse_qobj = any(isinstance(exp, (ScheduleBlock, Schedule, Instruction)) for exp in experiments) with warnings.catch_warnings(): - warnings.simplefilter("ignore", category=DeprecationWarning) + # The Qobj is deprecated + warnings.filterwarnings("ignore", category=DeprecationWarning, module="qiskit") qobj_id, qobj_header, run_config_common_dict = _parse_common_args( backend, qobj_id, diff --git a/qiskit/primitives/backend_estimator.py b/qiskit/primitives/backend_estimator.py index a41deca6e801..4f237396d2b2 100644 --- a/qiskit/primitives/backend_estimator.py +++ b/qiskit/primitives/backend_estimator.py @@ -70,7 +70,7 @@ def _run_circuits( raise RuntimeError("Backend version not supported") with warnings.catch_warnings(): # TODO remove this catch once Aer stops using QobjDictField - warnings.simplefilter("ignore", category=DeprecationWarning) + warnings.filterwarnings("ignore", category=DeprecationWarning, module="qiskit") if max_circuits: jobs = [ backend.run(circuits[pos : pos + max_circuits], **run_options) diff --git a/qiskit/providers/fake_provider/fake_backend.py b/qiskit/providers/fake_provider/fake_backend.py index 240c8e343edf..0256cbc9e17c 100644 --- a/qiskit/providers/fake_provider/fake_backend.py +++ b/qiskit/providers/fake_provider/fake_backend.py @@ -60,7 +60,7 @@ def _setup_sim(self): if self.properties(): with warnings.catch_warnings(): # TODO remove this catch once Aer stops Treating CircuitInstruction as an iterable - warnings.simplefilter("ignore", category=DeprecationWarning) + warnings.filterwarnings("ignore", category=DeprecationWarning, module="qiskit") noise_model = NoiseModel.from_backend(self) self.sim.set_options(noise_model=noise_model) # Update fake backend default options too to avoid overwriting diff --git a/qiskit/providers/fake_provider/fake_openpulse_2q.py b/qiskit/providers/fake_provider/fake_openpulse_2q.py index f2b5b02f5229..c76f4e048828 100644 --- a/qiskit/providers/fake_provider/fake_openpulse_2q.py +++ b/qiskit/providers/fake_provider/fake_openpulse_2q.py @@ -128,7 +128,8 @@ def __init__(self): ) with warnings.catch_warnings(): - warnings.simplefilter("ignore", category=DeprecationWarning) + # The class PulseQobjInstruction is deprecated + warnings.filterwarnings("ignore", category=DeprecationWarning, module="qiskit") self._defaults = PulseDefaults.from_dict( { "qubit_freq_est": [4.9, 5.0], diff --git a/qiskit/providers/fake_provider/fake_openpulse_3q.py b/qiskit/providers/fake_provider/fake_openpulse_3q.py index 161fc5fbb4d4..36b66847dad4 100644 --- a/qiskit/providers/fake_provider/fake_openpulse_3q.py +++ b/qiskit/providers/fake_provider/fake_openpulse_3q.py @@ -111,7 +111,8 @@ def __init__(self): }, ) with warnings.catch_warnings(): - warnings.simplefilter("ignore", category=DeprecationWarning) + # The class PulseQobjInstruction is deprecated + warnings.filterwarnings("ignore", category=DeprecationWarning, module="qiskit") self._defaults = PulseDefaults.from_dict( { "qubit_freq_est": [4.9, 5.0, 4.8], diff --git a/qiskit/providers/fake_provider/generic_backend_v2.py b/qiskit/providers/fake_provider/generic_backend_v2.py index f20ac772eac1..595e075dd44b 100644 --- a/qiskit/providers/fake_provider/generic_backend_v2.py +++ b/qiskit/providers/fake_provider/generic_backend_v2.py @@ -254,8 +254,8 @@ def _get_calibration_sequence( # 1q gates vs 2q gates vs measurement instructions. if inst == "measure": with warnings.catch_warnings(): - warnings.simplefilter("ignore", category=DeprecationWarning) - # TODO move away from deprecated PulseQobjInstruction + # The class PulseQobjInstruction is deprecated + warnings.filterwarnings("ignore", category=DeprecationWarning, module="qiskit") sequence = [ PulseQobjInstruction( name="acquire", @@ -268,10 +268,10 @@ def _get_calibration_sequence( PulseQobjInstruction(name=pulse_library[1].name, ch=f"m{i}", t0=0) for i in qargs ] - return sequence + return sequence with warnings.catch_warnings(): - warnings.simplefilter("ignore", category=DeprecationWarning) - # TODO: move away from deprecated PulseQobjInstruction + # The class PulseQobjInstruction is deprecated + warnings.filterwarnings("ignore", category=DeprecationWarning, module="qiskit") if num_qubits == 1: return [ PulseQobjInstruction(name="fc", ch=f"u{qargs[0]}", t0=0, phase="-P0"), diff --git a/qiskit/providers/models/pulsedefaults.py b/qiskit/providers/models/pulsedefaults.py index 4edfc5f2c065..fcd11c26ec29 100644 --- a/qiskit/providers/models/pulsedefaults.py +++ b/qiskit/providers/models/pulsedefaults.py @@ -272,7 +272,7 @@ def from_dict(cls, data): PulseDefaults: The PulseDefaults from the input dictionary. """ schema = { - "pulse_library": PulseLibraryItem, + "pulse_library": PulseLibraryItem, # The class PulseLibraryItem` is deprecated "cmd_def": Command, "meas_kernel": MeasurementKernel, "discriminator": Discriminator, @@ -284,7 +284,8 @@ def from_dict(cls, data): for key, value in data.items(): if key in schema: with warnings.catch_warnings(): - warnings.simplefilter("ignore", category=DeprecationWarning) + # The class PulseLibraryItem` is deprecated + warnings.filterwarnings("ignore", category=DeprecationWarning, module="qiskit") if isinstance(value, list): in_data[key] = list(map(schema[key].from_dict, value)) else: diff --git a/qiskit/result/models.py b/qiskit/result/models.py index 3eabbdd2f14f..93a1954ac7f4 100644 --- a/qiskit/result/models.py +++ b/qiskit/result/models.py @@ -225,7 +225,8 @@ def from_dict(cls, data): data_obj = ExperimentResultData.from_dict(in_data.pop("data")) if "header" in in_data: with warnings.catch_warnings(): - warnings.simplefilter("ignore", category=DeprecationWarning) + # The class QobjExperimentHeader is deprecated + warnings.filterwarnings("ignore", category=DeprecationWarning, module="qiskit") in_data["header"] = QobjExperimentHeader.from_dict(in_data.pop("header")) shots = in_data.pop("shots") success = in_data.pop("success") diff --git a/test/python/compiler/test_transpiler.py b/test/python/compiler/test_transpiler.py index 72f813ae6dfd..a1bfae10ee47 100644 --- a/test/python/compiler/test_transpiler.py +++ b/test/python/compiler/test_transpiler.py @@ -2641,7 +2641,7 @@ def test_parallel_dispatch(self, opt_level): ) with warnings.catch_warnings(): # TODO remove this catch once Aer stops using QobjDictField - warnings.simplefilter("ignore", category=DeprecationWarning) + warnings.filterwarnings("ignore", category=DeprecationWarning, module="qiskit") result = backend.run(tqc, seed_simulator=4242424242, shots=1000).result() counts = result.get_counts() for count in counts: diff --git a/test/python/providers/fake_provider/test_fake_backends.py b/test/python/providers/fake_provider/test_fake_backends.py index b2c8b6532ab2..7318fc2bc05a 100644 --- a/test/python/providers/fake_provider/test_fake_backends.py +++ b/test/python/providers/fake_provider/test_fake_backends.py @@ -48,7 +48,7 @@ def test_fake_backends_get_kwargs(self): trans_qc = transpile(qc, backend) with warnings.catch_warnings(): # TODO remove this catch once Aer stops using QobjDictField - warnings.simplefilter("ignore", category=DeprecationWarning) + warnings.filterwarnings("ignore", category=DeprecationWarning, module="qiskit") raw_counts = backend.run(trans_qc, shots=1000).result().get_counts() self.assertEqual(sum(raw_counts.values()), 1000) @@ -62,8 +62,9 @@ def test_fake_backend_v2_noise_model_always_present(self): qc.x(0) qc.measure_all() with warnings.catch_warnings(): - # TODO remove this catch once Aer stops using QobjDictField - warnings.simplefilter("ignore", category=DeprecationWarning) - res = backend.run(qc, shots=1000).result().get_counts() + with warnings.catch_warnings(): + # TODO remove this catch once Aer stops using QobjDictField + warnings.filterwarnings("ignore", category=DeprecationWarning, module="qiskit") + res = backend.run(qc, shots=1000).result().get_counts() # Assert noise was present and result wasn't ideal self.assertNotEqual(res, {"1": 1000}) 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 fd11b8a2eab6..8a19f62aee95 100644 --- a/test/python/providers/fake_provider/test_generic_backend_v2.py +++ b/test/python/providers/fake_provider/test_generic_backend_v2.py @@ -120,7 +120,7 @@ def test_run(self): with warnings.catch_warnings(): # TODO remove this catch once Aer stops using Provider ABC # https://github.com/Qiskit/qiskit-aer/pull/2184 - warnings.simplefilter("ignore", category=DeprecationWarning) + warnings.filterwarnings("ignore", category=DeprecationWarning, module="qiskit") result = backend.run(tqc, seed_simulator=42, shots=1000).result() counts = result.get_counts() diff --git a/test/python/providers/test_fake_backends.py b/test/python/providers/test_fake_backends.py index a5e67e4025ee..49771deef568 100644 --- a/test/python/providers/test_fake_backends.py +++ b/test/python/providers/test_fake_backends.py @@ -107,7 +107,7 @@ def setUpClass(cls): def test_circuit_on_fake_backend_v2(self, backend, optimization_level): with warnings.catch_warnings(): # TODO remove this catch once Aer stops using QobjDictField - warnings.simplefilter("ignore", category=DeprecationWarning) + warnings.filterwarnings("ignore", category=DeprecationWarning, module="qiskit") if not optionals.HAS_AER and backend.num_qubits > 20: self.skipTest(f"Unable to run fake_backend {backend.name} without qiskit-aer") job = backend.run( @@ -132,15 +132,15 @@ def test_circuit_on_fake_backend(self, backend, optimization_level): self.skipTest( f"Unable to run fake_backend {backend.configuration().backend_name} without qiskit-aer" ) - job = backend.run( - transpile( - self.circuit, backend, seed_transpiler=42, optimization_level=optimization_level - ), - seed_simulator=42, - ) with warnings.catch_warnings(): # TODO remove this catch once Aer stops using QobjDictField - warnings.simplefilter("ignore", category=DeprecationWarning) + warnings.filterwarnings("ignore", category=DeprecationWarning, module="qiskit") + job = backend.run( + transpile( + self.circuit, backend, seed_transpiler=42, optimization_level=optimization_level + ), + seed_simulator=42, + ) result = job.result() counts = result.get_counts() max_count = max(counts.items(), key=operator.itemgetter(1))[0] @@ -236,7 +236,7 @@ def test_converter(self, opt_level): job = backend_v2.run(res) with warnings.catch_warnings(): # TODO remove this catch once Aer stops using QobjDictField - warnings.simplefilter("ignore", category=DeprecationWarning) + warnings.filterwarnings("ignore", category=DeprecationWarning, module="qiskit") result = job.result() counts = result.get_counts() max_count = max(counts.items(), key=operator.itemgetter(1))[0] diff --git a/test/python/transpiler/test_sabre_swap.py b/test/python/transpiler/test_sabre_swap.py index 74932767f9e2..5273e2a17089 100644 --- a/test/python/transpiler/test_sabre_swap.py +++ b/test/python/transpiler/test_sabre_swap.py @@ -277,7 +277,7 @@ def test_no_infinite_loop(self, method): # swaps route the qubits correctly. with warnings.catch_warnings(): # TODO remove Aer stops using Provider Qiskit class - warnings.simplefilter("ignore", category=DeprecationWarning) + warnings.filterwarnings("ignore", category=DeprecationWarning, module="qiskit") if not optionals.HAS_AER: return @@ -286,7 +286,7 @@ def test_no_infinite_loop(self, method): with warnings.catch_warnings(): # TODO remove this catch once Aer stops using QobjDictField and Provider ABC # https://github.com/Qiskit/qiskit-aer/pull/2184 - warnings.simplefilter("ignore", category=DeprecationWarning) + warnings.filterwarnings("ignore", category=DeprecationWarning, module="qiskit") sim = Aer.get_backend("aer_simulator") in_results = sim.run(qc, shots=4096).result().get_counts() out_results = sim.run(routed, shots=4096).result().get_counts() diff --git a/test/python/transpiler/test_star_prerouting.py b/test/python/transpiler/test_star_prerouting.py index c09d4a717a28..aeac559e2b9c 100644 --- a/test/python/transpiler/test_star_prerouting.py +++ b/test/python/transpiler/test_star_prerouting.py @@ -262,7 +262,7 @@ def test_100q_grid_full_path(self, opt_level): result = pm.run(qc) with warnings.catch_warnings(): # TODO remove this catch once Aer stops using qiskit.qobj.common.QobjDictField` - warnings.simplefilter("ignore", category=DeprecationWarning) + warnings.filterwarnings("ignore", category=DeprecationWarning, module="qiskit") counts_before = AerSimulator().run(qc).result().get_counts() counts_after = AerSimulator().run(result).result().get_counts() self.assertEqual(counts_before, counts_after) @@ -305,7 +305,7 @@ def test_100q_grid_full_path_no_barrier(self, opt_level): result = pm.run(qc) with warnings.catch_warnings(): # TODO remove this catch once Aer stops using qiskit.qobj.common.QobjDictField` - warnings.simplefilter("ignore", category=DeprecationWarning) + warnings.filterwarnings("ignore", category=DeprecationWarning, module="qiskit") counts_before = AerSimulator().run(qc).result().get_counts() counts_after = AerSimulator().run(result).result().get_counts() self.assertEqual(counts_before, counts_after) From 82032bc011b319a324c76b6baf7ba4115234a90d Mon Sep 17 00:00:00 2001 From: Luciano Bello Date: Thu, 4 Jul 2024 11:38:44 +0200 Subject: [PATCH 30/51] test.python.compiler.test_transpiler --- qiskit/compiler/assembler.py | 53 ++++++++++++++++++------------------ 1 file changed, 27 insertions(+), 26 deletions(-) diff --git a/qiskit/compiler/assembler.py b/qiskit/compiler/assembler.py index 0446735a5089..68edde7f7e6f 100644 --- a/qiskit/compiler/assembler.py +++ b/qiskit/compiler/assembler.py @@ -227,26 +227,23 @@ def _assemble( start_time = time() experiments = experiments if isinstance(experiments, list) else [experiments] pulse_qobj = any(isinstance(exp, (ScheduleBlock, Schedule, Instruction)) for exp in experiments) - with warnings.catch_warnings(): - # The Qobj is deprecated - warnings.filterwarnings("ignore", category=DeprecationWarning, module="qiskit") - qobj_id, qobj_header, run_config_common_dict = _parse_common_args( - backend, - qobj_id, - qobj_header, - shots, - memory, - seed_simulator, - init_qubits, - rep_delay, - qubit_lo_freq, - meas_lo_freq, - qubit_lo_range, - meas_lo_range, - schedule_los, - pulse_qobj=pulse_qobj, - **run_config, - ) + qobj_id, qobj_header, run_config_common_dict = _parse_common_args( + backend, + qobj_id, + qobj_header, + shots, + memory, + seed_simulator, + init_qubits, + rep_delay, + qubit_lo_freq, + meas_lo_freq, + qubit_lo_range, + meas_lo_range, + schedule_los, + pulse_qobj=pulse_qobj, + **run_config, + ) # assemble either circuits or schedules if all(isinstance(exp, QuantumCircuit) for exp in experiments): @@ -265,12 +262,16 @@ def _assemble( ) end_time = time() _log_assembly_time(start_time, end_time) - return _assemble_circuits( - circuits=bound_experiments, - qobj_id=qobj_id, - qobj_header=qobj_header, - run_config=run_config, - ) + with warnings.catch_warnings(): + # The Qobj is deprecated + # warnings.filterwarnings("ignore", category=DeprecationWarning, module="qiskit") + warnings.filterwarnings("ignore", category=DeprecationWarning) + return _assemble_circuits( + circuits=bound_experiments, + qobj_id=qobj_id, + qobj_header=qobj_header, + run_config=run_config, + ) elif all(isinstance(exp, (ScheduleBlock, Schedule, Instruction)) for exp in experiments): run_config = _parse_pulse_args( From 963b1ae12337d675241b8dd6a58f963a23a93a3c Mon Sep 17 00:00:00 2001 From: Luciano Bello Date: Thu, 4 Jul 2024 12:45:05 +0200 Subject: [PATCH 31/51] fixing obscure expcetion handleing for comparison --- qiskit/compiler/assembler.py | 37 +++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/qiskit/compiler/assembler.py b/qiskit/compiler/assembler.py index 68edde7f7e6f..eb1697fd4e07 100644 --- a/qiskit/compiler/assembler.py +++ b/qiskit/compiler/assembler.py @@ -227,23 +227,26 @@ def _assemble( start_time = time() experiments = experiments if isinstance(experiments, list) else [experiments] pulse_qobj = any(isinstance(exp, (ScheduleBlock, Schedule, Instruction)) for exp in experiments) - qobj_id, qobj_header, run_config_common_dict = _parse_common_args( - backend, - qobj_id, - qobj_header, - shots, - memory, - seed_simulator, - init_qubits, - rep_delay, - qubit_lo_freq, - meas_lo_freq, - qubit_lo_range, - meas_lo_range, - schedule_los, - pulse_qobj=pulse_qobj, - **run_config, - ) + with warnings.catch_warnings(): + # The Qobj is deprecated + warnings.filterwarnings("ignore", category=DeprecationWarning, module="qiskit") + qobj_id, qobj_header, run_config_common_dict = _parse_common_args( + backend, + qobj_id, + qobj_header, + shots, + memory, + seed_simulator, + init_qubits, + rep_delay, + qubit_lo_freq, + meas_lo_freq, + qubit_lo_range, + meas_lo_range, + schedule_los, + pulse_qobj=pulse_qobj, + **run_config, + ) # assemble either circuits or schedules if all(isinstance(exp, QuantumCircuit) for exp in experiments): From d185d7e618b9eb7bc7810a2ff33b8215e2bbb7cf Mon Sep 17 00:00:00 2001 From: Luciano Bello Date: Sun, 21 Jul 2024 22:19:55 +0200 Subject: [PATCH 32/51] Apply suggestions from code review 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> --- qiskit/assembler/assemble_circuits.py | 6 +++--- .../notes/deprecate_assemble-67486b4d0a8d4f96.yaml | 7 ++----- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/qiskit/assembler/assemble_circuits.py b/qiskit/assembler/assemble_circuits.py index a8d7a78cfc4c..b6f8c4038574 100644 --- a/qiskit/assembler/assemble_circuits.py +++ b/qiskit/assembler/assemble_circuits.py @@ -404,9 +404,9 @@ def _assemble_circuits( @deprecate_func( since="1.2", removal_timeline="in the 2.0 release", - additional_msg="The function assemble_circuits is being deprecated " - "as they are not necessary for BackendV2. If user still need Qobj, that probably " - "means that they are using a backend based on the deprecated BackendV1 class.", + additional_msg="The `Qobj` class and related functionality are part of the deprecated `BackendV1` " + "workflow, and no longer necessary for `BackendV2`. If a user workflow requires `Qobj` it likely relies " + "on deprecated functionality and should be updated to use `BackendV2`.", ) def assemble_circuits( circuits: List[QuantumCircuit], run_config: RunConfig, qobj_id: int, qobj_header: QobjHeader diff --git a/releasenotes/notes/deprecate_assemble-67486b4d0a8d4f96.yaml b/releasenotes/notes/deprecate_assemble-67486b4d0a8d4f96.yaml index 94044a361bb9..b7b50d2eb2b2 100644 --- a/releasenotes/notes/deprecate_assemble-67486b4d0a8d4f96.yaml +++ b/releasenotes/notes/deprecate_assemble-67486b4d0a8d4f96.yaml @@ -1,10 +1,7 @@ --- deprecations_providers: - | - The structures related to Qobj are now deprecated. Interacting with remote backends should be done via QPY or - OpenQASM instead. + The `Qobj` structure and related classes are now deprecated, they were introduced as part of the `BackendV1` workflow and are no longer necessary for interacting with :class:`.BackendV2` backends. Remote backend interaction should be done via `QPY` or `OpenQASM` instead. deprecations_transpiler: - | - The function `assemble` is now deprecated as the Qobj structure is not needed any more. The function was used, - among other things, to create a Qobj. It was also used for binding parameter and that functionality is now - fully covered by :meth:`~.QuantumCircuit.assign_parameters`. + The `assemble` function is now deprecated and will be removed in the 2.0 release. The function was primarily used to create a `Qobj`, which is no longer necessary in :class:`.BackendV2`-based workflows. It was also used for binding parameters, a functionality fully covered by :meth:`~.QuantumCircuit.assign_parameters`. From ac54cd8b364cfb5b9a2171897c40077044a2b508 Mon Sep 17 00:00:00 2001 From: Luciano Bello Date: Sun, 21 Jul 2024 22:31:07 +0200 Subject: [PATCH 33/51] remove catch --- qiskit/compiler/assembler.py | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/qiskit/compiler/assembler.py b/qiskit/compiler/assembler.py index eb1697fd4e07..0446735a5089 100644 --- a/qiskit/compiler/assembler.py +++ b/qiskit/compiler/assembler.py @@ -265,16 +265,12 @@ def _assemble( ) end_time = time() _log_assembly_time(start_time, end_time) - with warnings.catch_warnings(): - # The Qobj is deprecated - # warnings.filterwarnings("ignore", category=DeprecationWarning, module="qiskit") - warnings.filterwarnings("ignore", category=DeprecationWarning) - return _assemble_circuits( - circuits=bound_experiments, - qobj_id=qobj_id, - qobj_header=qobj_header, - run_config=run_config, - ) + return _assemble_circuits( + circuits=bound_experiments, + qobj_id=qobj_id, + qobj_header=qobj_header, + run_config=run_config, + ) elif all(isinstance(exp, (ScheduleBlock, Schedule, Instruction)) for exp in experiments): run_config = _parse_pulse_args( From 9cd165b48f912f49750747cbe944293a6629f4f5 Mon Sep 17 00:00:00 2001 From: Luciano Bello Date: Sun, 21 Jul 2024 22:52:52 +0200 Subject: [PATCH 34/51] new deprecate warning message --- qiskit/assembler/disassemble.py | 7 +-- qiskit/circuit/instruction.py | 7 +-- qiskit/compiler/assembler.py | 7 +-- qiskit/qobj/common.py | 7 +-- qiskit/qobj/converters/lo_config.py | 7 +-- qiskit/qobj/converters/pulse_instruction.py | 8 ++-- qiskit/qobj/pulse_qobj.py | 51 +++++++++++---------- qiskit/qobj/qasm_qobj.py | 51 +++++++++++---------- qiskit/qobj/utils.py | 6 +-- 9 files changed, 83 insertions(+), 68 deletions(-) diff --git a/qiskit/assembler/disassemble.py b/qiskit/assembler/disassemble.py index 8f296a42d9bf..74905a9a6d20 100644 --- a/qiskit/assembler/disassemble.py +++ b/qiskit/assembler/disassemble.py @@ -41,9 +41,10 @@ @deprecate_func( since="1.2", removal_timeline="in the 2.0 release", - additional_msg="The function disassemble is being deprecated " - "as they are not necessary for BackendV2. If user still need Qobj, that probably " - "means that they are using a backend based on the deprecated BackendV1 class.", + additional_msg="The `Qobj` class and related functionality are part of the deprecated " + "`BackendV1` workflow, and no longer necessary for `BackendV2`. If a user " + "workflow requires `Qobj` it likely relies on deprecated functionality and " + "should be updated to use `BackendV2`.", ) def disassemble(qobj) -> Union[CircuitModule, PulseModule]: """Disassemble a qobj and return the circuits or pulse schedules, run_config, and user header. diff --git a/qiskit/circuit/instruction.py b/qiskit/circuit/instruction.py index 30796fa08ad2..7963d0c1e096 100644 --- a/qiskit/circuit/instruction.py +++ b/qiskit/circuit/instruction.py @@ -362,9 +362,10 @@ def unit(self, unit): @deprecate_func( since="1.2", removal_timeline="in the 2.0 release", - additional_msg="The method assemble is being deprecated " - "as it is not necessary for BackendV2. If user still need Qobj, that probably " - "means that they are using a backend based on the deprecated BackendV1 class.", + additional_msg="The `Qobj` class and related functionality are part of the deprecated " + "`BackendV1` workflow, and no longer necessary for `BackendV2`. If a user " + "workflow requires `Qobj` it likely relies on deprecated functionality and " + "should be updated to use `BackendV2`.", ) def assemble(self): """Assemble a QasmQobjInstruction""" diff --git a/qiskit/compiler/assembler.py b/qiskit/compiler/assembler.py index 0446735a5089..2802169b4afb 100644 --- a/qiskit/compiler/assembler.py +++ b/qiskit/compiler/assembler.py @@ -44,9 +44,10 @@ def _log_assembly_time(start_time, end_time): @deprecate_func( since="1.2", removal_timeline="in the 2.0 release", - additional_msg="The function assemble is being deprecated " - "as they are not necessary for BackendV2. If user still need Qobj, that probably " - "means that they are using a backend based on the deprecated BackendV1 class.", + additional_msg="The `Qobj` class and related functionality are part of the deprecated " + "`BackendV1` workflow, and no longer necessary for `BackendV2`. If a user " + "workflow requires `Qobj` it likely relies on deprecated functionality and " + "should be updated to use `BackendV2`.", ) def assemble( experiments: Union[ diff --git a/qiskit/qobj/common.py b/qiskit/qobj/common.py index 9a3fdd4e20e2..0f1e2372fd9a 100644 --- a/qiskit/qobj/common.py +++ b/qiskit/qobj/common.py @@ -26,9 +26,10 @@ class QobjDictField(SimpleNamespace): @deprecate_func( since="1.2", removal_timeline="in the 2.0 release", - additional_msg="The full Qobj module is being deprecated, including QobjDictField's subclasses, " - "as they are not necessary for BackendV2. If user still need Qobj, that probably " - "means that they are using a backend based on the deprecated BackendV1 class.", + additional_msg="The `Qobj` class and related functionality are part of the deprecated " + "`BackendV1` workflow, and no longer necessary for `BackendV2`. If a user " + "workflow requires `Qobj` it likely relies on deprecated functionality and " + "should be updated to use `BackendV2`.", ) def __init__(self, **kwargs): """Instantiate a new Qobj dict field object. diff --git a/qiskit/qobj/converters/lo_config.py b/qiskit/qobj/converters/lo_config.py index a76df3991f05..a5b5beb80df2 100644 --- a/qiskit/qobj/converters/lo_config.py +++ b/qiskit/qobj/converters/lo_config.py @@ -27,9 +27,10 @@ class LoConfigConverter: @deprecate_func( since="1.2", removal_timeline="in the 2.0 release", - additional_msg="The full Qobj module is being deprecated, including LoConfigConverter class, " - "as they are not necessary for BackendV2. If user still need Qobj, that probably " - "means that they are using a backend based on the deprecated BackendV1 class.", + additional_msg="The `Qobj` class and related functionality are part of the deprecated " + "`BackendV1` workflow, and no longer necessary for `BackendV2`. If a user " + "workflow requires `Qobj` it likely relies on deprecated functionality and " + "should be updated to use `BackendV2`.", ) def __init__( self, diff --git a/qiskit/qobj/converters/pulse_instruction.py b/qiskit/qobj/converters/pulse_instruction.py index 45f82a9c7d50..e17036210d57 100644 --- a/qiskit/qobj/converters/pulse_instruction.py +++ b/qiskit/qobj/converters/pulse_instruction.py @@ -111,10 +111,10 @@ def _convert_NewInstruction(self, instruction, time_offset): @deprecate_func( since="1.2", removal_timeline="in the 2.0 release", - additional_msg="The full Qobj module is being deprecated, including InstructionToQobjConverter " - "class, " - "as they are not necessary for BackendV2. If user still need Qobj, that probably " - "means that they are using a backend based on the deprecated BackendV1 class.", + additional_msg="The `Qobj` class and related functionality are part of the deprecated " + "`BackendV1` workflow, and no longer necessary for `BackendV2`. If a user " + "workflow requires `Qobj` it likely relies on deprecated functionality and " + "should be updated to use `BackendV2`.", ) def __init__( self, diff --git a/qiskit/qobj/pulse_qobj.py b/qiskit/qobj/pulse_qobj.py index 0de59f894dc6..7a5ce06c8f3f 100644 --- a/qiskit/qobj/pulse_qobj.py +++ b/qiskit/qobj/pulse_qobj.py @@ -32,10 +32,10 @@ class QobjMeasurementOption: @deprecate_func( since="1.2", removal_timeline="in the 2.0 release", - additional_msg="The full Qobj module is being deprecated, including QobjMeasurementOption " - "class, " - "as they are not necessary for BackendV2. If user still need Qobj, that probably " - "means that they are using a backend based on the deprecated BackendV1 class.", + additional_msg="The `Qobj` class and related functionality are part of the deprecated " + "`BackendV1` workflow, and no longer necessary for `BackendV2`. If a user " + "workflow requires `Qobj` it likely relies on deprecated functionality and " + "should be updated to use `BackendV2`.", ) def __init__(self, name, params=None): """Instantiate a new QobjMeasurementOption object. @@ -101,9 +101,10 @@ class PulseQobjInstruction: @deprecate_func( since="1.2", removal_timeline="in the 2.0 release", - additional_msg="The full Qobj module is being deprecated, including PulseQobjInstruction class, " - "as they are not necessary for BackendV2. If user still need Qobj, that probably " - "means that they are using a backend based on the deprecated BackendV1 class.", + additional_msg="The `Qobj` class and related functionality are part of the deprecated " + "`BackendV1` workflow, and no longer necessary for `BackendV2`. If a user " + "workflow requires `Qobj` it likely relies on deprecated functionality and " + "should be updated to use `BackendV2`.", ) def __init__( self, @@ -301,9 +302,10 @@ class PulseQobjConfig(QobjDictField): @deprecate_func( since="1.2", removal_timeline="in the 2.0 release", - additional_msg="The full Qobj module is being deprecated, including PulseQobjConfig class, " - "as they are not necessary for BackendV2. If user still need Qobj, that probably " - "means that they are using a backend based on the deprecated BackendV1 class.", + additional_msg="The `Qobj` class and related functionality are part of the deprecated " + "`BackendV1` workflow, and no longer necessary for `BackendV2`. If a user " + "workflow requires `Qobj` it likely relies on deprecated functionality and " + "should be updated to use `BackendV2`.", ) def __init__( self, @@ -409,9 +411,10 @@ class PulseQobjExperiment: @deprecate_func( since="1.2", removal_timeline="in the 2.0 release", - additional_msg="The full Qobj module is being deprecated, including PulseQobjExperiment class, " - "as they are not necessary for BackendV2. If user still need Qobj, that probably " - "means that they are using a backend based on the deprecated BackendV1 class.", + additional_msg="The `Qobj` class and related functionality are part of the deprecated " + "`BackendV1` workflow, and no longer necessary for `BackendV2`. If a user " + "workflow requires `Qobj` it likely relies on deprecated functionality and " + "should be updated to use `BackendV2`.", ) def __init__(self, instructions, config=None, header=None): """Instantiate a PulseQobjExperiment. @@ -506,10 +509,10 @@ class PulseQobjExperimentConfig(QobjDictField): @deprecate_func( since="1.2", removal_timeline="in the 2.0 release", - additional_msg="The full Qobj module is being deprecated, including PulseQobjExperimentConfig " - "class, " - "as they are not necessary for BackendV2. If user still need Qobj, that probably " - "means that they are using a backend based on the deprecated BackendV1 class.", + additional_msg="The `Qobj` class and related functionality are part of the deprecated " + "`BackendV1` workflow, and no longer necessary for `BackendV2`. If a user " + "workflow requires `Qobj` it likely relies on deprecated functionality and " + "should be updated to use `BackendV2`.", ) def __init__(self, qubit_lo_freq=None, meas_lo_freq=None, **kwargs): """Instantiate a PulseQobjExperimentConfig object. @@ -533,9 +536,10 @@ class PulseLibraryItem: @deprecate_func( since="1.2", removal_timeline="in the 2.0 release", - additional_msg="The full Qobj module is being deprecated, including PulseLibraryItem class, " - "as they are not necessary for BackendV2. If user still need Qobj, that probably " - "means that they are using a backend based on the deprecated BackendV1 class.", + additional_msg="The `Qobj` class and related functionality are part of the deprecated " + "`BackendV1` workflow, and no longer necessary for `BackendV2`. If a user " + "workflow requires `Qobj` it likely relies on deprecated functionality and " + "should be updated to use `BackendV2`.", ) def __init__(self, name, samples): """Instantiate a pulse library item. @@ -590,9 +594,10 @@ class PulseQobj: @deprecate_func( since="1.2", removal_timeline="in the 2.0 release", - additional_msg="The full Qobj module is being deprecated, including PulseQobj class, " - "as they are not necessary for BackendV2. If user still need Qobj, that probably " - "means that they are using a backend based on the deprecated BackendV1 class.", + additional_msg="The `Qobj` class and related functionality are part of the deprecated " + "`BackendV1` workflow, and no longer necessary for `BackendV2`. If a user " + "workflow requires `Qobj` it likely relies on deprecated functionality and " + "should be updated to use `BackendV2`.", ) def __init__(self, qobj_id, config, experiments, header=None): """Instantiate a new Pulse Qobj Object. diff --git a/qiskit/qobj/qasm_qobj.py b/qiskit/qobj/qasm_qobj.py index b9b78bcb4ec1..8858913fb47c 100644 --- a/qiskit/qobj/qasm_qobj.py +++ b/qiskit/qobj/qasm_qobj.py @@ -27,9 +27,10 @@ class QasmQobjInstruction: @deprecate_func( since="1.2", removal_timeline="in the 2.0 release", - additional_msg="The full Qobj module is being deprecated, including PulseQobj class, " - "as they are not necessary for BackendV2. If user still need Qobj, that probably " - "means that they are using a backend based on the deprecated BackendV1 class.", + additional_msg="The `Qobj` class and related functionality are part of the deprecated " + "`BackendV1` workflow, and no longer necessary for `BackendV2`. If a user " + "workflow requires `Qobj` it likely relies on deprecated functionality and " + "should be updated to use `BackendV2`.", ) def __init__( self, @@ -211,9 +212,10 @@ class QasmQobjExperiment: @deprecate_func( since="1.2", removal_timeline="in the 2.0 release", - additional_msg="The full Qobj module is being deprecated, including QasmQobjExperiment class, " - "as they are not necessary for BackendV2. If user still need Qobj, that probably " - "means that they are using a backend based on the deprecated BackendV1 class.", + additional_msg="The `Qobj` class and related functionality are part of the deprecated " + "`BackendV1` workflow, and no longer necessary for `BackendV2`. If a user " + "workflow requires `Qobj` it likely relies on deprecated functionality and " + "should be updated to use `BackendV2`.", ) def __init__(self, config=None, header=None, instructions=None): """Instantiate a QasmQobjExperiment. @@ -294,9 +296,10 @@ class QasmQobjConfig(SimpleNamespace): @deprecate_func( since="1.2", removal_timeline="in the 2.0 release", - additional_msg="The full Qobj module is being deprecated, including QasmQobjConfig class, " - "as they are not necessary for BackendV2. If user still need Qobj, that probably " - "means that they are using a backend based on the deprecated BackendV1 class.", + additional_msg="The `Qobj` class and related functionality are part of the deprecated " + "`BackendV1` workflow, and no longer necessary for `BackendV2`. If a user " + "workflow requires `Qobj` it likely relies on deprecated functionality and " + "should be updated to use `BackendV2`.", ) def __init__( self, @@ -435,10 +438,10 @@ class QasmQobjExperimentConfig(QobjDictField): @deprecate_func( since="1.2", removal_timeline="in the 2.0 release", - additional_msg="The full Qobj module is being deprecated, including QasmQobjExperimentConfig " - "class, " - "as they are not necessary for BackendV2. If user still need Qobj, that probably " - "means that they are using a backend based on the deprecated BackendV1 class.", + additional_msg="The `Qobj` class and related functionality are part of the deprecated " + "`BackendV1` workflow, and no longer necessary for `BackendV2`. If a user " + "workflow requires `Qobj` it likely relies on deprecated functionality and " + "should be updated to use `BackendV2`.", ) def __init__(self, calibrations=None, qubit_lo_freq=None, meas_lo_freq=None, **kwargs): """ @@ -479,10 +482,10 @@ class QasmExperimentCalibrations: @deprecate_func( since="1.2", removal_timeline="in the 2.0 release", - additional_msg="The full Qobj module is being deprecated, including QasmExperimentCalibrations " - "class, " - "as they are not necessary for BackendV2. If user still need Qobj, that probably " - "means that they are using a backend based on the deprecated BackendV1 class.", + additional_msg="The `Qobj` class and related functionality are part of the deprecated " + "`BackendV1` workflow, and no longer necessary for `BackendV2`. If a user " + "workflow requires `Qobj` it likely relies on deprecated functionality and " + "should be updated to use `BackendV2`.", ) def __init__(self, gates): """ @@ -527,9 +530,10 @@ class GateCalibration: @deprecate_func( since="1.2", removal_timeline="in the 2.0 release", - additional_msg="The full Qobj module is being deprecated, including GateCalibration class, " - "as they are not necessary for BackendV2. If user still need Qobj, that probably " - "means that they are using a backend based on the deprecated BackendV1 class.", + additional_msg="The `Qobj` class and related functionality are part of the deprecated " + "`BackendV1` workflow, and no longer necessary for `BackendV2`. If a user " + "workflow requires `Qobj` it likely relies on deprecated functionality and " + "should be updated to use `BackendV2`.", ) def __init__(self, name, qubits, params, instructions): """ @@ -589,9 +593,10 @@ class QasmQobj: @deprecate_func( since="1.2", removal_timeline="in the 2.0 release", - additional_msg="The full Qobj module is being deprecated, including QasmQobj class, " - "as they are not necessary for BackendV2. If user still need Qobj, that probably " - "means that they are using a backend based on the deprecated BackendV1 class.", + additional_msg="The `Qobj` class and related functionality are part of the deprecated " + "`BackendV1` workflow, and no longer necessary for `BackendV2`. If a user " + "workflow requires `Qobj` it likely relies on deprecated functionality and " + "should be updated to use `BackendV2`.", ) def __init__(self, qobj_id=None, config=None, experiments=None, header=None): """Instantiate a new OpenQASM 2 Qobj Object. diff --git a/qiskit/qobj/utils.py b/qiskit/qobj/utils.py index 1d3b6bd84300..1e691d6324bf 100644 --- a/qiskit/qobj/utils.py +++ b/qiskit/qobj/utils.py @@ -20,9 +20,9 @@ @deprecate_func( since="1.2", removal_timeline="in the 2.0 release", - additional_msg="The full Qobj module is being deprecated, including QobjType class, " - "as they are not necessary for BackendV2. If user still need Qobj, that probably " - "means that they are using a backend based on the deprecated BackendV1 class.", + additional_msg="The `Qobj` class and related functionality are part of the deprecated `BackendV1` " + "workflow, and no longer necessary for `BackendV2`. If a user workflow requires `Qobj` it likely " + "relies on deprecated functionality and should be updated to use `BackendV2`.", ) class QobjType(str, Enum): """Qobj.type allowed values.""" From a45431ac7a3af661c4b30fa6312adf04fd764830 Mon Sep 17 00:00:00 2001 From: Luciano Bello Date: Mon, 22 Jul 2024 10:44:25 +0200 Subject: [PATCH 35/51] lint qiskit/assembler/assemble_circuits.py --- qiskit/assembler/assemble_circuits.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/qiskit/assembler/assemble_circuits.py b/qiskit/assembler/assemble_circuits.py index b6f8c4038574..5fd3eced62cc 100644 --- a/qiskit/assembler/assemble_circuits.py +++ b/qiskit/assembler/assemble_circuits.py @@ -405,8 +405,9 @@ def _assemble_circuits( since="1.2", removal_timeline="in the 2.0 release", additional_msg="The `Qobj` class and related functionality are part of the deprecated `BackendV1` " - "workflow, and no longer necessary for `BackendV2`. If a user workflow requires `Qobj` it likely relies " - "on deprecated functionality and should be updated to use `BackendV2`.", + "workflow, and no longer necessary for `BackendV2`. If a user workflow requires " + "`Qobj` it likely relies on deprecated functionality and should be updated to " + "use `BackendV2`.", ) def assemble_circuits( circuits: List[QuantumCircuit], run_config: RunConfig, qobj_id: int, qobj_header: QobjHeader From fa7f32d58596df49e4726b29e8946851f5c44e90 Mon Sep 17 00:00:00 2001 From: Luciano Bello Date: Mon, 22 Jul 2024 13:56:49 +0200 Subject: [PATCH 36/51] concurrency warnings --- qiskit/assembler/assemble_circuits.py | 6 +++++- test/python/compiler/test_transpiler.py | 6 +----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/qiskit/assembler/assemble_circuits.py b/qiskit/assembler/assemble_circuits.py index 5fd3eced62cc..62f3df180718 100644 --- a/qiskit/assembler/assemble_circuits.py +++ b/qiskit/assembler/assemble_circuits.py @@ -316,7 +316,11 @@ def _configure_experiment_los( def _assemble_circuits( circuits: List[QuantumCircuit], run_config: RunConfig, qobj_id: int, qobj_header: QobjHeader ) -> QasmQobj: - experiments_and_pulse_libs = parallel_map(_assemble_circuit, circuits, [run_config]) + with warnings.catch_warnings(): + # Still constructs Qobj, that is deprecated. The message is hard to trace to a module, + # because concurrency is hard. + warnings.filterwarnings("ignore", category=DeprecationWarning) + experiments_and_pulse_libs = parallel_map(_assemble_circuit, circuits, [run_config]) experiments = [] pulse_library = {} for exp, lib in experiments_and_pulse_libs: diff --git a/test/python/compiler/test_transpiler.py b/test/python/compiler/test_transpiler.py index a1bfae10ee47..77b63a3098bc 100644 --- a/test/python/compiler/test_transpiler.py +++ b/test/python/compiler/test_transpiler.py @@ -17,7 +17,6 @@ import math import os import sys -import warnings from logging import StreamHandler, getLogger from unittest.mock import patch import numpy as np @@ -2639,10 +2638,7 @@ def test_parallel_dispatch(self, opt_level): tqc = transpile( qlist, backend=backend, optimization_level=opt_level, seed_transpiler=424242 ) - with warnings.catch_warnings(): - # TODO remove this catch once Aer stops using QobjDictField - warnings.filterwarnings("ignore", category=DeprecationWarning, module="qiskit") - result = backend.run(tqc, seed_simulator=4242424242, shots=1000).result() + result = backend.run(tqc, seed_simulator=4242424242, shots=1000).result() counts = result.get_counts() for count in counts: self.assertTrue(math.isclose(count["00000"], 500, rel_tol=0.1)) From 2a085b5356f693184c5b7ff8cfa5aaeedba4bf25 Mon Sep 17 00:00:00 2001 From: Luciano Bello Date: Mon, 22 Jul 2024 14:25:29 +0200 Subject: [PATCH 37/51] ignore aer warnings --- test/utils/base.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/test/utils/base.py b/test/utils/base.py index 0b02f3e58488..8bb76777f56d 100644 --- a/test/utils/base.py +++ b/test/utils/base.py @@ -129,6 +129,24 @@ def setUpClass(cls): module=r"qiskit_aer(\.[a-zA-Z0-9_]+)*", ) + # Safe to remove once https://github.com/Qiskit/qiskit-aer/issues/2065 is in a release version + # of Aer. + warnings.filterwarnings( + "ignore", # If "default", it floods the CI output + category=DeprecationWarning, + message=r".*The `Qobj` class and related functionality.*", + module=r"qiskit_aer", + ) + + # Safe to remove once https://github.com/Qiskit/qiskit-aer/pull/2184 is in a release version + # of Aer. + warnings.filterwarnings( + "ignore", # If "default", it floods the CI output + category=DeprecationWarning, + message=r".*The abstract Provider and ProviderV1 classes are deprecated.*", + module="qiskit_aer", + ) + allow_DeprecationWarning_message = [ r"The property ``qiskit\.circuit\.bit\.Bit\.(register|index)`` is deprecated.*", ] From 5e63bef6cc2aa15b5dadfcf0b39c5e8761757f93 Mon Sep 17 00:00:00 2001 From: Luciano Bello Date: Tue, 23 Jul 2024 11:39:11 +0200 Subject: [PATCH 38/51] Update test/python/providers/fake_provider/test_fake_backends.py 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> --- test/python/providers/fake_provider/test_fake_backends.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/test/python/providers/fake_provider/test_fake_backends.py b/test/python/providers/fake_provider/test_fake_backends.py index 7318fc2bc05a..3d22c2de7e72 100644 --- a/test/python/providers/fake_provider/test_fake_backends.py +++ b/test/python/providers/fake_provider/test_fake_backends.py @@ -61,10 +61,6 @@ def test_fake_backend_v2_noise_model_always_present(self): qc = QuantumCircuit(1) qc.x(0) qc.measure_all() - with warnings.catch_warnings(): - with warnings.catch_warnings(): - # TODO remove this catch once Aer stops using QobjDictField - warnings.filterwarnings("ignore", category=DeprecationWarning, module="qiskit") - res = backend.run(qc, shots=1000).result().get_counts() + res = backend.run(qc, shots=1000).result().get_counts() # Assert noise was present and result wasn't ideal self.assertNotEqual(res, {"1": 1000}) From 83332e52f2ca12a78f0ecc04cac6f163df796835 Mon Sep 17 00:00:00 2001 From: Luciano Bello Date: Tue, 23 Jul 2024 11:40:02 +0200 Subject: [PATCH 39/51] Update test/python/circuit/test_parameters.py 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> --- test/python/circuit/test_parameters.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/python/circuit/test_parameters.py b/test/python/circuit/test_parameters.py index d977aa30089f..4f989767164f 100644 --- a/test/python/circuit/test_parameters.py +++ b/test/python/circuit/test_parameters.py @@ -1022,8 +1022,7 @@ def test_binding_parameterized_circuits_built_in_multiproc_(self): ) def test_binding_parameterized_circuits_built_in_multiproc(self): - """Verify subcircuits built in a subprocess can still be bound. - REMOVE this test once assemble is REMOVED""" + """Verify subcircuits built in a subprocess can still be bound.""" # ref: https://github.com/Qiskit/qiskit-terra/issues/2429 num_processes = 4 From 60cc9c54159af92ab05bf158d24dbfc3dda0df4c Mon Sep 17 00:00:00 2001 From: Luciano Bello Date: Tue, 23 Jul 2024 11:40:21 +0200 Subject: [PATCH 40/51] Update qiskit/providers/models/pulsedefaults.py 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> --- qiskit/providers/models/pulsedefaults.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qiskit/providers/models/pulsedefaults.py b/qiskit/providers/models/pulsedefaults.py index fcd11c26ec29..494d31c7a60d 100644 --- a/qiskit/providers/models/pulsedefaults.py +++ b/qiskit/providers/models/pulsedefaults.py @@ -272,7 +272,7 @@ def from_dict(cls, data): PulseDefaults: The PulseDefaults from the input dictionary. """ schema = { - "pulse_library": PulseLibraryItem, # The class PulseLibraryItem` is deprecated + "pulse_library": PulseLibraryItem, # The class PulseLibraryItem is deprecated "cmd_def": Command, "meas_kernel": MeasurementKernel, "discriminator": Discriminator, From 1362b1b0cd882555750446b5ca681043e456d8e4 Mon Sep 17 00:00:00 2001 From: Luciano Bello Date: Tue, 23 Jul 2024 14:31:30 +0200 Subject: [PATCH 41/51] Update test/python/providers/fake_provider/test_fake_backends.py 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> --- test/python/providers/fake_provider/test_fake_backends.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/test/python/providers/fake_provider/test_fake_backends.py b/test/python/providers/fake_provider/test_fake_backends.py index 3d22c2de7e72..ba9909d95abc 100644 --- a/test/python/providers/fake_provider/test_fake_backends.py +++ b/test/python/providers/fake_provider/test_fake_backends.py @@ -46,10 +46,7 @@ def test_fake_backends_get_kwargs(self): qc.measure_all() trans_qc = transpile(qc, backend) - with warnings.catch_warnings(): - # TODO remove this catch once Aer stops using QobjDictField - warnings.filterwarnings("ignore", category=DeprecationWarning, module="qiskit") - raw_counts = backend.run(trans_qc, shots=1000).result().get_counts() + raw_counts = backend.run(trans_qc, shots=1000).result().get_counts() self.assertEqual(sum(raw_counts.values()), 1000) From 787090f4216271478d8ebcc2d95ecb00db7a44b6 Mon Sep 17 00:00:00 2001 From: Luciano Bello Date: Tue, 23 Jul 2024 14:31:37 +0200 Subject: [PATCH 42/51] Update test/python/providers/fake_provider/test_generic_backend_v2.py 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> --- .../providers/fake_provider/test_generic_backend_v2.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) 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 51df49e73456..e0dc3e986c8a 100644 --- a/test/python/providers/fake_provider/test_generic_backend_v2.py +++ b/test/python/providers/fake_provider/test_generic_backend_v2.py @@ -137,11 +137,7 @@ def test_run(self): backend = GenericBackendV2(num_qubits=5, basis_gates=["cx", "id", "rz", "sx", "x"]) tqc = transpile(qc, backend=backend, optimization_level=3, seed_transpiler=42) - with warnings.catch_warnings(): - # TODO remove this catch once Aer stops using Provider ABC - # https://github.com/Qiskit/qiskit-aer/pull/2184 - warnings.filterwarnings("ignore", category=DeprecationWarning, module="qiskit") - result = backend.run(tqc, seed_simulator=42, shots=1000).result() + result = backend.run(tqc, seed_simulator=42, shots=1000).result() counts = result.get_counts() self.assertTrue(math.isclose(counts["00000"], 500, rel_tol=0.1)) From 20a0c5cab953be84e3a680f88b9a9d33760a2396 Mon Sep 17 00:00:00 2001 From: Luciano Bello Date: Tue, 23 Jul 2024 16:49:45 +0200 Subject: [PATCH 43/51] lint --- test/python/providers/fake_provider/test_fake_backends.py | 1 - test/python/providers/fake_provider/test_generic_backend_v2.py | 1 - 2 files changed, 2 deletions(-) diff --git a/test/python/providers/fake_provider/test_fake_backends.py b/test/python/providers/fake_provider/test_fake_backends.py index ba9909d95abc..c12be3584fc2 100644 --- a/test/python/providers/fake_provider/test_fake_backends.py +++ b/test/python/providers/fake_provider/test_fake_backends.py @@ -13,7 +13,6 @@ """Test of generated fake backends.""" import math import unittest -import warnings from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit, transpile from qiskit.providers.fake_provider import Fake5QV1, GenericBackendV2 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 e0dc3e986c8a..33bf57cf3903 100644 --- a/test/python/providers/fake_provider/test_generic_backend_v2.py +++ b/test/python/providers/fake_provider/test_generic_backend_v2.py @@ -13,7 +13,6 @@ """ Test of GenericBackendV2 backend""" import math -import warnings from qiskit import ClassicalRegister, QuantumCircuit, QuantumRegister, transpile from qiskit.providers.fake_provider import GenericBackendV2 From bd216a17e8e0f3f20b6b5862c0b7c4f20d45ff56 Mon Sep 17 00:00:00 2001 From: Luciano Bello Date: Tue, 23 Jul 2024 16:53:01 +0200 Subject: [PATCH 44/51] https://github.com/Qiskit/qiskit/pull/12649#discussion_r1686717954 --- test/python/providers/test_fake_backends.py | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/test/python/providers/test_fake_backends.py b/test/python/providers/test_fake_backends.py index 49771deef568..f857d32c210c 100644 --- a/test/python/providers/test_fake_backends.py +++ b/test/python/providers/test_fake_backends.py @@ -132,16 +132,13 @@ def test_circuit_on_fake_backend(self, backend, optimization_level): self.skipTest( f"Unable to run fake_backend {backend.configuration().backend_name} without qiskit-aer" ) - with warnings.catch_warnings(): - # TODO remove this catch once Aer stops using QobjDictField - warnings.filterwarnings("ignore", category=DeprecationWarning, module="qiskit") - job = backend.run( - transpile( - self.circuit, backend, seed_transpiler=42, optimization_level=optimization_level - ), - seed_simulator=42, - ) - result = job.result() + job = backend.run( + transpile( + self.circuit, backend, seed_transpiler=42, optimization_level=optimization_level + ), + seed_simulator=42, + ) + result = job.result() counts = result.get_counts() max_count = max(counts.items(), key=operator.itemgetter(1))[0] self.assertEqual(max_count, "11") From c1c3b32caf4d040b756e3f05b08d743cefb76d5a Mon Sep 17 00:00:00 2001 From: Luciano Bello Date: Tue, 23 Jul 2024 16:55:01 +0200 Subject: [PATCH 45/51] https://github.com/Qiskit/qiskit/pull/12649#discussion_r1686717732 --- test/python/providers/test_fake_backends.py | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/test/python/providers/test_fake_backends.py b/test/python/providers/test_fake_backends.py index f857d32c210c..1a1c55d1ee2d 100644 --- a/test/python/providers/test_fake_backends.py +++ b/test/python/providers/test_fake_backends.py @@ -105,18 +105,15 @@ def setUpClass(cls): optimization_level=[0, 1, 2, 3], ) def test_circuit_on_fake_backend_v2(self, backend, optimization_level): - with warnings.catch_warnings(): - # TODO remove this catch once Aer stops using QobjDictField - warnings.filterwarnings("ignore", category=DeprecationWarning, module="qiskit") - if not optionals.HAS_AER and backend.num_qubits > 20: - self.skipTest(f"Unable to run fake_backend {backend.name} without qiskit-aer") - job = backend.run( - transpile( - self.circuit, backend, seed_transpiler=42, optimization_level=optimization_level - ), - seed_simulator=42, - ) - result = job.result() + if not optionals.HAS_AER and backend.num_qubits > 20: + self.skipTest(f"Unable to run fake_backend {backend.name} without qiskit-aer") + job = backend.run( + transpile( + self.circuit, backend, seed_transpiler=42, optimization_level=optimization_level + ), + seed_simulator=42, + ) + result = job.result() counts = result.get_counts() max_count = max(counts.items(), key=operator.itemgetter(1))[0] self.assertEqual(max_count, "11") From 7a2b3f79ec0a607eb4ed67a05f3b561f728aee17 Mon Sep 17 00:00:00 2001 From: Luciano Bello Date: Tue, 23 Jul 2024 16:56:09 +0200 Subject: [PATCH 46/51] Update test/python/transpiler/test_sabre_swap.py 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> --- test/python/transpiler/test_sabre_swap.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/test/python/transpiler/test_sabre_swap.py b/test/python/transpiler/test_sabre_swap.py index 5273e2a17089..ae3199a7ff27 100644 --- a/test/python/transpiler/test_sabre_swap.py +++ b/test/python/transpiler/test_sabre_swap.py @@ -275,11 +275,8 @@ def test_no_infinite_loop(self, method): # Assert that the same keys are produced by a simulation - this is a test that the inserted # swaps route the qubits correctly. - with warnings.catch_warnings(): - # TODO remove Aer stops using Provider Qiskit class - warnings.filterwarnings("ignore", category=DeprecationWarning, module="qiskit") - if not optionals.HAS_AER: - return + if not optionals.HAS_AER: + return from qiskit_aer import Aer From 5f19ae93c93d9a0ba9ddeb7aae32426b92f14b88 Mon Sep 17 00:00:00 2001 From: Luciano Bello Date: Tue, 23 Jul 2024 16:56:45 +0200 Subject: [PATCH 47/51] Update qiskit/providers/models/pulsedefaults.py 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> --- qiskit/providers/models/pulsedefaults.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qiskit/providers/models/pulsedefaults.py b/qiskit/providers/models/pulsedefaults.py index 494d31c7a60d..1302994d40e6 100644 --- a/qiskit/providers/models/pulsedefaults.py +++ b/qiskit/providers/models/pulsedefaults.py @@ -284,7 +284,7 @@ def from_dict(cls, data): for key, value in data.items(): if key in schema: with warnings.catch_warnings(): - # The class PulseLibraryItem` is deprecated + # The class PulseLibraryItem is deprecated warnings.filterwarnings("ignore", category=DeprecationWarning, module="qiskit") if isinstance(value, list): in_data[key] = list(map(schema[key].from_dict, value)) From a761b2d758780b72c7fec119aa3f242f5a15ebf5 Mon Sep 17 00:00:00 2001 From: Luciano Bello Date: Tue, 23 Jul 2024 17:58:00 +0200 Subject: [PATCH 48/51] ignore Treating CircuitInstruction... --- test/utils/base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/utils/base.py b/test/utils/base.py index 8bb76777f56d..6d0c917ace30 100644 --- a/test/utils/base.py +++ b/test/utils/base.py @@ -123,7 +123,7 @@ def setUpClass(cls): # Safe to remove once https://github.com/Qiskit/qiskit-aer/pull/2179 is in a release version # of Aer. warnings.filterwarnings( - "default", + "ignore", # If "default", it floods the CI output category=DeprecationWarning, message="Treating CircuitInstruction as an iterable is deprecated", module=r"qiskit_aer(\.[a-zA-Z0-9_]+)*", From 264f2af3d294991ecd8fa525f1d62a5021ba9e15 Mon Sep 17 00:00:00 2001 From: Luciano Bello Date: Wed, 24 Jul 2024 09:27:26 +0200 Subject: [PATCH 49/51] another unnecessary catch from aer --- qiskit/primitives/backend_estimator.py | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/qiskit/primitives/backend_estimator.py b/qiskit/primitives/backend_estimator.py index 4f237396d2b2..8446c870b1fd 100644 --- a/qiskit/primitives/backend_estimator.py +++ b/qiskit/primitives/backend_estimator.py @@ -15,7 +15,6 @@ from __future__ import annotations -import warnings from collections.abc import Sequence from itertools import accumulate @@ -68,17 +67,14 @@ def _run_circuits( max_circuits = backend.max_circuits else: raise RuntimeError("Backend version not supported") - with warnings.catch_warnings(): - # TODO remove this catch once Aer stops using QobjDictField - warnings.filterwarnings("ignore", category=DeprecationWarning, module="qiskit") - if max_circuits: - jobs = [ - backend.run(circuits[pos : pos + max_circuits], **run_options) - for pos in range(0, len(circuits), max_circuits) - ] - result = [x.result() for x in jobs] - else: - result = [backend.run(circuits, **run_options).result()] + if max_circuits: + jobs = [ + backend.run(circuits[pos : pos + max_circuits], **run_options) + for pos in range(0, len(circuits), max_circuits) + ] + result = [x.result() for x in jobs] + else: + result = [backend.run(circuits, **run_options).result()] return result, metadata From 4c76ad0ce05412ea1399b681ce0268460a0f929a Mon Sep 17 00:00:00 2001 From: Luciano Bello Date: Wed, 24 Jul 2024 09:29:53 +0200 Subject: [PATCH 50/51] another unnecessary catch from aer, again --- .../providers/fake_provider/fake_backend.py | 23 +++++-------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/qiskit/providers/fake_provider/fake_backend.py b/qiskit/providers/fake_provider/fake_backend.py index 0256cbc9e17c..4a638f315574 100644 --- a/qiskit/providers/fake_provider/fake_backend.py +++ b/qiskit/providers/fake_provider/fake_backend.py @@ -58,10 +58,7 @@ def _setup_sim(self): self.sim = AerSimulator() if self.properties(): - with warnings.catch_warnings(): - # TODO remove this catch once Aer stops Treating CircuitInstruction as an iterable - warnings.filterwarnings("ignore", category=DeprecationWarning, module="qiskit") - noise_model = NoiseModel.from_backend(self) + noise_model = NoiseModel.from_backend(self) self.sim.set_options(noise_model=noise_model) # Update fake backend default options too to avoid overwriting # it when run() is called @@ -123,20 +120,12 @@ def properties(self): @classmethod def _default_options(cls): - with warnings.catch_warnings(): - # Remove once https://github.com/Qiskit/qiskit-aer/issues/2178 gets closed. - warnings.filterwarnings( - "ignore", - category=DeprecationWarning, - module="qiskit", - message=".+abstract Provider and ProviderV1.+", - ) - if _optionals.HAS_AER: - from qiskit_aer import QasmSimulator + if _optionals.HAS_AER: + from qiskit_aer import QasmSimulator - return QasmSimulator._default_options() - else: - return basic_provider.BasicSimulator._default_options() + return QasmSimulator._default_options() + else: + return basic_provider.BasicSimulator._default_options() def run(self, run_input, **kwargs): """Main job in simulator""" From b69bdf96b5663ddb6bb8ffb367398701df515cef Mon Sep 17 00:00:00 2001 From: Luciano Bello Date: Thu, 25 Jul 2024 11:03:57 +0200 Subject: [PATCH 51/51] removing more unnecesary catches --- test/python/transpiler/test_sabre_swap.py | 11 +++-------- test/python/transpiler/test_star_prerouting.py | 15 ++++----------- 2 files changed, 7 insertions(+), 19 deletions(-) diff --git a/test/python/transpiler/test_sabre_swap.py b/test/python/transpiler/test_sabre_swap.py index ae3199a7ff27..bf2ef5b1f9c4 100644 --- a/test/python/transpiler/test_sabre_swap.py +++ b/test/python/transpiler/test_sabre_swap.py @@ -15,7 +15,6 @@ import unittest import itertools -import warnings import ddt import numpy.random @@ -280,13 +279,9 @@ def test_no_infinite_loop(self, method): from qiskit_aer import Aer - with warnings.catch_warnings(): - # TODO remove this catch once Aer stops using QobjDictField and Provider ABC - # https://github.com/Qiskit/qiskit-aer/pull/2184 - warnings.filterwarnings("ignore", category=DeprecationWarning, module="qiskit") - sim = Aer.get_backend("aer_simulator") - in_results = sim.run(qc, shots=4096).result().get_counts() - out_results = sim.run(routed, shots=4096).result().get_counts() + sim = Aer.get_backend("aer_simulator") + in_results = sim.run(qc, shots=4096).result().get_counts() + out_results = sim.run(routed, shots=4096).result().get_counts() self.assertEqual(set(in_results), set(out_results)) def test_classical_condition(self): diff --git a/test/python/transpiler/test_star_prerouting.py b/test/python/transpiler/test_star_prerouting.py index aeac559e2b9c..e244d97a45aa 100644 --- a/test/python/transpiler/test_star_prerouting.py +++ b/test/python/transpiler/test_star_prerouting.py @@ -15,7 +15,6 @@ """Test the StarPreRouting pass""" import unittest -import warnings from test import QiskitTestCase import ddt @@ -260,11 +259,8 @@ def test_100q_grid_full_path(self, opt_level): ) pm.init += StarPreRouting() result = pm.run(qc) - with warnings.catch_warnings(): - # TODO remove this catch once Aer stops using qiskit.qobj.common.QobjDictField` - warnings.filterwarnings("ignore", category=DeprecationWarning, module="qiskit") - counts_before = AerSimulator().run(qc).result().get_counts() - counts_after = AerSimulator().run(result).result().get_counts() + counts_before = AerSimulator().run(qc).result().get_counts() + counts_after = AerSimulator().run(result).result().get_counts() self.assertEqual(counts_before, counts_after) def test_10q_bv_no_barrier(self): @@ -303,11 +299,8 @@ def test_100q_grid_full_path_no_barrier(self, opt_level): ) pm.init += StarPreRouting() result = pm.run(qc) - with warnings.catch_warnings(): - # TODO remove this catch once Aer stops using qiskit.qobj.common.QobjDictField` - warnings.filterwarnings("ignore", category=DeprecationWarning, module="qiskit") - counts_before = AerSimulator().run(qc).result().get_counts() - counts_after = AerSimulator().run(result).result().get_counts() + counts_before = AerSimulator().run(qc).result().get_counts() + counts_after = AerSimulator().run(result).result().get_counts() self.assertEqual(counts_before, counts_after) def test_hadamard_ordering(self):