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

[WIP] Replace old fake v2 backends with new fake v2 backends #7967

Closed
wants to merge 11 commits into from
1 change: 0 additions & 1 deletion qiskit/providers/fake_provider/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
from qiskit.test.mock.fake_pulse_backend import FakePulseBackend
from qiskit.test.mock.fake_qasm_backend import FakeQasmBackend
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 FakeMumbaiFractionalCX
from qiskit.test.mock.fake_job import FakeJob
from qiskit.test.mock.fake_qobj import FakeQobj
Expand Down
1 change: 0 additions & 1 deletion qiskit/test/mock/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
from .fake_provider import FakeProviderForBackendV2, FakeProvider
from .fake_provider import FakeProviderFactory
from .fake_backend import FakeBackend
from .fake_backend_v2 import FakeBackendV2, FakeBackend5QV2
from .fake_mumbai_v2 import FakeMumbaiFractionalCX
from .fake_job import FakeJob
from .fake_qobj import FakeQobj
Expand Down
109 changes: 0 additions & 109 deletions qiskit/test/mock/fake_backend_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,112 +107,3 @@ def qubit_properties(self, qubit):
if isinstance(qubit, int):
return self._qubit_properties[qubit]
return [self._qubit_properties[i] for i in qubit]


class FakeBackend5QV2(BackendV2):
"""A mock backend that doesn't implement run() to test compatibility with Terra internals."""

def __init__(self, bidirectional=True):
super().__init__(
None,
name="Fake5QV2",
description="A fake BackendV2 example",
online_date=datetime.datetime.utcnow(),
backend_version="0.0.1",
)
qubit_properties = [
QubitProperties(t1=63.48783e-6, t2=112.23246e-6, frequency=5.17538e9),
QubitProperties(t1=73.09352e-6, t2=126.83382e-6, frequency=5.26722e9),
QubitProperties(t1=73.09352e-6, t2=126.83382e-6, frequency=5.26722e9),
QubitProperties(t1=73.09352e-6, t2=126.83382e-6, frequency=5.26722e9),
QubitProperties(t1=73.09352e-6, t2=126.83382e-6, frequency=5.26722e9),
]
self._target = Target(qubit_properties=qubit_properties)
self._theta = Parameter("theta")
self._phi = Parameter("phi")
self._lam = Parameter("lambda")
u_props = {
(0,): InstructionProperties(duration=5.23e-8, error=0.00038115),
(1,): InstructionProperties(duration=4.52e-8, error=0.00032115),
(2,): InstructionProperties(duration=5.23e-8, error=0.00038115),
(3,): InstructionProperties(duration=4.52e-8, error=0.00032115),
(4,): InstructionProperties(duration=4.52e-8, error=0.00032115),
}
self._target.add_instruction(UGate(self._theta, self._phi, self._lam), u_props)
cx_props = {
(0, 1): InstructionProperties(duration=5.23e-7, error=0.00098115),
(3, 4): InstructionProperties(duration=5.23e-7, error=0.00098115),
}
if bidirectional:
cx_props[(1, 0)] = InstructionProperties(duration=6.23e-7, error=0.00099115)
cx_props[(4, 3)] = InstructionProperties(duration=7.23e-7, error=0.00099115)
self._target.add_instruction(CXGate(), cx_props)
measure_props = {
(0,): InstructionProperties(duration=6e-6, error=5e-6),
(1,): InstructionProperties(duration=1e-6, error=9e-6),
(2,): InstructionProperties(duration=6e-6, error=5e-6),
(3,): InstructionProperties(duration=1e-6, error=9e-6),
(4,): InstructionProperties(duration=1e-6, error=9e-6),
}
self._target.add_instruction(Measure(), measure_props)
ecr_props = {
(1, 2): InstructionProperties(duration=4.52e-9, error=0.0000132115),
(2, 3): InstructionProperties(duration=4.52e-9, error=0.0000132115),
}
if bidirectional:
ecr_props[(2, 1)] = InstructionProperties(duration=5.52e-9, error=0.0000232115)
ecr_props[(3, 2)] = InstructionProperties(duration=5.52e-9, error=0.0000232115)
self._target.add_instruction(ECRGate(), ecr_props)
self.options.set_validator("shots", (1, 4096))

@property
def target(self):
return self._target

@property
def max_circuits(self):
return None

@classmethod
def _default_options(cls):
return Options(shots=1024)

def run(self, run_input, **options):
raise NotImplementedError


class FakeBackendSimple(BackendV2):
"""A fake simple backend that wraps BasicAer to implement run()."""

def __init__(self):
super().__init__(
None,
name="FakeSimpleV2",
description="A fake simple BackendV2 example",
online_date=datetime.datetime.utcnow(),
backend_version="0.0.1",
)
self._lam = Parameter("lambda")
self._target = Target(num_qubits=20)
self._target.add_instruction(SXGate())
self._target.add_instruction(XGate())
self._target.add_instruction(RZGate(self._lam))
self._target.add_instruction(CXGate())
self._target.add_instruction(Measure())
self._runner = QasmSimulatorPy()

@property
def target(self):
return self._target

@property
def max_circuits(self):
return None

@classmethod
def _default_options(cls):
return QasmSimulatorPy._default_options()

def run(self, run_input, **options):
self._runner._options = self._options
return self._runner.run(run_input, **options)
4 changes: 2 additions & 2 deletions test/python/algorithms/test_backendv2.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
""" Test Providers that support BackendV2 interface """

import unittest
from qiskit.test.mock.backends.manila.fake_manila import FakeManilaV2
from test.python.algorithms import QiskitAlgorithmsTestCase
from qiskit import QuantumCircuit
from qiskit.test.mock import FakeProvider
from qiskit.test.mock.fake_backend_v2 import FakeBackendSimple
from qiskit.utils import QuantumInstance
from qiskit.algorithms import Shor, VQE, Grover, AmplificationProblem
from qiskit.opflow import X, Z, I
Expand All @@ -30,7 +30,7 @@ class TestBackendV2(QiskitAlgorithmsTestCase):
def setUp(self):
super().setUp()
self._provider = FakeProvider()
self._qasm = FakeBackendSimple()
self._qasm = FakeManilaV2()
self.seed = 50

def test_shor_factoring(self):
Expand Down
10 changes: 4 additions & 6 deletions test/python/providers/test_backend_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,8 @@
from qiskit.compiler.transpiler import _parse_inst_map
from qiskit.pulse.instruction_schedule_map import InstructionScheduleMap
from qiskit.test.base import QiskitTestCase
from qiskit.providers.fake_provider import FakeManilaV2
from qiskit.test.mock.fake_backend_v2 import (
FakeBackendV2,
FakeBackend5QV2,
FakeBackendSimple,
FakeBackendV2LegacyQubitProps,
)
from qiskit.test.mock.fake_mumbai_v2 import FakeMumbaiFractionalCX
Expand All @@ -38,7 +36,7 @@
class TestBackendV2(QiskitTestCase):
def setUp(self):
super().setUp()
self.backend = FakeBackendV2()
self.backend = FakeManilaV2()

def assertMatchesTargetConstraints(self, tqc, target):
qubit_indices = {qubit: index for index, qubit in enumerate(tqc.qubits)}
Expand Down Expand Up @@ -68,7 +66,7 @@ def test_legacy_qubit_properties(self):
def test_no_qubit_properties_raises(self):
"""Ensure that if no qubit properties are defined we raise correctly."""
with self.assertRaises(NotImplementedError):
FakeBackendSimple().qubit_properties(0)
FakeManilaV2().qubit_properties(0)

def test_option_bounds(self):
"""Test that option bounds are enforced."""
Expand Down Expand Up @@ -110,7 +108,7 @@ def test_transpile(self, opt_level):
name="{gate}_level_{opt_level}_bidirectional_{bidirectional}",
)
def test_5q_ghz(self, opt_level, gate, bidirectional):
backend = FakeBackend5QV2(bidirectional)
backend = FakeManilaV2(bidirectional)
qc = QuantumCircuit(5)
qc.h(0)
getattr(qc, gate)(0, 1)
Expand Down
12 changes: 6 additions & 6 deletions test/python/transpiler/test_gates_in_basis_pass.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
from qiskit.circuit.library import HGate, CXGate, UGate
from qiskit.circuit.measure import Measure
from qiskit.circuit.equivalence_library import SessionEquivalenceLibrary
from qiskit.test.mock.backends.manila.fake_manila import FakeManilaV2
from qiskit.transpiler import PassManager
from qiskit.transpiler.passes import BasisTranslator
from qiskit.transpiler.passes import GatesInBasis
from qiskit.transpiler.target import Target
from qiskit.test import QiskitTestCase
from qiskit.test.mock.fake_backend_v2 import FakeBackend5QV2


class TestGatesInBasisPass(QiskitTestCase):
Expand Down Expand Up @@ -95,7 +95,7 @@ def test_all_gates_in_basis_after_translation(self):

def test_all_gates_in_basis_with_target(self):
"""Test circuit with all gates in basis with target."""
target = FakeBackend5QV2().target
target = FakeManilaV2().target
basis_gates = ["cx", "u"] # not used
property_set = {}
analysis_pass = GatesInBasis(basis_gates, target=target)
Expand All @@ -108,7 +108,7 @@ def test_all_gates_in_basis_with_target(self):

def test_all_gates_not_in_basis_with_target(self):
"""Test circuit with not all gates in basis with target."""
target = FakeBackend5QV2().target
target = FakeManilaV2().target
basis_gates = ["cx", "h"]
property_set = {}
analysis_pass = GatesInBasis(basis_gates, target=target)
Expand All @@ -121,7 +121,7 @@ def test_all_gates_not_in_basis_with_target(self):

def test_all_gates_in_basis_not_on_all_qubits_with_target(self):
"""Test circuit with gate in global basis but not local basis."""
target = FakeBackend5QV2().target
target = FakeManilaV2().target
basis_gates = ["ecr", "cx", "h"]
property_set = {}
analysis_pass = GatesInBasis(basis_gates, target=target)
Expand All @@ -134,7 +134,7 @@ def test_all_gates_in_basis_not_on_all_qubits_with_target(self):

def test_all_gates_in_basis_empty_circuit_with_target(self):
"""Test circuit with no gates with target."""
target = FakeBackend5QV2().target
target = FakeManilaV2().target
basis_gates = ["cx", "u"]
property_set = {}
analysis_pass = GatesInBasis(basis_gates, target=target)
Expand Down Expand Up @@ -187,7 +187,7 @@ def test_all_gates_not_in_ideal_sim_target(self):

def test_all_gates_in_basis_after_translation_with_target(self):
"""Test circuit with gates in basis after conditional translation."""
target = FakeBackend5QV2().target
target = FakeManilaV2().target
basis_gates = ["cx", "u"]
property_set = {}
analysis_pass = GatesInBasis(basis_gates, target)
Expand Down
4 changes: 2 additions & 2 deletions test/python/transpiler/test_target.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@
from qiskit.transpiler import Target
from qiskit.transpiler import InstructionProperties
from qiskit.test import QiskitTestCase
from qiskit.test.mock.fake_backend_v2 import FakeBackendV2
from qiskit.providers.fake_provider import FakeManilaV2


class TestTarget(QiskitTestCase):
def setUp(self):
super().setUp()
self.fake_backend = FakeBackendV2()
self.fake_backend = FakeManilaV2()
self.fake_backend_target = self.fake_backend.target
self.theta = Parameter("theta")
self.phi = Parameter("phi")
Expand Down
9 changes: 5 additions & 4 deletions test/python/transpiler/test_unitary_synthesis.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@

from qiskit import transpile
from qiskit.test import QiskitTestCase
from qiskit.test.mock import FakeVigo, FakeBackend5QV2, FakeBackendV2, FakeMumbaiFractionalCX
from qiskit.test.mock import FakeVigo, FakeMumbaiFractionalCX
from qiskit.providers.fake_provider import FakeManilaV2
from qiskit.circuit import QuantumCircuit, QuantumRegister
from qiskit.circuit.library import QuantumVolume
from qiskit.converters import circuit_to_dag
Expand Down Expand Up @@ -586,7 +587,7 @@ def test_coupling_map_transpile(self, opt):
name="opt_level_{opt_level}_bidirectional_{bidirectional}",
)
def test_coupling_map_transpile_with_backendv2(self, opt_level, bidirectional):
backend = FakeBackend5QV2(bidirectional)
backend = FakeManilaV2(bidirectional)
qr = QuantumRegister(2)
circ = QuantumCircuit(qr)
circ.append(random_unitary(4, seed=1), [0, 1])
Expand Down Expand Up @@ -635,7 +636,7 @@ def test_coupling_unequal_duration_with_backendv2(self, opt_level, bidirectional
qr = QuantumRegister(2)
circ = QuantumCircuit(qr)
circ.append(random_unitary(4, seed=1), [1, 0])
backend = FakeBackend5QV2(bidirectional)
backend = FakeManilaV2(bidirectional)
tqc = transpile(
circ,
backend=backend,
Expand Down Expand Up @@ -665,7 +666,7 @@ def test_non_overlapping_kak_gates_with_backendv2(self, opt_level):
qr = QuantumRegister(2)
circ = QuantumCircuit(qr)
circ.append(random_unitary(4, seed=1), [1, 0])
backend = FakeBackendV2()
backend = FakeManilaV2()
tqc = transpile(
circ,
backend=backend,
Expand Down