Skip to content

Commit

Permalink
Deprecate Qobj input to UnitarySimulatorPy.run (#11394)
Browse files Browse the repository at this point in the history
* deprecate qobj input in UnitarySimulatorPy

* add release note

* lint fix

* remove newline in deprecation

* fix predicate bug

* remove fixes section of reno

Co-authored-by: Elena Peña Tapia <[email protected]>

---------

Co-authored-by: Elena Peña Tapia <[email protected]>
  • Loading branch information
rupeshknn and ElePT authored Dec 18, 2023
1 parent 4c073de commit 3d69927
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
29 changes: 19 additions & 10 deletions qiskit/providers/basicaer/unitary_simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -39,6 +39,7 @@
from qiskit.providers.options import Options
from qiskit.providers.basicaer.basicaerjob import BasicAerJob
from qiskit.result import Result
from qiskit.utils.deprecation import deprecate_arg
from .exceptions import BasicAerError
from .basicaertools import single_gate_matrix
from .basicaertools import SINGLE_QUBIT_GATES
Expand Down Expand Up @@ -203,11 +204,18 @@ def _get_unitary(self):
unitary[abs(unitary) < self._chop_threshold] = 0.0
return unitary

def run(self, qobj, **backend_options):
"""Run qobj asynchronously.
@deprecate_arg(
"run_input",
deprecation_description="Using a QasmQobj for the first argument to UnitarySimulatorPy.run()",
since="0.46.0",
pending=False,
predicate=lambda run_input: not isinstance(run_input, (QuantumCircuit, list)),
)
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:
Expand All @@ -222,7 +230,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
Expand All @@ -238,7 +246,7 @@ def run(self, qobj, **backend_options):
"chop_threshold": 1e-15
}
"""
if isinstance(qobj, (QuantumCircuit, list)):
if isinstance(run_input, (QuantumCircuit, list)):
from qiskit.compiler import assemble

out_options = {}
Expand All @@ -249,9 +257,10 @@ def run(self, qobj, **backend_options):
)
else:
out_options[key] = backend_options[key]
qobj = assemble(qobj, self, **out_options)
qobj = assemble(run_input, self, **out_options)
qobj_options = qobj.config
else:
qobj = run_input
qobj_options = None
self._set_options(qobj_config=qobj_options, backend_options=backend_options)
job_id = str(uuid.uuid4())
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
deprecations:
- |
:class:`~qiskit.qobj.QasmQobj` input to :meth:`~qiskit.providers.basicaer.UnitarySimulatorPy.run`
is now deprecated and will be removed in the next major release.

0 comments on commit 3d69927

Please sign in to comment.