Skip to content

Commit

Permalink
Document generate_preset_pass_manager supports list for initial_layout (
Browse files Browse the repository at this point in the history
#12214)

This commit updates the documentation for the
generate_preset_pass_manager() function to clearly indicate that the
function will accept a integer list for the initial_layout field. This
already was supported but it wasn't documented. As it's now a documented
part of the API a unittest is added to ensure we don't regress this
functionality in the future.

Fixes #11690
  • Loading branch information
mtreinish committed Apr 18, 2024
1 parent d10f9a0 commit ff7ba3f
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
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)


@ddt
class TestIntegrationControlFlow(QiskitTestCase):
Expand Down

0 comments on commit ff7ba3f

Please sign in to comment.