Skip to content

Commit 7d0141c

Browse files
committed
Added further documentation for change_of_basis
1 parent d53805b commit 7d0141c

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

src/qrisp/operators/qubit/qubit_operator.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -984,7 +984,8 @@ def change_of_basis(qarg):
984984
# H X H = Z
985985
# H Y H = -Y
986986
# H Z H = X
987-
# For the original Pauli terms this translates to: Factor (-1) appears if S gate is applied to Y, or Hadamard gate H is applied to Y. (No factor (-1) occurs if S*H is applied.)
987+
# For the original Pauli terms this translates to: Factor (-1) appears if S gate is applied to Y, or Hadamard gate H is applied to Y
988+
# No factor (-1) occurs if H S^{-1} P S H is applied (i.e., H and S) for any P in {X,Y,Z}
988989

989990
s_vector = np.zeros(m, dtype=int)
990991
s_vector[s_list] = 1
@@ -998,16 +999,25 @@ def change_of_basis(qarg):
998999

9991000
for index,z_vector in enumerate(R_inv.T):
10001001

1001-
# Count the number of rows of the square submatrix A defined by z_vector (rows/columns), such that the number of 1's in each row is odd
1002+
# Determine the sign of the product of the selected graph state stabilizers:
1003+
#
1004+
# Consider product of stabilizers S_{i_1}*S_{i_2}*...*S_{i_m} with (w.l.o.g.) i_1<i_2<...<i_m
1005+
# For each i: Swap X_i with all Z_i's from stabilizers if index > i such that all Z_i's are on the left of X_i
1006+
# Calculate the paritiy n1 of the sum of the numbers of 1's with position j>i for each row of the square submatrix A defined by z_vector
1007+
# Yields a factor (-1)^n1
1008+
1009+
n1 = sum((z_vector @ A_low)*z_vector) % 2
1010+
1011+
# For each i: Count the number of Z_i's: if even, no factor, if odd: factor i (ZX=iY)
1012+
# Count the number n2 of rows of the square submatrix of A defined by z_vector, such that the number of 1's in each row is odd
10021013
# This number is always even since A is a symmetric matrix with 0's on the diagonal
1003-
n1 = sum((z_vector @ A)*z_vector % 2)
1014+
# Yields a factor i^n2=(-1)^(n2/2)
10041015

1005-
# Calculate the paritiy of the sum of the numbers of 1's with position j>i for each row of the square submatrix A defined by z_vector (rows/columns)
1006-
n2 = sum((z_vector @ A_low)*z_vector) % 2
1016+
n2 = sum((z_vector @ A)*z_vector % 2)
10071017

10081018
new_factor_dict = {qb_indices[perm[i]]:"Z" for i in range(m) if z_vector[i]==1}
10091019
new_factor_dicts.append(new_factor_dict)
1010-
prefactor = (-1)**sign_vector[index]*(-1)**(n1/2+n2)
1020+
prefactor = (-1)**sign_vector[index]*(-1)**(n1+n2/2)
10111021
prefactors.append(prefactor)
10121022

10131023
# Ladder operators

0 commit comments

Comments
 (0)