In [24]:
from qutip import *
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
N=25
a=destroy(N)
n_op = a.dag()*a
H=2*np.pi*a.dag()*a
kappa=0.25
n_th=0.0  # was 2.0
c_ops=[np.sqrt(kappa*(1+n_th))*a,np.sqrt(kappa*n_th)*a.dag()]
times=np.linspace(0,40,200)
rho01=thermal_dm(N,2)
rho02=fock_dm(N,2)
rho03=coherent_dm(N,np.sqrt(2))
n1=mesolve(H,rho01,times,c_ops,[a.dag()*a]).expect[0]
n2=mesolve(H,rho02,times,c_ops,[a.dag()*a]).expect[0]
n3=mesolve(H,rho03,times,c_ops,[a.dag()*a]).expect[0]
m1=mesolve(H,rho01,times,c_ops,[a.dag()*a.dag()*a*a]).expect[0]
m2=mesolve(H,rho02,times,c_ops,[a.dag()*a.dag()*a*a]).expect[0]
m3=mesolve(H,rho03,times,c_ops,[a.dag()*a.dag()*a*a]).expect[0]
plt.plot(times,np.real(m1-n1*n1),label='(a)',lw=3,ls='--')
plt.plot(times,np.real(m2-n2*n2),label='(b)',lw=3,ls='-')
plt.plot(times,np.real(m3-n3*n3),label='(c)',lw=1,ls=':')
plt.legend(['(thermal state)','(fock state)','(coherent state)'])
plt.xlabel(times,fontsize=20,fontweight='bold')
plt.xlabel(r'$t(ns)$',fontsize=20,fontweight='bold')
plt.ylabel(r'$variance - <n> $',fontsize=20,fontweight='bold')
plt.show()



In [4]:
from qutip import *
import numpy as np
import cmath

# Try to make a pi/2 pulse on a state ket |1> and see which axis it will be

# generating arbitrary qubit state
def gen_qubit_state(alpha, beta):
    return alpha*ket([1], dim=2) + beta*ket([0], dim=2)

imaginary_unit = cmath.sqrt(-1)
# getting the ket
#psi_0 = gen_qubit_state(1/np.sqrt(2), -1j*1/np.sqrt(2))
psi_0 = gen_qubit_state(0, 1)
# rabi frequency 
omega = 2*np.pi
# energy splitting of the system hamiltonian
w0 = 2*np.pi
# define Hamiltonian
def Ham2(t, args=None):
    return w0*sigmaz() + omega*np.sin(w0*t)*sigmax()

def H1_coeff(t, args):
    return np.sin(w0*t)
H0 = w0*sigmaz()
H1 = omega*sigmax()
Ham3 = [H0,[H1,H1_coeff]]

time = np.linspace(0,0.5,100)

eval_operators = [sigmax(),sigmay(),sigmaz()]
Ham1 = w0*sigmaz()
#exp_list = sesolve(Ham1, psi_0, time, eval_operators)
exp_list2 = mesolve(Ham2, psi_0, time, [], eval_operators)
#exp_list3 = mesolve(Ham3, coherent(2,1), time, sigmaz(), eval_operators)

In [5]:
exp_list2.expect


Out[5]:
[array([  0.00000000e+00,   2.12969205e-05,   1.70255094e-04,
          5.73889335e-04,   1.35791917e-03,   2.64610842e-03,
          4.55959179e-03,   7.21618193e-03,   1.07296573e-02,
          1.52090289e-02,   2.07577765e-02,   2.74730679e-02,
          3.54449542e-02,   4.47555468e-02,   5.54781815e-02,
          6.76765750e-02,   8.14039835e-02,   9.67023718e-02,
          1.13601605e-01,   1.32118677e-01,   1.52256983e-01,
          1.74005667e-01,   1.97339039e-01,   2.22216091e-01,
          2.48580138e-01,   2.76358569e-01,   3.05462765e-01,
          3.35788158e-01,   3.67214478e-01,   3.99606174e-01,
          4.32813036e-01,   4.66671005e-01,   5.01003195e-01,
          5.35621104e-01,   5.70326025e-01,   6.04910639e-01,
          6.39160784e-01,   6.72857369e-01,   7.05778434e-01,
          7.37701306e-01,   7.68404847e-01,   7.97671738e-01,
          8.25290796e-01,   8.51059254e-01,   8.74785002e-01,
          8.96288729e-01,   9.15405943e-01,   9.31988834e-01,
          9.45907945e-01,   9.57053622e-01,   9.65337231e-01,
          9.70692100e-01,   9.73074192e-01,   9.72462490e-01,
          9.68859078e-01,   9.62288943e-01,   9.52799485e-01,
          9.40459745e-01,   9.25359389e-01,   9.07607439e-01,
          8.87330799e-01,   8.64672592e-01,   8.39790344e-01,
          8.12854037e-01,   7.84044083e-01,   7.53549233e-01,
          7.21564467e-01,   6.88288891e-01,   6.53923669e-01,
          6.18670031e-01,   5.82727364e-01,   5.46291417e-01,
          5.09552650e-01,   4.72694713e-01,   4.35893099e-01,
          3.99313955e-01,   3.63113068e-01,   3.27435026e-01,
          2.92412542e-01,   2.58165950e-01,   2.24802860e-01,
          1.92417959e-01,   1.61092955e-01,   1.30896645e-01,
          1.01885103e-01,   7.41019593e-02,   4.75787809e-02,
          2.23355144e-02,  -1.61900203e-03,  -2.42864800e-02,
         -4.56785842e-02,  -6.58163079e-02,  -8.47293300e-02,
         -1.02455363e-01,  -1.19039497e-01,  -1.34533547e-01,
         -1.48995407e-01,  -1.62488414e-01,  -1.75080724e-01,
         -1.86844707e-01]),
 array([ 0.        , -0.00100659, -0.00402125, -0.00902872, -0.01600343,
        -0.02490928, -0.03569946, -0.04831607, -0.06268981, -0.0787396 ,
        -0.09637222, -0.11548193, -0.13595014, -0.1576452 , -0.1804222 ,
        -0.20412294, -0.22857599, -0.25359702, -0.27898918, -0.3045438 ,
        -0.33004128, -0.35525222, -0.37993885, -0.40385664, -0.42675626,
        -0.44838573, -0.46849284, -0.48682777, -0.50314593, -0.51721094,
        -0.52879768, -0.53769547, -0.54371121, -0.54667249, -0.54643062,
        -0.54286337, -0.53587765, -0.52541169, -0.51143703, -0.49395996,
        -0.47302259, -0.44870333, -0.42111692, -0.39041382, -0.3567791 ,
        -0.32043072, -0.2816173 , -0.2406154 , -0.19772622, -0.15327205,
        -0.10759221, -0.06103881, -0.01397227,  0.03324327,  0.08024461,
         0.12667404,  0.17218375,  0.21644011,  0.25912756,  0.2999522 ,
         0.33864491,  0.37496412,  0.40869791,  0.43966578,  0.46771979,
         0.49274512,  0.51466029,  0.53341671,  0.54899783,  0.56141797,
         0.57072059,  0.57697641,  0.58028117,  0.58075319,  0.57853082,
         0.57376974,  0.56664028,  0.55732467,  0.54601438,  0.5329076 ,
         0.51820677,  0.50211629,  0.48484045,  0.46658149,  0.44753791,
         0.427903  ,  0.40786353,  0.38759869,  0.36727924,  0.34706677,
         0.32711326,  0.30756066,  0.2885407 ,  0.2701748 ,  0.25257403,
         0.23583926,  0.22006122,  0.20532073,  0.19168892,  0.17922739]),
 array([ 1.        ,  0.99999949,  0.9999919 ,  0.99995908,  0.99987101,
         0.99968621,  0.99935217,  0.99880603,  0.99797538,  0.99677919,
         0.99512889,  0.99292958,  0.99008142,  0.98648109,  0.98202342,
         0.97660315,  0.9701167 ,  0.96246413,  0.95355111,  0.9432909 ,
         0.93160644,  0.9184323 ,  0.90371665,  0.88742314,  0.86953264,
         0.85004481,  0.82897947,  0.80637773,  0.78230282,  0.75684063,
         0.73009991,  0.70221204,  0.67333047,  0.64362972,  0.61330401,
         0.58256543,  0.55164176,  0.52077396,  0.49021318,  0.46021771,
         0.43104944,  0.40297037,  0.37623881,  0.35110568,  0.32781073,
         0.30657898,  0.2876172 ,  0.27111076,  0.25722073,  0.24608138,
         0.23779812,  0.23244593,  0.23006823,  0.23067638,  0.23424963,
         0.2407357 ,  0.25005179,  0.26208615,  0.27670004,  0.29373018,
         0.31299149,  0.33428015,  0.35737683,  0.38205014,  0.40806014,
         0.43516181,  0.46310852,  0.49165539,  0.5205624 ,  0.54959736,
         0.57853853,  0.607177  ,  0.63531871,  0.66278612,  0.68941954,
         0.71507807,  0.73964024,  0.76300427,  0.78508802,  0.80582866,
         0.82518205,  0.84312191,  0.85963876,  0.87473869,  0.88844203,
         0.90078184,  0.91180239,  0.92155758,  0.93010932,  0.9375259 ,
         0.94388049,  0.94924952,  0.95371128,  0.95734449,  0.96022703,
         0.96243471,  0.96404016,  0.96511186,  0.96571326,  0.96590196])]

In [7]:
import matplotlib.pyplot as plt
%matplotlib inline

In [9]:
plt.plot(exp_list2.expect[0])


Out[9]:
[<matplotlib.lines.Line2D at 0x10fbf6550>]

In [ ]: