QuTiP example: Wigner pseudo-probability functions

J.R. Johansson and P.D. Nation

For more information about QuTiP see http://qutip.org


In [1]:
%matplotlib inline
import matplotlib.pylab as plt
import matplotlib as mpl
from mpl_toolkits.mplot3d import Axes3D
from matplotlib import cm

In [3]:
from qutip import *
#from qutip.visualization import wigner_cmap

Wigner function for superposition of fock states


In [5]:
x = 1.0 / sqrt(2) * (basis(10, 4) + basis(10, 2))
xvec = arange(-5, 5, 10.0 / 100)
yvec = xvec
W = wigner(x, xvec, yvec)
cmap = wigner_cmap(W)
X, Y = meshgrid(xvec, yvec)

In [14]:
fig = plt.figure(figsize=(8,6))
plt.contourf(X, Y, W, 50, cmap=cmap)
plt.colorbar();



In [13]:
fig = plt.figure(figsize=(10,8))
ax = Axes3D(fig, azim=-30, elev=73)
ax.plot_surface(X, Y, W, cmap=cmap, rstride=1, cstride=1, alpha=1, linewidth=0)
ax.set_zlim3d(-0.25, 0.25)
for a in ax.w_zaxis.get_ticklines() + ax.w_zaxis.get_ticklabels():
    a.set_visible(False)
nrm = mpl.colors.Normalize(W.min(), W.max())
cax, kw = mpl.colorbar.make_axes(ax, shrink=.66, pad=.02)
cb1 = mpl.colorbar.ColorbarBase(cax, cmap=cmap, norm=nrm)
cb1.set_label('Pseudoprobability')


Winger and Q-function for squeezed states


In [15]:
#-----------------------------------------------------------------------------
# Illustrates the operator exponential and its use in making a squeezed state
#-----------------------------------------------------------------------------
N = 20;
alpha = -1.0;     # Coherent amplitude of field
epsilon = 0.5j;   # Squeezing parameter 
a = destroy(N);
#-----------------------------------------------------------------------------
# Define displacement and squeeze operators
#-----------------------------------------------------------------------------
D = (alpha*a.dag()-conj(alpha)*a).expm();                    # Displacement
S = (0.5*conj(epsilon)*a*a-0.5*epsilon*a.dag()*a.dag()).expm();  # Squeezing
psi = D*S*basis(N,0); # Apply to vacuum state
g = 2;

Wigner function


In [17]:
xvec = arange(-40.,40.)*5./40
X,Y = meshgrid(xvec, xvec)

W=wigner(psi,xvec,xvec)

fig1 = plt.figure()
ax = Axes3D(fig1)
ax.plot_surface(X, Y, W, rstride=2, cstride=2, cmap=cm.jet, alpha=0.7)
ax.contour(X, Y, W, 15,zdir='x', offset=-6)
ax.contour(X, Y, W, 15,zdir='y', offset=6)
ax.contour(X, Y, W, 15,zdir='z', offset=-0.3)
ax.set_xlim3d(-6,6)
ax.set_xlim3d(-6,6)
ax.set_zlim3d(-0.3,0.4)
plt.title('Wigner function of squeezed state');


Q-function


In [18]:
Q = qfunc(psi,xvec,xvec,g);

fig2 = plt.figure()
ax = Axes3D(fig2)
ax.plot_surface(X, Y, Q, rstride=2, cstride=2, cmap=cm.jet, alpha=0.7)
ax.contour(X, Y, Q,zdir='x', offset=-6)
ax.contour(X, Y, Q,zdir='y', offset=6)
ax.contour(X, Y, Q, 15,zdir='z', offset=-0.4)
ax.set_xlim3d(-6,6)
ax.set_xlim3d(-6,6)
ax.set_zlim3d(-0.3,0.4)
plt.title('Q function of squeezed state');


Schrodinger cat state


In [21]:
N = 20;
#amplitudes of coherent states
alpha1=-2.0-2j
alpha2=2.0+2j
#define ladder oeprators
a = destroy(N);
#define displacement oeprators
D1=(alpha1*dag(a)-conj(alpha1)*a).expm()show()
D2=(alpha2*dag(a)-conj(alpha2)*a).expm()
#sum of coherent states
psi = sqrt(2)**-1*(D1+D2)*basis(N,0); # Apply to vacuum state

In [26]:
#calculate Wigner function
xvec = arange(-100.,100.)*5./100
yvec=xvecshow()
g=2.
W = wigner(psi,xvec,yvec)
c = plt.contourf(xvec,yvec,real(W),100)
plt.xlim([-5,5])
plt.ylim([-5,5])
plt.title('Wigner function of Schrodinger cat')
cbar = plt.colorbar(c)
cbar.ax.set_ylabel('Pseudoprobability');



In [28]:
#calculate Q function
Q = qfunc(psi,xvec,yvec)
qplt = plt.contourf(xvec,yvec,real(Q),100)
plt.xlim([-5,5])
plt.ylim([-5,5])
plt.title('Q function of Schrodinger cat')
cbar = plt.colorbar(qplt)
cbar.ax.set_ylabel('Probability');


Versions


In [1]:
from qutip.ipynbtools import version_table

version_table()


Out[1]:
SoftwareVersion
Cython0.19
SciPy0.14.0.dev-2a4ba40
QuTiP2.3.0.dev-0fd8af4
Python2.7.4 (default, Apr 19 2013, 18:28:01) [GCC 4.7.3]
IPython2.0.0-dev
OSposix [linux2]
Numpy1.8.0.dev-928289b
matplotlib1.4.x
Sat Sep 28 23:14:28 2013 JST

In [ ]: