From 6ce52505c1901bcd95373d3ab2e8514dcefb92aa Mon Sep 17 00:00:00 2001 From: Luciano Bello Date: Thu, 25 Jul 2024 12:11:56 +0200 Subject: [PATCH] Deprecate Qobj and assemble (#12649) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * deprecate qobj and assemble * reno * shallow deprecation of assemble * test.python.compiler.test_disassembler * fakebackend pulse * test.python.circuit.test_parameters * PulseQobjInstruction is used by GenericBackendV2 * test.python.scheduler.test_basic_scheduler * test.python.result.test_result * test.python.pulse.test_calibration_entries * test.python.compiler.test_assembler * test.python.transpiler.test_star_prerouting * test.python.pulse.test_instruction_schedule_map * test.python.providers.basic_provider.test_basic_simulator * test.python.primitives.test_backend_sampler_v2 * test.python.compiler.test_disassembler * test.python.compiler.test_compiler * test.python.circuit.test_scheduled_circuit * test.python.providers.test_fake_backends * test.python.circuit.test_unitary * test.python.transpiler.test_sabre_swap * test.python.providers.fake_provider.test_fake_backends * Aer using Provider ABC * aer warnings * reno * another pass on reno * test.python.pulse * test.python.compiler.test_compiler * add module to fiterwarning * test.python.compiler.test_transpiler * fixing obscure expcetion handleing for comparison * Apply suggestions from code review Co-authored-by: Elena Peña Tapia <57907331+ElePT@users.noreply.github.com> * remove catch * new deprecate warning message * lint qiskit/assembler/assemble_circuits.py * concurrency warnings * ignore aer warnings * Update test/python/providers/fake_provider/test_fake_backends.py Co-authored-by: Elena Peña Tapia <57907331+ElePT@users.noreply.github.com> * Update test/python/circuit/test_parameters.py Co-authored-by: Elena Peña Tapia <57907331+ElePT@users.noreply.github.com> * Update qiskit/providers/models/pulsedefaults.py Co-authored-by: Elena Peña Tapia <57907331+ElePT@users.noreply.github.com> * Update test/python/providers/fake_provider/test_fake_backends.py Co-authored-by: Elena Peña Tapia <57907331+ElePT@users.noreply.github.com> * Update test/python/providers/fake_provider/test_generic_backend_v2.py Co-authored-by: Elena Peña Tapia <57907331+ElePT@users.noreply.github.com> * lint * https://github.com/Qiskit/qiskit/pull/12649#discussion_r1686717954 * https://github.com/Qiskit/qiskit/pull/12649#discussion_r1686717732 * Update test/python/transpiler/test_sabre_swap.py Co-authored-by: Elena Peña Tapia <57907331+ElePT@users.noreply.github.com> * Update qiskit/providers/models/pulsedefaults.py Co-authored-by: Elena Peña Tapia <57907331+ElePT@users.noreply.github.com> * ignore Treating CircuitInstruction... * another unnecessary catch from aer * another unnecessary catch from aer, again * removing more unnecesary catches --------- Co-authored-by: Elena Peña Tapia <57907331+ElePT@users.noreply.github.com> --- qiskit/assembler/assemble_circuits.py | 171 +-- qiskit/assembler/disassemble.py | 9 + qiskit/circuit/instruction.py | 19 +- qiskit/compiler/assembler.py | 95 +- .../basic_provider/basic_simulator.py | 4 +- .../fake_provider/fake_openpulse_2q.py | 300 +++--- .../fake_provider/fake_openpulse_3q.py | 443 ++++---- .../fake_provider/generic_backend_v2.py | 45 +- qiskit/providers/models/pulsedefaults.py | 14 +- qiskit/qobj/common.py | 10 + qiskit/qobj/converters/lo_config.py | 9 + qiskit/qobj/converters/pulse_instruction.py | 9 + qiskit/qobj/pulse_qobj.py | 57 + qiskit/qobj/qasm_qobj.py | 57 + qiskit/qobj/utils.py | 9 + qiskit/result/models.py | 6 +- qiskit/result/result.py | 4 +- .../deprecate_assemble-67486b4d0a8d4f96.yaml | 7 + test/benchmarks/assembler.py | 2 + test/python/circuit/test_diagonal_gate.py | 12 +- test/python/circuit/test_hamiltonian_gate.py | 6 +- test/python/circuit/test_initializer.py | 3 +- test/python/circuit/test_parameters.py | 52 +- test/python/circuit/test_scheduled_circuit.py | 18 +- test/python/circuit/test_unitary.py | 6 +- test/python/compiler/test_assembler.py | 977 ++++++++++-------- test/python/compiler/test_compiler.py | 12 +- test/python/compiler/test_disassembler.py | 131 ++- .../basic_provider/test_basic_simulator.py | 3 +- test/python/providers/test_fake_backends.py | 9 +- test/python/pulse/test_calibration_entries.py | 168 +-- .../pulse/test_instruction_schedule_map.py | 13 +- test/python/qobj/test_pulse_converter.py | 310 +++--- test/python/qobj/test_qobj.py | 427 ++++---- test/python/qobj/test_qobj_identifiers.py | 3 +- test/python/result/test_result.py | 150 ++- .../transpiler/test_preset_passmanagers.py | 14 +- test/python/transpiler/test_sabre_swap.py | 4 +- .../python/transpiler/test_star_prerouting.py | 1 + test/utils/base.py | 20 +- 40 files changed, 2128 insertions(+), 1481 deletions(-) create mode 100644 releasenotes/notes/deprecate_assemble-67486b4d0a8d4f96.yaml diff --git a/qiskit/assembler/assemble_circuits.py b/qiskit/assembler/assemble_circuits.py index a3d9b6bbb549..62f3df180718 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,26 @@ 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(): + # The class QobjExperimentHeader is deprecated + warnings.filterwarnings("ignore", category=DeprecationWarning, module="qiskit") + 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(): + # 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: config.calibrations = calibrations @@ -118,7 +126,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 @@ -151,13 +159,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(): + # 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 + 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 @@ -166,10 +177,13 @@ def _assemble_circuit( del instruction._condition instructions.append(instruction) - return ( - QasmQobjExperiment(instructions=instructions, header=header, config=config), - pulse_library, - ) + with warnings.catch_warnings(): + # The class QasmQobjExperiment is deprecated + warnings.filterwarnings("ignore", category=DeprecationWarning, module="qiskit") + return ( + QasmQobjExperiment(instructions=instructions, header=header, config=config), + pulse_library, + ) def _assemble_pulse_gates( @@ -299,42 +313,14 @@ 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]) + 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: @@ -346,10 +332,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.filterwarnings("ignore", category=DeprecationWarning, module="qiskit") + 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.filterwarnings("ignore", category=DeprecationWarning, module="qiskit") + qobj_config = QasmQobjConfig() if run_config: qobj_config_dict = run_config.to_dict() @@ -379,7 +371,10 @@ 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(): + # The class QasmQobjConfig is deprecated + warnings.filterwarnings("ignore", category=DeprecationWarning, module="qiskit") + qobj_config = QasmQobjConfig(**qobj_config_dict) qubit_sizes = [] memory_slot_sizes = [] @@ -402,7 +397,55 @@ def assemble_circuits( if calibrations and calibrations.gates: qobj_config.calibrations = calibrations + with warnings.catch_warnings(): + # 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 + ) - 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 `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 +) -> 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/assembler/disassemble.py b/qiskit/assembler/disassemble.py index 127bbd35eb26..74905a9a6d20 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,14 @@ 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 `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 4bebf812e185..d67fe4b5f12f 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 @@ -359,9 +360,23 @@ 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 `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""" - instruction = QasmQobjInstruction(name=self.name) + return self._assemble() + + def _assemble(self): + with warnings.catch_warnings(): + # The class QasmQobjInstruction is deprecated + warnings.filterwarnings("ignore", category=DeprecationWarning, module="qiskit") + 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 522e1c503ddf..2802169b4afb 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 @@ -29,6 +29,8 @@ 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 +from qiskit.assembler.assemble_circuits import _assemble_circuits logger = logging.getLogger(__name__) @@ -39,6 +41,14 @@ 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 `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[ QuantumCircuit, @@ -81,7 +91,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. @@ -153,27 +163,92 @@ 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(): + # 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): run_config = _parse_circuit_args( @@ -191,7 +266,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/providers/fake_provider/fake_openpulse_2q.py b/qiskit/providers/fake_provider/fake_openpulse_2q.py index caa0f53e7a38..c76f4e048828 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,159 @@ 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(): + # The class PulseQobjInstruction is deprecated + warnings.filterwarnings("ignore", category=DeprecationWarning, module="qiskit") + 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..36b66847dad4 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,231 @@ 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(): + # 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], + "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/qiskit/providers/fake_provider/generic_backend_v2.py b/qiskit/providers/fake_provider/generic_backend_v2.py index 0da1df7eab65..09827eba48b7 100644 --- a/qiskit/providers/fake_provider/generic_backend_v2.py +++ b/qiskit/providers/fake_provider/generic_backend_v2.py @@ -266,27 +266,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] + with warnings.catch_warnings(): + # The class PulseQobjInstruction is deprecated + warnings.filterwarnings("ignore", category=DeprecationWarning, module="qiskit") + 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(): + # 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"), + 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/qiskit/providers/models/pulsedefaults.py b/qiskit/providers/models/pulsedefaults.py index 7c1864bad9ee..1302994d40e6 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 @@ -271,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, @@ -282,10 +283,13 @@ 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(): + # 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: + in_data[key] = schema[key].from_dict(value) else: in_data[key] = value diff --git a/qiskit/qobj/common.py b/qiskit/qobj/common.py index 9b219e5ba8d0..0f1e2372fd9a 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,14 @@ class QobjDictField(SimpleNamespace): previously constructed using marshmallow. """ + @deprecate_func( + 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`.", + ) 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..a5b5beb80df2 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,14 @@ 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 `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_model, diff --git a/qiskit/qobj/converters/pulse_instruction.py b/qiskit/qobj/converters/pulse_instruction.py index 8f34ee0855ac..e17036210d57 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 `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_model: PulseQobjInstruction, diff --git a/qiskit/qobj/pulse_qobj.py b/qiskit/qobj/pulse_qobj.py index 3552d83ada84..7a5ce06c8f3f 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 `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. @@ -89,6 +98,14 @@ class PulseQobjInstruction: "parameters", ] + @deprecate_func( + 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`.", + ) def __init__( self, name, @@ -282,6 +299,14 @@ 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 `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, meas_level, @@ -383,6 +408,14 @@ 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 `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. @@ -473,6 +506,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 `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. @@ -492,6 +533,14 @@ 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 `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. @@ -542,6 +591,14 @@ def __eq__(self, other): class PulseQobj: """A Pulse Qobj.""" + @deprecate_func( + 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`.", + ) 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..8858913fb47c 100644 --- a/qiskit/qobj/qasm_qobj.py +++ b/qiskit/qobj/qasm_qobj.py @@ -18,11 +18,20 @@ 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 `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, @@ -200,6 +209,14 @@ class QasmQobjExperiment: part of a larger OpenQASM 2 qobj. """ + @deprecate_func( + 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`.", + ) def __init__(self, config=None, header=None, instructions=None): """Instantiate a QasmQobjExperiment. @@ -276,6 +293,14 @@ 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 `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, shots=None, @@ -410,6 +435,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 `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): """ Args: @@ -446,6 +479,14 @@ class QasmExperimentCalibrations: GateCalibrations. """ + @deprecate_func( + 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`.", + ) def __init__(self, gates): """ Initialize a container for calibrations. @@ -486,6 +527,14 @@ 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 `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): """ Initialize a single gate calibration. Instructions may reference waveforms which should be @@ -541,6 +590,14 @@ 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 `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 a689fc01e7e7..1e691d6324bf 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 `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.""" diff --git a/qiskit/result/models.py b/qiskit/result/models.py index 83d9e4e78d5f..93a1954ac7f4 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,10 @@ 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(): + # 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/qiskit/result/result.py b/qiskit/result/result.py index 7df365785166..4a5a928f06d5 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.filterwarnings("ignore", category=DeprecationWarning, module="qiskit") + in_data["header"] = QobjHeader.from_dict(in_data.pop("header")) return cls(**in_data) def data(self, experiment=None): diff --git a/releasenotes/notes/deprecate_assemble-67486b4d0a8d4f96.yaml b/releasenotes/notes/deprecate_assemble-67486b4d0a8d4f96.yaml new file mode 100644 index 000000000000..b7b50d2eb2b2 --- /dev/null +++ b/releasenotes/notes/deprecate_assemble-67486b4d0a8d4f96.yaml @@ -0,0 +1,7 @@ +--- +deprecations_providers: + - | + 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 `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`. 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/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 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_parameters.py b/test/python/circuit/test_parameters.py index f580416eccf5..4f989767164f 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,39 @@ 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.""" + # 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 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") 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") 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() 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) diff --git a/test/python/compiler/test_disassembler.py b/test/python/compiler/test_disassembler.py index e575c021adca..e5d0fd73a79c 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()) @@ -456,8 +477,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 +520,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 +541,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 +560,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) 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.""" diff --git a/test/python/providers/test_fake_backends.py b/test/python/providers/test_fake_backends.py index d5c5507b3b8e..1a1c55d1ee2d 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 @@ -142,7 +143,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 +228,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.filterwarnings("ignore", category=DeprecationWarning, module="qiskit") + result = job.result() counts = result.get_counts() max_count = max(counts.items(), key=operator.itemgetter(1))[0] self.assertEqual(max_count, "11") 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) 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() 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)) 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}) 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): diff --git a/test/python/transpiler/test_sabre_swap.py b/test/python/transpiler/test_sabre_swap.py index b1effdae7d8b..bf2ef5b1f9c4 100644 --- a/test/python/transpiler/test_sabre_swap.py +++ b/test/python/transpiler/test_sabre_swap.py @@ -15,6 +15,7 @@ import unittest import itertools + import ddt import numpy.random @@ -278,8 +279,7 @@ def test_no_infinite_loop(self, method): from qiskit_aer import Aer - with self.assertWarns(DeprecationWarning): - sim = Aer.get_backend("aer_simulator") + 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)) diff --git a/test/python/transpiler/test_star_prerouting.py b/test/python/transpiler/test_star_prerouting.py index ddc8096eefd7..e244d97a45aa 100644 --- a/test/python/transpiler/test_star_prerouting.py +++ b/test/python/transpiler/test_star_prerouting.py @@ -15,6 +15,7 @@ """Test the StarPreRouting pass""" import unittest + from test import QiskitTestCase import ddt diff --git a/test/utils/base.py b/test/utils/base.py index 0b02f3e58488..6d0c917ace30 100644 --- a/test/utils/base.py +++ b/test/utils/base.py @@ -123,12 +123,30 @@ 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_]+)*", ) + # 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.*", ]