def spectral(tp, U, BETA, pade_fit_pts): rot = np.matrix([[-1, 1], [1, 1]]) / np.sqrt(2) filestr = 'disk/metf_HF_Ul_tp{}_B{}.h5'.format(tp, BETA) f, (gl, gd) = plt.subplots(1, 2, figsize=(18, 8)) with h5.File(filestr, 'r') as results: u = 'U' + str(U) lastit = results[u].keys()[-1] g_iw = getGiw(results[u][lastit]) greal = GfReFreq(indices=[0, 1], window=(-3.5, 3.5), n_points=500) greal.set_from_pade(g_iw, pade_fit_pts, 0.) gl.oplot(greal[0, 0], RI='S', label='out') gl.set_title('On site GF, fit pts' + str(pade_fit_pts)) gl.set_ylim([0, 0.6]) rgiw = rot * g_iw * rot greal.set_from_pade(rgiw, pade_fit_pts, 0.) gd.oplot(greal[0, 0], RI='S', label='bond') gd.oplot(greal[1, 1], RI='S', label='anti-bond') gd.set_title('Diagonal GF') gl.oplot(0.5 * (greal[0, 0] + greal[1, 1]), '--', RI='S', label='d avg') plt.show() plt.close()
def energies(beta, filestr='SB_PM_B{}.h5'): """returns the potential, and kinetic energy Parameters ---------- beta : float, inverse temperature filestr : string, results file name, beta is replaced in format Returns ------- tuple of 3 ndarrays Contains, potential energy, Kinetic energy, values of U """ tau, w_n = gf.tau_wn_setup(dict(BETA=beta, N_MATSUBARA=beta)) giw_free = gf.greenF(w_n) e_mean = ipt.e_mean(beta) ekin = [] epot = [] with h5.File(filestr.format(beta), 'r') as results: for u_str in results: last_iter = results[u_str].keys()[-1] _, giw = get_giw(results[u_str], last_iter, tau, w_n) siw = get_sigmaiw(results[u_str], last_iter, tau, w_n) u_int = float(u_str[1:]) epot.append(ipt.epot(giw, siw, u_int, beta, w_n)) ekin.append(ipt.ekin(giw, siw, beta, w_n, e_mean, giw_free)) ur = np.array([float(u_str[1:]) for u_str in results]) return np.array(epot), np.array(ekin), ur
def report_docc_acc(BETA, u_str, tp, filestr): """Returns the last iteration mean double occupation and acceptance rate""" with h5.File(filestr.format(tp=tp, BETA=BETA), 'r') as output_files: last_iter = output_files[u_str].keys()[-1] try: docc = output_files[u_str][last_iter]['double_occ'][:].mean() acc = output_files[u_str][last_iter]['acceptance'].value except KeyError: docc, acc = -1., -1. return docc, acc
def plot_acc(BETA, u_str, tp, filestr, skip=5): """Plot the evolution of the acceptance rate in each DMFT loop""" acceptance_log = [] with h5.File(filestr.format(tp=tp, BETA=BETA), 'r') as output_files: for it_name in list(output_files[u_str].keys())[skip:]: try: acceptance_log.append( output_files[u_str][it_name]['acceptance'].value) except KeyError: acceptance_log.append(0.) plt.plot(acceptance_log, 'o-') plt.title(r'Change of acceptance @ $\beta={}$, U={}'.format( BETA, u_str[1:])) plt.ylabel('Acceptance rate') plt.xlabel('iterations')
def get_docc(BETA, tp, filestr): """Recovers the double occupation from results files""" with h5.File(filestr.format(tp=tp, BETA=BETA), 'r') as output_files: docc = [] for u_str in output_files: last_iter = output_files[u_str].keys()[-1] try: docc.append([ float(u_str[1:]), output_files[u_str][last_iter]['double_occ'][:].mean() ]) except KeyError: pass docc = np.array(docc).T return docc[0], docc[1]
def dos_plot(BETA, tp, filestr, ax=None): """Plots double occupation""" if ax is None: _, ax = plt.subplots() with h5.File(filestr.format(tp=tp, BETA=BETA), 'r') as results: fl_dos = [] tau, w_n = gf.tau_wn_setup(dict(BETA=BETA, N_MATSUBARA=BETA)) for u_str in results: lastit = results[u_str].keys()[-1] giwd, _ = get_giw(results[u_str], lastit, tau, w_n) fl_dos.append(-1. / np.pi * gf.fit_gf(w_n[:3], giwd.imag)(0.)) u_range = np.array([float(u_str[1:]) for u_str in results.keys()]) ax.scatter(u_range, fl_dos, s=120, marker='>', vmin=0, vmax=2. / np.pi) ax.set_title('Hysteresis loop of the \n density of states') ax.set_ylabel(r'$A(\omega=0)$') ax.set_xlabel('U/D')
def ekin( BETA, tp=0.25, filestr='tp{tp}_B{BETA}.h5', ): e_mean = dimer.free_ekin(tp, BETA) tau, w_n = gf.tau_wn_setup(dict(BETA=BETA, N_MATSUBARA=BETA)) giw_free_d, _ = dimer.gf_met(w_n, 0., tp, 0.5, 0.) T = [] with h5.File(filestr.format(tp=tp, BETA=BETA), 'r') as results: for u_str in results: last_iter = results[u_str].keys()[-1] giwd, giwo = get_giw(results[u_str], last_iter, tau, w_n) siwd, siwo = get_sigmaiw(results[u_str], last_iter, tau, w_n) T.append(2 * (w_n * (giw_free_d - giwd).imag + giwd.imag * siwd.imag - giwo.real * siwo.real).sum() / BETA + e_mean) ur = np.array([float(u_str[1:]) for u_str in results]) return np.array(T), ur
def phase_diag_b(BETA_range, tp, filestr='HF_DIM_tp{tp}_B{BETA}.h5'): for BETA in BETA_range: tau, w_n = gf.tau_wn_setup(dict(BETA=BETA, N_MATSUBARA=BETA)) with h5.File(filestr.format(tp=tp, BETA=BETA), 'r') as results: fl_dos = [] for u_str in results.keys(): lastit = results[u_str].keys()[-1] giwd, _ = get_giw(results[u_str], lastit, tau, w_n) fl_dos.append(gf.fit_gf(w_n[:3], giwd.imag)(0.)) u_range = np.array([float(u_str[1:]) for u_str in results.keys()]) plt.scatter(u_range, np.ones(len(fl_dos)) / BETA, c=fl_dos, s=150, vmin=-2, vmax=0) plt.ylim([0, 0.04]) plt.title(r'Phase diagram at $t_\perp={}$'.format(tp)) plt.ylabel(r'$T/D$') plt.xlabel('$U/D$')
def epot( BETA, tp=0.25, filestr='tp{tp}_B{BETA}.h5', ): tau, w_n = gf.tau_wn_setup(dict(BETA=BETA, N_MATSUBARA=BETA)) wsqr_4 = 4 * w_n * w_n V = [] with h5.File(filestr.format(tp=tp, BETA=BETA), 'r') as results: for u_str in results: last_iter = results[u_str].keys()[-1] giwd, giwo = get_giw(results[u_str], last_iter, tau, w_n) siwd, siwo = get_sigmaiw(results[u_str], last_iter, tau, w_n) u_int = float(u_str[1:]) V.append( (giwo * siwo + giwd * siwd + u_int**2 / wsqr_4).real.sum() / BETA) ur = np.array([float(u_str[1:]) for u_str in results]) return np.array(V) - BETA * ur**2 / 32 + ur / 8., ur
def dmft_loop_pm(simulation): """Implementation of the solver""" setup = { 't': 0.5, 'BANDS': 1, 'SITES': 2, } if simulation['new_seed']: if comm.rank == 0: hf.set_new_seed(simulation, ['gtau_d', 'gtau_o']) simulation['U'] = simulation['new_seed'][1] return setup.update(simulation) setup['dtau_mc'] = setup['BETA'] / 2. / setup['N_MATSUBARA'] current_u = 'U' + str(setup['U']) tau, w_n = gf.tau_wn_setup(setup) intm = hf.interaction_matrix(setup['BANDS']) setup['n_tau_mc'] = len(tau) mu, tp, U = setup['MU'], setup['tp'], setup['U'] giw_d_up, giw_o_up = dimer.gf_met(w_n, 1e-3, tp, 0.5, 0.) giw_d_dw, giw_o_dw = dimer.gf_met(w_n, -1e-3, tp, 0.5, 0.) gmix = np.array([[1j * w_n, -tp * np.ones_like(w_n)], [-tp * np.ones_like(w_n), 1j * w_n]]) g0tail = [ np.eye(2).reshape(2, 2, 1), tp * np.array([[0, 1], [1, 0]]).reshape(2, 2, 1), np.array([[tp**2, 0], [0, tp**2]]).reshape(2, 2, 1) ] gtail = [ np.eye(2).reshape(2, 2, 1), tp * np.array([[0, 1], [1, 0]]).reshape(2, 2, 1), np.array([[tp**2 + U**2 / 4, 0], [0, tp**2 + U**2 / 4]]).reshape(2, 2, 1) ] giw_up = np.array([[giw_d_up, giw_o_up], [giw_o_dw, giw_d_dw]]) giw_dw = np.array([[giw_d_dw, giw_o_dw], [giw_o_up, giw_d_up]]) try: # try reloading data from disk with h5.File(setup['ofile'].format(**setup), 'r') as last_run: last_loop = len(last_run[current_u].keys()) last_it = 'it{:03}'.format(last_loop - 1) giw_d, giw_o = pd.get_giw(last_run[current_u], last_it, tau, w_n) except (IOError, KeyError): # if no data clean start last_loop = 0 V_field = hf.ising_v(setup['dtau_mc'], setup['U'], L=setup['SITES'] * setup['n_tau_mc'], polar=setup['spin_polarization']) for loop_count in range(last_loop, last_loop + setup['Niter']): # For saving in the h5 file dest_group = current_u + '/it{:03}/'.format(loop_count) setup['group'] = dest_group if comm.rank == 0: print('On loop', loop_count, 'beta', setup['BETA'], 'U', U, 'tp', tp) # Bethe lattice bath g0iw_up = mat_2_inv(gmix - 0.25 * giw_up) g0iw_dw = mat_2_inv(gmix - 0.25 * giw_dw) g0tau_up = gf.gw_invfouriertrans(g0iw_up, tau, w_n, g0tail) g0tau_dw = gf.gw_invfouriertrans(g0iw_dw, tau, w_n, g0tail) # Impurity solver gtu, gtd = hf.imp_solver([g0tau_up, g0tau_dw], V_field, intm, setup) giw_up = gf.gt_fouriertrans(-gtu, tau, w_n, gtail) giw_dw = gf.gt_fouriertrans(-gtd, tau, w_n, gtail) # Save output if comm.rank == 0: with h5.File(setup['ofile'].format(**setup), 'a') as store: store[dest_group + 'gtau_u'] = gtu store[dest_group + 'gtau_d'] = gtd h5.add_attributes(store[dest_group], setup) sys.stdout.flush()