| 1 |
//--------------------------------------------------------------------------- |
| 2 |
// Not gate |
| 3 |
//--------------------------------------------------------------------------- |
| 4 |
#include "QC_not.h" |
| 5 |
//--------------------------------------------------------------------------- |
| 6 |
/** |
| 7 |
* Constructor |
| 8 |
*/ |
| 9 |
QC_not::QC_not(const int _Target) : QCalcUnit() { |
| 10 |
Target = _Target; |
| 11 |
} |
| 12 |
//--------------------------------------------------------------------------- |
| 13 |
/** |
| 14 |
* Calculation |
| 15 |
*/ |
| 16 |
void QC_not::calc(int target, double BitsR[], double BitsI[], int NumberOfBits) { |
| 17 |
unsigned int states = (1 << (NumberOfBits - 1)); |
| 18 |
for (unsigned int i = 0; i < states; i++) { |
| 19 |
unsigned int ix0 = QCalcUnit::insert1(i, target); |
| 20 |
unsigned int ix1 = QCalcUnit::insert0(i, target); |
| 21 |
swap(BitsR[ix0], BitsR[ix1]); |
| 22 |
swap(BitsI[ix0], BitsI[ix1]); |
| 23 |
} |
| 24 |
} |
| 25 |
//--------------------------------------------------------------------------- |
| 26 |
void |
| 27 |
QC_not::Calc(QBits *qBits) { |
| 28 |
double *R = qBits->GetBitsR();//Real Part |
| 29 |
double *I = qBits->GetBitsI();//Imaginary Part |
| 30 |
int N = qBits->GetNumberOfQBits(); |
| 31 |
|
| 32 |
QC_not::calc(Target, R, I, N); |
| 33 |
} |
| 34 |
//--------------------------------------------------------------------------- |
| 35 |
#ifdef __USE__MPI |
| 36 |
void |
| 37 |
QC_not::calcmpi(int t1, double R[], double I[], int N) { |
| 38 |
double r0 = 0.0; |
| 39 |
double i0 = 0.0; |
| 40 |
double r1 = 0.0; |
| 41 |
double i1 = 0.0; |
| 42 |
unsigned int ix0, ix1; |
| 43 |
|
| 44 |
for (int i = 0; i < (1 << (N - 1)); i++) { |
| 45 |
// Obtain indices of state: |
| 46 |
ix0 = QCalcUnit::insert0(i, t1); |
| 47 |
ix1 = QCalcUnit::insert1(i, t1); |
| 48 |
|
| 49 |
bool bstore = setup(R, I, ix0, ix1, r0, i0, r1, i1); |
| 50 |
if (bstore) { |
| 51 |
// Calc: |
| 52 |
swap(r0, r1); |
| 53 |
swap(i0, i1); |
| 54 |
// Store: |
| 55 |
store(R, I, ix0, ix1, r0, i0, r1, i1); |
| 56 |
} |
| 57 |
} |
| 58 |
} |
| 59 |
#endif |
| 60 |
//--------------------------------------------------------------------------- |