28 #include <tbb/scalable_allocator.h> 74 void*
qgd_calloc(
int element_num,
int size,
int alignment ) {
76 void* ret = scalable_aligned_malloc( size*element_num,
CACHELINE);
77 memset(ret, 0, element_num*size);
90 void*
qgd_realloc(
void* aligned_ptr,
int element_num,
int size,
int alignment ) {
92 void* ret = scalable_aligned_realloc(aligned_ptr, size*element_num,
CACHELINE);
106 scalable_aligned_free(ptr);
118 if (n == 0)
return 1;
119 if (n == 1)
return 2;
133 if ( involved_qbits.size() == 0 ) {
134 involved_qbits.push_back( qbit );
137 for(std::vector<int>::iterator it = involved_qbits.begin(); it != involved_qbits.end(); ++it) {
139 int current_val = *it;
141 if (current_val == qbit) {
144 else if (current_val > qbit) {
145 involved_qbits.insert( it, qbit );
152 involved_qbits.push_back( qbit );
172 int element_index = idx*matrix_size + idx;
173 mtx[element_index].real = 1.0;
193 if (mtxs.size() == 0 ) {
209 for(std::vector<Matrix>::iterator it=++mtxs.begin(); it != mtxs.end(); ++it) {
243 int element_idx = idx*matrix_size+idx;
244 mtx[element_idx].real = mtx[element_idx].real - scalar.
real;
245 mtx[element_idx].imag = mtx[element_idx].imag - scalar.
imag;
294 int element_num = b.
size();
296 for (
int idx=0; idx<element_num; idx++) {
316 std::string error(
"mult: The input argument b should be a single-column vector.");
323 tbb::parallel_for( tbb::blocked_range<int>(0, n_rows, 32), [&](tbb::blocked_range<int> r) {
325 for (
int idx=r.begin(); idx<r.end(); ++idx){
329 int nz_start = a.
indptr[idx];
330 int nz_end = a.
indptr[idx+1];
332 for (
int nz_idx=nz_start; nz_idx<nz_end; nz_idx++){
338 ret[idx].real += result.
real;
339 ret[idx].imag += result.
imag;
363 else if ( a.
real > 0 && a.
imag <= 0 ) {
367 else if ( a.
real < 0 && a.
imag > 0 ) {
368 angle = std::atan(a.
imag/a.
real) + M_PI;
371 else if ( a.
real < 0 && a.
imag <= 0 ) {
372 angle = std::atan(a.
imag/a.
real) - M_PI;
375 else if ( std::abs(a.
real) < 1e-8 && a.
imag > 0 ) {
397 int samples = b.
cols;
402 for (
int rdx=0; rdx<samples; rdx++){
405 for(
int cdx=0; cdx<samples; cdx++){
406 d[rdx] = d[rdx] - A[rdx*samples+cdx]*x0[cdx];
410 sk = sk + d[rdx]*d[rdx];
414 while (std::sqrt(sk/b.
cols) > tol && iter<1000){
418 for (
int rdx=0; rdx<samples; rdx++){
422 for(
int cdx=0; cdx<samples; cdx++){
423 Ad[rdx] = Ad[rdx] + A[rdx*samples+cdx]*d[cdx];
426 dAd = dAd + d[rdx]*Ad[rdx];
429 double mu_k = sk / dAd;
432 for(
int idx=0; idx<samples; idx++){
434 x0[idx] = x0[idx] + mu_k*d[idx];
435 g[idx] = g[idx] + mu_k*Ad[idx];
436 sk_new = sk_new + g[idx]*g[idx];
440 for (
int idx=0; idx<samples;idx++){
441 d[idx] = (sk_new/sk)*d[idx] - g[idx];
Matrix dot(Matrix &A, Matrix &B)
Call to calculate the product of two complex matrices by calling method zgemm3m from the CBLAS librar...
void * qgd_calloc(int element_num, int size, int alignment)
custom defined memory allocation function.
void conjugate_gradient(Matrix_real A, Matrix_real b, Matrix_real &x0, double tol)
void qgd_free(void *ptr)
custom defined memory release function.
QGD_Complex16 mult(QGD_Complex16 &a, QGD_Complex16 &b)
Call to calculate the product of two complex scalars.
Class to store data of complex arrays and its properties.
scalar * get_data() const
Call to get the pointer to the stored data.
Matrix reduce_zgemm(std::vector< Matrix > &mtxs)
Calculate the product of several square shaped complex matrices stored in a vector.
double arg(const QGD_Complex16 &a)
Call to retrieve the phase of a complex number.
int rows
The number of rows.
int cols
The number of columns.
Structure type representing complex numbers in the SQUANDER package.
int Power_of_2(int n)
Calculates the n-th power of 2.
Class to store data of complex arrays and its properties.
int size() const
Call to get the number of the allocated elements.
void subtract_diag(Matrix &mtx, QGD_Complex16 scalar)
Call to subtract a scalar from the diagonal of a complex matrix.
Matrix create_identity(int matrix_size)
Call to create an identity matrix.
Header file for commonly used functions and wrappers to CBLAS functions.
double activation_function(double Phi, int limit)
?????
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...
double real
the real part of a complex number
void * qgd_realloc(void *aligned_ptr, int element_num, int size, int alignment)
custom defined memory reallocation function.
result
the result of the Qiskit job
Class to store data of complex arrays and its properties.
double imag
the imaginary part of a complex number