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

Document generate_preset_pass_manager supports list for initial_layout #12214

Merged
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
2 changes: 1 addition & 1 deletion qiskit/transpiler/preset_passmanagers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def generate_preset_pass_manager(
instruction_durations (InstructionDurations): Dictionary of duration
(in dt) for each instruction.
timing_constraints (TimingConstraints): Hardware time alignment restrictions.
initial_layout (Layout): Initial position of virtual qubits on
initial_layout (Layout | List[int]): Initial position of virtual qubits on
physical qubits.
layout_method (str): The :class:`~.Pass` to use for choosing initial qubit
placement. Valid choices are ``'trivial'``, ``'dense'``,
Expand Down
32 changes: 32 additions & 0 deletions test/python/transpiler/test_preset_passmanagers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1436,6 +1436,38 @@ def test_generate_preset_pass_manager_with_list_coupling_map(self):
# Ensure the DAGs from both methods are identical
self.assertEqual(transpiled_circuit_list, transpiled_circuit_object)

@data(0, 1, 2, 3)
def test_generate_preset_pass_manager_with_list_initial_layout(self, optimization_level):
"""Test that generate_preset_pass_manager can handle list based initial layouts."""
coupling_map_list = [[0, 1]]

# 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=optimization_level,
coupling_map=coupling_map_list,
basis_gates=["u", "cx"],
seed_transpiler=42,
initial_layout=[1, 0],
)
pm_object = generate_preset_pass_manager(
optimization_level=optimization_level,
coupling_map=coupling_map_list,
basis_gates=["u", "cx"],
seed_transpiler=42,
initial_layout=Layout.from_intlist([1, 0], *qc.qregs),
)
tqc_list = pm_list.run(qc)
tqc_obj = pm_list.run(qc)
self.assertIsInstance(pm_list, PassManager)
self.assertIsInstance(pm_object, PassManager)
self.assertEqual(tqc_list, tqc_obj)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't actually formally compare layouts in QuantumCircuit.__eq__ because we immediately convert to DAGCircuit, which doesn't have a layout field, but we do compare qubit positions, so this should be a fine test.



@ddt
class TestIntegrationControlFlow(QiskitTestCase):
Expand Down
Loading