40 int cnot_num_curr = 0;
50 int cnot_or_u3 = rand() % 5 + 1;
57 if (cnot_or_u3 <= 4) {
60 parameters[0] = double(rand())/RAND_MAX*4*M_PI;
61 parameters[1] = double(rand())/RAND_MAX*2*M_PI;
62 parameters[2] = double(rand())/RAND_MAX*2*M_PI;
69 u3_op =
new U3(qbit_num, target_qbit);
75 else if ( cnot_or_u3 == 5 ) {
82 if (target_qbit == control_qbit) {
88 cnot_op =
new CNOT(qbit_num, control_qbit, target_qbit);
93 cnot_num_curr = cnot_num_curr + 1;
112 if (cnot_num_curr >= cnot_num) {
129 throw "wrong dimension";
146 double* vartheta = (
double*)
qgd_calloc(
int(
dim*(
dim-1)/2),
sizeof(double), 64);
147 double* varphi = (
double*)
qgd_calloc(
int(
dim*(
dim-1)/2),
sizeof(
double), 64);
148 double* varkappa = (
double*)
qgd_calloc( (
dim-1),
sizeof(double), 64);
153 for (
int idx=0; idx<
dim*(
dim-1)/2; idx++) {
154 vartheta[idx] = (2*double(rand())/double(RAND_MAX)-1)*2*M_PI;
158 for (
int idx=0; idx<
dim*(
dim-1)/2; idx++) {
159 varphi[idx] = (2*double(rand())/double(RAND_MAX)-1)*2*M_PI;
163 for (
int idx=0; idx<(
dim-1); idx++) {
164 varkappa[idx] = (2*double(rand())/double(RAND_MAX)-1)*2*M_PI;
194 for (
int varalpha=1; varalpha<
dim; varalpha++) {
195 for (
int varbeta = 0; varbeta<varalpha; varbeta++) {
203 a.
real = cos( theta_loc )*cos(phi_loc);
204 a.
imag = cos( theta_loc )*sin(phi_loc);
207 double varepsilon = varkappa[varalpha-1]*
kronecker( varalpha-1, varbeta);
209 b.
real = sin( theta_loc )*cos(varepsilon);
210 b.
imag = sin( theta_loc )*sin(varepsilon);
214 Matrix Omega_loc =
Omega( varalpha, varbeta, a, b );
226 for (
int idx=0; idx<dim*
dim; idx++) {
227 ret[idx] =
mult(ret[idx], gamma_loc);
245 int ret = varbeta + (varalpha-1)*(varalpha-2)/2;
277 Mloc =
M( varalpha, varbeta, x, y );
282 Mloc =
M( varalpha, varbeta, x,
mult(
gamma(), y) );
287 for (
int idx=0; idx<
dim*
dim; idx++ ) {
288 ret[idx].real = ret[idx].real + Mloc[idx].real;
289 ret[idx].imag = ret[idx].imag + Mloc[idx].imag;
324 for (
int idx=0; idx<
dim*
dim; idx++ ) {
325 ret[idx].real = ret1[idx].real + ret2[idx].real + ret3[idx].real + ret4[idx].real;
326 ret[idx].imag = ret1[idx].imag + ret2[idx].imag + ret3[idx].imag + ret4[idx].imag;
346 ret[2].real = -u1.
real;
347 ret[2].imag = u1.
imag;
348 ret[3].real = u2.
real;
349 ret[3].imag = -u2.
imag;
367 ret[varalpha*
dim+varbeta].real = 1;
385 ret[varalpha*
dim+varalpha].real = 0;
386 ret[varbeta*
dim+varbeta].real = 0;
400 double ret = pow(-1, 0.25*(2*
dim-1+pow(-1,
dim)));
Matrix dot(Matrix &A, Matrix &B)
Call to calculate the product of two complex matrices by calling method zgemm3m from the CBLAS librar...
A class representing a U3 gate.
Matrix few_CNOT_unitary(int qbit_num, int cnot_num)
Call to create a random unitary constructed by CNOT operation between randomly chosen qubits and by r...
void * qgd_calloc(int element_num, int size, int alignment)
custom defined memory allocation function.
Matrix get_matrix(Matrix_real ¶meters)
Call to retrieve the gate matrix.
void qgd_free(void *ptr)
custom defined memory release function.
QGD_Complex16 mult(QGD_Complex16 &a, QGD_Complex16 &b)
Call to calculate the product of two complex scalars.
int convert_indexes(int varalpha, int varbeta)
Calculates an index from paramaters varalpha and varbeta.
double kronecker(int a, int b)
Kronecker delta.
scalar * get_data() const
Call to get the pointer to the stored data.
int dim
The number of rows in the created unitary.
double gamma()
Implements Eq (11) of arXiv:1303:5904v1.
Matrix E_alpha_beta(int varalpha, int varbeta)
Implements matrix I below Eq (7) of arXiv:1303:5904v1.
Umtx
The unitary to be decomposed.
Matrix M(int varalpha, int varbeta, QGD_Complex16 s, QGD_Complex16 t)
Implements Eq (8) of arXiv:1303:5904v1.
Structure type representing complex numbers in the SQUANDER package.
A class representing a CNOT operation.
int Power_of_2(int n)
Calculates the n-th power of 2.
Class to store data of complex arrays and its properties.
Random_Unitary(int dim_in)
Constructor of the class.
Matrix Q(QGD_Complex16 u1, QGD_Complex16 u2)
Implements Eq (9) of arXiv:1303:5904v1.
Matrix I_alpha_beta(int varalpha, int varbeta)
Implements matrix I below Eq (7) of arXiv:1303:5904v1.
Matrix create_identity(int matrix_size)
Call to create an identity matrix.
double real
the real part of a complex number
Matrix Omega(int varalpha, int varbeta, QGD_Complex16 x, QGD_Complex16 y)
Eq (6) of arXiv:1303:5904v1.
Matrix get_matrix()
Call to retrieve the operation matrix.
Matrix Construct_Unitary_Matrix()
Call to create a random unitary.
Class to store data of complex arrays and its properties.
double imag
the imaginary part of a complex number