Chapter 12 - Simple Harmonic Oscillator

Several examples that make use of the built-in Simple Harmonic Oscillator tools:


In [32]:
from numpy import sqrt,linspace,exp
from qutip import *
import matplotlib.pyplot as plt
%matplotlib inline

In [9]:
N = 40 # size of the Hilbert space.
       # N needs to be large enough that matrix is not truncated
a = destroy(N)
n = a.dag()*a

Define a coherent state with $\alpha = 2:$


In [17]:
psi = coherent(N,1)

In [18]:
psi


Out[18]:
Quantum object: dims = [[40], [1]], shape = (40, 1), type = ket\begin{equation*}\left(\begin{array}{*{11}c}0.607\\0.607\\0.429\\0.248\\0.124\\\vdots\\0.0\\0.0\\0.0\\0.0\\0.0\\\end{array}\right)\end{equation*}

Expectation value $\langle n\rangle$:


In [19]:
psi.dag()*n*psi


Out[19]:
Quantum object: dims = [[1], [1]], shape = (1, 1), type = bra\begin{equation*}\left(\begin{array}{*{11}c}1.000\\\end{array}\right)\end{equation*}

In [20]:
# Convert to a density matrix:
psi_dm = ket2dm(psi)

In [21]:
psi*psi.dag()


Out[21]:
Quantum object: dims = [[40], [40]], shape = (40, 40), type = oper, isherm = True\begin{equation*}\left(\begin{array}{*{11}c}0.368 & 0.368 & 0.260 & 0.150 & 0.075 & \cdots & 0.0 & 0.0 & 0.0 & 0.0 & 0.0\\0.368 & 0.368 & 0.260 & 0.150 & 0.075 & \cdots & 0.0 & 0.0 & 0.0 & 0.0 & 0.0\\0.260 & 0.260 & 0.184 & 0.106 & 0.053 & \cdots & 0.0 & 0.0 & 0.0 & 0.0 & 0.0\\0.150 & 0.150 & 0.106 & 0.061 & 0.031 & \cdots & 0.0 & 0.0 & 0.0 & 0.0 & 0.0\\0.075 & 0.075 & 0.053 & 0.031 & 0.015 & \cdots & 0.0 & 0.0 & 0.0 & 0.0 & 0.0\\\vdots & \vdots & \vdots & \vdots & \vdots & \ddots & \vdots & \vdots & \vdots & \vdots & \vdots\\0.0 & 0.0 & 0.0 & 0.0 & 0.0 & \cdots & 0.0 & 0.0 & 0.0 & 0.0 & 0.0\\0.0 & 0.0 & 0.0 & 0.0 & 0.0 & \cdots & 0.0 & 0.0 & 0.0 & 0.0 & 0.0\\0.0 & 0.0 & 0.0 & 0.0 & 0.0 & \cdots & 0.0 & 0.0 & 0.0 & 0.0 & 0.0\\0.0 & 0.0 & 0.0 & 0.0 & 0.0 & \cdots & 0.0 & 0.0 & 0.0 & 0.0 & 0.0\\0.0 & 0.0 & 0.0 & 0.0 & 0.0 & \cdots & 0.0 & 0.0 & 0.0 & 0.0 & 0.0\\\end{array}\right)\end{equation*}

In [22]:
# Fock state distribution of the coherent state:
plot_fock_distribution(psi_dm)


Out[22]:
(<matplotlib.figure.Figure at 0x11a2f3358>,
 <matplotlib.axes._subplots.AxesSubplot at 0x11a3396d8>)

Also look at other coherent states:


In [25]:
# With larger N and α:
plot_fock_distribution(coherent_dm(100,6))


Out[25]:
(<matplotlib.figure.Figure at 0x11a549ef0>,
 <matplotlib.axes._subplots.AxesSubplot at 0x11a8247b8>)

And some other density matrices, like a fock-state (or n eigenstate):


In [26]:
# With a Fock state (number state):
plot_fock_distribution(fock_dm(20,2))


Out[26]:
(<matplotlib.figure.Figure at 0x1022aa5c0>,
 <matplotlib.axes._subplots.AxesSubplot at 0x1022f9940>)

In [27]:
fock(20,2)


Out[27]:
Quantum object: dims = [[20], [1]], shape = (20, 1), type = ket\begin{equation*}\left(\begin{array}{*{11}c}0.0\\0.0\\1.0\\0.0\\0.0\\\vdots\\0.0\\0.0\\0.0\\0.0\\0.0\\\end{array}\right)\end{equation*}

And a thermal state:


In [16]:
# A thermal state has decaying amplitudes
plot_fock_distribution(thermal_dm(20,2))


Out[16]:
(<matplotlib.figure.Figure at 0x124a1c2b0>,
 <matplotlib.axes._subplots.AxesSubplot at 0x124e6beb8>)

Finally, can visualize the phasor using what is called the Wigner function:


In [41]:
xvec = linspace(-10,10,200) # Create an array for the phase space coordinates.
plt.imshow(wigner(coherent(40,5j)+coherent(40,-5j),xvec,xvec), extent=[-10,10,-10,10]) # contour plot of Wigner function


Out[41]:
<matplotlib.image.AxesImage at 0x11c80bc50>

In [42]:


In [ ]: