Qubit Decay with mesolveΒΆ
This tutorial builds the smallest open quantum system in OpenQuantumSim: a two-level atom with spontaneous emission. It compares the excited-state population against the analytic result \(P_e(t)=e^{-\gamma t}\).
import numpy as np
import openquantumsim as oqs
gamma = 0.35
atom = oqs.SpinSpace(0.5, label="atom")
H = 0.0 * oqs.sigmaz(atom)
collapse = np.sqrt(gamma) * oqs.sigmam(atom)
excited = oqs.basis(atom, "up")
rho0 = oqs.ket2dm(excited)
P_excited = oqs.Operator(oqs.ket2dm(excited), atom, "P_excited")
times = np.linspace(0.0, 6.0, 61)
mesolve uses the Julia backend. Run python setup_julia.py once before executing this notebook locally.
result = oqs.mesolve(
H,
rho0,
times,
c_ops=[collapse],
e_ops=[P_excited],
options=oqs.Options(rtol=1e-9, atol=1e-11),
)
analytic = np.exp(-gamma * times)
np.max(np.abs(result.expect[0].real - analytic))
ax = oqs.expect_plot(times, result.expect[0], label="OpenQuantumSim")
ax.plot(times, analytic, "--", label="analytic")
ax.legend()