forked from rajray84/MLVS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
RACOS_FFN.py
60 lines (46 loc) · 1.46 KB
/
RACOS_FFN.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import sys
import csv
import signal
import argparse
import signal
import time
from src.RacosFFNEvaluation import runRacos
printStatus= "Result: "
printTimeout= "\n\nTime taken : "
# Register an handler for the timeout
def handler(signum, frame):
raise Exception("")#kill running :: Timeout occurs")
def runSingleInstance(onnxFile,vnnlibFile):
#Variable Initialization
startTime = time.time()
onnxFileName = onnxFile.split('/')[-1]
vnnFileName = vnnlibFile.split('/')[-1]
print(f"\nNetwork model: {onnxFileName}")
print(f"Property file: {vnnFileName}")
while(1):
status = runRacos(onnxFile,vnnlibFile)
endTime = time.time()
timeElapsed = endTime - startTime
if (status == "violated"):
resultStr = ""
return resultStr
resultStr = printStatus +"Timeout"
return resultStr
#Main function
if __name__ == '__main__':
onnxFile= sys.argv[1]
vnnlibFile=sys.argv[2]
timeout=sys.argv[3]
# Register the signal function handler
signal.signal(signal.SIGALRM, handler)
# Define a timeout for "runSingleInstance"
signal.alarm(int(timeout))
'"runSingleInstance" will continue until any adversarial found or timeout occurs'
'When timeout occurs codes written within exception will be executed'
try:
retStatus = runSingleInstance(onnxFile,vnnlibFile)
print(retStatus)
except Exception as exc:
printStr = printStatus+"timeout"
print(printStr)
print(exc)