tket
tket copied to clipboard
Work around numerical instability in `get_information_content()`
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.
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)
This issue has been automatically marked as stale.