Ejemplo n.º 1
0
def testHc_eigs(chi, d=2, eta=1E-14):
    """
    Tests that the sparse and dense Hc yield the same dominant eigenvector.
    (Specifically, that they yield eigenvectors of the same eigenvalue).
    """
    h = utils.random_complex((d, d, d, d))
    h = h.reshape((d**2, d**2))
    h = 0.5 * (h + np.conj(h.T))
    h = h.reshape((d, d, d, d))
    L_H = utils.random_complex((chi, chi))
    L_H = 0.5 * (L_H + np.conj(L_H.T))
    R_H = utils.random_complex((chi, chi))
    R_H = 0.5 * (R_H + np.conj(R_H.T))
    hlist = [h, L_H, R_H]

    A = utils.random_complex((d, chi, chi))
    mpslist = vumps.mixed_canonical(A)
    A_L, C, A_R = mpslist

    sparseEv = vumps.minimize_Hc(mpslist, hlist, eta).flatten()
    denseEv = vumps.Hc_dense_eigs(A_L, A_R, hlist).flatten()
    Hc = vumps.Hc_dense(A_L, A_R, hlist).reshape((chi**2, chi**2))

    Hvdense = np.dot(Hc, denseEv) / denseEv
    Hvsparse = np.dot(Hc, sparseEv) / sparseEv
    passed = np.allclose(Hvdense, Hvsparse)
    check(True, passed)
Ejemplo n.º 2
0
def testHAc(chi, d=2):
    """
    Tests that the sparse and dense apply_HAc give the same answer on random
    input.
    """
    h = utils.random_complex((d, d, d, d))
    A = utils.random_complex((d, chi, chi))
    mpslist = vumps.mixed_canonical(A)
    A_L, C, A_R = mpslist
    A_C = ct.rightmult(A_L, C)

    hL = utils.random_complex((chi, chi))
    hR = utils.random_complex((chi, chi))
    hlist = [h, hL, hR]
    Acp_sparse = vumps.apply_HAc(A_C, A_L, A_R, hlist)
    #print("Sparse: ", Acp_sparse)
    Acp_dense = vumps.apply_HAc_dense(A_C, A_L, A_R, hlist)
    # print("Dense: ", Acp_dense)
    # print("*")
    norm = np.linalg.norm(Acp_sparse - Acp_dense) / chi**2
    print("Test HAc.")
    print("Norm resid: ", norm)
    if norm < 1E-13:
        print("Passed!")
    else:
        print("Failed!")
Ejemplo n.º 3
0
def testHc(chi, d=2):
    """
    Tests that the sparse and dense apply_Hc give the same answer on random
    input.
    """
    h = utils.random_complex((d, d, d, d))
    A = utils.random_complex((d, chi, chi))
    mpslist = vumps.mixed_canonical(A)
    A_L, C, A_R = mpslist
    #h = 0.5*(h + np.conj(h.T))
    # A_L = utils.random_complex((d, chi, chi))
    # A_R = utils.random_complex((d, chi, chi))
    # C = utils.random_complex((chi, chi))
    hL = utils.random_complex((chi, chi))
    hR = utils.random_complex((chi, chi))
    hlist = [h, hL, hR]

    Cp_sparse = vumps.apply_Hc(C, A_L, A_R, hlist)
    print("Sparse: ", Cp_sparse)
    Cp_dense = vumps.apply_Hc_dense(C, A_L, A_R, hlist)
    print("Dense: ", Cp_dense)
    print("*")
    norm = np.linalg.norm(Cp_sparse - Cp_dense) / chi**2
    print("Norm resid: ", norm)
    if norm < 1E-13:
        print("Passed!")
    else:
        print("Failed!")
Ejemplo n.º 4
0
def maximize_overlap(thatmpslist, chi, thatAC=None, tol=1E-13):
    """
    Generate MPS tensors AL, C, AR of bond dimension chi, such
    that the overlap with the tensors in thatmpslist is maximized
    up to tolerance tol.
    """
    thatmpslist, thosefpoints = regauge(thatmpslist, tol=tol)
    thatAL, thatC, thatAR = thatmpslist
    print(np.diag(thatC))
    if thatAC is None:
        thatAC = ct.rightmult(thatAL, thatC)
    d, _, _ = thatAL.shape
    #IF CHANGING TO FLOAT LOOK HERE
    AL = utils.random_complex((d, chi, chi))
    AR = utils.random_complex((d, chi, chi))
    C = utils.random_complex((chi, chi))
    lam, L = tmeigs(thatAL,
                    B=np.conj(AL),
                    tol=0.01,
                    which="LM",
                    direction="left")
    _, R = tmeigs(thatAR,
                  B=np.conj(AR),
                  tol=0.01,
                  which="LM",
                  direction="right")
    AC = ct.gauge_transform(L, thatAC, R.T)
    C = ct.gauge_transform(L, thatC, R.T)
    AL, AR = gauge_match_polar(AC, C)
    delta = np.linalg.norm((ct.rightmult(AL, C) - AC / lam).flatten())
    while delta >= tol:
        print(delta)
        lam, L = tmeigs(thatAL,
                        B=np.conj(AL),
                        tol=delta / 10,
                        which="LM",
                        direction="left")
        _, R = tmeigs(thatAR,
                      B=np.conj(AR),
                      tol=delta / 10,
                      which="LM",
                      direction="right")
        AC = ct.gauge_transform(L, thatAC, R.T)
        C = ct.gauge_transform(L, thatC, R.T)
        print(np.diag(C))
        AL, AR = gauge_match_polar(AC, C)
        delta = np.linalg.norm((ct.rightmult(AL, C) - AC / lam).flatten())
    thismpslist = [AL, C, AR]
    return thismpslist
Ejemplo n.º 5
0
def randommps(d, n, maxchi, minlam=1E-13):
    chis = makechis(d, n, maxchi)
    lams = []
    for i in range(len(chis)):
        lamshape = (chis[i])
        thislam = utils.random_rng(lamshape, 0., 1.)
        thislam /= npla.norm(thislam)
        lams.append(thislam)

    gams = []
    for i in range(len(chis) - 1):
        gamshape = (d, chis[i], chis[i + 1])
        thisgam = utils.random_complex(gamshape)
        gams.append(thisgam)
    return lams, gams
Ejemplo n.º 6
0
def vumps_initial_tensor(d, chi, params, dtype=np.complex128):
    """
    Generate a random uMPS in mixed canonical forms, along with the left
    dominant eV L of A_L and right dominant eV R of A_R.
    """
    Ainit = utils.random_complex((d, chi, chi))
    if dtype == np.float64 or dtype == np.float32:
        Ainit = Ainit.real
    mpslist = mixed_canonical(Ainit)
    A_L, C, A_R = mpslist

    Cd = np.conj(C.T)
    rL = np.dot(Cd, C)
    lR = np.dot(C, Cd)
    lR /= np.trace(lR)
    rL /= np.trace(rL)
    A_C = ct.rightmult(A_L, C)
    fpoints = [rL, lR]
    return (mpslist, A_C, fpoints)
Ejemplo n.º 7
0
def RH_test(chi, d=2, tol=1E-11):
    """
    Tests that <L|R_H> = 0 where R_H is the renormalized effective 
    Hamiltonian of the right infinite block of a random uMPS with
    bond dimension chi. The Hamiltonian is randomized and Hermitian.
    """
    params = vumps.vumps_params()
    params["dom_ev_approx"] = False
    mpslist, rL, lR = vumps.vumps_initial_tensor(d, chi, params)
    A_L, C, A_R = mpslist
    # evl, evr, eVl, eVr = tm.tmeigs(A_R, nev=3, ncv=30, tol=1E-13,
    # which="both")

    #H = utils.random_hermitian(d*d).reshape((d,d,d,d))
    H = utils.H_ising(-1.0, -0.48).reshape((d, d, d, d))

    #RH = vumps.solve_for_RH(A_R, H, rL, params)
    RH = vumps.solve_for_RH(A_R, H, lR, params)
    proj = np.abs(vumps.proj(rL, RH))
    print("<L|RH>:", proj)
    if proj > tol:
        print("Failed!")
    else:
        print("Passed!")

    print("GAUGE MATCHING RANDOM AC AND C")
    mpslist, _, _ = vumps.vumps_initial_tensor(d, chi, params)
    A_C = utils.random_unitary(d * chi)[:, :chi].reshape((d, chi, chi))
    # A_C = utils.random_unitary(d*chi)[:, :chi].reshape(
    # (d, chi, chi))
    A_C = utils.random_complex((d, chi, chi))
    #C = np.diag(utils.random_rng(chi, 0.1, 1))
    C = utils.random_complex((chi, chi))
    A_L, A_R, _ = vumps.gauge_match_SVD(A_C, C, 1E-15)
    mpslist = [A_L, C, A_R]
    rL, lR = vumps.normalized_tm_eigs(mpslist, params)
    RH = vumps.solve_for_RH(A_R, H, rL, params)
    proj = np.abs(vumps.proj(rL, RH))
    print("<L|RH>:", proj)
    if proj > tol:
        print("Failed!")
    else:
        print("Passed!")

    print("GAUGE MATCHING CANONICAL AC AND C")
    mpslist, _, _ = vumps.vumps_initial_tensor(d, chi, params)
    A_L, C, A_R = mpslist
    A_C = ct.rightmult(A_L, C)
    A_L, A_R, _ = vumps.gauge_match_SVD(A_C, C, 1E-15)
    mpslist = [A_L, C, A_R]
    rL, lR = vumps.normalized_tm_eigs(mpslist, params)
    RH = vumps.solve_for_RH(A_R, H, rL, params)
    proj = np.abs(vumps.proj(rL, RH))
    print("<L|RH>:", proj)
    if proj > tol:
        print("Failed!")
    else:
        print("Passed!")

    print("TENSORS AFTER ONE VUMPS ITERATION")
    mpslist, rL, lR = vumps.vumps_initial_tensor(d, chi, params)
    A_L, C, A_R = mpslist
    A_C = ct.rightmult(A_L, C)
    vumps_state = [True, A_C, None, None]
    mpslist, delta, vumps_state = vumps.vumps_iteration(
        mpslist, H, params["delta_0"], params, vumps_state)
    A_L, C, A_R = mpslist
    rL, lR = vumps.normalized_tm_eigs(mpslist, params)

    RH = vumps.solve_for_RH(A_R, H, rL, params)
    proj = np.abs(vumps.proj(rL, RH))
    print("<L|RH>:", proj)
    if proj > tol:
        print("Failed!")
    else:
        print("Passed!")