Skip to content

Commit

Permalink
simplify dadnode handling of swap and cz
Browse files Browse the repository at this point in the history
  • Loading branch information
ewinston committed Sep 28, 2022
1 parent 4f1af5b commit 463a466
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 10 deletions.
7 changes: 2 additions & 5 deletions qiskit/dagcircuit/dagnode.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,10 @@ def semantic_eq(node1, node2, bit_indices1=None, bit_indices2=None):
node2_cargs = [bit_indices2[carg] for carg in node2.cargs]

# For barriers, qarg order is not significant so compare as sets
if "barrier" == node1.op.name == node2.op.name:
if node1.op.name == node2.op.name and node1.name in {"barrier", "swap", "cz"}:
return set(node1_qargs) == set(node2_qargs)

if node1_qargs == node2_qargs or (
(node1.op.name == node2.op.name in {"swap", "cz"})
and (set(node1_qargs) == set(node2_qargs))
):
if node1_qargs == node2_qargs):
if node1_cargs == node2_cargs:
if getattr(node1.op, "condition", None) == getattr(node2.op, "condition", None):
if node1.op == node2.op:
Expand Down
4 changes: 2 additions & 2 deletions qiskit/transpiler/passes/routing/layout_transformation.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ def run(self, dag):
perm_circ = self.token_swapper.permutation_circuit(permutation, self.trials)

qubits = [dag.qubits[i[0]] for i in sorted(perm_circ.inputmap.items(), key=lambda x: x[0])]
self.perm_circ = perm_circ
self.perm_qubits = qubits
self.property_set["perm_circ"] = perm_circ
self.property_set["perm_qubits"] = qubits

dag.compose(perm_circ.circuit, qubits=qubits, inplace=self.inplace)
return dag
4 changes: 1 addition & 3 deletions qiskit/transpiler/passes/routing/stochastic_swap.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,6 @@ def _layer_update(self, dag, layer, best_layout, best_depth, best_circuit):
def _mapper(self, circuit_graph, coupling_graph, trials=20):
"""Map a DAGCircuit onto a CouplingMap using swap gates.
Use self.trivial_layout for the initial layout.
Args:
circuit_graph (DAGCircuit): input DAG circuit
coupling_graph (CouplingMap): coupling graph to map onto
Expand Down Expand Up @@ -297,7 +295,7 @@ def _mapper(self, circuit_graph, coupling_graph, trials=20):
if not self.fake_run:
dagcircuit_output = circuit_graph.copy_empty_like()

logger.debug("trivial_layout = %s", layout)
logger.debug("layout = %s", layout)
# Iterate over layers
for i, layer in enumerate(layerlist):
subdag = layer["graph"]
Expand Down

0 comments on commit 463a466

Please sign in to comment.