From 74661de856327425c07f5ba12c64436f29e46c39 Mon Sep 17 00:00:00 2001 From: R K Rupesh <33568503+rupeshknn@users.noreply.github.com> Date: Mon, 18 Dec 2023 21:13:31 +0530 Subject: [PATCH] add release note (#11395) --- .../providers/basicaer/unitary_simulator.py | 45 +++++++++---------- ...n-UnitarySimulatorPy-436c3a7c0dcc5eb6.yaml | 20 +++++++++ 2 files changed, 41 insertions(+), 24 deletions(-) create mode 100644 releasenotes/notes/remove-qobj-input-in-UnitarySimulatorPy-436c3a7c0dcc5eb6.yaml diff --git a/qiskit/providers/basicaer/unitary_simulator.py b/qiskit/providers/basicaer/unitary_simulator.py index 16b1f69f09ce..de25f6bd83b1 100644 --- a/qiskit/providers/basicaer/unitary_simulator.py +++ b/qiskit/providers/basicaer/unitary_simulator.py @@ -17,11 +17,11 @@ .. code-block:: python - UnitarySimulator().run(qobj) + UnitarySimulator().run(run_input) -Where the input is a Qobj object and the output is a BasicAerJob object, which can -later be queried for the Result object. The result will contain a 'unitary' -data field, which is a 2**n x 2**n complex numpy array representing the +Where the input is a either Qobj object (deprecated) or QuantumCircuit or a list of circuits and +the output is a BasicAerJob object, which can later be queried for the Result object. The result +will contain a 'unitary' data field, which is a 2**n x 2**n complex numpy array representing the circuit's unitary matrix. """ import logging @@ -32,7 +32,6 @@ import numpy as np -from qiskit.circuit.quantumcircuit import QuantumCircuit from qiskit.utils.multiprocessing import local_hardware_info from qiskit.providers.models import QasmBackendConfiguration from qiskit.providers.backend import BackendV1 @@ -203,11 +202,11 @@ def _get_unitary(self): unitary[abs(unitary) < self._chop_threshold] = 0.0 return unitary - def run(self, qobj, **backend_options): - """Run qobj asynchronously. + def run(self, run_input, **backend_options): + """Run experiments in run_input asynchronously. Args: - qobj (Qobj): payload of the experiment + run_input (Qobj, QuantumCircuit, list): payload of the experiment backend_options (dict): backend options Returns: @@ -222,7 +221,7 @@ def run(self, qobj, **backend_options): The "initial_unitary" option specifies a custom initial unitary matrix for the simulator to be used instead of the identity matrix. This size of this matrix must be correct for the number - of qubits inall experiments in the qobj. + of qubits in all experiments in the run_input. The "chop_threshold" option specifies a truncation value for setting small values to zero in the output unitary. The default @@ -238,21 +237,19 @@ def run(self, qobj, **backend_options): "chop_threshold": 1e-15 } """ - 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 = None + 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/releasenotes/notes/remove-qobj-input-in-UnitarySimulatorPy-436c3a7c0dcc5eb6.yaml b/releasenotes/notes/remove-qobj-input-in-UnitarySimulatorPy-436c3a7c0dcc5eb6.yaml new file mode 100644 index 000000000000..a323af6935e8 --- /dev/null +++ b/releasenotes/notes/remove-qobj-input-in-UnitarySimulatorPy-436c3a7c0dcc5eb6.yaml @@ -0,0 +1,20 @@ +--- + +upgrade: + - | + It is no longer allowed to pass a :class:`~qiskit.qobj.QasmQobj` as the first input to + The :meth:`~qiskit.providers.basicaer.UnitarySimulatorPy.run`. This functionality was + deprecated in Qiskit 0.46 and has now been removed. + + Example usage: + + from qiskit import transpile, QuantumCircuit + from qiskit.providers.basicaer import BasicAer + + backend = BasicAer.get_backend('unitary_simulator') + circuit = QuantumCircuit(2) + qc.h(0) + qc.cx(0, 1) + qc.measure_all() + tqc = transpile(circuit, backend) + result = backend.run(tqc).result()