Copyright (C) 2011 and later, Paul D. Nation & Robert J. Johansson
%pylab inline
Populating the interactive namespace from numpy and matplotlib
from matplotlib import rcParams
rcParams["font.family"] = "STIXGeneral"
rcParams["mathtext.fontset"] = "stix"
rcParams["font.size"] = "16"
from qutip import *
from qutip.ipynbtools import plot_animation
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)
# 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]
result = mesolve(H, psi0, tlist, c_ops, [a.dag() * a, sz], options=Odeoptions(store_states=True))
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
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
plot_animation(plot_setup, plot_result, result)
from qutip.ipynbtools import version_table
version_table()
Software | Version |
---|---|
Cython | 0.19 |
SciPy | 0.14.0.dev-2a4ba40 |
QuTiP | 2.3.0.dev-0fd8af4 |
Python | 2.7.4 (default, Apr 19 2013, 18:28:01) [GCC 4.7.3] |
IPython | 2.0.0-dev |
OS | posix [linux2] |
Numpy | 1.8.0.dev-928289b |
matplotlib | 1.4.x |
Sat Sep 28 23:09:43 2013 JST |