-3

我正在尝试在 qutip 中运行此代码。但它没有显示任何结果。但是没有显示任何错误。所有代码都是正确的,没有显示任何错误。但不知道为什么程序没有执行。如果有人能解决这个问题,非常欢迎。

  from __future__ import division
  from qutip import *
  import pylab
  import math
  import matplotlib.pyplot as plt
  import numpy as np
  import csv
  #import plotly.plotly as py
  #from plotly.graph_objs import *
  #py.sign_in("cayayald", "zlae2s4d1i")
  #linewidth
  #gamma = 1 => fully independent
  #G = 1 => fully collective
  gamma = .25
  G = 1.0 - gamma
  #delta is detuning
  delta = -1
  deltastep = 0.1
  dlist = []
  #n is number of atoms
  n = 16
  #V is energy shiftdue to dipole-dipole
  V = 10
  #omega is rabi freq
  omega = 1.5
  omegastep = 0
  #lowering, raising, and state collapsing operators
  sigmamlist = []
  sigmaplist = []
  c_op_list =  []
  for j in range (n):
   if j==0:
   sigmajm=sigmam()
   else:
   sigmajm=qeye(2)
   for i in range (1,n):
   if j == i:
   sigmaj1= tensor(sigmam(),sigmajm)
   else:
   sigmajm = tensor(qeye(2),sigmajm)
   sigmamlist.append(sigmajm)


  coplist.append(math.sqrt(gamma)*sigmajm) #n-many indep collapse ops
  sigmajp = sigmajm.dag()
  sigmaplist.append(sigmajp)
  coplist.append(math.sqrt(G)*sum(sigmamlist)) #one collective collapse op
  #we want expectation values of operators in exoplist
  exoplist = []
  #numerator of cross correlation
  exoplist.append(sigmaplist[0]*sigmamlist[0]*sigmaplist[1]*sigmamlist[1])
  #denomenator of cross correlation
  exoplist.append(sigmaplist[0]*sigmamlist[0])
  exoplist.append(sigmaplist[1]*sigmamlist[1])

在此之后,下面的这些代码没有运行并且需要时间。不知道为什么?

   #initial state vector
  psi0 = basis(2,0)
  for i in range(1,n):
  psi0 = tensor(psi0,basis(2,0))
  #build Hamiltonian
  g2 = []
  list = np.linspace(0,200,2000)
  ntraj = 1
  while delta <= 7:
  glist = []
  hlist = []
  vlist = []
  for i in range(n):
        hlist.append(-delta*(sigmaplist[i]*sigmamlist[i])+ (omega / 2)*(sigmaplist[i] + 
        sigmamlist[i]))
  for i in range(n):
  for j in range(i):
        vlist.append((V / (n - 1))*((sigmaplist[j]*sigmamlist[j])
   *(sigmaplist[i]*sigmamlist[i])))
   H = sum(hlist) + sum(vlist)
   #monte carlo trajectory
   montecar = mcsolve(H, psi0, tlist, coplist, exoplist, ntraj)
   for i in range(len(montecar.expect[0])):
   numerator = montecar.expect[0][i]
  denomenator = montecar.expect[1][i]
  denom2 = montecar.expect[2][i]
  glist.append(numerator/(denomenator*denom2))
  g2.append(sum(glist)/len(glist))
  dlist.append(delta)
  delta = delta + deltastep
  x = np.arange(10)
  fig = plt.figure()
  ax = plt.subplot(111)
  ax.plot(dlist, g2)
  # Shink current axis by 20%
  box = ax.get_position()
  ax.set_position([box.x0, box.y0, box.width * 0.8, box.height])
  plt.grid(True)
  plt.show()   
4

1 回答 1

-1

你必须使用缩进,smt。像这样:

for j in range (n):
    if j==0:
        sigmajm=sigmam()
    else:
        sigmajm=qeye(2)

for i in range (1,n):
    if j == i:
        sigmaj1= tensor(sigmam(),sigmajm)
    else:
        sigmajm = tensor(qeye(2),sigmajm)
        sigmamlist.append(sigmajm)

更新: https ://www.tutorialspoint.com/python/python_basic_syntax.htm

于 2020-02-17T07:07:29.740 回答