What is QuTip?
Qutip Setup
Installing Anaconda
- Anaconda is a tool to automatically download and setup various Python packages
- Go to and click on the download link that matches your operating system (Windows, Mac, Linux)
- Choose Python 3.7 and click “Download”
- Once finished downloading, click the installer and following the instruction in the wizard
- Will ask if you would like to also install Visual Studio Code. If you do not already have a text editor, it is recommended that you choose this option.
Setting up the Qutip environment
- Windows
- Mac
- Open Terminal
- Type “conda create -n qutip-env python=3” and press enter
- When it says “The following NEW packages will be installed” type ‘y’ and press enter
- Your Qutip environment is now created
- Linux
Installing packages in your Qutip environment
- Type source activate qutip-env and press enter
- Type “conda install numpy scipy cython matplotlib nose jupyter notebook spyder”, this will install all the prerequisite packages needed by Qutip
- Type ‘y’
- Type “conda config --append channels conda-forge”
- Type “conda install qutip”
- Qutip should now be setup on your system under your Conda environment
- To test if setup completed successfully, start an interactive python session by typing “python”
- Once in the interactive python session type “import qutip.testing as qt” and press enter
- Then type “qt.run()” and press enter, this will run a suite of test scritpts to make sure everything is working. It’s okay if you get warnings.
QuTip Functions
These are the common Qutip functions that have been and will be used within the Qutip Quantum Simulator (especially within this project). Most of this information can be found on http://qutip.org/docs/latest/apidoc/apidoc.html.
basis(N, n=0, offset=0)
Parameters:
- N : int
Number of Fock states in Hilbert space.
- n : int
Integer corresponding to desired number state, defaults to 0 if omitted.
- offset : int (default 0)
The lowest number state that is included in the finite number state representation of the state.
Returns:
- state : qobj
Qobj representing the requested number state |n>.
basis(N, 0) = ground state
basis(N, 1) = ground state
Example:
>>> basis(5,2)
Quantum object: dims = [[5], [1]], shape = [5, 1], type = ket
Qobj data =
[[ 0.+0.j]
[ 0.+0.j]
[ 1.+0.j]
[ 0.+0.j]
[ 0.+0.j]]
qeye(N)
Identity operator
Parameters:
- N : int or list of ints
Dimension of Hilbert space. If provided as a list of ints, then the dimension is the product over this list, but the dims property of the new Qobj are set to this list.
Returns:
oper : qobj
Identity operator Qobj.
Example:
>>> qeye(3)
Quantum object: dims = [[3], [3]], shape = [3, 3], type = oper, isHerm = True
Qobj data =
[[ 1. 0. 0.]
[ 0. 1. 0.]
[ 0. 0. 1.]]
tensor(*args)
Calculates the tensor product of input operators.
Parameters:
- args : array_like
list or array of quantum objects for tensor product.
Returns:
- obj : qobj
A composite quantum object.
Example:
>>> tensor([sigmax(), sigmax()])
Quantum object: dims = [[2, 2], [2, 2]], shape = [4, 4], type = oper, isHerm = True
Qobj data =
[[ 0.+0.j 0.+0.j 0.+0.j 1.+0.j]
[ 0.+0.j 0.+0.j 1.+0.j 0.+0.j]
[ 0.+0.j 1.+0.j 0.+0.j 0.+0.j]
[ 1.+0.j 0.+0.j 0.+0.j 0.+0.j]]
hadamard_transform(N=1)
Quantum object representing the N-qubit Hadamard gate.
Returns:
- q : qobj
Quantum object representation of the N-qubit Hadamard gate.
sigmax()
Pauli spin ½ sigma-x operator
Example:
>>> sigmax()
Quantum object: dims = [[2], [2]], shape = [2, 2], type = oper, isHerm = False
Qobj data =
[[ 0. 1.]
[ 1. 0.]]
Classes
Qobj
class Qobj(inpt=None, dims=[[], []], shape=[], type=None, isherm=None, copy=True, fast=False, superrep=None)[source]
A class for representing quantum objects, such as quantum operators and states.
The Qobj class is the QuTiP representation of quantum operators and state vectors. This class also implements math operations +,-,* between Qobj instances (and / by a C-number), as well as a collection of common operator/state operations. The Qobj constructor optionally takes a dimension list and/or shape list as arguments.
Parameters:
- inpt : array_like
Data for vector/matrix representation of the quantum object.
- dims : list
Dimensions of object used for tensor products.
- shape : list
Shape of underlying data structure (matrix shape).
- copy : bool
Flag specifying whether Qobj should get a copy of the input data, or use the original.
- fast : bool
Flag for fast qobj creation when running ode solvers. This parameter is used internally only.
Attributes
data |
(array_like) Sparse matrix characterizing the quantum object. |
dims |
(list) List of dimensions keeping track of the tensor structure. |
shape |
(list) Shape of the underlying data array. |
type |
(str) Type of quantum object: ‘bra’, ‘ket’, ‘oper’, ‘operator-ket’, ‘operator-bra’, or ‘super’. |
superrep |
(str) Representation used if type is ‘super’. One of ‘super’ (Liouville form) or ‘choi’ (Choi matrix with tr = dimension). |
isherm |
(bool) Indicates if quantum object represents Hermitian operator. |
iscp |
(bool) Indicates if the quantum object represents a map, and if that map is completely positive (CP). |
ishp |
(bool) Indicates if the quantum object represents a map, and if that map is hermicity preserving (HP). |
istp |
(bool) Indicates if the quantum object represents a map, and if that map is trace preserving (TP). |
iscptp |
(bool) Indicates if the quantum object represents a map that is completely positive and trace preserving (CPTP). |
isket |
(bool) Indicates if the quantum object represents a ket. |
isbra |
(bool) Indicates if the quantum object represents a bra. |
isoper |
(bool) Indicates if the quantum object represents an operator. |
issuper |
(bool) Indicates if the quantum object represents a superoperator. |
isoperket |
(bool) Indicates if the quantum object represents an operator in column vector form. |
isoperbra |
(bool) Indicates if the quantum object represents an operator in row vector form. |
Methods
copy()
| Create copy of Qobj |
conj()
| Conjugate of quantum object. |
cosm()
| Cosine of quantum object. |
dag()
| Adjoint (dagger) of quantum object. |
dnorm()
| Diamond norm of quantum operator. |
dual_chan()
| Dual channel of quantum object representing a CP map. |
eigenenergies(sparse=False, sort=’low’, eigvals=0, tol=0, maxiter=100000)
| Returns eigenenergies (eigenvalues) of a quantum object. |
eigenstates(sparse=False, sort=’low’, eigvals=0, tol=0, maxiter=100000)
| Returns eigenenergies and eigenstates of quantum object. |
expm()
| Matrix exponential of quantum object. |
full(order=’C’)
| Returns dense array of quantum object data attribute. |
groundstate(sparse=False, tol=0, maxiter=100000)
| Returns eigenvalue and eigenket for the groundstate of a quantum object. |
matrix_element(bra, ket)
| Returns the matrix element of operator between bra and ket vectors. |
norm(norm=’tr’, sparse=False, tol=0, maxiter=100000)
| Returns norm of a ket or an operator. |
permute(order)
| Returns composite qobj with indices reordered. |
ptrace(sel)
| Returns quantum object for selected dimensions after performing partial trace. |
sinm()
| Sine of quantum object. |
sqrtm()
| Matrix square root of quantum object. |
tidyup(atol=1e-12)
| Removes small elements from quantum object. |
tr()
| Trace of quantum object. |
trans()
| Transpose of quantum object. |
transform(inpt, inverse=False)
| Performs a basis transformation defined by inpt matrix. |
trunc_neg(method=’clip’)
| Removes negative eigenvalues and returns a new Qobj that is a valid density operator. |
unit(norm=’tr’, sparse=False, tol=0, maxiter=100000)
| Returns normalized quantum object. |
check_herm()[
source]
Check if the quantum object is hermitian.
Returns:
isherm : bool
Returns the new value of isherm property.
conj()[
source]
Conjugate operator of quantum object.
copy()[source]
cosm()[
source]
Cosine of a quantum operator.
Operator must be square.
Returns:
oper : qobj
Matrix cosine of operator.
Raises:
TypeError
Quantum object is not square.
Notes
Uses the Q.expm() method.
dag()[
source]
Adjoint operator of quantum object.
diag()[
source]
Diagonal elements of quantum object.
Returns:
diags : array
Returns array of real values if operators is Hermitian, otherwise complex values are returned.
dnorm(B=None)[
source]
Calculates the diamond norm, or the diamond distance to another operator.