# QuTiP development notebook for testing distribution modules¶

Copyright (C) 2011 and later, Paul D. Nation & Robert J. Johansson

In [1]:
%pylab inline

In [2]:
from qutip import *

In [3]:
from qutip.distributions import *

In [4]:
N = 20
alpha = 2.0 + 2j
rho = (coherent(N, alpha) + coherent(N, -alpha)).unit()


### Wigner distribution¶

In [5]:
w = WignerDistribution(rho, extent=[[-10, 10], [-10, 10]])

In [6]:
w.visualize();


### Husimi Q function¶

In [7]:
q = QDistribution(rho, extent=[[-10, 10], [-10, 10]])

In [8]:
q.visualize(style="surface");


In [9]:
alpha = 1.0

In [10]:
psi = (tensor(coherent(N, alpha), basis(N, 0)) + tensor(basis(N, 0), coherent(N, -alpha))).unit()  # superposition
rho = (ket2dm(tensor(coherent(N, alpha), basis(N, 0))) + ket2dm(tensor(basis(N, 0), coherent(N, -alpha)))).unit()  # mixture

In [11]:
p = TwoModeQuadratureCorrelation(psi)

In [12]:
p.visualize();

In [13]:
p = TwoModeQuadratureCorrelation(rho)

In [14]:
p.visualize();

/usr/local/lib/python2.7/dist-packages/numpy/ma/core.py:2641: ComplexWarning: Casting complex values to real discards the imaginary part
_data = np.array(data, dtype=dtype, copy=copy, subok=True, ndmin=ndmin)

In [15]:
fig, axes = subplots(1, 2, figsize=(12, 5))

w0 = WignerDistribution(ptrace(rho, 0))
w1 = WignerDistribution(ptrace(rho, 1))

w0.visualize(fig=fig, ax=axes[0]);
w1.visualize(fig=fig, ax=axes[1]);


### Marginal distribution¶

In [16]:
alpha = 2.0
rho = (coherent(N, alpha) + coherent(N, -alpha)).unit()

In [17]:
w = WignerDistribution(rho)

In [18]:
w.visualize();

In [19]:
wx = w.marginal(dim=0)

In [20]:
fig, ax = wx.visualize();

In [21]:
wy = w.marginal(dim=1)

In [22]:
fig, ax = wy.visualize();

In [23]:
wx = w.project(dim=1)

In [24]:
fig, ax = wx.visualize();


### Harmonic oscillator wave function¶

In [25]:
M=8

fig, ax = subplots(M, 1, figsize=(10, 12), sharex=True)

for n in range(M):
psi = fock(N, n)
wf = HarmonicOscillatorWaveFunction(psi, 1.0, extent=[-10, 10])
wf.visualize(fig=fig, ax=ax[M-n-1], show_ylabel=False, show_xlabel=(n == 0))

/usr/local/lib/python2.7/dist-packages/numpy/core/numeric.py:331: ComplexWarning: Casting complex values to real discards the imaginary part
return array(a, dtype, copy=False, order=order)

In [26]:
psi = coherent(50, 4.0)
wf = HarmonicOscillatorWaveFunction(psi, 1.0, extent=[-15, 15])
wf.visualize();


### Software versions¶

In [27]:
from qutip.ipynbtools import version_table
version_table()

Out[27]:
SoftwareVersion
Cython0.19-dev