| 111 | } |
| 112 | |
| 113 | int main() |
| 114 | { |
| 115 | cout << "4-qubit Simon Algorithm\n" << endl; |
| 116 | cout << "f(x)=f(y)\t x+y=s" << endl; |
| 117 | cout << "input f(x),f(x):[0,3]" << endl; |
| 118 | vector<int> funcvalue(4, 0); |
| 119 | cout << "input f(0):" << endl; |
| 120 | cin >> funcvalue[0]; |
| 121 | cout << "input f(1):" << endl; |
| 122 | cin >> funcvalue[1]; |
| 123 | cout << "input f(2):" << endl; |
| 124 | cin >> funcvalue[2]; |
| 125 | cout << "input f(3):" << endl; |
| 126 | cin >> funcvalue[3]; |
| 127 | cout << "f(0)=" << funcvalue[0] << endl; |
| 128 | cout << "f(1)=" << funcvalue[1] << endl; |
| 129 | cout << "f(2)=" << funcvalue[2] << endl; |
| 130 | cout << "f(3)=" << funcvalue[3] << endl; |
| 131 | cout << " Programming the circuit..." << endl; |
| 132 | init(QMachineType::CPU); |
| 133 | int qubit_num = 4; |
| 134 | int cbit_nun = 2; |
| 135 | vector<Qubit*> qVec = qAllocMany(4); |
| 136 | vector<ClassicalCondition> cVec = cAllocMany(2); |
| 137 | QProg simonAlgorithm = Simon_QProg(qVec, cVec, funcvalue); |
| 138 | vector<int> result(20); |
| 139 | |
| 140 | for (auto i = 0; i < 20; i++) |
| 141 | { |
| 142 | directlyRun(simonAlgorithm); |
| 143 | result[i] = cVec[0].get_val() * 2 + cVec[1].get_val(); |
| 144 | } |
| 145 | if (find(result.begin(), result.end(), 3) != result.end()) |
| 146 | { |
| 147 | if (find(result.begin(), result.end(), 2) != result.end()) |
| 148 | { |
| 149 | cout << "s=00" << endl; |
| 150 | } |
| 151 | else |
| 152 | { |
| 153 | cout << "s=11" << endl; |
| 154 | } |
| 155 | |
| 156 | } |
| 157 | else if (find(result.begin(), result.end(), 2) != result.end()) |
| 158 | { |
| 159 | cout << "s=01" << endl; |
| 160 | } |
| 161 | else if (find(result.begin(), result.end(), 1) != result.end()) |
| 162 | { |
| 163 | cout << "s=10" << endl; |
| 164 | } |
| 165 | finalize(); |
| 166 | } |
nothing calls this directly
no test coverage detected