diff --git a/qiskit/providers/basicaer/qasm_simulator.py b/qiskit/providers/basicaer/qasm_simulator.py index a48112f5c144..97b3d3eb8f3d 100644 --- a/qiskit/providers/basicaer/qasm_simulator.py +++ b/qiskit/providers/basicaer/qasm_simulator.py @@ -19,9 +19,9 @@ .. code-block:: python - QasmSimulatorPy().run(qobj) + QasmSimulatorPy().run(run_input) -Where the input is a Qobj object and the output is a BasicAerJob object, which can +Where the input is a QuantumCircuit object and the output is a BasicAerJob object, which can later be queried for the Result object. The result will contain a 'memory' data field, which is a result of measurements for each shot. """ @@ -35,8 +35,6 @@ from collections import Counter import numpy as np -from qiskit.circuit.quantumcircuit import QuantumCircuit -from qiskit.utils.deprecation import deprecate_arg from qiskit.utils.multiprocessing import local_hardware_info from qiskit.providers.models import QasmBackendConfiguration from qiskit.result import Result @@ -387,18 +385,11 @@ def _validate_measure_sampling(self, experiment): # measure sampling is allowed self._sample_measure = True - @deprecate_arg( - "qobj", - deprecation_description="Using a qobj for the first argument to QasmSimulatorPy.run()", - since="0.22.0", - pending=True, - predicate=lambda qobj: not isinstance(qobj, (QuantumCircuit, list)), - ) - def run(self, qobj, **backend_options): - """Run qobj asynchronously. + def run(self, run_input, **backend_options): + """Run on the backend. Args: - qobj (Qobj): payload of the experiment + run_input (QuantumCircuit or list): payload of the experiment backend_options (dict): backend options Returns: @@ -411,7 +402,7 @@ def run(self, qobj, **backend_options): The "initial_statevector" option specifies a custom initial initial statevector for the simulator to be used instead of the all zero state. This size of this vector must be correct for the number - of qubits in all experiments in the qobj. + of qubits in ``run_input`` parameter. Example:: @@ -419,21 +410,18 @@ def run(self, qobj, **backend_options): "initial_statevector": np.array([1, 0, 0, 1j]) / np.sqrt(2), } """ - if isinstance(qobj, (QuantumCircuit, list)): - from qiskit.compiler import assemble - - out_options = {} - for key in backend_options: - if not hasattr(self.options, key): - warnings.warn( - "Option %s is not used by this backend" % key, UserWarning, stacklevel=2 - ) - else: - out_options[key] = backend_options[key] - qobj = assemble(qobj, self, **out_options) - qobj_options = qobj.config - else: - qobj_options = qobj.config + from qiskit.compiler import assemble + + out_options = {} + for key in backend_options: + if not hasattr(self.options, key): + warnings.warn( + "Option %s is not used by this backend" % key, UserWarning, stacklevel=2 + ) + else: + out_options[key] = backend_options[key] + 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()) job = BasicAerJob(self, job_id, self._run_job(job_id, qobj)) diff --git a/qiskit/transpiler/passes/calibration/rzx_builder.py b/qiskit/transpiler/passes/calibration/rzx_builder.py index 4ad964758429..36bbe5b365b7 100644 --- a/qiskit/transpiler/passes/calibration/rzx_builder.py +++ b/qiskit/transpiler/passes/calibration/rzx_builder.py @@ -35,7 +35,6 @@ from qiskit.pulse.filters import filter_instructions from qiskit.pulse.instruction_schedule_map import InstructionScheduleMap from qiskit.transpiler.target import Target -from qiskit.utils.deprecation import deprecate_arg from .base_builder import CalibrationBuilder from .exceptions import CalibrationNotAvailable @@ -65,11 +64,9 @@ class RZXCalibrationBuilder(CalibrationBuilder): angle. Additional details can be found in https://arxiv.org/abs/2012.11660. """ - @deprecate_arg("qubit_channel_mapping", since="0.22.0") def __init__( self, instruction_schedule_map: InstructionScheduleMap = None, - qubit_channel_mapping: list[list[str]] = None, verbose: bool = True, target: Target = None, ): @@ -79,8 +76,6 @@ def __init__( Args: instruction_schedule_map: The :obj:`InstructionScheduleMap` object representing the default pulse calibrations for the target backend - qubit_channel_mapping: The list mapping qubit indices to the list of - channel names that apply on that qubit. verbose: Set True to raise a user warning when RZX schedule cannot be built. target: The :class:`~.Target` representing the target backend, if both ``instruction_schedule_map`` and this are specified then this argument will take @@ -89,7 +84,6 @@ def __init__( Raises: QiskitError: Instruction schedule map is not provided. """ - del qubit_channel_mapping super().__init__() self._inst_map = instruction_schedule_map self._verbose = verbose diff --git a/releasenotes/notes/remove-deprecated-code-in-0.22.0-139fa09ee0cc6df9.yaml b/releasenotes/notes/remove-deprecated-code-in-0.22.0-139fa09ee0cc6df9.yaml new file mode 100644 index 000000000000..25869ed728b8 --- /dev/null +++ b/releasenotes/notes/remove-deprecated-code-in-0.22.0-139fa09ee0cc6df9.yaml @@ -0,0 +1,30 @@ +upgrade: + - | + Removed the argument `qubit_channel_mapping` in :class:`qiskit.transpiler.passes.calibration.rzx_builder.RZXCalibrationBuilder`, + which was deprecated in Qiskit 0.39 (released on Oct 2022, with qiskit-terra 0.22) + - | + Replaced the argument ``qobj[Qobj]`` in :meth:`qiskit.providers.aer.QasmSimulator.run()` with ``run_input[QuantumCircuit or Schedule or list]`` + + Here is an example to migrate yor code:: + + # Importing necessary Qiskit libraries + from qiskit import transpile, QuantumCircuit + from qiskit.aer import QasmSimulator + + # Defining the Quantum Circuit + qc = QuantumCircuit(2) + qc.h(0) + qc.cx(0, 1) + qc.measure_all() + + # Transpile the circuit to optimize for the target simulator + simulator = QasmSimulator() + transpiled_circuit = transpile(qc, simulator) + # Run the simulation + job = simulator.run(transpiled_circuit, shots=1024) + # Get the simulation result + result = job.result() + + + + All these were deprecated since 0.22 (released on October 13, 2022) and now they are removed. diff --git a/test/python/basicaer/test_basicaer_qobj_headers.py b/test/python/basicaer/test_basicaer_qobj_headers.py deleted file mode 100644 index 6d72193bef08..000000000000 --- a/test/python/basicaer/test_basicaer_qobj_headers.py +++ /dev/null @@ -1,67 +0,0 @@ -# This code is part of Qiskit. -# -# (C) Copyright IBM 2017, 2018. -# -# This code is licensed under the Apache License, Version 2.0. You may -# obtain a copy of this license in the LICENSE.txt file in the root directory -# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0. -# -# Any modifications or derivative works of this code must retain this -# copyright notice, and modified files need to carry a notice indicating -# that they have been altered from the originals. - -"""Tests for all BasicAer simulators.""" - -import io -from logging import StreamHandler, getLogger -import sys - -from qiskit import BasicAer -from qiskit import ClassicalRegister, QuantumCircuit, QuantumRegister -from qiskit.compiler import transpile -from qiskit.compiler import assemble -from qiskit.qobj import QobjHeader -from qiskit.test import QiskitTestCase - - -class StreamHandlerRaiseException(StreamHandler): - """Handler class that will raise an exception on formatting errors.""" - - def handleError(self, record): - raise sys.exc_info() - - -class TestBasicAerQobj(QiskitTestCase): - """Tests for all the Terra simulators.""" - - def setUp(self): - super().setUp() - logger = getLogger() - self.addCleanup(logger.setLevel, logger.level) - logger.setLevel("DEBUG") - - self.output = io.StringIO() - logger.addHandler(StreamHandlerRaiseException(self.output)) - - qr = QuantumRegister(1) - cr = ClassicalRegister(1) - self.qc1 = QuantumCircuit(qr, cr, name="circuit0") - self.qc1.h(qr[0]) - - def test_qobj_headers_in_result(self): - """Test that the qobj headers are passed onto the results.""" - custom_qobj_header = {"x": 1, "y": [1, 2, 3], "z": {"a": 4}} - - for backend in BasicAer.backends(): - with self.subTest(backend=backend): - new_circ = transpile(self.qc1, backend=backend) - qobj = assemble(new_circ, shots=1024) - - # Update the Qobj header. - qobj.header = QobjHeader.from_dict(custom_qobj_header) - # Update the Qobj.experiment header. - qobj.experiments[0].header.some_field = "extra info" - - result = backend.run(qobj).result() - self.assertEqual(result.header.to_dict(), custom_qobj_header) - self.assertEqual(result.results[0].header.some_field, "extra info") diff --git a/test/python/basicaer/test_qasm_simulator.py b/test/python/basicaer/test_qasm_simulator.py index 52941e210306..90bb10149943 100644 --- a/test/python/basicaer/test_qasm_simulator.py +++ b/test/python/basicaer/test_qasm_simulator.py @@ -45,10 +45,10 @@ def setUp(self): self.seed = 88 qasm_dir = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "qasm") qasm_filename = os.path.join(qasm_dir, "example.qasm") - transpiled_circuit = QuantumCircuit.from_qasm_file(qasm_filename) - transpiled_circuit.name = "test" - transpiled_circuit = transpile(transpiled_circuit, backend=self.backend) - self.qobj = assemble(transpiled_circuit, shots=1000, seed_simulator=self.seed) + 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) logger = getLogger() self.addCleanup(logger.setLevel, logger.level) logger.setLevel("DEBUG") @@ -75,8 +75,9 @@ def test_submission_log_time(self): def test_qasm_simulator_single_shot(self): """Test single shot run.""" shots = 1 - self.qobj.config.shots = shots - result = self.backend.run(self.qobj).result() + result = self.backend.run( + self.transpiled_circuit, shots=shots, seed_simulator=self.seed + ).result() self.assertEqual(result.success, True) def test_measure_sampler_repeated_qubits(self): @@ -152,7 +153,9 @@ def test_measure_sampler_partial_qubit(self): def test_qasm_simulator(self): """Test data counts output for single circuit run against reference.""" - result = self.backend.run(self.qobj).result() + result = self.backend.run( + self.transpiled_circuit, shots=1000, seed_simulator=self.seed + ).result() shots = 1024 threshold = 0.04 * shots counts = result.get_counts("test") diff --git a/test/python/compiler/test_compiler.py b/test/python/compiler/test_compiler.py index ce7b9d44f402..910d1e5866fe 100644 --- a/test/python/compiler/test_compiler.py +++ b/test/python/compiler/test_compiler.py @@ -62,12 +62,10 @@ def test_example_multiple_compile(self): bell.measure(qr[0], cr[0]) bell.measure(qr[1], cr[1]) shots = 2048 - bell_backend = transpile(bell, backend=backend) - ghz_backend = transpile(ghz, backend=backend, coupling_map=coupling_map) - bell_qobj = assemble(bell_backend, shots=shots, seed_simulator=10) - ghz_qobj = assemble(ghz_backend, shots=shots, seed_simulator=10) - bell_result = backend.run(bell_qobj).result() - ghz_result = backend.run(ghz_qobj).result() + bell_qcirc = transpile(bell, backend=backend) + ghz_qcirc = transpile(ghz, backend=backend, coupling_map=coupling_map) + bell_result = backend.run(bell_qcirc, shots=shots, seed_simulator=10).result() + ghz_result = backend.run(ghz_qcirc, shots=shots, seed_simulator=10).result() threshold = 0.05 * shots counts_bell = bell_result.get_counts() @@ -100,8 +98,7 @@ def test_compile_coupling_map(self): qc_b = transpile( qc, backend=backend, coupling_map=coupling_map, initial_layout=initial_layout ) - qobj = assemble(qc_b, shots=shots, seed_simulator=88) - job = backend.run(qobj) + job = backend.run(qc_b, shots=shots, seed_simulator=88) result = job.result() qasm_to_check = qc.qasm() self.assertEqual(len(qasm_to_check), 173) @@ -260,10 +257,10 @@ def test_compile_pass_manager(self): qc.barrier(qr) qc.measure(qr, cr) backend = BasicAer.get_backend("qasm_simulator") - qrtrue = assemble(transpile(qc, backend, seed_transpiler=8), seed_simulator=42) - rtrue = backend.run(qrtrue).result() - qrfalse = assemble(PassManager().run(qc), seed_simulator=42) - rfalse = backend.run(qrfalse).result() + qrtrue = transpile(qc, backend, seed_transpiler=8) + rtrue = backend.run(qrtrue, seed_simulator=42).result() + qrfalse = PassManager().run(qc) + rfalse = backend.run(qrfalse, seed_simulator=42).result() self.assertEqual(rtrue.get_counts(), rfalse.get_counts()) def test_mapper_overoptimization(self):