def delta_delta_h(dirname): result = [] try: update_no_ddh, ddh = util.load_columns(os.path.join(dirname,'extract', 'extract-DeltaDeltaH.tsv'), 2) update_no_dh, dh = util.load_columns(os.path.join(dirname,'extract', 'extract-deltaH.tsv'), 2) except ValueError: pass else: for i, update_no in enumerate(update_no_ddh): j = np.where(update_no == update_no_dh)[0][0] print(update_no, '->', j) result.append((update_no, ddh[i] / dh[j])) np.savetxt(os.path.join(dirname,'extract', 'extract-DeltaDeltaH_over_DeltaH.tsv'), result)
def main(): options = _parse_args() fig, ax = util.make_figure() t, e = util.load_columns( '/home/mu/Dokumente/Studium/Master_Science_Physik/Masterarbeit//Runs/0106-bmw-rho011/shard-wflow.config-100.out.xml.e.tsv' ) t, w = util.load_columns( '/home/mu/Dokumente/Studium/Master_Science_Physik/Masterarbeit//Runs/0106-bmw-rho011/shard-wflow.config-100.out.xml.w.tsv' ) data = np.loadtxt('gradflow.000100', skiprows=1) tm_traj = data[:, 0] tm_t = data[:, 1] tm_P = data[:, 2] tm_Eplaq = data[:, 3] tm_Esym = data[:, 4] tm_tsqEplaq = data[:, 5] tm_tsqEsym = data[:, 6] tm_Wsym = data[:, 7] for i, method in enumerate( ['gradient', 'chain-gradient', 'explicit-sym', 'explicit-asym']): tm_my_w = wflow.derive_w(tm_t, tm_Esym, method=method) ax.plot(tm_t + 0.1 * i, np.abs(tm_Wsym - tm_my_w), label=method) ax.set_yscale('log') ax.set_xlabel('$t/a^2$ (shifted)') ax.set_ylabel( r'$\left|(w/a)^\mathrm{tmLQCD} - (w/a)^\mathrm{Method}\right|$') util.save_figure(fig, 'plot-wflow-norm') x = np.linspace(0, 4, 1000) y = np.sin(x) z = x * (x**2 * np.cos(x) + 2 * x * np.sin(x)) fig, ax = util.make_figure() for i, method in enumerate( ['gradient', 'chain-gradient', 'explicit-sym', 'explicit-asym']): w = wflow.derive_w(x, y, method=method) ax.plot(x + 0.1 * i, np.abs(z - w), label=method) ax.set_xlabel('$x$ (shifted)') ax.set_ylabel('absolute deviation from analytic $w(x)$') ax.set_yscale('log') util.save_figure(fig, 'plot-gradient-check')
def convert_tau0_to_md_time(file_in, file_out): result = [] try: update_no, tau0 = util.load_columns(file_in, 2) except ValueError as e: print(e) else: md_time = np.cumsum(tau0) assert tau0.shape == md_time.shape result = np.column_stack([update_no, md_time]) np.savetxt(file_out, result)
def visualize(xml_file, root=None): t, t2e = util.load_columns(xml_file + '.t2e.tsv') fig = pl.figure(figsize=(16, 9)) ax1 = fig.add_subplot(1, 2, 1) ax2 = fig.add_subplot(2, 2, 2) ax3 = fig.add_subplot(2, 2, 4) ax1.plot(t, t2e) ax1.plot(t, np.ones(t.shape) * 0.3) if root is not None: x, y = root #ax2 = pl.axes([.65, .6, .3, .3], axisbg='0.9') ax2.plot(t, t2e, marker='o') ax2.plot(t, np.ones(t.shape) * 0.3) sel = t < 3 * x ax3.plot(t[sel], t2e[sel]) ax3.plot(t[sel], np.ones(t[sel].shape) * 0.3) ax1.plot([x], [y], marker='o', alpha=0.3, color='red', markersize=20) ax2.plot([x], [y], marker='o', alpha=0.3, color='red', markersize=20) ax3.plot([x], [y], marker='o', alpha=0.3, color='red', markersize=20) ax2.set_xlim(0.7 * x, 1.3 * x) ax2.set_ylim(0.22, 0.38) #ax2.locator_params(nbins=6) #ax3.locator_params(nbins=6) ax1.set_title('All Computed Data') ax2.set_title('Interpolation') ax3.set_title('First $3 t_0$') for ax in [ax1, ax2, ax3]: ax.set_xlabel('Wilson Flow Time $t$') ax.set_ylabel(r'$t^2 \langle E \rangle$') util.dandify_axes(ax) util.dandify_figure(fig) fig.savefig(xml_file + '.t2e.pdf')
def folded_list_loader(filenames): all_folded = [] for filename in filenames: t, re, im = util.load_columns(filename) n = len(t) a = re second_rev = a[n // 2 + 1:][::-1] first = a[:n // 2 + 1] first[1:-1] += second_rev first[1:-1] /= 2. a = first all_folded.append(a) return all_folded
def plot_generic(path_in, path_out, xlabel, ylabel, title, use_auto_ylim=False): fig = pl.figure() ax = fig.add_subplot(1, 1, 1) x, y = util.load_columns(path_in, 2) if len(x) > 0: ax.plot(x, y, marker='o', markersize=2) ax.set_title(title) ax.set_xlabel(xlabel) ax.set_ylabel(ylabel) if use_auto_ylim: ax.set_ylim(get_auto_ylim(y)) util.dandify_axes(ax) util.dandify_figure(fig) pl.savefig(path_out)
def main(): options = _parse_args() R = 300 # Read in the data from the paper. a_inv_val = 1616 a_inv_err = 20 a_inv_dist = bootstrap.make_dist(a_inv_val, a_inv_err, n=R) aml, ams, l, t, trajectories, ampi_val, ampi_err, amk_val, amk_err, f_k_f_pi_val, f_k_f_pi_err = util.load_columns( 'physical_point/gmor.txt') ampi_dist = bootstrap.make_dist(ampi_val, ampi_err, n=R) amk_dist = bootstrap.make_dist(amk_val, amk_err, n=R) mpi_dist = [ampi * a_inv for ampi, a_inv in zip(ampi_dist, a_inv_dist)] mk_dist = [amk * a_inv for amk, a_inv in zip(amk_dist, a_inv_dist)] # Convert the data in lattice units into physical units. mpi_dist = [a_inv * ampi for ampi, a_inv in zip(ampi_dist, a_inv_dist)] mpi_val, mpi_avg, mpi_err = bootstrap.average_and_std_arrays(mpi_dist) mpi_sq_dist = [mpi**2 for mpi in mpi_dist] mpi_sq_val, mpi_sq_avg, mpi_sq_err = bootstrap.average_and_std_arrays( mpi_sq_dist) ampi_sq_dist = [ampi**2 for ampi in ampi_dist] ampi_sq_val, ampi_sq_avg, ampi_sq_err = bootstrap.average_and_std_arrays( ampi_sq_dist) # Do a GMOR fit in order to extract `a B` and `a m_cr`. popt_dist = [ op.curve_fit(gmor_pion, aml, ampi_sq)[0] for ampi_sq in ampi_sq_dist ] aB_dist = [popt[0] for popt in popt_dist] amcr_dist = [popt[1] for popt in popt_dist] aB_val, aB_avg, aB_err = bootstrap.average_and_std_arrays(aB_dist) amcr_val, amcr_avg, amcr_err = bootstrap.average_and_std_arrays(amcr_dist) print('aB =', siunitx(aB_val, aB_err)) print('am_cr =', siunitx(amcr_val, amcr_err)) ams_paper = -0.057 ams_phys = ams_paper - amcr_val ams_red = 0.9 * ams_phys ams_bare_red = ams_red + amcr_val print(ams_paper, ams_phys, ams_red, ams_bare_red) print() print('Mass preconditioning masses:') amlq = aml - amcr_val for i in range(3): amprec = amlq * 10**i + amcr_val kappa = 1 / (amprec * 2 + 8) print('a m_prec:', amprec) print('κ', kappa) exit() diff_dist = [ np.sqrt(2) * np.sqrt(mk**2 - 0.5 * mpi**2) for mpi, mk in zip(mpi_dist, mk_dist) ] diff_val, diff_avg, diff_err = bootstrap.average_and_std_arrays(diff_dist) popt_dist = [ op.curve_fit(linear, mpi, diff)[0] for mpi, diff in zip(mpi_dist, diff_dist) ] fit_x = np.linspace(np.min(mpi_dist), np.max(mpi_dist), 100) fit_y_dist = [linear(fit_x, *popt) for popt in popt_dist] fit_y_val, fit_y_avg, fit_y_err = bootstrap.average_and_std_arrays( fit_y_dist) # Physical meson masses from FLAG paper. mpi_phys_dist = bootstrap.make_dist(134.8, 0.3, R) mk_phys_dist = bootstrap.make_dist(494.2, 0.3, R) mpi_phys_val, mpi_phys_avg, mpi_phys_err = bootstrap.average_and_std_arrays( mpi_phys_dist) ampi_phys_dist = [ mpi_phys / a_inv for a_inv, mpi_phys in zip(a_inv_dist, mpi_phys_dist) ] amk_phys_dist = [ mk_phys / a_inv for a_inv, mk_phys in zip(a_inv_dist, mk_phys_dist) ] ampi_phys_val, ampi_phys_avg, ampi_phys_err = bootstrap.average_and_std_arrays( ampi_phys_dist) amk_phys_val, amk_phys_avg, amk_phys_err = bootstrap.average_and_std_arrays( amk_phys_dist) print('aM_pi phys =', siunitx(ampi_phys_val, ampi_phys_err)) print('aM_k phys =', siunitx(amk_phys_val, amk_phys_err)) new_b_dist = [ np.sqrt(mk_phys**2 - 0.5 * mpi_phys**2) - popt[0] * mpi_phys for mpi_phys, mk_phys, popt in zip(mpi_phys_dist, mk_phys_dist, popt_dist) ] diff_sqrt_phys_dist = [ np.sqrt(mk_phys**2 - 0.5 * mpi_phys**2) for mpi_phys, mk_phys in zip(mpi_phys_dist, mk_phys_dist) ] diff_sqrt_phys_val, diff_sqrt_phys_avg, diff_sqrt_phys_err = bootstrap.average_and_std_arrays( diff_sqrt_phys_dist) ex_x = np.linspace(120, 700, 100) ex_y_dist = [ linear(ex_x, popt[0], b) for popt, b in zip(popt_dist, new_b_dist) ] ex_y_val, ex_y_avg, ex_y_err = bootstrap.average_and_std_arrays(ex_y_dist) ams_art_dist = [ linear(mpi, popt[0], b)**2 / a_inv**2 / aB - amcr for mpi, popt, b, a_inv, aB, amcr in zip( mpi_dist, popt_dist, new_b_dist, a_inv_dist, aB_dist, amcr_dist) ] ams_art_val, ams_art_avg, ams_art_err = bootstrap.average_and_std_arrays( ams_art_dist) print('a m_s with artifacts', siunitx(ams_art_val, ams_art_err)) fig, ax = util.make_figure() ax.fill_between(fit_x, fit_y_val + fit_y_err, fit_y_val - fit_y_err, color='red', alpha=0.2) ax.plot(fit_x, fit_y_val, label='Fit', color='red') ax.fill_between(ex_x, ex_y_val + ex_y_err, ex_y_val - ex_y_err, color='orange', alpha=0.2) ax.plot(ex_x, ex_y_val, label='Extrapolation', color='orange') ax.errorbar(mpi_val, diff_val, xerr=mpi_err, yerr=diff_err, linestyle='none', label='Data (Dürr 2010)') ax.errorbar([mpi_phys_val], [diff_sqrt_phys_val], xerr=[mpi_phys_err], yerr=[diff_sqrt_phys_err], label='Physical Point (Aoki)') util.save_figure(fig, 'test') np.savetxt('artifact-bmw-data.tsv', np.column_stack([mpi_val, diff_val, mpi_err, diff_err])) np.savetxt('artifact-bmw-fit.tsv', np.column_stack([fit_x, fit_y_val])) np.savetxt('artifact-bmw-band.tsv', bootstrap.pgfplots_error_band(fit_x, fit_y_val, fit_y_err)) np.savetxt( 'artifact-phys-data.tsv', np.column_stack([[mpi_phys_val], [diff_sqrt_phys_val], [mpi_phys_err], [diff_sqrt_phys_err]])) np.savetxt('artifact-phys-fit.tsv', np.column_stack([ex_x, ex_y_val])) np.savetxt('artifact-phys-band.tsv', bootstrap.pgfplots_error_band(ex_x, ex_y_val, ex_y_err)) np.savetxt('artifact-ms.tsv', np.column_stack([mpi_val, ams_art_val, mpi_err, ams_art_err])) # Compute the strange quark mass that is needed to obtain a physical meson # mass difference, ignoring lattice artifacts. ams_phys_dist = [(amk_phys**2 - 0.5 * ampi_phys**2) / aB - amcr for ampi_phys, amk_phys, aB, amcr in zip( ampi_phys_dist, amk_phys_dist, aB_dist, amcr_dist)] ams_phys_cen, ams_phys_val, ams_phys_err = bootstrap.average_and_std_arrays( ams_phys_dist) print('M_K = {} MeV <== am_s ='.format(siunitx(494.2, 0.3)), siunitx(ams_phys_cen, ams_phys_err)) aml_phys_dist = [ op.newton(lambda aml: gmor_pion(aml, *popt) - ampi_phys**2, np.min(aml)) for popt, ampi_phys in zip(popt_dist, ampi_phys_dist) ] fit_x = np.linspace(np.min(aml_phys_dist), np.max(aml), 100) fit_y_dist = [ np.sqrt(gmor_pion(fit_x, *popt)) * a_inv for popt, a_inv in zip(popt_dist, a_inv_dist) ] fit_y_cen, fit_y_val, fit_y_err = bootstrap.average_and_std_arrays( fit_y_dist) np.savetxt('physical_point/mpi-vs-aml-data.tsv', np.column_stack([aml, mpi_val, mpi_err])) np.savetxt('physical_point/mpi-vs-aml-fit.tsv', np.column_stack([fit_x, fit_y_cen])) np.savetxt('physical_point/mpi-vs-aml-band.tsv', bootstrap.pgfplots_error_band(fit_x, fit_y_cen, fit_y_err)) aml_phys_val, aml_phys_avg, aml_phys_err = bootstrap.average_and_std_arrays( aml_phys_dist) mpi_cen, mpi_val, mpi_err = bootstrap.average_and_std_arrays(mpi_dist) #aml_240_val, aml_240_avg, aml_240_err = bootstrap.average_and_std_arrays(aml_240_dist) print('M_pi = {} MeV <== am_l ='.format(siunitx(134.8, 0.3)), siunitx(aml_phys_val, aml_phys_err)) #print('M_pi = 240 MeV <== am_l =', siunitx(aml_240_val, aml_240_err)) fig = pl.figure() ax = fig.add_subplot(2, 1, 1) ax.fill_between(fit_x, fit_y_val - fit_y_err, fit_y_val + fit_y_err, color='0.8') ax.plot(fit_x, fit_y_val, color='black', label='GMOR Fit') ax.errorbar(aml, mpi_val, yerr=mpi_err, color='blue', marker='+', linestyle='none', label='Data') ax.errorbar([aml_phys_val], [135], xerr=[aml_phys_err], marker='+', color='red', label='Extrapolation') #ax.errorbar([aml_240_val], [240], xerr=[aml_240_err], marker='+', color='red') ax.set_title('Extrapolation to the Physical Point') ax.set_xlabel(r'$a m_\mathrm{ud}$') ax.set_ylabel(r'$M_\pi / \mathrm{MeV}$') util.dandify_axes(ax) ax = fig.add_subplot(2, 1, 2) ax.hist(aml_phys_dist - aml_phys_val, bins=50) ax.locator_params(nbins=6) ax.set_title('Bootstrap Bias') ax.set_xlabel( r'$(a m_\mathrm{ud}^\mathrm{phys})^* - a m_\mathrm{ud}^\mathrm{phys}$') util.dandify_axes(ax) util.dandify_figure(fig) fig.savefig('physical_point/GMOR.pdf') np.savetxt('physical_point/ampi-sq-vs-aml.tsv', np.column_stack([aml, ampi_sq_val, ampi_sq_err])) np.savetxt('physical_point/mpi-sq-vs-aml.tsv', np.column_stack([aml, mpi_sq_val, mpi_sq_err]))
def load_average_corr(paths): t = util.load_columns(paths[0])[0] reals = [util.load_columns(path)[1] for path in paths] a = np.row_stack(reals) return t, np.mean(a, axis=0), np.std(a, axis=0) / np.sqrt(len(reals))
def find_root(tsv_file, threshold=0.3): t, t2e = util.load_columns(tsv_file) x = interpolate_root(t, t2e - threshold) return x
def io_compute_w(path_in, path_out): t, e = util.load_columns(path_in) w = derive_w(t, e) np.savetxt(path_out, np.column_stack([t, w]))
def io_compute_t2_e(path_in, path_out): t, e = util.load_columns(path_in) np.savetxt(path_out, np.column_stack([t, t**2 * e]))
def io_w0_to_a(path_in, path_out): update, w0_a = util.load_columns(path_in, 2) a_fm = w0_cont_fm / w0_a a_mev = mev_fm / a_fm np.savetxt(path_out, np.column_stack([update, a_mev]))
def io_time_to_minutes(path_in, path_out): update_no, seconds = util.load_columns(path_in, 2) np.savetxt(path_out, np.column_stack([update_no, seconds / 60]))
def io_delta_h_to_exp(path_in, path_out): t, delta_h = util.load_columns(path_in, 2) exp = np.exp(- delta_h) np.savetxt(path_out, np.column_stack([t, exp]))