def test_mcf90_dtypes2(): "mcsolve_f90: check for correct dtypes (average_states=False)" # set system parameters kappa = 2.0 # mirror coupling gamma = 0.2 # spontaneous emission rate g = 1 # atom/cavity coupling strength wc = 0 # cavity frequency w0 = 0 # atom frequency wl = 0 # driving frequency E = 0.5 # driving amplitude N = 5 # number of cavity energy levels (0->3 Fock states) tlist = np.linspace(0, 10, 5) # times for expectation values # construct Hamiltonian ida = qeye(N) idatom = qeye(2) a = tensor(destroy(N), idatom) sm = tensor(ida, sigmam()) H = (w0 - wl) * sm.dag() * sm + (wc - wl) * a.dag() * a + \ 1j * g * (a.dag() * sm - sm.dag() * a) + E * (a.dag() + a) # collapse operators C1 = np.sqrt(2 * kappa) * a C2 = np.sqrt(gamma) * sm C1dC1 = C1.dag() * C1 C2dC2 = C2.dag() * C2 # intial state psi0 = tensor(basis(N, 0), basis(2, 1)) opts = Options(average_expect=False) data = mcsolve_f90( H, psi0, tlist, [C1, C2], [C1dC1, C2dC2, a], ntraj=5, options=opts) assert_equal(isinstance(data.expect[0][0][1], float), True) assert_equal(isinstance(data.expect[0][1][1], float), True) assert_equal(isinstance(data.expect[0][2][1], complex), True)
def test_MCNoCollExpt(): "mcsolve_f90: Constant H with no collapse ops (expect)" error = 1e-8 N = 10 # number of basis states to consider a = destroy(N) H = a.dag() * a psi0 = basis(N, 9) # initial state c_op_list = [] tlist = np.linspace(0, 10, 100) mcdata = mcsolve_f90(H, psi0, tlist, c_op_list, [a.dag() * a]) expt = mcdata.expect[0] actual_answer = 9.0 * np.ones(len(tlist)) diff = np.mean(abs(actual_answer - expt) / actual_answer) assert_equal(diff < error, True)
def test_MCSimpleSingleExpect(): """mcsolve_f90: Constant H with single expect operator""" N = 10 # number of basis states to consider a = destroy(N) H = a.dag() * a psi0 = basis(N, 9) # initial state kappa = 0.2 # coupling to oscillator c_op_list = [np.sqrt(kappa) * a] tlist = np.linspace(0, 10, 100) mcdata = mcsolve_f90(H, psi0, tlist, c_op_list, [a.dag() * a]) expt = mcdata.expect[0] actual_answer = 9.0 * np.exp(-kappa * tlist) avg_diff = np.mean(abs(actual_answer - expt) / actual_answer) assert_equal(avg_diff < mc_error, True)