def experiment_2(): inputs = np.array([2, 15, 20, 30, 50, 80]) # 2,22,42, etc. FIXEd outputs = np.arange(2, 150, 1) # NON fixed prevalence = np.arange(0.1, 1.00, 0.1) # FIXED counteraverage = 15 prev = 0.6 # prev = 0.2 # prev = 0.4 # prev = 0.8 plt.plot([0, 150], [prev, prev], c="black", label="Supplied Prevalence") for inp in inputs: print(inp) nondeterminism = np.array([]) for outp in outputs: sumprevalence = 0 for _ in range(0, counteraverage): statemachine = generator.random_generator(inp, outp, prev) sumprevalence += generator.determine_non_determinism( statemachine) nondeterminism = np.append(nondeterminism, sumprevalence / counteraverage) plt.plot(outputs, nondeterminism, label="Inputs = {}".format(inp, prev)) plt.ylim(0.0, 1.0) plt.xlabel("Outputs") plt.ylabel("Measured Prevalence") plt.legend() plt.title("{} Prevalence of Non-Determinism".format(prev)) plt.savefig("results/Tester{}.png".format(prev))
def experiment_1(): x = np.arange(2, 100, 4) z = np.array([]) countaverage = 10 for val in x: print(val) sumprevalence = 0 for _ in range(0, countaverage): statemachine = generator.generate( generator.random_generator(val, val, 1.00)) sumprevalence += generator.determine_non_determinism(statemachine) z = np.append(z, sumprevalence / countaverage) plot2d(x, z, "Average Maximum Prevalence of Non-Determinism")
def experiment_1_probability(): # equal number inputs outputs x = np.arange(2, 200, 4) z = np.array([]) for val in x: print(val) temp = 0 for _ in range(0, 200): statemachine = generator.generate( generator.random_generator(val, val, 1.00)) temp = max(generator.determine_non_determinism(statemachine), temp) z = np.append(z, temp) plot2d(x, z, "Maximum Observed Prevalence of Non-Determinism")
def experiment_4(prevalence=0.2): """This runs experiment set 1 and writes it to the file "experiments4.csv" formatted as "Operation, Inputs, Outputs, Prevalence, Time in seconds" """ INPUT_RANGE = [30, 50, 80] DATAPOINT_SAMPLES = 7 # TODO AMOUNT_MODIFICATIONS = 3 TIMEOUT = 350 filename = "experiments3.csv" TRIES = 10 possible_modifications = [ modifications.delete, modifications.create, modifications.merge, modifications.split ] possible_modifications = [modifications.merge, modifications.split] for modification in possible_modifications: for inout in INPUT_RANGE: x = 0 n_try = TRIES while x < DATAPOINT_SAMPLES: x += 1 modifications.ar_file_input = defaultdict(list) modifications.ar_file_output = defaultdict(list) modifications.already_modified = [] elapsed_time = None try: rules = generator.random_generator(inout, inout, prevalence) statemachine = generator.generate(rules) modifications.populate_ar_file(statemachine) # Attempt to perform modifications statemachine_modified = False while not statemachine_modified: statemachine_modified, performed_modifications = modifications.perform_modifications( statemachine, possible_modifications=[modification], amount=AMOUNT_MODIFICATIONS) # Genereates the COMMA files hardcoded directory conversion.generate_conversion(statemachine, "V1", "test/v1/") conversion.generate_conversion(statemachine_modified, "V2", "test/v2/") # Create AR file and run CMD Comma create_ar_file() # Should now have directories containing files # TODO: Run FIONA here with TIME # fiona -t adapter SERVER.owfn CLIENT.owfn -a ARFILE.ar with open(filename, 'a+') as f: time_start = time.time() outpu = subprocess.check_output([ 'fiona', "-p", "no-dot", "-p", "no-png", '-t', "smalladapter", "test/v1/src-gen/DYNAMICS/openNetTask/V1__1_0__Server.owfn", "test/v2/src-gen/DYNAMICS/openNetTask/V2__1_0__Client.owfn", "-a", "test/ZARFILE.ar" ], timeout=TIMEOUT) elapsed_time = time.time() - time_start # CHeck if an adapter was created even outpu = outpu.decode("utf-8") print(outpu) if "Cannot synthesize a partner for a net" in outpu or "memory exhausted" in outpu: elapsed_time = -1 if n_try > 0: x -= 1 n_try -= 1 print("{},{},{},{},{},(good)".format( ".".join(performed_modifications), inout, inout, prevalence, elapsed_time), file=f) except Exception as e: # How to end up here: # -- If it was timed out after subprocess call # -- Non zero exit status that is memory exhaustion if "timed out after" in str(e): with open(filename, 'a+') as f: print("{},{},{},{},-1,(timed_out)".format( ".".join(performed_modifications), inout, inout, prevalence), file=f) elif "non-zero exit status 5" in str(e): with open(filename, 'a+') as f: print("{},{},{},{},-1,(exhausted)".format( ".".join(performed_modifications), inout, inout, prevalence), file=f) # This was a memory exhaustion else: x -= 1 if elapsed_time != None: n_try = TRIES
def experiment_1(prevalence=0.2): """This runs experiment set 1 and writes it to the file "experiments1.csv" formatted as "Operation, Inputs, Outputs, Prevalence, Time in seconds" """ INPUT_RANGE = [10, 30, 50] # INPUT_RANGE = [50,80] DATAPOINT_SAMPLES = 5 AMOUNT_MODIFICATIONS = 1 TIMEOUT = 350 filename = "experiments1.csv" # possible_modifications = [modifications.delete,modifications.create,modifications.merge,modifications.split] possible_modifications = [modifications.merge] performed_modifications = [x.__name__ for x in possible_modifications] for modification in possible_modifications: for inout in INPUT_RANGE: x = 0 while x < DATAPOINT_SAMPLES: modifications.ar_file_input = defaultdict(list) modifications.ar_file_output = defaultdict(list) modifications.already_modified = [] try: # Generate a ruleset # Parameters (Inputs, OUtputs and prevalence) rules = generator.random_generator(inout, inout, prevalence) statemachine = generator.generate(rules) # Pass-through modifications.populate_ar_file(statemachine) # Attempt to perform modifications statemachine_modified = False while not statemachine_modified: # Performed modifications will be a list of operations [Delete,Create] statemachine_modified, performed_modifications = modifications.perform_modifications( statemachine, possible_modifications=[modification], amount=AMOUNT_MODIFICATIONS) # Genereates the COMMA files hardcoded directory # From here have a modified statemachine conversion.generate_conversion(statemachine, "V1", "test/v1/") conversion.generate_conversion(statemachine_modified, "V2", "test/v2/") # Create AR file and run CMD Comma and get .ownf files create_ar_file() # Should now have directories containing files # fiona -t adapter SERVER.owfn CLIENT.owfn -a ARFILE.ar with open(filename, 'a+') as f: time_start = time.time() outpu = subprocess.check_output([ 'fiona', "-p", "no-dot", "-p", "no-png", '-t', "smalladapter", "test/v1/src-gen/DYNAMICS/openNetTask/V1__1_0__Server.owfn", "test/v2/src-gen/DYNAMICS/openNetTask/V2__1_0__Client.owfn", "-a", "test/ZARFILE.ar" ], timeout=TIMEOUT) elapsed_time = time.time() - time_start # CHeck if an adapter was created even outpu = outpu.decode("utf-8") print(outpu) if "Cannot synthesize a partner for a net" in outpu or "memory exhausted" in outpu: elapsed_time = -1 x -= 1 print("{},{},{},{},{},(good)".format( ".".join(performed_modifications), inout, inout, prevalence, elapsed_time), file=f) # USED TO INDICATE A GOOD RESULT x += 1 except Exception as e: # How to end up here: # -- If it was timed out after subprocess call # -- Non zero exit status that is memory exhaustion if "timed out after" in str(e): with open(filename, 'a+') as f: print("{},{},{},{},-1,(timed_out)".format( ".".join(performed_modifications), inout, inout, prevalence), file=f) elif "non-zero exit status 5" in str(e): with open(filename, 'a+') as f: print("{},{},{},{},-1,(exhausted)".format( ".".join(performed_modifications), inout, inout, prevalence), file=f) # This was a memory exhaustion else: with open(filename, 'a+') as f: print( "{},{},{},{},-1,(COULD NOT SYNTHESIZE)".format( ".".join(performed_modifications), inout, inout, prevalence), file=f)
# TODOOOO # [150,222,602,1687,2452]: # random.seed(5) # wrong = 0 # for x in range(5090): # if x in [150,222,602,1687,2452]: # continue # random.seed(x) # print(x) INPUTS = 2 OUTPUTS = 2 NONDETERMINISM = 0.0 statemachine_modified = False while not statemachine_modified: # rules = generator.random_generator(5,5,0.0) rules = generator.random_generator(INPUTS, OUTPUTS, 0.0) statemachine = generator.generate(rules) # populate it for transition in statemachine.transitions: if transition.input: ar_file_input[transition.name] = transition.name # This will be C -> S else: ar_file_output[transition.name] = transition.name # This will be S -> C statemachine_modified = perform_modifications(statemachine) # if statemachine_modified == False: # wrong += 1