Ejemplo n.º 1
0
def test_divergence_1():
    config = {
        'dimH':    13,
        'EC':      1,
        'Omega':   3,
        'y_0':     0.02,
        't_bath':  0.0,
        'tr':      (0, 20, 0.001),
        't_rho0':  [0],
    }

    pf  = 1.0 / config['EC'] * config['Omega'] ** 2
    Oh0 = 0.5 * config['EC'] * Odn2(config['dimH'], qo.QO.T_COMPLEX) \
        - pf * Ocos(config['dimH'], qo.QO.T_COMPLEX)
    rs  = qo.ReducedSystem(Oh0, dipole=Osin(config['dimH'], qo.QO.T_COMPLEX))

    # -- Run with QuTip
    kernel = QutipKernel(rs)
    kernel.compile()
    kernel.sync(t_bath=config['t_bath'], y_0=config['y_0'], state=rs.thermal_state(T=config['t_rho0']))
    tlist = qo.time_gatter(*config['tr'])
    (_, _, tstate, _) = kernel.run(tlist)

    # -- Run with OpenCL kernel
    kernelCL = OpenCLKernel(rs)
    kernelCL.optimize_jumps = True
    kernelCL.compile()
    kernelCL.sync(t_bath=config['t_bath'], y_0=config['y_0'], state=rs.thermal_state(T=config['t_rho0']))
    tlist_cl, resultCL = kernelCL.reader_rho_t(kernelCL.run(config['tr'], steps_chunk_size=1e4))

    # -- compare all states at all times
    assert_allclose(tlist, tlist_cl)
    assert_allclose(resultCL, tstate, **qo.QO.TEST_TOLS)
Ejemplo n.º 2
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)