Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Work around numerical instability in get_information_content() #488

Open
cqc-alec opened this issue Aug 23, 2022 · 2 comments
Open

Work around numerical instability in get_information_content() #488

cqc-alec opened this issue Aug 23, 2022 · 2 comments
Labels

Comments

@cqc-alec
Copy link
Collaborator

When Eigen::SelfAdjointEigenSolver (called during KAK decomposition) finds repeated eigenvalues in a matrix, the eigenvectors and their order are not uniquely determined. Rounding errors lead to different results being returned on different platforms. We should find a way to normalize the decomposition in the presence of rounding errors. It seems that some decompositions are better than others when it comes to finding further Clifford simplifications. This needs further investigation.

@cqc-alec
Copy link
Collaborator Author

Partially solved by #491 . However, some issues remain. See this comparison of logs showing the results of the eigensolver and the resulting circuits on Linux and MacOS (from #498 ).

Linux:

============ Eigendecomposition =============
eigvals = 
(0,-1)
(0,-1)
 (0,1)
 (0,1)
eigvecs =
 (0.707107,0)         (0,0)         (0,0)  (0.707107,0)
        (0,0) (-0.707107,0) (-0.707107,0)         (0,0)
(-0.707107,0)         (0,0)         (0,0)  (0.707107,0)
        (0,0)  (0.707107,0) (-0.707107,0)         (0,0)
=============================================
============ Eigendecomposition =============
eigvals = 
(0,-1)
(0,-1)
 (0,1)
 (0,1)
eigvecs =
 (0.707107,0)         (0,0)         (0,0)  (0.707107,0)
        (0,0) (-0.707107,0) (-0.707107,0)         (0,0)
(-0.707107,0)         (0,0)         (0,0)  (0.707107,0)
        (0,0)  (0.707107,0) (-0.707107,0)         (0,0)
=============================================
TK1(0, 1, 0) q[0];
TK1(0, 3.5, 1) q[1];
TK2(0.5, 0, 0) q[0], q[1];
TK1(0, 3.5, 0.2) q[1];
TK2(0.5, 0, 0) q[0], q[1];
TK1(0.5, 0.5, 0.5) q[0];
TK1(0, 0, 1) q[1];
Phase (in half-turns): 0.0

============== (SythesiseTK)
============ Eigendecomposition =============
eigvals = 
(-0.809017,-0.587785)
(-0.809017,-0.587785)
 (-0.809017,0.587785)
 (-0.809017,0.587785)
eigvecs =
       (-0,0) (-0.707107,0)  (0.707107,0)         (0,0)
 (0.707107,0)        (-0,0)         (0,0) (-0.707107,0)
 (0.707107,0)        (-0,0)         (0,0)  (0.707107,0)
       (-0,0) (-0.707107,0) (-0.707107,0)         (0,0)
=============================================
TK1(0, 1, 0) q[0];
TK1(0, 3.5, 1) q[1];
TK1(0, 0, 1) q[0];
TK1(0, 0, 0.5) q[1];
TK2(0.2, 0, 0) q[0], q[1];
TK1(0.5, 3.5, 0.5) q[0];
TK1(0, 1.5, 0.5) q[1];
Phase (in half-turns): 1.5

============== (KAK Decomposition)

MacOS:

============ Eigendecomposition =============
eigvals = 
(0,-1)
(0,-1)
 (0,1)
 (0,1)
eigvecs =
 (0.707107,0)         (0,0)         (0,0)  (0.707107,0)
        (0,0) (-0.707107,0) (-0.707107,0)         (0,0)
(-0.707107,0)         (0,0)         (0,0)  (0.707107,0)
        (0,0)  (0.707107,0) (-0.707107,0)         (0,0)
=============================================
============ Eigendecomposition =============
eigvals = 
(0,-1)
(0,-1)
 (0,1)
 (0,1)
eigvecs =
 (0.707107,0)         (0,0)         (0,0)  (0.707107,0)
        (0,0) (-0.707107,0) (-0.707107,0)         (0,0)
(-0.707107,0)         (0,0)         (0,0)  (0.707107,0)
        (0,0)  (0.707107,0) (-0.707107,0)         (0,0)
=============================================
TK1(0, 1, 0) q[0];
TK1(0, 3.5, 1) q[1];
TK2(0.5, 0, 0) q[0], q[1];
TK1(0, 3.5, 0.2) q[1];
TK2(0.5, 0, 0) q[0], q[1];
TK1(0.5, 0.5, 0.5) q[0];
TK1(0, 0, 1) q[1];
Phase (in half-turns): 0.0

============== (SythesiseTK)
============ Eigendecomposition =============
eigvals = 
(-0.809017,-0.587785)
(-0.809017,-0.587785)
 (-0.809017,0.587785)
 (-0.809017,0.587785)
eigvecs =
       (-0,0) (-0.707107,0)  (0.707107,0)         (0,0)
(-0.707107,0)        (-0,0)         (0,0)  (0.707107,0)
(-0.707107,0)        (-0,0)         (0,0) (-0.707107,0)
       (-0,0) (-0.707107,0) (-0.707107,0)         (0,0)
=============================================
TK1(0, 1, 0) q[0];
TK1(0, 3.5, 1) q[1];
TK1(0, 0, 1.5) q[1];
TK2(0.2, 0, 0) q[0], q[1];
TK1(0.5, 3.5, 3.5) q[0];
TK1(0, 3.5, 3.5) q[1];
Phase (in half-turns): 1.5

============== (KAK Decomposition)

Copy link

This issue has been automatically marked as stale.

@github-actions github-actions bot added the stale label Jun 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant