-
Notifications
You must be signed in to change notification settings - Fork 3k
Relocate mock backends from qiskit.test.mock to qiskit.mock #7437
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
Merged
Merged
Changes from 5 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
64fe0f1
Relocate mock backends from qiskit.test.mock to qiskit.mock
iuliazidaru 6b3b91a
Relocate mock backends from qiskit.test.mock to qiskit.mock
iuliazidaru f5052b0
fix: Inline literal start-string without end-string
iuliazidaru 22eb8ca
change package to qiskit.providers.fake_provider
iuliazidaru 4cf03a7
fix test failure
iuliazidaru 8b23497
reformat file
iuliazidaru a071db7
Merge branch 'main' into issue3905
iuliazidaru 2631a36
fix review comments
iuliazidaru a3c0e94
Merge branch 'main' into issue3905
iuliazidaru afc7673
Merge branch 'main' into issue3905
iuliazidaru 82b7725
Release note is API change not feature
jakelishman 03f3a59
Merge branch 'main' into issue3905
jakelishman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| 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 | ||
6 changes: 6 additions & 0 deletions
6
releasenotes/notes/access-backends-from-mock-d3897ecb8490219a.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| --- | ||
|
|
||
| features: | ||
|
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. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) | ||
|
jakelishman marked this conversation as resolved.
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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
49
test/python/providers/fake_provider/test_new_pulse_backend.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.