For Better Performance Please Use Chrome or Firefox Web Browser

Basic Operations on Quantum Objects

First things first

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

The quantum object class

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.

     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 in states module:

States Command Inputs
Fock ket states.fock(N,m) N = number of levels in Hilbert space, m = level containing excitation
Coherent ket states.coherent(N,alpha) alpha = complex number (eigenvalue) for requested coherent state
Fock density matrix states.fock_dm(N,m) same as Fock state ket
Coherent density matrix states.coherent_dm(N,alpha) same as Coherent state ket
Thermal density matrix states.thermal_dm(N,n) n = particle number expectation value

and operators in the operators module:

Operators Command Inputs
Commutator operators.commutator(A, B, kind) Kind = ‘normal’ or ‘anti’.
Identity operators.qeye(N) N = number of levels in Hilbert space.
Annihilation operators.destroy(N) same as above
Creation operators.create(N) same as above

Qobj attributes

We have seen that a quantum object has several internal attributes, such as data, dims, and shape. These can be accessed in the following way:

In [4]: a = destroy(4)
In [5]: a.dims
Out[5]: [[4], [4]]
In [6]: a.shape
Out[6]: (4, 4)

In general, the attributes (properties) of a Qobj object (or any Python class) can be retrieved using the Q.attribute notation. In addition to the attributes shown with the print function, the Qobj class also has the following:

Property Attribute Description
Data Q.data Matrix representing state or operator
Dimensions Q.dims List keeping track of shapes for individual components of a multipartite system (for tensor products and partial traces).
Shape Q.shape Dimensions of underlying data matrix.
is Hermitian? Q.isherm Is the operator Hermitian or not?
Type Q.type Is object of type ‘ket, ‘bra’, ‘oper’, or ‘super’?

The data attribute returns a message stating that the data is a sparse matrix. All Qobj instances store their data as a sparse matrix to save memory. To access the underlying dense matrix one needs to use the qutip.Qobj.full function as described below.

Qobj Math

The rules for mathematical operations on Qobj instances are similar to standard matrix arithmetic. In addition, the logic operators is equal == and is not equal != are also supported.

In [7]: a + 5

Adds the matrix a with an identity matrix of the same size multiplied by 5. In other words an equivalent to the above math is:

In [8]: a + 5*qeye(4)

The matrix as well as scalar products are performed by '*'.

Functions operating on Qobj class

Like attributes, the quantum object class has defined functions (methods) that operate on Qobj class instances. For a general quantum object Q:

Function Command Description
Conjugate Q.conj() Conjugate of quantum object.
Dagger Q.dag() Returns adjoint (dagger) of object.
Diagonal Q.diag() Returns the diagonal elements.
Eigenenergies Q.eigenenergies() Eigenenergies (values) of operator.
Eigenstates Q.eigenstates() Returns eigenvalues and eigenvectors.
Groundstate Q.groundstate() Eigenval & eigket of Qobj groundstate.
Overlap Q.overlap(state) Overlap between current Qobj and a given state.
Projector Q.proj() Form projector operator from given ket or bra vector.
Trace Q.tr() Returns trace of quantum object.
Transpose Q.trans() Transpose of quantum object.

تحت نظارت وف ایرانی