ProjectQ icon indicating copy to clipboard operation
ProjectQ copied to clipboard

Fails to decompose single qubit unitary

Open emanuel-malvetti opened this issue 7 years ago • 1 comments

The following matrix cannot be decomposed even though it is unitary.

U = np.matrix([[(-0.7108860402090058-0.7033072016973199j),
                    (-9.403468524726843e-05+9.504800300819127e-05j)],
                   [(-9.507314515605492e-05+9.400926537078691e-05j),
                    (-0.7031170805491339-0.7110740841596025j)]])

In fact running np.linalg.norm(U.getH()*U - np.eye(2)) returns 5.462198399343198e-16.

Reducing TOLERANCE in arb1qubit2rzandry.py from 1e-12 to 1e-10 removes the exception, so I assume this is caused by cancellation effects, similar to what happens when solving the quadratic equation: https://en.wikipedia.org/wiki/Loss_of_significance#Instability_of_the_quadratic_equation

Exception: ("Couldn't find parameters for matrix ", [[(-0.7108860402090058-0.7033072016973199j), (-9.403468524726843e-05+9.504800300819127e-05j)], [(-9.507314515605492e-05+9.400926537078691e-05j), (-0.7031170805491339-0.7110740841596025j)]], "This shouldn't happen. Maybe the matrix is not unitary?")
 raised in:
'  File "/Users/isaac/Library/Python/3.5/lib/python/site-packages/projectq/setups/decompositions/arb1qubit2rzandry.py", line 192, in _find_parameters'
'    "not unitary?")'

emanuel-malvetti avatar Jun 02 '18 10:06 emanuel-malvetti

Thanks for pointing this out! I will try to make the current implementation more robust as soon as I find time.

thomashaener avatar Jun 07 '18 07:06 thomashaener