parser.py 2.92 KB
Newer Older
Thom Badings's avatar
Thom Badings committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import argparse
from ast import literal_eval

def parser():
    '''
    Parse arguments provided on the command line

    Returns
    -------
    args : Object containing raw argument values

    '''

    # Define the parser
    P = argparse.ArgumentParser(description='Sampler interfact')
    
    # Declare an argument (`--algo`), saying that the
    # corresponding value should be stored in the `algo`
    # field, and using a default value if the argument
    # isn't given
    P.add_argument('--model', action="store", dest='model', default=0)
    P.add_argument('--property', action="store", dest='property', default=0)
Thom Badings's avatar
Thom Badings committed
23
    P.add_argument('--bisimulation', action="store", dest='bisim', default='strong')
Thom Badings's avatar
Thom Badings committed
24
25
26
    P.add_argument('--threshold', action="store", dest='threshold', default=0)
    P.add_argument('--num_samples', action="store", dest='num_samples', 
                   default=0)
Thom Badings's avatar
synch    
Thom Badings committed
27
28
    P.add_argument('--num_iter', action="store", dest='num_iter', default=1)
    P.add_argument('--comparator', action="store", dest='comparator', 
Thom Badings's avatar
Thom Badings committed
29
30
31
32
                   default=0)
    P.add_argument('--eta', action="store", dest='eta', default=0)
    P.add_argument('--beta', action="store", dest='beta', default=0)
    P.add_argument('--outfile', action="store", dest='outfile', 
Thom Badings's avatar
Thom Badings committed
33
                   default='output')
Thom Badings's avatar
Thom Badings committed
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75

    # Weather conditions for drone    
    P.add_argument('--weather', action="store", dest='weather', default=0)
    
    # Now, parse the command line arguments and store the
    # values in the `args` variable
    args = P.parse_args()
    
    return args

def parse_settings():
    '''
    Do some basic checks and store argument values in a dictionary

    Returns
    -------
    Z : Dictionary of arguments

    '''
    
    # Parse the arguments provided
    args = parser()
    
    # Interpret some arguments as lists
    beta=args.beta
    if beta != 0:
        try:
            beta = [float(args.beta)]
        except:
            beta = list(literal_eval(args.beta))
            
    try:
        num_samples = [int(args.num_samples)]
    except:
        num_samples = list(literal_eval(args.num_samples))
        
    try:
        eta = [int(args.eta)]
    except:
        eta = list(literal_eval(args.eta))
    
    try:
Thom Badings's avatar
synch    
Thom Badings committed
76
        comparator = literal_eval(args.comparator)
Thom Badings's avatar
Thom Badings committed
77
    except:
Thom Badings's avatar
synch    
Thom Badings committed
78
        comparator = [args.comparator]
Thom Badings's avatar
Thom Badings committed
79
    
Thom Badings's avatar
synch    
Thom Badings committed
80
    if any([c != "leq" and c != "geq" for c in comparator]):
Thom Badings's avatar
Thom Badings committed
81
82
83
84
85
86
87
88
89
90
91
92
93
94
        raise RuntimeError("Invalid direction type: should be 'leq' or 'geq'")
        
    # Store arguments in dictionary
    Z = {
        'model': args.model,
        'property': args.property,
        'bisimulation': args.bisim,
        #
        'iterations': int(args.num_iter),
        'Nsamples': num_samples,
        'eta': eta,
        'beta': beta,
        #
        'threshold': float(args.threshold),
Thom Badings's avatar
synch    
Thom Badings committed
95
        'comparator': comparator,
Thom Badings's avatar
Thom Badings committed
96
97
98
99
100
101
        #
        'outfile': str(args.outfile),
        #
        'weather': args.weather
        }
        
102
    return Z