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

Update FakeBackend to use BackendV2 #1102

Merged
merged 3 commits into from
Mar 27, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 18 additions & 22 deletions qiskit_experiments/test/fake_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,38 +12,34 @@

"""Fake backend class for tests."""
import uuid
from qiskit.providers.backend import BackendV1
from qiskit.providers.models import QasmBackendConfiguration
from qiskit.circuit.library import Measure
from qiskit.providers.backend import BackendV2
from qiskit.providers.options import Options
from qiskit.transpiler import Target

from qiskit.result import Result

from qiskit_experiments.framework import Options
from qiskit_experiments.test.utils import FakeJob


class FakeBackend(BackendV1):
class FakeBackend(BackendV2):
"""
Fake backend for test purposes only.
"""

def __init__(self, **config):
default_config = {
"backend_name": "fake_backend",
"backend_version": "0",
"n_qubits": int(1e6),
"basis_gates": [],
"gates": [],
"local": True,
"simulator": True,
"conditional": False,
"open_pulse": False,
"memory": False,
"max_shots": int(1e6),
"max_experiments": None,
"coupling_map": None,
}
default_config.update(**config)
super().__init__(QasmBackendConfiguration(**default_config))
target = None
Copy link
Collaborator

Choose a reason for hiding this comment

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

Overriding abstract property method in this way seems hacky. I prefer to define a protected member and return it through property method as long as the base class provides such mechanism.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I agree that is more proper. I copied this from MinimalBackend, so I updated both classes in this PR now. I think for MinimalBackend I had been thinking I wanted to do backend.target = Target() in tests to test out different Target configurations but that wasn't a good reason to deviate from it being a property.


def __init__(self, backend_name="fake_backend", num_qubits=1, max_experiments=100):
super().__init__(name=backend_name)
self.target = Target(num_qubits=num_qubits)
# Add a measure for each qubit so a simple measure circuit works
self.target.add_instruction(Measure())
self._max_circuits = max_experiments

@property
def max_circuits(self):
"""Maximum circuits to run at once"""
return self._max_circuits

@classmethod
def _default_options(cls):
Expand Down
2 changes: 1 addition & 1 deletion test/framework/test_composite.py
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ def circuits(self):
par_exp = ParallelExperiment(
[exp1, BatchExperiment([ParallelExperiment([exp2, exp3]), exp4])]
)
expdata = par_exp.run(Backend())
expdata = par_exp.run(Backend(num_qubits=4))
self.assertExperimentDone(expdata)

self.assertEqual(len(expdata.data()), len(counts))
Expand Down