Skip to content

Commit a548d6f

Browse files
committed
Fixed option Simp for qubit decompositions
1 parent 8aed802 commit a548d6f

File tree

1 file changed

+33
-24
lines changed

1 file changed

+33
-24
lines changed

UniversalQCompiler.m

Lines changed: 33 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,6 @@
2525
6. Implementation of multi-controlled-Toffoli gates using ancillas to lower the C-NOT count.
2626
7. [Raban] Extend Stateprepration scheme for small Schmidt rank
2727
*)
28-
(*ToFix:
29-
1. XYXDec can return a ZYZ output, e.g. for
30-
{{0.7065332001434155` + 0.01331469739672239` I,
31-
0.4888081996161278` -
32-
0.5115663201544624` I}, {0.5440477104845266` -
33-
0.45237776762887333` I, -0.03542548508468498` +
34-
0.7057701318971897` I}}
35-
This seems to be due to the Simp->True default option; running with Simp->False gives the expected behaviour.
36-
*)
3728

3829
(*Methods to handle and simplify gate sequence*)
3930
(*CreateIsometryFromList::usage="CreateIsometryFromList[st,(n)] creates the operator corresponding to the list (optionally, the total number of qubits n can be determined)."
@@ -1325,9 +1316,12 @@
13251316
Null,actionQ=1,
13261317
_,actionQ=action
13271318
];
1328-
st={{zType,angles[[3]],actionQ},{yType,angles[[2]],actionQ},{zType,angles[[1]],actionQ}};
1319+
st={Rz[angles[[3]],actionQ],Ry[angles[[2]],actionQ],Rz[angles[[1]],actionQ]};
13291320
If[OptionValue[Simp],
1330-
st=SimplifyGateListReverseGateOrder[st]
1321+
If[Chop[st[[2]][[2]]]==0,
1322+
st={Rz[angles[[3]]+angles[[1]],actionQ]};
1323+
];
1324+
st=DeleteCases[st,x_/;Chop[x[[2]]]==0];
13311325
];
13321326
Reverse[st]
13331327
)
@@ -1344,7 +1338,10 @@
13441338
];
13451339
st={{xType,angles[[3]],actionQ},{yType,angles[[2]],actionQ},{xType,angles[[1]],actionQ}};
13461340
If[OptionValue[Simp],
1347-
st=SimplifyGateListReverseGateOrder[st]
1341+
If[Chop[st[[2]][[2]]]==0,
1342+
st={Rx[angles[[3]]+angles[[1]],actionQ]};
1343+
];
1344+
st=DeleteCases[st,x_/;Chop[x[[2]]]==0];
13481345
];
13491346
Reverse[st]
13501347
)
@@ -1359,9 +1356,12 @@
13591356
_,actionQ=action
13601357
];
13611358
st={{zType,angles[[3]],actionQ},{xType,angles[[2]],actionQ},{zType,angles[[1]],actionQ}};
1362-
(*If[OptionValue[Simp],
1363-
st=SimplifyGateListReverseGateOrder[st]
1364-
];*)(*This simplification makes the decomposition to become a ZYZ instead...*)
1359+
If[OptionValue[Simp],
1360+
If[Chop[st[[2]][[2]]]==0,
1361+
st={Rz[angles[[3]]+angles[[1]],actionQ]};
1362+
];
1363+
st=DeleteCases[st,x_/;Chop[x[[2]]]==0];
1364+
];
13651365
Reverse[st]
13661366
)]
13671367

@@ -1374,9 +1374,12 @@
13741374
_,actionQ=action
13751375
];
13761376
st={{xType,angles[[3]],actionQ},{zType,angles[[2]],actionQ},{xType,angles[[1]],actionQ}};
1377-
(*If[OptionValue[Simp],
1378-
st=SimplifyGateListReverseGateOrder[st]
1379-
];*)(*This simplification makes the decomposition to become a ZYZ instead...*)
1377+
If[OptionValue[Simp],
1378+
If[Chop[st[[2]][[2]]]==0,
1379+
st={Rx[angles[[3]]+angles[[1]],actionQ]};
1380+
];
1381+
st=DeleteCases[st,x_/;Chop[x[[2]]]==0];
1382+
];
13801383
Reverse[st]
13811384
)]
13821385

@@ -1389,9 +1392,12 @@
13891392
_,actionQ=action
13901393
];
13911394
st={{yType,angles[[3]],actionQ},{xType,angles[[2]],actionQ},{yType,angles[[1]],actionQ}};
1392-
(*If[OptionValue[Simp],
1393-
st=SimplifyGateListReverseGateOrder[st]
1394-
];*)(*This simplification makes the decomposition to become a ZYZ instead...*)
1395+
If[OptionValue[Simp],
1396+
If[Chop[st[[2]][[2]]]==0,
1397+
st={Ry[angles[[3]]+angles[[1]],actionQ]};
1398+
];
1399+
st=DeleteCases[st,x_/;Chop[x[[2]]]==0];
1400+
];
13951401
Reverse[st]
13961402
)]
13971403

@@ -1404,9 +1410,12 @@
14041410
_,actionQ=action
14051411
];
14061412
st={{yType,angles[[3]],actionQ},{zType,angles[[2]],actionQ},{yType,angles[[1]],actionQ}};
1407-
(*If[OptionValue[Simp],
1408-
st=SimplifyGateListReverseGateOrder[st]
1409-
];*)(*This simplification makes the decomposition to become a ZYZ instead...*)
1413+
If[OptionValue[Simp],
1414+
If[Chop[st[[2]][[2]]]==0,
1415+
st={Ry[angles[[3]]+angles[[1]],actionQ]};
1416+
];
1417+
st=DeleteCases[st,x_/;Chop[x[[2]]]==0];
1418+
];
14101419
Reverse[st]
14111420
)]
14121421

0 commit comments

Comments
 (0)