Browse Source

Faster HUTN compiler through the use of buffers

Yentl Van Tendeloo 5 years ago
parent
commit
15813c7019

+ 2 - 2
bootstrap/conformance_scd.alc

@@ -149,8 +149,8 @@ String function conformance_scd(model : Element):
 			type_name = read_type(model, model_name)
 			element = model["model"][model_name]
 
-			log("Check " + model_name)
-			log("   : " + type_name)
+			//log("Check " + model_name)
+			//log("   : " + type_name)
 
 			if (bool_not(dict_in(typing, model_name))):
 				return "Model has no type specified: " + model_info(model, model_name)!

+ 3 - 0
bootstrap/core_algorithm.alc

@@ -2075,7 +2075,10 @@ String function cmd_transformation_add_MT(source_models : Element, target_models
 	String new_model
 	// Finished with all information, now create the model itself!
 	output("Waiting for model constructors...")
+	Float start
+	start = time()
 	new_model = compile_model(input(), get_full_model(ramified_metamodel_id, get_entry_id("formalisms/SimpleClassDiagrams")))
+	log("Compile: " + cast_string(time() - start))
 	if (is_physical_string(new_model)):
 		return "Compilation error: " + cast_string(new_model)!
 	model_create(new_model, operation_name, ramified_metamodel_id, "ModelTransformation")

+ 9 - 0
bootstrap/modelling.alc

@@ -502,9 +502,13 @@ Element function construct_model_list(model : Element, list : Element):
 	String command
 
 	list = list_reverse(list)
+	Float start
+	Element timings
+	timings = dict_create()
 
 	while (list_len(list) > 0):
 		command = list_pop_final(list)
+		start = time()
 		if (command == "add_node"):
 			model_add_node(model, list_pop_final(list))
 		elif (command == "add_value"):
@@ -526,4 +530,9 @@ Element function construct_model_list(model : Element, list : Element):
 		else:
 			log("Modelling error: did not understand command " + command)
 
+		if bool_not(dict_in(timings, command)):
+			dict_add(timings, command, 0.0)
+		dict_overwrite(timings, command, cast_float(timings[command]) + time() - start)
+
+	log("Timings: " + dict_to_string(timings))
 	return model!

+ 14 - 0
examples/powerwindow.py

@@ -4,8 +4,18 @@ import os
 sys.path.append("wrappers")
 from modelverse import *
 
+global start
+start = time.time()
+
+def do_time(text):
+    global start
+    print("%s -- %s" % (time.time() - start, text))
+    start = time.time()
+
 init()
+do_time("init")
 login("admin", "admin")
+do_time("login")
 
 model_add("formalisms/ReachabilityGraph", "formalisms/SimpleClassDiagrams", open("models/ReachabilityGraph/metamodels/reachability_graph.mvc", "r").read())
 model_add("formalisms/PetriNet", "formalisms/SimpleClassDiagrams", open("models/PetriNets/metamodels/PetriNets.mvc", 'r').read())
@@ -18,6 +28,7 @@ model_add("formalisms/Query", "formalisms/SimpleClassDiagrams", open("models/Saf
 model_add("formalisms/Architecture", "formalisms/SimpleClassDiagrams", open("models/PowerWindow/metamodels/architecture.mvc", 'r').read())
 
 model_add("models/pm_powerwindow", "formalisms/ProcessModel", open("models/PowerWindow/PM_analyze.mvc", 'r').read())
+do_time("add models")
 
 transformation_add_MANUAL({"Requirements": "formalisms/Requirements"}, {"Requirements": "formalisms/Requirements"}, "models/revise_req")
 transformation_add_MANUAL({"Requirements": "formalisms/Requirements", "PW_Environment": "formalisms/PW_Environment"}, {"PW_Environment": "formalisms/PW_Environment"}, "models/revise_environment")
@@ -25,6 +36,7 @@ transformation_add_MANUAL({"Requirements": "formalisms/Requirements", "PW_Plant"
 transformation_add_MANUAL({"Requirements": "formalisms/Requirements", "PW_Control": "formalisms/PW_Control"}, {"PW_Control": "formalisms/PW_Control"}, "models/revise_control")
 transformation_add_MANUAL({"Requirements": "formalisms/Requirements", "Query": "formalisms/Query"}, {"Query": "formalisms/Query"}, "models/revise_query")
 transformation_add_MANUAL({"Requirements": "formalisms/Requirements", "Architecture": "formalisms/Architecture"}, {"Architecture": "formalisms/Architecture"}, "models/revise_architecture")
+do_time("add manual transformation")
 
 def tracability_CTRL2EPN(model):
     instantiate(model, "Association", ("PW_Control/State", "Encapsulated_PetriNet/Place"), ID="CTRL2EPN_link")
@@ -47,10 +59,12 @@ transformation_add_MT({"PW_Control": "formalisms/PW_Control"}, {"Encapsulated_Pe
 transformation_add_MT({"PW_Environment": "formalisms/PW_Environment"}, {"Encapsulated_PetriNet": "formalisms/Encapsulated_PetriNet"}, "models/environment_to_EPN", open("models/PowerWindow/transformations/environment_to_EPN.mvc", 'r').read(), tracability_ENV2EPN)
 transformation_add_MT({"Encapsulated_PetriNet": "formalisms/Encapsulated_PetriNet", "Architecture": "formalisms/Architecture"}, {"PetriNet": "formalisms/PetriNet"}, "models/combine_EPN", open("models/EncapsulatedPetriNets/transformations/combine.mvc", 'r').read(), tracability_EPN2PN)
 transformation_add_MT({"ReachabilityGraph": "formalisms/ReachabilityGraph", "Query": "formalisms/Query"}, {"ReachabilityGraph": "formalisms/ReachabilityGraph"}, "models/match", open("models/ReachabilityGraph/transformations/match_query.mvc", 'r').read())
+do_time("add MT transformation")
 
 transformation_add_AL({"PetriNet": "formalisms/PetriNet"}, {"ReachabilityGraph": "formalisms/ReachabilityGraph"}, "models/reachability", open("models/PetriNets/transformations/reachability.alc", 'r').read())
 transformation_add_AL({"ReachabilityGraph": "formalisms/ReachabilityGraph"}, {}, "models/bfs", open("models/ReachabilityGraph/transformations/bfs.alc", 'r').read())
 transformation_add_AL({"EPN_Plant": "formalisms/Encapsulated_PetriNet", "EPN_Control": "formalisms/Encapsulated_PetriNet", "EPN_Environment": "formalisms/Encapsulated_PetriNet"}, {"Encapsulated_PetriNet": "formalisms/Encapsulated_PetriNet"}, "models/merge_EPN", open("models/EncapsulatedPetriNets/transformations/merge.alc", 'r').read())
+do_time("add AL transformation")
 
 nr_of_operations = 6
 

+ 2 - 1
interface/HUTN/hutn_compiler/hutnparser.py

@@ -644,7 +644,8 @@ class Parser(object):
             return []
 
         rule = self.tokens[rulename]
-        mobj = re.match(rule['reg'], self.input[j:])
+        #mobj = re.match(rule['reg'], self.input[j:])
+        mobj = re.match(rule['reg'], buffer(self.input, j))
         #Changed by daniel instead of re.match(reg) did re.match(re.compile(reg).patern)
         #this is to avoid problems with \ before i did this i had the match the character \ by doing [\\\\]
         # because to write only two slashes it would have to be r'[\\]' which cant be done directly in hte grammar so it had to be in string form

+ 1 - 0
services/HUTN/main.py

@@ -71,6 +71,7 @@ def compile_service(port):
     except Exception as e:
         service_set(port, str(e))
         raise
+    print("Compilation time: " + str(time.time() - start))
 
 try:
     init(sys.argv[1])