Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed code deprecated in 0.22 [transpiler and providers] #10872

Merged
merged 14 commits into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 18 additions & 30 deletions qiskit/providers/basicaer/qasm_simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
"""
Expand All @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -411,29 +402,26 @@ 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::

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))
Expand Down
6 changes: 0 additions & 6 deletions qiskit/transpiler/passes/calibration/rzx_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
):
Expand All @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
67 changes: 0 additions & 67 deletions test/python/basicaer/test_basicaer_qobj_headers.py

This file was deleted.

17 changes: 10 additions & 7 deletions test/python/basicaer/test_qasm_simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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):
Expand Down Expand Up @@ -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")
Expand Down
21 changes: 9 additions & 12 deletions test/python/compiler/test_compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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):
Expand Down