示例#1
0
fdx.write("H10.STO6G.R1.8.ROTATION.LOWDIN")

bond_dim = 500
bdims = [bond_dim]
mpo = hamil.build_qc_mpo()
mpo, _ = mpo.compress(left=True, cutoff=1E-12, norm_cutoff=1E-12)
mps = hamil.build_mps(bond_dim)
print('MPO (NC) =         ', mpo.show_bond_dims())
print('MPS = ', mps.show_bond_dims())

noises = [1E-4, 1E-5, 1E-6, 0]
davthrds = [1E-3] + [1E-4] * 100

dmrg = MPE(mps, mpo, mps).dmrg(bdims=bdims,
                               noises=noises,
                               dav_thrds=davthrds,
                               iprint=2,
                               n_sweeps=20,
                               tol=1E-12)
ener = dmrg.energies[-1]
print("Energy = %20.12f" % ener)


def generate_terms(n_sites, c, d):
    for i in range(0, n_sites):
        for j in range(0, n_sites):
            for s in [0, 1]:
                t = kappa[i, j]
                yield t * c[i, s] * d[j, s]


mpo_rot = hamil.build_mpo(generate_terms, cutoff=1E-12).to_sparse().to_flat()
示例#2
0
    mpo = mpo.to_flat()

print('MPS energy = ', np.dot(mps, mpo @ mps))

mps[-3:] = [reduce(pbalg.hdot, mps[-3:])]
mpo[-3:] = [reduce(pbalg.hdot, mpo[-3:])]

print('MPO (hdot) = ', mpo.show_bond_dims())
print('MPS (hdot) = ', mps.show_bond_dims())

print('MPS energy = ', mps @ (mpo @ mps))

info = mps[-1].kron_product_info(1, 2, 3)
mps[-1] = mps[-1].fuse(1, 2, 3, info=info)
mpo[-1] = mpo[-1].fuse(4, 5, 6, info=info).fuse(1, 2, 3, info=info)

print('MPS energy = ', mps @ (mpo @ mps))

me = MPE(mps, mpo, mps)
mex = me[0:2]
# print(mex.ket[-2])
# print(mex.ket[-1])
mex.ket[:] = [reduce(pbalg.hdot, mex.ket[:])]
print(mex.expectation)
# l, s, r = mex.ket[0].tensor_svd(idx=3, pattern='++++--', full_matrices=False)
# ls = np.tensordot(l, s.diag(), axes=1)
# mex.ket[:] = [ls, r]
# # print(mex.ket[-2])
# # print(mex.ket[-1])
# print(mex.expectation)
示例#3
0
# fd = '../data/N2.STO3G.FCIDUMP'
# fd = '../data/H8.STO6G.R1.8.FCIDUMP'
# fd = '../my_test/n2/N2.FCIDUMP'
bdims = 200

# with HamilTools.hubbard(n_sites=4, u=2, t=1) as hamil:
# # with HamilTools.hubbard(n_sites=16, u=2, t=1) as hamil:
# # with HamilTools.from_fcidump(fd) as hamil:
#     mps = hamil.get_init_mps(bond_dim=bdims)
#     # mps = hamil.get_ground_state_mps(bond_dim=bdims, noise=0)
#     # exit(0)
#     mpo = hamil.get_mpo()

tx = time.perf_counter()
fcidump = FCIDUMP(pg='d2h').read(fd)
hamil = Hamiltonian(fcidump)
mpo = QCSymbolicMPO(hamil).to_sparse().to_flat()
print('build mpo time = ', time.perf_counter() - tx)

fhamil = Hamiltonian(fcidump, flat=True)
mps_info = MPSInfo(fhamil.n_sites, fhamil.vacuum, fhamil.target, fhamil.basis)
mps_info.set_bond_dimension(bdims)
mps = MPS.random(mps_info)

print('MPS = ', mps.show_bond_dims())
print('MPO (NC) =         ', mpo.show_bond_dims())
mpo, _ = mpo.compress(left=True, cutoff=1E-9, norm_cutoff=1E-9)
print('MPO (compressed) = ', mpo.show_bond_dims())

print(MPE(mps, mpo, mps).dmrg(bdims=[bdims]))
示例#4
0
    mpo = SimplifiedMPO(orig_mpo, NoTransposeRule(RuleQC()), True)
else:
    orig_mpo = MPOQC(hamil, QCTypes.NC)
    mpo = SimplifiedMPO(orig_mpo, RuleQC(), True)

if "PY" in mode:
    mps.dot = 1
    pymps = MPSTools.from_block2(mps)
    print('PY MPS MEM = ',
          [sum([y.size for y in x.blocks]) for x in pymps.tensors])
    pympo = MPOTools.from_block2(orig_mpo)
    pympo, _ = pympo.compress(left=True, cutoff=cutoff, norm_cutoff=cutoff)
    print(pympo.show_bond_dims())
    if flat:
        fpymps = pymps.to_flat()
        me = PYME(fpymps, pympo.to_flat(), fpymps, do_canon=do_canon)
    else:
        me = PYME(pymps, pympo, pymps, do_canon=do_canon)

    if profile:
        profiler.start()
    t0 = time.perf_counter()
    for i in range(0, n_sites - 1 if prop else 1):
        t = time.perf_counter()
        eff = me[i:i + dot]
        # print("PY time ctr/rot = ", me.t_ctr, me.t_rot)
        # print("PY Init elapsed = ", time.perf_counter() - t0)
        # if dot == 2:
        #     eff.ket[:] = [reduce(pbalg.hdot, eff.ket[:])]
        #     eff.bra[:] = [reduce(pbalg.hdot, eff.bra[:])]
        # # ener, eff, ndav = eff.eigs(iprint=True)
示例#5
0
import numpy as np
from pyblock3.algebra.mpe import MPE
from pyblock3.hamiltonian import Hamiltonian
from pyblock3.fcidump import FCIDUMP
from pyblock3.symbolic.expr import OpElement, OpNames
from pyblock3.algebra.symmetry import SZ

fd = '../data/N2.STO3G.FCIDUMP'
bond_dim = 500
hamil = Hamiltonian(FCIDUMP(pg='d2h').read(fd), flat=True)
mpo = hamil.build_qc_mpo()
mpo, _ = mpo.compress(cutoff=1E-9, norm_cutoff=1E-9)
mps = hamil.build_mps(bond_dim)

dmrg = MPE(mps, mpo, mps).dmrg(bdims=[bond_dim], noises=[1E-6, 0], dav_thrds=[1E-4], iprint=2, n_sweeps=10)
ener = dmrg.energies[-1]
print("Energy = %20.12f" % ener)

print('energy error = ', np.abs(ener - -107.654122447525))
assert np.abs(ener - -107.654122447525) < 1E-6

# FCI results
pdm1_std = np.zeros((hamil.n_sites, hamil.n_sites))
pdm1_std[0, 0] = 1.999989282592
pdm1_std[0, 1] = -0.000025398134
pdm1_std[0, 2] = 0.000238560621
pdm1_std[1, 0] = -0.000025398134
pdm1_std[1, 1] = 1.991431489457
pdm1_std[1, 2] = -0.005641787787
pdm1_std[2, 0] = 0.000238560621
示例#6
0
# occf = '../data/CR2.SVP.OCC'
# occ = [float(x) for x in open(occf, 'r').readline().split()]

hamil = Hamiltonian(FCIDUMP(pg='d2h').read(fd), flat=True)

tx = time.perf_counter()
mpo = hamil.build_qc_mpo()
print('MPO (NC) =         ', mpo.show_bond_dims())
print('build mpo time = ', time.perf_counter() - tx)

tx = time.perf_counter()
mpo, _ = mpo.compress(left=True, cutoff=1E-9, norm_cutoff=1E-9)
print('MPO (compressed) = ', mpo.show_bond_dims())
print('compress mpo time = ', time.perf_counter() - tx)

mps = hamil.build_mps(bond_dim, occ=occ)
print('MPS = ', mps.show_bond_dims())

bdims = [250] * 5 + [500] * 5
noises = [1E-5] * 2 + [1E-6] * 4 + [1E-7] * 4 + [0]
davthrds = [1E-5] * 4 + [1E-6] * 4 + [1E-7]

dmrg = MPE(mps, mpo, mps).dmrg(bdims=bdims,
                               noises=noises,
                               dav_thrds=davthrds,
                               iprint=2,
                               n_sweeps=20)
ener = dmrg.energies[-1]
print("Energy = %20.12f" % ener)
示例#7
0
tx = time.perf_counter()
mpo, _ = mpo.compress(left=True, cutoff=1E-9, norm_cutoff=1E-9)
print('MPO (compressed) = ', mpo.show_bond_dims())
print('compress mpo time = ', time.perf_counter() - tx)

mps = hamil.build_mps(ket_bond_dim)
print('MPS = ', mps.show_bond_dims())

bdims = [500]
noises = [1E-4, 1E-5, 1E-6, 0]
davthrds = None

dmrg = MPE(mps, mpo, mps).dmrg(bdims=bdims,
                               noises=noises,
                               dav_thrds=davthrds,
                               iprint=2,
                               n_sweeps=20,
                               tol=1E-12)
ener = dmrg.energies[-1]
print("Energy = %20.12f" % ener)

isite = 4
mpo.const -= ener

dop = OpElement(OpNames.D, (isite, 0),
                q_label=SZ(-1, -1, hamil.orb_sym[isite]))
bra = hamil.build_mps(bra_bond_dim,
                      target=SZ.to_flat(dop.q_label +
                                        SZ.from_flat(hamil.target)))
dmpo = hamil.build_site_mpo(dop)
print('DMPO =         ', dmpo.show_bond_dims())
示例#8
0
tx = time.perf_counter()
mpo, _ = mpo.compress(left=True, cutoff=1E-9, norm_cutoff=1E-9)
print('MPO (compressed) = ', mpo.show_bond_dims())
print('compress mpo time = ', time.perf_counter() - tx)

mps = hamil.build_mps(ket_bond_dim, occ=occ)
print('MPS = ', mps.show_bond_dims())

bdims = [500]
noises = [1E-4, 1E-5, 1E-6, 0]
davthrds = None

dmrg = MPE(mps, mpo, mps).dmrg(bdims=bdims,
                               noises=noises,
                               dav_thrds=davthrds,
                               iprint=2,
                               n_sweeps=20,
                               tol=1E-12)
ener = dmrg.energies[-1]
print("Energy = %20.12f" % ener)

isite = 4
mpo.const -= ener
omega, eta = -0.17, 0.05

dop = OpElement(OpNames.D, (isite, 0),
                q_label=SZ(-1, -1, hamil.orb_sym[isite]))
bra = hamil.build_mps(bra_bond_dim,
                      target=SZ.to_flat(dop.q_label +
                                        SZ.from_flat(hamil.target)))
dmpo = hamil.build_site_mpo(dop)