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

Fix fake backend kwargs #6743

Merged
merged 12 commits into from
Jul 14, 2021
2 changes: 1 addition & 1 deletion qiskit/test/mock/fake_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def run(self, run_input, **kwargs):
from qiskit.providers.aer.noise import NoiseModel

noise_model = NoiseModel.from_backend(self, warnings=False)
job = sim.run(circuits, noise_model=noise_model)
job = sim.run(circuits, noise_model=noise_model, **kwargs)
else:
job = sim.run(circuits, **kwargs)
else:
Expand Down
11 changes: 11 additions & 0 deletions releasenotes/notes/fix-kwargs-mock-f581d5118a1c7589.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
fixes:
- |
Fixed an issue with the mock backends located in ``qiskit.test.mock`` where
in some situations (mainly fake backends with stored
:class:`~qiskit.providers.models.BackendProperties` running a
:class:`~qiskit.circuit.QuantumCircuit` with ``qiskit-aer`` installed)
passing run time options to the ``run()`` method of a fake backend object
would not actually be passed to the simulator underlying the ``run()``
method and not have any effect.
Fixed `#6741 <https://github.com/Qiskit/qiskit-terra/issues/6741>`__
19 changes: 19 additions & 0 deletions test/python/mock/test_fake_backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from qiskit.qobj import PulseQobj
from qiskit.test import QiskitTestCase
from qiskit.test.mock.utils import ConfigurableFakeBackend
from qiskit.test.mock import FakeAthens

from qiskit.test.mock.fake_backend import HAS_AER

Expand Down Expand Up @@ -64,3 +65,21 @@ def test_transpile_schedule_and_assemble(self):
result = job.result()
self.assertTrue(result.success)
self.assertEqual(len(result.results), 1)


class FakeBackendsTest(QiskitTestCase):
"""fake backends test."""

@unittest.skipUnless(HAS_AER, "qiskit-aer is required to run this test")
def test_fake_backends_get_kwargs(self):
"""Fake backends honor kwargs passed."""
backend = FakeAthens()

qc = QuantumCircuit(2)
qc.x(range(0, 2))
qc.measure_all()

trans_qc = transpile(qc, backend)
raw_counts = backend.run(trans_qc, shots=1000).result().get_counts()

self.assertEqual(sum(raw_counts.values()), 1000)