Basic Operations on Quantum Objects¶
First things first¶
Warning
Do not run QuTiP from the installation directory.
To load the qutip modules, we must first call the import statement:
In [1]: from qutip import *
that will load all of the user available functions. Often, we also need to import the NumPy and Matplotlib libraries with:
In [2]: import numpy as np
In [3]: import matplotlib.pyplot as plt
Note that, in the rest of the documentation, functions are written using qutip.module.function() notation which links to the corresponding function in the QuTiP API: Functions. However, in calling import *, we have already loaded all of the QuTiP modules. Therefore, we will only need the function name and not the complete path when calling the function from the interpreter prompt, Python script, or Jupyter notebook.
The quantum object class¶
Introduction¶
The key difference between classical and quantum mechanics lies in the use of operators instead of numbers as variables. Moreover, we need to specify state vectors and their properties. Therefore, in computing the dynamics of quantum systems we need a data structure that is capable of encapsulating the properties of a quantum operator and ket/bra vectors. The quantum object class, qutip.Qobj
, accomplishes this using matrix representation.
To begin, let us create a blank Qobj
:
In [4]: Qobj()
Out[4]:
Quantum object: dims = [[1], [1]], shape = (1, 1), type = bra
Qobj data =
[[ 0.]]
where we see the blank Qobj
object with dimensions, shape, and data. Here the data corresponds to a 1x1-dimensional matrix consisting of a single zero entry.
Hint
By convention, Class objects in Python such as Qobj()
differ from functions in the use of a beginning capital letter.
We can create a Qobj
with a user defined data set by passing a list or array of data into the Qobj
:
In [5]: Qobj([[1],[2],[3],[4],[5]])
Out[5]:
Quantum object: dims = [[5], [1]], shape = (5, 1), type = ket
Qobj data =
[[ 1.]
[ 2.]
[ 3.]
[ 4.]
[ 5.]]
Notice how both the dims and shape change according to the input data. Although dims and shape appear to have the same function, the difference will become quite clear in the section on tensor products and partial traces.
Note
If you are running QuTiP from a python script you must use the print
function to view the Qobj attributes.
States and operators¶
Manually specifying the data for each quantum object is inefficient. Even more so when most objects correspond to commonly used types such as the ladder operators of a harmonic oscillator, the Pauli spin operators for a two-level system, or state vectors such as Fock states. Therefore, QuTiP includes predefined objects for a variety of states:
States | Command (# means optional) | Inputs |
---|---|---|
Fock state ket vector | basis(N,#m) /fock(N,#m) |
N = number of levels in Hilbert space, m = level containing excitation (0 if no m given) |
Fock density matrix (outer product of basis) | fock_dm(N,#p) |
same as basis(N,m) / fock(N,m) |
Coherent state | coherent(N,alpha) |
alpha = complex number (eigenvalue) for requested coherent state |
Coherent density matrix (outer product) | coherent_dm(N,alpha) |
same as coherent(N,alpha) |
Thermal density matrix (for n particles) | thermal_dm(N,n) |
n = particle number expectation value |
and operators:
Operators | Command (# means optional) | Inputs |
---|---|---|
Charge operator | charge(N,M=-N) |
Diagonal operator with entries from M..0..N. |
Commutator | commutator(A, B, kind) |
Kind = ‘normal’ or ‘anti’. |
Diagonals operator | qdiags(N) |
Quantum object created from arrays of diagonals at given offsets. |
Displacement operator (Single-mode) | displace(N,alpha) |
N=number of levels in Hilbert space, alpha = complex displacement amplitude. |
Higher spin operators | jmat(j,#s) |
j = integer or half-integer representing spin, s = ‘x’, ‘y’, ‘z’, ‘+’, or ‘-‘ |
Identity | qeye(N) |
N = number of levels in Hilbert space. |
Lowering (destruction) operator | destroy(N) |
same as above |
Momentum operator | momentum(N) |
same as above |
Number operator | num(N) |
same as above |
Phase operator (Single-mode) | phase(N, phi0) |
Single-mode Pegg-Barnett phase operator with ref phase phi0. |
Position operator | position(N) |
same as above |
Raising (creation) operator | create(N) |
same as above |
Squeezing operator (Single-mode) | squeeze(N, sp) |
N=number of levels in Hilbert space, sp = squeezing parameter. |
Squeezing operator (Generalized) | squeezing(q1, q2, sp) |
q1,q2 = Quantum operators (Qobj) sp = squeezing parameter. |
Sigma-X | sigmax() |
|
Sigma-Y | sigmay() |
|
Sigma-Z | sigmaz() |
|
Sigma plus | sigmap() |
|
Sigma minus | sigmam() |
|
Tunneling operator | tunneling(N,m) |
Tunneling operator with elements of the form \(|N><N+m| + |N+m><N|\). |
As an example, we give the output for a few of these functions:
In [6]: basis(5,3)
Out[6]:
Quantum object: dims = [[5], [1]], shape = (5, 1), type = ket
Qobj data =
[[ 0.]
[ 0.]
[ 0.]
[ 1.]
[ 0.]]
In [7]: coherent(5,0.5-0.5j)