def testCoherentDensityMatrix(self): """ states: coherent density matrix """ N = 10 rho = coherent_dm(N, 1) # make sure rho has trace close to 1.0 assert_(abs(rho.tr() - 1.0) < 1e-12)
def test_driven_cavity_power_bicgstab(): "Steady state: Driven cavity - power-bicgstab solver" N = 30 Omega = 0.01 * 2 * np.pi Gamma = 0.05 a = destroy(N) H = Omega * (a.dag() + a) c_ops = [np.sqrt(Gamma) * a] M = build_preconditioner(H, c_ops, method='power') rho_ss = steadystate(H, c_ops, method='power-bicgstab', M=M, use_precond=1) rho_ss_analytic = coherent_dm(N, -1.0j * (Omega)/(Gamma/2)) assert_((rho_ss - rho_ss_analytic).norm() < 1e-4)
def test_driven_cavity_lgmres(): "Steady state: Driven cavity - iterative-lgmres solver" N = 30 Omega = 0.01 * 2 * np.pi Gamma = 0.05 a = destroy(N) H = Omega * (a.dag() + a) c_ops = [np.sqrt(Gamma) * a] rho_ss = steadystate(H, c_ops, method='iterative-lgmres') rho_ss_analytic = coherent_dm(N, -1.0j * (Omega)/(Gamma/2)) assert_((rho_ss - rho_ss_analytic).norm() < 1e-4)
def test_driven_cavity_lgmres(): "Steady state: Driven cavity - iterative-lgmres solver" N = 30 Omega = 0.01 * 2 * np.pi Gamma = 0.05 a = destroy(N) H = Omega * (a.dag() + a) c_ops = [np.sqrt(Gamma) * a] rho_ss = steadystate(H, c_ops, method='iterative-lgmres') rho_ss_analytic = coherent_dm(N, -1.0j * (Omega) / (Gamma / 2)) assert_((rho_ss - rho_ss_analytic).norm() < 1e-4)
def compute_item(self, name, model): name += "_1" fock_dim = self.editor.fock_dim.value() timestep = self.editor.timestep.value() initial_alpha = self.editor.initial_alpha.value() steps = model.get_steps(fock_dim, timestep) res0 = coherent_dm(fock_dim, initial_alpha) qubit0 = ket2dm((basis(2, 0) + basis(2, 1)) / np.sqrt(2)) psi0 = tensor(qubit0, res0) def add_to_viewer(r): item = WignerPlotter(name, r) item.wigners_complete.connect(lambda: self.viewer.add_item(item)) win.statusBar().showMessage("Computing Wigners") args = (steps, fock_dim, psi0, timestep) run_in_process(to_state_list, add_to_viewer, args) #self.thread_is_running.emit() win.statusBar().showMessage("Computing States")
def test_compare_solvers_coherent_state_mees(): """ correlation: comparing me and es for oscillator in coherent initial state """ N = 20 a = destroy(N) H = a.dag() * a G1 = 0.75 n_th = 2.00 c_ops = [np.sqrt(G1 * (1 + n_th)) * a, np.sqrt(G1 * n_th) * a.dag()] rho0 = coherent_dm(N, np.sqrt(4.0)) taulist = np.linspace(0, 5.0, 100) corr1 = correlation_2op_2t(H, rho0, None, taulist, c_ops, a.dag(), a, solver="me") corr2 = correlation_2op_2t(H, rho0, None, taulist, c_ops, a.dag(), a, solver="es") assert_(max(abs(corr1 - corr2)) < 1e-4)
def test_compare_solvers_coherent_state_legacy(): """ correlation: legacy me and es for oscillator in coherent initial state """ N = 20 a = destroy(N) H = a.dag() * a G1 = 0.75 n_th = 2.00 c_ops = [np.sqrt(G1 * (1 + n_th)) * a, np.sqrt(G1 * n_th) * a.dag()] rho0 = coherent_dm(N, np.sqrt(4.0)) taulist = np.linspace(0, 5.0, 100) with warnings.catch_warnings(): warnings.simplefilter("ignore") corr1 = correlation(H, rho0, None, taulist, c_ops, a.dag(), a, solver="me") corr2 = correlation(H, rho0, None, taulist, c_ops, a.dag(), a, solver="es") assert_(max(abs(corr1 - corr2)) < 1e-4)
def test_coherentdm_type(): "State CSR Type: coherent_dm" st = coherent_dm(25,2+2j) assert_equal(isspmatrix_csr(st.data), True)
import numpy as np import matplotlib.pyplot as plt import qutip N = 25 taus = np.linspace(0, 25.0, 200) a = qutip.destroy(N) H = 2 * np.pi * a.dag() * a kappa = 0.25 n_th = 2.0 # bath temperature in terms of excitation number c_ops = [np.sqrt(kappa * (1 + n_th)) * a, np.sqrt(kappa * n_th) * a.dag()] states = [ {'state': qutip.coherent_dm(N, np.sqrt(2)), 'label': "coherent state"}, {'state': qutip.thermal_dm(N, 2), 'label': "thermal state"}, {'state': qutip.fock_dm(N, 2), 'label': "Fock state"}, ] fig, ax = plt.subplots(1, 1) for state in states: rho0 = state['state'] # first calculate the occupation number as a function of time n = qutip.mesolve(H, rho0, taus, c_ops, [a.dag() * a]).expect[0] # calculate the correlation function G2 and normalize with n(0)n(t) to # obtain g2 G2 = qutip.correlation_3op_1t(H, rho0, taus, c_ops, a.dag(), a.dag()*a, a) g2 = G2 / (n[0] * n)