Fix incorrect graph construction in VF2PostLayout (#9058)

The `add_nodes` call should be outside the loop; inside, it adds nodes
quadratically.  This commit also squashes a minor inefficiency in set
allocation.
This commit is contained in:
Jake Lishman 2022-11-02 17:31:47 +00:00 committed by GitHub
parent a2ea9288a2
commit 61ca9ca6b2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 4 deletions

View File

@ -169,16 +169,14 @@ class VF2PostLayout(AnalysisPass):
global_ops[num_qubits].append(op)
op_names = []
for i in range(self.target.num_qubits):
entry = set()
try:
entry = set(self.target.operation_names_for_qargs((i,)))
except KeyError:
pass
entry = set()
if global_ops is not None:
entry.update(global_ops[1])
op_names.append(entry)
cm_graph.add_nodes_from(op_names)
cm_graph.add_nodes_from(op_names)
for qargs in self.target.qargs:
len_args = len(qargs)
# If qargs == 1 we already populated it and if qargs > 2 there are no instructions

View File

@ -0,0 +1,7 @@
---
fixes:
- |
Fixed a bug in the :class:`.VF2PostLayout` pass when transpiling for backends
with a defined :class:`.Target`, where the interaction graph would be built
incorrectly. This could result in excessive runtimes due to the graph being
far more complex than necessary.