我对Python很陌生。安装软件包cosmoTransitions之后,我必须运行代码,并且有一些示例程序,并且我已经尝试过一个程序,并遇到了以下提到的错误,但无法理解错误的来源
import numpy as np
from cosmoTransitions import generic_potential
v2 = 246.**2
vq = 109.**2
vs = 65.75
class model1(generic_potential.generic_potential):
"""
A sample model which makes use of the *generic_potential* class.
This model doesn't have any physical significance. Instead, it is chosen
to highlight some of the features of the *generic_potential* class.
It consists of two scalar fields labeled *phi1* and *phi2*, plus a mixing
term and an extra boson whose mass depends on both fields.
It has low-temperature, mid-temperature, and high-temperature phases, all
of which are found from the *getPhases()* function.
"""
def init(self,m1=85.6051,m2=40.1313,m3=328.371,mu=25.,Y1=.1,Y2=.15,Y3=.15,Y4=0.15,n=30,k1=-8.24 ,k2=0.112962,k3=0.0241,k4=-34,k5=21.44,lam=0.122642,lam1=0.513109,lam2=0.79):
"""
m1 - tree-level mass of first singlet when mu = 0.
m2 - tree-level mass of second singlet when mu = 0.
mu - mass coefficient for the mixing term.
Y1 - Coupling of the extra boson to the two scalars individually
Y2 - Coupling to the two scalars together: m^2 = Y2*s1*s2
n - degrees of freedom of the boson that is coupling.
"""
# The init method is called by the generic_potential class, after it
# already does some of its own initialization in the default __init__()
# method. This is necessary for all subclasses to implement.
# This first line is absolutely essential in all subclasses.
# It specifies the number of field-dimensions in the theory.
self.Ndim = 3
# self.renormScaleSq is the renormalization scale used in the
# Coleman-Weinberg potential.
self.renormScaleSq = vq
# This next block sets all of the parameters that go into the potential
# and the masses. This will obviously need to be changed for different
# models.
self.l1 = lam
self.l2 = lam1
self.l11 = lam2
self.l3 = m1**2
self.l4 = m2**2
self.l10 = m3**2
self.l5 = k1
self.l6 = k2
self.l7 = k3
self.l8 = k4
self.l9 = k5
self.mu2 = mu**2
self.Y1, self.Y2, self.Y3, self.Y4 = Y1, Y2, Y3, Y4
self.n = n
def forbidPhaseCrit(self, X):
"""
forbidPhaseCrit is useful to set if there is, for example, a Z2 symmetry
in the theory and you don't want to double-count all of the phases. In
this case, we're throwing away all phases whose zeroth (since python
starts arrays at 0) field component of the vev goes below -5. Note that
we don't want to set this to just going below zero, since we are
interested in phases with vevs exactly at 0, and floating point numbers
will never be accurate enough to ensure that these aren't slightly
negative.
"""
return (np.array([X])[...,0] < -5.0).any()
def V0(self, X):
"""
This method defines the tree-level potential. It should generally be
subclassed. (You could also subclass Vtot() directly, and put in all of
quantum corrections yourself).
"""
# X is the input field array. It is helpful to ensure that it is a
# numpy array before splitting it into its components.
X = np.asanyarray(X)
# x and y are the two fields that make up the input. The array should
# always be defined such that the very last axis contains the different
# fields, hence the ellipses.
# (For example, X can be an array of N two dimensional points and have
# shape (N,2), but it should NOT be a series of two arrays of length N
# and have shape (2,N).)
phi1,phi2,phi3 = X[...,0], X[...,1], X[...,2]
r = .25*self.l1*(phi1)**4 + .25*self.l2*(phi2)**4 + .25*self.l11*(phi3)**4 + self.l5*(phi2)* (phi1)**2 + self.l6*(phi2**2)*(phi1**2) + self.l7*(phi3**2)*(phi1**2) + self.l9*(phi2)*(phi3**2) + self.l8*(phi2**3) + .5*self.l4*(phi2)**2 + .5*self.l10*(phi3)**2
r -= (.25*self.l3*(phi1)**2)
return r
def boson_massSq(self, X, T):
X = np.array(X)
phi1,phi2,phi3 = X[...,0], X[...,1], X[...,2]
# We need to define the field-dependnet boson masses. This is obviously
# model-dependent.
# Note that these can also include temperature-dependent corrections.
a = self.l1*6*phi1*phi1 + self.l6*2*phi2*phi2 + self.l7*2*phi3*phi3 +self.l5*2*phi2 - self.l1*v2 - self.l5*2*vs - self.l6*2*vs**2
b = self.l6*4*phi1*phi1 + self.l2*3*phi2*phi2 + self.l8*6*phi2 - self.l6*2*v2 - self.l5*v2/vs - self.l8*3*vs -self.l2*vs**2
d = self.l5*2*2**.5*phi1 + self.l6*4*2**.5*phi1*phi2
A = .5*(a+b)
B = np.sqrt(.25*(a-b)**2 + d**2)
mb = (self.Y1)*phi1*phi1+(self.Y1)*phi2*phi2+(self.Y1)*phi3*phi3 + (self.Y2)*phi1*phi2 #+ (self.Y3)*phi1*phi3 + (self.Y4)*phi2*phi3
M = np.array([A+B, A-B, mb])
# At this point, we have an array of boson masses, but each entry might
# be an array itself. This happens if the input X is an array of points.
# The generic_potential class requires that the output of this function
# have the different masses lie along the last axis, just like the
# different fields lie along the last axis of X, so we need to reorder
# the axes. The next line does this, and should probably be included in
# all subclasses.
M = np.rollaxis(M, 0, len(M.shape))
# The number of degrees of freedom for the masses. This should be a
# one-dimensional array with the same number of entries as there are
# masses.
dof = np.array([1, 1, self.n])
# c is a constant for each particle used in the Coleman-Weinberg
# potential using MS-bar renormalization. It equals 1.5 for all scalars
# and the longitudinal polarizations of the gauge bosons, and 0.5 for
# transverse gauge bosons.
c = np.array([1.5, 1.5, 1.5])
return M, dof, c
def approxZeroTMin(self):
# There are generically two minima at zero temperature in this model,
# and we want to include both of them.
v = v2**.5
return [np.array([v,v,v]), np.array([v,v,v])]
def makePlots(m=None):
import matplotlib.pyplot as plt
if m is None:
m = model1()
m.findAllTransitions()
# --
plt.figure()
m.plotPhasesPhi()
plt.axis([0,300,-50,550])
plt.title("Minima as a function of temperature")
plt.show()
# --
plt.figure(figsize=(8,3))
ax = plt.subplot(131)
T = 0
m.plot2d((-450,450,-450,450), T=T, cfrac=.4,clevs=65,n=100,lw=.5)
ax.set_aspect('equal')
ax.set_title("$T = %0.2f$" % T)
ax.set_xlabel(R"$\phi_1$")
ax.set_ylabel(R"$\phi_2$")
ax = plt.subplot(132)
T = m.TnTrans[1]['Tnuc']
instanton = m.TnTrans[1]['instanton']
phi = instanton.Phi
m.plot2d((-450,450,-450,450), T=T, cfrac=.4,clevs=65,n=100,lw=.5)
ax.plot(phi[:,0], phi[:,1], 'k')
ax.set_aspect('equal')
ax.set_title("$T = %0.2f$" % T)
ax.set_yticklabels([])
ax.set_xlabel(R"$\phi_1$")
ax = plt.subplot(133)
T = m.TnTrans[0]['Tnuc']
m.plot2d((-450,450,-450,450), T=T, cfrac=.4,clevs=65,n=100,lw=.5)
ax.set_aspect('equal')
ax.set_title("$T = %0.2f$" % T)
ax.set_yticklabels([])
ax.set_xlabel(R"$\phi_1$")
# --
plt.figure()
plt.plot(instanton.profile1D.R, instanton.profile1D.Phi)
plt.xlabel("radius")
plt.ylabel(R"$\phi-\phi_{min}$ (along the path)")
plt.title("Tunneling profile")
但是运行此命令后,它显示了太多错误,我也无法区分它们的来源。 这是错误信息:
Traceback (most recent call last):
File "C:/Users/SATYABRATA/AppData/Local/Programs/Python/Python38-32 /sdd.py", line 2, in <module>
from cosmoTransitions import generic_potential
File "C:\Users\SATYABRATA\AppData\Local\Programs\Python\Python38-32 \lib\site-packages\cosmoTransitions\generic_potential.py", line 20, in <module>
from .finiteT import Jb_spline as Jb
File "C:\Users\SATYABRATA\AppData\Local\Programs\Python\Python38-32\lib\site-packages\cosmoTransitions\finiteT.py", line 25, in <module>
from scipy.misc import factorial as fac
ImportError: cannot import name 'factorial' from 'scipy.misc' (C:\Users \SATYABRATA\AppData\Local\Programs\Python\Python38-32\lib\site-packages\scipy\misc\__init__.py)
答案 0 :(得分:0)
在最新版本的cosmoTransition软件包中,出现此问题的行from scipy.misc import factorial as fac
。您的scipy版本可能高于1.0.0。因为他们不赞成这样做。您应该尝试使用以下命令将scipy版本降级为1.0.0:python3 -m pip install scipy==1.0 --upgrade
。另外,据我了解的this post,您也可以尝试使用1.2
答案 1 :(得分:-1)
在python shell中尝试
from scipy.special import factorial
如果未收到ImportError,请在编辑器中打开finiteT.py
(发布错误消息的文件路径):
"C:\Users\SATYABRATA\AppData\Local\Programs\Python\Python38-32\lib\site-packages\cosmoTransitions\finiteT.py"
第25行更改
from scipy.misc import factorial as fac
到
from scipy.special import factorial as fac
或
try:
from scipy.misc import factorial as fac
except ImportError:
from scipy.special import factorial as fac
自2018年2月以来没有对该存储库进行任何提交-因此您最好更改副本。