Copyright (C) 2011 and later, Paul D. Nation & Robert J. Johansson
In [ ]:
%pylab inline
In [ ]:
from matplotlib import rcParams
rcParams["font.family"] = "STIXGeneral"
rcParams["mathtext.fontset"] = "stix"
rcParams["font.size"] = "16"
In [ ]:
from qutip import *
from qutip.ipynbtools import plot_animation
In [ ]:
wc = 1.0 * 2 * pi # cavity frequency
wa = 1.0 * 2 * pi # atom frequency
g = 0.1 * 2 * pi # coupling strength
kappa = 0.10 # cavity dissipation rate
gamma = 0.05 # atom dissipation rate
N = 15 # number of cavity fock states
tlist = linspace(0, 15, 150)
In [ ]:
# intial state
psi0 = tensor(coherent(N,2), basis(2,1)) # start with an excited atom
# operators
a = tensor(destroy(N), qeye(2))
sm = tensor(qeye(N), destroy(2))
sz = tensor(qeye(N), sigmaz())
# Hamiltonian
H = wc * a.dag() * a + wa * sm.dag() * sm + g * (a.dag() + a) * (sm + sm.dag())
c_ops = [sqrt(kappa) * a, sqrt(gamma) * sm]
In [ ]:
result = mesolve(H, psi0, tlist, c_ops, [a.dag() * a, sz], options=Odeoptions(store_states=True))
In [ ]:
def plot_setup(result):
fig = plt.figure(figsize=(8,8))
ax1 = plt.subplot2grid((2,2), (0,0), rowspan=1)
ax2 = plt.subplot2grid((2,2), (0,1), rowspan=1)
ax3 = plt.subplot2grid((2,2), (1,0), colspan=2)
axes = array([ax1, ax2, ax3])
axes[2].plot(result.times, result.expect[1], '-k')
return fig, axes
In [ ]:
def plot_result(result, n, fig=None, axes=None):
if fig is None or axes is None:
fig, axes = plot_setup(result)
axes[0].cla()
axes[1].cla()
wigner_fock_distribution(ptrace(result.states[n], 0), fig=fig, axes=axes[0:2])
axes[2].plot(result.times[n], result.expect[1][n], 'bo')
axes[2].set_ylim(-1, 1)
axes[2].set_xlim(0, max(tlist))
axes[2].set_xlabel(r'$t$')
axes[2].set_ylabel(r'Atomic inversion $\langle\sigma_z\rangle$')
return fig, axes
To embedd video in the notebook, make sure that ffmpeg and libx264 is installed.
# in ubuntu:
sudo apt-get install ffmpeg
sudo apt-get install libavcodec-extra-53
In [ ]:
plot_animation(plot_setup, plot_result, result)
In [ ]:
from qutip.ipynbtools import version_table
version_table()