Example #1
0
def test_svd_compress(comp, mp):

    if mp == "mpo":
        mps = Mpo(holstein_model)
        M = 22
    else:
        mps = Mps.random(holstein_model, 1, 10)
        if mp == "mpdm":
            mps = MpDm.from_mps(mps)
        mps.canonicalise().normalize()
        M = 36
    if comp:
        mps = mps.to_complex(inplace=True)
    print(f"{mps}")

    mpo = Mpo(holstein_model)
    if comp:
        mpo = mpo.scale(-1.0j)
    print(f"{mpo.bond_dims}")

    std_mps = mpo.apply(mps, canonicalise=True).canonicalise()
    print(f"std_mps: {std_mps}")
    mps.compress_config.bond_dim_max_value = M
    mps.compress_config.criteria = CompressCriteria.fixed
    svd_mps = mpo.contract(mps)
    dis = svd_mps.distance(std_mps) / std_mps.dmrg_norm
    print(f"svd_mps: {svd_mps}, dis: {dis}")
    assert np.allclose(dis, 0.0, atol=1e-3)
    assert np.allclose(svd_mps.dmrg_norm, std_mps.dmrg_norm, atol=1e-4)
Example #2
0
def test_variational_compress(comp, mp):

    if mp == "mpo":
        mps = Mpo(holstein_model)
        M = 20
    else:
        mps = Mps.random(holstein_model, 1, 10)
        if mp == "mpdm":
            mps = MpDm.from_mps(mps)
        mps.canonicalise().normalize()
        M = 36
    if comp:
        mps = mps.to_complex(inplace=True)
    print(f"{mps}")

    mpo = Mpo(holstein_model)
    if comp:
        mpo = mpo.scale(-1.0j)
    print(f"{mpo.bond_dims}")

    std_mps = mpo.apply(mps, canonicalise=True).canonicalise()
    print(f"std_mps: {std_mps}")

    # 2site algorithm
    mps.compress_config.vprocedure = [[M, 1.0], [M, 0.2], [M, 0.1]] + [
        [M, 0],
    ] * 10
    mps.compress_config.vmethod = "2site"
    var_mps = mps.variational_compress(mpo, guess=None)
    dis = var_mps.distance(std_mps) / std_mps.dmrg_norm
    print(f"var2_mps: {var_mps}, dis: {dis}")
    assert np.allclose(dis, 0.0, atol=1e-4)
    assert np.allclose(var_mps.dmrg_norm, std_mps.dmrg_norm, atol=1e-4)

    # 1site algorithm with 2site result as a guess
    # 1site algorithm is easy to be trapped in a local minimum
    var_mps.compress_config.vprocedure = [
        [M, 0],
    ] * 10
    var_mps.compress_config.vmethod = "1site"
    var_mps = mps.variational_compress(mpo, guess=var_mps)
    dis = var_mps.distance(std_mps) / std_mps.dmrg_norm
    print(f"var1_mps: {var_mps}, dis: {dis}")
    assert np.allclose(dis, 0.0, atol=1e-4)
    assert np.allclose(var_mps.dmrg_norm, std_mps.dmrg_norm, atol=1e-4)
Example #3
0
def test_H_chain_LDOS():
    # local density of states of four H_Chain
    # Ronca,J. Chem. Theory Comput. 2017, 13, 5560-5571
    # example to use Mollist2 to do CV calculation

    spatial_norbs = 4
    spin_norbs = spatial_norbs * 2
    h1e, h2e, nuc = h_qc.read_fcidump(
        os.path.join(cur_dir, "fcidump_lowdin_h4.txt"), spatial_norbs)

    basis, ham_terms = h_qc.qc_model(h1e, h2e)

    model = Model(basis, ham_terms)
    mpo = Mpo(model)

    nelec = spatial_norbs
    M = 50
    procedure = [[M, 0.4], [M, 0.2]] + [
        [M, 0],
    ] * 6
    mps = Mps.random(model, nelec, M, percent=1.0)

    mps.optimize_config.procedure = procedure
    mps.optimize_config.method = "2site"
    energies, mps = gs.optimize_mps(mps, mpo)
    gs_e = min(energies) + nuc

    assert np.allclose(gs_e, -2.190384218792706)
    mps_e = mps.expectation(mpo)

    def photoelectron_operator(idx):
        # norbs is the spin orbitals
        # green function
        op_list = [Op("sigma_z", iorb, qn=0) for iorb in range(idx)]
        return Op.product(op_list + [Op("sigma_+", idx, qn=-1)])

    dipole_model = photoelectron_operator(nelec - 1)
    dipole_op = Mpo(model, dipole_model)
    b_mps = dipole_op.apply(mps)

    #std
    #test_freq = np.linspace(0.25, 1.25, 100, endpoint=False).tolist()
    test_freq = np.linspace(0.25, 1.25, 20, endpoint=False).tolist()
    eta = 0.05
    M = 10
    procedure_cv = [0.4, 0.2] + [0] * 6
    spectra = SpectraZtCV(model,
                          None,
                          M,
                          eta,
                          h_mpo=mpo,
                          method="2site",
                          procedure_cv=procedure_cv,
                          b_mps=b_mps.scale(-eta),
                          e0=mps_e)

    result = batch_run(test_freq, 1, spectra)
    std = np.load(os.path.join(cur_dir, "H_chain_std.npy"))
    #np.save("res", result)
    #np.save("freq", test_freq)
    assert np.allclose(result, std[::5])