diff --git a/qiskit/providers/fake_provider/fake_backend.py b/qiskit/providers/fake_provider/fake_backend.py index 4a638f315574..21d221b68c04 100644 --- a/qiskit/providers/fake_provider/fake_backend.py +++ b/qiskit/providers/fake_provider/fake_backend.py @@ -23,7 +23,7 @@ from qiskit.providers import BackendV1 from qiskit import pulse from qiskit.exceptions import QiskitError -from qiskit.utils import optionals as _optionals +from qiskit.utils import optionals as _optionals, deprecate_func from qiskit.providers import basic_provider @@ -39,6 +39,13 @@ def __init__(self, token="123456", url="https://"): class FakeBackend(BackendV1): """This is a dummy backend just for testing purposes.""" + @deprecate_func( + since="1.2", + removal_timeline="in the 2.0 release", + additional_msg="Fake backends using BackendV1 are deprecated in favor of " + ":class:`.GenericBackendV2`. You can convert BackendV1 to " + ":class:`.BackendV2` with :class:`.BackendV2Converter`.", + ) def __init__(self, configuration, time_alive=10): """FakeBackend initializer. diff --git a/qiskit/providers/fake_provider/generic_backend_v2.py b/qiskit/providers/fake_provider/generic_backend_v2.py index c3de76cbd0e6..6374a0b0b60a 100644 --- a/qiskit/providers/fake_provider/generic_backend_v2.py +++ b/qiskit/providers/fake_provider/generic_backend_v2.py @@ -567,18 +567,12 @@ def _setup_sim(self) -> None: @classmethod def _default_options(cls) -> Options: - with warnings.catch_warnings(): # TODO remove catch once aer release without Provider ABC - warnings.filterwarnings( - "ignore", - category=DeprecationWarning, - message=".+abstract Provider and ProviderV1.+", - ) - if _optionals.HAS_AER: - from qiskit_aer import AerSimulator + if _optionals.HAS_AER: + from qiskit_aer import AerSimulator - return AerSimulator._default_options() - else: - return BasicSimulator._default_options() + return AerSimulator._default_options() + else: + return BasicSimulator._default_options() def drive_channel(self, qubit: int): drive_channels_map = getattr(self, "channels_map", {}).get("drive", {}) diff --git a/qiskit/visualization/circuit/_utils.py b/qiskit/visualization/circuit/_utils.py index 2077a3891542..e6ee03905d27 100644 --- a/qiskit/visualization/circuit/_utils.py +++ b/qiskit/visualization/circuit/_utils.py @@ -387,7 +387,7 @@ def _get_valid_justify_arg(justify): warn( f"Setting QuantumCircuit.draw()’s or circuit_drawer()'s justify argument: {justify}, to a " "value other than 'left', 'right', 'none' or None (='left'). Default 'left' will be used. " - "Support for invalid justify arguments is deprecated as of qiskit 1.2.0. Starting no " + "Support for invalid justify arguments is deprecated as of Qiskit 1.2.0. Starting no " "earlier than 3 months after the release date, invalid arguments will error.", DeprecationWarning, 2, diff --git a/test/python/circuit/test_parameters.py b/test/python/circuit/test_parameters.py index 4f989767164f..c2df1a423ec4 100644 --- a/test/python/circuit/test_parameters.py +++ b/test/python/circuit/test_parameters.py @@ -31,10 +31,11 @@ from qiskit.compiler import assemble, transpile from qiskit import pulse from qiskit.quantum_info import Operator -from qiskit.providers.fake_provider import Fake5QV1 +from qiskit.providers.fake_provider import Fake5QV1, GenericBackendV2 from qiskit.providers.basic_provider import BasicSimulator from qiskit.utils import parallel_map from test import QiskitTestCase, combine # pylint: disable=wrong-import-order +from ..legacy_cmaps import BOGOTA_CMAP def raise_if_parameter_table_invalid(circuit): @@ -1074,6 +1075,26 @@ def test_transpiling_multiple_parameterized_circuits(self): self.assertTrue(len(job.result().results), 2) + @data(0, 1, 2, 3) + def test_transpile_across_optimization_levelsV1(self, opt_level): + """Verify parameterized circuits can be transpiled with all default pass managers. + To remove once Fake5QV1 gets removed""" + + qc = QuantumCircuit(5, 5) + + theta = Parameter("theta") + phi = Parameter("phi") + + qc.rx(theta, 0) + qc.x(0) + for i in range(5 - 1): + qc.rxx(phi, i, i + 1) + + qc.measure(range(5 - 1), range(5 - 1)) + with self.assertWarns(DeprecationWarning): + backend = Fake5QV1() + transpile(qc, backend, optimization_level=opt_level) + @data(0, 1, 2, 3) def test_transpile_across_optimization_levels(self, opt_level): """Verify parameterized circuits can be transpiled with all default pass managers.""" @@ -1090,7 +1111,15 @@ def test_transpile_across_optimization_levels(self, opt_level): qc.measure(range(5 - 1), range(5 - 1)) - transpile(qc, Fake5QV1(), optimization_level=opt_level) + transpile( + qc, + GenericBackendV2( + num_qubits=5, + coupling_map=BOGOTA_CMAP, + seed=42, + ), + optimization_level=opt_level, + ) def test_repeated_gates_to_dag_and_back(self): """Verify circuits with repeated parameterized gates can be converted diff --git a/test/python/circuit/test_scheduled_circuit.py b/test/python/circuit/test_scheduled_circuit.py index c3b3158d7b85..c934b5b5e04c 100644 --- a/test/python/circuit/test_scheduled_circuit.py +++ b/test/python/circuit/test_scheduled_circuit.py @@ -33,8 +33,9 @@ class TestScheduledCircuit(QiskitTestCase): def setUp(self): super().setUp() - self.backend_with_dt = Fake27QPulseV1() - self.backend_without_dt = Fake27QPulseV1() + with self.assertWarns(DeprecationWarning): + self.backend_with_dt = Fake27QPulseV1() + self.backend_without_dt = Fake27QPulseV1() delattr(self.backend_without_dt.configuration(), "dt") # Remove timing constraints from the backends (alignment values, # granularity and min_length), so that these values will default @@ -50,21 +51,24 @@ def setUp(self): def test_schedule_circuit_when_backend_tells_dt(self): """dt is known to transpiler by backend""" qc = QuantumCircuit(2) - qc.delay(0.1, 0, unit="ms") # 450000[dt] + qc.delay(0.1, 0, unit="ms") # 450450[dt] qc.delay(100, 0, unit="ns") # 450[dt] - qc.h(0) # 160[dt] - qc.h(1) # 160[dt] - sc = transpile(qc, self.backend_with_dt, scheduling_method="alap", layout_method="trivial") - self.assertEqual(sc.duration, 450546) + qc.h(0) # 195[dt] + qc.h(1) # 210[dt] + + backend = GenericBackendV2(2, calibrate_instructions=True, seed=42) + + sc = transpile(qc, backend, scheduling_method="alap", layout_method="trivial") + self.assertEqual(sc.duration, 451095) self.assertEqual(sc.unit, "dt") self.assertEqual(sc.data[0].operation.name, "delay") - self.assertEqual(sc.data[0].operation.duration, 450450) + self.assertEqual(sc.data[0].operation.duration, 450900) self.assertEqual(sc.data[0].operation.unit, "dt") self.assertEqual(sc.data[1].operation.name, "rz") self.assertEqual(sc.data[1].operation.duration, 0) self.assertEqual(sc.data[1].operation.unit, "dt") self.assertEqual(sc.data[4].operation.name, "delay") - self.assertEqual(sc.data[4].operation.duration, 450450) + self.assertEqual(sc.data[4].operation.duration, 450885) self.assertEqual(sc.data[4].operation.unit, "dt") def test_schedule_circuit_when_transpile_option_tells_dt(self): @@ -301,7 +305,7 @@ def test_convert_duration_to_dt(self): """Test that circuit duration unit conversion is applied only when necessary. Tests fix for bug reported in PR #11782.""" - backend = GenericBackendV2(num_qubits=3, calibrate_instructions=True, seed=10) + backend = GenericBackendV2(num_qubits=3, calibrate_instructions=True, seed=42) schedule_config = ScheduleConfig( inst_map=backend.target.instruction_schedule_map(), meas_map=backend.meas_map, diff --git a/test/python/compiler/test_assembler.py b/test/python/compiler/test_assembler.py index ff1f86f228db..c333ce9ace22 100644 --- a/test/python/compiler/test_assembler.py +++ b/test/python/compiler/test_assembler.py @@ -63,7 +63,8 @@ def setUp(self): self.circ.cx(qr[0], qr[1]) self.circ.measure(qr, cr) - self.backend = Fake5QV1() + with self.assertWarns(DeprecationWarning): + self.backend = Fake5QV1() self.backend_config = self.backend.configuration() self.num_qubits = self.backend_config.n_qubits @@ -591,7 +592,8 @@ def test_pulse_gates_with_parameteric_pulses(self): circ.h(0) circ.add_calibration("h", [0], custom_h_schedule) - backend = FakeOpenPulse2Q() + with self.assertWarns(DeprecationWarning): + backend = FakeOpenPulse2Q() backend.configuration().parametric_pulses = ["drag"] with self.assertWarns(DeprecationWarning): qobj = assemble(circ, backend) @@ -974,7 +976,8 @@ class TestPulseAssembler(QiskitTestCase): def setUp(self): super().setUp() - self.backend = FakeOpenPulse2Q() + with self.assertWarns(DeprecationWarning): + self.backend = FakeOpenPulse2Q() self.backend_config = self.backend.configuration() test_pulse = pulse.Waveform( @@ -1282,7 +1285,8 @@ def test_pulse_name_conflicts(self): def test_pulse_name_conflicts_in_other_schedule(self): """Test two pulses with the same name in different schedule can be resolved.""" - backend = Fake27QPulseV1() + with self.assertWarns(DeprecationWarning): + backend = Fake27QPulseV1() defaults = backend.defaults() schedules = [] @@ -1390,7 +1394,8 @@ def test_assemble_parametric(self): ) << sched.duration ) - backend = FakeOpenPulse3Q() + with self.assertWarns(DeprecationWarning): + backend = FakeOpenPulse3Q() backend.configuration().parametric_pulses = [ "gaussian", "drag", @@ -1437,7 +1442,8 @@ def test_assemble_parametric_unsupported(self): ) sched += Play(pulse.Constant(duration=25, amp=1), DriveChannel(2)) - backend = FakeOpenPulse3Q() + with self.assertWarns(DeprecationWarning): + backend = FakeOpenPulse3Q() backend.configuration().parametric_pulses = ["something_extra"] with self.assertWarns(DeprecationWarning): @@ -1449,7 +1455,8 @@ def test_assemble_parametric_unsupported(self): def test_assemble_parametric_pulse_kwarg_with_backend_setting(self): """Test that parametric pulses respect the kwarg over backend""" - backend = Fake27QPulseV1() + with self.assertWarns(DeprecationWarning): + backend = Fake27QPulseV1() qc = QuantumCircuit(1, 1) qc.x(0) @@ -1465,7 +1472,8 @@ def test_assemble_parametric_pulse_kwarg_with_backend_setting(self): def test_assemble_parametric_pulse_kwarg_empty_list_with_backend_setting(self): """Test that parametric pulses respect the kwarg as empty list over backend""" - backend = Fake27QPulseV1() + with self.assertWarns(DeprecationWarning): + backend = Fake27QPulseV1() qc = QuantumCircuit(1, 1) qc.x(0) @@ -1822,7 +1830,8 @@ def setUp(self): super().setUp() self.schedule = pulse.Schedule(name="fake_experiment") - self.backend = FakeOpenPulse2Q() + with self.assertWarns(DeprecationWarning): + self.backend = FakeOpenPulse2Q() self.config = self.backend.configuration() self.defaults = self.backend.defaults() self.qubit_lo_freq = list(self.defaults.qubit_freq_est) @@ -1963,7 +1972,8 @@ def test_missing_lo_ranges(self): def test_unsupported_meas_level(self): """Test that assembly raises an error if meas_level is not supported""" - backend = FakeOpenPulse2Q() + with self.assertWarns(DeprecationWarning): + backend = FakeOpenPulse2Q() backend.configuration().meas_levels = [1, 2] with self.assertRaises(QiskitError), self.assertWarns(DeprecationWarning): assemble( @@ -1983,7 +1993,8 @@ def test_unsupported_meas_level(self): def test_single_and_deprecated_acquire_styles(self): """Test that acquires are identically combined with Acquires that take a single channel.""" - backend = FakeOpenPulse2Q() + with self.assertWarns(DeprecationWarning): + backend = FakeOpenPulse2Q() new_style_schedule = Schedule() acq_dur = 1200 for i in range(2): diff --git a/test/python/compiler/test_compiler.py b/test/python/compiler/test_compiler.py index 1479fde88cec..32d33ba3e56c 100644 --- a/test/python/compiler/test_compiler.py +++ b/test/python/compiler/test_compiler.py @@ -188,7 +188,6 @@ def test_example_swap_bits(self): def test_parallel_compile(self): """Trigger parallel routines in compile.""" - backend = Fake20QV1() qr = QuantumRegister(16) cr = ClassicalRegister(2) qc = QuantumCircuit(qr, cr) @@ -198,6 +197,7 @@ def test_parallel_compile(self): qc.measure(qr[5], cr[0]) qlist = [qc for k in range(10)] with self.assertWarns(DeprecationWarning): + backend = Fake20QV1() qobj = assemble(transpile(qlist, backend=backend)) self.assertEqual(len(qobj.experiments), 10) @@ -500,7 +500,8 @@ def test_yzy_zyz_cases(self): See: https://github.com/Qiskit/qiskit-terra/issues/607 """ - backend = Fake5QV1() + with self.assertWarns(DeprecationWarning): + backend = Fake5QV1() qr = QuantumRegister(2) circ1 = QuantumCircuit(qr) circ1.cx(qr[0], qr[1]) diff --git a/test/python/compiler/test_disassembler.py b/test/python/compiler/test_disassembler.py index e5d0fd73a79c..0525b54e2107 100644 --- a/test/python/compiler/test_disassembler.py +++ b/test/python/compiler/test_disassembler.py @@ -457,7 +457,8 @@ class TestPulseScheduleDisassembler(QiskitTestCase): def setUp(self): super().setUp() - self.backend = FakeOpenPulse2Q() + with self.assertWarns(DeprecationWarning): + self.backend = FakeOpenPulse2Q() self.backend_config = self.backend.configuration() self.backend_config.parametric_pulses = ["constant", "gaussian", "gaussian_square", "drag"] diff --git a/test/python/compiler/test_scheduler.py b/test/python/compiler/test_scheduler.py index 62e0af596ba4..ad9b14b24c4a 100644 --- a/test/python/compiler/test_scheduler.py +++ b/test/python/compiler/test_scheduler.py @@ -15,7 +15,7 @@ from qiskit.circuit import QuantumRegister, ClassicalRegister, QuantumCircuit from qiskit.exceptions import QiskitError from qiskit.pulse import InstructionScheduleMap, Schedule -from qiskit.providers.fake_provider import FakeOpenPulse3Q +from qiskit.providers.fake_provider import FakeOpenPulse3Q, GenericBackendV2 from qiskit.compiler.scheduler import schedule from test import QiskitTestCase # pylint: disable=wrong-import-order @@ -37,9 +37,9 @@ def setUp(self): self.circ2.cx(qr2[0], qr2[1]) self.circ2.measure(qr2, cr2) - self.backend = FakeOpenPulse3Q() - self.backend_config = self.backend.configuration() - self.num_qubits = self.backend_config.n_qubits + self.backend = GenericBackendV2( + 3, calibrate_instructions=True, basis_gates=["cx", "u1", "u2", "u3"], seed=42 + ) def test_instruction_map_and_backend_not_supplied(self): """Test instruction map and backend not supplied.""" @@ -51,6 +51,8 @@ def test_instruction_map_and_backend_not_supplied(self): def test_instruction_map_and_backend_defaults_unavailable(self): """Test backend defaults unavailable when backend is provided, but instruction map is not.""" + with self.assertWarns(DeprecationWarning): + self.backend = FakeOpenPulse3Q() self.backend._defaults = None with self.assertRaisesRegex( QiskitError, r"The backend defaults are unavailable. The backend may not support pulse." diff --git a/test/python/compiler/test_sequencer.py b/test/python/compiler/test_sequencer.py index 771e854effab..e32d6370367b 100644 --- a/test/python/compiler/test_sequencer.py +++ b/test/python/compiler/test_sequencer.py @@ -13,6 +13,8 @@ # pylint: disable=missing-function-docstring """Tests basic functionality of the sequence function""" +# TODO with the removal of pulses, this file can be removed too. + import unittest from qiskit import QuantumCircuit, pulse @@ -27,7 +29,8 @@ class TestSequence(QiskitTestCase): def setUp(self): super().setUp() - self.backend = Fake127QPulseV1() + with self.assertWarns(DeprecationWarning): + self.backend = Fake127QPulseV1() self.backend.configuration().timing_constraints = {} def test_sequence_empty(self): diff --git a/test/python/compiler/test_transpiler.py b/test/python/compiler/test_transpiler.py index 472fc732ca9a..46acff9d40d6 100644 --- a/test/python/compiler/test_transpiler.py +++ b/test/python/compiler/test_transpiler.py @@ -96,7 +96,7 @@ from test import QiskitTestCase, combine, slow_test # pylint: disable=wrong-import-order -from ..legacy_cmaps import MELBOURNE_CMAP, RUESCHLIKON_CMAP +from ..legacy_cmaps import MELBOURNE_CMAP, RUESCHLIKON_CMAP, MUMBAI_CMAP, TOKYO_CMAP class CustomCX(Gate): @@ -170,7 +170,7 @@ def test_num_processes_kwarg_concurrent_default(self, num_processes): qc.h(0) qc.cx(0, 1) qc.measure_all() - target = GenericBackendV2(num_qubits=27).target + target = GenericBackendV2(num_qubits=27, seed=42).target res = transpile([qc] * 3, target=target, num_processes=num_processes) self.assertIsInstance(res, list) for circ in res: @@ -269,7 +269,7 @@ def test_transpile_non_adjacent_layout(self): circuit.cx(qr[2], qr[3]) backend = GenericBackendV2( - num_qubits=15, basis_gates=["ecr", "id", "rz", "sx", "x"], coupling_map=cmap + num_qubits=15, basis_gates=["ecr", "id", "rz", "sx", "x"], coupling_map=cmap, seed=42 ) initial_layout = [None, qr[0], qr[1], qr[2], None, qr[3]] @@ -313,7 +313,7 @@ def test_already_mapped_1(self): See: https://github.com/Qiskit/qiskit-terra/issues/342 """ - backend = GenericBackendV2(num_qubits=16, coupling_map=RUESCHLIKON_CMAP) + backend = GenericBackendV2(num_qubits=16, coupling_map=RUESCHLIKON_CMAP, seed=42) coupling_map = backend.coupling_map basis_gates = backend.operation_names @@ -598,7 +598,7 @@ def test_transpile_singleton(self): def test_mapping_correction(self): """Test mapping works in previous failed case.""" - backend = GenericBackendV2(num_qubits=12) + backend = GenericBackendV2(num_qubits=12, seed=42) qr = QuantumRegister(name="qr", size=11) cr = ClassicalRegister(name="qc", size=11) circuit = QuantumCircuit(qr, cr) @@ -718,7 +718,7 @@ def test_transpiler_layout_from_intlist(self): def test_mapping_multi_qreg(self): """Test mapping works for multiple qregs.""" - backend = GenericBackendV2(num_qubits=8) + backend = GenericBackendV2(num_qubits=8, seed=42) qr = QuantumRegister(3, name="qr") qr2 = QuantumRegister(1, name="qr2") qr3 = QuantumRegister(4, name="qr3") @@ -735,7 +735,7 @@ def test_mapping_multi_qreg(self): def test_transpile_circuits_diff_registers(self): """Transpile list of circuits with different qreg names.""" - backend = GenericBackendV2(num_qubits=4) + backend = GenericBackendV2(num_qubits=4, seed=42) circuits = [] for _ in range(2): qr = QuantumRegister(2) @@ -751,7 +751,7 @@ def test_transpile_circuits_diff_registers(self): def test_wrong_initial_layout(self): """Test transpile with a bad initial layout.""" - backend = GenericBackendV2(num_qubits=4) + backend = GenericBackendV2(num_qubits=4, seed=42) qubit_reg = QuantumRegister(2, name="q") clbit_reg = ClassicalRegister(2, name="c") @@ -790,7 +790,7 @@ def test_parameterized_circuit_for_device(self): theta = Parameter("theta") qc.p(theta, qr[0]) - backend = GenericBackendV2(num_qubits=4) + backend = GenericBackendV2(num_qubits=4, seed=42) transpiled_qc = transpile( qc, @@ -830,7 +830,7 @@ def test_parameter_expression_circuit_for_device(self): square = theta * theta qc.rz(square, qr[0]) - backend = GenericBackendV2(num_qubits=4) + backend = GenericBackendV2(num_qubits=4, seed=42) transpiled_qc = transpile( qc, backend=backend, @@ -863,7 +863,7 @@ def test_do_not_run_gatedirection_with_symmetric_cm(self): circ = QuantumCircuit.from_qasm_file(os.path.join(qasm_dir, "example.qasm")) layout = Layout.generate_trivial_layout(*circ.qregs) coupling_map = [] - for node1, node2 in GenericBackendV2(num_qubits=16).coupling_map: + for node1, node2 in GenericBackendV2(num_qubits=16, seed=42).coupling_map: coupling_map.append([node1, node2]) coupling_map.append([node2, node1]) @@ -922,7 +922,7 @@ def test_pass_manager_empty(self): def test_move_measurements(self): """Measurements applied AFTER swap mapping.""" - cmap = GenericBackendV2(num_qubits=16).coupling_map + cmap = GenericBackendV2(num_qubits=16, seed=42).coupling_map qasm_dir = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "qasm") circ = QuantumCircuit.from_qasm_file(os.path.join(qasm_dir, "move_measurements.qasm")) @@ -966,7 +966,7 @@ def test_initialize_FakeMelbourne(self): qc = QuantumCircuit(qr) qc.initialize(desired_vector, [qr[0], qr[1], qr[2]]) - out = transpile(qc, backend=GenericBackendV2(num_qubits=4)) + out = transpile(qc, backend=GenericBackendV2(num_qubits=4, seed=42)) out_dag = circuit_to_dag(out) reset_nodes = out_dag.named_nodes("reset") @@ -1285,7 +1285,7 @@ def test_transpiled_custom_gates_calibration(self): transpiled_circuit = transpile( circ, - backend=GenericBackendV2(num_qubits=4), + backend=GenericBackendV2(num_qubits=4, seed=42), layout_method="trivial", seed_transpiler=42, ) @@ -1522,8 +1522,15 @@ def test_scheduling_timing_constraints(self): """Test that scheduling-related loose transpile constraints work with both BackendV1 and BackendV2.""" - backend_v1 = Fake27QPulseV1() - backend_v2 = BackendV2Converter(backend_v1) + with self.assertWarns(DeprecationWarning): + backend_v1 = Fake27QPulseV1() + backend_v2 = GenericBackendV2( + num_qubits=27, + calibrate_instructions=True, + control_flow=True, + coupling_map=MUMBAI_CMAP, + seed=42, + ) # the original timing constraints are granularity = min_length = 16 timing_constraints = TimingConstraints(granularity=32, min_length=64) error_msgs = { @@ -1557,7 +1564,8 @@ def test_scheduling_instruction_constraints(self): """Test that scheduling-related loose transpile constraints work with both BackendV1 and BackendV2.""" - backend_v1 = Fake27QPulseV1() + with self.assertWarns(DeprecationWarning): + backend_v1 = Fake27QPulseV1() backend_v2 = BackendV2Converter(backend_v1) qc = QuantumCircuit(2) qc.h(0) @@ -1582,7 +1590,8 @@ def test_scheduling_dt_constraints(self): """Test that scheduling-related loose transpile constraints work with both BackendV1 and BackendV2.""" - backend_v1 = Fake27QPulseV1() + with self.assertWarns(DeprecationWarning): + backend_v1 = Fake27QPulseV1() backend_v2 = BackendV2Converter(backend_v1) qc = QuantumCircuit(1, 1) qc.x(0) @@ -1602,7 +1611,8 @@ def test_backend_props_constraints(self): """Test that loose transpile constraints work with both BackendV1 and BackendV2.""" - backend_v1 = Fake20QV1() + with self.assertWarns(DeprecationWarning): + backend_v1 = Fake20QV1() backend_v2 = BackendV2Converter(backend_v1) qr1 = QuantumRegister(3, "qr1") qr2 = QuantumRegister(2, "qr2") @@ -2081,6 +2091,21 @@ def test_transpile_annotated_ops(self, opt_level): self.assertEqual(Operator(qc), Operator(transpiled)) self.assertEqual(Operator(qc), Operator(expected)) + @combine(opt_level=[0, 1, 2, 3]) + def test_transpile_annotated_ops_with_backend_v1(self, opt_level): + """Test transpilation of circuits with annotated operations given a backend. + Remove once Fake20QV1 is removed.""" + qc = QuantumCircuit(3) + qc.append(AnnotatedOperation(SGate(), InverseModifier()), [0]) + qc.append(AnnotatedOperation(XGate(), ControlModifier(1)), [1, 2]) + qc.append(AnnotatedOperation(HGate(), PowerModifier(3)), [2]) + with self.assertWarns(DeprecationWarning): + backend = Fake20QV1() + transpiled = transpile( + qc, optimization_level=opt_level, backend=backend, seed_transpiler=42 + ) + self.assertLessEqual(set(transpiled.count_ops().keys()), {"u1", "u2", "u3", "cx"}) + @combine(opt_level=[0, 1, 2, 3]) def test_transpile_annotated_ops_with_backend(self, opt_level): """Test transpilation of circuits with annotated operations given a backend.""" @@ -2088,7 +2113,12 @@ def test_transpile_annotated_ops_with_backend(self, opt_level): qc.append(AnnotatedOperation(SGate(), InverseModifier()), [0]) qc.append(AnnotatedOperation(XGate(), ControlModifier(1)), [1, 2]) qc.append(AnnotatedOperation(HGate(), PowerModifier(3)), [2]) - backend = Fake20QV1() + + backend = GenericBackendV2( + num_qubits=20, + coupling_map=TOKYO_CMAP, + basis_gates=["id", "u1", "u2", "u3", "cx"], + ) transpiled = transpile( qc, optimization_level=opt_level, backend=backend, seed_transpiler=42 ) @@ -2396,9 +2426,32 @@ def test_qpy_roundtrip_standalone_var_target(self, optimization_level): @data(0, 1, 2, 3) def test_qasm3_output(self, optimization_level): """Test that the output of a transpiled circuit can be dumped into OpenQASM 3.""" + backend = GenericBackendV2( + num_qubits=20, + coupling_map=TOKYO_CMAP, + basis_gates=["id", "u1", "u2", "u3", "cx"], + ) + transpiled = transpile( self._regular_circuit(), - backend=Fake20QV1(), + backend=backend, + optimization_level=optimization_level, + seed_transpiler=2022_10_17, + ) + # TODO: There's not a huge amount we can sensibly test for the output here until we can + # round-trip the OpenQASM 3 back into a Terra circuit. Mostly we're concerned that the dump + # itself doesn't throw an error, though. + self.assertIsInstance(qasm3.dumps(transpiled).strip(), str) + + @data(0, 1, 2, 3) + def test_qasm3_output_v1(self, optimization_level): + """Test that the output of a transpiled circuit can be dumped into OpenQASM 3 (backend V1).""" + with self.assertWarns(DeprecationWarning): + backend = Fake20QV1() + + transpiled = transpile( + self._regular_circuit(), + backend=backend, optimization_level=optimization_level, seed_transpiler=2022_10_17, ) diff --git a/test/python/legacy_cmaps.py b/test/python/legacy_cmaps.py index 08d2f043ca4e..84f4be45128b 100644 --- a/test/python/legacy_cmaps.py +++ b/test/python/legacy_cmaps.py @@ -426,3 +426,151 @@ [64, 54], [64, 63], ] + +# 127 qubits +KYOTO_CMAP = [ + [0, 14], + [1, 0], + [1, 2], + [3, 2], + [4, 3], + [4, 5], + [6, 5], + [7, 6], + [8, 7], + [8, 9], + [8, 16], + [9, 10], + [11, 10], + [11, 12], + [12, 13], + [15, 4], + [16, 26], + [17, 12], + [17, 30], + [18, 14], + [18, 19], + [19, 20], + [21, 20], + [22, 15], + [22, 21], + [22, 23], + [23, 24], + [25, 24], + [25, 26], + [27, 26], + [27, 28], + [28, 29], + [28, 35], + [30, 29], + [30, 31], + [31, 32], + [32, 36], + [33, 20], + [33, 39], + [34, 24], + [34, 43], + [37, 38], + [38, 39], + [39, 40], + [40, 41], + [42, 41], + [43, 42], + [44, 43], + [44, 45], + [46, 45], + [47, 35], + [47, 46], + [48, 47], + [49, 48], + [49, 55], + [50, 49], + [50, 51], + [51, 36], + [52, 37], + [53, 41], + [53, 60], + [54, 45], + [54, 64], + [55, 68], + [56, 52], + [57, 56], + [57, 58], + [59, 58], + [59, 60], + [61, 60], + [62, 61], + [62, 63], + [63, 64], + [64, 65], + [65, 66], + [67, 66], + [67, 68], + [68, 69], + [70, 69], + [71, 58], + [72, 62], + [73, 66], + [73, 85], + [74, 70], + [75, 90], + [76, 75], + [76, 77], + [77, 71], + [77, 78], + [79, 78], + [79, 91], + [80, 79], + [81, 72], + [81, 80], + [82, 81], + [82, 83], + [83, 92], + [84, 83], + [84, 85], + [86, 85], + [87, 86], + [87, 93], + [88, 87], + [89, 74], + [89, 88], + [93, 106], + [94, 90], + [94, 95], + [96, 95], + [96, 97], + [96, 109], + [97, 98], + [98, 91], + [98, 99], + [99, 100], + [101, 100], + [101, 102], + [102, 92], + [102, 103], + [104, 103], + [104, 111], + [105, 104], + [105, 106], + [106, 107], + [107, 108], + [109, 114], + [110, 100], + [112, 108], + [113, 114], + [115, 114], + [116, 115], + [117, 116], + [118, 110], + [118, 117], + [119, 118], + [120, 119], + [121, 120], + [122, 111], + [122, 121], + [122, 123], + [124, 123], + [125, 124], + [125, 126], + [126, 112], +] diff --git a/test/python/primitives/test_backend_estimator.py b/test/python/primitives/test_backend_estimator.py index 626ba7625bc9..80b471b66063 100644 --- a/test/python/primitives/test_backend_estimator.py +++ b/test/python/primitives/test_backend_estimator.py @@ -311,7 +311,7 @@ class FakeBackendLimitedCircuits(GenericBackendV2): def max_circuits(self): return 1 - backend = FakeBackendLimitedCircuits(num_qubits=5) + backend = FakeBackendLimitedCircuits(num_qubits=5, seed=42) backend.set_options(seed_simulator=123) qc = RealAmplitudes(num_qubits=2, reps=2) op = SparsePauliOp.from_list([("IZ", 1), ("XI", 2), ("ZY", -1)]) @@ -326,8 +326,10 @@ def max_circuits(self): self.assertEqual(run_mock.call_count, 10) def test_job_size_limit_v1(self): - """Test BackendEstimator respects job size limit""" - backend = Fake7QPulseV1() + """Test BackendEstimator respects job size limit + REMOVE ONCE Fake7QPulseV1 GETS REMOVED""" + with self.assertWarns(DeprecationWarning): + backend = Fake7QPulseV1() config = backend.configuration() config.max_experiments = 1 backend._configuration = config @@ -345,8 +347,10 @@ def test_job_size_limit_v1(self): self.assertEqual(run_mock.call_count, 10) def test_no_max_circuits(self): - """Test BackendEstimator works with BackendV1 and no max_experiments set.""" - backend = Fake7QPulseV1() + """Test BackendEstimator works with BackendV1 and no max_experiments set. + REMOVE ONCE Fake7QPulseV1 GETS REMOVED""" + with self.assertWarns(DeprecationWarning): + backend = Fake7QPulseV1() config = backend.configuration() del config.max_experiments backend._configuration = config @@ -387,7 +391,9 @@ def callback(msg): bound_counter = CallbackPass("bound_pass_manager", callback) bound_pass = PassManager(bound_counter) with self.assertWarns(DeprecationWarning): - estimator = BackendEstimator(backend=Fake7QPulseV1(), bound_pass_manager=bound_pass) + estimator = BackendEstimator( + backend=GenericBackendV2(num_qubits=5, seed=42), bound_pass_manager=bound_pass + ) _ = estimator.run(qc, op).result() expected = [ "bound_pass_manager", @@ -409,7 +415,8 @@ def callback(msg): # pylint: disable=function-redefined bound_pass = PassManager(bound_counter) with self.assertWarns(DeprecationWarning): estimator = BackendEstimator( - backend=Fake7QPulseV1(), bound_pass_manager=bound_pass + backend=GenericBackendV2(num_qubits=5, seed=42), + bound_pass_manager=bound_pass, ) _ = estimator.run([qc, qc], [op, op]).result() expected = [ diff --git a/test/python/primitives/test_backend_estimator_v2.py b/test/python/primitives/test_backend_estimator_v2.py index 6728d57e3fdd..319fd846ee95 100644 --- a/test/python/primitives/test_backend_estimator_v2.py +++ b/test/python/primitives/test_backend_estimator_v2.py @@ -446,8 +446,9 @@ def max_circuits(self): self.assertEqual(run_mock.call_count, 10) def test_job_size_limit_backend_v1(self): - """Test BackendEstimatorV2 respects job size limit""" - backend = Fake7QPulseV1() + """Test BackendEstimatorV2 respects job size limit from BackendV1""" + with self.assertWarns(DeprecationWarning): + backend = Fake7QPulseV1() config = backend.configuration() config.max_experiments = 1 backend._configuration = config diff --git a/test/python/primitives/test_backend_sampler.py b/test/python/primitives/test_backend_sampler.py index 8bc5f76ed095..f0fdb4f07f8c 100644 --- a/test/python/primitives/test_backend_sampler.py +++ b/test/python/primitives/test_backend_sampler.py @@ -323,9 +323,9 @@ def max_circuits(self): qc2.x(0) qc2.measure_all() with self.assertWarns(DeprecationWarning): - sampler = BackendSampler(backend=FakeBackendLimitedCircuits(num_qubits=5)) - result = sampler.run([qc, qc2]).result() - self.assertIsInstance(result, SamplerResult) + sampler = BackendSampler(backend=FakeBackendLimitedCircuits(num_qubits=5, seed=42)) + result = sampler.run([qc, qc2]).result() + self.assertIsInstance(result, SamplerResult) self.assertEqual(len(result.quasi_dists), 2) self.assertDictAlmostEqual(result.quasi_dists[0], {0: 1}, 0.1) @@ -333,10 +333,9 @@ def max_circuits(self): def test_primitive_job_size_limit_backend_v1(self): """Test primitive respects backend's job size limit.""" - backend = Fake7QPulseV1() - config = backend.configuration() - config.max_experiments = 1 - backend._configuration = config + backend = GenericBackendV2( + 7, calibrate_instructions=True, basis_gates=["cx", "u1", "u2", "u3"], seed=42 + ) qc = QuantumCircuit(1) qc.measure_all() qc2 = QuantumCircuit(1) @@ -374,14 +373,17 @@ def test_circuit_with_dynamic_circuit(self): def test_sequential_run(self): """Test sequential run.""" + backend = GenericBackendV2( + 7, calibrate_instructions=True, basis_gates=["cx", "u1", "u2", "u3"], seed=42 + ) qc = QuantumCircuit(1) qc.measure_all() qc2 = QuantumCircuit(1) qc2.x(0) qc2.measure_all() with self.assertWarns(DeprecationWarning): - sampler = BackendSampler(backend=Fake7QPulseV1()) - result = sampler.run([qc]).result() + sampler = BackendSampler(backend=backend) + result = sampler.run([qc]).result() self.assertDictAlmostEqual(result.quasi_dists[0], {0: 1}, 0.1) result2 = sampler.run([qc2]).result() self.assertDictAlmostEqual(result2.quasi_dists[0], {1: 1}, 0.1) @@ -421,9 +423,12 @@ def callback(msg): bound_counter = CallbackPass("bound_pass_manager", callback) bound_pass = PassManager(bound_counter) + backend = GenericBackendV2( + 7, calibrate_instructions=True, basis_gates=["cx", "u1", "u2", "u3"], seed=42 + ) with self.assertWarns(DeprecationWarning): - sampler = BackendSampler(backend=Fake7QPulseV1(), bound_pass_manager=bound_pass) - _ = sampler.run([self._circuit[0]]).result() + sampler = BackendSampler(backend=backend, bound_pass_manager=bound_pass) + _ = sampler.run([self._circuit[0]]).result() expected = [ "bound_pass_manager", ] @@ -442,9 +447,12 @@ def callback(msg): # pylint: disable=function-redefined bound_counter = CallbackPass("bound_pass_manager", callback) bound_pass = PassManager(bound_counter) + backend = GenericBackendV2( + 7, calibrate_instructions=True, basis_gates=["cx", "u1", "u2", "u3"], seed=42 + ) with self.assertWarns(DeprecationWarning): - sampler = BackendSampler(backend=Fake7QPulseV1(), bound_pass_manager=bound_pass) - _ = sampler.run([self._circuit[0], self._circuit[0]]).result() + sampler = BackendSampler(backend=backend, bound_pass_manager=bound_pass) + _ = sampler.run([self._circuit[0], self._circuit[0]]).result() expected = [ "bound_pass_manager", "bound_pass_manager", diff --git a/test/python/primitives/test_backend_sampler_v2.py b/test/python/primitives/test_backend_sampler_v2.py index b03818846c82..632ed1984d2d 100644 --- a/test/python/primitives/test_backend_sampler_v2.py +++ b/test/python/primitives/test_backend_sampler_v2.py @@ -714,10 +714,9 @@ def max_circuits(self): def test_job_size_limit_backend_v1(self): """Test BackendSamplerV2 respects backend's job size limit.""" - backend = Fake7QPulseV1() - config = backend.configuration() - config.max_experiments = 1 - backend._configuration = config + backend = GenericBackendV2( + 2, calibrate_instructions=True, basis_gates=["cx", "u1", "u2", "u3"], seed=42 + ) qc = QuantumCircuit(1) qc.measure_all() qc2 = QuantumCircuit(1) diff --git a/test/python/primitives/test_primitive.py b/test/python/primitives/test_primitive.py index c2b6b8f14202..fb96081fa001 100644 --- a/test/python/primitives/test_primitive.py +++ b/test/python/primitives/test_primitive.py @@ -21,7 +21,7 @@ from qiskit.circuit.random import random_circuit from qiskit.primitives.base import validation from qiskit.primitives.utils import _circuit_key -from qiskit.providers.fake_provider import Fake20QV1 +from qiskit.providers.fake_provider import GenericBackendV2 from test import QiskitTestCase # pylint: disable=wrong-import-order @@ -142,7 +142,11 @@ def test_with_scheduling(n): qc = QuantumCircuit(1) qc.x(0) qc.add_calibration("x", qubits=(0,), schedule=custom_gate) - return transpile(qc, Fake20QV1(), scheduling_method="alap", optimization_level=1) + + backend = GenericBackendV2( + num_qubits=2, basis_gates=["id", "u1", "u2", "u3", "cx"], seed=42 + ) + return transpile(qc, backend, scheduling_method="alap", optimization_level=1) keys = [_circuit_key(test_with_scheduling(i)) for i in range(1, 5)] self.assertEqual(len(keys), len(set(keys))) diff --git a/test/python/providers/fake_provider/test_fake_backends.py b/test/python/providers/fake_provider/test_fake_backends.py index c12be3584fc2..72c9675e1ce7 100644 --- a/test/python/providers/fake_provider/test_fake_backends.py +++ b/test/python/providers/fake_provider/test_fake_backends.py @@ -15,7 +15,7 @@ import unittest from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit, transpile -from qiskit.providers.fake_provider import Fake5QV1, GenericBackendV2 +from qiskit.providers.fake_provider import GenericBackendV2 from qiskit.utils import optionals from test import QiskitTestCase # pylint: disable=wrong-import-order @@ -36,9 +36,9 @@ class FakeBackendsTest(QiskitTestCase): """fake backends test.""" @unittest.skipUnless(optionals.HAS_AER, "qiskit-aer is required to run this test") - def test_fake_backends_get_kwargs(self): + def test_fake_backends_get_kwargs_v1(self): """Fake backends honor kwargs passed.""" - backend = Fake5QV1() + backend = GenericBackendV2(num_qubits=5, seed=42) qc = QuantumCircuit(2) qc.x(range(0, 2)) @@ -57,6 +57,7 @@ def test_fake_backend_v2_noise_model_always_present(self): qc = QuantumCircuit(1) qc.x(0) qc.measure_all() + res = backend.run(qc, shots=1000).result().get_counts() # Assert noise was present and result wasn't ideal self.assertNotEqual(res, {"1": 1000}) diff --git a/test/python/providers/fake_provider/test_generic_backend_v2.py b/test/python/providers/fake_provider/test_generic_backend_v2.py index 70ac50f659c9..42f46b7d7851 100644 --- a/test/python/providers/fake_provider/test_generic_backend_v2.py +++ b/test/python/providers/fake_provider/test_generic_backend_v2.py @@ -35,17 +35,17 @@ def setUp(self): def test_supported_basis_gates(self): """Test that target raises error if basis_gate not in ``supported_names``.""" with self.assertRaises(QiskitError): - GenericBackendV2(num_qubits=8, basis_gates=["cx", "id", "rz", "sx", "zz"]) + GenericBackendV2(num_qubits=8, basis_gates=["cx", "id", "rz", "sx", "zz"], seed=42) def test_cx_1Q(self): """Test failing with a backend with single qubit but with a two-qubit basis gate""" with self.assertRaises(QiskitError): - GenericBackendV2(num_qubits=1, basis_gates=["cx", "id"]) + GenericBackendV2(num_qubits=1, basis_gates=["cx", "id"], seed=42) def test_ccx_2Q(self): """Test failing with a backend with two qubits but with a three-qubit basis gate""" with self.assertRaises(QiskitError): - GenericBackendV2(num_qubits=2, basis_gates=["ccx", "id"]) + GenericBackendV2(num_qubits=2, basis_gates=["ccx", "id"], seed=42) def test_calibration_no_noise_info(self): """Test failing with a backend with calibration and no noise info""" @@ -55,12 +55,13 @@ def test_calibration_no_noise_info(self): basis_gates=["ccx", "id"], calibrate_instructions=True, noise_info=False, + seed=42, ) def test_no_noise(self): """Test no noise info when parameter is false""" backend = GenericBackendV2( - num_qubits=5, coupling_map=CouplingMap.from_line(5), noise_info=False + num_qubits=5, coupling_map=CouplingMap.from_line(5), noise_info=False, seed=42 ) qc = QuantumCircuit(5) qc.h(0) @@ -75,7 +76,7 @@ def test_no_noise(self): def test_no_noise_fully_connected(self): """Test no noise info when parameter is false""" - backend = GenericBackendV2(num_qubits=5, noise_info=False) + backend = GenericBackendV2(num_qubits=5, noise_info=False, seed=42) qc = QuantumCircuit(5) qc.h(0) qc.cx(0, 1) @@ -94,6 +95,7 @@ def test_no_info(self): coupling_map=CouplingMap.from_line(5), noise_info=False, pulse_channels=False, + seed=42, ) qc = QuantumCircuit(5) qc.h(0) @@ -109,7 +111,7 @@ def test_no_info(self): def test_no_pulse_channels(self): """Test no/empty pulse channels when parameter is false""" backend = GenericBackendV2( - num_qubits=5, coupling_map=CouplingMap.from_line(5), pulse_channels=False + num_qubits=5, coupling_map=CouplingMap.from_line(5), pulse_channels=False, seed=42 ) qc = QuantumCircuit(5) qc.h(0) @@ -125,12 +127,12 @@ def test_no_pulse_channels(self): def test_operation_names(self): """Test that target basis gates include "delay", "measure" and "reset" even if not provided by user.""" - target = GenericBackendV2(num_qubits=8) + target = GenericBackendV2(num_qubits=8, seed=42) op_names = list(target.operation_names) op_names.sort() self.assertEqual(op_names, ["cx", "delay", "id", "measure", "reset", "rz", "sx", "x"]) - target = GenericBackendV2(num_qubits=8, basis_gates=["ecr", "id", "rz", "sx", "x"]) + target = GenericBackendV2(num_qubits=8, basis_gates=["ecr", "id", "rz", "sx", "x"], seed=42) op_names = list(target.operation_names) op_names.sort() self.assertEqual(op_names, ["delay", "ecr", "id", "measure", "reset", "rz", "sx", "x"]) @@ -138,7 +140,7 @@ def test_operation_names(self): def test_incompatible_coupling_map(self): """Test that the size of the coupling map must match num_qubits.""" with self.assertRaises(QiskitError): - GenericBackendV2(num_qubits=5, coupling_map=self.cmap) + GenericBackendV2(num_qubits=5, coupling_map=self.cmap, seed=42) def test_control_flow_operation_names(self): """Test that control flow instructions are added to the target if control_flow is True.""" @@ -147,6 +149,7 @@ def test_control_flow_operation_names(self): basis_gates=["ecr", "id", "rz", "sx", "x"], coupling_map=self.cmap, control_flow=True, + seed=42, ).target op_names = list(target.operation_names) op_names.sort() @@ -176,7 +179,7 @@ def test_default_coupling_map(self): (1, 3), (3, 1), (1, 4), (4, 1), (2, 3), (3, 2), (2, 4), (4, 2), (3, 4), (4, 3)] # fmt: on self.assertEqual( - list(GenericBackendV2(num_qubits=5).coupling_map.get_edges()), + list(GenericBackendV2(num_qubits=5, seed=42).coupling_map.get_edges()), reference_cmap, ) @@ -191,7 +194,7 @@ def test_run(self): qc.cx(qr[0], qr[k]) qc.measure(qr, cr) - backend = GenericBackendV2(num_qubits=5, basis_gates=["cx", "id", "rz", "sx", "x"]) + backend = GenericBackendV2(num_qubits=5, basis_gates=["cx", "id", "rz", "sx", "x"], seed=42) tqc = transpile(qc, backend=backend, optimization_level=3, seed_transpiler=42) result = backend.run(tqc, seed_simulator=42, shots=1000).result() counts = result.get_counts() @@ -214,7 +217,7 @@ def test_duration_defaults(self): "rxx": (7.992e-08, 8.99988e-07), } for _ in range(20): - target = GenericBackendV2(num_qubits=2, basis_gates=basis_gates).target + target = GenericBackendV2(num_qubits=2, basis_gates=basis_gates, seed=42).target for inst in target: for qargs in target.qargs_for_operation_name(inst): duration = target[inst][qargs].duration diff --git a/test/python/providers/test_backend_v2.py b/test/python/providers/test_backend_v2.py index 40924e240826..df5f7b9abdea 100644 --- a/test/python/providers/test_backend_v2.py +++ b/test/python/providers/test_backend_v2.py @@ -41,7 +41,7 @@ class TestBackendV2(QiskitTestCase): def setUp(self): super().setUp() - self.backend = GenericBackendV2(num_qubits=2, seed=42, basis_gates=["rx", "u"]) + self.backend = GenericBackendV2(num_qubits=2, basis_gates=["rx", "u"], seed=42) cx_props = { (0, 1): InstructionProperties(duration=5.23e-7, error=0.00098115), } @@ -127,9 +127,9 @@ def test_transpile(self, opt_level): ) def test_5q_ghz(self, opt_level, gate, bidirectional): if bidirectional: - backend = GenericBackendV2(num_qubits=5) + backend = GenericBackendV2(num_qubits=5, seed=42) else: - backend = GenericBackendV2(num_qubits=5, coupling_map=TENERIFE_CMAP) + backend = GenericBackendV2(num_qubits=5, coupling_map=TENERIFE_CMAP, seed=42) qc = QuantumCircuit(5) qc.h(0) getattr(qc, gate)(0, 1) @@ -207,7 +207,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 = GenericBackendV2(num_qubits=5) + backend = GenericBackendV2(num_qubits=5, seed=42) chan = backend.drive_channel(qubit) ref = channels.DriveChannel(qubit) self.assertEqual(chan, ref) @@ -215,7 +215,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 = GenericBackendV2(num_qubits=5) + backend = GenericBackendV2(num_qubits=5, seed=42) chan = backend.measure_channel(qubit) ref = channels.MeasureChannel(qubit) self.assertEqual(chan, ref) @@ -223,7 +223,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 = GenericBackendV2(num_qubits=5) + backend = GenericBackendV2(num_qubits=5, seed=42) chan = backend.acquire_channel(qubit) ref = channels.AcquireChannel(qubit) self.assertEqual(chan, ref) @@ -241,7 +241,7 @@ def test_control_channel(self, qubits): (1, 0): 1, (0, 1): 0, } - backend = GenericBackendV2(num_qubits=5, coupling_map=BOGOTA_CMAP) + backend = GenericBackendV2(num_qubits=5, coupling_map=BOGOTA_CMAP, seed=42) chan = backend.control_channel(qubits)[0] ref = channels.ControlChannel(bogota_cr_channels_map[qubits]) self.assertEqual(chan, ref) diff --git a/test/python/providers/test_backendconfiguration.py b/test/python/providers/test_backendconfiguration.py index 5ba727fd660d..82bbd1c6847f 100644 --- a/test/python/providers/test_backendconfiguration.py +++ b/test/python/providers/test_backendconfiguration.py @@ -12,6 +12,9 @@ """ Test that the PulseBackendConfiguration methods work as expected with a mocked Pulse backend. """ +# TODO the full file can be removed once BackendV1 is removed, since it is the +# only one with backend.configuration() + import collections import copy @@ -26,7 +29,8 @@ class TestBackendConfiguration(QiskitTestCase): def setUp(self): super().setUp() - backend = FakeOpenPulse2Q() + with self.assertWarns(DeprecationWarning): + backend = FakeOpenPulse2Q() self.config = backend.configuration() def test_simple_config(self): @@ -60,7 +64,8 @@ def test_hamiltonian(self): {k: var * 1e-9 for k, var in ref_vars.items()}, ) # 3Q doesn't offer a hamiltonian -- test that we get a reasonable response - backend_3q = FakeOpenPulse3Q() + with self.assertWarns(DeprecationWarning): + backend_3q = FakeOpenPulse3Q() self.assertEqual(backend_3q.configuration().hamiltonian, None) def test_get_channels(self): @@ -80,7 +85,8 @@ def test_get_channel_qubits(self): """Test to get all qubits operated on a given channel.""" self.assertEqual(self.config.get_channel_qubits(channel=DriveChannel(0)), [0]) self.assertEqual(self.config.get_channel_qubits(channel=ControlChannel(0)), [0, 1]) - backend_3q = FakeOpenPulse3Q() + with self.assertWarns(DeprecationWarning): + backend_3q = FakeOpenPulse3Q() self.assertEqual(backend_3q.configuration().get_channel_qubits(ControlChannel(2)), [2, 1]) self.assertEqual(backend_3q.configuration().get_channel_qubits(ControlChannel(1)), [1, 0]) with self.assertRaises(BackendConfigurationError): @@ -107,7 +113,8 @@ def test_get_qubit_channels(self): ], ) ) - backend_3q = FakeOpenPulse3Q() + with self.assertWarns(DeprecationWarning): + backend_3q = FakeOpenPulse3Q() self.assertTrue( self._test_lists_equal( actual=backend_3q.configuration().get_qubit_channels(1), @@ -178,7 +185,8 @@ def test_deepcopy(self): def test_u_channel_lo_scale(self): """Ensure that u_channel_lo scale is a complex number""" - valencia_conf = Fake27QPulseV1().configuration() + with self.assertWarns(DeprecationWarning): + valencia_conf = Fake27QPulseV1().configuration() self.assertTrue(isinstance(valencia_conf.u_channel_lo[0][0].scale, complex)) def test_processor_type(self): diff --git a/test/python/providers/test_backendproperties.py b/test/python/providers/test_backendproperties.py index b1455bd9a320..ac024973133e 100644 --- a/test/python/providers/test_backendproperties.py +++ b/test/python/providers/test_backendproperties.py @@ -22,12 +22,13 @@ class BackendpropertiesTestCase(QiskitTestCase): """Test usability methods of backend.properties().""" - backend = Fake5QV1() - backend_name = "fake_ourense" + # TODO the full file can be removed once BackendV1 is removed, since it is the + # only one with backend.properties() def setUp(self): super().setUp() - self.backend = Fake5QV1() + with self.assertWarns(DeprecationWarning): + self.backend = Fake5QV1() self.properties = self.backend.properties() self.ref_gate = next( g for g in self.backend.configuration().basis_gates if g not in ["id", "rz"] diff --git a/test/python/providers/test_backendstatus.py b/test/python/providers/test_backendstatus.py index 8372108408ac..2cfa31791de3 100644 --- a/test/python/providers/test_backendstatus.py +++ b/test/python/providers/test_backendstatus.py @@ -35,7 +35,8 @@ def test_repr(self): def test_fake_backend_status(self): """Test backend status for one of the fake backends""" - fake_backend = Fake5QV1() + with self.assertWarns(DeprecationWarning): + fake_backend = Fake5QV1() backend_status = fake_backend.status() self.assertIsInstance(backend_status, BackendStatus) diff --git a/test/python/providers/test_fake_backends.py b/test/python/providers/test_fake_backends.py index 1a1c55d1ee2d..d743c4be5c53 100644 --- a/test/python/providers/test_fake_backends.py +++ b/test/python/providers/test_fake_backends.py @@ -78,12 +78,13 @@ from qiskit.transpiler.coupling import CouplingMap from test.utils.base import QiskitTestCase # pylint: disable=wrong-import-order -BACKENDS = [Fake5QV1(), Fake20QV1(), Fake7QPulseV1(), Fake27QPulseV1(), Fake127QPulseV1()] +with warnings.catch_warnings(): + BACKENDS = [Fake5QV1(), Fake20QV1(), Fake7QPulseV1(), Fake27QPulseV1(), Fake127QPulseV1()] BACKENDS_V2 = [] for n in [5, 7, 16, 20, 27, 65, 127]: cmap = CouplingMap.from_ring(n) - BACKENDS_V2.append(GenericBackendV2(num_qubits=n, coupling_map=cmap)) + BACKENDS_V2.append(GenericBackendV2(num_qubits=n, coupling_map=cmap, seed=42)) @ddt @@ -189,7 +190,7 @@ def test_to_dict_configuration(self, backend): self.assertIsInstance(configuration.to_dict(), dict) - @data(BACKENDS) + @data(*BACKENDS) def test_defaults_to_dict(self, backend): if hasattr(backend, "defaults"): defaults = backend.defaults() @@ -206,7 +207,8 @@ def test_defaults_to_dict(self, backend): self.skipTest(f"Backend {backend} does not have defaults") def test_delay_circuit(self): - backend = Fake27QPulseV1() + with self.assertWarns(DeprecationWarning): + backend = Fake27QPulseV1() backend.configuration().timing_constraints = { "acquire_alignment": 1, "granularity": 1, @@ -223,7 +225,8 @@ def test_delay_circuit(self): @data(0, 1, 2, 3) def test_converter(self, opt_level): - backend = Fake5QV1() + with self.assertWarns(DeprecationWarning): + backend = Fake5QV1() backend_v2 = BackendV2Converter(backend) self.assertIsInstance(backend_v2, BackendV2) res = transpile(self.circuit, backend_v2, optimization_level=opt_level) @@ -237,7 +240,8 @@ def test_converter(self, opt_level): self.assertEqual(max_count, "11") def test_converter_delay_circuit(self): - backend = Fake27QPulseV1() + with self.assertWarns(DeprecationWarning): + backend = Fake27QPulseV1() backend.configuration().timing_constraints = { "acquire_alignment": 1, "granularity": 1, @@ -256,8 +260,8 @@ def test_converter_delay_circuit(self): def test_converter_with_missing_gate_property(self): """Test converting to V2 model with irregular backend data.""" - backend = FakeOpenPulse2Q() - + with self.assertWarns(DeprecationWarning): + backend = FakeOpenPulse2Q() # The backend includes pulse calibration definition for U2, but its property is gone. # Note that u2 is a basis gate of this device. # Since gate property is not provided, the gate broadcasts to all qubits as ideal instruction. @@ -268,9 +272,11 @@ def test_converter_with_missing_gate_property(self): self.assertDictEqual(backend_v2.target["u2"], {None: None}) def test_non_cx_tests(self): - backend = GenericBackendV2(num_qubits=5, basis_gates=["cz", "x", "sx", "id", "rz"]) + backend = GenericBackendV2(num_qubits=5, basis_gates=["cz", "x", "sx", "id", "rz"], seed=42) self.assertIsInstance(backend.target.operation_from_name("cz"), CZGate) - backend = GenericBackendV2(num_qubits=5, basis_gates=["ecr", "x", "sx", "id", "rz"]) + backend = GenericBackendV2( + num_qubits=5, basis_gates=["ecr", "x", "sx", "id", "rz"], seed=42 + ) self.assertIsInstance(backend.target.operation_from_name("ecr"), ECRGate) @unittest.skipUnless(optionals.HAS_AER, "Aer required for this test") @@ -521,7 +527,8 @@ def __init__(self, num_ctrl_qubits, ctrl_state=None): def test_filter_faulty_qubits_backend_v2_converter(self): """Test faulty qubits in v2 conversion.""" - backend = Fake127QPulseV1() + with self.assertWarns(DeprecationWarning): + backend = Fake127QPulseV1() # Get properties dict to make it easier to work with the properties API # is difficult to edit because of the multiple layers of nesting and # different object types @@ -542,7 +549,8 @@ def test_filter_faulty_qubits_backend_v2_converter(self): def test_filter_faulty_qubits_backend_v2_converter_with_delay(self): """Test faulty qubits in v2 conversion.""" - backend = Fake127QPulseV1() + with self.assertWarns(DeprecationWarning): + backend = Fake127QPulseV1() # Get properties dict to make it easier to work with the properties API # is difficult to edit because of the multiple layers of nesting and # different object types @@ -584,14 +592,16 @@ def test_backend_v2_converter_without_delay(self): (4, 2), (4, 3), } - - backend = BackendV2Converter(backend=Fake5QV1(), filter_faulty=True, add_delay=False) + with self.assertWarns(DeprecationWarning): + backend = Fake5QV1() + backend = BackendV2Converter(backend=backend, filter_faulty=True, add_delay=False) self.assertEqual(backend.target.qargs, expected) def test_backend_v2_converter_with_meaningless_gate_config(self): """Test backend with broken gate config can be converted only with properties data.""" - backend_v1 = Fake5QV1() + with self.assertWarns(DeprecationWarning): + backend_v1 = Fake5QV1() backend_v1.configuration().gates = [ GateConfig(name="NotValidGate", parameters=[], qasm_def="not_valid_gate") ] @@ -608,7 +618,8 @@ def test_backend_v2_converter_with_meaningless_gate_config(self): def test_filter_faulty_qubits_and_gates_backend_v2_converter(self): """Test faulty gates and qubits.""" - backend = Fake127QPulseV1() + with self.assertWarns(DeprecationWarning): + backend = Fake127QPulseV1() # Get properties dict to make it easier to work with the properties API # is difficult to edit because of the multiple layers of nesting and # different object types @@ -651,7 +662,8 @@ def test_filter_faulty_qubits_and_gates_backend_v2_converter(self): def test_filter_faulty_gates_v2_converter(self): """Test just faulty gates in conversion.""" - backend = Fake127QPulseV1() + with self.assertWarns(DeprecationWarning): + backend = Fake127QPulseV1() # Get properties dict to make it easier to work with the properties API # is difficult to edit because of the multiple layers of nesting and # different object types @@ -685,14 +697,16 @@ def test_filter_faulty_gates_v2_converter(self): def test_filter_faulty_no_faults_v2_converter(self): """Test that faulty qubit filtering does nothing with all operational qubits and gates.""" - backend = Fake127QPulseV1() + with self.assertWarns(DeprecationWarning): + backend = Fake127QPulseV1() v2_backend = BackendV2Converter(backend, filter_faulty=True) for i in range(v2_backend.num_qubits): self.assertIn((i,), v2_backend.target.qargs) @data(0, 1, 2, 3) def test_faulty_full_path_transpile_connected_cmap(self, opt_level): - backend = Fake5QV1() + with self.assertWarns(DeprecationWarning): + backend = Fake5QV1() non_operational_gate = { "date": datetime.datetime.now(datetime.timezone.utc), "name": "operational", @@ -715,7 +729,8 @@ def test_faulty_full_path_transpile_connected_cmap(self, opt_level): self.assertNotIn((0, 1), connections) def test_convert_to_target_control_flow(self): - backend = Fake27QPulseV1() + with self.assertWarns(DeprecationWarning): + backend = Fake27QPulseV1() properties = backend.properties() configuration = backend.configuration() configuration.supported_instructions = [ @@ -739,7 +754,8 @@ def test_convert_to_target_control_flow(self): self.assertTrue(target.instruction_supported("switch_case", ())) def test_convert_unrelated_supported_instructions(self): - backend = Fake27QPulseV1() + with self.assertWarns(DeprecationWarning): + backend = Fake27QPulseV1() properties = backend.properties() configuration = backend.configuration() configuration.supported_instructions = [ diff --git a/test/python/providers/test_pulse_defaults.py b/test/python/providers/test_pulse_defaults.py index 33fe9ecbad65..18f849255917 100644 --- a/test/python/providers/test_pulse_defaults.py +++ b/test/python/providers/test_pulse_defaults.py @@ -17,7 +17,7 @@ import numpy as np -from qiskit.providers.fake_provider import FakeOpenPulse2Q +from qiskit.providers.fake_provider import FakeOpenPulse2Q, GenericBackendV2 from test import QiskitTestCase # pylint: disable=wrong-import-order @@ -26,8 +26,13 @@ class TestPulseDefaults(QiskitTestCase): def setUp(self): super().setUp() - self.defs = FakeOpenPulse2Q().defaults() - self.inst_map = self.defs.instruction_schedule_map + with self.assertWarns(DeprecationWarning): + # BackendV2 does not have defaults + self.defs = FakeOpenPulse2Q().defaults() + backend = GenericBackendV2( + 2, calibrate_instructions=True, basis_gates=["cx", "u1", "u2", "u3"], seed=42 + ) + self.inst_map = backend.instruction_schedule_map def test_buffer(self): """Test getting the buffer value.""" diff --git a/test/python/pulse/test_block.py b/test/python/pulse/test_block.py index 3af2d0b510d1..c6a2c2384f64 100644 --- a/test/python/pulse/test_block.py +++ b/test/python/pulse/test_block.py @@ -28,7 +28,8 @@ class BaseTestBlock(QiskitTestCase): def setUp(self): super().setUp() - self.backend = FakeOpenPulse2Q() + with self.assertWarns(DeprecationWarning): + self.backend = FakeOpenPulse2Q() self.test_waveform0 = pulse.Constant(100, 0.1) self.test_waveform1 = pulse.Constant(200, 0.1) diff --git a/test/python/pulse/test_builder.py b/test/python/pulse/test_builder.py index 1dc295a02be1..563b83345496 100644 --- a/test/python/pulse/test_builder.py +++ b/test/python/pulse/test_builder.py @@ -30,7 +30,8 @@ class TestBuilder(QiskitTestCase): def setUp(self): super().setUp() - self.backend = FakeOpenPulse2Q() + with self.assertWarns(DeprecationWarning): + self.backend = FakeOpenPulse2Q() self.configuration = self.backend.configuration() self.defaults = self.backend.defaults() self.inst_map = self.defaults.instruction_schedule_map @@ -689,7 +690,8 @@ def test_measure_all(self): self.assertScheduleEqual(schedule, reference) - backend = Fake127QPulseV1() + with self.assertWarns(DeprecationWarning): + backend = Fake127QPulseV1() num_qubits = backend.configuration().num_qubits with pulse.build(backend) as schedule: regs = pulse.measure_all() diff --git a/test/python/pulse/test_builder_v2.py b/test/python/pulse/test_builder_v2.py index 843c8a8447fe..79d3ac5b6020 100644 --- a/test/python/pulse/test_builder_v2.py +++ b/test/python/pulse/test_builder_v2.py @@ -32,9 +32,7 @@ class TestBuilderV2(QiskitTestCase): def setUp(self): super().setUp() self.backend = GenericBackendV2( - num_qubits=27, - coupling_map=MUMBAI_CMAP, - calibrate_instructions=True, + num_qubits=27, coupling_map=MUMBAI_CMAP, calibrate_instructions=True, seed=42 ) def assertScheduleEqual(self, program, target): diff --git a/test/python/pulse/test_instruction_schedule_map.py b/test/python/pulse/test_instruction_schedule_map.py index 3ef2ccaa38e5..d1610d7ebcc0 100644 --- a/test/python/pulse/test_instruction_schedule_map.py +++ b/test/python/pulse/test_instruction_schedule_map.py @@ -100,7 +100,9 @@ def test_has(self): def test_has_from_mock(self): """Test `has` and `assert_has` from mock data.""" - inst_map = FakeOpenPulse2Q().defaults().instruction_schedule_map + with self.assertWarns(DeprecationWarning): + backend = FakeOpenPulse2Q() + inst_map = backend.defaults().instruction_schedule_map self.assertTrue(inst_map.has("u1", [0])) self.assertTrue(inst_map.has("cx", (0, 1))) self.assertTrue(inst_map.has("u3", 0)) @@ -229,7 +231,9 @@ def test_has_gate(self): def test_has_from_mock_gate(self): """Test `has` and `assert_has` from mock data.""" - inst_map = FakeOpenPulse2Q().defaults().instruction_schedule_map + with self.assertWarns(DeprecationWarning): + backend = FakeOpenPulse2Q() + inst_map = backend.defaults().instruction_schedule_map self.assertTrue(inst_map.has(U1Gate(0), [0])) self.assertTrue(inst_map.has(CXGate(), (0, 1))) self.assertTrue(inst_map.has(U3Gate(0, 0, 0), 0)) @@ -531,14 +535,18 @@ def test_callable_sched1(par_b): def test_two_instmaps_equal(self): """Test eq method when two instmaps are identical.""" - instmap1 = Fake7QPulseV1().defaults().instruction_schedule_map + with self.assertWarns(DeprecationWarning): + backend = Fake7QPulseV1() + instmap1 = backend.defaults().instruction_schedule_map instmap2 = copy.deepcopy(instmap1) self.assertEqual(instmap1, instmap2) def test_two_instmaps_different(self): """Test eq method when two instmaps are not identical.""" - instmap1 = Fake7QPulseV1().defaults().instruction_schedule_map + with self.assertWarns(DeprecationWarning): + backend = Fake7QPulseV1() + instmap1 = backend.defaults().instruction_schedule_map instmap2 = copy.deepcopy(instmap1) # override one of instruction @@ -548,7 +556,9 @@ def test_two_instmaps_different(self): def test_instmap_picklable(self): """Test if instmap can be pickled.""" - instmap = Fake7QPulseV1().defaults().instruction_schedule_map + with self.assertWarns(DeprecationWarning): + backend = Fake7QPulseV1() + instmap = backend.defaults().instruction_schedule_map ser_obj = pickle.dumps(instmap) deser_instmap = pickle.loads(ser_obj) @@ -562,7 +572,9 @@ def test_instmap_picklable_with_arguments(self): in which arguments are provided by users in the form of python dict key object that is not picklable. """ - instmap = Fake7QPulseV1().defaults().instruction_schedule_map + with self.assertWarns(DeprecationWarning): + backend = Fake7QPulseV1() + instmap = backend.defaults().instruction_schedule_map param1 = Parameter("P1") param2 = Parameter("P2") @@ -582,14 +594,18 @@ def test_instmap_picklable_with_arguments(self): def test_check_backend_provider_cals(self): """Test if schedules provided by backend provider is distinguishable.""" - instmap = FakeOpenPulse2Q().defaults().instruction_schedule_map + with self.assertWarns(DeprecationWarning): + backend = FakeOpenPulse2Q() + instmap = backend.defaults().instruction_schedule_map publisher = instmap.get("u1", (0,), P0=0).metadata["publisher"] self.assertEqual(publisher, CalibrationPublisher.BACKEND_PROVIDER) def test_check_user_cals(self): """Test if schedules provided by user is distinguishable.""" - instmap = FakeOpenPulse2Q().defaults().instruction_schedule_map + with self.assertWarns(DeprecationWarning): + backend = FakeOpenPulse2Q() + instmap = backend.defaults().instruction_schedule_map test_u1 = Schedule() test_u1 += ShiftPhase(Parameter("P0"), DriveChannel(0)) @@ -601,7 +617,8 @@ def test_check_user_cals(self): def test_has_custom_gate(self): """Test method to check custom gate.""" - backend = FakeOpenPulse2Q() + with self.assertWarns(DeprecationWarning): + backend = FakeOpenPulse2Q() instmap = backend.defaults().instruction_schedule_map self.assertFalse(instmap.has_custom_gate()) diff --git a/test/python/pulse/test_macros.py b/test/python/pulse/test_macros.py index 05937c88982d..6d87320cf480 100644 --- a/test/python/pulse/test_macros.py +++ b/test/python/pulse/test_macros.py @@ -33,12 +33,15 @@ class TestMeasure(QiskitTestCase): def setUp(self): super().setUp() - self.backend = FakeOpenPulse2Q() + with self.assertWarns(DeprecationWarning): + self.backend = FakeOpenPulse2Q() + self.backend_v1 = Fake27QPulseV1() + self.inst_map = self.backend.defaults().instruction_schedule_map - self.backend_v1 = Fake27QPulseV1() self.backend_v2 = GenericBackendV2( num_qubits=27, calibrate_instructions=self.backend_v1.defaults().instruction_schedule_map, + seed=42, ) def test_measure(self): @@ -171,7 +174,9 @@ def test_output_with_measure_v1_and_measure_v2_sched_with_qubit_mem_slots(self): def test_output_with_measure_v1_and_measure_v2_sched_with_meas_map(self): """Test make outputs of measure_v1 and measure_v2 with custom meas_map as list and dict consistent.""" - num_qubits_list_measure_v1 = list(range(Fake27QPulseV1().configuration().num_qubits)) + with self.assertWarns(DeprecationWarning): + backend = Fake27QPulseV1() + num_qubits_list_measure_v1 = list(range(backend.configuration().num_qubits)) num_qubits_list_measure_v2 = list(range(self.backend_v2.num_qubits)) sched_with_meas_map_list_v1 = macros.measure( qubits=[0], backend=self.backend_v1, meas_map=[num_qubits_list_measure_v1] @@ -210,11 +215,13 @@ class TestMeasureAll(QiskitTestCase): def setUp(self): super().setUp() - self.backend_v1 = FakeOpenPulse2Q() + with self.assertWarns(DeprecationWarning): + self.backend_v1 = FakeOpenPulse2Q() self.inst_map = self.backend_v1.defaults().instruction_schedule_map self.backend_v2 = GenericBackendV2( num_qubits=2, calibrate_instructions=self.backend_v1.defaults().instruction_schedule_map, + seed=42, ) def test_measure_all(self): diff --git a/test/python/pulse/test_schedule.py b/test/python/pulse/test_schedule.py index 40d637887ed0..5e5676e7c2d9 100644 --- a/test/python/pulse/test_schedule.py +++ b/test/python/pulse/test_schedule.py @@ -61,7 +61,8 @@ def linear(duration, slope, intercept): return slope * x + intercept self.linear = linear - self.config = FakeOpenPulse2Q().configuration() + with self.assertWarns(DeprecationWarning): + self.config = FakeOpenPulse2Q().configuration() class TestScheduleBuilding(BaseTestSchedule): diff --git a/test/python/pulse/test_transforms.py b/test/python/pulse/test_transforms.py index 5918a6e6993d..c16405cff4d1 100644 --- a/test/python/pulse/test_transforms.py +++ b/test/python/pulse/test_transforms.py @@ -46,7 +46,8 @@ class TestAlignMeasures(QiskitTestCase): def setUp(self): super().setUp() - self.backend = FakeOpenPulse2Q() + with self.assertWarns(DeprecationWarning): + self.backend = FakeOpenPulse2Q() self.config = self.backend.configuration() self.inst_map = self.backend.defaults().instruction_schedule_map self.short_pulse = pulse.Waveform( @@ -202,7 +203,8 @@ class TestAddImplicitAcquires(QiskitTestCase): def setUp(self): super().setUp() - self.backend = FakeOpenPulse2Q() + with self.assertWarns(DeprecationWarning): + self.backend = FakeOpenPulse2Q() self.config = self.backend.configuration() self.short_pulse = pulse.Waveform( samples=np.array([0.02739068], dtype=np.complex128), name="p0" diff --git a/test/python/qpy/test_circuit_load_from_qpy.py b/test/python/qpy/test_circuit_load_from_qpy.py index a050a70cac5f..8f0cffb36a5f 100644 --- a/test/python/qpy/test_circuit_load_from_qpy.py +++ b/test/python/qpy/test_circuit_load_from_qpy.py @@ -61,8 +61,10 @@ class TestCalibrationPasses(QpyCircuitTestCase): def setUp(self): super().setUp() - # This backend provides CX(0,1) with native ECR direction. - self.inst_map = Fake27QPulseV1().defaults().instruction_schedule_map + # TODO remove context once https://github.com/Qiskit/qiskit/issues/12759 is fixed + with self.assertWarns(DeprecationWarning): + # This backend provides CX(0,1) with native ECR direction. + self.inst_map = Fake27QPulseV1().defaults().instruction_schedule_map @data(0.1, 0.7, 1.5) def test_rzx_calibration(self, angle): @@ -112,7 +114,7 @@ def test_transpile_layout(self, opt_level): qc.h(0) qc.cx(0, 1) qc.measure_all() - backend = GenericBackendV2(num_qubits=127) + backend = GenericBackendV2(num_qubits=127, seed=42) tqc = transpile(qc, backend, optimization_level=opt_level) self.assert_roundtrip_equal(tqc) @@ -126,7 +128,7 @@ def test_transpile_with_routing(self, opt_level): qc.cx(0, 3) qc.cx(0, 4) qc.measure_all() - backend = GenericBackendV2(num_qubits=127) + backend = GenericBackendV2(num_qubits=127, seed=42) tqc = transpile(qc, backend, optimization_level=opt_level) self.assert_roundtrip_equal(tqc) @@ -137,7 +139,7 @@ def test_transpile_layout_explicit_None_final_layout(self, opt_level): qc.h(0) qc.cx(0, 1) qc.measure_all() - backend = GenericBackendV2(num_qubits=127) + backend = GenericBackendV2(num_qubits=127, seed=42) tqc = transpile(qc, backend, optimization_level=opt_level) tqc.layout.final_layout = None self.assert_roundtrip_equal(tqc) @@ -201,7 +203,7 @@ def test_custom_register_name(self, opt_level): qc.cx(0, 3) qc.cx(0, 4) qc.measure_all() - backend = GenericBackendV2(num_qubits=127) + backend = GenericBackendV2(num_qubits=127, seed=42) tqc = transpile(qc, backend, optimization_level=opt_level) self.assert_roundtrip_equal(tqc) @@ -213,7 +215,7 @@ def test_no_register(self, opt_level): qc.h(0) qc.cx(0, 1) qc.measure_all() - backend = GenericBackendV2(num_qubits=127) + backend = GenericBackendV2(num_qubits=127, seed=42) 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/result/test_mitigators.py b/test/python/result/test_mitigators.py index 3b3e83bce009..8dcdedc433fe 100644 --- a/test/python/result/test_mitigators.py +++ b/test/python/result/test_mitigators.py @@ -119,8 +119,11 @@ def counts_data(circuit, assignment_matrices, shots=1024): def test_mitigation_improvement(self): """Test whether readout mitigation led to more accurate results""" shots = 1024 - assignment_matrices = self.assignment_matrices() - num_qubits = len(assignment_matrices) + with self.assertWarns(DeprecationWarning): + # TODO self.assignment_matrices calls LocalReadoutMitigator, + # which only supports BackendV1 at the moment: + # https://github.com/Qiskit/qiskit/issues/12832 + assignment_matrices = self.assignment_matrices() mitigators = self.mitigators(assignment_matrices) circuit, circuit_name, num_qubits = self.ghz_3_circuit() counts_ideal, counts_noise, probs_noise = self.counts_data( @@ -156,7 +159,8 @@ def test_expectation_improvement(self): """Test whether readout mitigation led to more accurate results and that its standard deviation is increased""" shots = 1024 - assignment_matrices = self.assignment_matrices() + with self.assertWarns(DeprecationWarning): + assignment_matrices = self.assignment_matrices() mitigators = self.mitigators(assignment_matrices) num_qubits = len(assignment_matrices) diagonals = [] @@ -198,7 +202,8 @@ def test_expectation_improvement(self): def test_clbits_parameter(self): """Test whether the clbits parameter is handled correctly""" shots = 10000 - assignment_matrices = self.assignment_matrices() + with self.assertWarns(DeprecationWarning): + assignment_matrices = self.assignment_matrices() mitigators = self.mitigators(assignment_matrices) circuit, _, _ = self.first_qubit_h_3_circuit() counts_ideal, counts_noise, _ = self.counts_data(circuit, assignment_matrices, shots) @@ -233,7 +238,8 @@ def test_clbits_parameter(self): def test_qubits_parameter(self): """Test whether the qubits parameter is handled correctly""" shots = 10000 - assignment_matrices = self.assignment_matrices() + with self.assertWarns(DeprecationWarning): + assignment_matrices = self.assignment_matrices() mitigators = self.mitigators(assignment_matrices) circuit, _, _ = self.first_qubit_h_3_circuit() counts_ideal, counts_noise, _ = self.counts_data(circuit, assignment_matrices, shots) @@ -281,7 +287,8 @@ def test_qubits_parameter(self): def test_repeated_qubits_parameter(self): """Tests the order of mitigated qubits.""" shots = 10000 - assignment_matrices = self.assignment_matrices() + with self.assertWarns(DeprecationWarning): + assignment_matrices = self.assignment_matrices() mitigators = self.mitigators(assignment_matrices, qubits=[0, 1, 2]) circuit, _, _ = self.first_qubit_h_3_circuit() counts_ideal, counts_noise, _ = self.counts_data(circuit, assignment_matrices, shots) @@ -319,7 +326,8 @@ def test_qubits_subset_parameter(self): """Tests mitigation on a subset of the initial set of qubits.""" shots = 10000 - assignment_matrices = self.assignment_matrices() + with self.assertWarns(DeprecationWarning): + assignment_matrices = self.assignment_matrices() mitigators = self.mitigators(assignment_matrices, qubits=[2, 4, 6]) circuit, _, _ = self.first_qubit_h_3_circuit() counts_ideal, counts_noise, _ = self.counts_data(circuit, assignment_matrices, shots) @@ -364,7 +372,8 @@ def test_qubits_subset_parameter(self): def test_from_backend(self): """Test whether a local mitigator can be created directly from backend properties""" - backend = Fake5QV1() + with self.assertWarns(DeprecationWarning): + backend = Fake5QV1() num_qubits = len(backend.properties().qubits) probs = TestReadoutMitigation.rng.random((num_qubits, 2)) for qubit_idx, qubit_prop in enumerate(backend.properties().qubits): @@ -422,7 +431,9 @@ def test_error_handling(self): def test_expectation_value_endian(self): """Test that endian for expval is little.""" - mitigators = self.mitigators(self.assignment_matrices()) + with self.assertWarns(DeprecationWarning): + assignment_matrices = self.assignment_matrices() + mitigators = self.mitigators(assignment_matrices) counts = Counts({"10": 3, "11": 24, "00": 74, "01": 923}) for mitigator in mitigators: expval, _ = mitigator.expectation_value(counts, diagonal="IZ", qubits=[0, 1]) @@ -449,7 +460,9 @@ class TestLocalReadoutMitigation(QiskitTestCase): def test_assignment_matrix(self): """Tests that the local mitigator generates the full assignment matrix correctly""" qubits = [7, 2, 3] - assignment_matrices = LocalReadoutMitigator(backend=Fake5QV1())._assignment_mats[0:3] + with self.assertWarns(DeprecationWarning): + backend = Fake5QV1() + assignment_matrices = LocalReadoutMitigator(backend=backend)._assignment_mats[0:3] expected_assignment_matrix = np.kron( np.kron(assignment_matrices[2], assignment_matrices[1]), assignment_matrices[0] ) diff --git a/test/python/scheduler/test_basic_scheduler.py b/test/python/scheduler/test_basic_scheduler.py index 16ec00927c67..947a255ddf21 100644 --- a/test/python/scheduler/test_basic_scheduler.py +++ b/test/python/scheduler/test_basic_scheduler.py @@ -46,14 +46,16 @@ class TestBasicSchedule(QiskitTestCase): def setUp(self): super().setUp() - self.backend = FakeOpenPulse2Q() + with self.assertWarns(DeprecationWarning): + self.backend = FakeOpenPulse2Q() self.inst_map = self.backend.defaults().instruction_schedule_map def test_unavailable_defaults(self): """Test backend with unavailable defaults.""" qr = QuantumRegister(1) qc = QuantumCircuit(qr) - backend = FakeBackend(None) + with self.assertWarns(DeprecationWarning): + backend = FakeBackend(None) backend.defaults = backend.configuration self.assertRaises(QiskitError, lambda: schedule(qc, backend)) @@ -252,7 +254,8 @@ def test_3q_schedule(self): # ┌──────┴───┴──────┐ └───────────────┘ ┌─┴─┐┌─────────────────┐ # q0_2: ┤ U2(0.778,0.122) ├───────────────────┤ X ├┤ U2(0.778,0.122) ├ # └─────────────────┘ └───┘└─────────────────┘ - backend = FakeOpenPulse3Q() + with self.assertWarns(DeprecationWarning): + backend = FakeOpenPulse3Q() inst_map = backend.defaults().instruction_schedule_map q = QuantumRegister(3) c = ClassicalRegister(3) @@ -416,9 +419,13 @@ def test_subset_calibrated_measurements(self): meas_scheds.append(meas) qc.add_calibration("measure", [qubit], meas) - meas = macros.measure([1], FakeOpenPulse3Q()) + with self.assertWarns(DeprecationWarning): + backend = FakeOpenPulse3Q() + meas = macros.measure([1], backend) meas = meas.exclude(channels=[AcquireChannel(0), AcquireChannel(2)]) - sched = schedule(qc, FakeOpenPulse3Q()) + with self.assertWarns(DeprecationWarning): + backend = FakeOpenPulse3Q() + sched = schedule(qc, backend) expected = Schedule(meas_scheds[0], meas_scheds[1], meas) self.assertEqual(sched.instructions, expected.instructions) @@ -509,7 +516,7 @@ class TestBasicScheduleV2(QiskitTestCase): def setUp(self): super().setUp() - self.backend = GenericBackendV2(num_qubits=3, calibrate_instructions=True) + self.backend = GenericBackendV2(num_qubits=3, calibrate_instructions=True, seed=42) 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. diff --git a/test/python/transpiler/test_1q.py b/test/python/transpiler/test_1q.py index 50bdc7b24643..13379f410c34 100644 --- a/test/python/transpiler/test_1q.py +++ b/test/python/transpiler/test_1q.py @@ -16,12 +16,16 @@ from qiskit import QuantumCircuit from qiskit.compiler import transpile -from qiskit.providers.fake_provider import Fake1Q +from qiskit.providers.fake_provider import Fake1Q, GenericBackendV2 from qiskit.providers.basic_provider import BasicSimulator from qiskit.transpiler import TranspilerError from test import combine # pylint: disable=wrong-import-order from test import QiskitTestCase # pylint: disable=wrong-import-order +Fake1QV2 = GenericBackendV2( + num_qubits=1, basis_gates=["u1", "u2", "u3"], coupling_map=None, dtm=1.3333, seed=42 +) + def emptycircuit(): """Empty circuit""" @@ -45,31 +49,54 @@ class Test1QFailing(QiskitTestCase): circuit=[circuit_3516], level=[0, 1, 2, 3], dsc="Transpiling {circuit.__name__} at level {level} should fail", - name="{circuit.__name__}_level{level}_fail", + name="{circuit.__name__}_level{level}_fail_v1", + ) + def test(self, circuit, level): + """All the levels with all the 1Q backendV1""" + with self.assertRaises(TranspilerError): + with self.assertWarns(DeprecationWarning): + transpile(circuit(), backend=Fake1Q(), optimization_level=level, seed_transpiler=42) + + +@ddt +class Test1QV2Failing(QiskitTestCase): + """1QV2 tests that should fail.""" + + @combine( + circuit=[circuit_3516], + level=[0, 1, 2, 3], + dsc="Transpiling {circuit.__name__} at level {level} should fail", + name="{circuit.__name__}_level{level}_fail_v2", ) def test(self, circuit, level): - """All the levels with all the 1Q backend""" + """All the levels with all the 1Q backendV2""" with self.assertRaises(TranspilerError): - transpile(circuit(), backend=Fake1Q(), optimization_level=level, seed_transpiler=42) + transpile(circuit(), backend=Fake1QV2, optimization_level=level, seed_transpiler=42) @ddt class Test1QWorking(QiskitTestCase): - """1Q tests that should work.""" + """1QV1 tests that should work.""" @combine( circuit=[emptycircuit], level=[0, 1, 2, 3], dsc="Transpiling {circuit.__name__} at level {level} should work", - name="{circuit.__name__}_level{level}_valid", + name="{circuit.__name__}_level{level}_valid_v1", ) def test_device(self, circuit, level): - """All the levels with all the 1Q backend""" - result = transpile( - circuit(), backend=Fake1Q(), optimization_level=level, seed_transpiler=42 - ) + """All the levels with all the 1Q backendV1""" + with self.assertWarns(DeprecationWarning): + result = transpile( + circuit(), backend=Fake1Q(), optimization_level=level, seed_transpiler=42 + ) self.assertIsInstance(result, QuantumCircuit) + +@ddt +class TestBasicSimulatorWorking(QiskitTestCase): + """All the levels with a simulator backend""" + @combine( circuit=[circuit_3516], level=[0, 1, 2, 3], @@ -81,3 +108,21 @@ def test_simulator(self, circuit, level): backend = BasicSimulator() result = transpile(circuit(), backend=backend, optimization_level=level, seed_transpiler=42) self.assertIsInstance(result, QuantumCircuit) + + +@ddt +class Test1QV2Working(QiskitTestCase): + """1QV2 tests that should work.""" + + @combine( + circuit=[emptycircuit], + level=[0, 1, 2, 3], + dsc="Transpiling {circuit.__name__} at level {level} should work", + name="{circuit.__name__}_level{level}_valid_v2", + ) + def test_device(self, circuit, level): + """All the levels with all the 1Q backendV2""" + result = transpile( + circuit(), backend=Fake1QV2, optimization_level=level, seed_transpiler=42 + ) + self.assertIsInstance(result, QuantumCircuit) diff --git a/test/python/transpiler/test_calibrationbuilder.py b/test/python/transpiler/test_calibrationbuilder.py index bc64d954a429..cb7293049ef5 100644 --- a/test/python/transpiler/test_calibrationbuilder.py +++ b/test/python/transpiler/test_calibrationbuilder.py @@ -266,7 +266,8 @@ def build_reverse( @data(-np.pi / 4, 0.1, np.pi / 4, np.pi / 2, np.pi) def test_rzx_calibration_cr_pulse_stretch(self, theta: float): """Test that cross resonance pulse durations are computed correctly.""" - backend = Fake27QPulseV1() + with self.assertWarns(DeprecationWarning): + backend = Fake27QPulseV1() inst_map = backend.defaults().instruction_schedule_map cr_schedule = inst_map.get("cx", (0, 1)) with builder.build() as test_sched: @@ -279,7 +280,8 @@ def test_rzx_calibration_cr_pulse_stretch(self, theta: float): @data(-np.pi / 4, 0.1, np.pi / 4, np.pi / 2, np.pi) def test_rzx_calibration_rotary_pulse_stretch(self, theta: float): """Test that rotary pulse durations are computed correctly.""" - backend = Fake27QPulseV1() + with self.assertWarns(DeprecationWarning): + backend = Fake27QPulseV1() inst_map = backend.defaults().instruction_schedule_map cr_schedule = inst_map.get("cx", (0, 1)) with builder.build() as test_sched: @@ -296,8 +298,8 @@ def test_raise(self): qc = circuit.QuantumCircuit(2) qc.rzx(theta, 0, 1) dag = circuit_to_dag(qc) - - backend = Fake7QPulseV1() + with self.assertWarns(DeprecationWarning): + backend = Fake7QPulseV1() # The error is raised when calibrations in multi-qubit # gates are not detected. # We force this by removing the 'cx' entries from the @@ -322,7 +324,8 @@ def test_ecr_cx_forward(self): qc = circuit.QuantumCircuit(2) qc.rzx(theta, 0, 1) - backend = Fake27QPulseV1() + with self.assertWarns(DeprecationWarning): + backend = Fake27QPulseV1() inst_map = backend.defaults().instruction_schedule_map _pass = RZXCalibrationBuilder(inst_map) test_qc = PassManager(_pass).run(qc) @@ -347,7 +350,8 @@ def test_ecr_cx_reverse(self): qc = circuit.QuantumCircuit(2) qc.rzx(theta, 1, 0) - backend = Fake27QPulseV1() + with self.assertWarns(DeprecationWarning): + backend = Fake27QPulseV1() inst_map = backend.defaults().instruction_schedule_map _pass = RZXCalibrationBuilder(inst_map) test_qc = PassManager(_pass).run(qc) @@ -434,7 +438,8 @@ def test_ecr_cx_forward(self): qc = circuit.QuantumCircuit(2) qc.rzx(theta, 0, 1) - backend = Fake27QPulseV1() + with self.assertWarns(DeprecationWarning): + backend = Fake27QPulseV1() inst_map = backend.defaults().instruction_schedule_map _pass = RZXCalibrationBuilderNoEcho(inst_map) diff --git a/test/python/transpiler/test_echo_rzx_weyl_decomposition.py b/test/python/transpiler/test_echo_rzx_weyl_decomposition.py index c4efffc977f4..8f876dd261d7 100644 --- a/test/python/transpiler/test_echo_rzx_weyl_decomposition.py +++ b/test/python/transpiler/test_echo_rzx_weyl_decomposition.py @@ -32,7 +32,12 @@ class TestEchoRZXWeylDecomposition(QiskitTestCase): def setUp(self): super().setUp() - self.backend = Fake27QPulseV1() + # TODO once https://github.com/Qiskit/qiskit/issues/12759 is fixed, replace with + # backend = GenericBackendV2(num_qubits=27, calibrate_instructions=True, + # control_flow=True, seed=42) + # self.inst_map = backend.instruction_schedule_map + with self.assertWarns(DeprecationWarning): + self.backend = Fake27QPulseV1() self.inst_map = self.backend.defaults().instruction_schedule_map def assertRZXgates(self, unitary_circuit, after): diff --git a/test/python/transpiler/test_instruction_durations.py b/test/python/transpiler/test_instruction_durations.py index ba37f6cd65e4..de68fbadf86a 100644 --- a/test/python/transpiler/test_instruction_durations.py +++ b/test/python/transpiler/test_instruction_durations.py @@ -36,14 +36,18 @@ def test_fail_if_invalid_dict_is_supplied_when_construction(self): InstructionDurations(invalid_dic) def test_from_backend_for_backend_with_dt(self): - backend = Fake27QPulseV1() + # Remove context once https://github.com/Qiskit/qiskit/issues/12760 is fixed + with self.assertWarns(DeprecationWarning): + backend = Fake27QPulseV1() gate = self._find_gate_with_length(backend) durations = InstructionDurations.from_backend(backend) self.assertGreater(durations.dt, 0) self.assertGreater(durations.get(gate, 0), 0) def test_from_backend_for_backend_without_dt(self): - backend = Fake27QPulseV1() + # Remove context once https://github.com/Qiskit/qiskit/issues/12760 is fixed + with self.assertWarns(DeprecationWarning): + backend = Fake27QPulseV1() delattr(backend.configuration(), "dt") gate = self._find_gate_with_length(backend) durations = InstructionDurations.from_backend(backend) diff --git a/test/python/transpiler/test_passmanager_config.py b/test/python/transpiler/test_passmanager_config.py index 01ec7ebf133a..ebac6a410b7f 100644 --- a/test/python/transpiler/test_passmanager_config.py +++ b/test/python/transpiler/test_passmanager_config.py @@ -19,6 +19,7 @@ from qiskit.transpiler.coupling import CouplingMap from qiskit.transpiler.passmanager_config import PassManagerConfig from test import QiskitTestCase # pylint: disable=wrong-import-order +from ..legacy_cmaps import ALMADEN_CMAP class TestPassManagerConfig(QiskitTestCase): @@ -30,7 +31,8 @@ def test_config_from_backend(self): `Fake27QPulseV1` is used in this testcase. This backend has `defaults` attribute that contains an instruction schedule map. """ - backend = Fake27QPulseV1() + with self.assertWarns(DeprecationWarning): + backend = Fake27QPulseV1() config = PassManagerConfig.from_backend(backend) self.assertEqual(config.basis_gates, backend.configuration().basis_gates) self.assertEqual(config.inst_map, backend.defaults().instruction_schedule_map) @@ -40,7 +42,7 @@ def test_config_from_backend(self): def test_config_from_backend_v2(self): """Test from_backend() with a BackendV2 instance.""" - backend = GenericBackendV2(num_qubits=27) + backend = GenericBackendV2(num_qubits=27, seed=42) config = PassManagerConfig.from_backend(backend) self.assertEqual(config.basis_gates, backend.operation_names) self.assertEqual(config.inst_map, backend.instruction_schedule_map) @@ -51,16 +53,19 @@ def test_invalid_backend(self): with self.assertRaises(AttributeError): PassManagerConfig.from_backend(Backend()) - def test_from_backend_and_user(self): + def test_from_backend_and_user_v1(self): """Test from_backend() with a backend and user options. `FakeMelbourne` is used in this testcase. This backend does not have `defaults` attribute and thus not provide an instruction schedule map. + + REMOVE AFTER Fake20QV1 GETS REMOVED. """ qr = QuantumRegister(4, "qr") initial_layout = [None, qr[0], qr[1], qr[2], None, qr[3]] - backend = Fake20QV1() + with self.assertWarns(DeprecationWarning): + backend = Fake20QV1() config = PassManagerConfig.from_backend( backend, basis_gates=["user_gate"], initial_layout=initial_layout ) @@ -72,9 +77,35 @@ def test_from_backend_and_user(self): ) self.assertEqual(config.initial_layout, initial_layout) + def test_from_backend_and_user(self): + """Test from_backend() with a backend and user options. + + `FakeMelbourne` is used in this testcase. This backend does not have + `defaults` attribute and thus not provide an instruction schedule map. + """ + qr = QuantumRegister(4, "qr") + initial_layout = [None, qr[0], qr[1], qr[2], None, qr[3]] + + backend = GenericBackendV2( + num_qubits=20, + coupling_map=ALMADEN_CMAP, + basis_gates=["id", "u1", "u2", "u3", "cx"], + calibrate_instructions=None, + seed=42, + ) + config = PassManagerConfig.from_backend( + backend, basis_gates=["user_gate"], initial_layout=initial_layout + ) + self.assertEqual(config.basis_gates, ["user_gate"]) + self.assertNotEqual(config.basis_gates, backend.operation_names) + self.assertEqual(config.inst_map.instructions, []) + self.assertEqual(str(config.coupling_map), str(CouplingMap(backend.coupling_map))) + self.assertEqual(config.initial_layout, initial_layout) + def test_from_backendv1_inst_map_is_none(self): """Test that from_backend() works with backend that has defaults defined as None.""" - backend = Fake27QPulseV1() + with self.assertWarns(DeprecationWarning): + backend = Fake27QPulseV1() backend.defaults = lambda: None config = PassManagerConfig.from_backend(backend) self.assertIsInstance(config, PassManagerConfig) @@ -82,8 +113,9 @@ def test_from_backendv1_inst_map_is_none(self): def test_invalid_user_option(self): """Test from_backend() with an invalid user option.""" + backend = GenericBackendV2(num_qubits=20, seed=42) with self.assertRaises(TypeError): - PassManagerConfig.from_backend(Fake20QV1(), invalid_option=None) + PassManagerConfig.from_backend(backend, invalid_option=None) def test_str(self): """Test string output.""" diff --git a/test/python/transpiler/test_passmanager_run.py b/test/python/transpiler/test_passmanager_run.py index caf6af2aaf67..3da6a042564c 100644 --- a/test/python/transpiler/test_passmanager_run.py +++ b/test/python/transpiler/test_passmanager_run.py @@ -15,9 +15,10 @@ from qiskit import QuantumRegister, QuantumCircuit from qiskit.circuit.library import CXGate from qiskit.transpiler.preset_passmanagers import level_1_pass_manager -from qiskit.providers.fake_provider import Fake20QV1 +from qiskit.providers.fake_provider import GenericBackendV2 from qiskit.transpiler import Layout, PassManager from qiskit.transpiler.passmanager_config import PassManagerConfig +from ..legacy_cmaps import ALMADEN_CMAP from test import QiskitTestCase # pylint: disable=wrong-import-order @@ -83,12 +84,14 @@ def test_default_pass_manager_single(self): circuit.cx(qr[1], qr[2]) circuit.cx(qr[2], qr[3]) - coupling_map = Fake20QV1().configuration().coupling_map + backend = GenericBackendV2( + num_qubits=20, coupling_map=ALMADEN_CMAP, basis_gates=["id", "u1", "u2", "u3", "cx"] + ) initial_layout = [None, qr[0], qr[1], qr[2], None, qr[3]] pass_manager = level_1_pass_manager( PassManagerConfig.from_backend( - Fake20QV1(), + backend, initial_layout=Layout.from_qubit_list(initial_layout), seed_transpiler=42, ) @@ -100,7 +103,7 @@ def test_default_pass_manager_single(self): for instruction in new_circuit.data: if isinstance(instruction.operation, CXGate): - self.assertIn([bit_indices[x] for x in instruction.qubits], coupling_map) + self.assertIn([bit_indices[x] for x in instruction.qubits], ALMADEN_CMAP) def test_default_pass_manager_two(self): """Test default_pass_manager.run(circuitS). @@ -133,12 +136,63 @@ def test_default_pass_manager_two(self): circuit2.cx(qr[0], qr[1]) circuit2.cx(qr[2], qr[3]) - coupling_map = Fake20QV1().configuration().coupling_map + coupling_map = [ + [0, 1], + [1, 0], + [1, 2], + [1, 6], + [2, 1], + [2, 3], + [3, 2], + [3, 4], + [3, 8], + [4, 3], + [5, 6], + [5, 10], + [6, 1], + [6, 5], + [6, 7], + [7, 6], + [7, 8], + [7, 12], + [8, 3], + [8, 7], + [8, 9], + [9, 8], + [9, 14], + [10, 5], + [10, 11], + [11, 10], + [11, 12], + [11, 16], + [12, 7], + [12, 11], + [12, 13], + [13, 12], + [13, 14], + [13, 18], + [14, 9], + [14, 13], + [15, 16], + [16, 11], + [16, 15], + [16, 17], + [17, 16], + [17, 18], + [18, 13], + [18, 17], + [18, 19], + [19, 18], + ] initial_layout = [None, qr[0], qr[1], qr[2], None, qr[3]] + backend = GenericBackendV2( + num_qubits=20, coupling_map=coupling_map, basis_gates=["id", "u1", "u2", "u3", "cx"] + ) + pass_manager = level_1_pass_manager( PassManagerConfig.from_backend( - Fake20QV1(), + backend=backend, initial_layout=Layout.from_qubit_list(initial_layout), seed_transpiler=42, ) diff --git a/test/python/transpiler/test_preset_passmanagers.py b/test/python/transpiler/test_preset_passmanagers.py index 949d754573c5..3d11a5d55e93 100644 --- a/test/python/transpiler/test_preset_passmanagers.py +++ b/test/python/transpiler/test_preset_passmanagers.py @@ -222,7 +222,9 @@ def test_alignment_constraints_called_with_by_default(self, level): circuit.h(q[0]) circuit.cz(q[0], q[1]) with unittest.mock.patch("qiskit.transpiler.passes.TimeUnitConversion.run") as mock: - transpile(circuit, backend=Fake20QV1(), optimization_level=level) + with self.assertWarns(DeprecationWarning): + backend = Fake20QV1() + transpile(circuit, backend=backend, optimization_level=level) mock.assert_not_called() @combine(level=[0, 1, 2, 3], name="level{level}") @@ -236,12 +238,15 @@ def test_alignment_constraints_called_with_delay_in_circuit(self, level): with unittest.mock.patch( "qiskit.transpiler.passes.TimeUnitConversion.run", return_value=circuit_to_dag(circuit) ) as mock: - transpile(circuit, backend=Fake20QV1(), optimization_level=level) + with self.assertWarns(DeprecationWarning): + backend = Fake20QV1() + transpile(circuit, backend=backend, optimization_level=level) mock.assert_called_once() def test_unroll_only_if_not_gates_in_basis(self): """Test that the list of passes _unroll only runs if a gate is not in the basis.""" - qcomp = Fake5QV1() + with self.assertWarns(DeprecationWarning): + qcomp = Fake5QV1() qv_circuit = QuantumVolume(3) gates_in_basis_true_count = 0 collect_2q_blocks_count = 0 @@ -782,7 +787,8 @@ def test_layout_2503(self, level): 19: ancilla[16], } - backend = Fake20QV1() + with self.assertWarns(DeprecationWarning): + backend = Fake20QV1() qc_b = transpile(qc, backend, initial_layout=initial_layout, optimization_level=level) self.assertEqual(qc_b._layout.initial_layout._p2v, final_layout) @@ -1038,7 +1044,8 @@ def test_trivial_layout(self, level): expected_layouts = [trivial_layout, trivial_layout] - backend = Fake20QV1() + with self.assertWarns(DeprecationWarning): + backend = Fake20QV1() result = transpile(qc, backend, optimization_level=level, seed_transpiler=42) self.assertEqual(result._layout.initial_layout._p2v, expected_layouts[level]) @@ -1071,7 +1078,8 @@ def test_initial_layout(self, level): 18: qr[9], } - backend = Fake20QV1() + with self.assertWarns(DeprecationWarning): + backend = Fake20QV1() result = transpile( qc, backend, optimization_level=level, initial_layout=initial_layout, seed_transpiler=42 ) @@ -1151,7 +1159,8 @@ def test_optimization_condition(self, level): cr = ClassicalRegister(1) qc = QuantumCircuit(qr, cr) qc.cx(0, 1).c_if(cr, 1) - backend = Fake20QV1() + with self.assertWarns(DeprecationWarning): + backend = Fake20QV1() circ = transpile(qc, backend, optimization_level=level) self.assertIsInstance(circ, QuantumCircuit) @@ -1215,8 +1224,9 @@ class TestGeneratePresetPassManagers(QiskitTestCase): @data(0, 1, 2, 3) def test_with_backend(self, optimization_level): """Test a passmanager is constructed when only a backend and optimization level.""" - target = Fake20QV1() - pm = generate_preset_pass_manager(optimization_level, target) + with self.assertWarns(DeprecationWarning): + backend = Fake20QV1() + pm = generate_preset_pass_manager(optimization_level, backend) self.assertIsInstance(pm, PassManager) def test_default_optimization_level(self): @@ -1587,7 +1597,8 @@ def test_invalid_methods_raise_on_control_flow(self, optimization_level): def test_unsupported_basis_gates_raise(self, optimization_level): """Test that trying to transpile a control-flow circuit for a backend that doesn't support the necessary operations in its `basis_gates` will raise a sensible error.""" - backend = Fake20QV1() + with self.assertWarns(DeprecationWarning): + backend = Fake20QV1() qc = QuantumCircuit(1, 1) with qc.for_loop((0,)): diff --git a/test/python/transpiler/test_pulse_gate_pass.py b/test/python/transpiler/test_pulse_gate_pass.py index a11d4c4a6b53..539674609c26 100644 --- a/test/python/transpiler/test_pulse_gate_pass.py +++ b/test/python/transpiler/test_pulse_gate_pass.py @@ -56,7 +56,8 @@ def setUp(self): def test_transpile_with_bare_backend(self): """Test transpile without custom calibrations.""" - backend = Fake27QPulseV1() + with self.assertWarns(DeprecationWarning): + backend = Fake27QPulseV1() # Remove timing constraints to avoid triggering # scheduling passes. backend.configuration().timing_constraints = {} @@ -96,7 +97,8 @@ def test_transpile_with_backend_target(self): def test_transpile_with_custom_basis_gate(self): """Test transpile with custom calibrations.""" - backend = Fake27QPulseV1() + with self.assertWarns(DeprecationWarning): + backend = Fake27QPulseV1() backend.defaults().instruction_schedule_map.add("sx", (0,), self.custom_sx_q0) backend.defaults().instruction_schedule_map.add("sx", (1,), self.custom_sx_q1) # Remove timing constraints to avoid triggering @@ -122,10 +124,13 @@ def test_transpile_with_custom_basis_gate(self): def test_transpile_with_custom_basis_gate_in_target(self): """Test transpile with custom calibrations.""" + with self.assertWarns(DeprecationWarning): + backend_pulse = Fake27QPulseV1() target = GenericBackendV2( num_qubits=5, coupling_map=BOGOTA_CMAP, - calibrate_instructions=Fake27QPulseV1().defaults().instruction_schedule_map, + calibrate_instructions=backend_pulse.defaults().instruction_schedule_map, + seed=42, ).target target["sx"][(0,)].calibration = self.custom_sx_q0 @@ -150,12 +155,15 @@ def test_transpile_with_custom_basis_gate_in_target(self): def test_transpile_with_instmap(self): """Test providing instruction schedule map.""" - instmap = Fake27QPulseV1().defaults().instruction_schedule_map + with self.assertWarns(DeprecationWarning): + backend = Fake27QPulseV1() + instmap = backend.defaults().instruction_schedule_map instmap.add("sx", (0,), self.custom_sx_q0) instmap.add("sx", (1,), self.custom_sx_q1) # Inst map is renewed - backend = Fake27QPulseV1() + with self.assertWarns(DeprecationWarning): + backend = Fake27QPulseV1() # Remove timing constraints to avoid triggering # scheduling passes. backend.configuration().timing_constraints = {} @@ -179,7 +187,8 @@ def test_transpile_with_instmap(self): def test_transpile_with_custom_gate(self): """Test providing non-basis gate.""" - backend = Fake27QPulseV1() + with self.assertWarns(DeprecationWarning): + backend = Fake27QPulseV1() backend.defaults().instruction_schedule_map.add( "my_gate", (0,), self.my_gate_q0, arguments=["P0"] ) @@ -215,7 +224,8 @@ def test_transpile_with_custom_gate(self): def test_transpile_with_parameterized_custom_gate(self): """Test providing non-basis gate, which is kept parameterized throughout transpile.""" - backend = Fake27QPulseV1() + with self.assertWarns(DeprecationWarning): + backend = Fake27QPulseV1() backend.defaults().instruction_schedule_map.add( "my_gate", (0,), self.my_gate_q0, arguments=["P0"] ) @@ -244,7 +254,8 @@ def test_transpile_with_parameterized_custom_gate(self): def test_transpile_with_multiple_circuits(self): """Test transpile with multiple circuits with custom gate.""" - backend = Fake27QPulseV1() + with self.assertWarns(DeprecationWarning): + backend = Fake27QPulseV1() backend.defaults().instruction_schedule_map.add( "my_gate", (0,), self.my_gate_q0, arguments=["P0"] ) @@ -274,7 +285,8 @@ def test_transpile_with_multiple_circuits(self): def test_multiple_instructions_with_different_parameters(self): """Test adding many instruction with different parameter binding.""" - backend = Fake27QPulseV1() + with self.assertWarns(DeprecationWarning): + backend = Fake27QPulseV1() backend.defaults().instruction_schedule_map.add( "my_gate", (0,), self.my_gate_q0, arguments=["P0"] ) @@ -308,7 +320,8 @@ def test_multiple_instructions_with_different_parameters(self): def test_transpile_with_different_qubit(self): """Test transpile with qubit without custom gate.""" - backend = Fake27QPulseV1() + with self.assertWarns(DeprecationWarning): + backend = Fake27QPulseV1() backend.defaults().instruction_schedule_map.add("sx", (0,), self.custom_sx_q0) # Remove timing constraints to avoid triggering # scheduling passes. @@ -329,16 +342,20 @@ def test_transpile_with_both_instmap_and_empty_target(self, opt_level): Test case from Qiskit/qiskit-terra/#9489 """ - instmap = Fake27QPulseV1().defaults().instruction_schedule_map + with self.assertWarns(DeprecationWarning): + backend = Fake27QPulseV1() + instmap = backend.defaults().instruction_schedule_map instmap.add("sx", (0,), self.custom_sx_q0) instmap.add("sx", (1,), self.custom_sx_q1) instmap.add("cx", (0, 1), self.custom_cx_q01) + with self.assertWarns(DeprecationWarning): + backend_pulse = Fake27QPulseV1() # This doesn't have custom schedule definition target = GenericBackendV2( num_qubits=5, coupling_map=BOGOTA_CMAP, - calibrate_instructions=Fake27QPulseV1().defaults().instruction_schedule_map, + calibrate_instructions=backend_pulse.defaults().instruction_schedule_map, seed=42, ).target @@ -371,7 +388,10 @@ def test_transpile_with_instmap_with_v2backend(self, opt_level): Test case from Qiskit/qiskit-terra/#9489 """ - instmap = Fake27QPulseV1().defaults().instruction_schedule_map + with self.assertWarns(DeprecationWarning): + backend = Fake27QPulseV1() + + instmap = backend.defaults().instruction_schedule_map instmap.add("sx", (0,), self.custom_sx_q0) instmap.add("sx", (1,), self.custom_sx_q1) instmap.add("cx", (0, 1), self.custom_cx_q01) @@ -380,9 +400,12 @@ def test_transpile_with_instmap_with_v2backend(self, opt_level): qc.append(random_unitary(4, seed=123), [0, 1]) qc.measure_all() + with self.assertWarns(DeprecationWarning): + backend_pulse = Fake27QPulseV1() + backend = GenericBackendV2( num_qubits=5, - calibrate_instructions=Fake27QPulseV1().defaults().instruction_schedule_map, + calibrate_instructions=backend_pulse.defaults().instruction_schedule_map, seed=42, ) @@ -416,8 +439,9 @@ def test_transpile_with_instmap_with_v2backend_with_custom_gate(self, opt_level) """ with pulse.build(name="custom") as rabi12: pulse.play(pulse.Constant(100, 0.4), pulse.DriveChannel(0)) - - instmap = Fake27QPulseV1().defaults().instruction_schedule_map + with self.assertWarns(DeprecationWarning): + backend = Fake27QPulseV1() + instmap = backend.defaults().instruction_schedule_map instmap.add("rabi12", (0,), rabi12) gate = circuit.Gate("rabi12", 1, []) @@ -457,7 +481,10 @@ def test_transpile_with_instmap_not_mutate_backend(self): ) original_sx0 = backend.target["sx"][(0,)].calibration - instmap = Fake27QPulseV1().defaults().instruction_schedule_map + with self.assertWarns(DeprecationWarning): + backend_pulse = Fake27QPulseV1() + + instmap = backend_pulse.defaults().instruction_schedule_map instmap.add("sx", (0,), self.custom_sx_q0) qc = circuit.QuantumCircuit(1) diff --git a/test/python/transpiler/test_sabre_layout.py b/test/python/transpiler/test_sabre_layout.py index 4c09bf12efa8..42ae3691c3ca 100644 --- a/test/python/transpiler/test_sabre_layout.py +++ b/test/python/transpiler/test_sabre_layout.py @@ -195,8 +195,10 @@ def test_layout_with_classical_bits(self): rz(0) q4835[1]; """ ) + with self.assertWarns(DeprecationWarning): + backend = Fake27QPulseV1() res = transpile( - qc, Fake27QPulseV1(), layout_method="sabre", seed_transpiler=1234, optimization_level=1 + qc, backend, layout_method="sabre", seed_transpiler=1234, optimization_level=1 ) self.assertIsInstance(res, QuantumCircuit) layout = res._layout.initial_layout @@ -247,9 +249,11 @@ def test_layout_many_search_trials(self): barrier q18585[5],q18585[2],q18585[8],q18585[3],q18585[6]; """ ) + with self.assertWarns(DeprecationWarning): + backend = Fake27QPulseV1() res = transpile( qc, - Fake27QPulseV1(), + backend, layout_method="sabre", routing_method="stochastic", seed_transpiler=12345, diff --git a/test/python/transpiler/test_sabre_swap.py b/test/python/transpiler/test_sabre_swap.py index bf2ef5b1f9c4..6650ca27c6f4 100644 --- a/test/python/transpiler/test_sabre_swap.py +++ b/test/python/transpiler/test_sabre_swap.py @@ -25,7 +25,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 Fake27QPulseV1, GenericBackendV2 +from qiskit.providers.fake_provider import GenericBackendV2 from qiskit.transpiler.passes import SabreSwap, TrivialLayout, CheckMap from qiskit.transpiler import CouplingMap, Layout, PassManager, Target, TranspilerError from qiskit import ClassicalRegister, QuantumRegister, QuantumCircuit @@ -1327,11 +1327,15 @@ class TestSabreSwapRandomCircuitValidOutput(QiskitTestCase): @classmethod def setUpClass(cls): super().setUpClass() - cls.backend = Fake27QPulseV1() - cls.backend.configuration().coupling_map = MUMBAI_CMAP - cls.backend.configuration().basis_gates += ["for_loop", "while_loop", "if_else"] - cls.coupling_edge_set = {tuple(x) for x in cls.backend.configuration().coupling_map} - cls.basis_gates = set(cls.backend.configuration().basis_gates) + cls.backend = GenericBackendV2( + num_qubits=27, + calibrate_instructions=True, + control_flow=True, + coupling_map=MUMBAI_CMAP, + seed=42, + ) + cls.coupling_edge_set = {tuple(x) for x in cls.backend.coupling_map} + cls.basis_gates = set(cls.backend.operation_names) def assert_valid_circuit(self, transpiled): """Assert circuit complies with constraints of backend.""" diff --git a/test/python/transpiler/test_star_prerouting.py b/test/python/transpiler/test_star_prerouting.py index e244d97a45aa..fb67698300b4 100644 --- a/test/python/transpiler/test_star_prerouting.py +++ b/test/python/transpiler/test_star_prerouting.py @@ -21,10 +21,7 @@ from qiskit.circuit.library import QFT from qiskit.circuit.quantumcircuit import QuantumCircuit -from qiskit.converters import ( - circuit_to_dag, - dag_to_circuit, -) +from qiskit.converters import circuit_to_dag, dag_to_circuit from qiskit.quantum_info import Operator from qiskit.transpiler.passes import VF2Layout, ApplyLayout, SabreSwap, SabreLayout from qiskit.transpiler.passes.routing.star_prerouting import StarPreRouting diff --git a/test/python/transpiler/test_stochastic_swap.py b/test/python/transpiler/test_stochastic_swap.py index 8c96150ae8ff..4843bac8baf5 100644 --- a/test/python/transpiler/test_stochastic_swap.py +++ b/test/python/transpiler/test_stochastic_swap.py @@ -24,7 +24,7 @@ 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 Fake27QPulseV1, GenericBackendV2 +from qiskit.providers.fake_provider import GenericBackendV2 from qiskit.compiler.transpiler import transpile from qiskit.circuit import ControlFlowOp, Clbit, CASE_DEFAULT from qiskit.circuit.classical import expr, types @@ -1488,10 +1488,11 @@ class TestStochasticSwapRandomCircuitValidOutput(QiskitTestCase): @classmethod def setUpClass(cls): super().setUpClass() - cls.backend = Fake27QPulseV1() - cls.backend.configuration().basis_gates += ["for_loop", "while_loop", "if_else"] - cls.coupling_edge_set = {tuple(x) for x in cls.backend.configuration().coupling_map} - cls.basis_gates = set(cls.backend.configuration().basis_gates) + cls.backend = GenericBackendV2( + num_qubits=27, calibrate_instructions=True, control_flow=True, seed=42 + ) + cls.coupling_edge_set = {tuple(x) for x in cls.backend.coupling_map} + cls.basis_gates = set(cls.backend.operation_names) def assert_valid_circuit(self, transpiled): """Assert circuit complies with constraints of backend.""" diff --git a/test/python/transpiler/test_target.py b/test/python/transpiler/test_target.py index f63ed5061cc7..928cd09c8dd1 100644 --- a/test/python/transpiler/test_target.py +++ b/test/python/transpiler/test_target.py @@ -1937,7 +1937,8 @@ def test_basis_gates_coupling_map(self): self.assertEqual({(0, 1), (1, 2), (2, 0)}, target["cx"].keys()) def test_properties(self): - fake_backend = Fake5QV1() + with self.assertWarns(DeprecationWarning): + fake_backend = Fake5QV1() config = fake_backend.configuration() properties = fake_backend.properties() target = Target.from_configuration( @@ -1950,7 +1951,8 @@ def test_properties(self): self.assertEqual(0, target["rz"][(0,)].duration) def test_properties_with_durations(self): - fake_backend = Fake5QV1() + with self.assertWarns(DeprecationWarning): + fake_backend = Fake5QV1() config = fake_backend.configuration() properties = fake_backend.properties() durations = InstructionDurations([("rz", 0, 0.5)], dt=1.0) @@ -1965,7 +1967,8 @@ def test_properties_with_durations(self): self.assertEqual(0.5, target["rz"][(0,)].duration) def test_inst_map(self): - fake_backend = Fake7QPulseV1() + with self.assertWarns(DeprecationWarning): + fake_backend = Fake7QPulseV1() config = fake_backend.configuration() properties = fake_backend.properties() defaults = fake_backend.defaults() @@ -1986,7 +1989,8 @@ def test_inst_map(self): self.assertEqual(target.acquire_alignment, constraints.acquire_alignment) def test_concurrent_measurements(self): - fake_backend = Fake5QV1() + with self.assertWarns(DeprecationWarning): + fake_backend = Fake5QV1() config = fake_backend.configuration() target = Target.from_configuration( basis_gates=config.basis_gates, diff --git a/test/python/transpiler/test_unitary_synthesis.py b/test/python/transpiler/test_unitary_synthesis.py index 0f4423426a8a..43acd4ef67af 100644 --- a/test/python/transpiler/test_unitary_synthesis.py +++ b/test/python/transpiler/test_unitary_synthesis.py @@ -148,7 +148,8 @@ def test_two_qubit_synthesis_to_directional_cx_from_gate_errors(self): """Verify two qubit unitaries are synthesized to match basis gates.""" # TODO: should make check more explicit e.g. explicitly set gate # direction in test instead of using specific fake backend - backend = Fake5QV1() + with self.assertWarns(DeprecationWarning): + backend = Fake5QV1() conf = backend.configuration() qr = QuantumRegister(2) coupling_map = CouplingMap(conf.coupling_map) @@ -182,7 +183,8 @@ def test_swap_synthesis_to_directional_cx(self): """Verify two qubit unitaries are synthesized to match basis gates.""" # TODO: should make check more explicit e.g. explicitly set gate # direction in test instead of using specific fake backend - backend = Fake5QV1() + with self.assertWarns(DeprecationWarning): + backend = Fake5QV1() conf = backend.configuration() qr = QuantumRegister(2) coupling_map = CouplingMap(conf.coupling_map) @@ -218,7 +220,8 @@ def test_two_qubit_synthesis_to_directional_cx_multiple_registers(self): across multiple registers.""" # TODO: should make check more explicit e.g. explicitly set gate # direction in test instead of using specific fake backend - backend = Fake5QV1() + with self.assertWarns(DeprecationWarning): + backend = Fake5QV1() conf = backend.configuration() qr0 = QuantumRegister(1) qr1 = QuantumRegister(1) @@ -253,7 +256,8 @@ def test_two_qubit_synthesis_to_directional_cx_from_coupling_map(self): """Verify natural cx direction is used when specified in coupling map.""" # TODO: should make check more explicit e.g. explicitly set gate # direction in test instead of using specific fake backend - backend = Fake5QV1() + with self.assertWarns(DeprecationWarning): + backend = Fake5QV1() conf = backend.configuration() qr = QuantumRegister(2) coupling_map = CouplingMap([[0, 1], [1, 2], [1, 3], [3, 4]]) @@ -296,7 +300,8 @@ def test_two_qubit_synthesis_to_directional_cx_from_coupling_map_natural_none(se when natural_direction is None.""" # TODO: should make check more explicit e.g. explicitly set gate # direction in test instead of using specific fake backend - backend = Fake5QV1() + with self.assertWarns(DeprecationWarning): + backend = Fake5QV1() conf = backend.configuration() qr = QuantumRegister(2) coupling_map = CouplingMap([[0, 1], [1, 2], [1, 3], [3, 4]]) @@ -339,7 +344,8 @@ def test_two_qubit_synthesis_to_directional_cx_from_coupling_map_natural_false(s when natural_direction is None.""" # TODO: should make check more explicit e.g. explicitly set gate # direction in test instead of using specific fake backend - backend = Fake5QV1() + with self.assertWarns(DeprecationWarning): + backend = Fake5QV1() conf = backend.configuration() qr = QuantumRegister(2) coupling_map = CouplingMap([[0, 1], [1, 2], [1, 3], [3, 4]]) @@ -379,7 +385,8 @@ def test_two_qubit_synthesis_to_directional_cx_from_coupling_map_natural_false(s def test_two_qubit_synthesis_not_pulse_optimal(self): """Verify not attempting pulse optimal decomposition when pulse_optimize==False.""" - backend = Fake5QV1() + with self.assertWarns(DeprecationWarning): + backend = Fake5QV1() conf = backend.configuration() qr = QuantumRegister(2) qc = QuantumCircuit(qr) @@ -415,7 +422,8 @@ def test_two_qubit_synthesis_not_pulse_optimal(self): def test_two_qubit_pulse_optimal_true_raises(self): """Verify raises if pulse optimal==True but cx is not in the backend basis.""" - backend = Fake5QV1() + with self.assertWarns(DeprecationWarning): + backend = Fake5QV1() conf = backend.configuration() # this assumes iswawp pulse optimal decomposition doesn't exist conf.basis_gates = [gate if gate != "cx" else "iswap" for gate in conf.basis_gates] @@ -438,7 +446,8 @@ def test_two_qubit_pulse_optimal_true_raises(self): def test_two_qubit_natural_direction_true_duration_fallback(self): """Verify not attempting pulse optimal decomposition when pulse_optimize==False.""" # this assumes iswawp pulse optimal decomposition doesn't exist - backend = Fake5QV1() + with self.assertWarns(DeprecationWarning): + backend = Fake5QV1() conf = backend.configuration() # conf.basis_gates = [gate if gate != "cx" else "iswap" for gate in conf.basis_gates] qr = QuantumRegister(2) @@ -462,7 +471,8 @@ def test_two_qubit_natural_direction_true_duration_fallback(self): def test_two_qubit_natural_direction_true_gate_length_raises(self): """Verify not attempting pulse optimal decomposition when pulse_optimize==False.""" # this assumes iswawp pulse optimal decomposition doesn't exist - backend = Fake5QV1() + with self.assertWarns(DeprecationWarning): + backend = Fake5QV1() conf = backend.configuration() for _, nduv in backend.properties()._gates["cx"].items(): nduv["gate_length"] = (4e-7, nduv["gate_length"][1]) @@ -485,7 +495,8 @@ def test_two_qubit_natural_direction_true_gate_length_raises(self): def test_two_qubit_pulse_optimal_none_optimal(self): """Verify pulse optimal decomposition when pulse_optimize==None.""" # this assumes iswawp pulse optimal decomposition doesn't exist - backend = Fake5QV1() + with self.assertWarns(DeprecationWarning): + backend = Fake5QV1() conf = backend.configuration() qr = QuantumRegister(2) coupling_map = CouplingMap([[0, 1], [1, 2], [1, 3], [3, 4]]) @@ -512,7 +523,8 @@ def test_two_qubit_pulse_optimal_none_no_raise(self): """Verify pulse optimal decomposition when pulse_optimize==None doesn't raise when pulse optimal decomposition unknown.""" # this assumes iswawp pulse optimal decomposition doesn't exist - backend = Fake5QV1() + with self.assertWarns(DeprecationWarning): + backend = Fake5QV1() conf = backend.configuration() conf.basis_gates = [gate if gate != "cx" else "iswap" for gate in conf.basis_gates] qr = QuantumRegister(2) @@ -662,7 +674,8 @@ def test_coupling_map_unequal_durations(self, opt): qr = QuantumRegister(2) circ = QuantumCircuit(qr) circ.append(random_unitary(4, seed=1), [1, 0]) - backend = Fake5QV1() + with self.assertWarns(DeprecationWarning): + backend = Fake5QV1() tqc = transpile( circ, backend=backend, diff --git a/test/python/transpiler/test_vf2_layout.py b/test/python/transpiler/test_vf2_layout.py index 716e49d35009..4e4844f5f701 100644 --- a/test/python/transpiler/test_vf2_layout.py +++ b/test/python/transpiler/test_vf2_layout.py @@ -629,7 +629,8 @@ def test_no_properties(self): def test_with_properties(self): """Test it finds the least noise perfect layout with no properties.""" - backend = Fake5QV1() + with self.assertWarns(DeprecationWarning): + backend = Fake5QV1() qr = QuantumRegister(2) qc = QuantumCircuit(qr) qc.x(qr) @@ -643,7 +644,8 @@ def test_with_properties(self): def test_max_trials_exceeded(self): """Test it exits when max_trials is reached.""" - backend = Fake5QV1() + with self.assertWarns(DeprecationWarning): + backend = Fake5QV1() qr = QuantumRegister(2) qc = QuantumCircuit(qr) qc.x(qr) @@ -663,7 +665,8 @@ def test_max_trials_exceeded(self): def test_time_limit_exceeded(self): """Test the pass stops after time_limit is reached.""" - backend = Fake5QV1() + with self.assertWarns(DeprecationWarning): + backend = Fake5QV1() qr = QuantumRegister(2) qc = QuantumCircuit(qr) qc.x(qr) @@ -685,9 +688,11 @@ def test_time_limit_exceeded(self): self.assertEqual(set(property_set["layout"].get_physical_bits()), {2, 0}) - def test_reasonable_limits_for_simple_layouts(self): - """Test that the default trials is set to a reasonable number.""" - backend = Fake127QPulseV1() + def test_reasonable_limits_for_simple_layouts_v1(self): + """Test that the default trials is set to a reasonable number. + REMOVE ONCE Fake127QPulseV1 IS GONE""" + with self.assertWarns(DeprecationWarning): + backend = Fake127QPulseV1() qc = QuantumCircuit(5) qc.cx(2, 3) qc.cx(0, 1) @@ -704,9 +709,28 @@ def test_reasonable_limits_for_simple_layouts(self): ) self.assertEqual(set(property_set["layout"].get_physical_bits()), {57, 58, 61, 62, 0}) + def test_reasonable_limits_for_simple_layouts(self): + """Test that the default trials is set to a reasonable number.""" + backend = GenericBackendV2(27, calibrate_instructions=True, seed=42) + qc = QuantumCircuit(5) + qc.cx(2, 3) + qc.cx(0, 1) + + # Run without any limits set + vf2_pass = VF2Layout(target=backend.target, seed=42) + property_set = {} + with self.assertLogs("qiskit.transpiler.passes.layout.vf2_layout", level="DEBUG") as cm: + vf2_pass(qc, property_set) + self.assertIn( + "DEBUG:qiskit.transpiler.passes.layout.vf2_layout:Trial 717 is >= configured max trials 717", + cm.output, + ) + self.assertEqual(set(property_set["layout"].get_physical_bits()), {16, 24, 6, 7, 0}) + def test_no_limits_with_negative(self): """Test that we're not enforcing a trial limit if set to negative.""" - backend = Fake5QV1() + with self.assertWarns(DeprecationWarning): + backend = Fake5QV1() qc = QuantumCircuit(3) qc.h(0) cmap = CouplingMap(backend.configuration().coupling_map) diff --git a/test/python/transpiler/test_vf2_post_layout.py b/test/python/transpiler/test_vf2_post_layout.py index 3df2fefcc73b..e97ed279a8d8 100644 --- a/test/python/transpiler/test_vf2_post_layout.py +++ b/test/python/transpiler/test_vf2_post_layout.py @@ -102,8 +102,9 @@ def test_no_backend_properties(self): def test_empty_circuit(self): """Test no solution found for empty circuit""" + with self.assertWarns(DeprecationWarning): + backend = Fake5QV1() qc = QuantumCircuit(2, 2) - backend = Fake5QV1() cmap = CouplingMap(backend.configuration().coupling_map) props = backend.properties() vf2_pass = VF2PostLayout(coupling_map=cmap, properties=props) @@ -128,9 +129,10 @@ def test_empty_circuit_v2(self): def test_skip_3q_circuit(self): """Test that the pass is a no-op on circuits with >2q gates.""" + with self.assertWarns(DeprecationWarning): + backend = Fake5QV1() qc = QuantumCircuit(3) qc.ccx(0, 1, 2) - backend = Fake5QV1() cmap = CouplingMap(backend.configuration().coupling_map) props = backend.properties() vf2_pass = VF2PostLayout(coupling_map=cmap, properties=props) @@ -141,10 +143,11 @@ def test_skip_3q_circuit(self): def test_skip_3q_circuit_control_flow(self): """Test that the pass is a no-op on circuits with >2q gates.""" + with self.assertWarns(DeprecationWarning): + backend = Fake5QV1() qc = QuantumCircuit(3) with qc.for_loop((1,)): qc.ccx(0, 1, 2) - backend = Fake5QV1() cmap = CouplingMap(backend.configuration().coupling_map) props = backend.properties() vf2_pass = VF2PostLayout(coupling_map=cmap, properties=props) @@ -182,7 +185,8 @@ def test_skip_3q_circuit_control_flow_v2(self): def test_best_mapping_ghz_state_full_device_multiple_qregs(self): """Test best mappings with multiple registers""" - backend = Fake5QV1() + with self.assertWarns(DeprecationWarning): + backend = Fake5QV1() qr_a = QuantumRegister(2) qr_b = QuantumRegister(3) qc = QuantumCircuit(qr_a, qr_b) @@ -207,7 +211,8 @@ def test_2q_circuit_5q_backend(self): 0 - 1 qr1 - qr0 """ - backend = Fake5QV1() + with self.assertWarns(DeprecationWarning): + backend = Fake5QV1() qr = QuantumRegister(2, "qr") circuit = QuantumCircuit(qr) @@ -227,7 +232,8 @@ def test_2q_circuit_5q_backend_controlflow(self): 0 - 1 qr1 - qr0 """ - backend = Fake5QV1() + with self.assertWarns(DeprecationWarning): + backend = Fake5QV1() circuit = QuantumCircuit(2, 1) with circuit.for_loop((1,)): @@ -253,7 +259,8 @@ def test_2q_circuit_5q_backend_max_trials(self): qr1 - qr0 """ max_trials = 11 - backend = Fake5QV1() + with self.assertWarns(DeprecationWarning): + backend = Fake5QV1() qr = QuantumRegister(2, "qr") circuit = QuantumCircuit(qr) @@ -564,8 +571,10 @@ def test_no_backend_properties(self): def test_empty_circuit(self): """Test no solution found for empty circuit""" + with self.assertWarns(DeprecationWarning): + backend = Fake5QV1() + qc = QuantumCircuit(2, 2) - backend = Fake5QV1() cmap = CouplingMap(backend.configuration().coupling_map) props = backend.properties() vf2_pass = VF2PostLayout(coupling_map=cmap, properties=props, strict_direction=False) @@ -593,9 +602,11 @@ def test_empty_circuit_v2(self): def test_skip_3q_circuit(self): """Test that the pass is a no-op on circuits with >2q gates.""" + with self.assertWarns(DeprecationWarning): + backend = Fake5QV1() + qc = QuantumCircuit(3) qc.ccx(0, 1, 2) - backend = Fake5QV1() cmap = CouplingMap(backend.configuration().coupling_map) props = backend.properties() vf2_pass = VF2PostLayout(coupling_map=cmap, properties=props, strict_direction=False) @@ -624,7 +635,8 @@ def test_skip_3q_circuit_v2(self): def test_best_mapping_ghz_state_full_device_multiple_qregs(self): """Test best mappings with multiple registers""" - backend = Fake5QV1() + with self.assertWarns(DeprecationWarning): + backend = Fake5QV1() qr_a = QuantumRegister(2) qr_b = QuantumRegister(3) qc = QuantumCircuit(qr_a, qr_b) @@ -651,7 +663,8 @@ def test_2q_circuit_5q_backend(self): 0 - 1 qr1 - qr0 """ - backend = Fake5QV1() + with self.assertWarns(DeprecationWarning): + backend = Fake5QV1() qr = QuantumRegister(2, "qr") circuit = QuantumCircuit(qr) diff --git a/test/python/visualization/test_circuit_drawer.py b/test/python/visualization/test_circuit_drawer.py index d459bd945046..dd69faac02cb 100644 --- a/test/python/visualization/test_circuit_drawer.py +++ b/test/python/visualization/test_circuit_drawer.py @@ -249,7 +249,7 @@ def test_warning_for_bad_justify_argument(self): error_message = re.escape( f"Setting QuantumCircuit.draw()’s or circuit_drawer()'s justify argument: {bad_arg}, to a " "value other than 'left', 'right', 'none' or None (='left'). Default 'left' will be used. " - "Support for invalid justify arguments is deprecated as of qiskit 1.2.0. Starting no " + "Support for invalid justify arguments is deprecated as of Qiskit 1.2.0. Starting no " "earlier than 3 months after the release date, invalid arguments will error.", ) diff --git a/test/python/visualization/test_circuit_latex.py b/test/python/visualization/test_circuit_latex.py index 5490648fd6bf..1be7ad7ce051 100644 --- a/test/python/visualization/test_circuit_latex.py +++ b/test/python/visualization/test_circuit_latex.py @@ -480,11 +480,15 @@ def test_partial_layout(self): """Tests partial_layout See: https://github.com/Qiskit/qiskit-terra/issues/4757""" filename = self._get_resource_path("test_latex_partial_layout.tex") + + with self.assertWarns(DeprecationWarning): + backend = Fake5QV1() + circuit = QuantumCircuit(3) circuit.h(1) transpiled = transpile( circuit, - backend=Fake5QV1(), + backend=backend, optimization_level=0, initial_layout=[1, 2, 0], seed_transpiler=0, diff --git a/test/python/visualization/test_gate_map.py b/test/python/visualization/test_gate_map.py index bf9b1ca80d79..fcac1e71c400 100644 --- a/test/python/visualization/test_gate_map.py +++ b/test/python/visualization/test_gate_map.py @@ -19,8 +19,6 @@ Fake5QV1, Fake20QV1, Fake7QPulseV1, - Fake27QPulseV1, - Fake127QPulseV1, GenericBackendV2, ) from qiskit.visualization import ( @@ -33,6 +31,7 @@ from qiskit import QuantumRegister, QuantumCircuit from qiskit.transpiler.layout import Layout, TranspileLayout from .visualization import path_to_diagram_reference, QiskitVisualizationTestCase +from ..legacy_cmaps import KYOTO_CMAP, MUMBAI_CMAP if optionals.HAS_MATPLOTLIB: import matplotlib.pyplot as plt @@ -108,7 +107,11 @@ def test_plot_gate_map_no_backend(self): @unittest.skipUnless(optionals.HAS_SEABORN, "Seaborn not installed") def test_plot_error_map_backend_v1(self): """Test plotting error map with fake backend v1.""" - backend = Fake27QPulseV1() + backend = GenericBackendV2( + num_qubits=27, + pulse_channels=True, + coupling_map=MUMBAI_CMAP, + ) img_ref = path_to_diagram_reference("fake_27_q_error.png") fig = plot_error_map(backend) with BytesIO() as img_buffer: @@ -122,9 +125,11 @@ def test_plot_error_map_backend_v1(self): @unittest.skipUnless(optionals.HAS_SEABORN, "Seaborn not installed") def test_plot_error_map_backend_v2(self): """Test plotting error map with fake backend v2.""" + coupling_map = MUMBAI_CMAP backend = GenericBackendV2( num_qubits=27, - coupling_map=Fake27QPulseV1().configuration().coupling_map, + pulse_channels=True, + coupling_map=coupling_map, ) img_ref = path_to_diagram_reference("fake_27_q_v2_error.png") fig = plot_error_map(backend) @@ -139,7 +144,10 @@ def test_plot_error_map_backend_v2(self): @unittest.skipUnless(optionals.HAS_SEABORN, "Seaborn not installed") def test_plot_error_map_over_100_qubit(self): """Test plotting error map with large fake backend.""" - backend = Fake127QPulseV1() + coupling_map = KYOTO_CMAP + backend = GenericBackendV2( + num_qubits=127, coupling_map=coupling_map, pulse_channels=True, seed=42 + ) img_ref = path_to_diagram_reference("fake_127_q_error.png") fig = plot_error_map(backend) with BytesIO() as img_buffer: @@ -153,9 +161,294 @@ def test_plot_error_map_over_100_qubit(self): @unittest.skipUnless(optionals.HAS_SEABORN, "Seaborn not installed") def test_plot_error_map_over_100_qubit_backend_v2(self): """Test plotting error map with large fake backendv2.""" + coupling_map = [ + [0, 1], + [0, 14], + [1, 0], + [1, 2], + [2, 1], + [2, 3], + [3, 2], + [3, 4], + [4, 3], + [4, 5], + [4, 15], + [5, 4], + [5, 6], + [6, 5], + [6, 7], + [7, 6], + [7, 8], + [8, 7], + [8, 16], + [9, 10], + [10, 9], + [10, 11], + [11, 10], + [11, 12], + [12, 11], + [12, 13], + [12, 17], + [13, 12], + [14, 0], + [14, 18], + [15, 4], + [15, 22], + [16, 8], + [16, 26], + [17, 12], + [17, 30], + [18, 14], + [18, 19], + [19, 18], + [19, 20], + [20, 19], + [20, 21], + [20, 33], + [21, 20], + [21, 22], + [22, 15], + [22, 21], + [22, 23], + [23, 22], + [23, 24], + [24, 23], + [24, 25], + [24, 34], + [25, 24], + [25, 26], + [26, 16], + [26, 25], + [26, 27], + [27, 26], + [27, 28], + [28, 27], + [28, 29], + [28, 35], + [29, 28], + [29, 30], + [30, 17], + [30, 29], + [30, 31], + [31, 30], + [31, 32], + [32, 31], + [32, 36], + [33, 20], + [33, 39], + [34, 24], + [34, 43], + [35, 28], + [35, 47], + [36, 32], + [36, 51], + [37, 38], + [37, 52], + [38, 37], + [38, 39], + [39, 33], + [39, 38], + [39, 40], + [40, 39], + [40, 41], + [41, 40], + [41, 42], + [41, 53], + [42, 41], + [42, 43], + [43, 34], + [43, 42], + [43, 44], + [44, 43], + [44, 45], + [45, 44], + [45, 46], + [45, 54], + [46, 45], + [46, 47], + [47, 35], + [47, 46], + [47, 48], + [48, 47], + [48, 49], + [49, 48], + [49, 50], + [49, 55], + [50, 49], + [50, 51], + [51, 36], + [51, 50], + [52, 37], + [52, 56], + [53, 41], + [53, 60], + [54, 45], + [54, 64], + [55, 49], + [55, 68], + [56, 52], + [56, 57], + [57, 56], + [57, 58], + [58, 57], + [58, 59], + [58, 71], + [59, 58], + [59, 60], + [60, 53], + [60, 59], + [60, 61], + [61, 60], + [61, 62], + [62, 61], + [62, 63], + [62, 72], + [63, 62], + [63, 64], + [64, 54], + [64, 63], + [64, 65], + [65, 64], + [65, 66], + [66, 65], + [66, 67], + [66, 73], + [67, 66], + [67, 68], + [68, 55], + [68, 67], + [68, 69], + [69, 68], + [69, 70], + [70, 69], + [70, 74], + [71, 58], + [71, 77], + [72, 62], + [72, 81], + [73, 66], + [73, 85], + [74, 70], + [74, 89], + [75, 76], + [75, 90], + [76, 75], + [76, 77], + [77, 71], + [77, 76], + [77, 78], + [78, 77], + [78, 79], + [79, 78], + [79, 80], + [79, 91], + [80, 79], + [80, 81], + [81, 72], + [81, 80], + [81, 82], + [82, 81], + [82, 83], + [83, 82], + [83, 84], + [83, 92], + [84, 83], + [84, 85], + [85, 73], + [85, 84], + [85, 86], + [86, 85], + [86, 87], + [87, 86], + [87, 88], + [87, 93], + [88, 87], + [88, 89], + [89, 74], + [89, 88], + [90, 75], + [90, 94], + [91, 79], + [91, 98], + [92, 83], + [92, 102], + [93, 87], + [93, 106], + [94, 90], + [94, 95], + [95, 94], + [95, 96], + [96, 95], + [96, 97], + [96, 109], + [97, 96], + [97, 98], + [98, 91], + [98, 97], + [98, 99], + [99, 98], + [99, 100], + [100, 99], + [100, 101], + [100, 110], + [101, 100], + [101, 102], + [102, 92], + [102, 101], + [102, 103], + [103, 102], + [103, 104], + [104, 103], + [104, 105], + [104, 111], + [105, 104], + [105, 106], + [106, 93], + [106, 105], + [106, 107], + [107, 106], + [107, 108], + [108, 107], + [108, 112], + [109, 96], + [110, 100], + [110, 118], + [111, 104], + [111, 122], + [112, 108], + [112, 126], + [113, 114], + [114, 113], + [114, 115], + [115, 114], + [115, 116], + [116, 115], + [116, 117], + [117, 116], + [117, 118], + [118, 110], + [118, 117], + [118, 119], + [119, 118], + [119, 120], + [120, 119], + [120, 121], + [121, 120], + [121, 122], + [122, 111], + [122, 121], + [122, 123], + [123, 122], + [123, 124], + [124, 123], + [124, 125], + [125, 124], + [125, 126], + [126, 112], + [126, 125], + ] backend = GenericBackendV2( - num_qubits=127, - coupling_map=Fake127QPulseV1().configuration().coupling_map, + num_qubits=127, coupling_map=coupling_map, pulse_channels=True, seed=42 ) img_ref = path_to_diagram_reference("fake_127_q_v2_error.png") fig = plot_error_map(backend)