Beispiel #1
0
def main():
    direc = "C:/Users/Gunnar/Documents/Ph.D/Data/Static_MF/"
    name = "SMF_N=20_1/GS_N=20,U=0.0.txt"
    Psi = get_GS(direc + name)

    g1 = Psi.g1
    g2 = Psi.g2
    dt = 0.1
    d = Psi.d
    chi_init = Psi.chi
    N = Psi.N
    order = "fourth"
    model = "HCboson"

    H = st.Hamiltonian(g1,
                       g2,
                       N,
                       dt,
                       d,
                       chi_init,
                       model,
                       TO=order,
                       grow_chi=False)

    a = np.array([[0, 0], [1, 0]])
    adag = np.array([[0, 1], [0, 0]])
    num_op = np.matmul(adag, a)
    symmetry_check(Psi, H, a, "Ord. param.", plot=True)
    symmetry_check(Psi, H, num_op, "Density", plot=True)
Beispiel #2
0
def run_algo(g1, g2, N, dt, d, chi_max, model, order, T, algo, bis_err,
             trunc_err_check):
    H = st.Hamiltonian(g1, g2, N, dt, d, chi_max, model, order,
                       grow_chi=trunc_err_check)
    Psi = st.StateChain(g1, g2, N, d, chi_max, algo, bis_err)
    step_num = int(T / dt)
    H.time_evolve(Psi, step_num, algo, fast_run=True)
    return Psi, H
Beispiel #3
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
Beispiel #4
0
def err_gen(chi, Psi):
    Psi.chi = chi
    step_num = 10
    H = st.Hamiltonian(Psi.g1,
                       Psi.g2,
                       Psi.N,
                       0.1,
                       Psi.d,
                       Psi.chi,
                       model="HCboson",
                       TO="fourth")
    Psi = H.time_evolve(Psi, step_num, "tDMRG", fast_run=True)

    return Psi.err
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!")
def refine():
    model = "HCboson"
    
    N = int(sys.argv[1])
    U = float(sys.argv[2])
    
    dt = 0.1
    hom = os.path.expanduser("~")
    dname = hom + "/Data/Static_MF/SMF_N=" + str(N) + "_1/"
    fname = "GS_N=" + str(N) + ",U=" + str(U) + ".txt"
    
    Psi = get_GS(dname + fname)
    
    H = st.Hamiltonian(Psi.g1, Psi.g2, N, dt, Psi.d, Psi.chi, model,
                       TO="fourth")
    
    Psi = H.time_evolve(Psi, 1000, "tDMRG", fast_run=False)
    
    gs_mat = store_GS(Psi)
    
    cwd_folder = "refined_gsdata"
    
    cwd_store(cwd_folder, fname, gs_mat)
Beispiel #7
0
def main():
    # model = input("Enter model (Heisen, HCboson): ")
    model = "HCboson"

    # Fetches parameters from a file in current directory with name model.txt
    directory = (os.path.dirname(os.path.realpath(__file__)) + "/" + model +
                 ".txt")
    f = open(directory, "r")
    inputlist = []
    keylist = {}
    for line in f:
        if line.startswith('#'):
            continue
        d = []
        inputlist.append(line.rstrip('\n').split(" = "))
        x = inputlist[-1][0]
        yl = inputlist[-1][1].split(',')
        for y in yl:
            try:
                d.append(int(y))
            except ValueError:
                try:
                    d.append(float(y))
                except ValueError:
                    d.append(y)
        if len(d) == 1:
            d = d[0]
        keylist[x] = d
    f.close()

    g1 = keylist['g1']
    g2 = keylist['g2']
    dt = keylist['dt']  #Time step
    d = keylist['d']  #One-particle Hilbert space dim
    chi = keylist['chi']  #Maximum MPS dim
    N = keylist['N']  #Site number
    T = keylist['T']  #Total time evolved
    step_number = int(T / dt)  #Number of time steps
    order = keylist['order']  #Trotter order
    algo = keylist['algo']  #Which algorithm to use

    # H belongs to class Hamiltonian which features time evolution and model
    # construction.
    H = st.Hamiltonian(g1, g2, N, dt, d, chi, model, TO=order, grow_chi=False)

    # Build the initial state
    Psi = st.StateChain(g1, g2, N, d, chi, algo, bis_err=10**-11)

    # Time evolve the state (imaginary time)
    start = t.process_time()
    actstart = t.time()
    Psi = H.time_evolve(Psi, step_number, algo, fast_run=False)
    end = t.process_time()
    actend = t.time()
    print("Process time taken for algorithm is:", end - start)
    print("Actual time taken:", actend - actstart)

    # Output data to terminal
    algo_output(Psi, H)

    # Exact diagonalization trotter
    if N <= 20:
        start = t.process_time()
        ED = ed.ExactD(g1, g2, N, d, model, TO=order)
        end1 = t.process_time()
        ED.exact_GS()
        end2 = t.process_time()
        exact_output(ED)
        print("\nProcess time taken for full Hamiltonian:", end1 - start)
        print("\nProcess time taken for ED is:", end2 - end1)

    if model == "HCboson":
        Free = st.FreeFerm(g1, g2, N)
        print("\nFree fermion result:", Free.E_GS)

    # ener = 0
    # M = st.Measure()
    # for i in range(N):
    #     ener += M.correl()

    print(Psi.err)
    return Psi
Beispiel #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