testAntiperiodicBCs.py 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. from statefuncs import State, Basis
  2. from phi1234 import Phi1234
  3. from scipy.constants import pi
  4. import numpy as np
  5. from numpy.testing import assert_array_equal
  6. from qedstatefuncs import FermionBasis, FermionState
  7. from qedops import FermionOperator
  8. import unittest
  9. class TestHalfIntegerNmax(unittest.TestCase):
  10. def setUp(self):
  11. self.L = 2*pi
  12. self.nmax = 0.5
  13. self.m = 0.
  14. #initialize a FermionState with half-integer nmax=0.5
  15. self.state = FermionState([1,1],[1,1],self.nmax,self.L,self.m)
  16. self.operator = FermionOperator(clist=[],dlist=[],
  17. anticlist=[],antidlist=[0.5],
  18. L=self.L,m=self.m,normed=True)
  19. def testGetter(self):
  20. assert_array_equal(self.state[-0.5],[1,1])
  21. assert_array_equal(self.state[0.5],[1,1])
  22. def testOperator(self):
  23. #test that adding a particle to a filled state annihilates it
  24. for c1 in (-0.5,0.5):
  25. operator = FermionOperator([c1],[],[],[],self.L,self.m)
  26. self.assertEqual(operator._transformState(self.state),
  27. (0,None))
  28. for c2 in (-0.5,0.5):
  29. operator = FermionOperator([],[],[c2],[],self.L,self.m)
  30. self.assertEqual(operator._transformState(self.state),
  31. (0,None))
  32. op1 = FermionOperator([],[-0.5],[],[],self.L,self.m,normed=True)
  33. outState1 = FermionState([0,1],[1,1],self.nmax,self.L,self.m,
  34. checkAtRest=False,checkChargeNeutral=False)
  35. n, newState = op1._transformState(self.state, returnCoeff=True)
  36. self.assertEqual(n,1)
  37. self.assertEqual(newState, outState1)
  38. op2 = FermionOperator([],[0.5],[],[],self.L,self.m,normed=True)
  39. outState2 = FermionState([1,0],[1,1],self.nmax,self.L,self.m,
  40. checkAtRest=False,checkChargeNeutral=False)
  41. n, newState = op2._transformState(self.state, returnCoeff=True)
  42. self.assertEqual(n,-1)
  43. self.assertEqual(newState, outState2)
  44. op3 = FermionOperator([],[],[],[-0.5],self.L,self.m,normed=True)
  45. outState3 = FermionState([1,1],[0,1],self.nmax,self.L,self.m,
  46. checkAtRest=False,checkChargeNeutral=False)
  47. n, newState = op3._transformState(self.state, returnCoeff=True)
  48. self.assertEqual(n,1)
  49. self.assertEqual(newState, outState3)
  50. op4 = FermionOperator([],[],[],[0.5],self.L,self.m,normed=True)
  51. outState4 = FermionState([1,1],[1,0],self.nmax,self.L,self.m,
  52. checkAtRest=False,checkChargeNeutral=False)
  53. n, newState = op4._transformState(self.state, returnCoeff=True)
  54. self.assertEqual(n,-1)
  55. self.assertEqual(newState, outState4)