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.]]
In [6]: x = np.array([[1, 2, 3, 4, 5]])
In [7]: Qobj(x)
Out[7]:
Quantum object: dims = [[1], [5]], shape = (1, 5), type = bra
Qobj data =
[[1. 2. 3. 4. 5.]]
In [8]: r = np.random.rand(4, 4)
In [9]: Qobj(r)
Out[9]:
Quantum object: dims = [[4], [4]], shape = (4, 4), type = oper, isherm = False
Qobj data =
[[0.05466434 0.64087948 0.17482837 0.515324 ]
[0.70784678 0.524319 0.31937872 0.56781693]
[0.93001784 0.30682201 0.83393431 0.11172942]
[0.17233207 0.48796145 0.88912997 0.94194679]]
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 |
|
N = number of levels in Hilbert space, m = level containing excitation (0 if no m given) |
Fock density matrix (outer product of basis) |
|
same as basis(N,m) / fock(N,m) |
Coherent state |
|
alpha = complex number (eigenvalue) for requested coherent state |
Coherent density matrix (outer product) |
|
same as coherent(N,alpha) |
Thermal density matrix (for n particles) |
|
n = particle number expectation value |
and operators:
Operators |
Command (# means optional) |
Inputs |
---|---|---|
Charge operator |
|
Diagonal operator with entries from M..0..N. |
Commutator |
|
Kind = ‘normal’ or ‘anti’. |
Diagonals operator |
|
Quantum object created from arrays of diagonals at given offsets. |
Displacement operator (Single-mode) |
|
N=number of levels in Hilbert space, alpha = complex displacement amplitude. |
Higher spin operators |
|
j = integer or half-integer representing spin, s = ‘x’, ‘y’, ‘z’, ‘+’, or ‘-‘ |
Identity |
|
N = number of levels in Hilbert space. |
Lowering (destruction) operator |
|
same as above |
Momentum operator |
|
same as above |
Number operator |
|
same as above |
Phase operator (Single-mode) |
|
Single-mode Pegg-Barnett phase operator with ref phase phi0. |
Position operator |
|
same as above |
Raising (creation) operator |
|
same as above |
Squeezing operator (Single-mode) |
|
N=number of levels in Hilbert space, sp = squeezing parameter. |
Squeezing operator (Generalized) |
|
q1,q2 = Quantum operators (Qobj) sp = squeezing parameter. |
Sigma-X |
|
|
Sigma-Y |
|
|
Sigma-Z |
|
|
Sigma plus |
|
|
Sigma minus |
|
|
Tunneling operator |
|
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 [10]: basis(5,3)
Out[10]:
Quantum object: dims = [[5], [1]], shape = (5, 1), type = ket
Qobj data =
[[0.]
[0.]
[0.]
[1.]
[0.]]
In [11]: coherent(5,0.5-0.5j)