MCPcopy Create free account
hub / github.com/OriginQ/QPanda-2 / controlfunc

Function controlfunc

Applications/SimonAlgorithm/SimonAlgorithm.cpp:24–78  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

22using namespace QPanda;
23
24QCircuit controlfunc(vector<Qubit*> qVec, size_t index, int value)
25{
26 auto length = qVec.size() / 2;
27 auto cfunc = CreateEmptyCircuit();
28 vector<Qubit*> qvtemp;
29 qvtemp.insert(qvtemp.begin(), qVec.begin(), qVec.begin() + length);
30 if (index == 1)
31 {
32 cfunc << X(qVec[0]);
33 }
34 else if (index == 2)
35 {
36 cfunc << X(qVec[1]);
37 }
38 else if (index == 0)
39 {
40 cfunc << X(qVec[0]);
41 cfunc << X(qVec[1]);
42 }
43 if (value == 1)
44 {
45 QGate temp = X(qVec[3]);
46 temp.setControl(qvtemp);
47 cfunc << temp;
48 }
49 else if (value == 2)
50 {
51 QGate temp1 = X(qVec[2]);
52 temp1.setControl(qvtemp);
53 cfunc << temp1;
54 }
55 else if (value == 3)
56 {
57 QGate temp2 = X(qVec[2]);
58 temp2.setControl(qvtemp);
59 cfunc << temp2;
60 QGate temp3 = X(qVec[3]);
61 temp3.setControl(qvtemp);
62 cfunc << temp3;
63 }
64 if (index == 1)
65 {
66 cfunc << X(qVec[0]);
67 }
68 else if (index == 2)
69 {
70 cfunc << X(qVec[1]);
71 }
72 else if (index == 0)
73 {
74 cfunc << X(qVec[0]);
75 cfunc << X(qVec[1]);
76 }
77 return cfunc;
78}
79
80
81//f(x),x is 2bits variable

Callers 1

oraclefuncFunction · 0.85

Calls 5

XClass · 0.85
sizeMethod · 0.45
insertMethod · 0.45
beginMethod · 0.45
setControlMethod · 0.45

Tested by

no test coverage detected