Development notebook for testing the visualization module in QuTiP


In [1]:
%matplotlib inline

In [2]:
from qutip import *

Hinton


In [3]:
rho = rand_dm(5)

In [4]:
hinton(rho);


Sphereplot


In [5]:
theta = np.linspace(0,     pi, 90)
phi   = np.linspace(0, 2 * pi, 60)

In [6]:
sphereplot(theta, phi, orbital(theta, phi, basis(3, 0)));



In [7]:
fig = plt.figure(figsize=(16,4))

ax = fig.add_subplot(1, 3, 1, projection='3d')
sphereplot(theta, phi, orbital(theta, phi, basis(3, 0)), fig, ax);

ax = fig.add_subplot(1, 3, 2, projection='3d')
sphereplot(theta, phi, orbital(theta, phi, basis(3, 1)), fig, ax);

ax = fig.add_subplot(1, 3, 3, projection='3d')
sphereplot(theta, phi, orbital(theta, phi, basis(3, 2)), fig, ax);


Matrix histogram


In [8]:
matrix_histogram(rho.full().real);


/home/rob/py-envs/py3-devel/lib/python3.3/site-packages/matplotlib-1.4.x-py3.3-linux-x86_64.egg/mpl_toolkits/mplot3d/axes3d.py:1678: RuntimeWarning: invalid value encountered in true_divide
  for n in normals])
/home/rob/py-envs/py3-devel/lib/python3.3/site-packages/matplotlib-1.4.x-py3.3-linux-x86_64.egg/matplotlib/colors.py:405: RuntimeWarning: invalid value encountered in greater
  if (c.ravel() > 1).any() or (c.ravel() < 0).any():
/home/rob/py-envs/py3-devel/lib/python3.3/site-packages/matplotlib-1.4.x-py3.3-linux-x86_64.egg/matplotlib/colors.py:405: RuntimeWarning: invalid value encountered in less
  if (c.ravel() > 1).any() or (c.ravel() < 0).any():

In [9]:
matrix_histogram_complex(rho.full());


Plot energy levels


In [10]:
H0 = tensor(sigmaz(), identity(2)) + tensor(identity(2), sigmaz())
Hint = 0.1 * tensor(sigmax(), sigmax())

plot_energy_levels([H0, Hint], figsize=(8,4));


Plot Fock distribution


In [11]:
rho = (coherent(15, 1.5) + coherent(15, -1.5)).unit()

In [12]:
plot_fock_distribution(rho);


Plot Wigner function and Fock distribution


In [13]:
plot_wigner_fock_distribution(rho);


Plot winger function


In [14]:
plot_wigner(rho, figsize=(6,6));


Plot expectation values


In [15]:
H = sigmaz() + 0.3 * sigmay()
e_ops = [sigmax(), sigmay(), sigmaz()]
times = np.linspace(0, 10, 100)
psi0 = (basis(2, 0) + basis(2, 1)).unit()
result = mesolve(H, psi0, times, [], e_ops)

In [16]:
plot_expectation_values(result);


Bloch sphere


In [17]:
b = Bloch()
b.add_vectors(expect(H.unit(), e_ops))
b.add_points(result.expect, meth='l')
b.make_sphere()


Plot spin Q-functions


In [18]:
j = 5
psi = spin_state(j, -j)
psi = spin_coherent(j, np.random.rand() * pi, np.random.rand() * 2 * pi)
rho = ket2dm(psi)

In [19]:
theta = np.linspace(0, pi, 50)
phi = np.linspace(0, 2*pi, 50)

In [20]:
Q, THETA, PHI = spin_q_function(psi, theta, phi)

2D


In [21]:
plot_spin_distribution_2d(Q, THETA, PHI);


3D


In [22]:
fig, ax = plot_spin_distribution_3d(Q, THETA, PHI);

ax.view_init(15, 30)


Combined 2D and 3D


In [23]:
fig = plt.figure(figsize=(14,6))

ax = fig.add_subplot(1, 2, 1)
f1, a1 = plot_spin_distribution_2d(Q, THETA, PHI, fig=fig, ax=ax)

ax = fig.add_subplot(1, 2, 2, projection='3d')
f2, a2 = plot_spin_distribution_3d(Q, THETA, PHI, fig=fig, ax=ax)


Plot spin-Wigner functions


In [24]:
W, THETA, PHI = spin_wigner(psi, theta, phi)

In [25]:
fig = plt.figure(figsize=(14,6))

ax = fig.add_subplot(1, 2, 1)
f1, a1 = plot_spin_distribution_2d(W, THETA, PHI, fig=fig, ax=ax)

ax = fig.add_subplot(1, 2, 2, projection='3d')
f2, a2 = plot_spin_distribution_3d(W, THETA, PHI, fig=fig, ax=ax)


/home/rob/py-envs/py3-devel/lib/python3.3/site-packages/numpy/ma/core.py:2965: ComplexWarning: Casting complex values to real discards the imaginary part
  output = self._data.astype(newtype).view(type(self))
/home/rob/py-envs/py3-devel/lib/python3.3/site-packages/matplotlib-1.4.x-py3.3-linux-x86_64.egg/matplotlib/colors.py:920: ComplexWarning: Casting complex values to real discards the imaginary part
  vmin = float(vmin)
/home/rob/py-envs/py3-devel/lib/python3.3/site-packages/matplotlib-1.4.x-py3.3-linux-x86_64.egg/matplotlib/colors.py:921: ComplexWarning: Casting complex values to real discards the imaginary part
  vmax = float(vmax)
/home/rob/py-envs/py3-devel/lib/python3.3/site-packages/matplotlib-1.4.x-py3.3-linux-x86_64.egg/matplotlib/colors.py:938: ComplexWarning: Casting complex values to real discards the imaginary part
  vmin = float(self.vmin)
/home/rob/py-envs/py3-devel/lib/python3.3/site-packages/matplotlib-1.4.x-py3.3-linux-x86_64.egg/matplotlib/colors.py:939: ComplexWarning: Casting complex values to real discards the imaginary part
  vmax = float(self.vmax)

Versions


In [26]:
from qutip.ipynbtools import version_table

version_table()


Out[26]:
SoftwareVersion
SciPy0.15.0.dev-c04c506
OSposix [linux]
QuTiP3.0.0.dev-dca7c5b
Python3.3.2+ (default, Oct 9 2013, 14:50:09) [GCC 4.8.1]
matplotlib1.4.x
IPython2.0.0-dev
Numpy1.9.0.dev-d4c7c3a
Cython0.20.post0
Tue Apr 08 13:24:31 2014 JST