Skip to content

Commit

Permalink
Improve performance of basis_gates path
Browse files Browse the repository at this point in the history
This commit improves the performance of the basis_gates code path by
combining the basis_gates set with the built-in directives and doing
only one set lookup per iteration instead of two.

Co-authored-by: John Lapeyre <[email protected]>
  • Loading branch information
mtreinish and jlapeyre committed Jan 20, 2022
1 parent 9f9c935 commit 557362f
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions qiskit/transpiler/passes/utils/gates_basis.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ def __init__(self, basis_gates=None, target=None):
"A value for 'basis_gates' or 'target' must be set to use this pass"
)
if basis_gates is not None:
self._basis_gates = set(basis_gates)
self._basis_gates = set(basis_gates).union(
{"measure", "reset", "barrier", "snapshot", "delay"}
)
self._target = target

def run(self, dag):
Expand All @@ -55,9 +57,8 @@ def run(self, dag):
gates_out_of_basis = True
break
else:
basic_instrs = {"measure", "reset", "barrier", "snapshot", "delay"}
for gate in dag._op_names:
if gate not in self._basis_gates and gate not in basic_instrs:
if gate not in self._basis_gates:
gates_out_of_basis = True
break
self.property_set["all_gates_in_basis"] = not gates_out_of_basis

0 comments on commit 557362f

Please sign in to comment.