[Tutor] I don’t know how to generate a number of data points from this part of code
SATYABRATA DATTA
iamsatyabrata428 at gmail.com
Thu Feb 27 00:09:27 EST 2020
I have a package and this part is written to calculate the quantity called
‘action’ at a output temperature T. But now I need a set of ‘action’ at
slightly different temperatures say T+1e-3,T+3*1e-3,T+4*1e-3… Etc.Since I
am a beginner at python I can’t figure out where in. This definition I have
to put a loop to print different values of action at slightly different
temperatures. The part of code is attached as below
def _tunnelFromPhaseAtT(T, phases, start_phase, V, dV,
phitol, overlapAngle, nuclCriterion,
fullTunneling_params, verbose, outdict):"""
Find the lowest action tunneling solution.
Return ``nuclCriterion(S,T)``, and store a dictionary describing the
transition in outdict for key `T`.
"""try:
T = T[0] # need this when the function is run from optimize.fminexcept:
passif T in outdict:
return nuclCriterion(outdict[T]['action'], T)
def fmin(x):
return optimize.fmin(V, x, args=(T,),
xtol=phitol, ftol=np.inf, disp=False)
# Loop through all the phases, adding acceptable minima
x0 = fmin(start_phase.valAt(T))
V0 = V(x0, T)
tunnel_list = []for key in phases.keys():
if key == start_phase.key:
continue
p = phases[key]
if (p.T[0] > T or p.T[-1] < T):
continue
x1 = fmin(p.valAt(T))
V1 = V(x1, T)
if V1 >= V0:
continue
tdict = dict(low_vev=x1, high_vev=x0, Tnuc=T,
low_phase=key, high_phase=start_phase.key)
tunnel_list.append(tdict)# Check for overlapif overlapAngle > 0:
excluded = []
cos_overlap = np.cos(overlapAngle * np.pi/180)
for i in xrange(1, len(tunnel_list)):
for j in xrange(i):
xi = tunnel_list[i]['low_vev']
xj = tunnel_list[j]['low_vev']
xi2 = np.sum((xi-x0)**2)
xj2 = np.sum((xj-x0)**2)
dotij = np.sum((xj-x0)*(xi-x0))
if dotij >= np.sqrt(xi2*xj2) * cos_overlap:
excluded.append(i if xi2 > xj2 else j)
for i in sorted(excluded)[::-1]:
del tunnel_list[i]# Get rid of the T parameter for V and dVdef
V_(x,T=T,V=V): return V(x,T)def dV_(x,T=T,dV=dV): return dV(x,T)# For
each item in tunnel_list, try tunneling
lowest_action = np.inf
lowest_tdict = dict(action=np.inf)for tdict in tunnel_list:
x1 = tdict['low_vev']
try:
print("Tunneling from phase %s to phase %s at T=%0.4g"
% (tdict['high_phase'], tdict['low_phase'], T))
print("high_vev =", tdict['high_vev'])
print("low_vev =", tdict['low_vev'])
tobj = pathDeformation.fullTunneling(
[x1,x0], V_, dV_, callback_data=T,
**fullTunneling_params)
tdict['instanton'] = tobj
tdict['action'] = tobj.action
tdict['trantype'] = 1
except tunneling1D.PotentialError as err:
if err.args[1] == "no barrier":
tdict['trantype'] = 0
tdict['action'] = 0.0
elif err.args[1] == "stable, not metastable":
tdict['trantype'] = 0
tdict['action'] = np.inf
else:
print("Unexpected error message.")
raise
if tdict['action'] <= lowest_action:
lowest_action = tdict['action']
lowest_tdict = tdict
outdict[T] = lowest_tdictreturn nuclCriterion(lowest_action, T)
More information about the Tutor
mailing list