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.

115 lines
4.1 KiB

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