Repository: Qiskit/qiskit

Issue:
Relocate mock backends from qiskit.test.mock to qiskit.mock or similar
<!-- ⚠️ If you do not respect this template, your issue will be closed -->
<!-- ⚠️ Make sure to browse the opened and closed issues to confirm this idea does not exist. -->

### What is the expected enhancement?

From https://github.com/Qiskit/qiskit-terra/pull/3890#issuecomment-591655403 : now that the fake backends are useful beyond testing, they should be moved somewhere more visible and  their usage should be documented.


Discussion:
# Update for Santa:elf:- QGoGP

✅  Fake backends are still in the test folder and may need a bit more verbose documentation! 

Will update comment/add more comments if cause is found/fixed!

> Python version 3.9.7
> qiskit-terra version: 0.19.1

May I work on this issue?
Yes, by all means, thanks!  I'll assign you.

When we move something like this, we need to do it in a couple of stages: in the next Terra release, we should make all the names accessible from `qiskit.mock` _and_ `qiskit.test.mock` (without any warnings), then we'll add the warnings in the release after that.  We're just in the process of updating the deprecation policy to say that, but it'll be good for this to be a trial run.
@jakelishman I see this warning: "The BaseBackend abstract interface is deprecated as of the 0.18.0 release and will be removed in a future release. Instead you should build your backends using the BackendV1 abstract class (which is the current latest version of the backend interface)". I will ignore the legacy backends in this move. Ok?
For this first step, it might be easiest if you don't actually move anything, but just make a new module called `qiskit.mock`, which imports all the names we want to move.  That will mean that all the names are accessible from two places, without us duplicating any code.  The advantage to this is that it's easier for us to maintain _all_ the locations that the objects are currently accessible from (e.g. you can access `FakeRome` from `qiskit.test.mock`, `qiskit.test.mock.backends` and `qiskit.test.mock.backends.rome` at the moment) during the swapover period.  In the new form, we generally just want people to access them directly as `from qiskit.mock import FakeRome` or so, so we don't need to duplicate all the structure right now.

After Terra 0.20 releases (which won't be for another three or so months) we can swap things over, then we can move where the objects are actually defined, and we'll issue a deprecation warning when using the old paths.

So, to answer the question fully: it probably _would_ be ok to ignore the legacy backends, but I think it's better at first just to create a pass-through `qiskit.mock` module, and that's easiest if you just import everything.  There's no real harm in importing the legacy mock backends - we'll be removing them from everywhere they are.
Oh. Thank you for the details. I will add the module with the imports, you are right... there is no need to duplicate 100 files...

Resolving patch:
diff --git a/qiskit/providers/fake_provider/__init__.py b/qiskit/providers/fake_provider/__init__.py
new file mode 100644
--- /dev/null
+++ b/qiskit/providers/fake_provider/__init__.py
@@ -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 qiskit.test.mock.fake_provider import FakeProvider, FakeLegacyProvider
+from qiskit.test.mock.fake_provider import FakeProviderFactory
+from qiskit.test.mock.fake_backend import FakeBackend, FakeLegacyBackend
+from qiskit.test.mock.fake_pulse_backend import FakePulseBackend, FakePulseLegacyBackend
+from qiskit.test.mock.fake_qasm_backend import FakeQasmBackend, FakeQasmLegacyBackend
+from qiskit.test.mock.utils.configurable_backend import ConfigurableFakeBackend
+from qiskit.test.mock.fake_backend_v2 import FakeBackendV2, FakeBackend5QV2
+from qiskit.test.mock.fake_mumbai_v2 import FakeMumbaiV2
+from qiskit.test.mock.fake_job import FakeJob, FakeLegacyJob
+from qiskit.test.mock.fake_qobj import FakeQobj
+
+from qiskit.test.mock.backends import *
+
+from qiskit.test.mock.fake_qasm_simulator import FakeQasmSimulator
+from qiskit.test.mock.fake_openpulse_2q import FakeOpenPulse2Q
+from qiskit.test.mock.fake_openpulse_3q import FakeOpenPulse3Q
+from qiskit.test.mock.fake_1q import Fake1Q


Test patch:
diff --git a/test/python/mock/test_new_qasm_backend.py b/test/python/mock/test_new_qasm_backend.py
new file mode 100644
--- /dev/null
+++ b/test/python/mock/test_new_qasm_backend.py
@@ -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 import optionals as _optionals
+
+
+class FakeQasmBackendsTest(QiskitTestCase):
+    """Tests for FakeQasmBackend"""
+
+    @unittest.skipUnless(_optionals.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)
diff --git a/test/python/providers/fake_provider/__init__.py b/test/python/providers/fake_provider/__init__.py
new file mode 100644
--- /dev/null
+++ b/test/python/providers/fake_provider/__init__.py
@@ -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."""
diff --git a/test/python/providers/fake_provider/test_new_pulse_backend.py b/test/python/providers/fake_provider/test_new_pulse_backend.py
new file mode 100644
--- /dev/null
+++ b/test/python/providers/fake_provider/test_new_pulse_backend.py
@@ -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 import optionals as _optionals
+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(_optionals.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()