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

Use singleton SwapGate in Sabre reconstruction #10865

Merged
merged 1 commit into from
Sep 20, 2023
Merged
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/passes/routing/sabre_swap.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,10 @@ def _apply_sabre_result(
:class:`.DAGCircuit` that represents the same thing.
"""

# The swap gate is a singleton instance, so we don't need to waste time reconstructing it each
# time we need to use it.
swap_singleton = SwapGate()

def empty_dag(block):
empty = DAGCircuit()
empty.add_qubits(out_dag.qubits)
Expand All @@ -362,7 +366,7 @@ def apply_swaps(dest_dag, swaps, layout):
for a, b in swaps:
qubits = (physical_qubits[a], physical_qubits[b])
layout.swap_physical(a, b)
dest_dag.apply_operation_back(SwapGate(), qubits, (), check=False)
dest_dag.apply_operation_back(swap_singleton, qubits, (), check=False)

def recurse(dest_dag, source_dag, result, root_logical_map, layout):
"""The main recursive worker. Mutates ``dest_dag`` and ``layout`` and returns them.
Expand Down