Explorar el Código

Make the DEVS model take parameters

Yentl Van Tendeloo hace 7 años
padre
commit
fe048505b9
Se han modificado 3 ficheros con 99 adiciones y 82 borrados
  1. 14 4
      model/benchmark.py
  2. 83 76
      model/model.py
  3. 2 2
      model/results_mvs_latency

+ 14 - 4
model/benchmark.py

@@ -1,4 +1,4 @@
-from subprocess import call
+from subprocess import call, check_output
 import time
 
 def run_real(samples):
@@ -16,7 +16,17 @@ def run_simulation(latency):
     sys.path.append("model")
     from model import simulate
     print("SIMULATE for " + str(latency))
-    result = simulate(latency)
+    params = ["pypy", "model/model.py"]
+    for k, v in latency.items():
+        params.extend([k, str(v)])
+    output = check_output(params)
+    lines = output.split("\n")
+    for l in lines:
+        if l.startswith("Execution time "):
+            exec_time = float(l.split("Execution time ", 1)[1].strip())
+        elif l.startswith("Simulation time "):
+            sim_time = float(l.split("Simulation time ", 1)[1].strip())
+    result = (exec_time, sim_time)
     print(result)
     return result
 
@@ -30,7 +40,7 @@ def benchmark(parallel, to_run):
     return results
 
 def benchmark_mvs(parallel, latency_range):
-    to_run = [{"mvk2mvs_latency": i} for i in latency_range]
+    to_run = [{"mvk2mvs_latency": i, "mvs2mvk_latency": i} for i in latency_range]
     results = benchmark(parallel, to_run)
 
     print(results)
@@ -41,7 +51,7 @@ def benchmark_mvs(parallel, latency_range):
             f.flush()
 
 def benchmark_mvi(parallel, latency_range):
-    to_run = [{"mvi2mvk_latency": i} for i in latency_range]
+    to_run = [{"mvi2mvk_latency": i, "mvk2mvi_latency": i} for i in latency_range]
     results = benchmark(parallel, to_run)
 
     print(results)

+ 83 - 76
model/model.py

@@ -648,82 +648,82 @@ class System(CoupledDEVS):
         self.connectPorts(self.mvk.to_mvi, self.mvk2mvi.input_port)
         self.connectPorts(self.mvk2mvi.output_port, self.mvi.from_mvk)
 
-taskname = "test_task"
-
-operations = json.loads(open("model/operations", 'r').read())
-#operations = json.loads(open("model/operations_simple", 'r').read())
-additional_operations = [[], # revise_req
-                         [], # revise_environment
-                         [], # revise_plant
-                         [], # revise_control
-                         [], # revise_query
-                         [], # revise_architecture
-                         [], # make_initial_models
-                         [["instantiate_edge", "Association", "PLANT2EPN_link", "PW_Plant/State", "Encapsulated_PetriNet/Place"], ["instantiate_edge", "Association", "PLANT2EPN_tlink", "PW_Plant/Transition", "Encapsulated_PetriNet/Transition"]], # plant_to_EPN
-                         [["instantiate_edge", "Association", "CTRL2EPN_link", "PW_Control/State", "Encapsulated_PetriNet/Place"], ["instantiate_edge", "Association", "CTRL2EPN_tlink", "PW_Control/Transition", "Encapsulated_PetriNet/Transition"]], # control_to_EPN
-                         [["instantiate_edge", "Association", "ENV2EPN_link", "PW_Environment/Event", "Encapsulated_PetriNet/Place"]], # environment_to_EPN
-                         [["instantiate_edge", "Association", "EPN2PN_place_link", "Encapsulated_PetriNet/Place", "PetriNet/Place"], ["instantiate_edge", "Association", "EPN2PN_transition_link", "Encapsulated_PetriNet/Transition", "PetriNet/Transition"]], # EPN_to_PN
-                         [], # match
-                         [], # reachability
-                         [], # bfs
-                         [], # merge
-                        ]
-
-#additional_operations = [[]]
-keyed_operations = {"models/revise_req": [["upload"], compile_model("models/requirements_model.mvc")],
-                    "models/revise_plant": [["upload"], compile_model("models/plant_model.mvc")],
-                    "models/revise_environment": [["upload"], compile_model("models/environment_model.mvc")],
-                    "models/revise_control": [["upload"], compile_model("models/control_model.mvc")],
-                    "models/revise_query": [["upload"], compile_model("models/query_model.mvc")],
-                    "models/revise_architecture": [["upload"], compile_model("models/architecture_model.mvc")],
-                    }
-#keyed_operations = {"models/modify_lang": [["instantiate_node", "PN/Class", ""]]}
-finish_on = "FINISHED"
-
-args = {
-        "taskname":             taskname,
-        "operations":           operations,
-        "finish_on":            finish_on,
-        "mvi_additional":       additional_operations,
-        "mvi_keyed":            keyed_operations,
-        "mvi2mvk_latency":      0.0000001,
-        "mvi2mvk_bandwidth":    50000000000,
-        "mvk2mvs_latency":      0.0000001,
-        "mvk2mvs_bandwidth":    50000000000,
-        "mvs2mvk_latency":      0.0000001,
-        "mvs2mvk_bandwidth":    50000000000,
-        "mvk2mvi_latency":      0.0000001,
-        "mvk2mvi_bandwidth":    50000000000,
-        "time_per_phase":       0.05,
-        # Automatically filled in from calibration results, just here to prevent crashes (results for my UA desktop)
-        "read_root":            0.00001406669616699,
-        "create_node":          0.00000379181167487,
-        "create_edge":          0.00000601282282066,
-        "create_nodevalue":     0.00000501364247391,
-        "create_dict":          0.00001028065706205,
-        "read_value":           0.00000388661630500,
-        "read_outgoing":        0.00000520600098073,
-        "read_incoming":        0.00000645903181994,
-        "read_edge":            0.00000449162172644,
-        "read_dict":            0.00000460127038355,
-        "read_dict_keys":       0.00001678063432883,
-        "read_dict_node":       0.00001020808859528,
-        "read_dict_edge":       0.00000642558526942,
-        "read_dict_node_edge":  0.0,
-        "read_reverse_dict":    0.00002557890755790,
-        "delete_node":          0.00004755891187096,
-        "delete_edge":          0.00000683382081240,
-        "rule_generation":      0.00001543215873893,
-        "purge":                7.0,
-    }
-
-with open("calibration/averages", 'r') as param_file:
-    for l in param_file:
-        op, t = l.split(": ")
-        op = op.strip()
-        args[op] = float(t)
-
 def simulate(supplied_args):
+    taskname = "test_task"
+
+    operations = json.loads(open("model/operations", 'r').read())
+    #operations = json.loads(open("model/operations_simple", 'r').read())
+    additional_operations = [[], # revise_req
+                             [], # revise_environment
+                             [], # revise_plant
+                             [], # revise_control
+                             [], # revise_query
+                             [], # revise_architecture
+                             [], # make_initial_models
+                             [["instantiate_edge", "Association", "PLANT2EPN_link", "PW_Plant/State", "Encapsulated_PetriNet/Place"], ["instantiate_edge", "Association", "PLANT2EPN_tlink", "PW_Plant/Transition", "Encapsulated_PetriNet/Transition"]], # plant_to_EPN
+                             [["instantiate_edge", "Association", "CTRL2EPN_link", "PW_Control/State", "Encapsulated_PetriNet/Place"], ["instantiate_edge", "Association", "CTRL2EPN_tlink", "PW_Control/Transition", "Encapsulated_PetriNet/Transition"]], # control_to_EPN
+                             [["instantiate_edge", "Association", "ENV2EPN_link", "PW_Environment/Event", "Encapsulated_PetriNet/Place"]], # environment_to_EPN
+                             [["instantiate_edge", "Association", "EPN2PN_place_link", "Encapsulated_PetriNet/Place", "PetriNet/Place"], ["instantiate_edge", "Association", "EPN2PN_transition_link", "Encapsulated_PetriNet/Transition", "PetriNet/Transition"]], # EPN_to_PN
+                             [], # match
+                             [], # reachability
+                             [], # bfs
+                             [], # merge
+                            ]
+
+    #additional_operations = [[]]
+    keyed_operations = {"models/revise_req": [["upload"], compile_model("models/requirements_model.mvc")],
+                        "models/revise_plant": [["upload"], compile_model("models/plant_model.mvc")],
+                        "models/revise_environment": [["upload"], compile_model("models/environment_model.mvc")],
+                        "models/revise_control": [["upload"], compile_model("models/control_model.mvc")],
+                        "models/revise_query": [["upload"], compile_model("models/query_model.mvc")],
+                        "models/revise_architecture": [["upload"], compile_model("models/architecture_model.mvc")],
+                        }
+    #keyed_operations = {"models/modify_lang": [["instantiate_node", "PN/Class", ""]]}
+    finish_on = "FINISHED"
+
+    args = {
+            "taskname":             taskname,
+            "operations":           operations,
+            "finish_on":            finish_on,
+            "mvi_additional":       additional_operations,
+            "mvi_keyed":            keyed_operations,
+            "mvi2mvk_latency":      0.0000001,
+            "mvi2mvk_bandwidth":    50000000000,
+            "mvk2mvs_latency":      0.0000001,
+            "mvk2mvs_bandwidth":    50000000000,
+            "mvs2mvk_latency":      0.0000001,
+            "mvs2mvk_bandwidth":    50000000000,
+            "mvk2mvi_latency":      0.0000001,
+            "mvk2mvi_bandwidth":    50000000000,
+            "time_per_phase":       0.05,
+            # Automatically filled in from calibration results, just here to prevent crashes (results for my UA desktop)
+            "read_root":            0.00001406669616699,
+            "create_node":          0.00000379181167487,
+            "create_edge":          0.00000601282282066,
+            "create_nodevalue":     0.00000501364247391,
+            "create_dict":          0.00001028065706205,
+            "read_value":           0.00000388661630500,
+            "read_outgoing":        0.00000520600098073,
+            "read_incoming":        0.00000645903181994,
+            "read_edge":            0.00000449162172644,
+            "read_dict":            0.00000460127038355,
+            "read_dict_keys":       0.00001678063432883,
+            "read_dict_node":       0.00001020808859528,
+            "read_dict_edge":       0.00000642558526942,
+            "read_dict_node_edge":  0.0,
+            "read_reverse_dict":    0.00002557890755790,
+            "delete_node":          0.00004755891187096,
+            "delete_edge":          0.00000683382081240,
+            "rule_generation":      0.00001543215873893,
+            "purge":                7.0,
+        }
+
+    with open("calibration/averages", 'r') as param_file:
+        for l in param_file:
+            op, t = l.split(": ")
+            op = op.strip()
+            args[op] = float(t)
+
     local_args = dict(args)
     local_args.update(supplied_args)
     model = System(**local_args)
@@ -735,6 +735,13 @@ def simulate(supplied_args):
     return (tn, time.time() - start)
 
 if __name__ == "__main__":
-    ts, te = simulate({})
+    import sys
+    args = {}
+    i = 2
+    while i < len(sys.argv):
+        args[sys.argv[i]] = float(sys.argv[i+1])
+        i += 2
+    ts, te = simulate(args)
+
     print("Simulation time %s" % ts)
     print("Execution time %s" % te)

+ 2 - 2
model/results_mvs_latency

@@ -1,2 +1,2 @@
-0.00 289.1 706.5
-0.01 2000.0 710.1
+{'mvk2mvs_latency': 0.0, 'mvs2mvk_latency': 0.0} 701.855383873 292.109978817
+{'mvk2mvs_latency': 0.5, 'mvs2mvk_latency': 0.5} 680.295352936 292.109978817