Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import matplotlib.pyplot as plt
- import pandas as pd
- import ntpath
- import sys
- import os
- from subprocess import getstatusoutput as cmd
- from comment_parser import comment_parser
- def getCurrentOpt(sourceFiles):
- comments = []
- for file in sourceFiles:
- print(file)
- comments += comment_parser.extract_comments(file)
- comments = [c for c in comments if c.text().strip()[0] == 'O']
- currentMax = 0
- currentOpt = "none"
- for c in comments:
- comString = c.text().strip()
- # print(comString)
- strNum = comString.partition(' ')[0][1:].strip()
- if strNum != "":
- optNum = int(comString.partition(' ')[0][1:].strip())
- if optNum > currentMax:
- currentMax = optNum
- currentOpt = str(
- c.line_number()) + ": " + comString.partition(' ')[1:][1]
- return currentMax, currentOpt
- def runExperiment(executableName):
- return cmd("./" + executableName)[1]
- def backupResult(currentOpt):
- tempResultFile = currentOpt[0] + ".txt"
- backupResultFile = sys.argv[2] + "/" + str(currentOpt[1]) + ".res"
- os.rename(tempResultFile, backupResultFile)
- f = open(backupResultFile, "a")
- f.write("; " + currentOpt[2])
- f.close()
- f = open(sys.argv[2] + "/" + "incumbent", "w")
- f.write(str(currentOpt[1]))
- f.close()
- def readData():
- dfs = []
- dir = os.path.dirname(__file__) #<-- absolute dir the script is in
- dir = os.path.join(dir, sys.argv[2])
- for file in os.listdir(dir):
- if file.endswith(".res"):
- df = pd.read_fwf(os.path.join(dir, file), comment=';')
- agregated = df.groupby("sec").mean()
- agregated = agregated.drop(columns=["#it", "deg", "n_start", "n_end"])
- # agregated.columns = [file + "_" + col for col in agregated.columns]
- print(agregated)
- dfs.append([agregated, file])
- return dfs
- def plot():
- dfs = readData()
- agregated, file = dfs[0]
- print(file)
- # print(agregated)
- for objective in dfs[0][0].columns[:-1]:
- print("obj: " + objective)
- currentPlot = dfs[0][0][[objective]]
- currentPlot.columns = [dfs[0][1] for col in currentPlot.columns]
- # print(currentPlot)
- for agregated, file in dfs[1:]:
- agregated = agregated[[objective]]
- agregated.columns = [file for col in agregated.columns]
- # print(agregated)
- currentPlot = currentPlot.join(agregated, on="sec")
- print(currentPlot)
- currentPlot.plot()
- plt.title(sys.argv[2] + "\n" + objective)
- plt.xlabel("section")
- plt.ylabel("time [ns]")
- plt.show()
- if __name__ == '__main__':
- recompute = sys.argv[1]
- if recompute != "False":
- executable = sys.argv[3]
- sourceFiles = sys.argv[4:]
- currentOpt = getCurrentOpt(sourceFiles)
- currentOptimization = [executable, currentOpt[0], currentOpt[1]]
- experimentResult = runExperiment(executable)
- print(experimentResult)
- print(currentOptimization)
- backupResult(currentOptimization)
- plot()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement