Beispiel #1
0
def test_idx():
    assert mol_list.e_idx(0) == 0
    assert mol_list.e_idx(1) == 3
    assert mol_list.switch_scheme(4).e_idx(0) == 2
    assert mol_list.ph_idx(0, 0) == 1
    assert mol_list.ph_idx(0, 1) == 2
    assert mol_list.ph_idx(2, 1) == 8
    assert mol_list.switch_scheme(4).ph_idx(2, 1) == 6
    assert mol_list.switch_scheme(4).ph_idx(1, 0) == 3
Beispiel #2
0
def test_construct_MPO_scheme3():
    Mmax = 10
    J = (np.array([[0.0, -0.1, 0.0], [-0.1, 0.0, -0.3], [0.0, -0.3, 0.0]]) /
         constant.au2ev)
    mol_list = custom_mol_list(J)
    mps2, mpo2 = construct_mps_mpo_2(mol_list, Mmax, nexciton)
    mps3, mpo3 = construct_mps_mpo_2(mol_list.switch_scheme(3), Mmax, nexciton)
    assert mpo2.ephtable == mpo3.ephtable
    assert mpo2.pbond_list == mpo3.pbond_list
    assert mpo3.distance(mpo2) == pytest.approx(0)
Beispiel #3
0
def test_optimization(scheme):
    mps, mpo = construct_mps_mpo_2(mol_list.switch_scheme(scheme), procedure[0][0], nexciton)
    mps.optimize_config.procedure = procedure
    mps.optimize_config.method = "2site"
    energy = optimize_mps(mps.copy(), mpo)
    assert energy * constant.au2ev == pytest.approx(2.28614053133, rel=1e-5)

    mps.optimize_config.method = "1site"
    energy = optimize_mps(mps.copy(), mpo)
    assert energy * constant.au2ev == pytest.approx(2.28614053133, rel=1e-5)
Beispiel #4
0
def test_construct_MPO():
    Mmax = 10
    mps1, mpo1 = construct_mps_mpo_2(mol_list.switch_scheme(1), Mmax, nexciton)
    mps2, mpo2 = construct_mps_mpo_2(mol_list, Mmax, nexciton)

    assert mpo1.ephtable == mpo2.ephtable
    assert mpo1.pbond_list == mpo2.pbond_list
    # for double precision the abs could be near 0. In single precision
    # the norm of mpo2 is not correct. (mpo2.dot(mpo2) != mpo1.dot(mpo1)
    # but mpo1.dot(mpo1) == mpo1.dot(mpo2)). Reason unknown
    assert mpo1.distance(mpo2) == pytest.approx(0, abs=1e-3)
Beispiel #5
0
def test_general_mpo_MolList(mol_list, scheme):

    if scheme == 4:
        mol_list1 = mol_list.switch_scheme(4)
    else:
        mol_list1 = mol_list

    mol_list1.mol_list2_para()
    mpo = Mpo.general_mpo(mol_list1,
                          const=Quantity(-mol_list1[0].gs_zpe *
                                         mol_list1.mol_num))
    mpo_std = Mpo(mol_list1)
    check_result(mpo, mpo_std)
Beispiel #6
0
def test_intersite(scheme):

    local_mlist = mol_list.switch_scheme(scheme)

    mpo1 = Mpo.intersite(local_mlist, {0: r"a^\dagger"}, {}, Quantity(1.0))
    mpo2 = Mpo.onsite(local_mlist, r"a^\dagger", mol_idx_set=[0])
    assert mpo1.distance(mpo2) == pytest.approx(0, abs=1e-5)

    mpo3 = Mpo.intersite(local_mlist, {2: r"a^\dagger a"}, {}, Quantity(1.0))
    mpo4 = Mpo.onsite(local_mlist, r"a^\dagger a", mol_idx_set=[2])
    assert mpo3.distance(mpo4) == pytest.approx(0, abs=1e-5)

    mpo5 = Mpo.intersite(local_mlist, {2: r"a^\dagger a"}, {}, Quantity(0.5))
    assert mpo5.add(mpo5).distance(mpo4) == pytest.approx(0, abs=1e-5)

    mpo6 = Mpo.intersite(local_mlist, {
        0: r"a^\dagger",
        2: "a"
    }, {}, Quantity(1.0))
    mpo7 = Mpo.onsite(local_mlist, "a", mol_idx_set=[2])
    assert mpo2.apply(mpo7).distance(mpo6) == pytest.approx(0, abs=1e-5)

    # the tests are based on the similarity between scheme 2 and scheme 3
    # so scheme 3 and scheme 4 will be skipped
    if scheme == 2:
        mpo8 = Mpo(local_mlist)
        # a dirty hack to switch from scheme 2 to scheme 3
        test_mlist = local_mlist.switch_scheme(2)
        test_mlist.scheme = 3
        mpo9 = Mpo(test_mlist)
        mpo10 = Mpo.intersite(test_mlist, {
            0: r"a^\dagger",
            2: "a"
        }, {}, Quantity(local_mlist.j_matrix[0, 2]))
        mpo11 = Mpo.intersite(test_mlist, {
            2: r"a^\dagger",
            0: "a"
        }, {}, Quantity(local_mlist.j_matrix[0, 2]))

        assert mpo11.conj_trans().distance(mpo10) == pytest.approx(0, abs=1e-6)
        assert mpo8.distance(mpo9 + mpo10 + mpo11) == pytest.approx(0,
                                                                    abs=1e-6)

        test_mlist.periodic = True
        mpo12 = Mpo(test_mlist)
        assert mpo12.distance(mpo9 + mpo10 + mpo11) == pytest.approx(0,
                                                                     abs=1e-6)

    ph_mpo1 = Mpo.ph_onsite(local_mlist, "b", 1, 1)
    ph_mpo2 = Mpo.intersite(local_mlist, {}, {(1, 1): "b"})
    assert ph_mpo1.distance(ph_mpo2) == pytest.approx(0, abs=1e-6)
Beispiel #7
0
def test_general_mpo_MolList2(mol_list, scheme, formula):
    if scheme == 4:
        mol_list1 = mol_list.switch_scheme(4)
    else:
        mol_list1 = mol_list

    # scheme123
    mol_list2 = MolList2.MolList_to_MolList2(mol_list1, formula=formula)
    mpo_std = Mpo(mol_list1)
    # classmethod method
    mpo = Mpo.general_mpo(mol_list2,
                          const=Quantity(-mol_list[0].gs_zpe *
                                         mol_list.mol_num))
    check_result(mpo, mpo_std)
    # __init__ method, same api
    mpo = Mpo(mol_list2,
              offset=Quantity(mol_list[0].gs_zpe * mol_list.mol_num))
    check_result(mpo, mpo_std)