39 int cnot_num_curr = 0;
49 int cnot_or_u3 = rand() % 5 + 1;
56 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,
true,
true,
true);
74 else if ( cnot_or_u3 == 5 ) {
79 int control_qbit = rand() %
qbit_num;
81 if (target_qbit == control_qbit) {
92 cnot_num_curr = cnot_num_curr + 1;
111 if (cnot_num_curr >= cnot_num) {
128 throw "wrong dimension";
145 double* vartheta = (
double*)
qgd_calloc(
int(
dim*(
dim-1)/2),
sizeof(double), 64);
146 double* varphi = (
double*)
qgd_calloc(
int(
dim*(
dim-1)/2),
sizeof(
double), 64);
147 double* varkappa = (
double*)
qgd_calloc( (
dim-1),
sizeof(double), 64);
152 for (
int idx=0; idx<
dim*(
dim-1)/2; idx++) {
153 vartheta[idx] = (2*double(rand())/double(RAND_MAX)-1)*2*M_PI;
157 for (
int idx=0; idx<
dim*(
dim-1)/2; idx++) {
158 varphi[idx] = (2*double(rand())/double(RAND_MAX)-1)*2*M_PI;
162 for (
int idx=0; idx<(
dim-1); idx++) {
163 varkappa[idx] = (2*double(rand())/double(RAND_MAX)-1)*2*M_PI;
193 for (
int varalpha=1; varalpha<
dim; varalpha++) {
194 for (
int varbeta = 0; varbeta<varalpha; varbeta++) {
202 a.
real = cos( theta_loc )*cos(phi_loc);
203 a.
imag = cos( theta_loc )*sin(phi_loc);
206 double varepsilon = varkappa[varalpha-1]*
kronecker( varalpha-1, varbeta);
208 b.
real = sin( theta_loc )*cos(varepsilon);
209 b.
imag = sin( theta_loc )*sin(varepsilon);
213 Matrix Omega_loc =
Omega( varalpha, varbeta, a, b );
225 for (
int idx=0; idx<
dim*
dim; idx++) {
226 ret[idx] =
mult(ret[idx], gamma_loc);
244 int ret = varbeta + (varalpha-1)*(varalpha-2)/2;
276 Mloc =
M( varalpha, varbeta, x, y );
281 Mloc =
M( varalpha, varbeta, x,
mult(
gamma(), y) );
286 for (
int idx=0; idx<
dim*
dim; idx++ ) {
287 ret[idx].real = ret[idx].real + Mloc[idx].real;
288 ret[idx].imag = ret[idx].imag + Mloc[idx].imag;
323 for (
int idx=0; idx<
dim*
dim; idx++ ) {
324 ret[idx].real = ret1[idx].real + ret2[idx].real + ret3[idx].real + ret4[idx].real;
325 ret[idx].imag = ret1[idx].imag + ret2[idx].imag + ret3[idx].imag + ret4[idx].imag;
345 ret[2].real = -u1.
real;
346 ret[2].imag = u1.
imag;
347 ret[3].real = u2.
real;
348 ret[3].imag = -u2.
imag;
366 ret[varalpha*
dim+varbeta].real = 1;
384 ret[varalpha*
dim+varalpha].real = 0;
385 ret[varbeta*
dim+varbeta].real = 0;
399 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 operation.
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(size_t element_num, size_t size, size_t alignment)
custom defined memory allocation function.
Header file for a class and methods to cerate random unitary matrices.
void qgd_free(void *ptr)
custom defined memory release function.
scalar * get_data()
Call to get the pointer to the stored data.
int convert_indexes(int varalpha, int varbeta)
Calculates an index from paramaters varalpha and varbeta.
QGD_Complex16 mult(QGD_Complex16 a, QGD_Complex16 b)
Call to calculate the product of two complex scalars.
double kronecker(int a, int b)
Kronecker delta.
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 QGD 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.
Matrix get_matrix(const double *parameters)
Call to retrieve the operation 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.
double imag
the imaginary part of a complex number