QuTiP example: Dynamics of an atom-cavity system using three different solvers

J.R. Johansson and P.D. Nation

For more information about QuTiP see http://qutip.org


In [1]:
%pylab inline


Populating the interactive namespace from numpy and matplotlib

In [2]:
from qutip import *
import time

Model and parameters


In [3]:
kappa = 2; 
gamma = 0.2;
g  = 1; 
wc = 0; 
w0 = 0; 
wl = 0;
N  = 4; 
E  = 0.5;
tlist = linspace(0,10,200);

mesolve


In [4]:
def solve(E,kappa,gamma,g,wc,w0,wl,N,tlist):

    ida    = qeye(N)
    idatom = qeye(2)

    # Define cavity field and atomic operators
    a  = tensor(destroy(N),idatom)
    sm = tensor(ida,sigmam())

    # Hamiltonian
    H = (w0-wl)*sm.dag()*sm + (wc-wl)*a.dag()*a + 1j*g*(a.dag()*sm - sm.dag()*a) + E*(a.dag()+a)

    #collapse operators
    C1=sqrt(2*kappa)*a
    C2=sqrt(gamma)*sm
    C1dC1=C1.dag()*C1
    C2dC2=C2.dag()*C2

    #intial state
    psi0 = tensor(basis(N,0),basis(2,1))
    rho0 = psi0.dag() * psi0;

    # evolve and calculate expectation values
    output = mesolve(H, psi0, tlist, [C1, C2], [C1dC1, C2dC2, a])  

    return output.expect[0], output.expect[1], output.expect[2]

In [5]:
start_time=time.time()
count1, count2, infield = solve(E,kappa,gamma,g,wc,w0,wl,N,tlist)
print 'time elapsed = ' +str(time.time()-start_time)


time elapsed = 0.0682821273804

In [6]:
figure(figsize=(12,6))
plot(tlist,real(count1))
plot(tlist,real(count2))
xlabel('Time')
ylabel('Transmitted Intensity and Spontaneous Emission');


eseries


In [7]:
def solve(E,kappa,gamma,g,wc,w0,wl,N,tlist):

    # Define cavity field and atomic operators
    a  = tensor(destroy(N),qeye(2))
    sm = tensor(qeye(N),sigmam())

    # Hamiltonian
    H = (w0-wl)*sm.dag()*sm + (wc-wl)*a.dag()*a + 1j*g*(a.dag()*sm - sm.dag()*a) + E*(a.dag()+a)

    #collapse operators
    C1 = sqrt(2*kappa)*a
    C2 = sqrt(gamma)*sm
    C1dC1 = C1.dag() * C1
    C2dC2 = C2.dag() * C2

    #intial state
    psi0 = tensor(basis(N,0),basis(2,1))
    rho0 = ket2dm(psi0)

    # Calculate the Liouvillian
    L = liouvillian(H, [C1, C2])

    # Calculate solution as an exponential series
    start_time = time.time()
    rhoES = ode2es(L,rho0);
    print 'time elapsed (ode2es) = ' + str(time.time()-start_time) 
    
    # Calculate expectation values
    start_time = time.time()
    count1  = esval(expect(C1dC1,rhoES),tlist);
    count2  = esval(expect(C2dC2,rhoES),tlist);
    infield = esval(expect(a,rhoES),tlist);
    print 'time elapsed (esval) = ' +str(time.time()-start_time) 

    # alternative
    start_time = time.time()
    expt_list = essolve(H, psi0, tlist, [C1, C2], [C1dC1, C2dC2, a]) 
    print 'time elapsed (essolve) = ' +str(time.time()-start_time) 

    return count1, count2, infield, expt_list[0], expt_list[1], expt_list[2]

In [8]:
start_time = time.time()
count1, count2, infield, count1_2, count2_2, infield_2 = solve(E,kappa,gamma,g,wc,w0,wl,N,tlist);
print 'time elapsed = ' + str(time.time()-start_time)


time elapsed (ode2es) = 0.150741100311
time elapsed (esval) = 0.0328660011292
time elapsed (essolve) = 0.242558002472
time elapsed = 0.498425960541

In [9]:
figure(figsize=(12,6))
plot(tlist, real(count1), tlist, real(count1_2), '.')
plot(tlist, real(count2), tlist, real(count2_2), '.')
xlabel('Time')
ylabel('Transmitted Intensity and Spontaneous Emission');


mcsolve


In [10]:
ntraj=500 #number of Monte-Carlo trajectories
# Hamiltonian
ida=qeye(N)
idatom=qeye(2)
a=tensor(destroy(N),idatom)
sm=tensor(ida,sigmam())
H=(w0-wl)*sm.dag()*sm+(wc-wl)*a.dag()*a+1j*g*(a.dag()*sm-sm.dag()*a)+E*(a.dag()+a)
#collapse operators
C1=sqrt(2*kappa)*a
C2=sqrt(gamma)*sm
C1dC1=C1.dag()*C1
C2dC2=C2.dag()*C2
#intial state
psi0=tensor(basis(N,0),basis(2,1))

In [11]:
start_time=time.time()
avg=mcsolve(H,psi0,tlist,[C1,C2],[C1dC1,C2dC2],ntraj)
elapsed_time=time.time() - start_time
print("elapsed time =", elapsed_time)


('elapsed time =', 13.352603912353516)

In [12]:
figure(figsize=(12, 6))
plot(tlist,avg.expect[0],tlist,avg.expect[1],'--')
xlabel('Time')
ylabel('Photocount rates')
legend(('Cavity ouput', 'Spontaneous emission'));


Versions


In [13]:
from qutip.ipynbtools import version_table

version_table()


Out[13]:
SoftwareVersion
Cython0.19
SciPy0.14.0.dev-2a4ba40
QuTiP2.3.0.dev-35120ca
Python2.7.4 (default, Apr 19 2013, 18:28:01) [GCC 4.7.3]
IPython2.0.0-dev
OSposix [linux2]
Numpy1.8.0.dev-928289b
matplotlib1.4.x
Mon Sep 30 00:32:33 2013 JST