Skip to content

Commit

Permalink
Allow for 2pi phase multiples in oper_equiv tests
Browse files Browse the repository at this point in the history
  • Loading branch information
thangleiter committed Mar 1, 2021
1 parent 067309e commit 42dbb98
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions tests/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -453,28 +453,31 @@ def test_oper_equiv(self):

result = util.oper_equiv(psi, psi*np.exp(1j*phase))
self.assertTrue(result[0])
self.assertAlmostEqual(result[1], phase, places=5)
self.assertAlmostEqual(np.mod(result[1], 2*np.pi), np.mod(phase, 2*np.pi), places=5)

result = util.oper_equiv(psi*np.exp(1j*phase), psi)
self.assertTrue(result[0])
self.assertAlmostEqual(result[1], -phase, places=5)
self.assertAlmostEqual(np.mod(result[1], 2*np.pi), np.mod(-phase, 2*np.pi), places=5)

psi /= np.linalg.norm(psi, ord=2)

result = util.oper_equiv(psi, psi*np.exp(1j*phase), normalized=True, eps=1e-13)
self.assertTrue(result[0])
self.assertArrayAlmostEqual(result[1], phase, atol=1e-5)
self.assertArrayAlmostEqual(np.mod(result[1], 2*np.pi), np.mod(phase, 2*np.pi),
atol=1e-5)

result = util.oper_equiv(psi, psi+1)
self.assertFalse(result[0])

result = util.oper_equiv(U, U*np.exp(1j*phase))
self.assertTrue(np.all(result[0]))
self.assertArrayAlmostEqual(result[1], phase, atol=1e-5)
self.assertArrayAlmostEqual(np.mod(result[1], 2*np.pi), np.mod(phase, 2*np.pi),
atol=1e-5)

result = util.oper_equiv(U*np.exp(1j*phase), U)
self.assertTrue(np.all(result[0]))
self.assertArrayAlmostEqual(result[1], -phase, atol=1e-5)
self.assertArrayAlmostEqual(np.mod(result[1], 2*np.pi), np.mod(-phase, 2*np.pi),
atol=1e-5)

norm = np.sqrt(util.dot_HS(U, U))
norm = norm[:, None, None] if U.ndim == 3 else norm
Expand All @@ -483,7 +486,7 @@ def test_oper_equiv(self):
# U /= np.expand_dims(np.sqrt(util.dot_HS(U, U)), axis=(-1, -2))
result = util.oper_equiv(U, U*np.exp(1j*phase), normalized=True, eps=1e-10)
self.assertTrue(np.all(result[0]))
self.assertArrayAlmostEqual(result[1], phase)
self.assertArrayAlmostEqual(np.mod(result[1], 2*np.pi), np.mod(phase, 2*np.pi))

result = util.oper_equiv(U, U+1)
self.assertFalse(np.all(result[0]))
Expand All @@ -496,7 +499,7 @@ def test_dot_HS(self):

for d in rng.integers(2, 10, (5,)):
U, V = testutil.rand_herm(d, 2)
self.assertArrayAlmostEqual(util.dot_HS(U, V), (U.conj().T @ V).trace())
self.assertArrayAlmostEqual(util.dot_HS(U, V), (U.conj().T @ V).trace())

U = testutil.rand_unit(d).squeeze()
self.assertEqual(util.dot_HS(U, U), d)
Expand Down

0 comments on commit 42dbb98

Please sign in to comment.