Copyright (C) 2011 and later, Paul D. Nation & Robert J. Johansson
import matplotlib.pyplot as plt
import numpy as np
from matplotlib import rcParams
from qutip import (Options, about, destroy, fock, identity, mesolve,
parallel_map, photocurrent_mesolve, tensor)
%matplotlib inline
rcParams["font.family"] = "STIXGeneral"
rcParams["mathtext.fontset"] = "stix"
rcParams["font.size"] = "14"
N = 15
w0 = 1.0 * 2 * np.pi
g = 0.2 * 2 * np.pi
times = np.linspace(0, 15, 150)
dt = times[1] - times[0]
gamma = 0.01
kappa = 0.1
ntraj = 150
a = tensor(destroy(N), identity(2))
sm = tensor(identity(N), destroy(2))
H = w0 * a.dag() * a + w0 * sm.dag() * sm + g * (sm * a.dag() + sm.dag() * a)
rho0 = tensor(fock(N, 5), fock(2, 0))
e_ops = [a.dag() * a, a + a.dag(), sm.dag() * sm]
c_ops = [np.sqrt(gamma) * sm] # collapse operator for qubit
sc_ops = [np.sqrt(kappa) * a] # stochastic collapse for resonator
result_ref = mesolve(H, rho0, times, c_ops + sc_ops, e_ops)
result1 = photocurrent_mesolve(
H,
rho0,
times,
c_ops=c_ops,
sc_ops=sc_ops,
e_ops=e_ops,
ntraj=1,
nsubsteps=100,
store_measurement=True,
options=Options(store_states=True),
)
Total run time: 0.35s
Run the smesolve
solver in parallel by passing the keyword argument map_func=parallel_map
:
result2 = photocurrent_mesolve(
H,
rho0,
times,
c_ops=c_ops,
sc_ops=sc_ops,
e_ops=e_ops,
ntraj=ntraj,
nsubsteps=100,
store_measurement=True,
options=Options(store_states=True),
map_func=parallel_map,
)
10.0%. Run time: 3.00s. Est. time left: 00:00:00:27 20.0%. Run time: 5.67s. Est. time left: 00:00:00:22 30.0%. Run time: 8.92s. Est. time left: 00:00:00:20 40.0%. Run time: 11.65s. Est. time left: 00:00:00:17 50.0%. Run time: 14.50s. Est. time left: 00:00:00:14 60.0%. Run time: 17.30s. Est. time left: 00:00:00:11 70.0%. Run time: 20.07s. Est. time left: 00:00:00:08 80.0%. Run time: 22.98s. Est. time left: 00:00:00:05 90.0%. Run time: 25.74s. Est. time left: 00:00:00:02 100.0%. Run time: 28.60s. Est. time left: 00:00:00:00 Total run time: 28.61s
fig, axes = plt.subplots(2, 3, figsize=(16, 8), sharex=True)
axes[0, 0].plot(times,
result1.expect[0], label=r"Stochastic ME (ntraj = 1)", lw=2)
axes[0, 0].plot(times, result_ref.expect[0], label=r"Lindblad ME", lw=2)
axes[0, 0].set_title("Cavity photon number (ntraj = 1)")
axes[0, 0].legend()
axes[1, 0].plot(
times, result2.expect[0], label=r"Stochatic ME (ntraj = %d)" % ntraj, lw=2
)
axes[1, 0].plot(times, result_ref.expect[0], label=r"Lindblad ME", lw=2)
axes[1, 0].set_title("Cavity photon number (ntraj = 10)")
axes[1, 0].legend()
axes[0, 1].plot(times,
result1.expect[2], label=r"Stochastic ME (ntraj = 1)", lw=2)
axes[0, 1].plot(times, result_ref.expect[2], label=r"Lindblad ME", lw=2)
axes[0, 1].set_title("Qubit excition probability (ntraj = 1)")
axes[0, 1].legend()
axes[1, 1].plot(
times, result2.expect[2], label=r"Stochatic ME (ntraj = %d)" % ntraj, lw=2
)
axes[1, 1].plot(times, result_ref.expect[2], label=r"Lindblad ME", lw=2)
axes[1, 1].set_title("Qubit excition probability (ntraj = %d)" % ntraj)
axes[1, 1].legend()
axes[0, 2].step(times, dt * np.cumsum(result1.measurement[0].real), lw=2)
axes[0, 2].set_title("Cummulative photon detections (ntraj = 1)")
axes[1, 2].step(
times,
dt * np.cumsum(np.array(result2.measurement).sum(axis=0).real) / ntraj,
lw=2
)
axes[1, 2].set_title("Cummulative avg. photon detections (ntraj = %d)" % ntraj)
fig.tight_layout()
about()
QuTiP: Quantum Toolbox in Python ================================ Copyright (c) QuTiP team 2011 and later. Current admin team: Alexander Pitchford, Nathan Shammah, Shahnawaz Ahmed, Neill Lambert, Eric Giguère, Boxi Li, Jake Lishman, Simon Cross and Asier Galicia. Board members: Daniel Burgarth, Robert Johansson, Anton F. Kockum, Franco Nori and Will Zeng. Original developers: R. J. Johansson & P. D. Nation. Previous lead developers: Chris Granade & A. Grimsmo. Currently developed through wide collaboration. See https://github.com/qutip for details. QuTiP Version: 4.7.1 Numpy Version: 1.22.4 Scipy Version: 1.8.1 Cython Version: 0.29.33 Matplotlib Version: 3.5.2 Python Version: 3.10.4 Number of CPUs: 2 BLAS Info: Generic OPENMP Installed: False INTEL MKL Ext: False Platform Info: Linux (x86_64) Installation path: /home/runner/work/qutip-tutorials/qutip-tutorials/qutip/qutip ================================================================================ Please cite QuTiP in your publication. ================================================================================ For your convenience a bibtex reference can be easily generated using `qutip.cite()`