Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

List support for coupling map in pass manager #11063

Merged
merged 5 commits into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion qiskit/transpiler/preset_passmanagers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@

from qiskit.transpiler.passmanager_config import PassManagerConfig
from qiskit.transpiler.target import target_to_backend_properties
from qiskit.transpiler import CouplingMap

from .level0 import level_0_pass_manager
from .level1 import level_1_pass_manager
Expand Down Expand Up @@ -130,7 +131,7 @@ def generate_preset_pass_manager(
circuit, transpiler attaches the custom gate definition to the circuit.
This enables one to flexibly override the low-level instruction
implementation.
coupling_map (CouplingMap): Directed graph represented a coupling
coupling_map (CouplingMap or list): Directed graph represented a coupling
map.
instruction_durations (InstructionDurations): Dictionary of duration
(in dt) for each instruction.
Expand Down Expand Up @@ -213,6 +214,9 @@ def generate_preset_pass_manager(
stacklevel=2,
)

if coupling_map is not None and not isinstance(coupling_map, CouplingMap):
coupling_map = CouplingMap(coupling_map)

if target is not None:
if coupling_map is None:
coupling_map = target.build_coupling_map()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
features:
- |
Enhanced the :func:`.generate_preset_pass_manager` function to allow users to
provide a coupling map as a legacy-format list. Previously, users were required
to provide a :class:`.CouplingMap` object.
33 changes: 32 additions & 1 deletion test/python/transpiler/test_preset_passmanagers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1272,7 +1272,7 @@ def test_size_optimization(self, level):


@ddt
class TestGeenratePresetPassManagers(QiskitTestCase):
class TestGeneratePresetPassManagers(QiskitTestCase):
"""Test generate_preset_pass_manager function."""

@data(0, 1, 2, 3)
Expand Down Expand Up @@ -1445,6 +1445,37 @@ def get_translation_stage_plugin(self):
]
self.assertIn("RemoveResetInZeroState", post_translation_pass_list)

def test_generate_preset_pass_manager_with_list_coupling_map(self):
"""Test that generate_preset_pass_manager can handle list-based coupling_map."""

# Define the coupling map as a list
coupling_map_list = [[0, 1]]
coupling_map_object = CouplingMap(coupling_map_list)

# Circuit that doesn't fit in the coupling map
qc = QuantumCircuit(2)
qc.h(0)
qc.cx(0, 1)
qc.cx(1, 0)
qc.measure_all()

pm_list = generate_preset_pass_manager(
optimization_level=0, coupling_map=coupling_map_list, seed_transpiler=42
)
pm_object = generate_preset_pass_manager(
optimization_level=0, coupling_map=coupling_map_object, seed_transpiler=42
)

transpiled_circuit_list = pm_list.run(qc)
transpiled_circuit_object = pm_object.run(qc)

# Check if both are instances of PassManager
self.assertIsInstance(pm_list, PassManager)
self.assertIsInstance(pm_object, PassManager)

# Ensure the DAGs from both methods are identical
self.assertEqual(transpiled_circuit_list, transpiled_circuit_object)


@ddt
class TestIntegrationControlFlow(QiskitTestCase):
Expand Down