2

I have been coding to calculate the following equation:

equation

Where rho(t) is calculated by solving a quantum mechanics equation. <3| is a row vector with 1 at the 3rd element. |3> is a column vector with 1 at the 3rd element.

To solve the quantum mechanics equation (for the physics experts, I am solving the Lindblad Equation), I am using the qutip module.

The problem is, whenever I do the integration (using the scipy.integrate.quad function), I get a number like -0.842371561579 which is not what I expected (I am hoping for a number like 0.99). Also, I get a warning:

/usr/local/lib/python2.7/dist-packages/scipy/integrate/quadpack.py:352: IntegrationWarning: The integral is probably divergent, or slowly convergent.
  warnings.warn(msg, IntegrationWarning) 

I tried playing around with the values of the constants in the gamma constant. However, it didn't change any of the output. I have noticed it has to do with calculating rho(t), but that's all I could discover.

What is wrong with the code?

from qutip import *
import numpy as np
import scipy
from scipy.constants import *

hamiltonian = np.array([[215, -104.1, 5.1, -4.3  ,4.7,-15.1 ,-7.8 ],
[-104.1,  220.0, 32.6 ,7.1, 5.4, 8.3, 0.8],
      [ 5.1, 32.6, 0.0, -46.8, 1.0 , -8.1, 5.1],
     [-4.3, 7.1, -46.8, 125.0, -70.7, -14.7, -61.5],
       [ 4.7, 5.4, 1.0, -70.7, 450.0, 89.7, -2.5],
    [-15.1, 8.3, -8.1, -14.7, 89.7, 330.0, 32.7],
     [-7.8, 0.8, 5.1, -61.5,  -2.5, 32.7,  280.0]])
H=Qobj(hamiltonian) #This just converts hamiltonian into the qutip format

ground=H.groundstate()[1]

rho0 = ground*ground.dag()
gamma=(2*pi)*(296*0.695)*(35/150)
print gamma

#collapse operators:
L1 = Qobj(np.array([[1,0,0,0,0,0,0],[0,0,0,0,0,0,0],[0,0,0,0,0,0,0],[0,0,0,0,0,0,0],[0,0,0,0,0,0,0],[0,0,0,0,0,0,0],[0,0,0,0,0,0,0]]))
L2 = Qobj(np.array([[0,0,0,0,0,0,0],[0,1,0,0,0,0,0],[0,0,0,0,0,0,0],[0,0,0,0,0,0,0],[0,0,0,0,0,0,0],[0,0,0,0,0,0,0],[0,0,0,0,0,0,0]]))
L3 = Qobj(np.array([[0,0,0,0,0,0,0],[0,0,0,0,0,0,0],[0,0,1,0,0,0,0],[0,0,0,0,0,0,0],[0,0,0,0,0,0,0],[0,0,0,0,0,0,0],[0,0,0,0,0,0,0]]))
L4 = Qobj(np.array([[0,0,0,0,0,0,0],[0,0,0,0,0,0,0],[0,0,0,0,0,0,0],[0,0,0,1,0,0,0],[0,0,0,0,0,0,0],[0,0,0,0,0,0,0],[0,0,0,0,0,0,0]]))
L5 = Qobj(np.array([[0,0,0,0,0,0,0],[0,0,0,0,0,0,0],[0,0,0,0,0,0,0],[0,0,0,0,0,0,0],[0,0,0,0,1,0,0],[0,0,0,0,0,0,0],[0,0,0,0,0,0,0]]))
L6 = Qobj(np.array([[0,0,0,0,0,0,0],[0,0,0,0,0,0,0],[0,0,0,0,0,0,0],[0,0,0,0,0,0,0],[0,0,0,0,0,0,0],[0,0,0,0,0,1,0],[0,0,0,0,0,0,0]]))
L7 = Qobj(np.array([[0,0,0,0,0,0,0],[0,0,0,0,0,0,0],[0,0,0,0,0,0,0],[0,0,0,0,0,0,0],[0,0,0,0,0,0,0],[0,0,0,0,0,0,0],[0,0,0,0,0,0,1]]))
#Since our gamma variable cannot be directly applied onto the Lindblad operator, we must multiply it with the collapse operators:

L1=gamma*L1
L2=gamma*L2
L3=gamma*L3
L4=gamma*L4
L5=gamma*L5
L6=gamma*L6
L7=gamma*L7

options = Options(nsteps=10000000, atol=1e-20)

#This code is for function-based integration
def integratefunc(x):
    results = mesolve(H, rho0, [x], [L1,L2,L3,L4,L5,L6,L7],[], options=options) #this function find rho(t) and evaluates it at t=x
    bra3= [[0,0,1,0,0,0,0]] #<3|
    bra3q=Qobj(bra3) #convert to qutip format
    ket3= [[0],[0],[1],[0],[0],[0],[0]] #|3>
    ket3q=Qobj(ket3) #convert to qutip format
    tempq=bra3q*(results.states[0]*ket3q) #multiply <3|rho(x)|3>
    y=tempq.data.data[0].real #gets the real part of the number, since the imaginary part is zero
    return y #returns the value

efficiency, error = scipy.integrate.quad(integratefunc, 0, np.inf) #does the integration to calculate the efficiency and the error
print efficiency, error #prints the final results
hpaulj
  • 221,503
  • 14
  • 230
  • 353
TanMath
  • 598
  • 1
  • 9
  • 27
  • 1
    Have you studied numerical methods and their errors? I assume that your inputs are hitting a weak spot in `scipy.integrate.quad`. At the very least, use the parameter `full_output=1` and then run `scipy.integrate.quad_explain` to figure out what the method wants to tell you. (All this from the `scipy.integrate.quad` docstring.) – cphlewis Aug 10 '15 at 19:15
  • @cphlewis how does `scipy.integrate.quad_explain` work? in particular, what arguments does it take? – TanMath Aug 10 '15 at 20:52
  • It dumps a longer docstring at you. Have you gotten to the section " If one of the integration limits is infinite, then a Fourier integral is computed (assuming w neq 0). If full_output is 1 and a numerical error is encountered, besides the error message attached to the output tuple, a dictionary is also appended to the output tuple which translates the error codes in the array ``info['ierlst']`` to English messages. The output information dictionary contains the following entries instead of 'last', 'alist', 'blist', 'rlist', and 'elist':" ? – cphlewis Aug 10 '15 at 21:59
  • @cphlewis yes..now what is this fourier integral part? – TanMath Aug 10 '15 at 22:03
  • 4
    I'm really not going to do your Googling for you. Also, since you weren't interested enough to look up algorithm choices to start with, you probably don't really care now. Extract and analyze your error codes instead. – cphlewis Aug 10 '15 at 23:06

0 Answers0