applyTest.py 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. # -*- coding: utf-8 -*-
  2. """
  3. Created on Mon May 25 10:43:17 2020
  4. @author: aura1
  5. """
  6. import sys
  7. import numpy
  8. from statefuncs import Basis, NotInBasis, omega, State
  9. from oscillators import NormalOrderedOperator as NOO
  10. import time
  11. class npState(State):
  12. def __init__(self, occs, nmax, L=None, m=None, fast=False, checkAtRest=True):
  13. State.__init__(self, occs, nmax, L, m, fast, checkAtRest)
  14. self.occs = numpy.array(occs)
  15. if self.size == 2*self.nmax+1 and numpy.array_equal(self.occs[::-1],self.occs):
  16. self.__parityEigenstate = True
  17. else:
  18. self.__parityEigenstate = False
  19. def main(argv):
  20. print("Hello world")
  21. #arguments to NOO are clist, dlist, L, m, and extracoeff (optional)
  22. L = 1
  23. m = 1
  24. myOperator = NOO([],[1],L,m)
  25. print(myOperator)
  26. nmax = 1
  27. myState = npState([2,0,2],nmax,L,m)
  28. print(myState)
  29. print(myState[numpy.array([0,0,-1])])
  30. occs = numpy.array([1,0,5])
  31. dlist = numpy.array([-1,1,1,1,1])
  32. uniqueCounts = numpy.unique(dlist,return_counts=True)
  33. dlist2 = numpy.vstack((uniqueCounts[0],uniqueCounts[1])).transpose()
  34. print(dlist2)
  35. start = time.time()
  36. for n in range(50000):
  37. npTest(occs,dlist2)
  38. print(time.time()-start)
  39. start = time.time()
  40. for n in range(50000):
  41. oldTest(occs,dlist)
  42. print(time.time()-start)
  43. def npTest(myOccs,mydlist):
  44. #occs = myOccs
  45. #dlist = mydlist#numpy.array([[-1,1],[1,2]])
  46. nmax=1
  47. '''
  48. print("occs is ", occs)
  49. print("dlist is", dlist)
  50. print("dlist[:,0] is",dlist[:,0])
  51. print("occs[dlist[:,0]+nmax] is",occs[dlist[:,0]+nmax])
  52. print("dlist[:,1] is",dlist[:,1])
  53. print("occs[dlist[:,0]+nmax]-dlist[:,1] is",occs[dlist[:,0]+nmax]-dlist[:,1])
  54. '''
  55. myOccs[mydlist[:,0]+nmax] -= mydlist[:,1]
  56. #print("new version of occs is",occs)
  57. def oldTest(myOccs,mydlist):
  58. #print("Called oldTest")
  59. occs = [1,0,5]#myOccs
  60. dlist = [-1,1,1,1,1]# mydlist#[-1,1,1]
  61. nmax=1
  62. n = 1.
  63. #for each of the destruction operators
  64. for i in dlist:
  65. #if there is no Fourier mode at that value of n (ground state)
  66. if occs[i+nmax] == 0:
  67. #then the state is annihilated
  68. return None
  69. #otherwise we multiply n by the occupation number of that state
  70. n *= occs[i+nmax]
  71. #and decrease its occupation number by 1
  72. occs[i+nmax] -= 1
  73. #print("old way says",occs)
  74. #return occs
  75. if __name__ == "__main__":
  76. main(sys.argv)