Skip to content
Merged
39 changes: 39 additions & 0 deletions qiskit/providers/fake_provider/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# This code is part of Qiskit.
#
# (C) Copyright IBM 2022.
#
# This code is licensed under the Apache License, Version 2.0. You may
# obtain a copy of this license in the LICENSE.txt file in the root directory
# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0.
#
# Any modifications or derivative works of this code must retain this
# copyright notice, and modified files need to carry a notice indicating
# that they have been altered from the originals.

"""
Utilities for mocking the IBMQ provider, including job responses and backends.

The module includes dummy provider, backends, and jobs.
The purpose of these classes is to fake backends for testing purposes:
testing local timeouts, arbitrary responses or behavior, etc.

The mock devices are mainly for testing the compiler.
"""

from ...test.mock.fake_provider import FakeProvider, FakeLegacyProvider

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When things are far away, it's best to reference them by complete name (e.g. from qiskit.test.mock.fake_provider) for legibility.

from ...test.mock.fake_provider import FakeProviderFactory
from ...test.mock.fake_backend import FakeBackend, FakeLegacyBackend
from ...test.mock.fake_pulse_backend import FakePulseBackend, FakePulseLegacyBackend
from ...test.mock.fake_qasm_backend import FakeQasmBackend, FakeQasmLegacyBackend
from ...test.mock.utils.configurable_backend import ConfigurableFakeBackend
from ...test.mock.fake_backend_v2 import FakeBackendV2, FakeBackend5QV2
from ...test.mock.fake_mumbai_v2 import FakeMumbaiV2
from ...test.mock.fake_job import FakeJob, FakeLegacyJob
from ...test.mock.fake_qobj import FakeQobj

from ...test.mock.backends import *

from ...test.mock.fake_qasm_simulator import FakeQasmSimulator
from ...test.mock.fake_openpulse_2q import FakeOpenPulse2Q
from ...test.mock.fake_openpulse_3q import FakeOpenPulse3Q
from ...test.mock.fake_1q import Fake1Q
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---

features:
Comment thread
jakelishman marked this conversation as resolved.
Outdated
- |
Mock backends from `~qiskit.test.mock` are now accessible from `~qiskit.providers.fake_provider`.
The `~qiskit.test.mock` package will be deprecated soon.
36 changes: 36 additions & 0 deletions test/python/mock/test_new_qasm_backend.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# This code is part of Qiskit.
#
# (C) Copyright IBM 2021.
#
# This code is licensed under the Apache License, Version 2.0. You may
# obtain a copy of this license in the LICENSE.txt file in the root directory
# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0.
#
# Any modifications or derivative works of this code must retain this
# copyright notice, and modified files need to carry a notice indicating
# that they have been altered from the originals.

"""Test of qasm fake backends from qiskit.mock package."""
import unittest
from qiskit import QuantumCircuit, transpile
from qiskit.test import QiskitTestCase
from qiskit.providers.fake_provider import FakeBogota
from qiskit.utils.backend_utils import has_aer


class FakeQasmBackendsTest(QiskitTestCase):
"""Tests for FakeQasmBackend"""

@unittest.skipUnless(has_aer(), "qiskit-aer is required to run this test")
def test_fake_qasm_backend_configured(self):
"""Fake backends honor kwargs passed."""
backend = FakeBogota() # this is a FakePulseBackend implementation

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)
Comment thread
jakelishman marked this conversation as resolved.
13 changes: 13 additions & 0 deletions test/python/providers/fake_provider/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# This code is part of Qiskit.
#
# (C) Copyright IBM 2022.
#
# This code is licensed under the Apache License, Version 2.0. You may
# obtain a copy of this license in the LICENSE.txt file in the root directory
# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0.
#
# Any modifications or derivative works of this code must retain this
# copyright notice, and modified files need to carry a notice indicating
# that they have been altered from the originals.

"""Qiskit Fake Provider tests."""
49 changes: 49 additions & 0 deletions test/python/providers/fake_provider/test_new_pulse_backend.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# This code is part of Qiskit.
#
# (C) Copyright IBM 2021.
#
# This code is licensed under the Apache License, Version 2.0. You may
# obtain a copy of this license in the LICENSE.txt file in the root directory
# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0.
#
# Any modifications or derivative works of this code must retain this
# copyright notice, and modified files need to carry a notice indicating
# that they have been altered from the originals.

"""Test of pulse fake backends from qiskit.mock package."""
import unittest
from qiskit import QuantumCircuit, transpile
from qiskit.test import QiskitTestCase
from qiskit.providers.fake_provider import FakeAthens
from qiskit.utils.backend_utils import has_aer
from qiskit.providers.fake_provider import FakePulseBackend


class FakePulseBackendConfigError(FakePulseBackend):
"""Example backend not configured used for testing errors."""

props_filename = None


class FakePulseBackendsTest(QiskitTestCase):
"""Tests for FakePulseBackend"""

@unittest.skipUnless(has_aer(), "qiskit-aer is required to run this test")
def test_fake_pulse_backend_configured(self):
"""Fake backends honor kwargs passed."""
backend = FakeAthens() # this is a FakePulseBackend implementation

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)

@unittest.expectedFailure
def test_fake_pulse_backend_configuration_error(self):
"""Test configuration error for pulse backend."""
backend = FakePulseBackendConfigError()
backend.defaults()