Skip to content

Commit

Permalink
added multiprocessing to classifier
Browse files Browse the repository at this point in the history
  • Loading branch information
jacksonvanover committed Sep 8, 2020
1 parent f49edf0 commit 2c35e44
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 22 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
Expand All @@ -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
```
Expand Down
5 changes: 5 additions & 0 deletions frozenState/subset_testing_files/runTest.sh
Original file line number Diff line number Diff line change
@@ -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
Expand Down
13 changes: 6 additions & 7 deletions workspace/classify.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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__":
Expand All @@ -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)

Expand Down
36 changes: 23 additions & 13 deletions workspace/diffTester.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,16 @@
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
with that equivalence class, and creates/saves discrepancy objects
'''
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]

Expand Down Expand Up @@ -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 '''
Expand Down Expand Up @@ -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]))
Expand All @@ -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 = {}
Expand Down Expand Up @@ -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 = []
Expand All @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions workspace/runExperiment.sh
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 2c35e44

Please sign in to comment.