-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathev_math.cu
More file actions
179 lines (154 loc) · 5.45 KB
/
ev_math.cu
File metadata and controls
179 lines (154 loc) · 5.45 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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
#ifndef EVMATH
# define EVMATH
namespace evmath{
typedef void (*operador_evolucion)(double *, double *, itpp::vec, double, double, itpp::mat, int, int, itpp::ivec, itpp::ivec);
itpp::cmat evolution_matrix(operador_evolucion evolucion, itpp::vec js, double j, double jp, itpp::mat b , int nqubits, int extra, itpp::ivec A, itpp::ivec B) {
int l = pow(2,nqubits);
double *dev_umatR,*dev_umatI;
evcuda::cmalloc(&dev_umatR,&dev_umatI,l);
int numthreads, numblocks;
choosenumblocks(l,numthreads,numblocks);
itpp::cvec state(l);
itpp::cmat Umat(l,l);
for(int i=0;i<l;i++) {
index_one<<<numblocks,numthreads>>>(dev_umatR,dev_umatI,l,i);
evolucion(dev_umatR,dev_umatI,js,j,jp,b,nqubits,extra,A,B);
evcuda::cuda2itpp(state,dev_umatR,dev_umatI);
Umat.set_col(i,state);
}
cudaFree(dev_umatR);
cudaFree(dev_umatI);
return Umat;
}
itpp::cmat evolution_matrix_chain_reflection(double j, itpp::vec b , int nqubits, int symr) {
//SECTORES DE SIMETRIA POR REFLEXION
int l = pow(2,nqubits);
double *dev_umatR,*dev_umatI;
evcuda::cmalloc(&dev_umatR,&dev_umatI,l);
int *S=new int[l];
for(int m=0;m<l;m++) {
S[m]=2;
}
find_states_reflection(S,nqubits,symr,l);
int rcont=0;
for(int i=0;i<l;i++) {
if(S[i]==1) {
S[rcont]=i;
rcont++;
}
}
int *dev_S;
cudaMalloc((void**)&dev_S,rcont*sizeof(int));
cudaMemcpy(dev_S,S,rcont*sizeof(int),cudaMemcpyHostToDevice);
double *dev_dotR,*dev_dotI;
evcuda::cmalloc(&dev_dotR,&dev_dotI,rcont);
int numthreads, numblocks;
choosenumblocks(l,numthreads,numblocks);
itpp::cvec state(rcont);
itpp::cmat Umat(rcont,rcont);
for(int i=0;i<rcont;i++) {
to_zero<<<numblocks,numthreads>>>(dev_umatR,dev_umatI,l);
reflection_proyector<<<1,1>>>(dev_umatR,dev_umatI,nqubits,symr,S[i]);
times_norm<<<numblocks,numthreads>>>(dev_umatR,dev_umatI,l);
model::chain_open(dev_umatR,dev_umatI,j,b,nqubits);
to_zero<<<numblocks,numthreads>>>(dev_dotR,dev_dotI,rcont);
proyected_dot_reflection<<<numblocks,numthreads>>>(dev_umatR,dev_umatI,dev_dotR,dev_dotI,nqubits,rcont,symr,dev_S);
evcuda::cuda2itpp(state,dev_dotR,dev_dotI);
Umat.set_col(i,state);
}
cudaFree(dev_umatR);
cudaFree(dev_umatI);
return Umat;
}
itpp::cmat evolution_matrix_chain_translation(double j, itpp::vec b , int nqubits, int kx) {
//SECTORES DE SIMETRIA POR REFLEXION
int l = pow(2,nqubits);
double *dev_umatR,*dev_umatI;
evcuda::cmalloc(&dev_umatR,&dev_umatI,l);
int *S=new int[l];
for(int m=0;m<l;m++) {
S[m]=2;
}
find_states_total_horizontal(S,nqubits,kx,l);
int rcont=0;
for(int i=0;i<l;i++) {
if(S[i]==1) {
S[rcont]=i;
rcont++;
}
}
int *dev_S;
cudaMalloc((void**)&dev_S,rcont*sizeof(int));
cudaMemcpy(dev_S,S,rcont*sizeof(int),cudaMemcpyHostToDevice);
double *dev_dotR,*dev_dotI;
evcuda::cmalloc(&dev_dotR,&dev_dotI,rcont);
int numthreads, numblocks;
choosenumblocks(l,numthreads,numblocks);
itpp::cvec state(rcont);
itpp::cmat Umat(rcont,rcont);
for(int i=0;i<rcont;i++) {
to_zero<<<numblocks,numthreads>>>(dev_umatR,dev_umatI,l);
special_chain_proyector<<<1,1>>>(dev_umatR,dev_umatI,nqubits,l,kx,S[i]);
times_norm<<<numblocks,numthreads>>>(dev_umatR,dev_umatI,l);
model::chain(dev_umatR,dev_umatI,j,b,nqubits);
to_zero<<<numblocks,numthreads>>>(dev_dotR,dev_dotI,rcont);
proyected_dot_chain<<<numblocks,numthreads>>>(dev_umatR,dev_umatI,dev_dotR,dev_dotI,nqubits,rcont,kx,dev_S);
evcuda::cuda2itpp(state,dev_dotR,dev_dotI);
Umat.set_col(i,state);
}
cudaFree(dev_umatR);
cudaFree(dev_umatI);
return Umat;
}
std::complex<double> purity_last_qubit(itpp::cvec state, int l) {
itpp::cmat rho= itpp::zeros_c(2,2);
itpp::cvec a=state.right(l/2);
itpp::cvec b=state.left(l/2);
rho(0,0)=itpp::dot(a,itpp::conj(a));
rho(0,1)=itpp::dot(a,itpp::conj(b));
rho(1,0)=itpp::dot(b,itpp::conj(a));
rho(1,1)=itpp::dot(b,itpp::conj(b));
rho=rho*rho;
return itpp::trace(rho);
}
itpp::cmat reduced_densMat (double* dev_R, double* dev_I, int which, int nqubits) {
int ndens=pow(2,numbits(which));
int l=pow(2,nqubits);
double *densR=new double[ndens*ndens];
double *densI=new double[ndens*ndens];
double *dev_densR;
double *dev_densI;
evcuda::cmalloc(&dev_densR,&dev_densI,ndens*ndens);
cudaCheckError("dot",0);
int numthreads, numblocks;
choosenumblocks(l,numthreads,numblocks);
to_zero<<<numthreads,numblocks>>>(dev_densR,dev_densI,ndens*ndens);
itpp::cmat densMat(ndens,ndens);
//cout<<numblocks<<" "<<numthreads/ndens<<endl;
for(int i=0;i<ndens;i++) {
for(int j=0;j<ndens;j++) {
density_matrix<<<numblocks,numthreads>>>(which,ndens,i,j,dev_R,dev_I,dev_densR,dev_densI,l/ndens);
cudaCheckError("dot",i+j);
}
}
cudaMemcpy(densR,dev_densR,ndens*ndens*sizeof(double),cudaMemcpyDeviceToHost);
cudaMemcpy(densI,dev_densI,ndens*ndens*sizeof(double),cudaMemcpyDeviceToHost);
for(int i=0;i<ndens;i++) {
for(int j=0;j<ndens;j++) {
densMat(i,j)=std::complex<double>(densR[(ndens*i)+j],densI[(ndens*i)+j]);
}
}
cudaFree(dev_densR);
cudaFree(dev_densI);
return densMat;
}
void apply_sumdx(int nqubits,double* dev_R,double* dev_I,double* dev_sumdxR,double* dev_sumdxI) {
int l=pow(nqubits,2);
int numthreads;
int numblocks;
choosenumblocks(l,numthreads,numblocks);
sumsigma_x<<<numblocks,numthreads>>>(dev_R,dev_I,dev_sumdxR,dev_sumdxI,nqubits,l);
cudaCheckError("kick",10);
}
}
#endif