tket icon indicating copy to clipboard operation
tket copied to clipboard

Work around numerical instability in `get_information_content()`

Open cqc-alec opened this issue 1 year ago • 2 comments

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 avatar Aug 23 '22 14:08 cqc-alec

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)

cqc-alec avatar Aug 30 '22 07:08 cqc-alec

This issue has been automatically marked as stale.

github-actions[bot] avatar Jun 30 '24 05:06 github-actions[bot]