Browse Source

Merge branch 'DEVS' of msdl.uantwerpen.be:yentl/modelverse into DEVS

Yentl Van Tendeloo 7 years ago
parent
commit
da24fe7438
3 changed files with 61 additions and 33 deletions
  1. 60 0
      model/benchmark.py
  2. 0 32
      scripts/sim_loop.py
  3. 1 1
      wrappers/modelverse_SCCD.py

+ 60 - 0
model/benchmark.py

@@ -0,0 +1,60 @@
+from subprocess import call
+import time
+
+def run_real(samples):
+    with open("model/results_real", 'w') as f:
+        for _ in range(samples):
+            start = time.time()
+            call(["pypy", "-m", "pytest", "integration/test_powerwindow.py", "-k", "fast", "-x"])
+            print("Time to execute: " + str(time.time() - start))
+            f.write(str(time.time() - start))
+            f.write("\n")
+            f.flush()
+
+def run_simulation(latency):
+    import sys
+    sys.path.append("model")
+    from model import simulate
+    print("SIMULATE for " + str(latency))
+    result = simulate(latency)
+    print(result)
+    return result
+
+def benchmark(parallel, to_run):
+    if parallel:
+        from multiprocessing import Pool
+        pool = Pool(processes=4)
+        results = pool.map(run_simulation, to_run)
+    else:
+        results = map(run_simulation, to_run)
+    return results
+
+def benchmark_mvs(parallel, latency_range):
+    to_run = [{"mvk2mvs_latency": i} for i in latency_range]
+    results = benchmark(parallel, to_run)
+
+    print(results)
+    with open("model/results_mvs_latency", 'w') as f:
+        for latency, result in zip(to_run, results):
+            sim, exe = result
+            f.write("%s %s %s\n" % (latency, sim, exe))
+            f.flush()
+
+def benchmark_mvi(parallel, latency_range):
+    to_run = [{"mvi2mvk_latency": i} for i in latency_range]
+    results = benchmark(parallel, to_run)
+
+    print(results)
+    with open("model/results_mvi_latency", 'w') as f:
+        for latency, result in zip(to_run, results):
+            sim, exe = result
+            f.write("%s %s %s\n" % (latency, sim, exe))
+            f.flush()
+
+if __name__ == "__main__":
+    benchmark_mvs(parallel = False, latency_range=[0.0, 0.5])
+    benchmark_mvi(parallel = False, latency_range=[0.0, 0.5])
+    run_real(samples = 2)
+    #benchmark_mvs(parallel = False, latency_range=[0.0, 0.0017, 0.012, 0.02, 0.1, 0.5])
+    #benchmark_mvi(parallel = False, latency_range=[0.0, 0.0017, 0.012, 0.02, 0.1, 0.5])
+    #run_real(samples = 10)

+ 0 - 32
scripts/sim_loop.py

@@ -1,32 +0,0 @@
-# Run some experiments and store all values
-to_run = []
-for latency in [0 + i * 0.001 for i in range(0, 50)]:
-    to_run.append((latency, 0.0))
-for latency in [0 + i * 0.001 for i in range(50, 600, 50)]:
-    to_run.append((latency, 0.0))
-for latency in [0 + i * 0.001 for i in range(0, 50)]:
-    to_run.append((0.0, latency))
-for latency in [0 + i * 0.001 for i in range(50, 600, 50)]:
-    to_run.append((latency, 0.0))
-
-to_run = [(0.0, 0.0), (0.2, 0.2), (0.1, 0.1), (0.0, 0.2)]
-print(to_run)
-print("NR simulations: " + str(len(to_run)))
-
-def run_simulation(latency):
-    import sys
-    sys.path.append("model")
-    from model import simulate
-    latency_mvi, latency_mvs = latency
-    print("SIMULATE for " + str(latency))
-    results[(latency_mvi, latency_mvs)] = result = simulate({"mvi2mvk_latency": 0.0, "mvk2mvs_latency": 0.0})
-    print("(%s, %s) --> %s" % (latency_mvi, latency_mvs, result))
-    return result
-
-from multiprocessing import Pool
-pool = Pool(processors=4)
-results = pool.map(run_simulation, to_run)
-
-print(dict(to_run, results))
-with open("simloop_results", 'w') as f:
-    json.dump(f, results)

+ 1 - 1
wrappers/modelverse_SCCD.py

@@ -1,7 +1,7 @@
 """
 """
 Generated by Statechart compiler by Glenn De Jonghe, Joeri Exelmans, Simon Van Mierlo, and Yentl Van Tendeloo (for the inspiration)
 Generated by Statechart compiler by Glenn De Jonghe, Joeri Exelmans, Simon Van Mierlo, and Yentl Van Tendeloo (for the inspiration)
 
 
-Date:   Thu Jan  4 15:47:25 2018
+Date:   Fri Jan  5 08:43:03 2018
 
 
 Model author: Yentl Van Tendeloo
 Model author: Yentl Van Tendeloo
 Model name:   MvK Server
 Model name:   MvK Server