-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Add tests executing a circuit on each fake backend #4018
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 all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
57da6c3
Add tests executing a circuit on each fake backend
mtreinish 32adc56
Add qiskit-aer to ci jobs
mtreinish 12a5c03
Merge branch 'master' into add-fake-backend-tests
mtreinish bff8b2b
Reduce error rates on fake_openpulse_2q backend
mtreinish 13fbc4f
Handle simulators properly for fake backends
mtreinish bcd8a6e
Adjust tests to use fake provider
mtreinish 3dfb7a4
Change fake_qasm_simulator basis to basic aer's
mtreinish a10f50a
Cleanup arg name for test
mtreinish 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
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
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
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
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,61 @@ | ||
| # -*- coding: utf-8 -*- | ||
|
|
||
| # This code is part of Qiskit. | ||
| # | ||
| # (C) Copyright IBM 2020. | ||
| # | ||
| # 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. | ||
|
|
||
| # pylint: disable=missing-class-docstring,missing-function-docstring | ||
| # pylint: disable=missing-module-docstring | ||
|
|
||
| import operator | ||
|
|
||
| from test import combine | ||
| from ddt import ddt | ||
|
|
||
| from qiskit.circuit import QuantumCircuit | ||
| from qiskit.execute import execute | ||
| from qiskit.test.base import QiskitTestCase | ||
| from qiskit.test.mock import FakeProvider | ||
| from qiskit.test.mock.fake_backend import HAS_AER | ||
|
|
||
|
|
||
| FAKE_PROVIDER = FakeProvider() | ||
|
|
||
|
|
||
| @ddt | ||
| class TestFakeBackends(QiskitTestCase): | ||
|
|
||
| @classmethod | ||
| def setUpClass(cls): | ||
| super().setUpClass() | ||
| cls.circuit = QuantumCircuit(2) | ||
| cls.circuit.h(0) | ||
| cls.circuit.h(1) | ||
| cls.circuit.h(0) | ||
| cls.circuit.h(1) | ||
| cls.circuit.x(0) | ||
| cls.circuit.x(1) | ||
| cls.circuit.measure_all() | ||
|
|
||
| @combine(backend=FAKE_PROVIDER.backends(), | ||
| optimization_level=[0, 1, 2, 3]) | ||
| def test_circuit_on_fake_backend(self, backend, optimization_level): | ||
| if not HAS_AER and backend.configuration().n_qubits > 20: | ||
| self.skipTest( | ||
| 'Unable to run fake_backend %s without qiskit-aer' % | ||
| backend.configuration().backend_name) | ||
| job = execute(self.circuit, backend, | ||
| optimization_level=optimization_level, | ||
| seed_simulator=42, seed_transpiler=42) | ||
| result = job.result() | ||
| counts = result.get_counts() | ||
| max_count = max(counts.items(), key=operator.itemgetter(1))[0] | ||
| self.assertEqual(max_count, '11') | ||
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.
It's a bit unfortunate that we need to use (and install) Aer for these tests (though I understand why its necessary). Maybe it makes sense to update the BasicAer n_qubits check to be number of used qubits.
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.
Yeah, I wasn't happy with adding aer to the testing. But to do this well it was needed.
The issue with adjusting basicaer to avoid this is that it's looking at the transpiled qobj to determine the number of qubits required: https://github.com/Qiskit/qiskit-terra/blob/master/qiskit/providers/basicaer/qasm_simulator.py#L622. With the fake backends (and specifically in this case for FakeRochester), the physical circuit will have an ancilla with no operations set for all the unused qubits since it's pulling that from the fake backend. To workaround this we'd have to disassemble the qobj and determine that 51 qubits are idle. It's not too much work, but definitely outside the scope of this PR.