|
22 | 22 | import rustworkx |
23 | 23 |
|
24 | 24 | from qiskit import QuantumRegister, QuantumCircuit, ClassicalRegister |
25 | | -from qiskit.circuit import ControlFlowOp |
| 25 | +from qiskit.circuit import ControlFlowOp, Qubit |
26 | 26 | from qiskit.transpiler import CouplingMap, Target, TranspilerError |
27 | 27 | from qiskit.transpiler.passes.layout.vf2_layout import VF2Layout, VF2LayoutStopReason |
28 | 28 | from qiskit._accelerate.error_map import ErrorMap |
|
33 | 33 | from qiskit.transpiler import PassManager, AnalysisPass |
34 | 34 | from qiskit.transpiler.target import InstructionProperties |
35 | 35 | from qiskit.transpiler.preset_passmanagers.common import generate_embed_passmanager |
36 | | -from test import QiskitTestCase # pylint: disable=wrong-import-order |
| 36 | +from test import QiskitTestCase, combine # pylint: disable=wrong-import-order |
37 | 37 |
|
38 | 38 | from ..legacy_cmaps import TENERIFE_CMAP, RUESCHLIKON_CMAP, MANHATTAN_CMAP, YORKTOWN_CMAP |
39 | 39 |
|
@@ -307,6 +307,25 @@ def test_determinism_all_1q(self): |
307 | 307 | layouts[0], layout, f"Layout for execution {i} differs from the expected" |
308 | 308 | ) |
309 | 309 |
|
| 310 | + @combine( |
| 311 | + seed=(-1, 12), # This hits both the "seeded" and "unseeded" paths. |
| 312 | + strict_direction=(True, False), |
| 313 | + ) |
| 314 | + def test_complete_layout_with_idle_qubits(self, seed, strict_direction): |
| 315 | + """Test that completely idle qubits are included in the resulting layout.""" |
| 316 | + # Use registerless qubits to avoid any register-based shenangigans from adding the bits |
| 317 | + # automatically. |
| 318 | + qc = QuantumCircuit([Qubit() for _ in range(3)]) |
| 319 | + qc.cx(0, 1) |
| 320 | + target = Target.from_configuration( |
| 321 | + num_qubits=3, basis_gates=["sx", "rz", "cx"], coupling_map=CouplingMap.from_line(3) |
| 322 | + ) |
| 323 | + property_set = {} |
| 324 | + pass_ = VF2Layout(target=target, seed=seed, strict_direction=strict_direction) |
| 325 | + pass_(qc, property_set=property_set) |
| 326 | + unallocated = {i for i, bit in enumerate(qc.qubits) if bit not in property_set["layout"]} |
| 327 | + self.assertEqual(unallocated, set()) |
| 328 | + |
310 | 329 |
|
311 | 330 | @ddt.ddt |
312 | 331 | class TestVF2LayoutLattice(LayoutTestCase): |
|
0 commit comments