-
Notifications
You must be signed in to change notification settings - Fork 1
/
run.py
59 lines (47 loc) · 1.51 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
import sys
import ast
from datetime import datetime
from ML.GradientQML import GradientQML
from ML.Genetic import GeneticAlgorithm
from ML.models import classicalNN, vqc
from postgresqlJoins import PostgresqlJoins
from util.databases import ErgastF1
from util.dataformat import DataFormat
from ML import interpretation
settings = {
"features": "simple",
"encoding": "rx",
"reuploading": False,
"reps": 20,
"calc": "yz",
"entangleType": "circular",
"entangle": "cx",
"reward": "rational",
"numEpisodes": 8000,
"optimizer": "SGD",
"lr": [0.01, 100, 0.9],
"prefix": "Loss_New",
"noisy": False,
"seed": 42,
"batchsize": 1,
"loss": "standard"
}
# update settings with command line option
if len(sys.argv) > 1:
settings.update(ast.literal_eval(sys.argv[1]))
start_time = datetime.now()
env = PostgresqlJoins(ErgastF1(), inputFile="ergastf1nC.csv", dataFormat=DataFormat(0, 1, -1))
print("Qubit Input : {}, Output: {}".format(env.getInputSize(), env.getOutputSize()))
# use quantum model
model = vqc(settings=settings, num_inputs=env.getInputSize(), num_outputs=env.getOutputSize())
# use classical model
# model = classicalNN()
# select the algorithm
#nn = GeneticAlgorithm(model,{"numEpisodes":40,"lr":0.001})
nn = GradientQML(interpretation.fromString(settings["loss"], model), env, settings)
#nn = GeneticAlgorithm(model,env,settings)
nn.run()
end_time = datetime.now()
print("Duration =", end_time - start_time)
nn.listSolutions()
print(nn.env.elvaluateModel(nn.agent))