Mesolve is QuTiP's main solver for the master equation. Given a Hamiltonian, collapse operators, initial state, and time points, it integrates the Lindblad equation and returns the state or expectation values at each time.
Mesolve uses adaptive ODE solvers (IDA, dopri5) for efficiency and accuracy. It handles large systems (up to hundreds of qubits for classical simulation) and time-dependent Hamiltonians.
from qutip import * import numpy as np # Damped qubit H = 0.5 * sigmaz() gamma = 0.1 c_ops = [np.sqrt(gamma) * sigmam()] # Time points times = np.linspace(0, 20, 100) # Initial state psi0 = basis(2, 1) # Excited state # Solve result = mesolve(H, psi0, times, c_ops, [sigmaz()]) # Access results print(result.expect[0]) # <σ_z>(t) print(result.states) # ρ(t) at each time print(result.times) # Time points (may differ from input)
For time-dependent systems, pass a list of [H0, [H1, f1], [H2, f2], ...] where f_i(t) is a coefficient function:
# Rabi drive: H(t) = 0.5*σ_z + Ω(t)*σ_x def rabi_pulse(t, args): return np.exp(-(t - 5)**2 / 2) # Gaussian pulse H = [0.5 * sigmaz(), [sigmax(), rabi_pulse]] result = mesolve(H, psi0, times, c_ops, [sigmaz()])
result.expect contains expectation valuesoptions=Options(store_states=True) to get result.statesresult.solver contains solver informationMesolve is the workhorse for simulating realistic quantum systems with decay and noise.