|
1 | | -import argparse |
2 | | - |
3 | | -import mpmath |
4 | | - |
5 | | -from .diophantine import set_random_seed |
6 | | -from .gridsynth import gridsynth_gates |
7 | | -from .loop_controller import LoopController |
8 | | - |
9 | | -helps = { |
10 | | - "dt": "Diophantine algorithm timeout in milliseconds", |
11 | | - "ft": "Factoring algorithm timeout in milliseconds", |
12 | | - "dl": "Diophantine algorithm max loop count", |
13 | | - "fl": "Factoring algorithm max loop count", |
14 | | - "seed": "Random seed for deterministic results", |
15 | | -} |
16 | | - |
17 | | - |
18 | | -def main(): |
19 | | - parser = argparse.ArgumentParser() |
20 | | - |
21 | | - parser.add_argument("theta", type=str) |
22 | | - parser.add_argument("epsilon", type=str) |
23 | | - parser.add_argument("--dps", type=int, default=None) |
24 | | - parser.add_argument("--dtimeout", "-dt", type=float, default=None, help=helps["dt"]) |
25 | | - parser.add_argument("--ftimeout", "-ft", type=float, default=None, help=helps["ft"]) |
26 | | - parser.add_argument("--dloop", "-dl", type=int, default=2000, help=helps["dl"]) |
27 | | - parser.add_argument("--floop", "-fl", type=int, default=500, help=helps["fl"]) |
28 | | - parser.add_argument("--seed", type=int, default=0, help=helps["seed"]) |
29 | | - parser.add_argument("--verbose", "-v", action="store_true") |
30 | | - parser.add_argument("--time", "-t", action="store_true") |
31 | | - parser.add_argument("--showgraph", "-g", action="store_true") |
32 | | - args = parser.parse_args() |
33 | | - |
34 | | - # Set random seed for deterministic results |
35 | | - set_random_seed(args.seed) |
36 | | - |
37 | | - # Use the same heuristic as Haskell gridsynth for setting dps |
38 | | - if args.dps is None: |
39 | | - epsilon1 = mpmath.mpmathify(args.epsilon) |
40 | | - dps_of_result = -mpmath.log10(epsilon1) |
41 | | - args.dps = 15 + 2.5 * dps_of_result |
42 | | - mpmath.mp.dps = args.dps |
43 | | - epsilon = mpmath.mpmathify(args.epsilon) |
44 | | - mpmath.mp.pretty = True |
45 | | - theta = mpmath.mpmathify(args.theta) |
46 | | - |
47 | | - loop_controller = LoopController( |
48 | | - dloop=args.dloop, |
49 | | - floop=args.floop, |
50 | | - dtimeout=args.dtimeout, |
51 | | - ftimeout=args.ftimeout, |
52 | | - ) |
53 | | - gates = gridsynth_gates( |
54 | | - theta=theta, |
55 | | - epsilon=epsilon, |
56 | | - loop_controller=loop_controller, |
57 | | - verbose=args.verbose, |
58 | | - measure_time=args.time, |
59 | | - show_graph=args.showgraph, |
60 | | - ) |
61 | | - print(gates) |
62 | | - return gates |
63 | | - |
| 1 | +from .cli import main |
64 | 2 |
|
65 | 3 | if __name__ == "__main__": |
66 | | - main() |
| 4 | + print(main()) |
0 commit comments