-2

我想修复这段代码。一切都很好,但是当我尝试运行此代码时,它显示为 TypeError: 'Result' object does not support indexing,我不知道为什么会出现这个问题。如果有人可以解决这个问题,这是最受欢迎的。答案将不胜感激。

import math
import pylab as pl
from qutip import *
%matplotlib inline
# system parameters
n = 3
m = 128
gamma = 1
kappa = 0.5
Y = 0.01
g = 1/np.sqrt(2.0)
omega_M = 1
kappa_M = 0.1
ntraj = 1
# initial state
psi0 = tensor(fock(2,1), fock(n,0), fock(m,0))
# operators
sig_plus = tensor(sigmap(), qeye(n), qeye(m))
a = tensor(qeye(2), destroy(n), qeye(m))
b = tensor(qeye(2), qeye(n), destroy(m))
# collapse operators
c_ops= [np.sqrt(2*kappa)*a, np.sqrt(gamma)*sig_plus.dag(), np.sqrt(kappa_M)*b]
# expectation values
e_ops = [a.dag()*a.dag()*a*a, a.dag()*a*sig_plus*sig_plus.dag(), a.dag()*a,
sig_plus*sig_plus.dag()]
# lists of steady-state values
fieldfield_list = []
atomfield_list = []
tlist = np.linspace(0,20,2000)
gM_list = np.linspace(0,3,200)
# build the correlation plots
for g_M in gM_list:
    H = omega_M*b.dag()*b + Y*(a + a.dag())+ g*((a*sig_plus) + (a.dag()*sig_plus.dag()))
    + g_M*a.dag()*a*(b + b.dag())
    evalues = mcsolve(H, psi0, tlist, c_ops=[], e_ops=[], ntraj=None, args={}, options=None, progress_bar=True, map_func=None, map_kwargs=None, _safe_mode=True)
    fieldfield_list.append(evalues[0][-1]/(evalues[2][-1]**2))
    atomfield_list.append(evalues[1][-1]/(evalues[2][-1]*evalues[3][-1]))
# plot the correlation functions
pl.plot(gM_list, fieldfield_list, 'r', gM_list, atomfield_list, 'b')
pl.xlabel('g_M')
pl.ylabel('intensity correlation values')
pl.legend(('field-field', 'atom-field'))
pl.show()

运行上述代码后,我收到此错误。

 TypeError                                 Traceback (most recent call last)
 <ipython-input-20-15b5e0ad0f36> in <module>()
 33   evalues =mcsolve(H, psi0, times_list, c_ops=[], e_ops=[], ntraj=None, 
 args={}, options=None, progress_bar=True, map_func=None, map_kwargs=None, _safe_mode=True)
 34 
 ---> 35   fieldfield_list.append(evalues[0][-1]/(evalues[2][-1]**2))
 36   atomfield_list.append(evalues[1][-1]/(evalues[2][-1]*evalues[3][-1]))
 37 # plot the correlation functions

 TypeError: 'Result' object does not support indexing
4

1 回答 1

0
evalues = mcsolve(H, psi0, times_list, ntraj, collapse, evalue_list) 

这是实际的语法。,

** mcsolve(H, psi0, tlist, c_ops=[], e_ops=[], ntraj=None, args={}, options=None, progress_bar=True, map_func=None, map_kwargs=None, _safe_mode=True)**

所以你已经将 ntraj 作为第四个参数传递了,但它实际上是第六个参数,

ntraj它只是一个整数,所以它抛出一个错误

所以根据函数参数传递mcsolve函数参数值

于 2020-03-01T12:17:21.757 回答