Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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,7 @@
---
features:
- |
Enhanced the `generate_preset_pass_manager` function to allow users to
directly provide a coupling map as a list. Previously, users were required
to provide a coupling map as an object. This change streamlines the process,
making it easier to define coupling maps without the need for object creation.
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
---
prelude: >
Replace this text with content to appear at the top of the section for this
release. All of the prelude content is merged together and then rendered
separately from the items listed in other parts of the file, so the text
needs to be worded so that both the prelude and the other items make sense
when read independently. This may mean repeating some details. Not every
release note requires a prelude. Usually only notes describing major
features or adding release theme details should have a prelude.
features:
- |
List new features here, or remove this section. All of the list items in
this section are combined when the release notes are rendered, so the text
needs to be worded so that it does not depend on any information only
available in another section, such as the prelude. This may mean repeating
some details.
issues:
- |
List known issues here, or remove this section. All of the list items in
this section are combined when the release notes are rendered, so the text
needs to be worded so that it does not depend on any information only
available in another section, such as the prelude. This may mean repeating
some details.
upgrade:
- |
List upgrade notes here, or remove this section. All of the list items in
this section are combined when the release notes are rendered, so the text
needs to be worded so that it does not depend on any information only
available in another section, such as the prelude. This may mean repeating
some details.
deprecations:
- |
List deprecations notes here, or remove this section. All of the list
items in this section are combined when the release notes are rendered, so
the text needs to be worded so that it does not depend on any information
only available in another section, such as the prelude. This may mean
repeating some details.
critical:
- |
Add critical notes here, or remove this section. All of the list items in
this section are combined when the release notes are rendered, so the text
needs to be worded so that it does not depend on any information only
available in another section, such as the prelude. This may mean repeating
some details.
security:
- |
Add security notes here, or remove this section. All of the list items in
this section are combined when the release notes are rendered, so the text
needs to be worded so that it does not depend on any information only
available in another section, such as the prelude. This may mean repeating
some details.
fixes:
- |
Add normal bug fixes here, or remove this section. All of the list items
in this section are combined when the release notes are rendered, so the
text needs to be worded so that it does not depend on any information only
available in another section, such as the prelude. This may mean repeating
some details.
other:
- |
Add other notes here, or remove this section. All of the list items in
this section are combined when the release notes are rendered, so the text
needs to be worded so that it does not depend on any information only
available in another section, such as the prelude. This may mean repeating
some details.
31 changes: 30 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,35 @@ 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)
pm_object = generate_preset_pass_manager(
optimization_level=0, coupling_map=coupling_map_object
)

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