diff --git a/qiskit/transpiler/passes/routing/stochastic_swap.py b/qiskit/transpiler/passes/routing/stochastic_swap.py index 6935e74929fd..a06c2b851221 100644 --- a/qiskit/transpiler/passes/routing/stochastic_swap.py +++ b/qiskit/transpiler/passes/routing/stochastic_swap.py @@ -25,7 +25,6 @@ from qiskit.transpiler.passes.routing.utils import ( route_cf_multiblock, route_cf_looping, - get_ordered_virtual_qubits, combine_permutations, ) from qiskit.circuit import IfElseOp, WhileLoopOp, ForLoopOp, ControlFlowOp @@ -254,10 +253,11 @@ def _layer_update(self, dag, layer, best_layout, best_depth, best_circuit): logger.debug("layer_update: there are no swaps in this layer") # Output this layer layer_circuit = layer["graph"] - order = combine_permutations( - get_ordered_virtual_qubits(self.initial_layout, dag.qregs), - get_ordered_virtual_qubits(layout, dag.qregs), - ) + initial_v2p = self.initial_layout.get_virtual_bits() + new_v2p = layout.get_virtual_bits() + initial_order = [initial_v2p[qubit] for qubit in dag.qubits] + new_order = [new_v2p[qubit] for qubit in dag.qubits] + order = combine_permutations(initial_order, new_order) dag.compose(layer_circuit, qubits=order) def _mapper(self, circuit_graph, coupling_graph, trials=20): diff --git a/qiskit/transpiler/passes/routing/utils.py b/qiskit/transpiler/passes/routing/utils.py index ebbdff50a6c2..3895e4ddf6a3 100644 --- a/qiskit/transpiler/passes/routing/utils.py +++ b/qiskit/transpiler/passes/routing/utils.py @@ -165,21 +165,6 @@ def route_cf_looping(tpass, cf_opnode, current_layout, root_dag, seed=None): return cf_op.replace_blocks([updated_circ_block]), current_layout, idle_qubits -def get_ordered_virtual_qubits(layout, qregs): - """Get list of virtual qubits associated with ordered list - of physical qubits. - - Args: - layout (Layout): circuit layout - qregs (list(QuantumRegister)): list of registers for circuit - - Returns: - list(int): list of virtual qubit indices - """ - p2v = layout.get_virtual_bits() - return [p2v[qubit] for qreg in qregs.values() for qubit in qreg] - - def combine_permutations(*permutations): """ Chain a series of permutations.