testBasis.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. # -*- coding: utf-8 -*-
  2. """
  3. Created on Thu Jun 18 17:39:07 2020
  4. @author: Ian Lim
  5. """
  6. from statefuncs import State, Basis
  7. from phi1234 import Phi1234
  8. from scipy.constants import pi
  9. import numpy as np
  10. import unittest
  11. class TestBasis(unittest.TestCase):
  12. def setUp(self):
  13. self.Emax = 10.
  14. self.basis = Basis(L=2*pi, Emax=self.Emax, m=4., K=1)
  15. def test_nmax(self):
  16. # nmax is computed as
  17. # nmax = int(math.floor(sqrt((Emax/2.)**2.-m**2.)*self.L/(2.*pi)))
  18. # with the values above, nmax = 3
  19. self.assertEqual(self.basis.nmax,3)
  20. def test_basis_elements(self):
  21. expected_basis = [[0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 2, 0, 0, 0],
  22. [0, 0, 1, 0, 1, 0, 0], [0, 1, 0, 0, 0, 1, 0],
  23. [1, 0, 0, 0, 0, 0, 1]]
  24. # note there is no [0, 0, 0, 1, 0, 0, 0] state because such a state
  25. # has k-parity -1
  26. self.assertEqual(len(self.basis),len(expected_basis))
  27. for index, occs in enumerate(expected_basis):
  28. self.assertEqual(self.basis[index].occs, occs)
  29. def test_basis_sorted(self):
  30. laststate = None
  31. for state in self.basis:
  32. self.assertLessEqual(state.energy, self.Emax)
  33. if laststate:
  34. self.assertLessEqual(laststate.energy, state.energy)
  35. laststate = state
  36. '''
  37. #test the length of a large basis whose length is known
  38. class TestLargeBasis(unittest.TestCase):
  39. def setUp(self):
  40. self.Emax = 20.
  41. self.basisk1 = Basis(L=10, Emax=20, m=1., K=1)
  42. self.basisk2 = Basis(L=10, Emax=20, m=1., K=-1)
  43. def test_length(self):
  44. self.assertEqual(len(self.basisk1), 12870)
  45. self.assertEqual(len(self.basisk2), 12801)
  46. # n.b. these numbers come from footnote 14 in
  47. # https://arxiv.org/pdf/1412.3460.pdf
  48. '''
  49. if __name__ == '__main__':
  50. unittest.main()