<jupyter_start><jupyter_text>Plotting notebook Notebook to plot timing results and study the performance of the code.by <NAME>.<jupyter_code>import os
from glob import glob
import numpy as np
try:
    import matplotlib as mpl
    import matplotlib.pyplot as plt
except ModuleNotFoundError:
    print("matplotlib not found: I will now install it!")
    !pip install matplotlib
finally:
    import matplotlib as mpl
    import matplotlib.pyplot as plt
%matplotlib inline

# % mpl
mpl.rcParams['figure.figsize'] = (6, 6)
mpl.rcParams['font.size'] = 10
mpl.rcParams['font.weight'] = 'normal'
mpl.rcParams['axes.linewidth'] = 1.2
mpl.rcParams['xtick.major.pad'] = 8<jupyter_output><empty_output><jupyter_text>Read timing logs<jupyter_code>fnames = glob("timings/*.txt")

fnames = sorted(glob("timings/*.txt"))
data = {}
for fname in fnames:
    simulator_id = os.path.splitext(fname)[0][-1]
    data[simulator_id] = np.loadtxt(fname)

# extrapolate timing for `python` (id=0) for N=1e7
# (just for the sake of speed in returning the test; the timing takes 30 mins)
d = data["0"].copy()
new_entry = d[-1].copy()
new_entry[6] = 1e7
new_entry[8] = 0.1*0.001*1e7  # roughly linear extrapolation
data["0"] = np.concatenate((d, new_entry[None, :]))

# descriptions of simulators
desc = {
    '0': 'python',
    '1': 'jit',
    '2': 'jit-parallel',
    '3': 'jit-noloops',
    '4': 'python-noloops',
    '5': 'jit-parallel-fastmath',
}<jupyter_output><empty_output><jupyter_text>Plot the timing and convergence results<jupyter_code>fig, ax = plt.subplots(1, 1, figsize=(3, 3), dpi=200, facecolor='w')

s_to_ms = 1e3  # factor to convert from seconds (measured) to ms (plotted)

ax.plot(np.logspace(1, 7), 0.01*np.logspace(1, 7), 'k--',
       lw=0.5,
       label='linear (reference)')

for simulator_id, data_ in data.items():
    ax.plot(data_[:, 6], data_[:, 8]*s_to_ms, '.-', 
            lw=0.5,
            label=desc[simulator_id])

ax.grid(lw=0.2, which="both", axis='both')

ax.set_xscale('log')
ax.set_yscale('log')

ax.set_xticks(data["0"][:, 6])

ax.set_xlabel("num_monte_carlo_samples", fontsize=9)
ax.set_ylabel("t [ms]", fontsize=9)

ax.legend(fontsize=7, labelspacing=0.15, handletextpad=0.1, frameon=True)

fig.savefig('execution_time_vs_num_monte_carlo_samples.png', bbox_inches='tight')
fig, ax = plt.subplots(1, 1, figsize=(3, 3), dpi=200, facecolor='w')

# baseline: `python` id=0
baseline = data["0"][:, 8]

for simulator_id, data_ in data.items():
    ax.plot(data_[:, 6], baseline/data_[:, 8], '.-', 
            lw=0.5,
            label=desc[simulator_id])

ax.grid(lw=0.2, which="both", axis='both')

ax.set_xscale('log')

ax.set_xticks(data["0"][:, 6])

ax.set_xlabel("num_monte_carlo_samples", fontsize=9)
ax.set_ylabel("speedup", fontsize=9)

ax.legend(fontsize=7, labelspacing=0.15, handletextpad=0.1, frameon=True)

fig.savefig('speedup_vs_num_monte_carlo_samples.png', bbox_inches='tight')
fig, ax = plt.subplots(1, 1, figsize=(3, 3), dpi=200, facecolor='w')

ax.plot(np.logspace(1, 7), 50.*np.ones(50), 'k--',
       lw=0.5,
       label='expected value (50)')

for simulator_id, data_ in data.items():
    ax.plot(data_[:, 6], data_[:, 9], '.-', 
            lw=0.5,
            label=desc[simulator_id])

ax.grid(lw=0.2, which="both", axis='both')

ax.set_xscale('log')

ax.set_xticks(data["0"][:, 6])

ax.set_xlabel("num_monte_carlo_samples", fontsize=9)
ax.set_ylabel("Mean loss [$B]", fontsize=9)

ax.legend(fontsize=7, labelspacing=0.15, handletextpad=0.5, frameon=True, loc='lower right')

fig.savefig('mean_loss_vs_num_monte_carlo_samples.png', bbox_inches='tight')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.17820689655172414, 'fraction_numerical': 0.03531034482758621, 'mean_word_length': 4.820224719101123, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '478669', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 1531, 'n_tokens_neox': 1465, 'n_words': 284, 'path': 'benchmark/plot_timing_results.ipynb', 'repo_name': 'mtazzari/OasisHurricane', 'size': '3632'}