Comprehensive Python library for simulating quantum systems dynamics and quantum information processing.
npx @tessl/cli install tessl/pypi-qutip@5.2.0QuTiP (Quantum Toolbox in Python) is a comprehensive library for simulating quantum systems dynamics and quantum information processing. It provides user-friendly and efficient numerical simulations of quantum mechanical problems, including systems with arbitrary time-dependent Hamiltonians and collapse operators, commonly found in quantum optics, quantum computing, and condensed matter physics.
pip install qutip or conda install -c conda-forge qutipimport qutipCommon imports for specific functionality:
from qutip import Qobj, basis, coherent, destroy, num, sigmax, sigmay, sigmaz
from qutip import mesolve, sesolve, mcsolve, steadystate
from qutip import tensor, expect, ptrace
from qutip import Bloch, hinton, plot_wignerimport qutip as qt
import numpy as np
# Create quantum objects
psi = qt.basis(2, 0) # |0⟩ state
sigma_x = qt.sigmax() # Pauli-X operator
a = qt.destroy(10) # Annihilation operator for 10-level system
# Quantum operations
psi_x = sigma_x * psi # Apply Pauli-X
rho = psi * psi.dag() # Create density matrix
exp_val = qt.expect(sigma_x, psi) # Expectation value
# Time evolution
H = qt.sigmaz() # Hamiltonian
times = np.linspace(0, 10, 100)
result = qt.sesolve(H, psi, times) # Solve Schrödinger equation
# Visualization
b = qt.Bloch()
b.add_states(psi)
b.show()QuTiP is built around the Qobj (Quantum Object) class, which represents quantum states, operators, and superoperators in a unified framework. The library uses efficient sparse matrix representations from SciPy and provides multiple solver backends for different types of quantum systems:
The modular design allows users to combine components flexibly while maintaining computational efficiency through optimized linear algebra backends.
Fundamental quantum object manipulation, state construction, and basic operations. The Qobj class serves as the foundation for all quantum computations in QuTiP.
class Qobj:
def __init__(self, inpt=None, dims=None, shape=None, type=None,
isherm=None, isunitary=None, copy=True): ...
def copy(self) -> 'Qobj': ...
def dag(self) -> 'Qobj': ...
def conj(self) -> 'Qobj': ...
def trans(self) -> 'Qobj': ...
def norm(self, norm=None, sparse=False, tol=0, maxiter=100000): ...
def tr(self): ...
def ptrace(self, sel): ...
def eigenstates(self, sparse=False, sort='low', eigvals=0, tol=0, maxiter=100000): ...
def eigenenergies(self, sparse=False, sort='low', eigvals=0, tol=0, maxiter=100000): ...
def expm(self, dtype=None): ...
def logm(self, dtype=None): ...
def sqrtm(self, dtype=None): ...
def unit(self, inplace=False): ...
def tidyup(self, atol=None, rtol=None): ...Creation of fundamental quantum states including basis states, coherent states, squeezed states, and multi-qubit entangled states.
def basis(N: int, n: int = 0, offset: int = 0) -> Qobj: ...
def coherent(N: int, alpha: complex, offset: int = 0, method: str = 'operator') -> Qobj: ...
def fock(N: int, n: int = 0, offset: int = 0) -> Qobj: ...
def thermal_dm(N: int, n: float, method: str = 'operator') -> Qobj: ...
def bell_state(state: str = '00') -> Qobj: ...
def ghz_state(N: int = 3) -> Qobj: ...
def w_state(N: int = 3) -> Qobj: ...Construction of quantum operators including Pauli matrices, creation/annihilation operators, spin operators, and quantum gates.
def create(N: int, offset: int = 0) -> Qobj: ...
def destroy(N: int, offset: int = 0) -> Qobj: ...
def num(N: int, offset: int = 0) -> Qobj: ...
def sigmax() -> Qobj: ...
def sigmay() -> Qobj: ...
def sigmaz() -> Qobj: ...
def jmat(j: float, op: str = None) -> Qobj: ...
def squeeze(N: int, z: complex, offset: int = 0) -> Qobj: ...
def displace(N: int, alpha: complex, offset: int = 0) -> Qobj: ...Comprehensive suite of solvers for quantum system dynamics including unitary evolution, open system dynamics, and stochastic methods.
def sesolve(H, psi0, tlist, e_ops=None, options=None) -> Result: ...
def mesolve(H, rho0, tlist, c_ops=None, e_ops=None, options=None) -> Result: ...
def mcsolve(H, psi0, tlist, c_ops=None, e_ops=None, ntraj=500, options=None) -> McResult: ...
def steadystate(A, c_ops=None, method='direct', sparse=True, use_wbm=False) -> Qobj: ...
def floquet_modes(H, T, args=None, sort=True, U=None) -> tuple: ...
def propagator(H, t, c_ops=None, args=None, options=None, unitary_mode='batch', parallel=False) -> Qobj: ...Operations for combining quantum systems and manipulating composite quantum states and operators.
def tensor(*args) -> Qobj: ...
def ptrace(obj: Qobj, sel) -> Qobj: ...
def expect(oper: Qobj, state: Qobj) -> float: ...
def variance(oper: Qobj, state: Qobj) -> float: ...
def composite(*args) -> Qobj: ...
def tensor_swap(obj: Qobj, mask) -> Qobj: ...Quantum gate operations for quantum computing applications including single-qubit, two-qubit, and multi-qubit gates.
def rx(phi: float, N: int = None) -> Qobj: ...
def ry(phi: float, N: int = None) -> Qobj: ...
def rz(phi: float, N: int = None) -> Qobj: ...
def cnot(N: int = None, control: int = 0, target: int = 1) -> Qobj: ...
def hadamard_transform(N: int = 1) -> Qobj: ...
def toffoli(N: int = None, controls: list = [0, 1], target: int = 2) -> Qobj: ...
def qft(N: int, swap: bool = True) -> Qobj: ...Superoperator representations for open quantum system dynamics and Liouvillian formalism.
def liouvillian(H: Qobj, c_ops: list = None) -> Qobj: ...
def lindblad_dissipator(a: Qobj, b: Qobj = None) -> Qobj: ...
def spre(A: Qobj) -> Qobj: ...
def spost(A: Qobj) -> Qobj: ...
def sprepost(A: Qobj, B: Qobj) -> Qobj: ...
def operator_to_vector(op: Qobj) -> Qobj: ...
def vector_to_operator(vec: Qobj) -> Qobj: ...Comprehensive visualization tools for quantum states, processes, and dynamics including Bloch sphere, Wigner functions, and matrix representations.
class Bloch:
def __init__(self, fig=None, axes=None, view=None, figsize=None, background=False): ...
def add_states(self, state, kind='vector'): ...
def add_vectors(self, list_of_vectors): ...
def render(self, title=''): ...
def show(self): ...
def hinton(rho: Qobj, xlabels=None, ylabels=None, title=None, ax=None) -> None: ...
def plot_wigner(rho: Qobj, xvec=None, yvec=None, method='clenshaw', projection='2d') -> tuple: ...
def matrix_histogram(M: Qobj, xlabels=None, ylabels=None, title=None, limits=None, ax=None) -> None: ...Tools for quantum information processing including entropy measures, entanglement quantification, and quantum correlations.
def entropy_vn(rho: Qobj, base: float = np.e, sparse: bool = False) -> float: ...
def entropy_mutual(rho: Qobj, selA: list, selB: list, base: float = np.e, sparse: bool = False) -> float: ...
def concurrence(rho: Qobj) -> float: ...
def negativity(rho: Qobj, mask) -> float: ...
def entangling_power(U: Qobj, targets: list = None) -> float: ...
def quantum_relative_entropy(rho: Qobj, sigma: Qobj, base: float = np.e, sparse: bool = False) -> float: ...Generation of random quantum objects for testing, benchmarking, and quantum algorithm development.
def rand_herm(N: int, density: float = 0.75, dims: list = None) -> Qobj: ...
def rand_unitary(N: int, density: float = 0.75, dims: list = None) -> Qobj: ...
def rand_dm(N: int, density: float = 0.75, dims: list = None) -> Qobj: ...
def rand_ket(N: int, density: float = 1, dims: list = None) -> Qobj: ...
def rand_kraus_map(N: int, dims: list = None) -> list: ...Phase space representations and quasi-probability distributions for continuous variable quantum systems.
def wigner(rho: Qobj, xvec: ArrayLike, yvec: ArrayLike, g: float = np.sqrt(2)) -> np.ndarray: ...
def qfunc(rho: Qobj, xvec: ArrayLike, yvec: ArrayLike, g: float = np.sqrt(2)) -> np.ndarray: ...
def spin_wigner(rho: Qobj, theta: ArrayLike, phi: ArrayLike) -> np.ndarray: ...
def spin_q_function(rho: Qobj, theta: ArrayLike, phi: ArrayLike) -> np.ndarray: ...Quantum process tomography tools for characterizing quantum operations and noise processes.
def qpt(U: Qobj, op_basis: list = None) -> Qobj: ...
def qpt_plot(chi: Qobj, lbls_list: list = None, title: str = None, fig: object = None, threshold: float = None) -> None: ...
def qpt_plot_combined(chi: Qobj, lbls_list: list = None, title: str = None, fig: object = None, threshold: float = 0.01) -> None: ...Data persistence, file operations, and utility functions for QuTiP objects and calculations.
def qsave(obj, name: str, format: str = 'pickle') -> None: ...
def qload(name: str, format: str = 'pickle') -> object: ...
def about() -> None: ...
def cite() -> str: ...
def n_thermal(w: float, w_th: float) -> float: ...
def clebsch(j1: float, j2: float, j3: float, m1: float, m2: float, m3: float) -> float: ...class Qobj:
"""
Quantum object class representing quantum states, operators, and superoperators.
Attributes:
data: Underlying sparse or dense matrix data
dims: List representing the tensor structure dimensions
shape: Tuple of matrix dimensions
type: String indicating 'ket', 'bra', 'oper', or 'super'
isherm: Boolean indicating if operator is Hermitian
isunitary: Boolean indicating if operator is unitary
"""
class Result:
"""
Result object for time evolution solvers.
Attributes:
solver: String name of solver used
times: Array of time points
states: List of quantum states at each time
expect: List of expectation values (if e_ops provided)
num_expect: Number of expectation operators
num_collapse: Number of collapse events (Monte Carlo)
"""
class McResult(Result):
"""
Monte Carlo result object with trajectory information.
Additional Attributes:
ntraj: Number of trajectories computed
col_times: Collapse times for each trajectory
col_which: Which collapse operator caused each collapse
"""