def test_compare_solvers_steadystate():
    """
    correlation: comparing me and es for oscillator in steady-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()]

    taulist = np.linspace(0, 5.0, 100)
    with warnings.catch_warnings():
        warnings.simplefilter("ignore")
        corr1 = correlation_2op_1t(H,
                                   None,
                                   taulist,
                                   c_ops,
                                   a.dag(),
                                   a,
                                   solver="me")
        corr2 = correlation_2op_1t(H,
                                   None,
                                   taulist,
                                   c_ops,
                                   a.dag(),
                                   a,
                                   solver="es")

    assert_(max(abs(corr1 - corr2)) < 1e-4)
Example #2
0
def test_correlation_2op_1t_known_cases(solver,
                                        state,
                                        is_e_op_hermitian,
                                        w,
                                        gamma,
                                       ):
    """This test compares the output correlation_2op_1 solution to an analytical
    solution."""

    a = qutip.destroy(_equivalence_dimension)
    x = (a + a.dag())/np.sqrt(2)

    H = w * a.dag() * a

    a_op = x if is_e_op_hermitian else a
    b_op = x if is_e_op_hermitian else a.dag()
    c_ops = [np.sqrt(gamma) * a]

    times = np.linspace(0, 1, 30)

    # Handle the case state==None when computing expt values
    rho0 = state if state else qutip.steadystate(H, c_ops)
    if is_e_op_hermitian:
        # Analitycal solution for x,x as operators.
        base = 0
        base += qutip.expect(a*x, rho0)*np.exp(-1j*w*times - gamma*times/2)
        base += qutip.expect(a.dag()*x, rho0)*np.exp(1j*w*times - gamma*times/2)
        base /= np.sqrt(2)
    else:
        # Analitycal solution for a,adag as operators.
        base = qutip.expect(a*a.dag(), rho0)*np.exp(-1j*w*times - gamma*times/2)

    cmp = qutip.correlation_2op_1t(H, state, times, c_ops, a_op, b_op, solver=solver)

    np.testing.assert_allclose(base, cmp, atol=0.25 if solver == 'mc' else 2e-5)
Example #3
0
def test_compare_solvers_steadystate():
    """
    correlation: comparing me and es for oscillator in steady-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()]

    taulist = np.linspace(0, 5.0, 100)
    with warnings.catch_warnings():
        warnings.simplefilter("ignore")
        corr1 = correlation_2op_1t(H, None, taulist, c_ops, a.dag(), a,
                                   solver="me")
        corr2 = correlation_2op_1t(H, None, taulist, c_ops, a.dag(), a,
                                   solver="es")

    assert_(max(abs(corr1 - corr2)) < 1e-4)
Example #4
0
import numpy as np
import matplotlib.pyplot as plt
import qutip

times = np.linspace(0, 10, 200)
a = qutip.destroy(10)
x = a.dag() + a
H = a.dag() * a

corr1 = qutip.correlation_2op_1t(H, None, times, [np.sqrt(0.5) * a], x, x)
corr2 = qutip.correlation_2op_1t(H, None, times, [np.sqrt(1.0) * a], x, x)
corr3 = qutip.correlation_2op_1t(H, None, times, [np.sqrt(2.0) * a], x, x)

plt.plot(times, np.real(corr1), times, np.real(corr2), times, np.real(corr3))
plt.xlabel(r'Time $t$')
plt.ylabel(r'Correlation $\left<x(t)x(0)\right>$')
plt.show()