Skip to content

Commit

Permalink
test Pauli matrices
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenhky committed Sep 3, 2022
1 parent f265ef3 commit 76df4ad
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions test/test_lanzcos.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,33 @@ def test_four(self):
assert np.abs(np.linalg.norm(eigvec2[:, j]) - 1.) < tol
assert np.all(np.abs(A @ eigvec2[:, j] / eigval2[j] - eigvec2[:, j]) < tol)

def test_paulix(self):
tol = 1e-8
A = np.array(
[
[0., 1.],
[1., 0.]
]
)
eigval1, eigvec1 = np.linalg.eig(A)
eigval2, eigvec2 = lanzcos(A, A.shape[0])

assert len(eigval2) == A.shape[0] + 1

eig1dict = {}
for i in range(A.shape[0]):
for j in range(len(eigval2)):
if abs(eigval1[i] - eigval2[j]) < tol:
eig1dict[i] = j
break
assert len(set(eig1dict.values())) == len(eigval1)

for i in range(A.shape[0]):
j = eig1dict[i]
assert np.abs(np.linalg.norm(eigvec2[:, j]) - 1.) < tol
assert np.all(np.abs(A @ eigvec2[:, j] / eigval2[j] - eigvec2[:, j]) < tol)
assert abs(abs(eigvec2[0, j]) - np.sqrt(0.5)) < tol


if __name__ == '__main__':
unittest.main()

0 comments on commit 76df4ad

Please sign in to comment.