In [115]:
import numpy as np
from qutip import *
import pylab as plt

In [130]:
N = 25
taus = np.linspace(0, 25.0, 200)
a = destroy(N)
n_op = a.dag()*a
H = 2 * np.pi * n_op

In [143]:
kappa = 0.25
n_th = 2.0  # bath temperature in terms of excitation number
c_ops = [np.sqrt(kappa * (1 + n_th)) * a, np.sqrt(kappa * n_th) * a.dag()]

In [144]:
states = [{'state': coherent_dm(N, np.sqrt(2)), 'label': "coherent state"},
          {'state': thermal_dm(N, 2), 'label': "thermal state"},
          {'state': fock_dm(N, 2), 'label': "Fock state"}]

In [145]:
fig, ax = plt.subplots(1, 1)

for state in states:
    rho0 = state['state']

    # first calculate the occupation number as a function of time
    n = mesolve(H, rho0, taus, c_ops, [n_op]).expect[0]

    # calculate the correlation function G2 and normalize with n(0)n(t) to
    # obtain g2
    G2 = correlation_3op_1t(H, rho0, taus, c_ops, a.dag(), a.dag()*a, a)
    g2 = G2 / (n[0] * n)
    
    

    ax.plot(taus, np.real(g2), label=state['label'], lw=2)
    
ax.legend(loc=0)
ax.set_xlabel(r'$\tau$')
ax.set_ylabel(r'$g^{(2)}(\tau)$')


Out[145]:
<matplotlib.text.Text at 0x115e40908>

In [128]:
variance?

In [133]:
result = mesolve(H, coherent_dm(N, np.sqrt(2)), taus, c_ops, [n_op])

In [146]:
result.expect[0]


Out[146]:
array([ 2.        ,  2.        ,  2.        ,  2.        ,  2.        ,
        2.        ,  2.        ,  1.99999998,  1.99999996,  1.9999999 ,
        1.9999998 ,  1.99999962,  1.99999933,  1.9999989 ,  1.99999828,
        1.99999743,  1.9999963 ,  1.99999484,  1.99999302,  1.99999078,
        1.9999881 ,  1.99998494,  1.99998126,  1.99997706,  1.99997231,
        1.999967  ,  1.99996112,  1.99995469,  1.99994768,  1.99994013,
        1.99993204,  1.99992342,  1.9999143 ,  1.9999047 ,  1.99989463,
        1.99988414,  1.99987323,  1.99986195,  1.99985032,  1.99983837,
        1.99982612,  1.99981362,  1.99980088,  1.99978793,  1.99977482,
        1.99976155,  1.99974816,  1.99973467,  1.99972111,  1.99970749,
        1.99969386,  1.99968021,  1.99966658,  1.99965298,  1.99963943,
        1.99962594,  1.99961254,  1.99959923,  1.99958604,  1.99957296,
        1.99956002,  1.99954721,  1.99953456,  1.99952208,  1.99950975,
        1.99949761,  1.99948564,  1.99947386,  1.99946227,  1.99945087,
        1.99943967,  1.99942867,  1.99941788,  1.99940728,  1.9993969 ,
        1.99938671,  1.99937674,  1.99936697,  1.9993574 ,  1.99934805,
        1.99933889,  1.99932994,  1.99932119,  1.99931264,  1.99930429,
        1.99929613,  1.99928817,  1.99928039,  1.99927281,  1.99926541,
        1.99925819,  1.99925116,  1.9992443 ,  1.99923762,  1.9992311 ,
        1.99922476,  1.99921858,  1.99921256,  1.9992067 ,  1.99920099,
        1.99919544,  1.99919004,  1.99918478,  1.99917967,  1.99917469,
        1.99916985,  1.99916514,  1.99916057,  1.99915612,  1.99915179,
        1.99914759,  1.9991435 ,  1.99913953,  1.99913567,  1.99913193,
        1.99912828,  1.99912475,  1.99912131,  1.99911797,  1.99911473,
        1.99911158,  1.99910852,  1.99910556,  1.99910267,  1.99909988,
        1.99909716,  1.99909452,  1.99909196,  1.99908948,  1.99908707,
        1.99908473,  1.99908246,  1.99908026,  1.99907812,  1.99907605,
        1.99907403,  1.99907208,  1.99907019,  1.99906835,  1.99906657,
        1.99906484,  1.99906316,  1.99906153,  1.99905995,  1.99905842,
        1.99905694,  1.9990555 ,  1.9990541 ,  1.99905275,  1.99905144,
        1.99905016,  1.99904893,  1.99904773,  1.99904657,  1.99904544,
        1.99904435,  1.99904329,  1.99904227,  1.99904127,  1.99904031,
        1.99903937,  1.99903847,  1.99903759,  1.99903673,  1.99903591,
        1.99903511,  1.99903433,  1.99903358,  1.99903285,  1.99903214,
        1.99903146,  1.99903079,  1.99903015,  1.99902952,  1.99902892,
        1.99902833,  1.99902776,  1.99902721,  1.99902668,  1.99902616,
        1.99902566,  1.99902517,  1.9990247 ,  1.99902424,  1.9990238 ,
        1.99902337,  1.99902295,  1.99902255,  1.99902216,  1.99902178,
        1.99902141,  1.99902106,  1.99902071,  1.99902038,  1.99902005,
        1.99901974,  1.99901944,  1.99901914,  1.99901886,  1.99901858])

In [ ]: