Skip to content

Commit

Permalink
Fix runtime scaling of StarPreRouting pass (#12376)
Browse files Browse the repository at this point in the history
This commit fixes a runtime performance scaling issue with the new
StarPreRouting pass. If there are any stars identified by the pass when
the pass goes to pre-route those star connectivity blocks it specifies a
custom lexicographical topological sort key to ensure the stars are
kept together in the sort. However the mechanism by which this sort key
was generated scaled quadratically with the number of DAG nodes in the
identified stars. This ended up being a large runtime performance
bottleneck. This commit fixes this issue by pre-computing the sort key
for all nodes in the stars and putting that in a dictionary so that when
we call rustworkx to perform the topological sort the sort key callback
does not become the bottleneck for the entire pass.
  • Loading branch information
mtreinish authored May 9, 2024
1 parent 8c8c78a commit 4a6c570
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions qiskit/transpiler/passes/routing/star_prerouting.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,13 +329,13 @@ def _apply_mapping(qargs, qubit_mapping, qubits):
last_2q_gate = None

int_digits = floor(log10(len(processing_order))) + 1
processing_order_s = set(processing_order)
processing_order_index_map = {
node: f"a{str(index).zfill(int(int_digits))}"
for index, node in enumerate(processing_order)
}

def tie_breaker_key(node):
if node in processing_order_s:
return "a" + str(processing_order.index(node)).zfill(int(int_digits))
else:
return node.sort_key
return processing_order_index_map.get(node, node.sort_key)

for node in dag.topological_op_nodes(key=tie_breaker_key):
block_id = node_to_block_id.get(node, None)
Expand Down

0 comments on commit 4a6c570

Please sign in to comment.