Example #1
0
 def save_vec(vec):
     fname = 'data/peps_vec1'
     np.save(fname, vec)
     e = bound_energy_fn(vec)
     elst.append(e)
     print ' --- save vec into fname=', fname, ' e=', e
     return 0
Example #2
0
def test_save():
    print '\n[test_gen]'
    shape = (nr, nc)
    # simple peps
    peps0 = peps.random(shape, pdim, bond, fac=rfac)
    vec = peps.flatten(peps0)
    np.save('data/peps_vec3by3', vec)
    dumpVcoeff.dump(peps0)
    return 0
Example #3
0
def test_load():
    print '[test_load]'
    shape = (nr, nc)
    # simple peps
    vec = np.load('data/peps_vec2by2.npy')
    peps0 = peps.aspeps(vec, (nr, nc), pdim, bond)
    ovlp, etot = energy_fpeps2by2(peps0)
    ovlp, php = nAverage_fpeps2by2(peps0)
    print 'etot=', ovlp, etot, etot / ovlp
    print 'nAverage=', ovlp, php, php / ovlp
    exit()

    def energy_fn(vec, pdim, bond):
        P = peps.aspeps(vec, (nr, nc), pdim, bond)
        PP, PHP = energy_fpeps2by2(P)
        e = PHP / PP
        print ' PHP,PP,PHP/PP,eav=', PHP, PP, e, e / (nr * nc)
        return PHP / PP

    def bound_energy_fn(vec):
        return energy_fn(vec, pdim, bond)

    vec = peps.flatten(peps0)
    import scipy.optimize
    import autograd

    deriv = autograd.grad(bound_energy_fn)
    print 'nparams=', len(vec)
    elst = []

    def save_vec(vec):
        fname = 'data/peps_vec1'
        np.save(fname, vec)
        e = bound_energy_fn(vec)
        elst.append(e)
        print ' --- save vec into fname=', fname, ' e=', e
        return 0

    # Optimize
    result = scipy.optimize.minimize(bound_energy_fn, jac=deriv, x0=vec,\
             tol=1.e-4, callback=save_vec)
    P0 = peps.aspeps(result.x, (nr, nc), pdim, bond)
    print "final =", energy_fn(peps.flatten(P0), pdim, bond)
    np.save('data/energy', elst)
    return 0
Example #4
0
def dump(peps0):
    shape = peps0.shape
    if shape == (2, 2):
        vcoeff = dump2by2(peps0)
        np.save('data/vcoeff2by2', vcoeff)
    elif shape == (2, 3):
        vcoeff = dump2by3(peps0)
        np.save('data/vcoeff2by3', vcoeff)
    elif shape == (3, 3):
        vcoeff = dump3by3(peps0)
        np.save('data/vcoeff3by3', vcoeff)
    print '\n[dumpVcoeff.dump] shape=', shape
    print 'shape=', vcoeff.shape
    print 'vcoeff<P|P>=', vcoeff.dot(vcoeff)
    print '<P|P>=', vcoeff.dot(vcoeff)
    return 0
Example #5
0
 def save_vec(vec):
     fname = 'peps_vec1_3by3'
     np.save(fname, vec)
     print ' --- save vec into fname=', fname
     return 0