Skip to content

Commit

Permalink
fix fail of qobj run without run_options (Qiskit#1792)
Browse files Browse the repository at this point in the history
* fix fail of qobj run without run_options

* fix lint error

---------

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
hhorii and mergify[bot] committed Jun 7, 2023
1 parent b23d0d2 commit fc5c11b
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 3 deletions.
4 changes: 2 additions & 2 deletions qiskit_aer/backends/aerbackend.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,8 @@ def run(self, circuits, validate=False, parameter_binds=None, **run_options):
for key, value in circuits.config.__dict__.items():
if key not in run_options and value is not None:
run_options[key] = value
if "parameter_binds" in run_options:
parameter_binds = run_options.pop("parameter_binds")
if "parameter_binds" in run_options:
parameter_binds = run_options.pop("parameter_binds")
return self._run_qobj(circuits, validate, parameter_binds, **run_options)

only_circuits = True
Expand Down
6 changes: 6 additions & 0 deletions releasenotes/notes/fix_qobj_run-8ea657a93ce9acd2.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
fixes:
- |
Aer still supports Qobj as an argument of :meth:`~.AerSimulator.run` though
it was deprecated. However, since 0.12.0, it always fails if no ``run_options``
is specified. This fix enables simulation of Qobj without ``run_options``.
25 changes: 24 additions & 1 deletion test/terra/backends/aer_simulator/test_circuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from math import sqrt
from ddt import ddt
import numpy as np
from qiskit import ClassicalRegister, QuantumCircuit, QuantumRegister
from qiskit import ClassicalRegister, QuantumCircuit, QuantumRegister, assemble
from qiskit.circuit import CircuitInstruction
from test.terra.reference import ref_algorithms

Expand Down Expand Up @@ -173,6 +173,29 @@ def test_partial_result_a_single_invalid_circuit(self):
self.assertTrue(hasattr(result.results[1].data, "counts"))
self.assertFalse(hasattr(result.results[0].data, "counts"))

def test_run_qobj(self):
"""Test qobj run"""

qubits = QuantumRegister(3)
clbits = ClassicalRegister(3)

circuit = QuantumCircuit(qubits, clbits)
circuit.h(qubits[0])
circuit.cx(qubits[0], qubits[1])
circuit.cx(qubits[0], qubits[2])

for q, c in zip(qubits, clbits):
circuit.measure(q, c)

backend = self.backend()

shots = 1000
with self.assertWarns(DeprecationWarning):
result = backend.run(assemble(circuit), shots=shots).result()

self.assertSuccess(result)
self.compare_counts(result, [circuit], [{"0x0": 500, "0x7": 500}], delta=0.05 * shots)

def test_numpy_integer_shots(self):
"""Test implicit cast of shot option from np.int_ to int."""

Expand Down

0 comments on commit fc5c11b

Please sign in to comment.