Skip to content

Commit

Permalink
Optimize UnrollCustomDefinitions pass (Qiskit#10777)
Browse files Browse the repository at this point in the history
This commit makes some small tweaks to the UnrollCustomDefinitions pass
to optimize it's runtime performance. It makes 2 primary changes to
improve the efficiency. First, when calling `circuit_to_dag()` the
copy_operations flag is set to False. This eliminates an inner deep copy
from the conversion which will make the conversion operate more
efficiently. The second is previously on every recursive call to run the
pass we were previously reconstructing the pass on every execution.
Instead this just reuses the existing instance. This will have less
measurable of an impact as the pass construction is relatively fast, but
it was unecessary work as we already have a pass object that can reused.
  • Loading branch information
mtreinish authored Sep 5, 2023
1 parent 4a57411 commit 61e5bde
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions qiskit/transpiler/passes/basis/unroll_custom_definitions.py
Original file line number Diff line number Diff line change
@@ -97,10 +97,8 @@ def run(self, dag):
"and no rule found to expand." % (str(self._basis_gates), node.op.name)
)

decomposition = circuit_to_dag(unrolled)
unrolled_dag = UnrollCustomDefinitions(
self._equiv_lib, self._basis_gates, target=self._target
).run(decomposition)
decomposition = circuit_to_dag(unrolled, copy_operations=False)
unrolled_dag = self.run(decomposition)
dag.substitute_node_with_dag(node, unrolled_dag)

return dag

0 comments on commit 61e5bde

Please sign in to comment.