QuTiP development notebook: test number state basis with lower cut off

Copyright (C) 2013, Paul D. Nation & Robert J. Johansson

When we work with harmonic oscillator operators in the number state representation we always need to truncate the number of basis states at a finite number. Usually we pick an upper limit for the number state and use all the number states below this cut off. However, in some problems it can also be useful with a number basis representation that does not start with the zero number state, but rather at some lower cut off. This notebook demonstrates how to do this in QuTiP using the optional offset argument to oscillator operator functions.

In [1]:
%pylab inline
Populating the interactive namespace from numpy and matplotlib
In [2]:
from qutip import *

Test operators with offset

In [3]:
def steadystate_fock_distribution(N, offset):
    """
    Solve for the steady state of a driven dissipative cavity, given
    the upper (N) and lower (offset) cut offs for the number states in
    in the basis. Calculate the average photon number in the steady
    state and plot the fock state distribution.
    """
    N = N - offset
    Omega = 1.0 * 2 * pi
    kappa = 0.9
    
    a = destroy(N, offset)
    n = num(N, offset)
    H = Omega * (a + a.dag())
    c_ops = [sqrt(kappa) * a]
    
    rho_ss = steadystate(H, c_ops)
    
    title = "Steady state avg. photon number = %.2f" % expect(rho_ss, n)    
    
    fig, ax = fock_distribution(rho_ss, offset=offset, unit_y_range=False, title=title)
    
    return fig, ax
In [4]:
steadystate_fock_distribution(250, 0);
In [5]:
steadystate_fock_distribution(250, 150);

Test states with offset

In [1]:
%pylab inline
Populating the interactive namespace from numpy and matplotlib
In [2]:
from qutip import *

Fock states

In [3]:
N = 10
offset = 0

n = num(N, offset=offset)
psi = (basis(N, 2, offset=offset) + basis(N, 4, offset=offset) + basis(N, 6, offset=offset)).unit()

fock_distribution(psi, offset=offset, unit_y_range=False, figsize=(4,3))

expect(n, psi)
Out[3]:
4.000000000000001
In [4]:
N = 5
offset = 2

n = num(N, offset=offset)
psi = (basis(N, 2, offset=offset) + basis(N, 4, offset=offset) + basis(N, 6, offset=offset)).unit()

fock_distribution(psi, offset=offset, unit_y_range=False, figsize=(4,3))

expect(n, psi)
Out[4]:
4.000000000000001

Coherent states

In [12]:
N = 75
offset = 0

n = num(N, offset=offset)
psi = coherent(N, 6.5, offset=offset)

fock_distribution(psi, offset=offset, unit_y_range=False, figsize=(4,3))

expect(n, psi)
Out[12]:
42.24999120237548
In [14]:
N = 50
offset = 20

n = num(N, offset=offset)
psi = coherent(N, 6.5, offset=offset)

fock_distribution(psi, offset=offset, unit_y_range=False, figsize=(4,3))

expect(n, psi)
Out[14]:
42.244955490644436

Software versions

In [6]:
from qutip.ipynbtools import version_table; version_table()
Out[6]:
SoftwareVersion
Cython0.19.1
QuTiP2.3.0.dev-15c5f51
SciPy0.13.0.dev-7c6d92e
Python3.3.1 (default, Apr 17 2013, 22:30:32) [GCC 4.7.3]
Numpy1.8.0.dev-b307a8a
matplotlib1.4.x
IPython2.0.0-dev
OSposix [linux]
Fri Aug 30 15:46:41 2013 JST