2023-08-21 22:17:38 +05:30
|
|
|
import os
|
2023-08-16 12:42:41 +05:30
|
|
|
import typer
|
2023-08-21 22:17:38 +05:30
|
|
|
import json
|
|
|
|
|
import pandas as pd
|
|
|
|
|
import numpy as np
|
2023-08-16 12:42:41 +05:30
|
|
|
import logging as log
|
|
|
|
|
from pathlib import Path
|
2023-08-21 22:17:38 +05:30
|
|
|
import matplotlib.pyplot as plt
|
2023-08-16 12:42:41 +05:30
|
|
|
|
2023-08-21 22:17:38 +05:30
|
|
|
def read_json(fname):
|
|
|
|
|
with open(fname) as f:
|
|
|
|
|
cdata = json.load(f)
|
|
|
|
|
return cdata
|
2023-08-16 12:42:41 +05:30
|
|
|
|
|
|
|
|
|
2023-08-21 22:17:38 +05:30
|
|
|
def read_csv(fname):
|
|
|
|
|
df = pd.read_csv(fname, header=0, comment='#', skipinitialspace = True )
|
|
|
|
|
return df
|
2023-08-16 12:42:41 +05:30
|
|
|
|
|
|
|
|
|
2023-08-21 22:17:38 +05:30
|
|
|
def write_csv(df, fname):
|
|
|
|
|
df.to_csv(fname)
|
2023-08-16 12:42:41 +05:30
|
|
|
|
|
|
|
|
|
2023-08-21 22:17:38 +05:30
|
|
|
app = typer.Typer()
|
2023-08-16 12:42:41 +05:30
|
|
|
|
2023-08-21 22:17:38 +05:30
|
|
|
@app.command()
|
|
|
|
|
def views(ctx: typer.Context,
|
2023-08-16 12:42:41 +05:30
|
|
|
data_file: Path = typer.Option("simout.csv",
|
|
|
|
|
exists=True, file_okay=True, readable=True,
|
|
|
|
|
help="Set the simulation data file"),
|
|
|
|
|
oprefix: str = typer.Option("output",
|
|
|
|
|
help="Set the output prefix for the plots"),
|
|
|
|
|
debug: bool = typer.Option(True,
|
|
|
|
|
help="Set debug")
|
|
|
|
|
):
|
2023-08-21 22:17:38 +05:30
|
|
|
log.basicConfig(level=log.INFO)
|
|
|
|
|
tag = os.path.splitext(os.path.basename(data_file))[0]
|
|
|
|
|
|
|
|
|
|
df = read_csv(data_file)
|
|
|
|
|
steps_df = data=df.drop_duplicates('current_view').step_id.diff().values[1:]
|
|
|
|
|
views_df = df['current_view'].unique()[1:]
|
|
|
|
|
|
|
|
|
|
fig, axes = plt.subplots(1, 1, layout='constrained', sharey=False)
|
|
|
|
|
fig.set_figwidth(12)
|
|
|
|
|
fig.set_figheight(10)
|
|
|
|
|
|
|
|
|
|
fig.suptitle(f'View installation times :: {tag}')
|
|
|
|
|
axes.set_ylabel("Number of Epochs")
|
|
|
|
|
axes.set_xlabel("Views")
|
|
|
|
|
axes.set_xticks([x + 1 for x in range(max(views_df.astype(int)))])
|
|
|
|
|
axes.set_yticks([x + 1 for x in range(max(steps_df.astype(int)))])
|
|
|
|
|
|
2023-08-21 22:33:33 +05:30
|
|
|
|
|
|
|
|
# TODO: all nodes' current view change. currently we do only the earliest
|
|
|
|
|
|
2023-08-21 22:17:38 +05:30
|
|
|
axes.plot(views_df, steps_df, linestyle='--', marker='o')
|
|
|
|
|
plt.show()
|
|
|
|
|
plt.savefig(f'{oprefix}-view-installion-times.pdf', format="pdf", bbox_inches="tight")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@app.command()
|
|
|
|
|
def other_commands():
|
|
|
|
|
pass
|
2023-08-16 12:42:41 +05:30
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2023-08-21 22:17:38 +05:30
|
|
|
app()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|