Skip to content

Commit

Permalink
Fix more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ElePT committed Jan 31, 2024
1 parent 83b333f commit 5ce3a97
Show file tree
Hide file tree
Showing 9 changed files with 179 additions and 44 deletions.
3 changes: 2 additions & 1 deletion qiskit/providers/fake_provider/generic_backend_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,8 @@ def _add_noisy_instruction_to_target(
instruction.name, qargs
)
for qubit in qargs:
self._target[instruction.name][(qubit,)].calibration = calibration_entry
if qubit < self.num_qubits:
self._target[instruction.name][(qubit,)].calibration = calibration_entry

def run(self, run_input, **options):
"""Run on the backend using a simulator.
Expand Down
3 changes: 1 addition & 2 deletions test/python/compiler/test_transpiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,6 @@ def test_transpile_non_adjacent_layout(self):
13 - 12 - 11 - 10 - 9 - 8 - 7
"""

cmap = [
[0, 1],
[0, 14],
Expand Down Expand Up @@ -2292,7 +2291,7 @@ def test_parallel_num_processes_kwarg(self, num_processes):
@data(0, 1, 2, 3)
def test_parallel_dispatch(self, opt_level):
"""Test that transpile in parallel works for all optimization levels."""
backend = GenericBackendV2(num_qubits=5)
backend = GenericBackendV2(num_qubits=5, basis_gates=["cx", "id", "rz", "sx", "x"], seed=42)
qr = QuantumRegister(5)
cr = ClassicalRegister(5)
qc = QuantumCircuit(qr, cr)
Expand Down
148 changes: 148 additions & 0 deletions test/python/legacy_cmaps.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,3 +279,151 @@
[25, 26],
[26, 25],
]

# 65 qubits
MANHATTAN_CMAP = [
[0, 1],
[0, 10],
[1, 0],
[1, 2],
[2, 1],
[2, 3],
[3, 2],
[3, 4],
[4, 3],
[4, 5],
[4, 11],
[5, 4],
[5, 6],
[6, 5],
[6, 7],
[7, 6],
[7, 8],
[8, 7],
[8, 9],
[8, 12],
[9, 8],
[10, 0],
[10, 13],
[11, 4],
[11, 17],
[12, 8],
[12, 21],
[13, 10],
[13, 14],
[14, 13],
[14, 15],
[15, 14],
[15, 16],
[15, 24],
[16, 15],
[16, 17],
[17, 11],
[17, 16],
[17, 18],
[18, 17],
[18, 19],
[19, 18],
[19, 20],
[19, 25],
[20, 19],
[20, 21],
[21, 12],
[21, 20],
[21, 22],
[22, 21],
[22, 23],
[23, 22],
[23, 26],
[24, 15],
[24, 29],
[25, 19],
[25, 33],
[26, 23],
[26, 37],
[27, 28],
[27, 38],
[28, 27],
[28, 29],
[29, 24],
[29, 28],
[29, 30],
[30, 29],
[30, 31],
[31, 30],
[31, 32],
[31, 39],
[32, 31],
[32, 33],
[33, 25],
[33, 32],
[33, 34],
[34, 33],
[34, 35],
[35, 34],
[35, 36],
[35, 40],
[36, 35],
[36, 37],
[37, 26],
[37, 36],
[38, 27],
[38, 41],
[39, 31],
[39, 45],
[40, 35],
[40, 49],
[41, 38],
[41, 42],
[42, 41],
[42, 43],
[43, 42],
[43, 44],
[43, 52],
[44, 43],
[44, 45],
[45, 39],
[45, 44],
[45, 46],
[46, 45],
[46, 47],
[47, 46],
[47, 48],
[47, 53],
[48, 47],
[48, 49],
[49, 40],
[49, 48],
[49, 50],
[50, 49],
[50, 51],
[51, 50],
[51, 54],
[52, 43],
[52, 56],
[53, 47],
[53, 60],
[54, 51],
[54, 64],
[55, 56],
[56, 52],
[56, 55],
[56, 57],
[57, 56],
[57, 58],
[58, 57],
[58, 59],
[59, 58],
[59, 60],
[60, 53],
[60, 59],
[60, 61],
[61, 60],
[61, 62],
[62, 61],
[62, 63],
[63, 62],
[63, 64],
[64, 54],
[64, 63],
]
5 changes: 2 additions & 3 deletions test/python/transpiler/test_calibrationbuilder.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This code is part of Qiskit.
#
# (C) Copyright IBM 2020.
# (C) Copyright IBM 2020, 2024.
#
# This code is licensed under the Apache License, Version 2.0. You may
# obtain a copy of this license in the LICENSE.txt file in the root directory
Expand Down Expand Up @@ -554,7 +554,6 @@ def test_pulse_schedule(self, theta: float):

def test_with_normalizerxangles(self):
"""Checks that this pass works well with the NormalizeRXAngles pass."""
backend = GenericBackendV2(num_qubits=5)
# add Drag pulse to 'sx' calibrations
sched = ScheduleBlock()
sched.append(
Expand All @@ -573,7 +572,7 @@ def test_with_normalizerxangles(self):
)
ism = InstructionScheduleMap()
ism.add("sx", (0,), sched)
backend.target.add_calibrations_from_instruction_schedule_map(ism)
backend = GenericBackendV2(num_qubits=5, calibrate_instructions=ism)

# NormalizeRXAngle pass should also be included because it's a required pass.
pm = PassManager(RXCalibrationBuilder(backend.target))
Expand Down
36 changes: 9 additions & 27 deletions test/python/transpiler/test_preset_passmanagers.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,9 +344,7 @@ def test_backend(self, level):
qc = QuantumCircuit(qr)
qc.cx(qr[2], qr[4])

backend = GenericBackendV2(
num_qubits=14, coupling_map=MELBOURNE_CMAP
)
backend = GenericBackendV2(num_qubits=14, coupling_map=MELBOURNE_CMAP)

_ = transpile(qc, backend, optimization_level=level, callback=self.callback)

Expand Down Expand Up @@ -469,9 +467,7 @@ def get_translation_stage_plugin(self):

def test_level1_runs_vf2post_layout_when_routing_required(self):
"""Test that if we run routing as part of sabre layout VF2PostLayout runs."""
target = GenericBackendV2(
num_qubits=7, coupling_map=LAGOS_CMAP
)
target = GenericBackendV2(num_qubits=7, coupling_map=LAGOS_CMAP)
qc = QuantumCircuit(5)
qc.h(0)
qc.cy(0, 1)
Expand All @@ -494,9 +490,7 @@ def test_level1_runs_vf2post_layout_when_routing_required(self):

def test_level1_runs_vf2post_layout_when_routing_method_set_and_required(self):
"""Test that if we run routing as part of sabre layout VF2PostLayout runs."""
target = GenericBackendV2(
num_qubits=7, coupling_map=LAGOS_CMAP
)
target = GenericBackendV2(num_qubits=7, coupling_map=LAGOS_CMAP)
qc = QuantumCircuit(5)
qc.h(0)
qc.cy(0, 1)
Expand Down Expand Up @@ -1303,9 +1297,7 @@ def test_with_backend(self, optimization_level):
@data(0, 1, 2, 3)
def test_with_no_backend(self, optimization_level):
"""Test a passmanager is constructed with no backend and optimization level."""
target = GenericBackendV2(
num_qubits=7, coupling_map=LAGOS_CMAP
)
target = GenericBackendV2(num_qubits=7, coupling_map=LAGOS_CMAP)
pm = generate_preset_pass_manager(
optimization_level,
coupling_map=target.coupling_map,
Expand All @@ -1320,9 +1312,7 @@ def test_with_no_backend(self, optimization_level):
@data(0, 1, 2, 3)
def test_with_no_backend_only_target(self, optimization_level):
"""Test a passmanager is constructed with a manual target and optimization level."""
target = GenericBackendV2(
num_qubits=7, coupling_map=LAGOS_CMAP
)
target = GenericBackendV2(num_qubits=7, coupling_map=LAGOS_CMAP)
pm = generate_preset_pass_manager(optimization_level, target=target.target)
self.assertIsInstance(pm, PassManager)

Expand Down Expand Up @@ -1351,9 +1341,7 @@ def get_translation_stage_plugin(self):
"""Custom post translation stage."""
return "custom_stage_for_test"

target = TargetBackend(
num_qubits=7, coupling_map=LAGOS_CMAP
)
target = TargetBackend(num_qubits=7, coupling_map=LAGOS_CMAP)
pm = generate_preset_pass_manager(optimization_level, backend=target)
self.assertIsInstance(pm, PassManager)

Expand Down Expand Up @@ -1385,9 +1373,7 @@ def get_translation_stage_plugin(self):
"""Custom post translation stage."""
return "custom_stage_for_test"

target = TargetBackend(
num_qubits=7, coupling_map=LAGOS_CMAP
)
target = TargetBackend(num_qubits=7, coupling_map=LAGOS_CMAP)
pm = generate_preset_pass_manager(optimization_level, backend=target)
self.assertIsInstance(pm, PassManager)

Expand Down Expand Up @@ -1419,9 +1405,7 @@ def get_translation_stage_plugin(self):
"""Custom post translation stage."""
return "custom_stage_for_test"

target = TargetBackend(
num_qubits=7, coupling_map=LAGOS_CMAP
)
target = TargetBackend(num_qubits=7, coupling_map=LAGOS_CMAP)
pm = generate_preset_pass_manager(optimization_level, backend=target)
self.assertIsInstance(pm, PassManager)

Expand Down Expand Up @@ -1453,9 +1437,7 @@ def get_translation_stage_plugin(self):
"""Custom post translation stage."""
return "custom_stage_for_test"

target = TargetBackend(
num_qubits=7, coupling_map=LAGOS_CMAP
)
target = TargetBackend(num_qubits=7, coupling_map=LAGOS_CMAP)
pm = generate_preset_pass_manager(optimization_level, backend=target)
self.assertIsInstance(pm, PassManager)

Expand Down
23 changes: 14 additions & 9 deletions test/python/transpiler/test_pulse_gate_pass.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from qiskit.quantum_info.random import random_unitary
from test import QiskitTestCase # pylint: disable=wrong-import-order

from ..legacy_cmaps import BOGOTA_CMAP
from test.python.legacy_cmaps import BOGOTA_CMAP


@ddt.ddt
Expand All @@ -29,7 +29,6 @@ class TestPulseGate(QiskitTestCase):
def setUp(self):
super().setUp()

self.basis_gates = ["cx", "id", "rz", "sx", "x"]
self.sched_param = circuit.Parameter("P0")

with pulse.build(name="sx_q0") as custom_sx_q0:
Expand Down Expand Up @@ -267,6 +266,7 @@ def test_multiple_instructions_with_different_parameters(self):
# Remove timing constraints to avoid triggering
# scheduling passes.
backend.configuration().timing_constraints = {}

qc = circuit.QuantumCircuit(1)
qc.append(circuit.Gate("my_gate", 1, [1.0]), [0])
qc.append(circuit.Gate("my_gate", 1, [2.0]), [0])
Expand Down Expand Up @@ -310,6 +310,11 @@ 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
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)

# This doesn't have custom schedule definition
target = GenericBackendV2(
num_qubits=5,
Expand Down Expand Up @@ -347,12 +352,7 @@ def test_transpile_with_instmap_with_v2backend(self, opt_level):
Test case from Qiskit/qiskit-terra/#9489
"""
backend = GenericBackendV2(
num_qubits=5,
calibrate_instructions=Fake27QPulseV1().defaults().instruction_schedule_map,
)

instmap = backend.target.instruction_schedule_map()
instmap = Fake27QPulseV1().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)
Expand All @@ -361,6 +361,11 @@ def test_transpile_with_instmap_with_v2backend(self, opt_level):
qc.append(random_unitary(4, seed=123), [0, 1])
qc.measure_all()

backend = GenericBackendV2(
num_qubits=5,
calibrate_instructions=Fake27QPulseV1().defaults().instruction_schedule_map,
)

transpiled_qc = transpile(
qc,
backend,
Expand Down Expand Up @@ -432,7 +437,7 @@ def test_transpile_with_instmap_not_mutate_backend(self):
)
original_sx0 = backend.target["sx"][(0,)].calibration

instmap = backend.target.instruction_schedule_map()
instmap = Fake27QPulseV1().defaults().instruction_schedule_map
instmap.add("sx", (0,), self.custom_sx_q0)

qc = circuit.QuantumCircuit(1)
Expand Down
2 changes: 1 addition & 1 deletion test/python/transpiler/test_sabre_layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ def test_integration_with_pass_manager(self):
qct_initial_layout = qct.layout.initial_layout
self.assertEqual(
[qct_initial_layout[q] for q in self.circuit.qubits],
[8, 9, 14, 13, 18, 19, 17, 16, 11, 10, 5, 6, 1, 2, 3, 7],
[3, 8, 7, 12, 13, 14, 18, 17, 16, 11, 10, 5, 6, 1, 2, 4],
)


Expand Down
1 change: 1 addition & 0 deletions test/python/transpiler/test_trivial_layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

from ..legacy_cmaps import RUESCHLIKON_CMAP, TENERIFE_CMAP


class TestTrivialLayout(QiskitTestCase):
"""Tests the TrivialLayout pass"""

Expand Down
Loading

0 comments on commit 5ce3a97

Please sign in to comment.