def test_compare_solvers_coherent_state_memc():
    """
    correlation: comparing me and mc for driven oscillator in fock state
    """

    N = 2
    a = destroy(N)
    H = a.dag() * a + a + a.dag()
    G1 = 0.75
    n_th = 2.00
    c_ops = [np.sqrt(G1 * (1 + n_th)) * a, np.sqrt(G1 * n_th) * a.dag()]
    psi0 = fock(N, 1)

    taulist = np.linspace(0, 1.0, 3)
    corr1 = correlation_2op_2t(H,
                               psi0, [0, 0.5],
                               taulist,
                               c_ops,
                               a.dag(),
                               a,
                               solver="me")
    corr2 = correlation_2op_2t(H,
                               psi0, [0, 0.5],
                               taulist,
                               c_ops,
                               a.dag(),
                               a,
                               solver="mc")

    # pretty lax criterion, but would otherwise require a quite long simulation
    # time
    assert_(abs(corr1 - corr2).max() < 0.25)
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)
Beispiel #3
0
def test_fn_list_td_corr2():
    """
    correlation: multi time-dependent factor
    """
    # test for bug of issue #1048
    sm = destroy(2)
    args = {}

    def step_func(t, args={}):
        return np.arctan(t - 2) / np.pi + 0.5

    def inv_step_func(t, args={}):
        return np.arctan(-(t - 2)) / np.pi + 0.5

    H1 = [[(sm + sm.dag()), step_func], [qeye(2), inv_step_func]]

    H2 = [[qeye(2), inv_step_func], [(sm + sm.dag()), step_func]]

    tlist = np.linspace(0, 5, 6)
    corr1 = correlation_2op_2t(H1,
                               fock(2, 0),
                               tlist,
                               tlist, [sm],
                               sm.dag(),
                               sm,
                               args=args)
    corr2 = correlation_2op_2t(H2,
                               fock(2, 0),
                               tlist,
                               tlist, [sm],
                               sm.dag(),
                               sm,
                               args=args)
    assert_(np.sum(np.abs(corr1 - corr2)) < 1e-5)
Beispiel #4
0
def test_compare_solvers_coherent_state_memc():
    """
    correlation: comparing me and mc for driven oscillator in ground state
    """

    N = 20
    a = destroy(N)
    H = a.dag() * a + a + a.dag()
    G1 = 0.75
    n_th = 2.00
    c_ops = [np.sqrt(G1 * (1 + n_th)) * a, np.sqrt(G1 * n_th) * a.dag()]
    psi0 = fock(N, 0)

    taulist = np.linspace(0, 1.0, 5)
    corr1 = correlation_2op_2t(H,
                               psi0, [0],
                               taulist,
                               c_ops,
                               a.dag(),
                               a,
                               solver="me")[0]
    corr2 = correlation_2op_2t(H,
                               psi0, [0],
                               taulist,
                               c_ops,
                               a.dag(),
                               a,
                               solver="mc")[0]

    assert_(max(abs(corr1 - corr2)) < 5e-2)
def test_c_ops_fn_list_td_corr():
    """
    correlation: comparing 3LS emission corr., c_ops td (fn-list td format)
    """

    # calculate zero-delay HOM cross-correlation, for incoherently pumped
    # 3LS ladder system g2ab[0]
    # with following parameters:
    #   gamma = 1, 99% initialized, tp = 0.5
    # Then: g2ab(0)~0.185
    tlist = np.linspace(0, 6, 20)
    ket0 = fock(3, 0)
    ket1 = fock(3, 1)
    ket2 = fock(3, 2)
    sm01 = ket0 * ket1.dag()
    sm12 = ket1 * ket2.dag()
    psi0 = fock(3, 2)

    tp = 1
    # define "pi" pulse as when 99% of population has been transferred
    Om = np.sqrt(-np.log(1e-2) / (tp * np.sqrt(np.pi)))
    c_ops = [
        sm01,
        [
            sm12 * Om, lambda t, args: np.exp(-(t - args["t_off"])**2 /
                                              (2 * args["tp"]**2))
        ]
    ]
    args = {"tp": tp, "t_off": 2}
    H = qeye(3) * 0
    # HOM cross-correlation depends on coherences (g2[0]=0)
    c1 = correlation_2op_2t(H,
                            psi0,
                            tlist,
                            tlist,
                            c_ops,
                            sm01.dag(),
                            sm01,
                            args=args)
    c2 = correlation_2op_2t(H,
                            psi0,
                            tlist,
                            tlist,
                            c_ops,
                            sm01.dag(),
                            sm01,
                            args=args,
                            reverse=True)
    n = mesolve(H, psi0, tlist, c_ops, [sm01.dag() * sm01],
                args=args).expect[0]
    n_f = Cubic_Spline(tlist[0], tlist[-1], n)
    corr_ab = -c1 * c2 + np.array([[n_f(t) * n_f(t + tau) for tau in tlist]
                                   for t in tlist])
    dt = tlist[1] - tlist[0]
    gab = abs(np.trapz(np.trapz(corr_ab, axis=0))) * dt**2

    assert_(abs(gab - 0.185) < 1e-2)
Beispiel #6
0
def test_hamiltonian_order_unimportant():
    # Testing for regression on issue 1048.
    sp = qutip.sigmap()
    H = [[qutip.sigmax(), lambda t, _: _step(t-2)],
         [qutip.qeye(2), lambda t, _: _step(-(t-2))]]
    start = qutip.basis(2, 0)
    times = np.linspace(0, 5, 6)
    forwards = qutip.correlation_2op_2t(H, start, times, times, [sp],
                                        sp.dag(), sp)
    backwards = qutip.correlation_2op_2t(H[::-1], start, times, times, [sp],
                                         sp.dag(), sp)
    np.testing.assert_allclose(forwards, backwards, atol=1e-6)
def test_c_ops_fn_list_td_corr():
    """
    correlation: comparing 3LS emission corr., c_ops td (fn-list td format)
    """

    # calculate zero-delay HOM cross-correlation, for incoherently pumped
    # 3LS ladder system g2ab[0]
    # with following parameters:
    #   gamma = 1, 99% initialized, tp = 0.5
    # Then: g2ab(0)~0.185
    tlist = np.linspace(0, 6, 20)
    ket0 = fock(3, 0)
    ket1 = fock(3, 1)
    ket2 = fock(3, 2)
    sm01 = ket0 * ket1.dag()
    sm12 = ket1 * ket2.dag()
    psi0 = fock(3, 2)

    tp = 1
    # define "pi" pulse as when 99% of population has been transferred
    Om = np.sqrt(-np.log(1e-2) / (tp * np.sqrt(np.pi)))
    c_ops = [sm01,
             [sm12 * Om,
              lambda t, args:
                    np.exp(-(t - args["t_off"]) ** 2 / (2 * args["tp"] ** 2))]]
    args = {"tp": tp, "t_off": 2}
    H = qeye(3) * 0
    # HOM cross-correlation depends on coherences (g2[0]=0)
    c1 = correlation_2op_2t(H, psi0, tlist, tlist, c_ops,
                            sm01.dag(), sm01, args=args)
    c2 = correlation_2op_2t(H, psi0, tlist, tlist, c_ops,
                            sm01.dag(), sm01, args=args, reverse=True)
    n = mesolve(
        H, psi0, tlist, c_ops, [sm01.dag() * sm01], args=args
    ).expect[0]
    n_f = Cubic_Spline(tlist[0], tlist[-1], n)
    corr_ab = - c1 * c2 + np.array(
        [[n_f(t) * n_f(t + tau) for tau in tlist]
         for t in tlist])
    dt = tlist[1] - tlist[0]
    gab = abs(np.trapz(np.trapz(corr_ab, axis=0))) * dt ** 2

    assert_(abs(gab - 0.185) < 1e-2)
Beispiel #8
0
def test_compare_solvers_coherent_state_memc():
    """
    correlation: comparing me and mc for driven oscillator in ground state
    """

    N = 20
    a = destroy(N)
    H = a.dag() * a + a + a.dag()
    G1 = 0.75
    n_th = 2.00
    c_ops = [np.sqrt(G1 * (1 + n_th)) * a, np.sqrt(G1 * n_th) * a.dag()]
    psi0 = fock(N, 0)

    taulist = np.linspace(0, 1.0, 5)
    corr1 = correlation_2op_2t(H, psi0, [0], taulist, c_ops, a.dag(), a,
                               solver="me")[0]
    corr2 = correlation_2op_2t(H, psi0, [0], taulist, c_ops, a.dag(), a,
                               solver="mc")[0]

    assert_(max(abs(corr1 - corr2)) < 5e-2)
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)
Beispiel #10
0
def test_np_str_list_td_corr():
    """
    correlation: comparing 3LS emission corr., c_ops td (np-list td format)
    """

    # calculate zero-delay HOM cross-correlation, for incoherently pumped
    # 3LS ladder system g2ab[0]
    # with following parameters:
    #   gamma = 1, 99% initialized, tp = 0.5
    # Then: g2ab(0)~0.185
    tlist = np.linspace(0, 6, 20)
    ket0 = fock(3, 0)
    ket1 = fock(3, 1)
    ket2 = fock(3, 2)
    sm01 = ket0 * ket1.dag()
    sm12 = ket1 * ket2.dag()
    psi0 = fock(3, 2)

    tp = 1
    t_off = 2
    # define "pi" pulse as when 99% of population has been transferred
    Om = np.sqrt(-np.log(1e-2) / (tp * np.sqrt(np.pi)))
    c_ops = [sm01,
             [sm12 * Om, np.exp(-(tlist - t_off) ** 2 / (2 * tp ** 2))]]
    H = qeye(3) * 0
    # HOM cross-correlation depends on coherences (g2[0]=0)
    c1 = correlation_2op_2t(H, psi0, tlist, tlist, c_ops,
                            sm01.dag(), sm01)
    c2 = correlation_2op_2t(H, psi0, tlist, tlist, c_ops,
                            sm01.dag(), sm01, reverse=True)
    n = mesolve(
        H, psi0, tlist, c_ops, sm01.dag() * sm01
    ).expect[0]
    n_f = interp1d(tlist, n, kind="cubic", fill_value=0, bounds_error=False)
    corr_ab = - c1 * c2 + np.array(
        [[n_f(t) * n_f(t + tau) for tau in tlist]
         for t in tlist])
    dt = tlist[1] - tlist[0]
    gab = abs(np.trapz(np.trapz(corr_ab, axis=0))) * dt ** 2

    assert_(abs(gab - 0.185) < 1e-2)
Beispiel #11
0
 def test_coefficient_c_ops_3ls(self, dependence_3ls):
     # Calculate zero-delay HOM cross-correlation for incoherently pumped
     # three-level system, g2_ab[0] with gamma = 1.
     dimension = 3
     H = qutip.qzero(dimension)
     start = qutip.basis(dimension, 2)
     times = _3ls_times
     project_0_1 = qutip.projection(dimension, 0, 1)
     project_1_2 = qutip.projection(dimension, 1, 2)
     population_1 = qutip.projection(dimension, 1, 1)
     # Define the pi pulse to be when 99% of the population is transferred.
     rabi = np.sqrt(-np.log(0.01) / (_3ls_args['tp'] * np.sqrt(np.pi)))
     c_ops = [project_0_1, [rabi * project_1_2, dependence_3ls]]
     forwards = qutip.correlation_2op_2t(H,
                                         start,
                                         times,
                                         times,
                                         c_ops,
                                         project_0_1.dag(),
                                         project_0_1,
                                         args=_3ls_args)
     backwards = qutip.correlation_2op_2t(H,
                                          start,
                                          times,
                                          times,
                                          c_ops,
                                          project_0_1.dag(),
                                          project_0_1,
                                          args=_3ls_args,
                                          reverse=True)
     n_expect = qutip.mesolve(H,
                              start,
                              times,
                              c_ops,
                              args=_3ls_args,
                              e_ops=[population_1]).expect[0]
     correlation_ab = -forwards * backwards + _n_correlation(
         times, n_expect)
     g2_ab_0 = _trapz_2d(np.real(correlation_ab), times)
     assert abs(g2_ab_0 - 0.185) < 1e-2
def test_compare_solvers_coherent_state_memc():
    """
    correlation: comparing me and mc for driven oscillator in fock state
    """

    N = 2
    a = destroy(N)
    H = a.dag() * a + a + a.dag()
    G1 = 0.75
    n_th = 2.00
    c_ops = [np.sqrt(G1 * (1 + n_th)) * a, np.sqrt(G1 * n_th) * a.dag()]
    psi0 = fock(N, 1)

    taulist = np.linspace(0, 1.0, 3)
    corr1 = correlation_2op_2t(H, psi0, [0, 0.5], taulist, c_ops, a.dag(), a,
                               solver="me")
    corr2 = correlation_2op_2t(H, psi0, [0, 0.5], taulist, c_ops, a.dag(), a,
                               solver="mc")

    # pretty lax criterion, but would otherwise require a quite long simulation
    # time
    assert_(abs(corr1 - corr2).max() < 0.2)
Beispiel #13
0
N = 15
taus = np.linspace(0, 10.0, 200)
a = qutip.destroy(N)
H = 2 * np.pi * a.dag() * a

# collapse operator
G1 = 0.75
n_th = 2.00  # bath temperature in terms of excitation number
c_ops = [np.sqrt(G1 * (1 + n_th)) * a, np.sqrt(G1 * n_th) * a.dag()]

# start with a coherent state
rho0 = qutip.coherent_dm(N, 2.0)

# 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 G1 and normalize with n to obtain g1
G1 = qutip.correlation_2op_2t(H, rho0, None, taus, c_ops, a.dag(), a)
g1 = G1 / np.sqrt(n[0] * n)

plt.plot(taus, np.real(g1), 'b', lw=2)
plt.plot(taus, n, 'r', lw=2)
plt.title('Decay of a coherent state to an incoherent (thermal) state')
plt.xlabel(r'$\tau$')
plt.legend([
    r'First-order coherence function $g^{(1)}(\tau)$',
    r'Occupation number $n(\tau)$',
])
plt.show()
Beispiel #14
0
import numpy as np
import matplotlib.pyplot as plt
import qutip

times = np.linspace(0, 10.0, 200)
a = qutip.destroy(10)
x = a.dag() + a
H = a.dag() * a
alpha = 2.5
rho0 = qutip.coherent_dm(10, alpha)
corr = qutip.correlation_2op_2t(H, rho0, times, times, [np.sqrt(0.25) * a], x,
                                x)

plt.pcolor(np.real(corr))
plt.xlabel(r'Time $t_2$')
plt.ylabel(r'Time $t_1$')
plt.title(r'Correlation $\left<x(t)x(0)\right>$')
plt.show()