eaf.py 1.58 KB
Newer Older
Julien Lin's avatar
Julien Lin committed
1
2
3
4
5
6
7
8
9
import argparse
from matplotlib import pyplot as plt
import numpy as np
from snp import main as run
import multiprocessing
from joblib import Parallel, delayed

num_cores = multiprocessing.cpu_count()

Julien Lin's avatar
Julien Lin committed
10

Julien Lin's avatar
Julien Lin committed
11
12
13
14
15
def get_args_parse():
    can = argparse.ArgumentParser()

    can.add_argument("--nb-run", type=int, default=10, help="number of runs")

Julien Lin's avatar
Julien Lin committed
16
17
18
19
20
21
22
    can.add_argument(
        "--quality-threshold", type=float, default=600, help="Quality threshold"
    )

    can.add_argument(
        "--not-parallel", type=bool, default=False, help="launch runs sequentialy"
    )
Julien Lin's avatar
Julien Lin committed
23

Julien Lin's avatar
Julien Lin committed
24
25
    can.add_argument("--solver", type=str, default="num_random", help="Solver to use.")

Julien Lin's avatar
Julien Lin committed
26
27
28
29
30
31
32
33
34
    return can


def main():

    can = get_args_parse()

    the = can.parse_args()

Julien Lin's avatar
Julien Lin committed
35
36
    args = ["--solver", the.solver, "--iters", "2000", "--steady-delta", "500"]

Julien Lin's avatar
Julien Lin committed
37
38
39
    if the.not_parallel:
        results = []
        for i in range(the.nb_run):
Julien Lin's avatar
Julien Lin committed
40
            # print(f"{i}th run")
Julien Lin's avatar
Julien Lin committed
41
            results.append(run(args))
Julien Lin's avatar
Julien Lin committed
42
    else:
Julien Lin's avatar
Julien Lin committed
43

Julien Lin's avatar
Julien Lin committed
44
        def f(i):
Julien Lin's avatar
Julien Lin committed
45
            # print(f"{i}th run")
Julien Lin's avatar
Julien Lin committed
46
47
48
            return run(args)

        results = Parallel(n_jobs=num_cores)(delayed(f)(i) for i in range(the.nb_run))
Julien Lin's avatar
Julien Lin committed
49
50
51
52

    fig = plt.figure()

    ax3 = fig.add_subplot(111)
Julien Lin's avatar
Julien Lin committed
53
    plt.title(f"{the.solver}, threshold {the.quality_threshold}")
Julien Lin's avatar
Julien Lin committed
54
55
56
57
    values = [(val, iter) for val, iter, _, _ in results]

    values = sorted(values, key=lambda el: el[1])

Julien Lin's avatar
Julien Lin committed
58
59
60
    t = [iter for _, iter in values]
    values = np.array([val for val, _ in values])
    values = np.cumsum(values >= the.quality_threshold) / len(values)
Julien Lin's avatar
Julien Lin committed
61
62
63
64
65
66
67
68

    ax3.step(t, values)

    plt.show()


if __name__ == "__main__":
    main()