-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.py
111 lines (104 loc) · 2.85 KB
/
run.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import argparse
from pathlib import Path
from src import cvar_opt
parser = argparse.ArgumentParser()
parser.add_argument("--qubits", type=int, help="Number of qubits/spins")
parser.add_argument(
"--circ-depth", type=int, default=1, help="Depth of the circuit (default: 1)"
)
parser.add_argument(
"--shots",
nargs="+",
type=int,
default=[None],
help="Number circuit evaluations, may be a list. If None the exact quantum hamiltonian is used. (default: None)",
)
parser.add_argument(
"--maxiters",
nargs="+",
type=int,
default=[None],
help="Maximum optimizer steps, may be a list. If None the classical optimizer runs until convergence (default: None)",
)
parser.add_argument(
"--initial-points",
nargs="+",
type=int,
default=[1000],
help="Number of initial points, i.e., different runs to produce. Use two values input to resume old runs. (default: 1000)",
)
parser.add_argument(
"--gradient",
action="store_true",
help="Flag for using the gradient during optimization. (default: False)",
)
parser.add_argument(
"--opt-parameters",
action="store_true",
help="Flag for using the optimized parameters, only for QAOA. (default: False)",
)
parser.add_argument(
"--type-ansatz",
type=str,
default="vqe",
choices={"vqe", "qaoa", "qaoa+"},
help="Choose the quantum ansatz to use (default: 'vqe')",
)
parser.add_argument(
"--noise-model",
action="store_true",
help="Flag to run the circuit with a noisy simulator (default: False)",
)
parser.add_argument(
"--type-ising",
type=str,
default="ferro",
choices={"ferro", "binary", "random"},
help="Change between ferromagnetic, random binary model and random gaussian model with external field (default: 'ferro')",
)
parser.add_argument(
"--seed",
type=int,
default=42,
help="Seed to generate different ising random models [only apply with random gaussian] (default: 42)",
)
parser.add_argument(
"--alpha",
type=int,
default=25,
choices={1, 5, 10, 25, 50, 75, 100},
help="Alpha-th quantile to evaluate the loss (0,100] (default: 25)",
)
parser.add_argument(
"--save-dir",
type=Path,
default=None,
help="Path to the save directory, None means local dir (default: None)",
)
parser.add_argument(
"-v",
"--verbose",
action="count",
default=0,
help="Verbosity level for prints (default=0)",
)
def main(args: argparse.ArgumentParser):
cvar_opt.cvar_opt(
args.qubits,
args.circ_depth,
args.shots,
args.maxiters,
args.initial_points,
args.gradient,
args.opt_parameters,
args.type_ansatz,
args.noise_model,
args.type_ising,
args.seed,
args.alpha,
args.save_dir,
args.verbose,
)
if __name__ == "__main__":
args = parser.parse_args()
main(args)