-
Notifications
You must be signed in to change notification settings - Fork 0
/
harvest_data_pqc.py
70 lines (51 loc) · 1.98 KB
/
harvest_data_pqc.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
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)
'''
Function to harvest data for cost function of PQCs
'''
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]
'''
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
theta = sample_parameters(n_params, n=extra_dim) # Create parameters to sample
y_pqc = sample_function(circuit.energy, theta) # Execute functions
namePQC = f'data/q{nqubits}_l{nlayers}_PQC{model}_y_r{seed}.csv' # Save data
np.savetxt(namePQC, y_pqc)
nameX = f'data/q{nqubits}_l{nlayers}_model{model}_X_r{seed}.csv'
np.savetxt(nameX, theta)
if __name__ == '__main__':
args = vars(parser.parse_args())
main(**args)