You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

133 lines
4.8 KiB

  1. import os
  2. import os.path
  3. import subprocess
  4. import re
  5. import time
  6. import argparse
  7. STORM_PATH= "/Users/mvolk/develop/dft-storm/build/src/storm-dft"
  8. EXAMPLE_DIR= "/Users/mvolk/develop/dft-storm/examples/dft/"
  9. benchmarks = [
  10. ("and", False, [3, 1]),
  11. ("and_param", True, ["(4*x^2+2*x+1)/((x) * (2*x+1))", "1"]),
  12. ("cardiac", False, [11378, 1]),
  13. ("cas", False, [0.859736, 1]),
  14. ("cm2", False, [0.256272, 1]),
  15. #("cm4", False, [0, 1]),
  16. ("cps", False, ["inf", 0.333333]),
  17. ("deathegg", False, [46.667, 1]),
  18. ("fdep", False, [0.666667, 1]),
  19. ("fdep2", False, [2, 1]),
  20. #("ftpp_complex", False, [0, 1]), # Compute
  21. #("ftpp_large", False, [0, 1]), # Compute
  22. #("ftpp_standard", False, [0, 1]), # Compute
  23. ("mdcs", False, [2.85414, 1]),
  24. ("mdcs2", False, [2.85414, 1]),
  25. ("mp", False, [1.66667, 1]),
  26. ("or", False, [1, 1]),
  27. ("pand", False, ["inf", 0.666667]),
  28. ("pand_param", True, ["-1", "(x)/(y+x)"]),
  29. ("pdep", False, [0, 1]), #Compute
  30. ("pdep2", False, [0, 1]), #Compute
  31. ("spare", False, [3.53846, 1]),
  32. ("spare2", False, [1.86957, 1]),
  33. ("spare3", False, [1.27273, 1]),
  34. ("spare4", False, [4.8459, 1]),
  35. ("spare5", False, [2.66667, 1]), # We discard the result 2.16667 from DFTCalc
  36. ("spare6", False, [1.4, 1]),
  37. ("spare7", False, [3.67333, 1]),
  38. ("symmetry", False, [4.16667, 1]),
  39. ("symmetry2", False, [3.06111, 1]),
  40. ("tripple_and1", False, [4.16667, 1]),
  41. ("tripple_and2", False, [3.66667, 1]),
  42. ("tripple_and2_c", False, [3.6667, 1]),
  43. ("tripple_and_c", False, [4.16667, 1]),
  44. ("tripple_or", False, [0.5, 1]),
  45. ("tripple_or2", False, [0.666667, 1]),
  46. ("tripple_or2_c", False, [0.66667, 1]),
  47. ("tripple_or_c", False, [0.5, 1]),
  48. ("tripple_pand", False, ["inf", 0.0416667]),
  49. ("tripple_pand2", False, ["inf", 0.166667]),
  50. ("tripple_pand2_c", False, ["inf", 0.166667]),
  51. ("tripple_pand_c", False, ["inf", 0.0416667]),
  52. ("voting", False, [1.66667, 1]),
  53. ("voting2", False, [0.588235, 1])
  54. ]
  55. def run_storm_dft(filename, prop, parametric, quiet):
  56. # Run storm-dft on filename and return result
  57. dft_file = os.path.join(EXAMPLE_DIR, filename + ".dft")
  58. args = [STORM_PATH,
  59. dft_file,
  60. prop]
  61. if parametric:
  62. args.append('--parametric')
  63. output = run_tool(args, quiet)
  64. # Get result
  65. match = re.search(r'Result: \[(.*)\]', output)
  66. if not match:
  67. return None
  68. result = match.group(1)
  69. return result
  70. def run_tool(args, quiet=False):
  71. """
  72. Executes a process,
  73. :returns: the `stdout`
  74. """
  75. pipe = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
  76. result = "";
  77. for line in iter(pipe.stdout.readline, ""):
  78. if not line and pipe.poll() is not None:
  79. break
  80. output = line.decode(encoding='UTF-8').rstrip()
  81. if output != "":
  82. if not quiet:
  83. print("\t * " + output)
  84. result = output
  85. return result
  86. def isclose(a, b, rel_tol=1e-09, abs_tol=0.0):
  87. if a == b:
  88. return True
  89. return abs(a-b) <= max(rel_tol * max(abs(a), abs(b)), abs_tol)
  90. if __name__ == "__main__":
  91. parser = argparse.ArgumentParser(description='Benchmarking DFTs via Storm')
  92. parser.add_argument('--debuglevel', type=int, default=0, help='the debug level (0=silent, 1=print benchmarks, 2=print output from storm')
  93. args = parser.parse_args()
  94. count = 0
  95. correct = 0
  96. properties = ['--expectedtime', '--probability']
  97. start = time.time()
  98. for index, prop in enumerate(properties):
  99. for (benchmark, parametric, result_original) in benchmarks:
  100. expected_result = result_original[index]
  101. # Run benchmark and check result
  102. count += 1;
  103. if args.debuglevel > 0:
  104. print("Running '{}' with property '{}'".format(benchmark, prop))
  105. result = run_storm_dft(benchmark, prop, parametric, args.debuglevel<2)
  106. if result is None:
  107. print("Error occurred on example '{}' with property '{}'".format(benchmark, prop))
  108. continue
  109. if not parametric:
  110. # Float
  111. result = float(result)
  112. if not isclose(result, float(expected_result), rel_tol=1e-05):
  113. print("Wrong result on example '{}' with property '{}': result: {}, Expected: {}".format(benchmark, prop, result, expected_result))
  114. else:
  115. correct += 1
  116. else:
  117. # Parametric
  118. if result != expected_result:
  119. print("Wrong result on example '{}' with property '{}': result: {}, Expected: {}".format(benchmark, prop, result, expected_result))
  120. else:
  121. correct += 1
  122. end = time.time()
  123. print("Correct results for {} of {} DFT checks in {}s".format(correct, count, end-start))