Skip to content

Commit

Permalink
Restore approx 0 rounding to decomp0 method (#4862)
Browse files Browse the repository at this point in the history
In #4656 we added rounding to the output of the decomp0 method to handle
a case where differing FP precision on windows environments was causing
an expected result in running two_qubit_cnot_decompose on np.eye(4)
with numpy 1.19.x installed leading to a hard failure in the qasm tests.
This seemed to reliably unblock testing and make unit tests work
reliably. However, that original fix from #4656 was superseded by #4835
which was a fix for a more general issue with the reproducibility of the
decompositions and reverted. Since #4835 has merged we've been seeing an
uptick in the failure rate on the same unitary qasm test that #4656
fixed, so the change in #4835 was not actually sufficient for the
windows case. This commit restores the fix from #4656 to unblock CI and
fix the reproducability of the decompositions across systems.

Fixes #4856
  • Loading branch information
mtreinish authored Aug 4, 2020
1 parent d8b5f0f commit 83d40dd
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions qiskit/quantum_info/synthesis/two_qubit_decompose.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,15 +382,18 @@ def traces(self, target):
4]

@staticmethod
def decomp0(target):
def decomp0(target, eps=1e-15):
"""Decompose target ~Ud(x, y, z) with 0 uses of the basis gate.
Result Ur has trace:
:math:`|Tr(Ur.Utarget^dag)| = 4|(cos(x)cos(y)cos(z)+ j sin(x)sin(y)sin(z)|`,
which is optimal for all targets and bases"""

U0l = target.K1l.dot(target.K2l)
U0r = target.K1r.dot(target.K2r)

U0l.real[abs(U0l.real) < eps] = 0.0
U0l.imag[abs(U0l.imag) < eps] = 0.0
U0r.real[abs(U0r.real) < eps] = 0.0
U0r.imag[abs(U0r.imag) < eps] = 0.0
return U0r, U0l

def decomp1(self, target):
Expand Down

0 comments on commit 83d40dd

Please sign in to comment.