Sequential Quantum Gate Decomposer  v1.9.6
Powerful decomposition of general unitarias into one- and two-qubit gates gates
common.h
Go to the documentation of this file.
1 /*
2 Created on Fri Jun 26 14:13:26 2020
3 Copyright 2020 Peter Rakyta, Ph.D.
4 
5 Licensed under the Apache License, Version 2.0 (the "License");
6 you may not use this file except in compliance with the License.
7 You may obtain a copy of the License at
8 
9  http://www.apache.org/licenses/LICENSE-2.0
10 
11 Unless required by applicable law or agreed to in writing, software
12 distributed under the License is distributed on an "AS IS" BASIS,
13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 See the License for the specific language governing permissions and
15 limitations under the License.
16 
17 @author: Peter Rakyta, Ph.D.
18 */
23 #ifndef common_H
24 #define common_H
25 
26 #define _USE_MATH_DEFINES
27 #include <cmath>
28 #define NOMINMAX
29 #include <algorithm>
30 
31 #include <omp.h>
32 #include "QGDTypes.h"
33 #include "dot.h"
34 #include "matrix_sparse.h"
35 #include "matrix_real.h"
36 
37 class Matrix_float;
38 
39 #include <string>
40 #include <stdio.h>
41 #include <iostream>
42 #include <vector>
43 #include <cstring>
44 #include <sstream>
45 
46 #ifdef __cplusplus
47 extern "C"
48 {
49 #endif
50 
51 #if BLAS==0 // undefined blas
52  void omp_set_num_threads(int num_threads);
55  int omp_get_max_threads();
56 #elif BLAS==1 // MKL
57  void MKL_Set_Num_Threads(int num_threads);
60  int mkl_get_max_threads();
61 #elif BLAS==2 // OpenBLAS
62  void openblas_set_num_threads(int num_threads);
65  int openblas_get_num_threads();
66 #endif
67 
68 #ifdef __cplusplus
69 }
70 #endif
71 
72 
73 
77 double activation_function( double Phi, int limit );
78 
79 
87 void fread_wrapper( void * buffer, size_t size, size_t count, FILE * stream);
88 
89 
96 void* qgd_calloc( int element_num, int size, int alignment );
97 
107 void* qgd_realloc(void* aligned_ptr, int element_num, int size, int alignment );
108 
112 void qgd_free( void* ptr );
113 
119 int Power_of_2(int n);
120 
121 
127 void add_unique_elelement( std::vector<int>& involved_qbits, int qbit );
128 
135 
142 
149 Matrix reduce_zgemm( std::vector<Matrix>& mtxs );
150 
157 
158 
166 
174 
181 QGD_Complex16 mult( double a, QGD_Complex16 b );
182 
189 QGD_Complex8 mult( float a, QGD_Complex8 b );
190 
196 void mult( QGD_Complex16 a, Matrix& b );
197 
203 void mult( QGD_Complex8 a, Matrix_float& b );
204 
205 
212 
217 double arg( const QGD_Complex16& a );
218 
219 
220 
221 
222 
223 
224 void conjugate_gradient(Matrix_real A, Matrix_real b, Matrix_real& x0, double tol);
225 
226 
227 #endif
void fread_wrapper(void *buffer, size_t size, size_t count, FILE *stream)
Wrapper function aound fread with error handling.
Definition: common.cpp:75
Matrix reduce_zgemm(std::vector< Matrix > &mtxs)
Calculate the product of several square shaped complex matrices stored in a vector.
Definition: common.cpp:228
int Power_of_2(int n)
Calculates the n-th power of 2.
Definition: common.cpp:136
void * qgd_realloc(void *aligned_ptr, int element_num, int size, int alignment)
custom defined memory reallocation function.
Definition: common.cpp:109
void subtract_diag(Matrix &mtx, QGD_Complex16 scalar)
Call to subtract a scalar from the diagonal of a complex matrix.
Definition: common.cpp:277
Structure type representing single-precision complex numbers.
Definition: QGDTypes.h:46
Matrix create_identity(int matrix_size)
Call to create an identity matrix.
Definition: common.cpp:182
Header file of complex array storage array with automatic and thread safe reference counting...
void conjugate_gradient(Matrix_real A, Matrix_real b, Matrix_real &x0, double tol)
Definition: common.cpp:485
Class to store data of complex arrays and its properties.
Definition: matrix_sparse.h:38
QGD_Complex16 mult(QGD_Complex16 &a, QGD_Complex16 &b)
Call to calculate the product of two complex scalars.
Definition: common.cpp:298
matrix_size
[load Umtx]
Definition: example.py:58
Custom types for the SQUANDER package.
Structure type representing complex numbers in the SQUANDER package.
Definition: QGDTypes.h:38
void qgd_free(void *ptr)
custom defined memory release function.
Definition: common.cpp:121
Matrix_float create_identity_float(int matrix_size)
Call to create a single-precision complex identity matrix.
Definition: common.cpp:203
Double-precision complex matrix (float64).
Definition: matrix.h:38
int size() const
Call to get the number of the allocated elements.
void omp_set_num_threads(int num_threads)
Set the number of threads on runtime in MKL.
Single-precision complex matrix (float32).
Definition: matrix_float.h:41
double activation_function(double Phi, int limit)
?????
Definition: common.cpp:35
void add_unique_elelement(std::vector< int > &involved_qbits, int qbit)
Add an integer to a vector of integers if the integer is not already an element of the vector...
Definition: common.cpp:149
double arg(const QGD_Complex16 &a)
Call to retrieve the phase of a complex number.
Definition: common.cpp:444
void * qgd_calloc(int element_num, int size, int alignment)
custom defined memory allocation function.
Definition: common.cpp:93
Class to store data of complex arrays and its properties.
Definition: matrix_real.h:41
int omp_get_max_threads()
get the number of threads in MKL