<jupyter_start><jupyter_text>CHARITH LOOK HERE<jupyter_code>bad_blocks = [
    (i, d.block) for (i, d) in enumerate(data.test) if 
    not mem_free(d) and 
    dag_errs[i] < 0.3 and 
    llvm_errs[i] > 0.6 and 
    600 < d.y < 1000
]
len(bad_blocks)
times
qa = [d.y for d in data.data if 
      len(d.block.instrs) == 1 
      and not mem_free(d) and 
#      all(5 not in i.srcs for i in d.block.instrs) and
#      all(5 not in i.dsts for i in d.block.instrs) and
         d.block.instrs[0].opcode == 176
#       and d.y > 100
    ]
sns.distplot(qa)<jupyter_output><empty_output><jupyter_text>RE-RUN THIS CELL TO SAMPLE<jupyter_code>idx, block = random.choice(bad_blocks)
print('Actual: {}, errs: DAG: {:.2f}, LSTM: {:.2f}, LLVM: {:.2f}, IACA: {:.2f}'.format(
    actual[idx],
    dag_errs[idx],
    lstm_errs[idx],
    llvm_errs[idx],
    iaca_errs[idx],
))
block.draw()
q = next(b for b in data.data for i in b.block.instrs if ' ax' in str(i))
q.block.instrs[-1].srcs
q.block.draw()
def errof(preds):
    return np.abs(actual - preds) / actual
dag_errs = errof(ithemal_dag_pred)
lstm_errs = errof(ithemal_lstm_pred)
iaca_errs = errof(iaca_preds)
llvm_errs = errof(llvm_preds)
block_lens = np.array([len(d.block.instrs) for d in data.test])

def plot_legal(legal, title):
    max_txput = 1000
    
    legal_idxs = [i for i in range(len(data.test)) if legal(data.test[i])]
    
    errs = pd.DataFrame.from_items(
        zip(actual, zip(dag_errs, lstm_errs, iaca_errs, llvm_errs)), 
        orient='index', 
        columns=['dag_errs', 'lstm_errs', 'iaca_errs', 'llvm_errs']
    )
    errs = errs.iloc[legal_idxs]
    errs = errs[errs.index <= max_txput]

    means = errs.groupby(pd.cut(errs.index, 50)).mean().dropna()
    
    mids = [i.mid for i in means.index]
    err_ax = plt.gca()
    err_ax.plot(mids, means.lstm_errs, label='LSTM errors')
    err_ax.plot(mids, means.dag_errs, label='DAG errors')
    err_ax.plot(mids, means.iaca_errs, label='IACA errors')
    err_ax.plot(mids, means.llvm_errs, label='LLVM errors')
    err_ax.set_ylabel('Average error')
    err_ax.set_xlabel('Measured BB throughput')
    err_ax.legend(loc=0)
    
    cdf_ax = err_ax.twinx()
    legal_actual = actual[legal_idxs]
    legal_block_lens = block_lens[legal_idxs]
    actuals_to_hist = legal_actual[legal_actual <= max_txput]
    vals, bins = np.histogram(actuals_to_hist, bins=1000)
    vals = vals.astype(np.float64)
    vals /= vals.sum()
    vals = vals.cumsum()
    mids = (bins[:-1] + bins[1:]) / 2
    cdf_ax.plot(mids, vals, 'k--', label='CDF of block frequency')
    cdf_ax.legend(loc=0)
    
    plt.title('{} ({:.2f}%, LSTM err: {:.3f}, DAG err: {:.3f})'.format(
        title, 
        100.0 * len(legal_block_lens) / len(data.test),
        lstm_errs.mean(),
        dag_errs.mean(),
    ))

plt.figure(figsize=(8, 6))
plot_legal(mem_free, 'Memory-free blocks')

plt.figure(figsize=(8, 6))
plot_legal(lambda x: not mem_free(x), 'Memory-containing blocks')
plt.plot()
predictable_idxs = [
    i for (i, (_, r)) in enumerate(errs.iterrows()) if
#     r['dag_errs'] < .5 * r['lstm_errs'] and
#     r['dag_errs'] >= 0.05 and
    mem_free(data.test[i]) and
    actual[i] > 600 and actual[i] < 1000 and
    len(data.test[i].block.instrs) > 1 and
    True
]
len(predictable_idxs)
r = random.choice(predictable_idxs)
print('Test index {}\n\n{}\n\n'.format(
    r,
    '\n'.join(map(str, data.test[r].block.instrs))
))
print('Actual: {}\nDag pred: {:.0f} ({:.3f} err)\nLSTM Pred: {:.0f} ({:.3f} err)'.format(
    actual[r],
    ithemal_dag_pred[r], errs.iloc[r]['dag_errs'],
    ithemal_lstm_pred[r], errs.iloc[r]['lstm_errs'],
))
data.test[r].block.draw()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1701492537313433, 'fraction_numerical': 0.018995929443690638, 'mean_word_length': 3.4302884615384617, 'pattern_counts': {'":': 0, '<': 16, '<?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': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '480986', 'license': 'MIT', 'n_tokens_mistral': 1647, 'n_tokens_neox': 1562, 'n_words': 294, 'path': 'vm_setup/foreign/Ithemal/learning/pytorch/notebooks/Figures.ipynb', 'repo_name': 'qcjiang/pmevo-artifact', 'size': '3685'}