-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtransformers.cpp
More file actions
120 lines (102 loc) · 3.34 KB
/
Copy pathtransformers.cpp
File metadata and controls
120 lines (102 loc) · 3.34 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
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
112
113
114
115
116
117
118
119
120
#include <iostream>
#include <random>
#include <complex>
#include <string>
#include "transformers.h"
using namespace std;
IdealStateDeviationTransformer::IdealStateDeviationTransformer() {
name = "Ideal State Deviation Transformer";
}
state IdealStateDeviationTransformer::operator()(state s) {
return s;
}
UniformRadianStateDeviationTransformer::UniformRadianStateDeviationTransformer(double radians) {
gen = default_random_engine();
dist = uniform_real_distribution<double>(-radians, radians);
name = to_string(radians) + " radian Uniform Random State Deviation Transformer";
}
UniformRadianStateDeviationTransformer::UniformRadianStateDeviationTransformer() {
gen = default_random_engine();
cout << "Enter maximum radian deviation for uniform distribution(r), i.e. Uniform distribution from [-r,r]: ";
double radians;
cin >> radians;
dist = uniform_real_distribution<double>(-radians, radians);
name = to_string(radians) + " radian Uniform Random State Deviation Transformer";
}
state UniformRadianStateDeviationTransformer::operator()(state s) {
auto zero_amp = s.first;
auto one_amp = s.second;
double theta, phi;
complex<double> phaseDelta;
if (abs(zero_amp) == 0 || abs(one_amp) == 0) {
theta = (abs(zero_amp) == 0) ? 3.14159 : 0;
phi = 0;
phaseDelta = 1;
} else {
phaseDelta = zero_amp / abs(zero_amp);
phi = arg(one_amp) - arg(zero_amp);
theta = 2 * acos(abs(zero_amp));
}
double deviated_phi = phi + dist(gen);
double deviated_theta = theta + dist(gen);
amplitude deviated_zero_amp = phaseDelta * cos(deviated_theta/2);
amplitude deviated_one_amp = phaseDelta * exp(complex<double>(0,1) * deviated_phi) * sin(deviated_theta/2);
return make_pair(deviated_zero_amp, deviated_one_amp);
}
StateTransformer* chooseStateDeviationTransformer() {
StateTransformer* chosenTransformer;
vector<string> transformers {"Ideal State Deviation Transformer, No deviation from generated state",
"Uniform Random Radian State Deviation Transformer, deviates Bloch Sphere angles uniformly random b/w [-r,r]"};
int index = 1;
for (auto name: transformers) {
cout << index << ")" << name << endl;
index++;
}
cout << "Choose which State Deviation Transformer to use: ";
int choice;
cin >> choice;
switch(choice) {
case 1: {
chosenTransformer = new IdealStateDeviationTransformer();
break;
}
case 2: {
chosenTransformer = new UniformRadianStateDeviationTransformer();
break;
}
default:{
cout << "Out of Index State Deviation Transformer choice" << endl;
throw -1;
}
}
return chosenTransformer;
}
IdealBasisDeviationTransformer::IdealBasisDeviationTransformer() {
name = "Ideal Basis Deviation Transformer";
}
basis IdealBasisDeviationTransformer::operator()(basis b){
return b;
}
BasisTransformer* chooseBasisDeviationTransformer() {
BasisTransformer* chosenTransformer;
vector<string> transformers {"Ideal Basis Deviation Transformer, able to measure qubit in basis with exact precision"};
int index = 1;
for (auto name: transformers) {
cout << index << ")" << name << endl;
index++;
}
cout << "Choose which Basis Deviation Transformer to use: ";
int choice;
cin >> choice;
switch(choice) {
case 1: {
chosenTransformer = new IdealBasisDeviationTransformer();
break;
}
default:{
cout << "Out of Index Basis Deviation Transformer choice" << endl;
throw -1;
}
}
return chosenTransformer;
}