summaryBench.py 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. # Process the test results
  2. # Test status (like passed, or failed with error code)
  3. import argparse
  4. import re
  5. import TestScripts.NewParser as parse
  6. import TestScripts.CodeGen
  7. from collections import deque
  8. import os.path
  9. import numpy as np
  10. import pandas as pd
  11. import statsmodels.api as sm
  12. import statsmodels.formula.api as smf
  13. import csv
  14. import TestScripts.Deprecate as d
  15. def findItem(root,path):
  16. """ Find a node in a tree
  17. Args:
  18. path (list) : A list of node ID
  19. This list is describing a path in the tree.
  20. By starting from the root and following this path,
  21. we can find the node in the tree.
  22. Raises:
  23. Nothing
  24. Returns:
  25. TreeItem : A node
  26. """
  27. # The list is converted into a queue.
  28. q = deque(path)
  29. q.popleft()
  30. c = root
  31. while q:
  32. n = q.popleft()
  33. # We get the children based on its ID and continue
  34. c = c[n-1]
  35. return(c)
  36. NORMAL = 1
  37. INTEST = 2
  38. TESTPARAM = 3
  39. def joinit(iterable, delimiter):
  40. it = iter(iterable)
  41. yield next(it)
  42. for x in it:
  43. yield delimiter
  44. yield x
  45. def formatProd(a,b):
  46. if a == "Intercept":
  47. return("%.3f" % b)
  48. return("%s * %.3f" % (a,b))
  49. def log2(x):
  50. return(np.log2(x))
  51. def log(x):
  52. return(np.log(x))
  53. def summaryBenchmark(resultPath,elem,path):
  54. regressionPath=os.path.join(os.path.dirname(path),"regression.csv")
  55. if os.path.isfile(path):
  56. print(" Generating %s" % regressionPath)
  57. full=pd.read_csv(path,dtype={'OLDID': str} ,keep_default_na = False)
  58. #print(full)
  59. csvheaders = []
  60. with open(os.path.join(resultPath,'currentConfig.csv'), 'r') as f:
  61. reader = csv.reader(f)
  62. csvheaders = next(reader, None)
  63. groupList = list(set(elem.params.full) - set(elem.params.summary))
  64. #grouped=full.groupby(list(elem.params.summary) + ['ID','CATEGORY']).max()
  65. #grouped.reset_index(level=grouped.index.names, inplace=True)
  66. #print(grouped)
  67. #print(grouped.columns)
  68. def reg(d):
  69. m=d["CYCLES"].max()
  70. #print( elem.params.formula)
  71. results = smf.ols('CYCLES ~ ' + elem.params.formula, data=d).fit()
  72. f=joinit([formatProd(a,b) for (a,b) in zip(results.params.index,results.params.values)]," + ")
  73. f="".join(f)
  74. f = re.sub(r':','*',f)
  75. #print(results.summary())
  76. return(pd.Series({'Regression':"%s" % f,'MAX' : m,'MAXREGCOEF' : results.params.values[-1]}))
  77. regList = ['ID','OLDID','CATEGORY','TESTNAME','NAME'] + csvheaders + groupList
  78. regression=full.groupby(regList).apply(reg)
  79. regression.reset_index(level=regression.index.names, inplace=True)
  80. renamingDict = { a : b for (a,b) in zip(elem.params.full,elem.params.paramNames)}
  81. regression = regression.rename(columns=renamingDict)
  82. regression.to_csv(regressionPath,index=False,quoting=csv.QUOTE_NONNUMERIC)
  83. def extractBenchmarks(resultPath,benchmark,elem):
  84. if not elem.data["deprecated"]:
  85. if elem.params:
  86. benchPath = os.path.join(benchmark,elem.fullPath(),"fullBenchmark.csv")
  87. print("Processing %s" % benchPath)
  88. summaryBenchmark(resultPath,elem,benchPath)
  89. for c in elem.children:
  90. extractBenchmarks(resultPath,benchmark,c)
  91. parser = argparse.ArgumentParser(description='Generate summary benchmarks')
  92. parser.add_argument('-f', nargs='?',type = str, default="Output.pickle", help="Test description cache")
  93. parser.add_argument('-b', nargs='?',type = str, default="FullBenchmark", help="Full Benchmark dir path")
  94. # Needed to find the currentConfig.csv and know the headers
  95. parser.add_argument('-r', nargs='?',type = str, default=None, help="Result file path")
  96. parser.add_argument('others', nargs=argparse.REMAINDER)
  97. args = parser.parse_args()
  98. if args.f is not None:
  99. #p = parse.Parser()
  100. # Parse the test description file
  101. #root = p.parse(args.f)
  102. root=parse.loadRoot(args.f)
  103. d.deprecate(root,args.others)
  104. resultPath=os.path.dirname(args.r)
  105. extractBenchmarks(resultPath,args.b,root)
  106. else:
  107. parser.print_help()