Ejemplo n.º 1
0
def new_mu(coup1, coup2, N, dt, d, chi, T, num_op, old_mu, start_dens,
           rho_maxerr):
    goal_dens = 1 / 2
    Meas = st.Measure()
    order = "fourth"
    model = "HCboson"
    if start_dens < goal_dens:
        mu0 = old_mu
        dens0 = start_dens
    else:
        mu1 = old_mu
        dens1 = start_dens
    for ind in range(40):
        mu_ham = st.Hamiltonian(coup1,
                                coup2,
                                N,
                                dt,
                                d,
                                chi,
                                model,
                                TO=order,
                                grow_chi=False)
        mu_psi = st.StateChain(coup1, coup2, N, d, chi, "tDMRG")

        steps = int(T / dt)
        #for ind2 in range(5):
        mu_psi = mu_ham.time_evolve(mu_psi, steps, "tDMRG", fast_run=True)

        mu_dens = 0
        for m in range(N):
            mu_dens += Meas.expec(mu_psi, num_op, m)
        mu_dens /= N

        dens_err = abs((mu_dens - goal_dens)) / mu_dens

        if mu_dens > goal_dens:
            mu1 = coup2[0]
            dens1 = mu_dens
        else:
            mu0 = coup2[0]
            dens0 = mu_dens

        if abs(dens_err) < rho_maxerr or ind == 39:
            mu = coup2[0]
            if ind == 39:
                print("Density error:", dens_err)
            break
        else:
            yp = ([mu0, mu1] if mu0 < mu1 else [mu1, mu0])
            xp = ([dens0, dens1] if mu0 < mu1 else [dens1, dens0])

            coup2[0] = np.interp(goal_dens, xp, yp)

    return mu
Ejemplo n.º 2
0
def orp_from_GS(filename):
    Psi = get_GS(filename)
    M = st.Measure()
    a = np.array([[0, 0], [1, 0]])
    orp = 0
    qlen = int(Psi.N / 4)

    for orpind in range(qlen, 3 * qlen):
        orp += abs(M.expec(Psi, a, orpind))
    orp /= Psi.N / 2

    return orp
Ejemplo n.º 3
0
def filewrite(Psi, H, direc, T):
    a = np.array([[0, 0], [1, 0]])
    adag = np.array([[0, 1], [0, 0]])
    E_GS = sum(Psi.get_ener(H.Hchain))
    meas = st.Measure()
    corr_mat = meas.corr_mat(Psi, adag, a)
    
    name = ("chi=" + str(H.chi_max) + ",T=" + str(T) + ",dt=" + str(H.dt)
            + ",BE=" + str(Psi.bis_err))
    with open(direc+name+".txt",'x') as fw:
        fw.write(str(E_GS) + "\n")
        fw.write(str(Psi.err) + "\n")
        for correlations in corr_mat.reshape(Psi.N ** 2):
            fw.write(str(correlations) + "\n")
    fw.close()
Ejemplo n.º 4
0
def orp_meas(Psi, a, num_site):
    orp_meas = st.Measure()
    qlen = int(num_site / 4)
    hnum = int(num_site / 2)

    order_par = 0
    av_num_sites = 0

    for orpind in range(hnum - qlen, hnum + qlen):
        av_num_sites += 1
        order_par += abs(orp_meas.expec(Psi, a, orpind))

    order_par /= av_num_sites

    return order_par
Ejemplo n.º 5
0
def main():
    N = int(sys.argv[1])
    dt = float(sys.argv[2])
    T = int(sys.argv[3])
    chi = int(sys.argv[4])
    alf = float(sys.argv[5])
    step_num = int(T / dt)
    g1 = [1., 1.]
    g2 = [1., alf]
    d = 2
    algo = "tDMRG"

    H = st.Hamiltonian(g1,
                       g2,
                       N,
                       dt,
                       d,
                       chi,
                       model="HCboson",
                       TO="fourth",
                       grow_chi=False)
    Psi = st.StateChain(g1, g2, N, d, chi, algo)

    Psi = H.time_evolve(Psi, step_num, algo)

    M = st.Measure()

    adag = np.array([[0., 1.], [0, 0]])
    a = np.array([[0, 0], [1, 0]])
    corr_matrix = M.corr_mat(Psi, adag, a)
    E_GS = sum(Psi.get_ener(H.Hchain))

    data = [E_GS, Psi.err]
    corr_matrix = np.reshape(corr_matrix, (corr_matrix.shape[0]**2))
    data += [corr for corr in corr_matrix]

    direc_name = "alf=" + str(alf)
    file_name = "chi=" + str(chi) + ",T=" + str(T) + ",dt=" + str(dt) + ".txt"

    cwd_store(direc_name, file_name, data)
    print("Success!")
Ejemplo n.º 6
0
def symmetry_check(Psi, H, oper, tag, plot=False):
    M = st.Measure()
    
    measures = [abs(M.expec(Psi, oper, ind)) for ind in range(Psi.N)]
    
    residues = [abs(measures[ind]-measures[Psi.N-ind-1])/abs(measures[ind])
                for ind in range(Psi.N)]
    
    if plot:
        
        fig, axes = plt.subplots(nrows=2,ncols=1, sharex="row")
        plt.subplots_adjust(hspace=0.3)
        
        axes[0].plot(range(1, Psi.N+1), measures)
        axes[0].set_ylabel("Measure " + tag)
        axes[1].plot(range(1, Psi.N+1), residues)
        axes[1].set_xlabel("Site number")
        axes[1].set_ylabel("Residue")
        
        plt.show()
        
Ejemplo n.º 7
0
def algo_output(Psi, H):
    adag = np.array([[0, 1], [0, 0]])
    a = np.array([[0, 0], [1, 0]])
    num_op = np.matmul(adag, a)
    print("\nMPS algorithm results")
    E = Psi.get_ener(H.Hchain)
    print("GS energy:", sum(E))
    print("Bond energies:", E)

    if H.N < 12:
        B = Psi.B
        psi = B[0]
        for i in range(len(B) - 1):
            psi = np.tensordot(psi, B[i + 1], (i + 2, 1))
        psi = np.reshape(psi, (H.d**H.N))
        print("Energy from product state: ", sum(ed.ExactD.get_ener(H, psi)))

    M = st.Measure()
    dens = 0
    for i in range(H.N):
        dens += M.expec(Psi, num_op, i)
    print("Expec algo:", dens / H.N)
Ejemplo n.º 8
0
def SMF_loop(tperp, g1, g2, N, chi, T, rho_maxerr=1e-6, orp_maxerr=1e-6):
    dt = 0.1
    model = "HCboson"
    order = "fourth"
    d = 2
    algo = "tDMRG"

    step_num = int(T / dt)

    M = st.Measure()
    a = np.array([[0, 0], [1, 0]])
    adag = np.array([[0, 1], [0, 0]])
    num_op = np.matmul(adag, a)
    a_exp_guess = np.sqrt(1 / 2)
    i = 0
    err = 1
    g2[1] = 4 * tperp * a_exp_guess
    ord_pars = [a_exp_guess]
    mu_list = [g2[0]]
    dens = 1 / 2

    # Loops for at most 100 iterations. Some runs do not converge even at this
    # point.
    while i < 150 and err > orp_maxerr and ord_pars[-1] > 1e-8:
        H = st.Hamiltonian(g1,
                           g2,
                           N,
                           dt,
                           d,
                           chi,
                           model,
                           TO=order,
                           grow_chi=False)
        Psi = st.StateChain(g1, g2, N, d, chi, algo)
        Psi = H.time_evolve(Psi, step_num, algo, fast_run=True)

        new_dens = 0
        for k in range(N):
            new_dens += M.expec(Psi, num_op, k)
        new_dens /= N

        # Only finds a new chemical potential if density deviates too much from
        # the goal density. Finds a guess which should lie on the other side
        # of goal density.
        if abs(new_dens - dens) / dens > rho_maxerr:
            if new_dens > dens:
                over = True
            else:
                over = False
            mu_guess = guess_mu(g2[1], g1[1], tperp, over, new_dens)
            g2[0] = new_mu(g1, [mu_guess, g2[1]], N, dt, d, chi, T, num_op,
                           g2[0], new_dens, rho_maxerr)

        mu_list.append(g2[0])

        #        new_ord_par = M.expec(Psi, a, int(N / 2))
        new_ord_par = orp_meas(Psi, a, N)

        print(abs(new_ord_par))
        err = abs((abs(ord_pars[i]) - abs(new_ord_par)) / abs(ord_pars[i]))
        g2[1] = abs(4 * new_ord_par * tperp)
        i += 1
        ord_pars.append(abs(new_ord_par))

        # Some print statements to see if the convergence is coming along
        if i % 20 == 0:
            print("Error in order parameter is:", err)
            print("Truncation error:", Psi.err)
    print("Error in order parameter is:", err)
    print("Truncation error:", Psi.err)

    return ord_pars, Psi, mu_list