Skip to content

Commit

Permalink
Don't run both ZSX and ZSXX basis in Optimize1qGatesDecomposition
Browse files Browse the repository at this point in the history
Currently in the Optimize1qGatesDecomposition transpielr pass we build a
list of valid bases for the decomposer to synthesize the 1q unitary for.
However, in the case of the overlapping bases ZSX and ZSXX if ZSXX is
valid we end up doing the same work twice for no reason. ZSX and ZSXX
produce the same basic output except ZSXX will always be the same or
more efficient if multiple sx gates can be simplified to an x gate. So
there is no need for us to run 2 decomposers in that case. This commit
updates the pass to only run ZSXX if both ZSX and ZSXX are valid bases
to use.
  • Loading branch information
mtreinish committed Apr 23, 2023
1 parent 73c1e1c commit fb105b8
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions qiskit/transpiler/passes/optimization/optimize_1q_decomposition.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,16 @@ def _possible_decomposers(basis_set):
for euler_basis_name, gates in euler_basis_gates.items():
if set(gates).issubset(basis_set):
decomposers.append(euler_basis_name)
# If both U3 and U321 are in decomposer list only run U321 because
# in worst case it will produce the same U3 output, but in the general
# case it will use U2 and U1 which will be more efficient.
if "U3" in decomposers and "U321" in decomposers:
decomposers.remove("U3")
# If both ZSX and ZSXX are in decomposer list only run ZSXX because
# in the worst case it will produce the same output, but in the general
# case it will simplify X rotations to use X gate instead of multiple
# SX gates and be more efficient. Running multiple decomposers in this
# case will just waste time.
if "ZSX" in decomposers and "ZSXX" in decomposers:
decomposers.remove("ZSX")
return decomposers

0 comments on commit fb105b8

Please sign in to comment.