Sequential Quantum Gate Decomposer  v1.9.3
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 #include <string>
38 #include <stdio.h>
39 #include <iostream>
40 #include <vector>
41 #include <cstring>
42 #include <sstream>
43 
44 #ifdef __cplusplus
45 extern "C"
46 {
47 #endif
48 
49 #if BLAS==0 // undefined blas
50  void omp_set_num_threads(int num_threads);
53  int omp_get_max_threads();
54 #elif BLAS==1 // MKL
55  void MKL_Set_Num_Threads(int num_threads);
58  int mkl_get_max_threads();
59 #elif BLAS==2 // OpenBLAS
60  void openblas_set_num_threads(int num_threads);
63  int openblas_get_num_threads();
64 #endif
65 
66 #ifdef __cplusplus
67 }
68 #endif
69 
70 
71 
75 double activation_function( double Phi, int limit );
76 
77 
84 void* qgd_calloc( int element_num, int size, int alignment );
85 
95 void* qgd_realloc(void* aligned_ptr, int element_num, int size, int alignment );
96 
100 void qgd_free( void* ptr );
101 
107 int Power_of_2(int n);
108 
109 
115 void add_unique_elelement( std::vector<int>& involved_qbits, int qbit );
116 
123 
130 Matrix reduce_zgemm( std::vector<Matrix>& mtxs );
131 
138 
139 
147 
154 QGD_Complex16 mult( double a, QGD_Complex16 b );
155 
161 void mult( QGD_Complex16 a, Matrix& b );
162 
163 
170 
175 double arg( const QGD_Complex16& a );
176 
177 
178 
179 
180 
181 
182 void conjugate_gradient(Matrix_real A, Matrix_real b, Matrix_real& x0, double tol);
183 
184 
185 #endif
Matrix reduce_zgemm(std::vector< Matrix > &mtxs)
Calculate the product of several square shaped complex matrices stored in a vector.
Definition: common.cpp:189
int Power_of_2(int n)
Calculates the n-th power of 2.
Definition: common.cpp:117
void * qgd_realloc(void *aligned_ptr, int element_num, int size, int alignment)
custom defined memory reallocation function.
Definition: common.cpp:90
void subtract_diag(Matrix &mtx, QGD_Complex16 scalar)
Call to subtract a scalar from the diagonal of a complex matrix.
Definition: common.cpp:238
Matrix create_identity(int matrix_size)
Call to create an identity matrix.
Definition: common.cpp:164
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:395
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:259
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:102
Class to store data of complex arrays and its properties.
Definition: matrix.h:38
void omp_set_num_threads(int num_threads)
Set the number of threads on runtime in MKL.
double activation_function(double Phi, int limit)
?????
Definition: common.cpp:34
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:131
double arg(const QGD_Complex16 &a)
Call to retrieve the phase of a complex number.
Definition: common.cpp:354
void * qgd_calloc(int element_num, int size, int alignment)
custom defined memory allocation function.
Definition: common.cpp:74
Class to store data of complex arrays and its properties.
Definition: matrix_real.h:39
int omp_get_max_threads()
get the number of threads in MKL