Skip to content

Commit 70338e5

Browse files
committed
Added some more comments and changed the Y gate implementation for the clifford simulator, to make more clear what's happening there
1 parent 47074ca commit 70338e5

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

QCSim/Clifford.h

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@ namespace QC {
490490
// looking at it might not reveal immediately what it does
491491
// the swaps below just switch the X with Z, because HZH^t = X and HXH^t = Z
492492

493-
// if we have both X and Z, then it's an Y (with some global phase, given by the sign, Y = iXZ)
493+
// if we have both X and Z, then it's a Y (with some global phase, given by the sign, Y = iXZ)
494494
// a Y is transformed to a -Y, so a sign change is needed
495495

496496
if (destabilizerGenerators[q].X[qubit] && destabilizerGenerators[q].Z[qubit])
@@ -525,6 +525,7 @@ namespace QC {
525525

526526
inline void ApplyX(size_t qubit, size_t q)
527527
{
528+
// X does nothing to X, but flips the sign for Z, as XZX^t = -Z
528529
if (destabilizerGenerators[q].Z[qubit])
529530
destabilizerGenerators[q].PhaseSign = !destabilizerGenerators[q].PhaseSign;
530531

@@ -534,13 +535,20 @@ namespace QC {
534535

535536
inline void ApplyY(size_t qubit, size_t q)
536537
{
538+
// Y flips the sign for both X and Z, as YZY^t = -Z and YXY^t = -X
539+
// if both X and Z are present, the sign is flipped twice, so it remains unchanged
540+
537541
// can be done with ifs, can be done with XORs
538-
destabilizerGenerators[q].PhaseSign = XOR(destabilizerGenerators[q].PhaseSign, XOR(destabilizerGenerators[q].Z[qubit], destabilizerGenerators[q].X[qubit]));
539-
stabilizerGenerators[q].PhaseSign = XOR(stabilizerGenerators[q].PhaseSign, XOR(stabilizerGenerators[q].Z[qubit], stabilizerGenerators[q].X[qubit]));
542+
if (XOR(destabilizerGenerators[q].Z[qubit], destabilizerGenerators[q].X[qubit]))
543+
destabilizerGenerators[q].PhaseSign = !destabilizerGenerators[q].PhaseSign;
544+
545+
if (XOR(stabilizerGenerators[q].Z[qubit], stabilizerGenerators[q].X[qubit]))
546+
stabilizerGenerators[q].PhaseSign = !stabilizerGenerators[q].PhaseSign;
540547
}
541548

542549
inline void ApplyZ(size_t qubit, size_t q)
543550
{
551+
// very similar with applying X, but now Z does nothing to Z, and flips the sign for X, as Z^tXZ = -X
544552
if (destabilizerGenerators[q].X[qubit])
545553
destabilizerGenerators[q].PhaseSign = !destabilizerGenerators[q].PhaseSign;
546554

0 commit comments

Comments
 (0)