forked from ProjectQ-Framework/ProjectQ
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgen_state_vec.cpp
More file actions
40 lines (34 loc) · 1.02 KB
/
gen_state_vec.cpp
File metadata and controls
40 lines (34 loc) · 1.02 KB
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
#include<stdlib.h> //rand,srand
#include<vector>
#include<fstream>
#include <iostream>
#include<complex>
#include <iomanip>
#define SEED 1235
#define FILENAME "state_vec.txt"
typedef std::complex<float> complex;
#define C(r, i) complex(r, i)
int main(int argc, char **argv) {
if (argc != 2) {
std::cout << "Input args wrong. Needs exactly one input arg which is the total number of qubits" << std::endl;
exit(1);
}
int NUM_QUBITS = atoi(argv[1]);
srand(SEED);
std::ofstream f;
f.open(FILENAME);
f << std::fixed;
f << std::setprecision(6);
unsigned long state_vec_size = 1UL << NUM_QUBITS;
//std::vector<complex> state_vec(state_vec_size, C(0.0f, 0.0f));
for (unsigned long i = 0; i < state_vec_size; i++){
//Note: normalization ignored for now
float real = ((float) rand() / (float) (RAND_MAX));
float imag = ((float) rand() / (float) (RAND_MAX));
complex val = C(real, imag);
//state_vec[i] = val;
f << val << "\n";
}
f.close();
return 0;
}