Sequential Quantum Gate Decomposer  v1.9.6
Powerful decomposition of general unitarias into one- and two-qubit gates gates
Functions
common.cpp File Reference

Provides commonly used functions and wrappers to CBLAS functions. More...

#include "common.h"
#include "matrix_float.h"
#include <tbb/scalable_allocator.h>
Include dependency graph for common.cpp:

Go to the source code of this file.

Functions

double activation_function (double Phi, int limit)
 ????? More...
 
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. More...
 
double arg (const QGD_Complex16 &a)
 Call to retrieve the phase of a complex number. More...
 
void conjugate_gradient (Matrix_real A, Matrix_real b, Matrix_real &x0, double tol)
 
Matrix create_identity (int matrix_size)
 Call to create an identity matrix. More...
 
Matrix_float create_identity_float (int matrix_size)
 Call to create a single-precision complex identity matrix. More...
 
void fread_wrapper (void *buffer, size_t size, size_t count, FILE *stream)
 Wrapper function aound fread with error handling. More...
 
QGD_Complex16 mult (QGD_Complex16 &a, QGD_Complex16 &b)
 Call to calculate the product of two complex scalars. More...
 
QGD_Complex8 mult (QGD_Complex8 &a, QGD_Complex8 &b)
 Call to calculate the product of two single-precision complex scalars. More...
 
QGD_Complex16 mult (double a, QGD_Complex16 b)
 calculate the product of a real scalar and a complex scalar More...
 
QGD_Complex8 mult (float a, QGD_Complex8 b)
 calculate the product of a real scalar and a single-precision complex scalar More...
 
void mult (QGD_Complex16 a, Matrix &b)
 Multiply the elements of matrix b by a scalar a. More...
 
void mult (QGD_Complex8 a, Matrix_float &b)
 Multiply the elements of matrix b by a scalar a. More...
 
Matrix mult (Matrix_sparse a, Matrix &b)
 Multiply the elements of a sparse matrix a and a dense vector b. More...
 
int Power_of_2 (int n)
 Calculates the n-th power of 2. More...
 
void * qgd_calloc (int element_num, int size, int alignment)
 custom defined memory allocation function. More...
 
void qgd_free (void *ptr)
 custom defined memory release function. More...
 
void * qgd_realloc (void *aligned_ptr, int element_num, int size, int alignment)
 custom defined memory reallocation function. More...
 
Matrix reduce_zgemm (std::vector< Matrix > &mtxs)
 Calculate the product of several square shaped complex matrices stored in a vector. More...
 
void subtract_diag (Matrix &mtx, QGD_Complex16 scalar)
 Call to subtract a scalar from the diagonal of a complex matrix. More...
 

Detailed Description

Provides commonly used functions and wrappers to CBLAS functions.

Definition in file common.cpp.

Function Documentation

◆ activation_function()

double activation_function ( double  Phi,
int  limit 
)

?????

Definition at line 35 of file common.cpp.

Here is the caller graph for this function:

◆ add_unique_elelement()

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.

The ascending order is kept during the process.

Parameters
involved_qbitsThe vector of integer to be updated by the new integer. The result is returned via this vector.
qbitThe integer to be added to the vector

Definition at line 149 of file common.cpp.

◆ arg()

double arg ( const QGD_Complex16 a)

Call to retrieve the phase of a complex number.

Parameters
aA complex numberr.

Definition at line 444 of file common.cpp.

Here is the caller graph for this function:

◆ conjugate_gradient()

void conjugate_gradient ( Matrix_real  A,
Matrix_real  b,
Matrix_real x0,
double  tol 
)

Definition at line 485 of file common.cpp.

Here is the caller graph for this function:

◆ create_identity()

Matrix create_identity ( int  matrix_size)

Call to create an identity matrix.

Parameters
matrix_sizeThe number of rows in the resulted identity matrix
Returns
Returns with an identity matrix.

Definition at line 182 of file common.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ create_identity_float()

Matrix_float create_identity_float ( int  matrix_size)

Call to create a single-precision complex identity matrix.

Parameters
matrix_sizeThe number of rows in the resulted identity matrix
Returns
Returns with a single-precision complex identity matrix.

Definition at line 203 of file common.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fread_wrapper()

void fread_wrapper ( void *  buffer,
size_t  size,
size_t  count,
FILE *  stream 
)

Wrapper function aound fread with error handling.

Parameters
bufferIt refers to the pointer to the buffer memory block where the data read will be stored.
sizeIt refers to the size of each element in bytes.
countIt refers to the count of elements to be read.
streamIt refers to the pointer to the file stream.

Definition at line 75 of file common.cpp.

Here is the caller graph for this function:

◆ mult() [1/7]

QGD_Complex16 mult ( QGD_Complex16 a,
QGD_Complex16 b 
)

Call to calculate the product of two complex scalars.

Parameters
aThe firs scalar
bThe second scalar
Returns
Returns with the calculated product.

Definition at line 298 of file common.cpp.

Here is the caller graph for this function:

◆ mult() [2/7]

QGD_Complex8 mult ( QGD_Complex8 a,
QGD_Complex8 b 
)

Call to calculate the product of two single-precision complex scalars.

Parameters
aThe firs scalar
bThe second scalar
Returns
Returns with the calculated product.

Definition at line 314 of file common.cpp.

◆ mult() [3/7]

QGD_Complex16 mult ( double  a,
QGD_Complex16  b 
)

calculate the product of a real scalar and a complex scalar

Parameters
aThe real scalar.
bThe complex scalar.
Returns
Returns with the calculated product.

Definition at line 330 of file common.cpp.

◆ mult() [4/7]

QGD_Complex8 mult ( float  a,
QGD_Complex8  b 
)

calculate the product of a real scalar and a single-precision complex scalar

Parameters
aThe real scalar.
bThe complex scalar.
Returns
Returns with the calculated product.

Definition at line 346 of file common.cpp.

◆ mult() [5/7]

void mult ( QGD_Complex16  a,
Matrix b 
)

Multiply the elements of matrix b by a scalar a.

Parameters
aA complex scalar.
bA complex matrix.

Definition at line 363 of file common.cpp.

Here is the call graph for this function:

◆ mult() [6/7]

void mult ( QGD_Complex8  a,
Matrix_float b 
)

Multiply the elements of matrix b by a scalar a.

Parameters
aA single-precision complex scalar.
bA single-precision complex matrix.

Definition at line 382 of file common.cpp.

Here is the call graph for this function:

◆ mult() [7/7]

Matrix mult ( Matrix_sparse  a,
Matrix b 
)

Multiply the elements of a sparse matrix a and a dense vector b.

Parameters
aA complex sparse matrix in CSR format.
bA complex dense vector.

Definition at line 403 of file common.cpp.

Here is the call graph for this function:

◆ Power_of_2()

int Power_of_2 ( int  n)

Calculates the n-th power of 2.

Parameters
nAn natural number
Returns
Returns with the n-th power of 2.

Definition at line 136 of file common.cpp.

Here is the caller graph for this function:

◆ qgd_calloc()

void* qgd_calloc ( int  element_num,
int  size,
int  alignment 
)

custom defined memory allocation function.

Memory allocated with aligned realloc MUST be freed using qgd_free.

Parameters
element_numThe number of elements in the array to be allocated.
sizeA size of one element (such as sizeof(double) )
alignmentThe number of bytes to which memory must be aligned. This value must be <= 255.

Definition at line 93 of file common.cpp.

Here is the caller graph for this function:

◆ qgd_free()

void qgd_free ( void *  ptr)

custom defined memory release function.

Definition at line 121 of file common.cpp.

Here is the caller graph for this function:

◆ qgd_realloc()

void* qgd_realloc ( void *  aligned_ptr,
int  element_num,
int  size,
int  alignment 
)

custom defined memory reallocation function.

Memory allocated with aligned realloc MUST be freed using qgd_free. The reallocation is done by either: a) expanding or contracting the existing area pointed to by aligned_ptr, if possible. The contents of the area remain unchanged up to the lesser of the new and old sizes. If the area is expanded, the contents of the new part of the array is set to zero. b) allocating a new memory block of size new_size bytes, copying memory area with size equal the lesser of the new and the old sizes, and freeing the old block.

Parameters
aligned_ptrThe aligned pointer created by qgd_calloc
element_numThe number of elements in the array to be allocated.
sizeA size of one element (such as sizeof(double) )
alignmentThe number of bytes to which memory must be aligned. This value must be <= 255.

Definition at line 109 of file common.cpp.

◆ reduce_zgemm()

Matrix reduce_zgemm ( std::vector< Matrix > &  mtxs)

Calculate the product of several square shaped complex matrices stored in a vector.

Parameters
mtxsThe vector of matrices.
matrix_sizeThe number rows in the matrices
Returns
Returns with the calculated product matrix

Definition at line 228 of file common.cpp.

Here is the call graph for this function:

◆ subtract_diag()

void subtract_diag ( Matrix mtx,
QGD_Complex16  scalar 
)

Call to subtract a scalar from the diagonal of a complex matrix.

Parameters
mtxThe input-output matrix
scalarThe complex scalar to be subtracked from the diagonal elements of the matrix

Definition at line 277 of file common.cpp.

Here is the caller graph for this function: