@@ -21,7 +21,7 @@ limitations under the License.
21
21
USING_QPANDA
22
22
using namespace std ;
23
23
24
- static size_t g_shot = 100000 ;
24
+ static size_t g_shot = 10000 ;
25
25
26
26
static uint32_t classcial_search (const std::vector<uint32_t >& search_space, const std::vector<uint32_t >& search_data,
27
27
std::vector<size_t >& search_result)
@@ -47,7 +47,10 @@ static uint32_t quantum_grover_search(const std::vector<uint32_t>& search_space,
47
47
uint32_t repeat_times = 0 ;
48
48
auto machine = initQuantumMachine (CPU);
49
49
machine->setConfigure ({ 64 ,64 });
50
- auto x = machine->allocateCBit ();
50
+
51
+ CPUQVM _tmp_qvm;
52
+ _tmp_qvm.init ();
53
+ auto x = _tmp_qvm.allocateCBit ();
51
54
52
55
std::vector<size_t > search_result_for_check;
53
56
for (size_t i = 0 ; i < search_space.size (); ++i)
@@ -85,14 +88,20 @@ static uint32_t quantum_grover_search(const std::vector<uint32_t>& search_space,
85
88
printf (" Strat measure.\n " );
86
89
// auto result = probRunDict(grover_Qprog, measure_qubits);
87
90
grover_Qprog << MeasureAll (measure_qubits, c);
91
+ write_to_originir_file (grover_Qprog, machine, " Grover_prog.ir" );
92
+
93
+ // just for test
94
+ // auto _grover_prog = convert_originir_to_qprog("Grover_prog.ir", machine);
95
+ // auto result = runWithConfiguration(_grover_prog, c, g_shot);
96
+
88
97
auto result = runWithConfiguration (grover_Qprog, c, g_shot);
89
98
90
99
// get result
91
100
std::map<string, double > normal_result;
92
101
for (const auto & _r : result){
93
102
normal_result.insert (std::make_pair (_r.first , (double )_r.second /(double )g_shot));
94
103
}
95
- search_result = search_target_from_measure_result (normal_result);
104
+ search_result = search_target_from_measure_result (normal_result, measure_qubits. size () );
96
105
if ((search_result.size () > 0 )
97
106
|| ((search_result.size () == 0 ) && (max_repeat < repeat_times))){
98
107
break ;
@@ -180,7 +189,7 @@ static uint32_t quantum_walk_search(const std::vector<uint32_t>& search_space, c
180
189
for (const auto & _r : result) {
181
190
normal_result.insert (std::make_pair (_r.first , (double )_r.second / (double )g_shot));
182
191
}
183
- search_result = search_target_from_measure_result (normal_result);
192
+ search_result = search_target_from_measure_result (normal_result, measure_qubits. size () );
184
193
if ((search_result.size () > 0 )
185
194
|| ((search_result.size () == 0 ) && (4 < repeat_times))) {
186
195
break ;
@@ -260,16 +269,18 @@ int main(int argc, char* argv[])
260
269
{
261
270
const std::string parameter_descr_str = R"(
262
271
The legal parameter form is as follows:
263
- QGrover .exe [Option] [search-space-file] [search-data]
272
+ Grover_Algorithm .exe [Option] [search-space-file] [search-data]
264
273
Option:
265
274
-g: run Grover-search-algorithm
266
275
-c: run classcial-search-algorithm
267
276
-r: run quantum-walk-search-algorithm
268
277
example:
269
- To search for 100 in data.txt use Grover-search-algorithm, execute the following command:
270
- Search.exe -g data.txt 100
278
+ To search for 2 in data.txt use Grover-search-algorithm, execute the following command:
279
+ Grover_Algorithm.exe -g data.txt 2
280
+ data.txt:
281
+ 2,4,12,23,1,2,3,4,3,3,21,8,
271
282
)" ;
272
- #if 1
283
+ #if 0
273
284
/* read param
274
285
*/
275
286
int search_type = -1; /**< 0: classcial-search-algorithm; 1:Grover-search-algorithm; 2:quantum-walk-search-algorithm */
@@ -314,8 +325,8 @@ int main(int argc, char* argv[])
314
325
return -1;
315
326
}
316
327
#else
317
- int search_type = 2 ;
318
- std::string data_file = "data1 .txt";
328
+ int search_type = 1 ;
329
+ std::string data_file = " F: \\ data .txt" ;
319
330
std::vector<uint32_t > search_data = {21 };
320
331
#endif
321
332
/* run search algorithm
0 commit comments