testSchwinger.py 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. # -*- coding: utf-8 -*-
  2. """
  3. Created on Mon Jun 22 20:51:40 2020
  4. @author: Ian Lim
  5. """
  6. from statefuncs import State, Basis
  7. from qedstatefuncs import FermionState, FermionBasis
  8. from phi1234 import Phi1234
  9. from schwinger import Schwinger
  10. from scipy.constants import pi
  11. import numpy as np
  12. import unittest
  13. import time
  14. from numpy.testing import assert_array_equal
  15. def calculateAxialCharge(state):
  16. total = 0
  17. for wn in np.arange(state.nmin, state.nmax+1):
  18. if wn < 0:
  19. total -= (state[wn][0]-state[wn][1])
  20. elif wn > 0:
  21. total += (state[wn][0]-state[wn][1])
  22. return total
  23. class TestSchwinger(unittest.TestCase):
  24. def setUp(self):
  25. self.schwinger = Schwinger()
  26. self.schwinger.buildFullBasis(Emax=3., m=0, L=2*pi)
  27. # this test was before we added zero modes. May want to rewrite with the
  28. # dressed states?
  29. # def testBasisElements(self):
  30. # #print(self.schwinger.fullBasis)
  31. # expectedOccs = [([0,0,0],[0,0,0]), ([0,1,0],[0,1,0]),
  32. # ([1,0,0],[0,0,1]),([1,1,0],[0,1,1]),
  33. # ([0,0,1],[1,0,0]),([0,1,1],[1,1,0])]
  34. # for i, state in enumerate(self.schwinger.fullBasis):
  35. # assert_array_equal(state.particleOccs,expectedOccs[i][0])
  36. # assert_array_equal(state.antiparticleOccs,expectedOccs[i][1])
  37. def testGenerateOperators(self):
  38. #print(self.schwinger.fullBasis)
  39. ops = self.schwinger.generateOperators()
  40. #print(ops)
  41. def testMatrix(self):
  42. verbose = False
  43. if verbose:
  44. print("Beginning Schwinger matrix test")
  45. start = time.time()
  46. #print(a.fullBasis)
  47. #self.assertEqual(len(a.fullBasis[1]),len(expected_basis))
  48. #for index, occs in enumerate(expected_basis):
  49. # self.assertEqual(a.fullBasis[1][index].occs, occs)
  50. #ops = a.generateOperators()
  51. """
  52. for key in ops.keys():
  53. for op in ops[key]:
  54. print(f"Coeff:{op.coeff}, ops:{op}")
  55. """
  56. #print([state.occs for state in a.fullBasis[-1]])
  57. self.schwinger.buildMatrix()
  58. print(f"Runtime: {time.time()-start}")
  59. if verbose:
  60. print("Free Hamiltonian:")
  61. print(self.schwinger.h0.M.toarray())
  62. # we could check that the diagonal elements are the expected energies
  63. #order zero is just the mass term, which comes out to 2*pi here.
  64. print("Order zero potential matrix:")
  65. print(self.schwinger.potential.M.toarray())
  66. # def testAxialCharge(self):
  67. # for n in range(6):
  68. # print(calculateAxialCharge(self.schwinger.fullBasis[n]))
  69. if __name__ == '__main__':
  70. unittest.main()