Exemplo n.º 1
0
def test_two_level_T_driving():
    """ two level system at finite temperature with
        time dependent hamiltonian compared to reference
        implementation.
        """
    REF_TOL = 0.0001
    OMEGA = 2.0
    tr = (0, 1.0, 0.001)
    y_0 = 0.5
    t_bath = 1.0
    h0 = [0, 0, 0, OMEGA]
    states = [[1.0, 0.0, 0.0, 0.0]] * 3
    param = np.array([(0.0, 0.0), (1.0, 2.0), (1.0, 2.5)],
                     dtype=np.dtype([
                         ('A', np.float32),
                         ('b', np.float32),
                     ]))

    kernel = OpenCLKernel(ReducedSystem(h0, [
        0,
        1,
        1,
        0,
    ]))
    kernel.t_sysparam = param.dtype
    kernel.ht_coeff = [lambda t, p: p['A'] * np.sin(p['b'] * t / np.pi)]
    kernel.compile()

    kernel.sync(state=states,
                y_0=y_0,
                t_bath=t_bath,
                sysparam=param,
                htl=[[1, 1, 1, 1]])
    tf, rhof = kernel.reader_tfinal_rho(kernel.run(tr, steps_chunk_size=1234))

    # test final time
    assert np.isclose(tf, tr[1])

    # reference result
    (_, fstate, _, _) = opmesolve([h0, [[1, 1, 1, 1], kernel.ht_coeff[0]]],
                                  states,
                                  t_bath=t_bath,
                                  y_0=y_0,
                                  tw=[OMEGA],
                                  tr=tr,
                                  kernel="QuTip",
                                  args=param)

    # test against reference
    assert_allclose(rhof[0], fstate[0], **QOP.TEST_TOLS)
    assert_allclose(rhof[1], fstate[1], **QOP.TEST_TOLS)
    assert_allclose(rhof[2], fstate[2], **QOP.TEST_TOLS)
Exemplo n.º 2
0
def test_opmesolve_thermal_state():
    (_, fstate, _, _) = opme.opmesolve(H=[0, 0, 0, 0, 1, 0, 0, 0, 2],
                                       rho0=[[0.5, 0, 0, 0, 0, 0, 0, 0, 0.5],
                                             [1, 0, 0, 0, 0, 0, 0, 0, 0]],
                                       t_bath=[0.0, 1.0],
                                       y_0=2.0,
                                       tr=(0, 3, 0.0025))

    # test if state converged to thermal state within 0.001 tol
    rho_e1 = np.diag([1, 0, 0])
    assert np.all(np.abs(rho_e1 - fstate[0]) < 0.001)

    Z = 1 + np.exp(-1.0) + np.exp(-2.0)
    rho_e2 = np.diag([1.0 / Z, np.exp(-1.0) / Z, np.exp(-2.0) / Z])
    assert np.all(np.abs(rho_e2 - fstate[1]) < 0.001)
Exemplo n.º 3
0
def test_two_level_TZero():
    """ most simple dissipative case.
        two level system with at T=0:

          d rho / dt = -i[H,rho] + y_0 \\Omega^3 D[A(\\Omega)]
    """
    REF_TOL = 0.0001
    OMEGA = 2.0
    tr = (0, 1.0, 0.001)
    y_0 = [0.5, 0.5, 0.25]
    h0 = [0, 0, 0, OMEGA]
    states = [
        # T=inf
        [0.5, 0.0, 0.0, 0.5],
        # T=0
        [1.0, 0.0, 0.0, 0.0],
        # T=t + coherence
        [0.75, 0.5, 0.5, 0.25],
    ]
    kernel = OpenCLKernel(ReducedSystem(h0, [
        0,
        1,
        1,
        0,
    ]))
    kernel.compile()
    kernel.sync(state=states, y_0=y_0, t_bath=0)
    tf, rhof = kernel.reader_tfinal_rho(kernel.run(tr))

    # test final time
    assert np.isclose(tf, tr[1])

    # reference result
    (_, fstate, _, _) = opmesolve(h0,
                                  states,
                                  t_bath=0,
                                  y_0=y_0,
                                  tw=[OMEGA],
                                  tr=tr,
                                  kernel="QuTip")

    # test against reference
    assert_allclose(rhof[0], fstate[0], **QOP.TEST_TOLS)
    assert_allclose(rhof[1], fstate[1], **QOP.TEST_TOLS)
    assert_allclose(rhof[2], fstate[2], **QOP.TEST_TOLS)
Exemplo n.º 4
0
def test_four_level_T():
    """ four level system at finite temperature T

        - all possible jumps
        - no dipole
        - eigenbase
        - compare optimized and non-optimized vs. reference
        """
    REF_TOL = 0.0001
    tr = (0, 1.0, 0.001)
    t_bath = [1.0, 0.5]
    y_0 = [1.3, 2.4]

    h0 = [
        0.0,
        0,
        0,
        0,
        0,
        1.0,
        0,
        0,
        0,
        0,
        2.0,
        0,
        0,
        0,
        0,
        6.0,
    ]

    states = [
        [
            # T=0
            1.0,
            0.0,
            0.0,
            0.0,
            0.0,
            0.0,
            0.0,
            0.0,
            0.0,
            0.0,
            0.0,
            0.0,
            0.0,
            0.0,
            0.0,
            0.0,
        ],
        [
            # some weird state
            0.4,
            0.4,
            0.6,
            0.3,
            0.4,
            0.3,
            0.2,
            0.2,
            0.6,
            0.2,
            0.1,
            0.6,
            0.3,
            0.2,
            0.6,
            0.2,
        ]
    ]

    sys = ReducedSystem(h0)
    kernel = OpenCLKernel(sys)
    kernel.optimize_jumps = True
    kernel.compile()
    kernel.sync(state=states, y_0=y_0, t_bath=t_bath)
    tf, rhof = kernel.reader_tfinal_rho(kernel.run(tr, steps_chunk_size=1111))

    # test final time
    assert np.isclose(tf, tr[1])

    kernel2 = OpenCLKernel(sys)
    kernel2.optimize_jumps = False
    kernel2.compile()
    kernel2.sync(state=states, y_0=y_0, t_bath=t_bath)
    tf, rhof2 = kernel.reader_tfinal_rho(kernel2.run(tr))

    # test final time
    assert np.isclose(tf, tr[1])

    # reference result
    (_, fstate, _, _) = opmesolve(h0,
                                  states,
                                  t_bath=t_bath,
                                  y_0=y_0,
                                  tr=tr,
                                  kernel="QuTip")

    # test against reference
    assert_allclose(rhof[0], fstate[0], **QOP.TEST_TOLS)
    assert_allclose(rhof[1], fstate[1], **QOP.TEST_TOLS)
    assert_allclose(rhof2[0], fstate[0], **QOP.TEST_TOLS)
    assert_allclose(rhof2[1], fstate[1], **QOP.TEST_TOLS)
Exemplo n.º 5
0
def test_three_level_T():
    """ three level system at finite temperature.

        - two jumps (1*Omega, 2*Omega)
        - no dipole
        - eigenbase
        - compare optimized vs. reference

        """
    REF_TOL = 0.0001
    OMEGA = 2.0
    tr = (0, 0.5, 0.001)
    tw = [OMEGA, 2 * OMEGA]
    t_bath = 1.0
    h0 = [
        0.0,
        0,
        0,
        0,
        OMEGA,
        0,
        0,
        0,
        2 * OMEGA,
    ]
    states = [
        [
            # T=inf
            1.0 / 3.0,
            0.0,
            0.0,
            0.0,
            1.0 / 3.0,
            0.0,
            0.0,
            0.0,
            1.0 / 3.0
        ],
        [
            # T=0
            1.0,
            0.0,
            0.0,
            0.0,
            0.0,
            0.0,
            0.0,
            0.0,
            0.0
        ],
        [
            # T=t + coherence
            0.4,
            0.4 + 0.25j,
            0.6 - 0.5j,
            0.4 - 0.25j,
            0.2,
            -0.2j,
            0.6 + 0.5j,
            0.2j,
            0.4
        ]
    ]

    sys = ReducedSystem(h0, [
        0,
        1,
        1,
        1,
        0,
        1,
        1,
        1,
        0,
    ])

    kernel = OpenCLKernel(sys)
    assert kernel.optimize_jumps
    kernel.compile()
    kernel.sync(state=states, y_0=1.0, t_bath=t_bath)
    tf, rhof = kernel.reader_tfinal_rho(kernel.run(tr))

    # test final time
    assert np.isclose(tf, tr[1])

    # reference result
    (_, fstate, _, _) = opmesolve(h0,
                                  states,
                                  t_bath=t_bath,
                                  y_0=1.0,
                                  tw=tw,
                                  tr=tr,
                                  kernel="QuTip")

    # test against reference
    assert_allclose(rhof[0], fstate[0], **QOP.TEST_TOLS)
    assert_allclose(rhof[1], fstate[1], **QOP.TEST_TOLS)
    assert_allclose(rhof[2], fstate[2], **QOP.TEST_TOLS)
Exemplo n.º 6
0
def test_two_level_T():
    """ most simple dissipative case at finite temperature:
        two level system at T > 0:

          d rho / dt = -i[H,rho] + y_0 * \Omega^3 * (1 + N(\\Omega)) * D[A(\\Omega)]
                                 + y_0 * \Omega^3 * N(\\Omega) * D[A^\\dagger(\\Omega)]

        - single jump
        - no dipole
        - eigenbase
        - compared optimized vs. reference
    """
    REF_TOL = 0.0001
    OMEGA = 2.0
    tr = (0, 1.0, 0.001)
    y_0 = 0.5
    t_bath = 1.0

    h0 = [0, 0, 0, OMEGA]
    states = [
        [
            # T=inf
            0.5,
            0.2 - 0.4j,
            0.2 + 0.4j,
            0.5
        ],
        [
            # T=0
            1.0,
            0.0,
            0.0,
            0.0
        ]
    ]

    kernel = OpenCLKernel(ReducedSystem(h0, [
        0,
        1,
        1,
        0,
    ]))
    kernel.compile()
    kernel.sync(state=states, y_0=y_0, t_bath=t_bath)
    tf, rhof = kernel.reader_tfinal_rho(kernel.run(tr))

    # test final time
    assert np.isclose(tf, tr[1])

    # reference result
    (_, fstate, _, _) = opmesolve(h0,
                                  states,
                                  t_bath=t_bath,
                                  y_0=y_0,
                                  tw=[OMEGA],
                                  tr=tr,
                                  kernel="QuTip")

    # test against reference
    assert_allclose(rhof[0], fstate[0], **QOP.TEST_TOLS)
    assert_allclose(rhof[1], fstate[1], **QOP.TEST_TOLS)
Exemplo n.º 7
0
def test_three_level_TZero():
    """ two different annihilation processes A(Omega), A(2*Omega) at T=0:

        - two possible jumps
        - no dipole
        - eigenbase
        - compared optimized vs. reference
        """
    REF_TOL = 0.0001
    OMEGA = 2.0
    tr = (0, 0.1, 0.001)
    tw = [OMEGA, 2 * OMEGA]

    h0 = [
        0.0,
        0,
        0,
        0,
        OMEGA,
        0,
        0,
        0,
        2 * OMEGA,
    ]

    states = [
        [
            # T=inf
            1.0 / 3.0,
            0.0,
            0.0,
            0.0,
            1.0 / 3.0,
            0.0,
            0.0,
            0.0,
            1.0 / 3.0
        ],
        [
            # T=0
            1.0,
            0.0,
            0.0,
            0.0,
            0.0,
            0.0,
            0.0,
            0.0,
            0.0
        ],
        [
            # T=t + coherence
            0.4,
            0.4,
            0.6,
            0.4,
            0.2,
            0.2,
            0.6,
            0.2,
            0.4
        ]
    ]
    sys = ReducedSystem(h0, [
        0,
        1,
        1,
        1,
        0,
        1,
        1,
        1,
        0,
    ])
    kernel = OpenCLKernel(sys)
    kernel.compile()
    kernel.sync(state=states, y_0=1.0, t_bath=0)
    tf, rhof = kernel.reader_tfinal_rho(kernel.run(tr))

    # test final time
    assert np.isclose(tf, tr[1])

    # reference result
    (_, fstate, _, _) = opmesolve(h0,
                                  states,
                                  t_bath=0,
                                  y_0=1.0,
                                  tw=tw,
                                  tr=tr,
                                  kernel="QuTip")

    # test against reference
    assert_allclose(rhof[0], fstate[0], **QOP.TEST_TOLS)
    assert_allclose(rhof[1], fstate[1], **QOP.TEST_TOLS)
    assert_allclose(rhof[2], fstate[2], **QOP.TEST_TOLS)
Exemplo n.º 8
0
def test_von_neumann_basis():
    """ we integrate a system which is not provided in eigenbase.
        two states are tests:

            1. stationary (and pure) state |i><i|
            2. some non stationary state

        test checks basic integrator and density operator
        properties and compares the result against QuTip
        reference solver.
        """
    REF_TOL = 0.0001
    tr = (0, 1, 0.001)
    h0 = [
        1,
        1.5,
        0,
        1.5,
        1.42,
        3,
        0,
        3,
        2.11,
    ]

    ev, s = np.linalg.eigh(np.array(h0).reshape((3, 3)))
    s = s.T
    rho1 = np.outer(s[0].conj().T, s[0])
    rho2 = np.array([0.5, 0, 0, 0, 0.5, 0, 0, 0, 0],
                    dtype=np.complex64).reshape((3, 3))
    states = [rho1, rho2]

    system = ReducedSystem(h0)
    kernel = OpenCLKernel(system)
    kernel.compile()

    # we archive von Neumann by setting global damping to y_0=
    # which leads to supression of dissipative terms
    kernel.sync(state=states, y_0=0, t_bath=0)
    tlist, ts = kernel.reader_rho_t(kernel.run(tr))

    # test times
    assert_allclose(np.arange(tr[0], tr[1] + tr[2], tr[2]), tlist)

    # test density operator
    assert tstate_rho_hermitian(ts[1:2])
    assert tstate_rho_trace(1.0, ts)

    # test stationary state
    assert_allclose(ts[-1][0], rho1, **QOP.TEST_TOLS)

    # test against reference
    (_, fstate, _, _) = opmesolve(h0,
                                  states,
                                  0,
                                  0,
                                  tw=[],
                                  tr=tr,
                                  kernel="QuTip")
    assert_allclose(ts[-1][0], fstate[0], **QOP.TEST_TOLS)
    assert_allclose(ts[-1][1], fstate[1], **QOP.TEST_TOLS)
Exemplo n.º 9
0
def test_qutip_kernel_case_1():
    j0f = [[0. - 0.j, 0. - 2.j, 0. - 0.j, 0. - 0.j, 0. - 0.j],
           [
               0. + 2.j,
               0. - 0.j,
               0. - 2.44948974j,
               0. - 0.j,
               0. - 0.j,
           ],
           [
               0. - 0.j,
               0. + 2.44948974j,
               0. - 0.j,
               0. - 2.44948974j,
               0. - 0.j,
           ], [
               0. - 0.j,
               0. - 0.j,
               0. + 2.44948974j,
               0. - 0.j,
               0. - 2.j,
           ], [
               0. - 0.j,
               0. - 0.j,
               0. - 0.j,
               0. + 2.j,
               0. - 0.j,
           ]]
    h0f = [
        [6. + 0.j, -2. + 0.j, -0. + 0.j, -0. + 0.j, -0. + 0.j],
        [
            -2. + 0.j,
            3. + 0.j,
            -2.44948974 + 0.j,
            -0. + 0.j,
            -0. + 0.j,
        ],
        [
            -0. + 0.j,
            -2.44948974 + 0.j,
            2. + 0.j,
            -2.44948974 + 0.j,
            -0. + 0.j,
        ],
        [
            -0. + 0.j,
            -0. + 0.j,
            -2.44948974 + 0.j,
            3. + 0.j,
            -2. + 0.j,
        ],
        [
            -0. + 0.j,
            -0. + 0.j,
            -0. + 0.j,
            -2. + 0.j,
            6. + 0.j,
        ],
    ]
    rho0 = [[
        0.5,
        0,
        0,
        0,
        -.5j,
    ], [
        0,
        0,
        0,
        0,
        0,
    ], [
        0,
        0,
        0,
        0,
        0,
    ], [
        0,
        0,
        0,
        0,
        0,
    ], [
        .5j,
        0,
        0,
        0,
        0.5,
    ]]

    opme.opmesolve(H=h0f,
                   rho0=rho0,
                   dipole=j0f,
                   tr=(0, 0.2, 0.00005),
                   t_bath=10,
                   y_0=0.04,
                   kernel="QuTip")