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

Add VF2PostLayout pass #7862

Merged
merged 31 commits into from
Apr 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
d451d08
Add VF2PostLayout pass
mtreinish Apr 1, 2022
7b63d18
Fix matching callback function
mtreinish Apr 1, 2022
30355f1
Merge branch 'main' into post-layout-ala-mapomatic
mtreinish Apr 1, 2022
2c177c2
Fix lint
mtreinish Apr 1, 2022
7ffb187
Add back removed ancillas to layout
mtreinish Apr 1, 2022
bb7b3e4
Move VF2PostLayout before scheduling
mtreinish Apr 1, 2022
cc82c4a
Fix docs
mtreinish Apr 1, 2022
2a153cc
Drop max_trials and rely solely on time
mtreinish Apr 1, 2022
9368a96
Fix ancilla handling
mtreinish Apr 1, 2022
0ec350a
Restore original virtual bits and registers
mtreinish Apr 1, 2022
9d957c8
Only run post layout if no manual layout options are set
mtreinish Apr 1, 2022
93359c9
Only run VF2PostLayout if there are connectivity constraints in the t…
mtreinish Apr 1, 2022
3e456d7
Merge branch 'main' into post-layout-ala-mapomatic
mtreinish Apr 1, 2022
926680d
Adjust cost function to no be a sum of error rates
mtreinish Apr 2, 2022
8cb4ae9
Update tests that check exact layout
mtreinish Apr 2, 2022
f98b430
Fix lint
mtreinish Apr 2, 2022
9c95dd0
Fix typo in target node/edge match function
mtreinish Apr 4, 2022
9270a9b
Merge remote-tracking branch 'origin/main' into post-layout-ala-mapom…
mtreinish Apr 4, 2022
411e835
Add release notes
mtreinish Apr 5, 2022
b7f478a
Add tests
mtreinish Apr 5, 2022
48a4e4f
Merge branch 'main' into post-layout-ala-mapomatic
mtreinish Apr 5, 2022
ad6ac58
Merge remote-tracking branch 'origin/main' into post-layout-ala-mapom…
mtreinish Apr 21, 2022
356aad9
Update release notes
mtreinish Apr 21, 2022
3b8f208
Fix typos in release notes
mtreinish Apr 22, 2022
3b3c0a0
Add strict_direction flag to pass
mtreinish Apr 25, 2022
6873cf9
Merge remote-tracking branch 'origin/main' into post-layout-ala-mapom…
mtreinish Apr 25, 2022
5e90148
Move VF2PostLayout to right after routing in preset passmanagers
mtreinish Apr 25, 2022
878c69a
Updated expected test layout for v2 failing test case
mtreinish Apr 25, 2022
c5d7070
Fix doc issues
mtreinish Apr 26, 2022
70e2bfd
Merge remote-tracking branch 'origin/main' into post-layout-ala-mapom…
mtreinish Apr 26, 2022
29886f5
Merge branch 'main' into post-layout-ala-mapomatic
mergify[bot] Apr 26, 2022
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
9 changes: 9 additions & 0 deletions qiskit/transpiler/passes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,14 @@
LinearFunctionsSynthesis
LinearFunctionsToPermutations

Post Layout (Post transpile qubit selection)
============================================

.. autosummary::
:toctree: ../stubs/

VF2PostLayout

Additional Passes
=================

Expand Down Expand Up @@ -169,6 +177,7 @@
from .layout import SabreLayout
from .layout import CSPLayout
from .layout import VF2Layout
from .layout import VF2PostLayout
from .layout import ApplyLayout
from .layout import Layout2qDistance
from .layout import EnlargeWithAncilla
Expand Down
1 change: 1 addition & 0 deletions qiskit/transpiler/passes/layout/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from .sabre_layout import SabreLayout
from .csp_layout import CSPLayout
from .vf2_layout import VF2Layout
from .vf2_post_layout import VF2PostLayout
from .apply_layout import ApplyLayout
from .layout_2q_distance import Layout2qDistance
from .enlarge_with_ancilla import EnlargeWithAncilla
Expand Down
42 changes: 36 additions & 6 deletions qiskit/transpiler/passes/layout/apply_layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from qiskit.dagcircuit import DAGCircuit
from qiskit.transpiler.basepasses import TransformationPass
from qiskit.transpiler.exceptions import TranspilerError
from qiskit.transpiler.layout import Layout


class ApplyLayout(TransformationPass):
Expand All @@ -25,6 +26,13 @@ class ApplyLayout(TransformationPass):
by applying the Layout given in `property_set`.
Requires either of passes to set/select Layout, e.g. `SetLayout`, `TrivialLayout`.
Assumes the Layout has full physical qubits.

If a post layout pass is run and sets the ``post_layout`` property set field with
a new layout to use after ``ApplyLayout`` has already run once this pass will
compact the layouts so that we apply
``original_virtual`` -> ``existing_layout`` -> ``new_layout`` -> ``new_physical``
so that the output circuit and layout combination become:
``original_virtual`` -> ``new_physical``
"""

def run(self, dag):
Expand All @@ -47,8 +55,7 @@ def run(self, dag):
if len(layout) != (1 + max(layout.get_physical_bits())):
raise TranspilerError("The 'layout' must be full (with ancilla).")

for qreg in dag.qregs.values():
self.property_set["layout"].add_register(qreg)
post_layout = self.property_set["post_layout"]

q = QuantumRegister(len(layout), "q")

Expand All @@ -58,10 +65,33 @@ def run(self, dag):
new_dag.add_clbits(dag.clbits)
for creg in dag.cregs.values():
new_dag.add_creg(creg)
virtual_phsyical_map = layout.get_virtual_bits()
for node in dag.topological_op_nodes():
qargs = [q[virtual_phsyical_map[qarg]] for qarg in node.qargs]
new_dag.apply_operation_back(node.op, qargs, node.cargs)
if post_layout is None:
for qreg in dag.qregs.values():
self.property_set["layout"].add_register(qreg)
virtual_phsyical_map = layout.get_virtual_bits()
for node in dag.topological_op_nodes():
qargs = [q[virtual_phsyical_map[qarg]] for qarg in node.qargs]
new_dag.apply_operation_back(node.op, qargs, node.cargs)
else:
# First build a new layout object going from:
# old virtual -> old phsyical -> new virtual -> new physical
# to:
# old virtual -> new physical
full_layout = Layout()
old_phys_to_virtual = layout.get_physical_bits()
new_virtual_to_physical = post_layout.get_virtual_bits()
qubit_index_map = {bit: index for index, bit in enumerate(dag.qubits)}
for new_virt, new_phys in new_virtual_to_physical.items():
old_phys = qubit_index_map[new_virt]
old_virt = old_phys_to_virtual[old_phys]
full_layout.add(old_virt, new_phys)
for reg in layout.get_registers():
full_layout.add_register(reg)
# Apply new layout to the circuit
for node in dag.topological_op_nodes():
qargs = [q[new_virtual_to_physical[qarg]] for qarg in node.qargs]
new_dag.apply_operation_back(node.op, qargs, node.cargs)
self.property_set["layout"] = full_layout
new_dag._global_phase = dag._global_phase

return new_dag
Loading