phi4_benchmark.py 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. ######################################################
  2. #
  3. #
  4. #
  5. ######################################################
  6. import phi1234
  7. import sys
  8. import scipy
  9. import time
  10. import matplotlib.pyplot as plt
  11. import numpy as np
  12. def main(argv):
  13. '''
  14. #if there are too few arguments, print the right syntax and exit
  15. if len(argv) < 3:
  16. print("python genMatrix.py <L> <Emax>")
  17. sys.exit(-1)
  18. '''
  19. print("Beginning execution.")
  20. startTime = time.time()
  21. L = 10.
  22. Emax = 15.
  23. #mass
  24. m = 1.
  25. a = phi1234.Phi1234()
  26. #build the full basis with both values of k (parity)
  27. a.buildFullBasis(k=1, Emax=Emax, L=L, m=m)
  28. a.buildFullBasis(k=-1, Emax=Emax, L=L, m=m)
  29. print("K=1 basis size :", a.fullBasis[1].size)
  30. print("K=-1 basis size :", a.fullBasis[-1].size)
  31. #set the file name for saving the generated matrix
  32. datestring = time.strftime("%Y_%m_%d", time.gmtime())
  33. fstr = "./phi4data/" + datestring + f"_Emax={a.fullBasis[1].Emax}_L={a.L}"
  34. print(fstr)
  35. try:
  36. a.loadMatrix(fstr+".npz")
  37. print("Matrix loaded from file.")
  38. except:
  39. print("No saved matrix found. Building matrix.")
  40. a.buildMatrix()
  41. a.saveMatrix(fstr)
  42. print(f"Building/loading matrix took: {time.time()-startTime}s")
  43. startTime = time.time()
  44. a.buildBasis(k=1, Emax=Emax)
  45. a.buildBasis(k=-1, Emax=Emax)
  46. numsamples = 11
  47. vacuumEnergiesRen = np.zeros(numsamples)
  48. vacuumEnergiesSubl = np.zeros(numsamples)
  49. gvalues = np.linspace(0,5,numsamples)
  50. for i, g in enumerate(gvalues):
  51. vacuumEnergiesRen[i], vacuumEnergiesSubl[i] = computeVacuumEnergy(a, g)
  52. print(f"Computing eigenvalues took: {time.time()-startTime}s")
  53. #fig, ax = plt.subplots()
  54. plt.plot(gvalues, vacuumEnergiesRen, "x-k", label="ren.")
  55. plt.plot(gvalues, vacuumEnergiesSubl, ".--k", label="subl.")
  56. plt.xlabel(r'$g$')
  57. plt.ylabel(r'$\mathcal{E}$')
  58. plt.title(r'$m=1, L=10, E_\mathrm{max}=15$')
  59. plt.legend()
  60. #print("gvalues are", gvalues)
  61. #print("vacuum energies are", vacuumEnergies)
  62. plt.show()
  63. def computeVacuumEnergy(phi4, g):
  64. """
  65. Parameters
  66. ----------
  67. phi4 : Phi1234
  68. A Phi1234 object initialized with a suitable basis and the matrices
  69. for the various terms in the Hamiltonian.
  70. g : float
  71. Value of the coupling g.
  72. Returns
  73. -------
  74. A float representing the vacuum energy for this set of parameters.
  75. """
  76. sigma = -30.
  77. neigs = 3
  78. phi4.setcouplings(g4=g)
  79. print(f"Computing raw eigenvalues for g4 = {g}")
  80. phi4.computeHamiltonian(k=1, ren=False)
  81. phi4.computeHamiltonian(k=-1, ren=False)
  82. phi4.computeEigval(k=1, sigma=sigma, n=neigs, ren=False)
  83. phi4.computeEigval(k=-1, sigma=sigma, n=neigs, ren=False)
  84. print("Raw vacuum energy: ", phi4.vacuumE(ren="raw"))
  85. #print("K=1 Raw spectrum: ", phi4.spectrum(k=1, ren="raw"))
  86. #print("K=-1 Raw spectrum: ", phi4.spectrum(k=-1, ren="raw"))
  87. phi4.renlocal(Er=phi4.vacuumE(ren="raw"))
  88. print("Computing renormalized eigenvalues for g0r,g2r,g4r = ", phi4.g0r,phi4.g2r,phi4.g4r)
  89. phi4.computeHamiltonian(k=1, ren=True)
  90. phi4.computeHamiltonian(k=-1, ren=True)
  91. phi4.computeEigval(k=1, sigma=sigma, n=neigs, ren=True, corr=True)
  92. phi4.computeEigval(k=-1, sigma=sigma, n=neigs, ren=True, corr=True)
  93. print("Renlocal vacuum energy: ", phi4.vacuumE(ren="renlocal"))
  94. #print("K=1 renlocal spectrum: ", phi4.spectrum(k=1, ren="renlocal"))
  95. #print("K=-1 renlocal spectrum: ", phi4.spectrum(k=-1, ren="renlocal"))
  96. print("Rensubl vacuum energy: ", phi4.vacuumE(ren="rensubl"))
  97. #print("K=1 rensubl spectrum: ", phi4.spectrum(k=1, ren="rensubl"))
  98. #print("K=-1 rensubl spectrum: ", phi4.spectrum(k=-1, ren="rensubl"))
  99. return phi4.vacuumE(ren="renlocal"), phi4.vacuumE(ren="rensubl")
  100. if __name__ == "__main__":
  101. main(sys.argv)