Skip to content

Commit 224d9b4

Browse files
committed
Fix bug in ThreeQubitSchmidtDecomposition function
1 parent a548d6f commit 224d9b4

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

UniversalQCompiler.m

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3242,15 +3242,18 @@ gate is returned (however ReturnDiagonal is set to True), the diagonal gate is e
32423242
T1 = ArrayReshape[u[[T1Indices]],{2,2}];
32433243
T2 = ArrayReshape[u[[T2Indices]],{2,2}];
32443244

3245-
eVals = Eigenvalues[{T2,T1}];
3245+
eVals = Eigenvalues[{T1,T2}];
32463246

3247-
lambda = If[Chop[N[eVals[[1]]]] != 0, eVals[[1]], If[Chop[N[eVals[[2]]]] != 0, eVals[[2]], Throw["In threeQubitSchmidtDecomposition, neither generalised eigenValue is non-zero"]]];
3247+
U = Switch[Chop[Abs[N[eVals[[1]]]]],
3248+
Infinity,
3249+
{{0., 1.}, {1.,0.}},
3250+
0,
3251+
{{1., 0.}, {0.,1.}},
3252+
_,
3253+
{{1/Sqrt[1+Abs[eVals[[1]]]^2], -eVals[[1]]/Sqrt[1+Abs[eVals[[1]]]^2]}, {-Conjugate[eVals[[1]]]/Sqrt[1+Abs[eVals[[1]]]^2], -1/Sqrt[1+Abs[eVals[[1]]]^2]}}
3254+
];
32483255

3249-
If[N[eVals[[1]]]!=\[Infinity],u11 = Abs[eVals[[1]]]Sqrt[1/(1+Abs[eVals[[1]]]^2)];
3250-
u12 = -(u11/eVals[[1]]),u11 = Limit[Abs[x]Sqrt[1/(1+Abs[x]^2)],x->\[Infinity]];
3251-
u12 = Limit[-(u11/x),x->\[Infinity]]];If[Chop[N[u12]]!=0,
3252-
U = {{u11, u12}, {(1-u11^2)/u12,-u11}},U = {{u11, u12}, {Limit[(1-u11^2)/x,x->0],-u11}}];
3253-
T1Prime = U[[1,1]]T1 + U[[1,2]] T2;
3256+
T1Prime = U[[1,1]] T1 + U[[1,2]] T2;
32543257
{a1,s1,b1} = SingularValueDecomposition[T1Prime];
32553258
T2Prime = U[[2,1]] T1 + U[[2,2]] T2;
32563259
{a2,s2,b2} = SingularValueDecomposition[T2Prime];

0 commit comments

Comments
 (0)