コード例 #1
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('filename')
    options = parser.parse_args()

    results = collections.defaultdict(list)

    with open(options.filename) as f:
        for line in f:
            for pattern in patterns:
                m = pattern.search(line)
                if m:
                    gd = m.groupdict()
                    iteration = gd['iter']
                    del gd['iter']
                    key, val = list(gd.items())[0]
                    results[key].append((float(iteration), float(val)))

    fig, ax = util.make_figure()

    for key, data in sorted(results.items()):
        x, y = list(zip(*data))
        ax.loglog(x, y, label=key)
        util.save_columns(options.filename + '-' + key + '.tsv', x, y)

    ax.set_xlabel('Conjugate Gradient Iteration')
    ax.set_ylabel('Spinor Norms')
    ax.set_title(options.filename)

    util.save_figure(fig, options.filename)
コード例 #2
0
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')
コード例 #3
0
def io_extract_mass(paths_in, path_out):
    twopts_orig = correlators.loader.folded_list_loader(paths_in)

    sample_count = 3 * len(twopts_orig)

    b_twopts = bootstrap.Boot(
        bootstrap.make_dist_draw(twopts_orig, sample_count))

    b_corr_matrix = bootstrap.Boot([
        correlators.corrfit.correlation_matrix(twopts)
        for twopts in b_twopts.dist
    ])

    omit_pre = 7

    b_inv_corr_mat = bootstrap.Boot([
        corr_matrix[omit_pre:, omit_pre:].getI()
        for corr_matrix in b_corr_matrix.dist
    ])

    time_extent = len(b_twopts.dist[0][0])
    time = np.arange(time_extent)

    fit_function = correlators.fit.cosh_fit_decorator(2 * (time_extent - 1))
    b_fit_param = bootstrap.Boot([
        perform_fits(time, bootstrap.average_arrays(twopts),
                     bootstrap.std_arrays(twopts), inv_corr_mat, fit_function,
                     (0.4, 1.0, 0.0), omit_pre)
        for twopts, inv_corr_mat in zip(b_twopts.dist, b_inv_corr_mat.dist)
    ])

    fig, ax = util.make_figure()
    ax.errorbar(time, bootstrap.average_arrays(b_twopts.cen),
                bootstrap.std_arrays(b_twopts.cen))
    ax.plot(time, fit_function(time, *b_fit_param.cen))
    ax.set_yscale('log')
    util.save_figure(fig, 'test-corr.pdf')

    print('cen', b_fit_param.cen[0])
    print('val', b_fit_param.val[0])
    print('err', b_fit_param.err[0])

    print('len', len(twopts_orig), len(b_fit_param.dist))

    np.savetxt(
        path_out,
        np.column_stack(
            [b_fit_param.cen[0], b_fit_param.val[0], b_fit_param.err[0]]))
コード例 #4
0
def plot_solver_data(path_in,
                     path_out,
                     ylabel,
                     title='Solver Data',
                     log_scale=False):
    fig, ax = util.make_figure()

    with open(path_in) as f:
        data = json.load(f)

    for solver, (x, y, yerr_down, yerr_up) in data.items():
        x = np.array(x)
        y = np.array(y)
        yerr_down = np.array(yerr_down)
        yerr_up = np.array(yerr_up)

        label = solver
        p = ax.plot(x, y, label=label)
        ax.fill_between(x,
                        y - yerr_down,
                        y + yerr_up,
                        alpha=0.3,
                        color=p[0].get_color())

    ax.set_title(title)
    ax.set_xlabel('Update Number')
    ax.set_ylabel(ylabel)

    if log_scale:
        ax.set_yscale('log')

    util.dandify_axes(ax)

    if log_scale:
        start, end = ax.get_ylim()
        print(start, end)
        print(end / start)
        if end / start < 15:
            start = 10**int(np.log10(start) - 1)
            end = 10**int(np.log10(end) + 1)
            print('{:.10g} {:.10g}'.format(start, end))
            ax.set_ylim(start, end)

    util.dandify_figure(fig)
    fig.savefig(path_out)
コード例 #5
0
def main():
    options = _parse_args()

    pattern = re.compile(
        r'0105-perf_nodes=(?P<A_nodes>\d+)_ntasks=(?P<B_ntasks>\d+)_cpus=(?P<C_cpus>\d+)_affinity=(?P<E_affinity>\w+?)/'
    )

    pattern_total_time = re.compile('HMC: total time = ([\d.]+) secs')

    rows = []

    for run in options.run:
        print(run)
        m = pattern.match(run)
        if not m:
            continue

        cols1 = m.groupdict()

        nodes = int(cols1['A_nodes'])
        tasks = int(cols1['B_ntasks'])
        cpus = int(cols1['C_cpus'])

        cols1['D_SMT'] = tasks * cpus // 24

        try:
            cols2 = {
                'QPhiX CG Perf':
                np.loadtxt(
                    os.path.join(
                        run,
                        'extract-solver-QPhiX_Clover_CG-gflops_per_node.tsv'))
                [1],
                'QPhiX M-Shift Perf':
                np.loadtxt(
                    os.path.join(
                        run,
                        'extract-solver-QPhiX_Clover_M-Shift_CG-gflops_per_node.tsv'
                    ))[1],
            }
        except FileNotFoundError as e:
            print(e)
            continue

        logfile = glob.glob(os.path.join(run, 'slurm-*.out'))[0]

        with open(logfile) as f:
            lines = f.readlines()

        m = pattern_total_time.match(lines[-1])
        if m:
            cols2['minutes'] = float(m.group(1)) / 60
        else:
            cols2['minutes'] = 0

        print(cols2.values())

        rows.append((cols1, cols2))

    print()
    print()

    for key in itertools.chain(sorted(cols1.keys()), sorted(cols2.keys())):
        print('{:15s}'.format(str(key)[:13]), end='')
    print()

    for cols1, cols2 in rows:
        for key, value in itertools.chain(sorted(cols1.items()),
                                          sorted(cols2.items())):
            print('{:15s}'.format(str(value)[:13]), end='')
        print()

    for x in cols1.keys():
        for y in cols2.keys():
            fig, ax = util.make_figure()
            data = collections.defaultdict(list)
            for c1, c2 in rows:
                data[c1[x]].append(c2[y])
            d = [value for key, value in sorted(data.items())]
            l = [key for key, value in sorted(data.items())]
            ax.boxplot(d, labels=l)
            ax.set_xlabel(x)
            ax.set_ylabel(y)

            util.save_figure(fig, 'boxplot-{}-{}'.format(x, y))
コード例 #6
0
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]))
コード例 #7
0

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))


source_0 = load_average_corr(
    glob.glob(
        '/home/mu/Dokumente/Studium/Master_Science_Physik/Masterarbeit/Runs/0120-Mpi270-L24-T96/corr/T=0/extract/corr/*.tsv'
    ))
source_20 = load_average_corr(
    glob.glob(
        '/home/mu/Dokumente/Studium/Master_Science_Physik/Masterarbeit/Runs/0120-Mpi270-L24-T96/corr/extract/corr/*.tsv'
    ))

fig, ax = util.make_figure()

print([x.shape for x in source_0])

ax.errorbar(source_0[0], source_0[1], source_0[2], label='T = 0')
ax.errorbar(source_20[0], source_20[1], source_20[2], label='T = 20')
ax.set_title('Different Source time with Chroma')
ax.set_xlabel(r'$t$')
ax.set_ylabel(r'$C(t)$')
ax.set_yscale('log')

util.save_figure(fig, 'chroma-source_t20')