Develop and Download Open Source Software

Browse Subversion Repository

Contents of /trunk/calcunits/QC_pauliY.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1 - (show annotations) (download) (as text)
Wed Aug 3 10:14:23 2011 UTC (12 years, 9 months ago) by kaityo
File MIME type: text/x-c++src
File size: 2070 byte(s)
First commit
1 //---------------------------------------------------------------------------
2 // Pauli Y gate
3 //---------------------------------------------------------------------------
4 #include "QC_pauliY.h"
5 //---------------------------------------------------------------------------
6 /**
7 * Constructor
8 */
9 QC_pauliY::QC_pauliY(int _Target) : QCalcUnit() {
10 Target = _Target;
11 }
12 //---------------------------------------------------------------------------
13 /**
14 * Calculate
15 */
16 void
17 QC_pauliY::calc(int target, double R[], double I[], int NumberOfBits) {
18 unsigned int state = 1<< (NumberOfBits - 1);
19
20 double r0,r1,i0,i1;
21 for (unsigned int i=0;i<state;i++) {
22 unsigned int ix0 = insert0(i,target);
23 unsigned int ix1 = insert1(i,target);
24
25 //pauli Y
26 r0 = R[ix0];
27 i0 = I[ix0];
28 r1 = R[ix1];
29 i1 = I[ix1];
30
31 R[ix0] = i1;
32 I[ix0] = -r1;
33 R[ix1] = -i0;
34 I[ix1] = r0;
35 }
36 }
37 //---------------------------------------------------------------------------
38 void QC_pauliY::Calc(QBits *qBits)
39 {
40 int N = qBits->GetNumberOfQBits();
41 double *R = qBits->GetBitsR();//Real Part
42 double *I = qBits->GetBitsI();//Imaginary Part
43
44 QC_pauliY::calc(Target, R, I, N);
45 }
46 //---------------------------------------------------------------------------
47 #ifdef __USE__MPI
48 void
49 QC_pauliY::calcmpi(int t1, double R[], double I[], int N) {
50 double r0 = 0.0;
51 double i0 = 0.0;
52 double r1 = 0.0;
53 double i1 = 0.0;
54 unsigned int ix0, ix1;
55
56 for (int i = 0; i < (1 << (N - 1)); i++)
57 {
58 // Obtain indices of state:
59 ix0 = QCalcUnit::insert0(i, t1);
60 ix1 = QCalcUnit::insert1(i, t1);
61
62 bool bstore = setup(R, I, ix0, ix1, r0, i0, r1, i1);
63 if (bstore) {
64 double nr0 = i1;
65 double ni0 = -r1;
66 double nr1 = -i0;
67 double ni1 = r0;
68 // Store:
69 store(R, I, ix0, ix1, nr0, ni0, nr1, ni1);
70 }
71 }
72 }
73 #endif
74 //---------------------------------------------------------------------------

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26