-
Notifications
You must be signed in to change notification settings - Fork 0
/
harvest_data_gauss.py
69 lines (53 loc) · 2.3 KB
/
harvest_data_gauss.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
from circuits_IC import *
from IC_aux import sample_parameters, sample_function
import numpy as np
from argparse import ArgumentParser
parser = ArgumentParser()
parser.add_argument('--nqubits', type=int, default=4)
parser.add_argument('--nlayers', type=int, default = 4)
parser.add_argument('--model', type=int, default = 2)
parser.add_argument('--seed', type=int, default=0)
parser.add_argument('--extra_dim', type=int, default=2)
parser.add_argument('--data_size', type=int, default=5)
def main(nqubits, nlayers, model, seed, extra_dim, data_size):
'''
nqubits: size of the circuits
nlayers: depth of the ansatz
model: choose the model, from the ones available in circuits_IC.py
seed: random seed for reproducibility
extra_dim: overhead in the number of dimensions for computing IC, see [48]
data_size: size of data x to compute hypothesis functions
'''
nameGAUSS = f'data/q{nqubits}_l{nlayers}_gauss{model}_y_r{seed}.csv'
try:
np.loadtxt(nameGAUSS)
print(nqubits, nlayers, model, seed, extra_dim, data_size, 'already done')
except:
if model == 1:
circuit = single_qubit(nqubits, nlayers)
elif model == 2:
circuit = single_qubit_and_entangling(nqubits, nlayers)
elif model == 3:
circuit = permutation_simple(nqubits, nlayers)
elif model == 4:
circuit = permutation_double(nqubits, nlayers)
elif model == 5:
circuit = permutation_composed(nqubits, nlayers)
# Create circuits
circuit.create_PQC()
circuit.create_QML()
np.random.seed(seed)
if model in [1, 2]:
n_params = len(circuit.PQC.get_parameters())
elif model == 3:
n_params = circuit.nlayers
elif model in [4, 5]:
n_params = 2 * circuit.nlayers
nameX = f'data/q{nqubits}_l{nlayers}_model{model}_X_r{seed}.csv'
theta = np.loadtxt(nameX) # load parameters fro m PQC
y_gauss = sample_function(lambda x: circuit.function(x, np.sqrt(np.pi)* np.random.randn(data_size)), theta) # Execute functions
nameGAUSS = f'data/q{nqubits}_l{nlayers}_gauss{model}_y_r{seed}.csv' # Save data
np.savetxt(nameGAUSS, y_gauss)
if __name__ == '__main__':
args = vars(parser.parse_args())
main(**args)