Quantum Gate Decomposer  v1.3
Powerful decomposition of almost any unitary into U3 and CNOT gates
Functions
common.h File Reference

Header file for commonly used functions and wrappers to CBLAS functions. More...

#include <tbb/tbb.h>
#include <tbb/scalable_allocator.h>
#include <omp.h>
#include "qgd/QGDTypes.h"
#include "qgd/dot.h"
#include <string>
#include <stdio.h>
#include <iostream>
#include <cmath>
#include <vector>
#include <cstring>
#include <sstream>
Include dependency graph for common.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

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...
 
Matrix create_identity (int matrix_size)
 Call to create an identity matrix. More...
 
int create_identity (QGD_Complex16 *matrix, int matrix_size)
 Call to create an identity matrix — OBSOLETE. More...
 
double get_cost_function (QGD_Complex16 *matrix, int matrix_size)
 Call co calculate the cost funtion during the final optimization process. More...
 
QGD_Complex16 mult (QGD_Complex16 a, QGD_Complex16 b)
 Call to calculate the product of two complex scalars. More...
 
QGD_Complex16 mult (double a, QGD_Complex16 b)
 calculate the product of a real scalar and a complex scalar More...
 
void mult (QGD_Complex16 a, Matrix &b)
 Multiply the elements of matrix b by a scalar a. More...
 
int Power_of_2 (int n)
 Calculates the n-th power of 2. More...
 
void * qgd_calloc (size_t element_num, size_t size, size_t alignment)
 custom defined memory allocation function. More...
 
void qgd_free (void *ptr)
 custom defined memory release function. More...
 
void * qgd_realloc (void *aligned_ptr, size_t element_num, size_t size, size_t 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...
 
QGD_Complex16 scalar_product (QGD_Complex16 *A, QGD_Complex16 *B, int vector_size)
 Call to calculate the scalar product of two complex vectors using function cblas_zgemm3m or cblas_zgemm. More...
 
void subtract_diag (Matrix &mtx, QGD_Complex16 scalar)
 Call to subtract a scalar from the diagonal of a complex matrix. More...
 
QGD_Complex16zgemm3m_wrapper (QGD_Complex16 *A, QGD_Complex16 *B, int matrix_size)
 Call to calculate the product of two square shaped complex matrices using function cblas_zgemm3m or cblas_zgemm. More...
 
int zgemm3m_wrapper (QGD_Complex16 *A, QGD_Complex16 *B, QGD_Complex16 *C, int matrix_size)
 Call to calculate the product of two square shaped complex matrices using function cblas_zgemm3m or cblas_zgemm. More...
 
int zgemm3m_wrapper_adj (QGD_Complex16 *A, QGD_Complex16 *B, QGD_Complex16 *C, int matrix_size)
 Call to calculate the product of a square shaped complex matrix and a complex transpose of a second square shaped complex matrix using function cblas_zgemm3m or cblas_zgemm. More...
 

Detailed Description

Header file for commonly used functions and wrappers to CBLAS functions.

Definition in file common.h.

Function Documentation

◆ 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 95 of file common.cpp.

◆ create_identity() [1/2]

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 128 of file common.cpp.

Here is the call graph for this function:

◆ create_identity() [2/2]

int create_identity ( QGD_Complex16 matrix,
int  matrix_size 
)

Call to create an identity matrix — OBSOLETE.

Parameters
matrixThe pointer to the memory array allocated for the identity matrix. The result is returned via this pointer.
matrix_sizeThe number of rows in the resulted identity matrix
Returns
Returns with zero on success.

Definition at line 152 of file common.cpp.

◆ get_cost_function()

double get_cost_function ( QGD_Complex16 matrix,
int  matrix_size 
)

Call co calculate the cost funtion during the final optimization process.

Parameters
matrixThe square shaped complex matrix from which the cost function is calculated.
matrix_sizeThe number rows in the matrix
Returns
Returns with the calculated cost function.

◆ mult() [1/3]

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 367 of file common.cpp.

◆ mult() [2/3]

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 383 of file common.cpp.

◆ mult() [3/3]

void mult ( QGD_Complex16  a,
Matrix b 
)

Multiply the elements of matrix b by a scalar a.

Parameters
aA complex scalar.
bA square shaped matrix.

Definition at line 400 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 81 of file common.cpp.

Here is the call graph for this function:

◆ qgd_calloc()

void* qgd_calloc ( size_t  element_num,
size_t  size,
size_t  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.

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 38 of file common.cpp.

◆ qgd_free()

void qgd_free ( void *  ptr)

custom defined memory release function.

Definition at line 66 of file common.cpp.

◆ qgd_realloc()

void* qgd_realloc ( void *  aligned_ptr,
size_t  element_num,
size_t  size,
size_t  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 54 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 297 of file common.cpp.

Here is the call graph for this function:

◆ scalar_product()

QGD_Complex16 scalar_product ( QGD_Complex16 A,
QGD_Complex16 B,
int  vector_size 
)

Call to calculate the scalar product of two complex vectors using function cblas_zgemm3m or cblas_zgemm.

Parameters
AThe first vector of the product
BThe second vector of the product
vector_sizeThe size of the vectors.
Returns
Returns the scalar product of the two vectors.

Definition at line 175 of file common.cpp.

◆ 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 346 of file common.cpp.

◆ zgemm3m_wrapper() [1/2]

QGD_Complex16* zgemm3m_wrapper ( QGD_Complex16 A,
QGD_Complex16 B,
int  matrix_size 
)

Call to calculate the product of two square shaped complex matrices using function cblas_zgemm3m or cblas_zgemm.

Parameters
AThe first matrix.
BThe second matrix
matrix_sizeThe number rows in the matrices
Returns
Returns with a pointer to the resulted matrix.

Definition at line 236 of file common.cpp.

Here is the call graph for this function:

◆ zgemm3m_wrapper() [2/2]

int zgemm3m_wrapper ( QGD_Complex16 A,
QGD_Complex16 B,
QGD_Complex16 C,
int  matrix_size 
)

Call to calculate the product of two square shaped complex matrices using function cblas_zgemm3m or cblas_zgemm.

Parameters
AThe first matrix.
BThe second matrix
CPointer to the resulted matrix. The calculated matrix is returned via this pointer.
matrix_sizeThe number rows in the matrices
Returns
Returns with zero on success.

Definition at line 268 of file common.cpp.

◆ zgemm3m_wrapper_adj()

int zgemm3m_wrapper_adj ( QGD_Complex16 A,
QGD_Complex16 B,
QGD_Complex16 C,
int  matrix_size 
)

Call to calculate the product of a square shaped complex matrix and a complex transpose of a second square shaped complex matrix using function cblas_zgemm3m or cblas_zgemm.

Parameters
AThe first matrix.
BThe second matrix
CPointer to the resulted matrix. The calculated matrix is returned via this pointer.
matrix_sizeThe number rows in the matrices

Definition at line 207 of file common.cpp.