Skip to content

Commit 5ce3a97

Browse files
committed
Fix more tests
1 parent 83b333f commit 5ce3a97

9 files changed

+179
-44
lines changed

qiskit/providers/fake_provider/generic_backend_v2.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,8 @@ def _add_noisy_instruction_to_target(
434434
instruction.name, qargs
435435
)
436436
for qubit in qargs:
437-
self._target[instruction.name][(qubit,)].calibration = calibration_entry
437+
if qubit < self.num_qubits:
438+
self._target[instruction.name][(qubit,)].calibration = calibration_entry
438439

439440
def run(self, run_input, **options):
440441
"""Run on the backend using a simulator.

test/python/compiler/test_transpiler.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,6 @@ def test_transpile_non_adjacent_layout(self):
204204
205205
13 - 12 - 11 - 10 - 9 - 8 - 7
206206
"""
207-
208207
cmap = [
209208
[0, 1],
210209
[0, 14],
@@ -2292,7 +2291,7 @@ def test_parallel_num_processes_kwarg(self, num_processes):
22922291
@data(0, 1, 2, 3)
22932292
def test_parallel_dispatch(self, opt_level):
22942293
"""Test that transpile in parallel works for all optimization levels."""
2295-
backend = GenericBackendV2(num_qubits=5)
2294+
backend = GenericBackendV2(num_qubits=5, basis_gates=["cx", "id", "rz", "sx", "x"], seed=42)
22962295
qr = QuantumRegister(5)
22972296
cr = ClassicalRegister(5)
22982297
qc = QuantumCircuit(qr, cr)

test/python/legacy_cmaps.py

+148
Original file line numberDiff line numberDiff line change
@@ -279,3 +279,151 @@
279279
[25, 26],
280280
[26, 25],
281281
]
282+
283+
# 65 qubits
284+
MANHATTAN_CMAP = [
285+
[0, 1],
286+
[0, 10],
287+
[1, 0],
288+
[1, 2],
289+
[2, 1],
290+
[2, 3],
291+
[3, 2],
292+
[3, 4],
293+
[4, 3],
294+
[4, 5],
295+
[4, 11],
296+
[5, 4],
297+
[5, 6],
298+
[6, 5],
299+
[6, 7],
300+
[7, 6],
301+
[7, 8],
302+
[8, 7],
303+
[8, 9],
304+
[8, 12],
305+
[9, 8],
306+
[10, 0],
307+
[10, 13],
308+
[11, 4],
309+
[11, 17],
310+
[12, 8],
311+
[12, 21],
312+
[13, 10],
313+
[13, 14],
314+
[14, 13],
315+
[14, 15],
316+
[15, 14],
317+
[15, 16],
318+
[15, 24],
319+
[16, 15],
320+
[16, 17],
321+
[17, 11],
322+
[17, 16],
323+
[17, 18],
324+
[18, 17],
325+
[18, 19],
326+
[19, 18],
327+
[19, 20],
328+
[19, 25],
329+
[20, 19],
330+
[20, 21],
331+
[21, 12],
332+
[21, 20],
333+
[21, 22],
334+
[22, 21],
335+
[22, 23],
336+
[23, 22],
337+
[23, 26],
338+
[24, 15],
339+
[24, 29],
340+
[25, 19],
341+
[25, 33],
342+
[26, 23],
343+
[26, 37],
344+
[27, 28],
345+
[27, 38],
346+
[28, 27],
347+
[28, 29],
348+
[29, 24],
349+
[29, 28],
350+
[29, 30],
351+
[30, 29],
352+
[30, 31],
353+
[31, 30],
354+
[31, 32],
355+
[31, 39],
356+
[32, 31],
357+
[32, 33],
358+
[33, 25],
359+
[33, 32],
360+
[33, 34],
361+
[34, 33],
362+
[34, 35],
363+
[35, 34],
364+
[35, 36],
365+
[35, 40],
366+
[36, 35],
367+
[36, 37],
368+
[37, 26],
369+
[37, 36],
370+
[38, 27],
371+
[38, 41],
372+
[39, 31],
373+
[39, 45],
374+
[40, 35],
375+
[40, 49],
376+
[41, 38],
377+
[41, 42],
378+
[42, 41],
379+
[42, 43],
380+
[43, 42],
381+
[43, 44],
382+
[43, 52],
383+
[44, 43],
384+
[44, 45],
385+
[45, 39],
386+
[45, 44],
387+
[45, 46],
388+
[46, 45],
389+
[46, 47],
390+
[47, 46],
391+
[47, 48],
392+
[47, 53],
393+
[48, 47],
394+
[48, 49],
395+
[49, 40],
396+
[49, 48],
397+
[49, 50],
398+
[50, 49],
399+
[50, 51],
400+
[51, 50],
401+
[51, 54],
402+
[52, 43],
403+
[52, 56],
404+
[53, 47],
405+
[53, 60],
406+
[54, 51],
407+
[54, 64],
408+
[55, 56],
409+
[56, 52],
410+
[56, 55],
411+
[56, 57],
412+
[57, 56],
413+
[57, 58],
414+
[58, 57],
415+
[58, 59],
416+
[59, 58],
417+
[59, 60],
418+
[60, 53],
419+
[60, 59],
420+
[60, 61],
421+
[61, 60],
422+
[61, 62],
423+
[62, 61],
424+
[62, 63],
425+
[63, 62],
426+
[63, 64],
427+
[64, 54],
428+
[64, 63],
429+
]

test/python/transpiler/test_calibrationbuilder.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This code is part of Qiskit.
22
#
3-
# (C) Copyright IBM 2020.
3+
# (C) Copyright IBM 2020, 2024.
44
#
55
# This code is licensed under the Apache License, Version 2.0. You may
66
# obtain a copy of this license in the LICENSE.txt file in the root directory
@@ -554,7 +554,6 @@ def test_pulse_schedule(self, theta: float):
554554

555555
def test_with_normalizerxangles(self):
556556
"""Checks that this pass works well with the NormalizeRXAngles pass."""
557-
backend = GenericBackendV2(num_qubits=5)
558557
# add Drag pulse to 'sx' calibrations
559558
sched = ScheduleBlock()
560559
sched.append(
@@ -573,7 +572,7 @@ def test_with_normalizerxangles(self):
573572
)
574573
ism = InstructionScheduleMap()
575574
ism.add("sx", (0,), sched)
576-
backend.target.add_calibrations_from_instruction_schedule_map(ism)
575+
backend = GenericBackendV2(num_qubits=5, calibrate_instructions=ism)
577576

578577
# NormalizeRXAngle pass should also be included because it's a required pass.
579578
pm = PassManager(RXCalibrationBuilder(backend.target))

test/python/transpiler/test_preset_passmanagers.py

+9-27
Original file line numberDiff line numberDiff line change
@@ -344,9 +344,7 @@ def test_backend(self, level):
344344
qc = QuantumCircuit(qr)
345345
qc.cx(qr[2], qr[4])
346346

347-
backend = GenericBackendV2(
348-
num_qubits=14, coupling_map=MELBOURNE_CMAP
349-
)
347+
backend = GenericBackendV2(num_qubits=14, coupling_map=MELBOURNE_CMAP)
350348

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

@@ -469,9 +467,7 @@ def get_translation_stage_plugin(self):
469467

470468
def test_level1_runs_vf2post_layout_when_routing_required(self):
471469
"""Test that if we run routing as part of sabre layout VF2PostLayout runs."""
472-
target = GenericBackendV2(
473-
num_qubits=7, coupling_map=LAGOS_CMAP
474-
)
470+
target = GenericBackendV2(num_qubits=7, coupling_map=LAGOS_CMAP)
475471
qc = QuantumCircuit(5)
476472
qc.h(0)
477473
qc.cy(0, 1)
@@ -494,9 +490,7 @@ def test_level1_runs_vf2post_layout_when_routing_required(self):
494490

495491
def test_level1_runs_vf2post_layout_when_routing_method_set_and_required(self):
496492
"""Test that if we run routing as part of sabre layout VF2PostLayout runs."""
497-
target = GenericBackendV2(
498-
num_qubits=7, coupling_map=LAGOS_CMAP
499-
)
493+
target = GenericBackendV2(num_qubits=7, coupling_map=LAGOS_CMAP)
500494
qc = QuantumCircuit(5)
501495
qc.h(0)
502496
qc.cy(0, 1)
@@ -1303,9 +1297,7 @@ def test_with_backend(self, optimization_level):
13031297
@data(0, 1, 2, 3)
13041298
def test_with_no_backend(self, optimization_level):
13051299
"""Test a passmanager is constructed with no backend and optimization level."""
1306-
target = GenericBackendV2(
1307-
num_qubits=7, coupling_map=LAGOS_CMAP
1308-
)
1300+
target = GenericBackendV2(num_qubits=7, coupling_map=LAGOS_CMAP)
13091301
pm = generate_preset_pass_manager(
13101302
optimization_level,
13111303
coupling_map=target.coupling_map,
@@ -1320,9 +1312,7 @@ def test_with_no_backend(self, optimization_level):
13201312
@data(0, 1, 2, 3)
13211313
def test_with_no_backend_only_target(self, optimization_level):
13221314
"""Test a passmanager is constructed with a manual target and optimization level."""
1323-
target = GenericBackendV2(
1324-
num_qubits=7, coupling_map=LAGOS_CMAP
1325-
)
1315+
target = GenericBackendV2(num_qubits=7, coupling_map=LAGOS_CMAP)
13261316
pm = generate_preset_pass_manager(optimization_level, target=target.target)
13271317
self.assertIsInstance(pm, PassManager)
13281318

@@ -1351,9 +1341,7 @@ def get_translation_stage_plugin(self):
13511341
"""Custom post translation stage."""
13521342
return "custom_stage_for_test"
13531343

1354-
target = TargetBackend(
1355-
num_qubits=7, coupling_map=LAGOS_CMAP
1356-
)
1344+
target = TargetBackend(num_qubits=7, coupling_map=LAGOS_CMAP)
13571345
pm = generate_preset_pass_manager(optimization_level, backend=target)
13581346
self.assertIsInstance(pm, PassManager)
13591347

@@ -1385,9 +1373,7 @@ def get_translation_stage_plugin(self):
13851373
"""Custom post translation stage."""
13861374
return "custom_stage_for_test"
13871375

1388-
target = TargetBackend(
1389-
num_qubits=7, coupling_map=LAGOS_CMAP
1390-
)
1376+
target = TargetBackend(num_qubits=7, coupling_map=LAGOS_CMAP)
13911377
pm = generate_preset_pass_manager(optimization_level, backend=target)
13921378
self.assertIsInstance(pm, PassManager)
13931379

@@ -1419,9 +1405,7 @@ def get_translation_stage_plugin(self):
14191405
"""Custom post translation stage."""
14201406
return "custom_stage_for_test"
14211407

1422-
target = TargetBackend(
1423-
num_qubits=7, coupling_map=LAGOS_CMAP
1424-
)
1408+
target = TargetBackend(num_qubits=7, coupling_map=LAGOS_CMAP)
14251409
pm = generate_preset_pass_manager(optimization_level, backend=target)
14261410
self.assertIsInstance(pm, PassManager)
14271411

@@ -1453,9 +1437,7 @@ def get_translation_stage_plugin(self):
14531437
"""Custom post translation stage."""
14541438
return "custom_stage_for_test"
14551439

1456-
target = TargetBackend(
1457-
num_qubits=7, coupling_map=LAGOS_CMAP
1458-
)
1440+
target = TargetBackend(num_qubits=7, coupling_map=LAGOS_CMAP)
14591441
pm = generate_preset_pass_manager(optimization_level, backend=target)
14601442
self.assertIsInstance(pm, PassManager)
14611443

test/python/transpiler/test_pulse_gate_pass.py

+14-9
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
from qiskit.quantum_info.random import random_unitary
2020
from test import QiskitTestCase # pylint: disable=wrong-import-order
2121

22-
from ..legacy_cmaps import BOGOTA_CMAP
22+
from test.python.legacy_cmaps import BOGOTA_CMAP
2323

2424

2525
@ddt.ddt
@@ -29,7 +29,6 @@ class TestPulseGate(QiskitTestCase):
2929
def setUp(self):
3030
super().setUp()
3131

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

3534
with pulse.build(name="sx_q0") as custom_sx_q0:
@@ -267,6 +266,7 @@ def test_multiple_instructions_with_different_parameters(self):
267266
# Remove timing constraints to avoid triggering
268267
# scheduling passes.
269268
backend.configuration().timing_constraints = {}
269+
270270
qc = circuit.QuantumCircuit(1)
271271
qc.append(circuit.Gate("my_gate", 1, [1.0]), [0])
272272
qc.append(circuit.Gate("my_gate", 1, [2.0]), [0])
@@ -310,6 +310,11 @@ def test_transpile_with_both_instmap_and_empty_target(self, opt_level):
310310
311311
Test case from Qiskit/qiskit-terra/#9489
312312
"""
313+
instmap = Fake27QPulseV1().defaults().instruction_schedule_map
314+
instmap.add("sx", (0,), self.custom_sx_q0)
315+
instmap.add("sx", (1,), self.custom_sx_q1)
316+
instmap.add("cx", (0, 1), self.custom_cx_q01)
317+
313318
# This doesn't have custom schedule definition
314319
target = GenericBackendV2(
315320
num_qubits=5,
@@ -347,12 +352,7 @@ def test_transpile_with_instmap_with_v2backend(self, opt_level):
347352
348353
Test case from Qiskit/qiskit-terra/#9489
349354
"""
350-
backend = GenericBackendV2(
351-
num_qubits=5,
352-
calibrate_instructions=Fake27QPulseV1().defaults().instruction_schedule_map,
353-
)
354-
355-
instmap = backend.target.instruction_schedule_map()
355+
instmap = Fake27QPulseV1().defaults().instruction_schedule_map
356356
instmap.add("sx", (0,), self.custom_sx_q0)
357357
instmap.add("sx", (1,), self.custom_sx_q1)
358358
instmap.add("cx", (0, 1), self.custom_cx_q01)
@@ -361,6 +361,11 @@ def test_transpile_with_instmap_with_v2backend(self, opt_level):
361361
qc.append(random_unitary(4, seed=123), [0, 1])
362362
qc.measure_all()
363363

364+
backend = GenericBackendV2(
365+
num_qubits=5,
366+
calibrate_instructions=Fake27QPulseV1().defaults().instruction_schedule_map,
367+
)
368+
364369
transpiled_qc = transpile(
365370
qc,
366371
backend,
@@ -432,7 +437,7 @@ def test_transpile_with_instmap_not_mutate_backend(self):
432437
)
433438
original_sx0 = backend.target["sx"][(0,)].calibration
434439

435-
instmap = backend.target.instruction_schedule_map()
440+
instmap = Fake27QPulseV1().defaults().instruction_schedule_map
436441
instmap.add("sx", (0,), self.custom_sx_q0)
437442

438443
qc = circuit.QuantumCircuit(1)

test/python/transpiler/test_sabre_layout.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ def test_integration_with_pass_manager(self):
431431
qct_initial_layout = qct.layout.initial_layout
432432
self.assertEqual(
433433
[qct_initial_layout[q] for q in self.circuit.qubits],
434-
[8, 9, 14, 13, 18, 19, 17, 16, 11, 10, 5, 6, 1, 2, 3, 7],
434+
[3, 8, 7, 12, 13, 14, 18, 17, 16, 11, 10, 5, 6, 1, 2, 4],
435435
)
436436

437437

test/python/transpiler/test_trivial_layout.py

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
from ..legacy_cmaps import RUESCHLIKON_CMAP, TENERIFE_CMAP
2727

28+
2829
class TestTrivialLayout(QiskitTestCase):
2930
"""Tests the TrivialLayout pass"""
3031

0 commit comments

Comments
 (0)