{ "cells": [ { "cell_type": "markdown", "source": [ " QuTiP example: Wigner function animation for the dynamics of the Jaynes-Cumming model" ], "metadata": {} }, { "cell_type": "markdown", "source": [ "J.R. Johansson and P.D. Nation\n", "\n", "For more information about QuTiP see [http://qutip.org](http://qutip.org)" ], "metadata": {} }, { "cell_type": "code", "source": [ "%matplotlib inline" ], "outputs": [], "execution_count": 1, "metadata": {} }, { "cell_type": "code", "source": [ "import matplotlib.pyplot as plt" ], "outputs": [], "execution_count": 2, "metadata": {} }, { "cell_type": "code", "source": [ "import numpy as np" ], "outputs": [], "execution_count": 3, "metadata": {} }, { "cell_type": "code", "source": [ "from mpl_toolkits.mplot3d import Axes3D\n", "from matplotlib import cm\n", "import time" ], "outputs": [], "execution_count": 4, "metadata": {} }, { "cell_type": "code", "source": [ "from qutip import *\n", "from qutip.ipynbtools import plot_animation" ], "outputs": [], "execution_count": 5, "metadata": {} }, { "cell_type": "code", "source": [ "def jc_integrate(N, wc, wa, g, kappa, gamma, psi0, use_rwa, tlist):\n", "\n", " # Hamiltonian\n", " idc = qeye(N)\n", " ida = qeye(2)\n", "\n", " a = tensor(destroy(N), ida)\n", " sm = tensor(idc, destroy(2))\n", "\n", " if use_rwa: \n", " # use the rotating wave approxiation\n", " H = wc * a.dag() * a + wa * sm.dag() * sm + g * (a.dag() * sm + a * sm.dag())\n", " else:\n", " H = wc * a.dag() * a + wa * sm.dag() * sm + g * (a.dag() + a) * (sm + sm.dag())\n", " \n", " # collapse operators\n", " c_op_list = []\n", "\n", " n_th_a = 0.0 # zero temperature\n", "\n", " rate = kappa * (1 + n_th_a)\n", " if rate > 0.0:\n", " c_op_list.append(np.sqrt(rate) * a)\n", "\n", " rate = kappa * n_th_a\n", " if rate > 0.0:\n", " c_op_list.append(np.sqrt(rate) * a.dag())\n", "\n", " rate = gamma\n", " if rate > 0.0:\n", " c_op_list.append(np.sqrt(rate) * sm)\n", "\n", " # evolve and calculate return state vectors\n", " result = mesolve(H, psi0, tlist, c_op_list, []) \n", "\n", " return result" ], "outputs": [], "execution_count": 6, "metadata": {} }, { "cell_type": "code", "source": [ "# parameters\n", "wc = 1.0 * 2 * np.pi # cavity frequency\n", "wa = 1.0 * 2 * np.pi # atom frequency\n", "g = 0.05 * 2 * np.pi # coupling strength\n", "kappa = 0.05 # cavity dissipation rate\n", "gamma = 0.15 # atom dissipation rate\n", "N = 10 # number of cavity fock states\n", "\n", "use_rwa = True\n", "\n", "# initial state\n", "psi0 = tensor(basis(N,0), basis(2,1)) # start with an excited atom \n", "#psi0 = tensor(coherent(N,1.5), basis(2,0)) # or a coherent state the in cavity\n", "#psi0 = tensor((coherent(N,2.0)+coherent(N,-2.0)).unit(), basis(2,0)) # or a superposition of coherent states\n", "\n", "tlist = np.linspace(0, 30, 150)" ], "outputs": [], "execution_count": 7, "metadata": {} }, { "cell_type": "code", "source": [ "result = jc_integrate(N, wc, wa, g, kappa, gamma, psi0, use_rwa, tlist)" ], "outputs": [], "execution_count": 8, "metadata": {} }, { "cell_type": "code", "source": [ "xvec = np.linspace(-5.,5.,100)\n", "X,Y = np.meshgrid(xvec, xvec)" ], "outputs": [], "execution_count": 9, "metadata": {} }, { "cell_type": "code", "source": [ "def plot_setup(result): \n", " \n", " fig = plt.figure(figsize=(12, 6))\n", " ax = Axes3D(fig, azim=-107, elev=49)\n", "\n", " return fig, ax" ], "outputs": [], "execution_count": 10, "metadata": {} }, { "cell_type": "code", "source": [ "cb = None\n", "\n", "def plot_result(result, n, fig=None, axes=None):\n", " \n", " global cb\n", " \n", " if fig is None or axes is None:\n", " fig, ax = plot_setup(result)\n", " \n", " axes.cla()\n", "\n", " # trace out the atom\n", " rho_cavity = ptrace(result.states[n], 0)\n", "\n", " W = wigner(rho_cavity, xvec, xvec)\n", " \n", " surf = axes.plot_surface(X, Y, W, rstride=1, cstride=1, cmap=cm.jet,\n", " alpha=1.0, linewidth=0.05, vmax=0.25, vmin=-0.25)\n", " axes.set_xlim3d(-5, 5)\n", " axes.set_ylim3d(-5, 5)\n", " axes.set_zlim3d(-0.25, 0.25)\n", " \n", " if not cb:\n", " cb = plt.colorbar(surf, shrink=0.65, aspect=20)\n", "\n", " return fig, axes" ], "outputs": [], "execution_count": 11, "metadata": {} }, { "cell_type": "code", "source": [ "plot_animation(plot_setup, plot_result, result)" ], "outputs": [ { "output_type": "execute_result", "execution_count": 12, "data": { "text/html": [ "