From 2c35e44e6732f7275887b6042febc3b928607c1d Mon Sep 17 00:00:00 2001 From: Jackson Vanover Date: Tue, 8 Sep 2020 12:51:59 -0700 Subject: [PATCH] added multiprocessing to classifier --- README.md | 4 +-- frozenState/subset_testing_files/runTest.sh | 5 +++ workspace/classify.py | 13 ++++---- workspace/diffTester.py | 36 +++++++++++++-------- workspace/runExperiment.sh | 4 +++ 5 files changed, 40 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index b467105..c625a6c 100644 --- a/README.md +++ b/README.md @@ -86,7 +86,7 @@ of representative results. _The subset execution need not be undertaken if the full run is performed;_ it is provided as a convenience. Hyperparameters for FPDiff executions may be adjusted by editing `header.py`. -### [1.1] Running FPDiff on all discoverable functions (approx. 1.5 hours) +### [1.1] Running FPDiff on all discoverable functions (approx. 1 hour) ``` $ nohup ./run.sh ``` @@ -102,7 +102,7 @@ equivalence classes, and finally perform differential testing to discover numerical discrepancies. -### [1.2] Running FPDiff on a subset of representative functions (approx. 15 minutes) +### [1.2] Running FPDiff on a subset of representative functions (approx. 8 minutes) ``` $ nohup ./run.sh subset ``` diff --git a/frozenState/subset_testing_files/runTest.sh b/frozenState/subset_testing_files/runTest.sh index 3db3846..bde24ac 100644 --- a/frozenState/subset_testing_files/runTest.sh +++ b/frozenState/subset_testing_files/runTest.sh @@ -1,5 +1,10 @@ cd /usr/local/src/fp-diff-testing/workspace +echo "" +echo "** Loading Subset of Function Signatures" + +echo "" +echo "** Running Driver Generator" python3 driverGenerator.py mpmath python python3 driverGenerator.py scipy python python3 driverGenerator.py gsl c diff --git a/workspace/classify.py b/workspace/classify.py index 3486ece..cfd4082 100644 --- a/workspace/classify.py +++ b/workspace/classify.py @@ -112,7 +112,7 @@ def runDriver_parallelly(elementaryInput, driver, key): # printing progress bar sys.stdout.write('\r') - sys.stdout.write("[%-100s] %d%%" % ('='*int(i/lengthInput*100), int(i/lengthInput*100))) + sys.stdout.write("[%-100s] %d%%" % ('#'*int(i/lengthInput*100), int(i/lengthInput*100))) sys.stdout.flush() i+=1 @@ -345,18 +345,17 @@ def getStats(CLASSES): # gather some statistics, save the information with open("logs/statistics.txt", 'a') as f: f.write("\nTOTAL # OF CLASSES: {}\n".format(allClassTally)) - f.write("# OF NON-TRIVIAL CLASSES: {}\n".format(nontrivialClassTally)) - + def prettyPrintClasses(CLASSES): - print("==================================================") + print("--------------------------------------------") for counter, classKey in enumerate(CLASSES.keys()): print("Class {}:\n".format(counter)) for driver in CLASSES[classKey]: - print("{:<35} => {}".format(driver.get_driverName(), driver.get_id())) + print("{}".format(driver.get_driverName())) print() - print("==================================================") + print("--------------------------------------------") if __name__ == "__main__": @@ -373,7 +372,7 @@ def prettyPrintClasses(CLASSES): CLASSES = {} - print("Running classifier: ") + print("\n** Running Classifier: ") classify(CLASSES, DRIVER_LIST_MANAGER, ELEMENTARY_INPUTS) DRIVER_LIST = dict(DRIVER_LIST_MANAGER) diff --git a/workspace/diffTester.py b/workspace/diffTester.py index 1bf031e..bc1ae12 100644 --- a/workspace/diffTester.py +++ b/workspace/diffTester.py @@ -17,6 +17,9 @@ WD = os.path.dirname(os.path.abspath(__file__)) os.chdir(WD) +# diffTester ID for progress bar +diffTesterID = multiprocessing.Value("i", 1) +numDiffTester = 0 ''' takes in an equivalence class, gathers all test inputs to be used @@ -24,8 +27,6 @@ ''' def diffTester(classNo, classKey, totalClassCount, equivalenceClass, TEST_INPUTS, UNIQUE_DISCREPANCIES, ALL_DISCREPANCIES, USED_INPUTS): - print("Testing Class {}/{}".format(classNo, totalClassCount - 1)) - # grab all inputs tagged with "all_" inputNames = [x for x in TEST_INPUTS.keys() if "all_" in x] @@ -68,6 +69,12 @@ def diffTester(classNo, classKey, totalClassCount, equivalenceClass, TEST_INPUTS UNIQUE_DISCREPANCIES[x.get_id()] = x ALL_DISCREPANCIES.append(x) + + # printing progress bar + sys.stdout.write('\r') + sys.stdout.write("[%-100s] %d%%" % ('#'*int(diffTesterID.value/numDiffTester*100), int(diffTesterID.value/numDiffTester*100))) + sys.stdout.flush() + diffTesterID.value += 1 ''' function to write out a csv file of the results ''' @@ -163,11 +170,8 @@ def getStats(UNIQUE_DISCREPANCIES, ALL_DISCREPANCIES, USED_INPUTS): tempz.reverse() f.write("\nspecialValue_unique_discrepancyTally: {}\n".format(tempx)) - #f.write("\t# of Unique Discrepancies/# of Evals (# of Unique Inputs): {}/{} ({})\n".format(sum(list(specialValue_discrepancyTally.values())), specialValueEvals, specialValueInputTotal)) f.write("testMigration_unique_discrepancyTally: {}\n".format(tempy)) - #f.write("\t# of Unique Discrepancies/# of Evals (# of Unique Inputs): {}/{} ({})\n".format(sum(list(testMigration_discrepancyTally.values())), testMigrationEvals, testMigrationInputTotal)) f.write("s3fp_unique_discrepancyTally: {}\n".format(tempz)) - #f.write("\t# of Unique Discrepancies/# of Evals (# of Unique Inputs): {}/{} ({})\n".format(sum(list(s3fp_discrepancyTally.values())), s3fpEvals, s3fpInputTotal)) f.write("\nUNIQUE DISCREPANCY TOTALS:\n") f.write("\tTIMEOUTS: {}\n".format(total_discrepancyTally[6])) @@ -178,6 +182,14 @@ def getStats(UNIQUE_DISCREPANCIES, ALL_DISCREPANCIES, USED_INPUTS): f.write("\tMIX OF EXCEPTIONS AND SPECIAL VALUES: {}\n".format(total_discrepancyTally[1])) f.write("\n\t\tTOTAL # OF DISCREPANCIES: {}\n".format(sum(list(total_discrepancyTally.values())))) + # write contents of statistics file to stdout + with open("logs/statistics.txt", "r") as f: + line = f.readline() + print() + while line: + print(line, end='') + line = f.readline() + def inspect(UNIQUE_DISCREPANCIES): inspected_discrepancies = {} @@ -244,20 +256,15 @@ def runDiffTester(start, end): for i in range(start, end): diffTester(classNoList[i], classKeyList[i], len(list(CLASSES.keys())), CLASSES[classKeyList[i]], TEST_INPUTS, UNIQUE_DISCREPANCIES_MANAGER, ALL_DISCREPANCIES_MANAGER, USED_INPUTS_MANAGER) - # check user tuned multi-task number - if MAX_THREAD == "max": - NUM_MULTIPROCESSING = os.cpu_count() - elif MAX_THREAD > len(classNoList): - NUM_MULTIPROCESSING = os.cpu_count() - else: - NUM_MULTIPROCESSING = MAX_THREAD - # find break points for chunks of classes breakPoints = [] breakPoints.append(0) for i in range(1, NUM_MULTIPROCESSING): breakPoints.append(int(len(classNoList) * (i / NUM_MULTIPROCESSING))) breakPoints.append(len(classNoList)) + numDiffTester = len(classNoList) + + print("\n** Running Differential Tester: ") # create multi-process processes = [] @@ -270,6 +277,9 @@ def runDiffTester(start, end): for process in processes: process.join() + sys.stdout.write('\n') + + # convert multiprocess data structure back to normal python data structure UNIQUE_DISCREPANCIES = dict(UNIQUE_DISCREPANCIES_MANAGER) ALL_DISCREPANCIES = list(ALL_DISCREPANCIES_MANAGER) diff --git a/workspace/runExperiment.sh b/workspace/runExperiment.sh index abba45a..a6d8dc4 100755 --- a/workspace/runExperiment.sh +++ b/workspace/runExperiment.sh @@ -1,10 +1,14 @@ cd /usr/local/src/fp-diff-testing/workspace && make reset +echo "" +echo "** Running Extractor" python3 /usr/local/src/fp-diff-testing/workspace/extractor.py mpmath /usr/local/lib/python3.6/dist-packages/mpmath/tests/ python >> /usr/local/src/fp-diff-testing/workspace/logs/__extractedSignatures.txt python3 /usr/local/src/fp-diff-testing/workspace/extractor.py scipy /usr/local/lib/python3.6/dist-packages/scipy/special/tests/ python >> /usr/local/src/fp-diff-testing/workspace/logs/__extractedSignatures.txt python3 /usr/local/src/fp-diff-testing/workspace/extractor.py gsl /usr/local/lib/gsl/specfunc/ c >> /usr/local/src/fp-diff-testing/workspace/logs/__extractedSignatures.txt python3 /usr/local/src/fp-diff-testing/workspace/extractor.py jmat /usr/local/lib/jmat/ javascript >> /usr/local/src/fp-diff-testing/workspace/logs/__extractedSignatures.txt +echo "" +echo "** Running Driver Generator" python3 /usr/local/src/fp-diff-testing/workspace/driverGenerator.py mpmath python python3 /usr/local/src/fp-diff-testing/workspace/driverGenerator.py scipy python python3 /usr/local/src/fp-diff-testing/workspace/driverGenerator.py gsl c