diff --git a/qiskit/providers/fake_provider/generic_backend_v2.py b/qiskit/providers/fake_provider/generic_backend_v2.py index ab038ecd0af7..3d0502aeb617 100644 --- a/qiskit/providers/fake_provider/generic_backend_v2.py +++ b/qiskit/providers/fake_provider/generic_backend_v2.py @@ -251,15 +251,15 @@ def _get_calibration_sequence( name="acquire", duration=1792, t0=0, - qubits=list(range(num_qubits)), - memory_slot=list(range(num_qubits)), + qubits=qargs, + memory_slot=qargs, ) - ] + [PulseQobjInstruction(name=pulse_library[1], ch=f"m{i}", t0=0) for i in qargs] + ] + [PulseQobjInstruction(name=pulse_library[1].name, ch=f"m{i}", t0=0) for i in qargs] return sequence if num_qubits == 1: return [ - PulseQobjInstruction(name="fc", ch=f"u{qargs}", t0=0, phase="-P0"), - PulseQobjInstruction(name=pulse_library[0].name, ch=f"d{qargs}", t0=0), + PulseQobjInstruction(name="fc", ch=f"u{qargs[0]}", t0=0, phase="-P0"), + PulseQobjInstruction(name=pulse_library[0].name, ch=f"d{qargs[0]}", t0=0), ] return [ PulseQobjInstruction(name=pulse_library[1].name, ch=f"d{qargs[0]}", t0=0), diff --git a/test/python/legacy_cmaps.py b/test/python/legacy_cmaps.py new file mode 100644 index 000000000000..8a23e879ed10 --- /dev/null +++ b/test/python/legacy_cmaps.py @@ -0,0 +1,194 @@ +# This code is part of Qiskit. +# +# (C) Copyright IBM 2024. +# +# 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. + +"""Coupling maps for fake backend generation and transpiler testing.""" + +# 5 qubits +# bidirectional +BOGOTA_CMAP = [[0, 1], [1, 0], [1, 2], [2, 1], [2, 3], [3, 2], [3, 4], [4, 3]] +LIMA_CMAP = [[0, 1], [1, 0], [1, 2], [1, 3], [2, 1], [3, 1], [3, 4], [4, 3]] +YORKTOWN_CMAP = [ + [0, 1], + [0, 2], + [1, 0], + [1, 2], + [2, 0], + [2, 1], + [2, 3], + [2, 4], + [3, 2], + [3, 4], + [4, 2], + [4, 3], +] +# directional +TENERIFE_CMAP = [[1, 0], [2, 0], [2, 1], [3, 2], [3, 4], [4, 2]] + +# 16 qubits +RUESCHLIKON_CMAP = [ + [1, 0], + [1, 2], + [2, 3], + [3, 4], + [3, 14], + [5, 4], + [6, 5], + [6, 7], + [6, 11], + [7, 10], + [8, 7], + [9, 8], + [9, 10], + [11, 10], + [12, 5], + [12, 11], + [12, 13], + [13, 4], + [13, 14], + [15, 0], + [15, 2], + [15, 14], +] + +# 20 qubits +TOKYO_CMAP = [ + [0, 1], + [0, 5], + [1, 0], + [1, 2], + [1, 6], + [1, 7], + [2, 1], + [2, 6], + [3, 8], + [4, 8], + [4, 9], + [5, 0], + [5, 6], + [5, 10], + [5, 11], + [6, 1], + [6, 2], + [6, 5], + [6, 7], + [6, 10], + [6, 11], + [7, 1], + [7, 6], + [7, 8], + [7, 12], + [8, 3], + [8, 4], + [8, 7], + [8, 9], + [8, 12], + [8, 13], + [9, 4], + [9, 8], + [10, 5], + [10, 6], + [10, 11], + [10, 15], + [11, 5], + [11, 6], + [11, 10], + [11, 12], + [11, 16], + [11, 17], + [12, 7], + [12, 8], + [12, 11], + [12, 13], + [12, 16], + [13, 8], + [13, 12], + [13, 14], + [13, 18], + [13, 19], + [14, 13], + [14, 18], + [14, 19], + [15, 10], + [15, 16], + [16, 11], + [16, 12], + [16, 15], + [16, 17], + [17, 11], + [17, 16], + [17, 18], + [18, 13], + [18, 14], + [18, 17], + [19, 13], + [19, 14], +] + +# 27 qubits +MUMBAI_CMAP = [ + [0, 1], + [1, 0], + [1, 2], + [1, 4], + [2, 1], + [2, 3], + [3, 2], + [3, 5], + [4, 1], + [4, 7], + [5, 3], + [5, 8], + [6, 7], + [7, 4], + [7, 6], + [7, 10], + [8, 5], + [8, 9], + [8, 11], + [9, 8], + [10, 7], + [10, 12], + [11, 8], + [11, 14], + [12, 10], + [12, 13], + [12, 15], + [13, 12], + [13, 14], + [14, 11], + [14, 13], + [14, 16], + [15, 12], + [15, 18], + [16, 14], + [16, 19], + [17, 18], + [18, 15], + [18, 17], + [18, 21], + [19, 16], + [19, 20], + [19, 22], + [20, 19], + [21, 18], + [21, 23], + [22, 19], + [22, 25], + [23, 21], + [23, 24], + [24, 23], + [24, 25], + [25, 22], + [25, 24], + [25, 26], + [26, 25], +] diff --git a/test/python/primitives/test_backend_estimator.py b/test/python/primitives/test_backend_estimator.py index d1a81b9ea871..a91c6faf840c 100644 --- a/test/python/primitives/test_backend_estimator.py +++ b/test/python/primitives/test_backend_estimator.py @@ -1,6 +1,6 @@ # This code is part of Qiskit. # -# (C) Copyright IBM 2022. +# (C) Copyright IBM 2022, 2024. # # 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 @@ -10,7 +10,7 @@ # copyright notice, and modified files need to carry a notice indicating # that they have been altered from the originals. -"""Tests for Estimator.""" +"""Tests for BackendEstimator.""" import unittest from unittest.mock import patch @@ -21,8 +21,8 @@ from qiskit.circuit import QuantumCircuit from qiskit.circuit.library import RealAmplitudes from qiskit.primitives import BackendEstimator, EstimatorResult -from qiskit.providers.fake_provider import FakeNairobi, FakeNairobiV2 -from qiskit.providers.fake_provider.fake_backend_v2 import FakeBackendSimple +from qiskit.providers.fake_provider import FakeNairobi, GenericBackendV2 +from qiskit.providers.backend_compat import BackendV2Converter from qiskit.quantum_info import SparsePauliOp from qiskit.transpiler import PassManager from qiskit.utils import optionals @@ -31,7 +31,11 @@ from test.python.transpiler._dummy_passes import DummyAP # pylint: disable=wrong-import-order -BACKENDS = [FakeNairobi(), FakeNairobiV2(), FakeBackendSimple()] +BACKENDS = [ + FakeNairobi(), + BackendV2Converter(FakeNairobi()), + GenericBackendV2(num_qubits=5, seed=42), +] class CallbackPass(DummyAP): @@ -271,14 +275,14 @@ def test_options(self, backend): def test_job_size_limit_v2(self): """Test BackendEstimator respects job size limit""" - class FakeNairobiLimitedCircuits(FakeNairobiV2): - """FakeNairobiV2 with job size limit.""" + class FakeBackendLimitedCircuits(GenericBackendV2): + """Generic backend V2 with job size limit.""" @property def max_circuits(self): return 1 - backend = FakeNairobiLimitedCircuits() + backend = FakeBackendLimitedCircuits(num_qubits=5) backend.set_options(seed_simulator=123) qc = RealAmplitudes(num_qubits=2, reps=2) op = SparsePauliOp.from_list([("IZ", 1), ("XI", 2), ("ZY", -1)]) @@ -387,10 +391,11 @@ def test_layout(self, backend): estimator = BackendEstimator(backend) estimator.set_transpile_options(seed_transpiler=15) value = estimator.run(qc, op, shots=10000).result().values[0] - if optionals.HAS_AER and not isinstance(backend, FakeBackendSimple): - self.assertEqual(value, -0.916) + if optionals.HAS_AER: + ref_value = -0.9922 if isinstance(backend, GenericBackendV2) else -0.916 else: - self.assertEqual(value, -1) + ref_value = -1 + self.assertEqual(value, ref_value) with self.subTest("final layout test"): qc = QuantumCircuit(3) @@ -402,10 +407,11 @@ def test_layout(self, backend): estimator = BackendEstimator(backend) estimator.set_transpile_options(initial_layout=[0, 1, 2], seed_transpiler=15) value = estimator.run(qc, op, shots=10000).result().values[0] - if optionals.HAS_AER and not isinstance(backend, FakeBackendSimple): - self.assertEqual(value, -0.8902) + if optionals.HAS_AER: + ref_value = -0.9922 if isinstance(backend, GenericBackendV2) else -0.8902 else: - self.assertEqual(value, -1) + ref_value = -1 + self.assertEqual(value, ref_value) @unittest.skipUnless(optionals.HAS_AER, "qiskit-aer is required to run this test") def test_circuit_with_measurement(self): diff --git a/test/python/primitives/test_backend_sampler.py b/test/python/primitives/test_backend_sampler.py index f80f06b71529..3886729a4108 100644 --- a/test/python/primitives/test_backend_sampler.py +++ b/test/python/primitives/test_backend_sampler.py @@ -22,7 +22,8 @@ from qiskit.circuit.library import RealAmplitudes from qiskit.primitives import BackendSampler, SamplerResult from qiskit.providers import JobStatus -from qiskit.providers.fake_provider import FakeNairobi, FakeNairobiV2 +from qiskit.providers.fake_provider import FakeNairobi, GenericBackendV2 +from qiskit.providers.backend_compat import BackendV2Converter from qiskit.providers.basic_provider import BasicSimulator from qiskit.transpiler import PassManager from qiskit.utils import optionals @@ -31,7 +32,10 @@ from test.python.transpiler._dummy_passes import DummyAP # pylint: disable=wrong-import-order -BACKENDS = [FakeNairobi(), FakeNairobiV2()] +BACKENDS = [ + FakeNairobi(), + BackendV2Converter(FakeNairobi()), +] class CallbackPass(DummyAP): @@ -298,8 +302,8 @@ def test_primitive_job_status_done(self, backend): def test_primitive_job_size_limit_backend_v2(self): """Test primitive respects backend's job size limit.""" - class FakeNairobiLimitedCircuits(FakeNairobiV2): - """FakeNairobiV2 with job size limit.""" + class FakeBackendLimitedCircuits(GenericBackendV2): + """Generic backend V2 with job size limit.""" @property def max_circuits(self): @@ -310,7 +314,7 @@ def max_circuits(self): qc2 = QuantumCircuit(1) qc2.x(0) qc2.measure_all() - sampler = BackendSampler(backend=FakeNairobiLimitedCircuits()) + sampler = BackendSampler(backend=FakeBackendLimitedCircuits(num_qubits=5)) result = sampler.run([qc, qc2]).result() self.assertIsInstance(result, SamplerResult) self.assertEqual(len(result.quasi_dists), 2) diff --git a/test/python/providers/fake_provider/test_fake_generic.py b/test/python/providers/fake_provider/test_generic_backend_v2.py similarity index 100% rename from test/python/providers/fake_provider/test_fake_generic.py rename to test/python/providers/fake_provider/test_generic_backend_v2.py diff --git a/test/python/providers/test_backend_v2.py b/test/python/providers/test_backend_v2.py index 2d582db513f3..81be16d8e77a 100644 --- a/test/python/providers/test_backend_v2.py +++ b/test/python/providers/test_backend_v2.py @@ -1,6 +1,6 @@ # This code is part of Qiskit. # -# (C) Copyright IBM 2021. +# (C) Copyright IBM 2021, 2024. # # 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 @@ -20,25 +20,35 @@ from ddt import ddt, data from qiskit.circuit import QuantumCircuit, ClassicalRegister, QuantumRegister -from qiskit.compiler import transpile -from qiskit.providers.fake_provider import FakeMumbaiFractionalCX -from qiskit.providers.fake_provider.fake_backend_v2 import ( - FakeBackendV2, - FakeBackend5QV2, - FakeBackendSimple, - FakeBackendV2LegacyQubitProps, +from qiskit.circuit.library.standard_gates import ( + CXGate, + ECRGate, ) -from qiskit.providers.fake_provider.backends import FakeBogotaV2 +from qiskit.compiler import transpile +from qiskit.transpiler import InstructionProperties +from qiskit.providers.fake_provider import FakeMumbaiFractionalCX, GenericBackendV2 +from qiskit.providers.basic_provider import BasicSimulator from qiskit.quantum_info import Operator from qiskit.pulse import channels from test import QiskitTestCase # pylint: disable=wrong-import-order +from ..legacy_cmaps import BOGOTA_CMAP, TENERIFE_CMAP + @ddt class TestBackendV2(QiskitTestCase): def setUp(self): super().setUp() - self.backend = FakeBackendV2() + self.backend = GenericBackendV2(num_qubits=2, seed=42, basis_gates=["rx", "u"]) + cx_props = { + (0, 1): InstructionProperties(duration=5.23e-7, error=0.00098115), + } + self.backend.target.add_instruction(CXGate(), cx_props) + ecr_props = { + (1, 0): InstructionProperties(duration=4.52e-9, error=0.0000132115), + } + self.backend.target.add_instruction(ECRGate(), ecr_props) + self.backend.options.set_validator("shots", (1, 4096)) def assertMatchesTargetConstraints(self, tqc, target): qubit_indices = {qubit: index for index, qubit in enumerate(tqc.qubits)} @@ -55,21 +65,30 @@ def assertMatchesTargetConstraints(self, tqc, target): def test_qubit_properties(self): """Test that qubit properties are returned as expected.""" props = self.backend.qubit_properties([1, 0]) - self.assertEqual([73.09352e-6, 63.48783e-6], [x.t1 for x in props]) - self.assertEqual([126.83382e-6, 112.23246e-6], [x.t2 for x in props]) - self.assertEqual([5.26722e9, 5.17538e9], [x.frequency for x in props]) + self.assertEqual([0.0001697368029059364, 0.00017739560485559633], [x.t1 for x in props]) + self.assertEqual([0.00010941773478876496, 0.00014388784397520525], [x.t2 for x in props]) + self.assertEqual([5487811175.818378, 5429298959.955691], [x.frequency for x in props]) def test_legacy_qubit_properties(self): """Test that qubit props work for backends not using properties in target.""" - props = FakeBackendV2LegacyQubitProps().qubit_properties([1, 0]) - self.assertEqual([73.09352e-6, 63.48783e-6], [x.t1 for x in props]) - self.assertEqual([126.83382e-6, 112.23246e-6], [x.t2 for x in props]) - self.assertEqual([5.26722e9, 5.17538e9], [x.frequency for x in props]) + + class FakeBackendV2LegacyQubitProps(GenericBackendV2): + """Fake backend that doesn't use qubit properties via the target.""" + + def qubit_properties(self, qubit): + if isinstance(qubit, int): + return self.target.qubit_properties[qubit] + return [self.target.qubit_properties[i] for i in qubit] + + props = FakeBackendV2LegacyQubitProps(num_qubits=2, seed=42).qubit_properties([1, 0]) + self.assertEqual([0.0001697368029059364, 0.00017739560485559633], [x.t1 for x in props]) + self.assertEqual([0.00010941773478876496, 0.00014388784397520525], [x.t2 for x in props]) + self.assertEqual([5487811175.818378, 5429298959.955691], [x.frequency for x in props]) 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) + BasicSimulator().qubit_properties(0) def test_option_bounds(self): """Test that option bounds are enforced.""" @@ -101,7 +120,10 @@ 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) + if bidirectional: + backend = GenericBackendV2(num_qubits=5) + else: + backend = GenericBackendV2(num_qubits=5, coupling_map=TENERIFE_CMAP) qc = QuantumCircuit(5) qc.h(0) getattr(qc, gate)(0, 1) @@ -179,7 +201,7 @@ def test_transpile_mumbai_target(self): @data(0, 1, 2, 3, 4) def test_drive_channel(self, qubit): """Test getting drive channel with qubit index.""" - backend = FakeBogotaV2() + backend = GenericBackendV2(num_qubits=5) chan = backend.drive_channel(qubit) ref = channels.DriveChannel(qubit) self.assertEqual(chan, ref) @@ -187,7 +209,7 @@ def test_drive_channel(self, qubit): @data(0, 1, 2, 3, 4) def test_measure_channel(self, qubit): """Test getting measure channel with qubit index.""" - backend = FakeBogotaV2() + backend = GenericBackendV2(num_qubits=5) chan = backend.measure_channel(qubit) ref = channels.MeasureChannel(qubit) self.assertEqual(chan, ref) @@ -195,7 +217,7 @@ def test_measure_channel(self, qubit): @data(0, 1, 2, 3, 4) def test_acquire_channel(self, qubit): """Test getting acquire channel with qubit index.""" - backend = FakeBogotaV2() + backend = GenericBackendV2(num_qubits=5) chan = backend.acquire_channel(qubit) ref = channels.AcquireChannel(qubit) self.assertEqual(chan, ref) @@ -213,7 +235,7 @@ def test_control_channel(self, qubits): (1, 0): 1, (0, 1): 0, } - backend = FakeBogotaV2() + backend = GenericBackendV2(num_qubits=5, coupling_map=BOGOTA_CMAP) chan = backend.control_channel(qubits)[0] ref = channels.ControlChannel(bogota_cr_channels_map[qubits]) self.assertEqual(chan, ref) diff --git a/test/python/pulse/test_builder_v2.py b/test/python/pulse/test_builder_v2.py index b5601a80f866..0df2293eb4ae 100644 --- a/test/python/pulse/test_builder_v2.py +++ b/test/python/pulse/test_builder_v2.py @@ -19,17 +19,23 @@ from qiskit.pulse.instructions import directives from qiskit.pulse.transforms import target_qobj_transform -from qiskit.providers.fake_provider import FakeMumbaiV2 +from qiskit.providers.fake_provider import GenericBackendV2 from qiskit.pulse import instructions from test import QiskitTestCase # pylint: disable=wrong-import-order +from ..legacy_cmaps import MUMBAI_CMAP + class TestBuilderV2(QiskitTestCase): """Test the pulse builder context with backendV2.""" def setUp(self): super().setUp() - self.backend = FakeMumbaiV2() + self.backend = GenericBackendV2( + num_qubits=27, + coupling_map=MUMBAI_CMAP, + calibrate_instructions=True, + ) def assertScheduleEqual(self, program, target): """Assert an error when two pulse programs are not equal. diff --git a/test/python/qpy/test_circuit_load_from_qpy.py b/test/python/qpy/test_circuit_load_from_qpy.py index 715c3755ca50..d8ce1228bdc3 100644 --- a/test/python/qpy/test_circuit_load_from_qpy.py +++ b/test/python/qpy/test_circuit_load_from_qpy.py @@ -1,6 +1,6 @@ # This code is part of Qiskit. # -# (C) Copyright IBM 2022. +# (C) Copyright IBM 2022, 2024. # # 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 @@ -18,7 +18,7 @@ from ddt import ddt, data from qiskit.circuit import QuantumCircuit, QuantumRegister, Qubit, Parameter, Gate -from qiskit.providers.fake_provider import FakeHanoi, FakeSherbrooke +from qiskit.providers.fake_provider import FakeHanoi, GenericBackendV2 from qiskit.exceptions import QiskitError from qiskit.qpy import dump, load, formats, QPY_COMPATIBILITY_VERSION from qiskit.qpy.common import QPY_VERSION @@ -107,7 +107,7 @@ def test_transpile_layout(self, opt_level): qc.h(0) qc.cx(0, 1) qc.measure_all() - backend = FakeSherbrooke() + backend = GenericBackendV2(num_qubits=127) tqc = transpile(qc, backend, optimization_level=opt_level) self.assert_roundtrip_equal(tqc) @@ -121,7 +121,7 @@ def test_transpile_with_routing(self, opt_level): qc.cx(0, 3) qc.cx(0, 4) qc.measure_all() - backend = FakeSherbrooke() + backend = GenericBackendV2(num_qubits=127) tqc = transpile(qc, backend, optimization_level=opt_level) self.assert_roundtrip_equal(tqc) @@ -132,7 +132,7 @@ def test_transpile_layout_explicit_None_final_layout(self, opt_level): qc.h(0) qc.cx(0, 1) qc.measure_all() - backend = FakeSherbrooke() + backend = GenericBackendV2(num_qubits=127) tqc = transpile(qc, backend, optimization_level=opt_level) tqc.layout.final_layout = None self.assert_roundtrip_equal(tqc) @@ -196,7 +196,7 @@ def test_custom_register_name(self, opt_level): qc.cx(0, 3) qc.cx(0, 4) qc.measure_all() - backend = FakeSherbrooke() + backend = GenericBackendV2(num_qubits=127) tqc = transpile(qc, backend, optimization_level=opt_level) self.assert_roundtrip_equal(tqc) @@ -208,7 +208,7 @@ def test_no_register(self, opt_level): qc.h(0) qc.cx(0, 1) qc.measure_all() - backend = FakeSherbrooke() + backend = GenericBackendV2(num_qubits=127) tqc = transpile(qc, backend, optimization_level=opt_level) # Manually validate to deal with qubit equality needing exact objects qpy_file = io.BytesIO() diff --git a/test/python/quantum_info/operators/symplectic/test_sparse_pauli_op.py b/test/python/quantum_info/operators/symplectic/test_sparse_pauli_op.py index 8fb64bfab62c..4ab53d35b080 100644 --- a/test/python/quantum_info/operators/symplectic/test_sparse_pauli_op.py +++ b/test/python/quantum_info/operators/symplectic/test_sparse_pauli_op.py @@ -1,6 +1,6 @@ # This code is part of Qiskit. # -# (C) Copyright IBM 2017, 2023. +# (C) Copyright IBM 2017, 2024. # # 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 @@ -23,8 +23,9 @@ from qiskit.quantum_info.operators import Operator, Pauli, PauliList, SparsePauliOp from qiskit.circuit.library import EfficientSU2 from qiskit.primitives import BackendEstimator -from qiskit.providers.fake_provider import FakeNairobiV2 +from qiskit.providers.fake_provider import GenericBackendV2 from qiskit.compiler.transpiler import transpile +from qiskit.utils import optionals from test import QiskitTestCase # pylint: disable=wrong-import-order from test import combine # pylint: disable=wrong-import-order @@ -1032,7 +1033,7 @@ def test_apply_layout_with_transpile(self): """Test the apply_layout method with a transpiler layout.""" psi = EfficientSU2(4, reps=4, entanglement="circular") op = SparsePauliOp.from_list([("IIII", 1), ("IZZZ", 2), ("XXXI", 3)]) - backend = FakeNairobiV2() + backend = GenericBackendV2(num_qubits=7) transpiled_psi = transpile(psi, backend, optimization_level=3, seed_transpiler=12345) permuted_op = op.apply_layout(transpiled_psi.layout) identity_op = SparsePauliOp("I" * 7) @@ -1047,7 +1048,7 @@ def test_permute_sparse_pauli_op_estimator_example(self): """Test using the apply_layout method with an estimator workflow.""" psi = EfficientSU2(4, reps=4, entanglement="circular") op = SparsePauliOp.from_list([("IIII", 1), ("IZZZ", 2), ("XXXI", 3)]) - backend = FakeNairobiV2() + backend = GenericBackendV2(num_qubits=7, seed=0) backend.set_options(seed_simulator=123) estimator = BackendEstimator(backend=backend, skip_transpilation=True) thetas = list(range(len(psi.parameters))) @@ -1055,7 +1056,10 @@ def test_permute_sparse_pauli_op_estimator_example(self): permuted_op = op.apply_layout(transpiled_psi.layout) job = estimator.run(transpiled_psi, permuted_op, thetas) res = job.result().values - np.testing.assert_allclose(res, [1.35351562], rtol=0.5, atol=0.2) + if optionals.HAS_AER: + np.testing.assert_allclose(res, [1.419922], rtol=0.5, atol=0.2) + else: + np.testing.assert_allclose(res, [1.660156], rtol=0.5, atol=0.2) def test_apply_layout_invalid_qubits_list(self): """Test that apply_layout with an invalid qubit count raises.""" diff --git a/test/python/scheduler/test_basic_scheduler.py b/test/python/scheduler/test_basic_scheduler.py index 6f15527eff3a..16ec00927c67 100644 --- a/test/python/scheduler/test_basic_scheduler.py +++ b/test/python/scheduler/test_basic_scheduler.py @@ -1,6 +1,6 @@ # This code is part of Qiskit. # -# (C) Copyright IBM 2019. +# (C) Copyright IBM 2019, 2024. # # 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 @@ -12,6 +12,7 @@ """Test cases for the pulse scheduler passes.""" +import numpy as np from numpy import pi from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit, schedule from qiskit.circuit import Gate, Parameter @@ -20,7 +21,6 @@ from qiskit.pulse import ( Schedule, DriveChannel, - Delay, AcquireChannel, Acquire, MeasureChannel, @@ -28,10 +28,16 @@ Gaussian, GaussianSquare, Play, + Waveform, transforms, ) from qiskit.pulse import build, macros, play, InstructionScheduleMap -from qiskit.providers.fake_provider import FakeBackend, FakeOpenPulse2Q, FakeOpenPulse3Q, FakePerth +from qiskit.providers.fake_provider import ( + FakeBackend, + FakeOpenPulse2Q, + FakeOpenPulse3Q, + GenericBackendV2, +) from test import QiskitTestCase # pylint: disable=wrong-import-order @@ -235,6 +241,7 @@ def test_measure_combined(self): ) self.assertEqual(sched.instructions, expected.instructions) + # def test_3q_schedule(self): """Test a schedule that was recommended by David McKay :D""" @@ -502,8 +509,11 @@ class TestBasicScheduleV2(QiskitTestCase): def setUp(self): super().setUp() - self.backend = FakePerth() + self.backend = GenericBackendV2(num_qubits=3, calibrate_instructions=True) self.inst_map = self.backend.instruction_schedule_map + # self.pulse_2_samples is the pulse sequence used to calibrate "measure" in + # GenericBackendV2. See class construction for more details. + self.pulse_2_samples = np.linspace(0, 1.0, 32, dtype=np.complex128) def test_alap_pass(self): """Test ALAP scheduling.""" @@ -531,54 +541,41 @@ def test_alap_pass(self): qc.measure(q, c) sched = schedule(circuits=qc, backend=self.backend, method="alap") + # Since, the method of scheduling chosen here is 'as_late_as_possible' # so all the π/2 pulse here should be right shifted. # # Calculations: - # Duration of the π/2 pulse for FakePerth backend is 160dt - # first π/2 pulse on q0 should start at 160dt because of 'as_late_as_possible'. + # Duration of the π/2 pulse for GenericBackendV2 backend is 16dt + # first π/2 pulse on q0 should start at 16dt because of 'as_late_as_possible'. # first π/2 pulse on q1 should start 0dt. - # second π/2 pulse on q1 should start with a delay of 160dt. + # second π/2 pulse on q1 should start with a delay of 16dt. # cx pulse( pulse on drive channel, control channel) should start with a delay - # of 160dt+160dt. - # measure pulse should start with a delay of 160dt+160dt+1760dt(1760dt for cx gate). + # of 16dt+16dt. + # measure pulse should start with a delay of 16dt+16dt+64dt(64dt for cx gate). expected = Schedule( (0, self.inst_map.get("sx", [1])), - (0 + 160, self.inst_map.get("sx", [0])), # Right shifted because of alap. - (0 + 160, self.inst_map.get("sx", [1])), - (0 + 160 + 160, self.inst_map.get("cx", [0, 1])), - (0 + 160 + 160 + 1760, Acquire(1472, AcquireChannel(0), MemorySlot(0))), - (0 + 160 + 160 + 1760, Acquire(1472, AcquireChannel(1), MemorySlot(1))), + (0 + 16, self.inst_map.get("sx", [0])), # Right shifted because of alap. + (0 + 16, self.inst_map.get("sx", [1])), + (0 + 16 + 16, self.inst_map.get("cx", [0, 1])), ( - 0 + 160 + 160 + 1760, + 0 + 16 + 16 + 64, Play( - GaussianSquare( - duration=1472, - sigma=64, - width=1216, - amp=0.24000000000000002, - angle=-0.24730169436555283, - name="M_m0", - ), + Waveform(samples=self.pulse_2_samples, name="pulse_2"), MeasureChannel(0), - name="M_m0", + name="pulse_2", ), ), ( - 0 + 160 + 160 + 1760, + 0 + 16 + 16 + 64, Play( - GaussianSquare( - duration=1472, - sigma=64, - width=1216, - amp=0.32, - angle=-1.9900962136758156, - name="M_m1", - ), + Waveform(samples=self.pulse_2_samples, name="pulse_2"), MeasureChannel(1), - name="M_m1", + name="pulse_2", ), ), + (0 + 16 + 16 + 64, Acquire(1792, AcquireChannel(0), MemorySlot(0))), + (0 + 16 + 16 + 64, Acquire(1792, AcquireChannel(1), MemorySlot(1))), ) for actual, expected in zip(sched.instructions, expected.instructions): self.assertEqual(actual[0], expected[0]) @@ -614,7 +611,7 @@ def test_alap_with_barriers(self): sched = schedule(qc, self.backend, method="alap") # If there wasn't a barrier the π/2 pulse on q1 would have started from 0dt, but since, # there is a barrier so the π/2 pulse on q1 should start with a delay of 160dt. - expected = Schedule((0, self.inst_map.get("sx", [0])), (160, self.inst_map.get("sx", [1]))) + expected = Schedule((0, self.inst_map.get("sx", [0])), (16, self.inst_map.get("sx", [1]))) for actual, expected in zip(sched.instructions, expected.instructions): self.assertEqual(actual, expected) @@ -682,50 +679,36 @@ def test_asap_pass(self): # so all the π/2 pulse here should be left shifted. # # Calculations: - # Duration of the π/2 pulse for FakePerth backend is 160dt + # Duration of the π/2 pulse for FakePerth backend is 16dt # first π/2 pulse on q0 should start at 0dt because of 'as_soon_as_possible'. # first π/2 pulse on q1 should start 0dt. - # second π/2 pulse on q1 should start with a delay of 160dt. + # second π/2 pulse on q1 should start with a delay of 16dt. # cx pulse( pulse on drive channel, control channel) should start with a delay - # of 160dt+160dt. - # measure pulse should start with a delay of 160dt+160dt+1760dt(1760dt for cx gate). + # of 16dt+16dt. + # measure pulse should start with a delay of 16dt+16dt+64dt(64dt for cx gate). expected = Schedule( (0, self.inst_map.get("sx", [1])), (0, self.inst_map.get("sx", [0])), # Left shifted because of asap. - (0 + 160, self.inst_map.get("sx", [1])), - (0 + 160 + 160, self.inst_map.get("cx", [0, 1])), - (0 + 160 + 160 + 1760, Acquire(1472, AcquireChannel(0), MemorySlot(0))), - (0 + 160 + 160 + 1760, Acquire(1472, AcquireChannel(1), MemorySlot(1))), + (0 + 16, self.inst_map.get("sx", [1])), + (0 + 16 + 16, self.inst_map.get("cx", [0, 1])), ( - 0 + 160 + 160 + 1760, + 0 + 16 + 16 + 64, Play( - GaussianSquare( - duration=1472, - sigma=64, - width=1216, - amp=0.24000000000000002, - angle=-0.24730169436555283, - name="M_m0", - ), + Waveform(samples=self.pulse_2_samples, name="pulse_2"), MeasureChannel(0), - name="M_m0", + name="pulse_2", ), ), ( - 0 + 160 + 160 + 1760, + 0 + 16 + 16 + 64, Play( - GaussianSquare( - duration=1472, - sigma=64, - width=1216, - amp=0.32, - angle=-1.9900962136758156, - name="M_m1", - ), + Waveform(samples=self.pulse_2_samples, name="pulse_2"), MeasureChannel(1), - name="M_m1", + name="pulse_2", ), ), + (0 + 16 + 16 + 64, Acquire(1792, AcquireChannel(0), MemorySlot(0))), + (0 + 16 + 16 + 64, Acquire(1792, AcquireChannel(1), MemorySlot(1))), ) for actual, expected in zip(sched.instructions, expected.instructions): self.assertEqual(actual[0], expected[0]) @@ -746,10 +729,10 @@ def test_alap_resource_respecting(self): # This is ShiftPhase for the cx operation. self.assertEqual(insts[0][0], 0) - # It takes 9 pulse operations on DriveChannel and ControlChannel to do a + # It takes 4 pulse operations on DriveChannel and ControlChannel to do a # cx operation on this backend. - # 1760dt is duration of cx operation on this backend. - self.assertEqual(insts[9][0], 1760) + # 64dt is duration of cx operation on this backend. + self.assertEqual(insts[4][0], 64) qc = QuantumCircuit(q, c) qc.cx(q[0], q[1]) @@ -757,10 +740,9 @@ def test_alap_resource_respecting(self): qc.measure(q, c) sched = schedule(qc, self.backend, method="as_late_as_possible") - # 1760dt for cx operation + 160dt for sx operation + 1472dt for measure on both qubits. - # Total: 3392dt. - # So, the delay in MeasureChannel0 and 1 starts from 3392dt. - self.assertEqual(sched.instructions[-1][0], 3392) + # 64dt for cx operation + 16dt for sx operation + # So, the pulses in MeasureChannel0 and 1 starts from 80dt. + self.assertEqual(sched.instructions[-1][0], 80) def test_inst_map_schedules_unaltered(self): """Test that forward scheduling doesn't change relative timing with a command.""" @@ -776,13 +758,8 @@ def test_inst_map_schedules_unaltered(self): insts = sched1.instructions self.assertEqual(insts[0][0], 0) # ShiftPhase at DriveChannel(0) no dt required. self.assertEqual(insts[1][0], 0) # ShiftPhase at ControlChannel(1) no dt required. - self.assertEqual(insts[2][0], 0) # Pulse Ym_d0 of duration 160dt. - self.assertEqual(insts[3][0], 0) # Pulse X90p_d1 of duration 160dt. - self.assertEqual(insts[4][0], 160) # Pusle CR90p_d1_u0 of duration 720dt. - self.assertEqual(insts[5][0], 160) # Pulse CR90p_u0 of duration 720dt. - self.assertEqual(insts[6][0], 880) # Pulse Xp_d0 of duratoin 160dt. - self.assertEqual(insts[7][0], 1040) # Pulse CR90m_d1_u0 of duration 720dt. - self.assertEqual(insts[8][0], 1040) # Pulse CR90m_u0 of duration 720dt. + self.assertEqual(insts[2][0], 0) # Pulse pulse_2 of duration 32dt. + self.assertEqual(insts[3][0], 0) # Pulse pulse_3 of duration 160dt. def test_measure_combined(self): """ @@ -799,72 +776,36 @@ def test_measure_combined(self): qc.measure(q[0], c[0]) qc.measure(q[1], c[1]) qc.measure(q[1], c[1]) + sched = schedule(qc, self.backend, method="as_soon_as_possible") expected_sched = Schedule( - # This is the Schedule to implement sx gate. + # This is the schedule to implement sx gate. (0, self.inst_map.get("sx", [0])), # This is the schedule to implement cx gate - (0 + 160, self.inst_map.get("cx", [0, 1])), - # Getting ready the to take classical data in MemorySlot(0) for qubit:0 - (0 + 160 + 1760, Acquire(1472, AcquireChannel(0), MemorySlot(0))), - # Since, the method of Scheduling is 'as_soon_as_possilbe' so again for - # qubit:1 getting ready the to take classical data in MemorySlot(1) - (0 + 160 + 1760, Acquire(1472, AcquireChannel(1), MemorySlot(1))), - # Playing pulse on MeasureChannel(0) to read qubit:0 to MemoryChannel(0) + (0 + 16, self.inst_map.get("cx", [0, 1])), + # This is the schedule for the measurements on qubits 0 and 1 (combined) ( - 0 + 160 + 1760, - Play( - GaussianSquare( - duration=1472, - sigma=64, - width=1216, - amp=0.24000000000000002, - angle=-0.24730169436555283, - name="M_m0", - ), - MeasureChannel(0), - name="M_m0", + 0 + 16 + 64, + self.inst_map.get("measure", [0]).filter( + channels=[MeasureChannel(0), MeasureChannel(1)] ), ), - # Playing pulse on MeasureChannel(1) to read qubit:1 to MemoryChannel(1) ( - 0 + 160 + 1760, - Play( - GaussianSquare( - duration=1472, - sigma=64, - width=1216, - amp=0.32, - angle=-1.9900962136758156, - name="M_m1", - ), - MeasureChannel(1), - name="M_m1", + 0 + 16 + 64, + self.inst_map.get("measure", [0]).filter( + channels=[AcquireChannel(0), AcquireChannel(1)] ), ), - # Time for MeasureChannel(0) to relax - (0 + 160 + 1760 + 1472, Delay(1568, MeasureChannel(0))), - # Time for MeasureChannel(1) to relax - (0 + 160 + 1760 + 1472, Delay(1568, MeasureChannel(1))), - # The below schedules would be for the additional measure(1, 1) instruction added. - (0 + 160 + 1760 + 1472 + 1568, Acquire(1472, AcquireChannel(1), MemorySlot(1))), + # This is the schedule for the second measurement on qubit 1 ( - 0 + 160 + 1760 + 1472 + 1568, - Play( - GaussianSquare( - duration=1472, - sigma=64, - width=1216, - amp=0.32, - angle=-1.9900962136758156, - name="M_m1", - ), - MeasureChannel(1), - name="M_m1", - ), + 0 + 16 + 64 + 1792, + self.inst_map.get("measure", [1]).filter(channels=[MeasureChannel(1)]), + ), + ( + 0 + 16 + 64 + 1792, + self.inst_map.get("measure", [1]).filter(channels=[AcquireChannel(1)]), ), - (0 + 160 + 1760 + 1472 + 1568 + 1472, Delay(1568, MeasureChannel(1))), ) self.assertEqual(sched.instructions, expected_sched.instructions) @@ -894,10 +835,10 @@ def test_3q_schedule(self): expected = Schedule( (0, self.inst_map.get("cx", [0, 1])), (0, self.inst_map.get("sx", [2])), - (0 + 1760, self.inst_map.get("sx", [0])), - (0 + 1760, self.inst_map.get("x", [1])), - (0 + 1760 + 160, self.inst_map.get("cx", [1, 2])), - (0 + 1760 + 1760, self.inst_map.get("sx", [2])), + (0 + 64, self.inst_map.get("sx", [0])), + (0 + 64, self.inst_map.get("x", [1])), + (0 + 64 + 16, self.inst_map.get("cx", [1, 2])), + (0 + 64 + 16 + 64, self.inst_map.get("sx", [2])), ) for actual, expected in zip(sched.instructions, expected.instructions): self.assertEqual(actual[0], expected[0]) @@ -949,10 +890,10 @@ def test_can_add_gates_into_free_space(self): expected = Schedule( (0, self.inst_map.get("sx", [0])), (0, self.inst_map.get("sx", [1])), - (0 + 160, self.inst_map.get("x", [0])), - (0 + 160, self.inst_map.get("x", [1])), - (0 + 160 + 160, self.inst_map.get("sx", [0])), - (0 + 160 + 160, self.inst_map.get("sx", [1])), + (0 + 16, self.inst_map.get("x", [0])), + (0 + 16, self.inst_map.get("x", [1])), + (0 + 16 + 16, self.inst_map.get("sx", [0])), + (0 + 16 + 16, self.inst_map.get("sx", [1])), ) for actual, expected in zip(sched.instructions, expected.instructions): self.assertEqual(actual[0], expected[0]) @@ -974,10 +915,10 @@ def test_barriers_in_middle(self): expected = Schedule( (0, self.inst_map.get("sx", [0])), (0, self.inst_map.get("sx", [1])), - (0 + 160, self.inst_map.get("x", [0])), - (0 + 160, self.inst_map.get("x", [1])), - (0 + 160 + 160, self.inst_map.get("sx", [0])), - (0 + 160 + 160, self.inst_map.get("sx", [1])), + (0 + 16, self.inst_map.get("x", [0])), + (0 + 16, self.inst_map.get("x", [1])), + (0 + 16 + 16, self.inst_map.get("sx", [0])), + (0 + 16 + 16, self.inst_map.get("sx", [1])), ) for actual, expected in zip(sched.instructions, expected.instructions): self.assertEqual(actual[0], expected[0]) @@ -1035,7 +976,7 @@ def test_calibrated_measurements(self): qc.add_calibration("measure", [0], meas_sched) sched = schedule(qc, self.backend) - expected = Schedule(self.inst_map.get("sx", [0]), (160, meas_sched)) + expected = Schedule(self.inst_map.get("sx", [0]), (16, meas_sched)) self.assertEqual(sched.instructions, expected.instructions) def test_subset_calibrated_measurements(self): @@ -1145,29 +1086,33 @@ def test_inst_sched_map_get_measure_0(self): is actually Schedule for just qubit_0""" sched_from_backend = self.backend.instruction_schedule_map.get("measure", [0]) expected_sched = Schedule( - (0, Acquire(1472, AcquireChannel(0), MemorySlot(0))), - (0, Acquire(1472, AcquireChannel(1), MemorySlot(1))), - (0, Acquire(1472, AcquireChannel(2), MemorySlot(2))), - (0, Acquire(1472, AcquireChannel(3), MemorySlot(3))), - (0, Acquire(1472, AcquireChannel(4), MemorySlot(4))), - (0, Acquire(1472, AcquireChannel(5), MemorySlot(5))), - (0, Acquire(1472, AcquireChannel(6), MemorySlot(6))), ( 0, Play( - GaussianSquare( - duration=1472, - sigma=64, - width=1216, - amp=0.24000000000000002, - angle=-0.24730169436555283, - name="M_m0", - ), + Waveform(samples=self.pulse_2_samples, name="pulse_2"), MeasureChannel(0), - name="M_m0", + name="pulse_2", + ), + ), + ( + 0, + Play( + Waveform(samples=self.pulse_2_samples, name="pulse_2"), + MeasureChannel(1), + name="pulse_2", + ), + ), + ( + 0, + Play( + Waveform(samples=self.pulse_2_samples, name="pulse_2"), + MeasureChannel(2), + name="pulse_2", ), ), - (1472, Delay(1568, MeasureChannel(0))), + (0, Acquire(1792, AcquireChannel(0), MemorySlot(0))), + (0, Acquire(1792, AcquireChannel(1), MemorySlot(1))), + (0, Acquire(1792, AcquireChannel(2), MemorySlot(2))), name="measure", ) self.assertEqual(sched_from_backend, expected_sched) diff --git a/test/python/transpiler/test_apply_layout.py b/test/python/transpiler/test_apply_layout.py index e7a9a9df6953..143d9424fab8 100644 --- a/test/python/transpiler/test_apply_layout.py +++ b/test/python/transpiler/test_apply_layout.py @@ -1,6 +1,6 @@ # This code is part of Qiskit. # -# (C) Copyright IBM 2019. +# (C) Copyright IBM 2019, 2024. # # 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 @@ -20,10 +20,11 @@ from qiskit.transpiler.passes import ApplyLayout, SetLayout from qiskit.transpiler.exceptions import TranspilerError from qiskit.transpiler.preset_passmanagers import common -from qiskit.providers.fake_provider import FakeVigoV2 -from qiskit.transpiler import PassManager +from qiskit.transpiler import PassManager, CouplingMap from test import QiskitTestCase # pylint: disable=wrong-import-order +from ..legacy_cmaps import YORKTOWN_CMAP + class TestApplyLayout(QiskitTestCase): """Tests the ApplyLayout pass.""" @@ -125,7 +126,7 @@ def test_final_layout_is_updated(self): for i in range(5): qc.cx(i % qubits, int(i + qubits / 2) % qubits) initial_pm = PassManager([SetLayout([1, 3, 4])]) - cmap = FakeVigoV2().coupling_map + cmap = CouplingMap(YORKTOWN_CMAP) initial_pm += common.generate_embed_passmanager(cmap) first_layout_circ = initial_pm.run(qc) out_pass = ApplyLayout() diff --git a/test/python/transpiler/test_csp_layout.py b/test/python/transpiler/test_csp_layout.py index f64308099ef6..3e7892e42a93 100644 --- a/test/python/transpiler/test_csp_layout.py +++ b/test/python/transpiler/test_csp_layout.py @@ -1,6 +1,6 @@ # This code is part of Qiskit. # -# (C) Copyright IBM 2019. +# (C) Copyright IBM 2019, 2024. # # 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 @@ -16,13 +16,15 @@ from time import process_time from qiskit import QuantumRegister, QuantumCircuit +from qiskit.providers.fake_provider import GenericBackendV2 from qiskit.transpiler import CouplingMap from qiskit.transpiler.passes import CSPLayout from qiskit.converters import circuit_to_dag -from qiskit.providers.fake_provider import FakeTenerife, FakeRueschlikon, FakeTokyo, FakeYorktownV2 from qiskit.utils import optionals from test import QiskitTestCase # pylint: disable=wrong-import-order +from ..legacy_cmaps import TENERIFE_CMAP, RUESCHLIKON_CMAP, TOKYO_CMAP, YORKTOWN_CMAP + @unittest.skipUnless(optionals.HAS_CONSTRAINT, "needs python-constraint") class TestCSPLayout(QiskitTestCase): @@ -56,8 +58,7 @@ def test_3q_circuit_5q_coupling(self): | / 4 """ - cmap5 = FakeTenerife().configuration().coupling_map - + cmap5 = TENERIFE_CMAP qr = QuantumRegister(3, "qr") circuit = QuantumCircuit(qr) circuit.cx(qr[1], qr[0]) # qr1 -> qr0 @@ -82,7 +83,10 @@ def test_3q_circuit_5q_coupling_with_target(self): | / 4 """ - target = FakeYorktownV2().target + target = GenericBackendV2( + num_qubits=5, + coupling_map=YORKTOWN_CMAP, + ).target qr = QuantumRegister(3, "qr") circuit = QuantumCircuit(qr) @@ -106,7 +110,7 @@ def test_9q_circuit_16q_coupling(self): | | | | | | | | q0[2] - q1[4] -- 14 ---- 13 ---- 12 ---- 11 ---- 10 --- 9 """ - cmap16 = FakeRueschlikon().configuration().coupling_map + cmap16 = RUESCHLIKON_CMAP qr0 = QuantumRegister(4, "q0") qr1 = QuantumRegister(5, "q1") @@ -157,7 +161,7 @@ def test_3q_circuit_5q_coupling_sd(self): ↑ ↙ 4 """ - cmap5 = FakeTenerife().configuration().coupling_map + cmap5 = TENERIFE_CMAP qr = QuantumRegister(3, "qr") circuit = QuantumCircuit(qr) @@ -181,7 +185,7 @@ def test_9q_circuit_16q_coupling_sd(self): ↓ ↑ ↓ ↓ ↑ ↓ ↓ ↑ q0[2] ← q1[4] → 14 ← 13 ← 12 → 11 → 10 ← 9 """ - cmap16 = FakeRueschlikon().configuration().coupling_map + cmap16 = RUESCHLIKON_CMAP qr0 = QuantumRegister(4, "q0") qr1 = QuantumRegister(5, "q1") @@ -213,7 +217,7 @@ def test_5q_circuit_16q_coupling_no_solution(self): q0[0] q0[3] ↙ ↘ q0[4] """ - cmap16 = FakeRueschlikon().configuration().coupling_map + cmap16 = RUESCHLIKON_CMAP qr = QuantumRegister(5, "q") circuit = QuantumCircuit(qr) @@ -269,7 +273,7 @@ def create_hard_dag(): def test_time_limit(self): """Hard to solve situations hit the time limit""" dag = TestCSPLayout.create_hard_dag() - coupling_map = CouplingMap(FakeTokyo().configuration().coupling_map) + coupling_map = CouplingMap(TOKYO_CMAP) pass_ = CSPLayout(coupling_map, call_limit=None, time_limit=1) start = process_time() @@ -282,7 +286,7 @@ def test_time_limit(self): def test_call_limit(self): """Hard to solve situations hit the call limit""" dag = TestCSPLayout.create_hard_dag() - coupling_map = CouplingMap(FakeTokyo().configuration().coupling_map) + coupling_map = CouplingMap(TOKYO_CMAP) pass_ = CSPLayout(coupling_map, call_limit=1, time_limit=None) start = process_time() @@ -297,7 +301,7 @@ def test_seed(self): seed_1 = 42 seed_2 = 43 - cmap5 = FakeTenerife().configuration().coupling_map + cmap5 = TENERIFE_CMAP qr = QuantumRegister(3, "qr") circuit = QuantumCircuit(qr) diff --git a/test/python/transpiler/test_gates_in_basis_pass.py b/test/python/transpiler/test_gates_in_basis_pass.py index 62d6ebd2b54a..2138070ed9d9 100644 --- a/test/python/transpiler/test_gates_in_basis_pass.py +++ b/test/python/transpiler/test_gates_in_basis_pass.py @@ -1,6 +1,6 @@ # This code is part of Qiskit. # -# (C) Copyright IBM 2021 +# (C) Copyright IBM 2021, 2024. # # 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 @@ -21,7 +21,7 @@ from qiskit.transpiler.passes import BasisTranslator from qiskit.transpiler.passes import GatesInBasis from qiskit.transpiler.target import Target -from qiskit.providers.fake_provider.fake_backend_v2 import FakeBackend5QV2 +from qiskit.providers.fake_provider import GenericBackendV2 from test import QiskitTestCase # pylint: disable=wrong-import-order @@ -98,7 +98,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 = GenericBackendV2(num_qubits=5, basis_gates=["u", "cx"]).target basis_gates = ["cx", "u"] # not used property_set = {} analysis_pass = GatesInBasis(basis_gates, target=target) @@ -111,7 +111,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 = GenericBackendV2(num_qubits=5, basis_gates=["u", "cx"]).target basis_gates = ["cx", "h"] property_set = {} analysis_pass = GatesInBasis(basis_gates, target=target) @@ -124,7 +124,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 = GenericBackendV2(num_qubits=5, basis_gates=["u", "cx"]).target basis_gates = ["ecr", "cx", "h"] property_set = {} analysis_pass = GatesInBasis(basis_gates, target=target) @@ -137,7 +137,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 = GenericBackendV2(num_qubits=5, basis_gates=["u", "cx"]).target basis_gates = ["cx", "u"] property_set = {} analysis_pass = GatesInBasis(basis_gates, target=target) @@ -190,7 +190,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 = GenericBackendV2(num_qubits=5, basis_gates=["u", "cx"]).target basis_gates = ["cx", "u"] property_set = {} analysis_pass = GatesInBasis(basis_gates, target) diff --git a/test/python/transpiler/test_high_level_synthesis.py b/test/python/transpiler/test_high_level_synthesis.py index beb94658e54c..b4f997525ad7 100644 --- a/test/python/transpiler/test_high_level_synthesis.py +++ b/test/python/transpiler/test_high_level_synthesis.py @@ -58,7 +58,7 @@ PowerModifier, ) from qiskit.quantum_info import Operator -from qiskit.providers.fake_provider.fake_backend_v2 import FakeBackend5QV2 +from qiskit.providers.fake_provider import GenericBackendV2 from qiskit.circuit.library.standard_gates.equivalence_library import ( StandardEquivalenceLibrary as std_eqlib, ) @@ -471,7 +471,12 @@ def test_target_gets_passed_to_plugins(self): ): hls_config = HLSConfig(op_a=["needs_coupling_map"]) pm_good = PassManager( - [HighLevelSynthesis(hls_config=hls_config, target=FakeBackend5QV2().target)] + [ + HighLevelSynthesis( + hls_config=hls_config, + target=GenericBackendV2(num_qubits=5, basis_gates=["u", "cx"]).target, + ) + ] ) # HighLevelSynthesis is initialized with target. @@ -1039,7 +1044,7 @@ def test_control_high_level_object(self): annotated_linear_function = AnnotatedOperation(linear_function, ControlModifier(1)) qc = QuantumCircuit(3) qc.append(annotated_linear_function, [0, 1, 2]) - backend = FakeBackend5QV2() + backend = GenericBackendV2(num_qubits=5, basis_gates=["u", "cx"]) qct = HighLevelSynthesis(target=backend.target)(qc) self.assertEqual(Operator(qc), Operator(qct)) @@ -1052,7 +1057,7 @@ def test_transpile_control_high_level_object(self): annotated_linear_function = AnnotatedOperation(linear_function, ControlModifier(1)) qc = QuantumCircuit(3) qc.append(annotated_linear_function, [0, 1, 2]) - backend = FakeBackend5QV2() + backend = GenericBackendV2(num_qubits=5, basis_gates=["u", "cx"]) qct = transpile(qc, target=backend.target) ops = qct.count_ops().keys() for op in ops: @@ -1067,7 +1072,7 @@ def test_inverse_high_level_object(self): annotated_linear_function = AnnotatedOperation(linear_function, InverseModifier()) qc = QuantumCircuit(3) qc.append(annotated_linear_function, [0, 1]) - backend = FakeBackend5QV2() + backend = GenericBackendV2(num_qubits=5, basis_gates=["u", "cx"]) qct = HighLevelSynthesis(target=backend.target)(qc) self.assertEqual(Operator(qc), Operator(qct)) @@ -1080,7 +1085,7 @@ def test_transpile_inverse_high_level_object(self): annotated_linear_function = AnnotatedOperation(linear_function, InverseModifier()) qc = QuantumCircuit(3) qc.append(annotated_linear_function, [0, 1]) - backend = FakeBackend5QV2() + backend = GenericBackendV2(num_qubits=5, basis_gates=["u", "cx"]) qct = transpile(qc, target=backend.target) ops = qct.count_ops().keys() for op in ops: @@ -1095,7 +1100,7 @@ def test_power_high_level_object(self): annotated_linear_function = AnnotatedOperation(linear_function, PowerModifier(3)) qc = QuantumCircuit(3) qc.append(annotated_linear_function, [0, 1]) - backend = FakeBackend5QV2() + backend = GenericBackendV2(num_qubits=5, basis_gates=["u", "cx"]) qct = HighLevelSynthesis(target=backend.target)(qc) self.assertEqual(Operator(qc), Operator(qct)) @@ -1108,7 +1113,7 @@ def test_transpile_power_high_level_object(self): annotated_linear_function = AnnotatedOperation(linear_function, PowerModifier(3)) qc = QuantumCircuit(3) qc.append(annotated_linear_function, [0, 1]) - backend = FakeBackend5QV2() + backend = GenericBackendV2(num_qubits=5, basis_gates=["u", "cx"]) qct = transpile(qc, target=backend.target) ops = qct.count_ops().keys() for op in ops: diff --git a/test/python/transpiler/test_normalize_rx_angle.py b/test/python/transpiler/test_normalize_rx_angle.py index be653f64a99a..6f1c7f22ea76 100644 --- a/test/python/transpiler/test_normalize_rx_angle.py +++ b/test/python/transpiler/test_normalize_rx_angle.py @@ -1,6 +1,6 @@ # This code is part of Qiskit. # -# (C) Copyright IBM 2023. +# (C) Copyright IBM 2023, 2024. # # 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 @@ -20,7 +20,7 @@ from qiskit.transpiler.passes.optimization.normalize_rx_angle import ( NormalizeRXAngle, ) -from qiskit.providers.fake_provider import FakeBelemV2 +from qiskit.providers.fake_provider import GenericBackendV2 from qiskit.transpiler import Target from qiskit.circuit.library.standard_gates import SXGate from test import QiskitTestCase # pylint: disable=wrong-import-order @@ -59,7 +59,7 @@ def test_rz_added_for_negative_rotation_angles(self): """Check that RZ is added before and after RX, if RX rotation angle is negative""" - backend = FakeBelemV2() + backend = GenericBackendV2(num_qubits=5) tp = NormalizeRXAngle(target=backend.target) # circuit to transpile and test @@ -82,7 +82,7 @@ def test_rz_added_for_negative_rotation_angles(self): ) def test_angle_wrapping_works(self, raw_theta, correct_wrapped_theta): """Check that RX rotation angles are correctly wrapped to [0, pi]""" - backend = FakeBelemV2() + backend = GenericBackendV2(num_qubits=5) tp = NormalizeRXAngle(target=backend.target) # circuit to transpile and test @@ -117,7 +117,7 @@ def test_quantize_angles(self, resolution, rx_angles, correct_num_of_cals): """Test that quantize_angles() adds a new calibration only if the requested angle is not in the vicinity of the already generated angles. """ - backend = FakeBelemV2() + backend = GenericBackendV2(num_qubits=5) tp = NormalizeRXAngle(backend.target, resolution_in_radian=resolution) qc = QuantumCircuit(1) diff --git a/test/python/transpiler/test_parameterizedgate_translator.py b/test/python/transpiler/test_parameterizedgate_translator.py index 94ea3f8a287f..4afe5990d9dc 100644 --- a/test/python/transpiler/test_parameterizedgate_translator.py +++ b/test/python/transpiler/test_parameterizedgate_translator.py @@ -1,6 +1,6 @@ # This code is part of Qiskit. # -# (C) Copyright IBM 2022. +# (C) Copyright IBM 2022, 2024. # # 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 @@ -18,7 +18,7 @@ from qiskit.circuit.library import TwoLocal from qiskit.exceptions import QiskitError from qiskit.transpiler.passes import TranslateParameterizedGates -from qiskit.providers.fake_provider import FakeAthensV2 +from qiskit.providers.fake_provider import GenericBackendV2 from test import QiskitTestCase # pylint: disable=wrong-import-order @@ -64,7 +64,7 @@ def test_only_parameterized_is_unrolled(self): def test_target(self): """Test unrolling with a target.""" - target = FakeAthensV2().target + target = GenericBackendV2(num_qubits=5).target circuit = TwoLocal(2, "rz", "cx", reps=2, entanglement="linear") translator = TranslateParameterizedGates(target=target) diff --git a/test/python/transpiler/test_passmanager_config.py b/test/python/transpiler/test_passmanager_config.py index 5fa511a20d8f..1b0e8698d7e8 100644 --- a/test/python/transpiler/test_passmanager_config.py +++ b/test/python/transpiler/test_passmanager_config.py @@ -1,6 +1,6 @@ # This code is part of Qiskit. # -# (C) Copyright IBM 2017, 2023. +# (C) Copyright IBM 2017, 2024. # # 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 @@ -14,7 +14,7 @@ from qiskit import QuantumRegister from qiskit.providers.backend import Backend -from qiskit.providers.fake_provider import FakeMelbourne, FakeArmonk, FakeHanoi, FakeHanoiV2 +from qiskit.providers.fake_provider import FakeMelbourne, FakeArmonk, FakeHanoi, GenericBackendV2 from qiskit.transpiler.coupling import CouplingMap from qiskit.transpiler.passmanager_config import PassManagerConfig from test import QiskitTestCase # pylint: disable=wrong-import-order @@ -39,7 +39,7 @@ def test_config_from_backend(self): def test_config_from_backend_v2(self): """Test from_backend() with a BackendV2 instance.""" - backend = FakeHanoiV2() + backend = GenericBackendV2(num_qubits=27) config = PassManagerConfig.from_backend(backend) self.assertEqual(config.basis_gates, backend.operation_names) self.assertEqual(config.inst_map, backend.instruction_schedule_map) diff --git a/test/python/transpiler/test_pulse_gate_pass.py b/test/python/transpiler/test_pulse_gate_pass.py index d793f422150d..d8ed71710a91 100644 --- a/test/python/transpiler/test_pulse_gate_pass.py +++ b/test/python/transpiler/test_pulse_gate_pass.py @@ -1,6 +1,6 @@ # This code is part of Qiskit. # -# (C) Copyright IBM 2021. +# (C) Copyright IBM 2021, 2024. # # 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 @@ -15,10 +15,12 @@ import ddt from qiskit import pulse, circuit, transpile -from qiskit.providers.fake_provider import FakeAthens, FakeAthensV2 +from qiskit.providers.fake_provider import FakeAthens, GenericBackendV2 from qiskit.quantum_info.random import random_unitary from test import QiskitTestCase # pylint: disable=wrong-import-order +from ..legacy_cmaps import BOGOTA_CMAP + @ddt.ddt class TestPulseGate(QiskitTestCase): @@ -69,8 +71,12 @@ def test_transpile_with_bare_backend(self): def test_transpile_with_backend_target(self): """Test transpile without custom calibrations from target.""" - backend = FakeAthensV2() - target = backend.target + + target = GenericBackendV2( + num_qubits=5, + coupling_map=BOGOTA_CMAP, + calibrate_instructions=True, + ).target qc = circuit.QuantumCircuit(2) qc.sx(0) @@ -109,8 +115,12 @@ def test_transpile_with_custom_basis_gate(self): def test_transpile_with_custom_basis_gate_in_target(self): """Test transpile with custom calibrations.""" - backend = FakeAthensV2() - target = backend.target + target = GenericBackendV2( + num_qubits=5, + coupling_map=BOGOTA_CMAP, + calibrate_instructions=FakeAthens().defaults().instruction_schedule_map, + ).target + target["sx"][(0,)].calibration = self.custom_sx_q0 target["sx"][(1,)].calibration = self.custom_sx_q1 @@ -282,7 +292,12 @@ def test_transpile_with_both_instmap_and_empty_target(self, opt_level): instmap.add("cx", (0, 1), self.custom_cx_q01) # This doesn't have custom schedule definition - target = FakeAthensV2().target + target = GenericBackendV2( + num_qubits=5, + coupling_map=BOGOTA_CMAP, + calibrate_instructions=FakeAthens().defaults().instruction_schedule_map, + seed=42, + ).target qc = circuit.QuantumCircuit(2) qc.append(random_unitary(4, seed=123), [0, 1]) @@ -322,9 +337,14 @@ def test_transpile_with_instmap_with_v2backend(self, opt_level): qc.append(random_unitary(4, seed=123), [0, 1]) qc.measure_all() + backend = GenericBackendV2( + num_qubits=5, + calibrate_instructions=FakeAthens().defaults().instruction_schedule_map, + ) + transpiled_qc = transpile( qc, - FakeAthensV2(), + backend, optimization_level=opt_level, inst_map=instmap, initial_layout=[0, 1], @@ -361,9 +381,13 @@ def test_transpile_with_instmap_with_v2backend_with_custom_gate(self, opt_level) qc.append(gate, [0]) qc.measure_all() + backend = GenericBackendV2( + num_qubits=5, + calibrate_instructions=True, + ) transpiled_qc = transpile( qc, - FakeAthensV2(), + backend, optimization_level=opt_level, inst_map=instmap, initial_layout=[0], @@ -383,7 +407,10 @@ def test_transpile_with_instmap_not_mutate_backend(self): This should not override the source object since the same backend may be used for future transpile without intention of instruction overriding. """ - backend = FakeAthensV2() + backend = GenericBackendV2( + num_qubits=5, + calibrate_instructions=True, + ) original_sx0 = backend.target["sx"][(0,)].calibration instmap = FakeAthens().defaults().instruction_schedule_map @@ -395,7 +422,7 @@ def test_transpile_with_instmap_not_mutate_backend(self): transpiled_qc = transpile( qc, - FakeAthensV2(), + backend, inst_map=instmap, initial_layout=[0], ) diff --git a/test/python/transpiler/test_sabre_layout.py b/test/python/transpiler/test_sabre_layout.py index eca7ed109136..0ad0e833be6d 100644 --- a/test/python/transpiler/test_sabre_layout.py +++ b/test/python/transpiler/test_sabre_layout.py @@ -1,6 +1,6 @@ # This code is part of Qiskit. # -# (C) Copyright IBM 2017, 2020. +# (C) Copyright IBM 2017, 2024. # # 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 @@ -23,7 +23,7 @@ from qiskit.transpiler.exceptions import TranspilerError from qiskit.converters import circuit_to_dag from qiskit.compiler.transpiler import transpile -from qiskit.providers.fake_provider import FakeAlmaden, FakeAlmadenV2 +from qiskit.providers.fake_provider import FakeAlmaden, GenericBackendV2 from qiskit.providers.fake_provider import FakeKolkata from qiskit.providers.fake_provider import FakeMontreal from qiskit.transpiler.passes.layout.sabre_pre_layout import SabrePreLayout @@ -160,7 +160,7 @@ def test_6q_circuit_20q_coupling_with_target(self): circuit.cx(qr1[1], qr0[0]) dag = circuit_to_dag(circuit) - target = FakeAlmadenV2().target + target = GenericBackendV2(num_qubits=20, coupling_map=self.cmap20).target pass_ = SabreLayout(target, seed=0, swap_trials=32, layout_trials=32) pass_.run(dag) @@ -422,7 +422,8 @@ def test_starting_layout(self): def test_integration_with_pass_manager(self): """Tests SabrePreLayoutIntegration with the rest of PassManager pipeline.""" - backend = FakeAlmadenV2() + cmap20 = FakeAlmaden().configuration().coupling_map + backend = GenericBackendV2(num_qubits=20, coupling_map=cmap20, seed=42) pm = generate_preset_pass_manager( 0, backend, layout_method="sabre", routing_method="sabre", seed_transpiler=0 ) diff --git a/test/python/transpiler/test_sabre_swap.py b/test/python/transpiler/test_sabre_swap.py index 5c648956c9cd..04482abe50f5 100644 --- a/test/python/transpiler/test_sabre_swap.py +++ b/test/python/transpiler/test_sabre_swap.py @@ -1,6 +1,6 @@ # This code is part of Qiskit. # -# (C) Copyright IBM 2017, 2020. +# (C) Copyright IBM 2017, 2024. # # 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 @@ -24,7 +24,7 @@ from qiskit.circuit.random import random_circuit from qiskit.compiler.transpiler import transpile from qiskit.converters import circuit_to_dag, dag_to_circuit -from qiskit.providers.fake_provider import FakeMumbai, FakeMumbaiV2 +from qiskit.providers.fake_provider import FakeMumbai, GenericBackendV2 from qiskit.transpiler.passes import SabreSwap, TrivialLayout, CheckMap from qiskit.transpiler import CouplingMap, Layout, PassManager, Target, TranspilerError from qiskit import ClassicalRegister, QuantumRegister, QuantumCircuit @@ -32,6 +32,8 @@ from test.utils._canonical import canonicalize_control_flow # pylint: disable=wrong-import-order from test import QiskitTestCase # pylint: disable=wrong-import-order +from ..legacy_cmaps import MUMBAI_CMAP + def looping_circuit(uphill_swaps=1, additional_local_minimum_gates=0): """A circuit that causes SabreSwap to loop infinitely. @@ -1325,6 +1327,7 @@ class TestSabreSwapRandomCircuitValidOutput(QiskitTestCase): def setUpClass(cls): super().setUpClass() cls.backend = FakeMumbai() + cls.backend.configuration().coupling_map = MUMBAI_CMAP cls.coupling_edge_set = {tuple(x) for x in cls.backend.configuration().coupling_map} cls.basis_gates = set(cls.backend.configuration().basis_gates) cls.basis_gates.update(["for_loop", "while_loop", "if_else"]) @@ -1385,7 +1388,7 @@ def test_random_circuit_no_control_flow_target(self, size): routing_method="sabre", layout_method="sabre", seed_transpiler=12342, - target=FakeMumbaiV2().target, + target=GenericBackendV2(num_qubits=27, coupling_map=MUMBAI_CMAP).target, ) self.assert_valid_circuit(tqc) diff --git a/test/python/transpiler/test_stochastic_swap.py b/test/python/transpiler/test_stochastic_swap.py index 4a80ad1c6635..ae3530bf3e3e 100644 --- a/test/python/transpiler/test_stochastic_swap.py +++ b/test/python/transpiler/test_stochastic_swap.py @@ -1,6 +1,6 @@ # This code is part of Qiskit. # -# (C) Copyright IBM 2017, 2018. +# (C) Copyright IBM 2017, 2024. # # 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 @@ -24,13 +24,15 @@ from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit from qiskit.transpiler.passes.utils import CheckMap from qiskit.circuit.random import random_circuit -from qiskit.providers.fake_provider import FakeMumbai, FakeMumbaiV2 +from qiskit.providers.fake_provider import FakeMumbai, GenericBackendV2 from qiskit.compiler.transpiler import transpile from qiskit.circuit import ControlFlowOp, Clbit, CASE_DEFAULT from qiskit.circuit.classical import expr from test import QiskitTestCase # pylint: disable=wrong-import-order from test.utils._canonical import canonicalize_control_flow # pylint: disable=wrong-import-order +from ..legacy_cmaps import MUMBAI_CMAP, RUESCHLIKON_CMAP + @ddt class TestStochasticSwap(QiskitTestCase): @@ -370,33 +372,7 @@ def test_already_mapped(self): """Circuit not remapped if matches topology. See: https://github.com/Qiskit/qiskit-terra/issues/342 """ - coupling = CouplingMap( - [ - [1, 0], - [1, 2], - [2, 3], - [3, 4], - [3, 14], - [5, 4], - [6, 5], - [6, 7], - [6, 11], - [7, 10], - [8, 7], - [9, 8], - [9, 10], - [11, 10], - [12, 5], - [12, 11], - [12, 13], - [13, 4], - [13, 14], - [15, 0], - [15, 0], - [15, 2], - [15, 14], - ] - ) + coupling = CouplingMap(RUESCHLIKON_CMAP) qr = QuantumRegister(16, "q") cr = ClassicalRegister(16, "c") circ = QuantumCircuit(qr, cr) @@ -1531,7 +1507,10 @@ def test_random_circuit_no_control_flow_target(self, size): routing_method="stochastic", layout_method="dense", seed_transpiler=12342, - target=FakeMumbaiV2().target, + target=GenericBackendV2( + num_qubits=27, + coupling_map=MUMBAI_CMAP, + ).target, ) self.assert_valid_circuit(tqc) diff --git a/test/python/transpiler/test_target.py b/test/python/transpiler/test_target.py index 0b3a13de0461..1081036f5011 100644 --- a/test/python/transpiler/test_target.py +++ b/test/python/transpiler/test_target.py @@ -1,6 +1,6 @@ # This code is part of Qiskit. # -# (C) Copyright IBM 2021. +# (C) Copyright IBM 2021, 2024. # # 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 @@ -13,6 +13,7 @@ # pylint: disable=missing-docstring import math +import numpy as np from qiskit.circuit.library import ( RZGate, @@ -43,11 +44,10 @@ from qiskit.transpiler import Target from qiskit.transpiler import InstructionProperties from qiskit.providers.fake_provider import ( - FakeBackendV2, + GenericBackendV2, FakeMumbaiFractionalCX, FakeVigo, FakeNairobi, - FakeGeneva, ) from test import QiskitTestCase # pylint: disable=wrong-import-order @@ -55,10 +55,39 @@ class TestTarget(QiskitTestCase): def setUp(self): super().setUp() - self.fake_backend = FakeBackendV2() - self.fake_backend_target = self.fake_backend.target self.theta = Parameter("theta") self.phi = Parameter("phi") + self.lam = Parameter("lam") + self.fake_backend = GenericBackendV2(num_qubits=2, basis_gates=[]) + self.fake_backend_target = self.fake_backend.target + + # GenericBackendV2 is limited to the standard gate library, and doesn't + # let you pick which gates go to which qubits (beyond a general coupling + # map), so the instructions are added to the target manually. + rx_30_props = { + (0,): InstructionProperties(duration=1.23e-8, error=0.00018115), + (1,): InstructionProperties(duration=1.52e-8, error=0.00012115), + } + self.fake_backend_target.add_instruction(RXGate(np.pi / 6), rx_30_props, name="rx_30") + rx_props = { + (0,): InstructionProperties(duration=5.23e-8, error=0.00038115), + (1,): InstructionProperties(duration=4.52e-8, error=0.00032115), + } + self.fake_backend_target.add_instruction(RXGate(self.theta), rx_props) + u_props = { + (0,): InstructionProperties(duration=5.23e-8, error=0.00038115), + (1,): InstructionProperties(duration=4.52e-8, error=0.00032115), + } + self.fake_backend_target.add_instruction(UGate(self.theta, self.phi, self.lam), u_props) + cx_props = { + (0, 1): InstructionProperties(duration=5.23e-7, error=0.00098115), + } + self.fake_backend_target.add_instruction(CXGate(), cx_props) + ecr_props = { + (1, 0): InstructionProperties(duration=4.52e-9, error=0.0000132115), + } + self.fake_backend_target.add_instruction(ECRGate(), ecr_props) + self.ibm_target = Target() i_props = { (0,): InstructionProperties(duration=35.5e-9, error=0.000413), @@ -178,7 +207,6 @@ def setUp(self): self.aqt_target.add_instruction(Measure(), measure_props) self.empty_target = Target() self.ideal_sim_target = Target(num_qubits=3, description="Ideal Simulator") - self.lam = Parameter("lam") for inst in [ UGate(self.theta, self.phi, self.lam), RXGate(self.theta), @@ -269,7 +297,8 @@ def test_instruction_names(self): self.assertEqual(self.ibm_target.operation_names, {"rz", "id", "sx", "x", "cx", "measure"}) self.assertEqual(self.aqt_target.operation_names, {"rz", "ry", "rx", "rxx", "r", "measure"}) self.assertEqual( - self.fake_backend_target.operation_names, {"u", "cx", "measure", "ecr", "rx_30", "rx"} + self.fake_backend_target.operation_names, + {"u", "cx", "measure", "ecr", "rx_30", "rx", "reset", "delay"}, ) self.assertEqual( self.ideal_sim_target.operation_names, @@ -291,12 +320,12 @@ def test_operations(self): for gate in aqt_expected: self.assertIn(gate, self.aqt_target.operations) fake_expected = [ - UGate(self.fake_backend._theta, self.fake_backend._phi, self.fake_backend._lam), + UGate(self.theta, self.phi, self.lam), CXGate(), Measure(), ECRGate(), RXGate(math.pi / 6), - RXGate(self.fake_backend._theta), + RXGate(self.theta), ] for gate in fake_expected: self.assertIn(gate, self.fake_backend_target.operations) @@ -373,10 +402,7 @@ def test_get_instruction_from_name(self): self.empty_target.operation_from_name("measure") self.assertEqual(self.ibm_target.operation_from_name("measure"), Measure()) self.assertEqual(self.fake_backend_target.operation_from_name("rx_30"), RXGate(math.pi / 6)) - self.assertEqual( - self.fake_backend_target.operation_from_name("rx"), - RXGate(self.fake_backend._theta), - ) + self.assertEqual(self.fake_backend_target.operation_from_name("rx"), RXGate(self.theta)) self.assertEqual(self.ideal_sim_target.operation_from_name("ccx"), CCXGate()) def test_get_instructions_for_qargs(self): @@ -538,9 +564,7 @@ def test_coupling_map_no_filter_mutations_do_not_propagate(self): def test_coupling_map_2q_gate(self): cmap = self.fake_backend_target.build_coupling_map("ecr") self.assertEqual( - [ - (1, 0), - ], + [(1, 0)], cmap.get_edges(), ) @@ -1304,7 +1328,7 @@ def test_timing_constraints(self): ) def test_default_instmap_has_no_custom_gate(self): - backend = FakeGeneva() + backend = GenericBackendV2(num_qubits=27, calibrate_instructions=True) target = backend.target # This copies .calibraiton of InstructionProperties of each instruction diff --git a/test/python/transpiler/test_unitary_synthesis.py b/test/python/transpiler/test_unitary_synthesis.py index f2502664f2f8..19fca2dbb1f1 100644 --- a/test/python/transpiler/test_unitary_synthesis.py +++ b/test/python/transpiler/test_unitary_synthesis.py @@ -1,6 +1,6 @@ # This code is part of Qiskit. # -# (C) Copyright IBM 2017, 2019. +# (C) Copyright IBM 2017, 2024. # # 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 @@ -21,8 +21,7 @@ from ddt import ddt, data from qiskit import transpile -from qiskit.providers.fake_provider import FakeVigo, FakeMumbaiFractionalCX, FakeBelemV2 -from qiskit.providers.fake_provider.fake_backend_v2 import FakeBackendV2, FakeBackend5QV2 +from qiskit.providers.fake_provider import FakeVigo, FakeMumbaiFractionalCX, GenericBackendV2 from qiskit.circuit import QuantumCircuit, QuantumRegister, ClassicalRegister from qiskit.circuit.library import QuantumVolume from qiskit.converters import circuit_to_dag, dag_to_circuit @@ -65,6 +64,43 @@ from test import QiskitTestCase # pylint: disable=wrong-import-order +class FakeBackend2QV2(GenericBackendV2): + """A 2-qubit fake backend""" + + def __init__(self): + super().__init__(num_qubits=2, basis_gates=["rx", "u"], seed=42) + cx_props = { + (0, 1): InstructionProperties(duration=5.23e-7, error=0.00098115), + } + self._target.add_instruction(CXGate(), cx_props) + ecr_props = { + (1, 0): InstructionProperties(duration=4.52e-9, error=0.0000132115), + } + self._target.add_instruction(ECRGate(), ecr_props) + + +class FakeBackend5QV2(GenericBackendV2): + """A 5-qubit fake backend""" + + def __init__(self, bidirectional=True): + super().__init__(num_qubits=5, basis_gates=["u"], seed=42) + 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) + 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) + + @ddt class TestUnitarySynthesis(QiskitTestCase): """Test UnitarySynthesis pass.""" @@ -680,7 +716,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 = FakeBackend2QV2() tqc = transpile( circ, backend=backend, @@ -856,7 +892,8 @@ def test_single_qubit_with_target(self): qc = QuantumCircuit(1) qc.append(ZGate(), [qc.qubits[0]]) dag = circuit_to_dag(qc) - unitary_synth_pass = UnitarySynthesis(target=FakeBelemV2().target) + backend = GenericBackendV2(num_qubits=5) + unitary_synth_pass = UnitarySynthesis(target=backend.target) result_dag = unitary_synth_pass.run(dag) result_qc = dag_to_circuit(result_dag) self.assertEqual(qc, result_qc) @@ -866,7 +903,8 @@ def test_single_qubit_identity_with_target(self): qc = QuantumCircuit(1) qc.unitary([[1.0, 0.0], [0.0, 1.0]], 0) dag = circuit_to_dag(qc) - unitary_synth_pass = UnitarySynthesis(target=FakeBelemV2().target) + backend = GenericBackendV2(num_qubits=5) + unitary_synth_pass = UnitarySynthesis(target=backend.target) result_dag = unitary_synth_pass.run(dag) result_qc = dag_to_circuit(result_dag) self.assertEqual(result_qc, QuantumCircuit(1)) @@ -876,7 +914,7 @@ def test_unitary_synthesis_with_ideal_and_variable_width_ops(self): qc = QuantumCircuit(2) qc.unitary(np.eye(4), [0, 1]) dag = circuit_to_dag(qc) - target = FakeBelemV2().target + target = GenericBackendV2(num_qubits=5).target target.add_instruction(IfElseOp, name="if_else") target.add_instruction(ZGate()) target.add_instruction(ECRGate()) diff --git a/test/python/transpiler/test_vf2_layout.py b/test/python/transpiler/test_vf2_layout.py index 9487a00ad86f..09c8e7052644 100644 --- a/test/python/transpiler/test_vf2_layout.py +++ b/test/python/transpiler/test_vf2_layout.py @@ -1,6 +1,6 @@ # This code is part of Qiskit. # -# (C) Copyright IBM 2021. +# (C) Copyright IBM 2021, 2024. # # 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 @@ -28,12 +28,9 @@ from qiskit._accelerate.error_map import ErrorMap from qiskit.converters import circuit_to_dag from qiskit.providers.fake_provider import ( - FakeTenerife, - FakeVigoV2, - FakeRueschlikon, - FakeManhattan, FakeYorktown, - FakeGuadalupeV2, + FakeManhattan, + GenericBackendV2, ) from qiskit.circuit import Measure from qiskit.circuit.library import GraphState, CXGate, XGate, HGate @@ -42,6 +39,8 @@ from qiskit.transpiler.preset_passmanagers.common import generate_embed_passmanager from test import QiskitTestCase # pylint: disable=wrong-import-order +from ..legacy_cmaps import TENERIFE_CMAP, RUESCHLIKON_CMAP + class LayoutTestCase(QiskitTestCase): """VF2Layout assertions""" @@ -332,7 +331,7 @@ def test_5q_circuit_Rueschlikon_no_solution(self): q0[0] q0[3] ↙ ↘ q0[4] """ - cmap16 = FakeRueschlikon().configuration().coupling_map + cmap16 = RUESCHLIKON_CMAP qr = QuantumRegister(5, "q") circuit = QuantumCircuit(qr) @@ -356,7 +355,7 @@ def test_9q_circuit_Rueschlikon_sd(self): ↓ ↑ ↓ ↓ ↑ ↓ ↓ ↑ 0 ← 15 → 14 ← 13 ← 12 → 11 → 10 ← 9 """ - cmap16 = CouplingMap(FakeRueschlikon().configuration().coupling_map) + cmap16 = CouplingMap(RUESCHLIKON_CMAP) qr0 = QuantumRegister(4, "q0") qr1 = QuantumRegister(5, "q1") @@ -379,7 +378,7 @@ def test_4q_circuit_Tenerife_loose_nodes(self): ↑ ↙ 4 """ - cmap5 = CouplingMap(FakeTenerife().configuration().coupling_map) + cmap5 = CouplingMap(TENERIFE_CMAP) qr = QuantumRegister(4, "q") circuit = QuantumCircuit(qr) @@ -399,7 +398,7 @@ def test_3q_circuit_Tenerife_sd(self): ↑ ↙ ↑ ↙ 4 qr0 """ - cmap5 = CouplingMap(FakeTenerife().configuration().coupling_map) + cmap5 = CouplingMap(TENERIFE_CMAP) qr = QuantumRegister(3, "qr") circuit = QuantumCircuit(qr) @@ -423,7 +422,7 @@ def test_9q_circuit_Rueschlikon(self): | | | | | | | | q1_2 - q1_3 - q0_0 - 13 - q0_3 - 11 - q1_4 - q0_2 """ - cmap16 = CouplingMap(FakeRueschlikon().configuration().coupling_map) + cmap16 = CouplingMap(RUESCHLIKON_CMAP) qr0 = QuantumRegister(4, "q0") qr1 = QuantumRegister(5, "q1") @@ -446,7 +445,7 @@ def test_3q_circuit_Tenerife(self): ↑ ↙ | / 4 qr0 """ - cmap5 = CouplingMap(FakeTenerife().configuration().coupling_map) + cmap5 = CouplingMap(TENERIFE_CMAP) qr = QuantumRegister(3, "q") circuit = QuantumCircuit(qr) @@ -461,7 +460,7 @@ def test_3q_circuit_Tenerife(self): def test_3q_circuit_vigo_with_custom_scores(self): """Test custom ErrorMap from analysis pass are used for scoring.""" - backend = FakeVigoV2() + backend = GenericBackendV2(num_qubits=5, seed=42) target = backend.target class FakeScore(AnalysisPass): @@ -534,7 +533,7 @@ def test_seed(self): seed_1 = 42 seed_2 = 45 - cmap5 = FakeTenerife().configuration().coupling_map + cmap5 = TENERIFE_CMAP qr = QuantumRegister(3, "qr") circuit = QuantumCircuit(qr) @@ -563,7 +562,7 @@ def test_3_q_gate(self): """The pass does not handle gates with more than 2 qubits""" seed_1 = 42 - cmap5 = FakeTenerife().configuration().coupling_map + cmap5 = TENERIFE_CMAP qr = QuantumRegister(3, "qr") circuit = QuantumCircuit(qr) @@ -716,7 +715,9 @@ def test_qregs_valid_layout_output(self): Reproduce from https://github.com/Qiskit/qiskit-terra/issues/8667 """ - backend = FakeGuadalupeV2() + backend = GenericBackendV2( + basis_gates=["cx", "id", "rz", "sx", "x"], num_qubits=16, seed=42 + ) qr = QuantumRegister(16, name="qr") cr = ClassicalRegister(5) qc = QuantumCircuit(qr, cr) diff --git a/test/python/transpiler/test_vf2_post_layout.py b/test/python/transpiler/test_vf2_post_layout.py index 1fb5021a446b..fb1e3dd5324c 100644 --- a/test/python/transpiler/test_vf2_post_layout.py +++ b/test/python/transpiler/test_vf2_post_layout.py @@ -1,6 +1,6 @@ # This code is part of Qiskit. # -# (C) Copyright IBM 2021. +# (C) Copyright IBM 2021, 2024. # # 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 @@ -20,12 +20,14 @@ from qiskit.transpiler import CouplingMap, Layout, TranspilerError from qiskit.transpiler.passes.layout.vf2_post_layout import VF2PostLayout, VF2PostLayoutStopReason from qiskit.converters import circuit_to_dag -from qiskit.providers.fake_provider import FakeLima, FakeYorktown, FakeLimaV2, FakeYorktownV2 +from qiskit.providers.fake_provider import FakeLima, FakeYorktown, GenericBackendV2 from qiskit.circuit import Qubit from qiskit.compiler.transpiler import transpile from qiskit.transpiler.target import Target, InstructionProperties from test import QiskitTestCase # pylint: disable=wrong-import-order +from ..legacy_cmaps import LIMA_CMAP, YORKTOWN_CMAP + class TestVF2PostLayout(QiskitTestCase): """Tests the VF2Layout pass""" @@ -114,8 +116,10 @@ def test_empty_circuit(self): def test_empty_circuit_v2(self): """Test no solution found for empty circuit with v2 backend""" qc = QuantumCircuit(2, 2) - backend = FakeLimaV2() - vf2_pass = VF2PostLayout(target=backend.target) + target = GenericBackendV2( + num_qubits=5, basis_gates=["cx", "id", "rz", "sx", "x"], coupling_map=LIMA_CMAP, seed=42 + ).target + vf2_pass = VF2PostLayout(target=target) vf2_pass.run(circuit_to_dag(qc)) self.assertEqual( vf2_pass.property_set["VF2PostLayout_stop_reason"], @@ -153,8 +157,10 @@ def test_skip_3q_circuit_v2(self): """Test that the pass is a no-op on circuits with >2q gates with a target.""" qc = QuantumCircuit(3) qc.ccx(0, 1, 2) - backend = FakeLimaV2() - vf2_pass = VF2PostLayout(target=backend.target) + target = GenericBackendV2( + num_qubits=5, basis_gates=["cx", "id", "rz", "sx", "x"], coupling_map=LIMA_CMAP, seed=42 + ).target + vf2_pass = VF2PostLayout(target=target) vf2_pass.run(circuit_to_dag(qc)) self.assertEqual( vf2_pass.property_set["VF2PostLayout_stop_reason"], VF2PostLayoutStopReason.MORE_THAN_2Q @@ -165,8 +171,10 @@ def test_skip_3q_circuit_control_flow_v2(self): qc = QuantumCircuit(3) with qc.for_loop((1,)): qc.ccx(0, 1, 2) - backend = FakeLimaV2() - vf2_pass = VF2PostLayout(target=backend.target) + target = GenericBackendV2( + num_qubits=5, basis_gates=["cx", "id", "rz", "sx", "x"], coupling_map=LIMA_CMAP, seed=42 + ).target + vf2_pass = VF2PostLayout(target=target) vf2_pass.run(circuit_to_dag(qc)) self.assertEqual( vf2_pass.property_set["VF2PostLayout_stop_reason"], VF2PostLayoutStopReason.MORE_THAN_2Q @@ -274,7 +282,12 @@ def test_2q_circuit_5q_backend_max_trials(self): def test_best_mapping_ghz_state_full_device_multiple_qregs_v2(self): """Test best mappings with multiple registers""" - backend = FakeLimaV2() + backend = GenericBackendV2( + num_qubits=5, + basis_gates=["cx", "id", "rz", "sx", "x"], + coupling_map=LIMA_CMAP, + seed=123, + ) qr_a = QuantumRegister(2) qr_b = QuantumRegister(3) qc = QuantumCircuit(qr_a, qr_b) @@ -297,7 +310,12 @@ def test_2q_circuit_5q_backend_v2(self): 0 - 1 qr1 - qr0 """ - backend = FakeYorktownV2() + backend = GenericBackendV2( + num_qubits=5, + basis_gates=["cx", "id", "rz", "sx", "x"], + coupling_map=YORKTOWN_CMAP, + seed=42, + ) qr = QuantumRegister(2, "qr") circuit = QuantumCircuit(qr) @@ -315,7 +333,12 @@ def test_2q_circuit_5q_backend_v2_control_flow(self): 0 - 1 qr1 - qr0 """ - backend = FakeYorktownV2() + target = GenericBackendV2( + num_qubits=5, + basis_gates=["cx", "id", "rz", "sx", "x"], + coupling_map=YORKTOWN_CMAP, + seed=42, + ).target circuit = QuantumCircuit(2, 1) with circuit.for_loop((1,)): @@ -328,18 +351,23 @@ def test_2q_circuit_5q_backend_v2_control_flow(self): initial_layout = Layout(dict(enumerate(circuit.qubits))) circuit._layout = initial_layout dag = circuit_to_dag(circuit) - pass_ = VF2PostLayout(target=backend.target, seed=self.seed) + pass_ = VF2PostLayout(target=target, seed=self.seed) pass_.run(dag) - self.assertLayoutV2(dag, backend.target, pass_.property_set) + self.assertLayoutV2(dag, target, pass_.property_set) self.assertNotEqual(pass_.property_set["post_layout"], initial_layout) def test_target_invalid_2q_gate(self): """Test that we don't find a solution with a gate outside target.""" - backend = FakeYorktownV2() + target = GenericBackendV2( + num_qubits=5, + basis_gates=["cx", "id", "rz", "sx", "x"], + coupling_map=YORKTOWN_CMAP, + seed=42, + ).target qc = QuantumCircuit(2) qc.ecr(0, 1) dag = circuit_to_dag(qc) - pass_ = VF2PostLayout(target=backend.target, seed=self.seed) + pass_ = VF2PostLayout(target=target, seed=self.seed) pass_.run(dag) self.assertEqual( pass_.property_set["VF2PostLayout_stop_reason"], @@ -348,12 +376,17 @@ def test_target_invalid_2q_gate(self): def test_target_invalid_2q_gate_control_flow(self): """Test that we don't find a solution with a gate outside target.""" - backend = FakeYorktownV2() + target = GenericBackendV2( + num_qubits=5, + basis_gates=["cx", "id", "rz", "sx", "x"], + coupling_map=YORKTOWN_CMAP, + seed=42, + ).target qc = QuantumCircuit(2) with qc.for_loop((1,)): qc.ecr(0, 1) dag = circuit_to_dag(qc) - pass_ = VF2PostLayout(target=backend.target, seed=self.seed) + pass_ = VF2PostLayout(target=target, seed=self.seed) pass_.run(dag) self.assertEqual( pass_.property_set["VF2PostLayout_stop_reason"], @@ -438,8 +471,13 @@ def test_empty_score(self): bit_map = {} reverse_bit_map = {} im_graph = rustworkx.PyDiGraph() - backend = FakeYorktownV2() - vf2_pass = VF2PostLayout(target=backend.target) + target = GenericBackendV2( + num_qubits=5, + basis_gates=["cx", "id", "rz", "sx", "x"], + coupling_map=YORKTOWN_CMAP, + seed=42, + ).target + vf2_pass = VF2PostLayout(target=target) layout = Layout() score = vf2_pass._score_layout(layout, bit_map, reverse_bit_map, im_graph) self.assertEqual(0, score) @@ -451,8 +489,22 @@ def test_all_1q_score(self): im_graph = rustworkx.PyDiGraph() im_graph.add_node({"sx": 1}) im_graph.add_node({"sx": 1}) - backend = FakeYorktownV2() - vf2_pass = VF2PostLayout(target=backend.target) + + target = GenericBackendV2( + num_qubits=5, + basis_gates=["cx", "id", "rz", "sx", "x"], + coupling_map=YORKTOWN_CMAP, + seed=42, + ).target + + target.update_instruction_properties( + "sx", (0,), InstructionProperties(duration=3.56e-08, error=0.0013043388897769352) + ) + target.update_instruction_properties( + "sx", (1,), InstructionProperties(duration=3.56e-08, error=0.0016225037300878712) + ) + + vf2_pass = VF2PostLayout(target=target) layout = Layout(bit_map) score = vf2_pass._score_layout(layout, bit_map, reverse_bit_map, im_graph) self.assertAlmostEqual(0.002925, score, places=5) @@ -526,8 +578,13 @@ def test_empty_circuit(self): def test_empty_circuit_v2(self): """Test no solution found for empty circuit with v2 backend""" qc = QuantumCircuit(2, 2) - backend = FakeLimaV2() - vf2_pass = VF2PostLayout(target=backend.target, strict_direction=False) + target = GenericBackendV2( + num_qubits=5, + basis_gates=["cx", "id", "rz", "sx", "x"], + coupling_map=LIMA_CMAP, + seed=self.seed, + ).target + vf2_pass = VF2PostLayout(target=target, strict_direction=False) vf2_pass.run(circuit_to_dag(qc)) self.assertEqual( vf2_pass.property_set["VF2PostLayout_stop_reason"], @@ -544,18 +601,25 @@ def test_skip_3q_circuit(self): vf2_pass = VF2PostLayout(coupling_map=cmap, properties=props, strict_direction=False) vf2_pass.run(circuit_to_dag(qc)) self.assertEqual( - vf2_pass.property_set["VF2PostLayout_stop_reason"], VF2PostLayoutStopReason.MORE_THAN_2Q + vf2_pass.property_set["VF2PostLayout_stop_reason"], + VF2PostLayoutStopReason.MORE_THAN_2Q, ) def test_skip_3q_circuit_v2(self): """Test that the pass is a no-op on circuits with >2q gates with a target.""" qc = QuantumCircuit(3) qc.ccx(0, 1, 2) - backend = FakeLimaV2() - vf2_pass = VF2PostLayout(target=backend.target, strict_direction=False) + target = GenericBackendV2( + num_qubits=5, + basis_gates=["cx", "id", "rz", "sx", "x"], + coupling_map=LIMA_CMAP, + seed=self.seed, + ).target + vf2_pass = VF2PostLayout(target=target, strict_direction=False) vf2_pass.run(circuit_to_dag(qc)) self.assertEqual( - vf2_pass.property_set["VF2PostLayout_stop_reason"], VF2PostLayoutStopReason.MORE_THAN_2Q + vf2_pass.property_set["VF2PostLayout_stop_reason"], + VF2PostLayoutStopReason.MORE_THAN_2Q, ) def test_best_mapping_ghz_state_full_device_multiple_qregs(self): @@ -606,7 +670,13 @@ def test_2q_circuit_5q_backend(self): def test_best_mapping_ghz_state_full_device_multiple_qregs_v2(self): """Test best mappings with multiple registers""" - backend = FakeLimaV2() + + backend = GenericBackendV2( + num_qubits=5, + basis_gates=["cx", "id", "rz", "sx", "x"], + coupling_map=LIMA_CMAP, + seed=self.seed, + ) qr_a = QuantumRegister(2) qr_b = QuantumRegister(3) qc = QuantumCircuit(qr_a, qr_b) @@ -629,7 +699,12 @@ def test_2q_circuit_5q_backend_v2(self): 0 - 1 qr1 - qr0 """ - backend = FakeYorktownV2() + backend = GenericBackendV2( + num_qubits=5, + basis_gates=["cx", "id", "rz", "sx", "x"], + coupling_map=YORKTOWN_CMAP, + seed=self.seed, + ) qr = QuantumRegister(2, "qr") circuit = QuantumCircuit(qr)