Skip to content

Commit

Permalink
Avoid deepcopy in sabre_swap (#5316)
Browse files Browse the repository at this point in the history
This commit changes the deepcopy usage in the sabreswap pass to a
shallow copy. In sabre_swap the deepcopy was run on the DAGCircuit node
when remapping it, however this was not necessary because it's not
actually used where shared references matter. The output from the
remapper is not used directly and instead a copy of the DAGNode object
is just used as a container for the required args in
apply_operation_back() where a new DAGNode is always created from the
op, qargs, etc. The remapping just replaces the qargs parameter with the
remapped one. So this commit changes the deepcopy to a shallow copy
which won't have the performance overhead.

Fixes #5197

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
mtreinish and mergify[bot] authored Nov 2, 2020
1 parent 074a867 commit a506ba9
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions qiskit/transpiler/passes/routing/sabre_swap.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"""Routing via SWAP insertion using the SABRE method from Li et al."""

import logging
from copy import deepcopy
from copy import copy
from itertools import cycle
import numpy as np

Expand Down Expand Up @@ -336,7 +336,7 @@ def _score_heuristic(self, heuristic, front_layer, extended_set, layout, swap_qu

def _transform_gate_for_layout(op_node, layout):
"""Return node implementing a virtual op on given layout."""
mapped_op_node = deepcopy(op_node)
mapped_op_node = copy(op_node)

device_qreg = op_node.qargs[0].register
premap_qargs = op_node.qargs
Expand Down

0 comments on commit a506ba9

Please sign in to comment.