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

Function test_mps_encoding

test/QAlg/Encode.test.cpp:283–368  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

281 return true;
282}
283static bool test_mps_encoding()
284{
285 auto qvm = new CPUQVM();
286 qvm->init();
287 auto q = qvm->qAllocMany(2);
288 //QVec q1, q2, q3;
289 //for (int i = 0; i < 2; ++i) {
290 // q1.push_back(q[i]);
291 //}
292 //for (int i = 2; i < 4; ++i) {
293 // q2.push_back(q[i]);
294 //}
295 //for (int i = 4; i < 7; ++i) {
296 // q3.push_back(q[i]);
297 //}
298 std::vector<qcomplex_t>p = { qcomplex_t(0.4330127,0),qcomplex_t(0,0.5), qcomplex_t(0,0.55901699),qcomplex_t(0,0.5) };
299
300 Encode encode_b = Encode();
301 encode_b.approx_mps_encode(q, p, 1, 0);
302 //int dim = 4;
303 //Eigen::VectorXcd v2 = Eigen::VectorXcd::Random(1 << dim);
304 //v2.normalize();
305 //vector<std::complex<double>> data(v2.data(), v2.data() + v2.size());
306 ////double tmp = 0.0;
307 ////for (int i = 0; i < data.size(); ++i) {
308 //// tmp += data[i].real() * data[i].real()+ data[i].imag() * data[i].imag();
309 ////}
310 ////std::cout << tmp << std::endl;
311 ////QStat data{ qcomplex_t(0.016149328485063213,0.28882784478720575), qcomplex_t(0.06798688402448427,0.08462169020140721), qcomplex_t(0.3604460814011521,0.3721195422668412), qcomplex_t(0.034335701555517434,0.2825307847328346),qcomplex_t(0.4136767437887583,0.31439966778277506),qcomplex_t(0.18393603540428655,0.30588919458289876), qcomplex_t(0.1234427644644139,0.07995535607117477), qcomplex_t(0.3653047043801535,0.05179716511548195) };
312 ////std::vector<double>data{ 0.00010455027646829108, 0.000112165951999467, 0.00012026976656399777, 0.00012888769278913994, 0.00013804668784637316, 0.00014777470219979341, 0.00015810068613349398, 0.0001690545938777599, 0.0001806673851507228, 0.00019297102392962486, 0.00020599847426405876, 0.00021978369294236823, 0.00023436161882216627, 0.00024976815863643215, 0.00026604016908805074, 0.00028321543504814667, 0.0003013326436767946, 0.00032043135428928994, 0.0003405519637965668, 0.00036173566755516817, 0.00038402441546985037, 0.0004074608632011414, 0.0004320883183403972, 0.00045795068142645415, 0.0004850923816909944, 0.0005135583074336693, 0.0005433937309437296, 0.0005746442279015633, 0.0006073555912116153, 0.000641573739237675, 0.0006773446184318551, 0.0007147141003707094, 0.0007537278732348019, 0.0007944313277921636, 0.0008368694379715253, 0.0008810866361370585, 0.0009271266832039047, 0.0009750325337614142, 0.0010248461964000976, 0.001076608589467171, 0.0011303593925058894, 0.0011861368936638033, 0.0012439778333856323, 0.0013039172447372308, 0.001365988290737279, 0.0014302220991040896, 0.0014966475948546922, 0.0015652913312227358, 0.0016361773193908685, 0.0017093268575604616, 0.001784758359908941, 0.0018624871860101265, 0.0019425254713170382, 0.0020248819593294146, 0.0021095618360881313, 0.0021965665676579272, 0.0022858937412759063, 0.002377536910857247, 0.0024714854475615033, 0.0025677243961309097, 0.002666234337718773, 0.0027669912599285603, 0.0028699664347840337, 0.0029751263053478445, 0.0030824323816982776, 0.003191841146964451, 0.0033033039741057185, 0.003416767054104374, 0.0035321713362186703, 0.0036494524809194107, 0.003768540826104412, 0.003889361367153092, 0.004011833751348344, 0.00413587228715262, 0.004261385968783476, 0.004388278516487203, 0.004516448432859853, 0.004645789075513201, 0.004776188746326735, 0.004907530797469909, 0.005039693754317577, 0.005172551455318753, 0.005305973208814569, 0.0054398239667334996, 0.005573964515025005, 0.005708251680622479, 0.005842538554657211, 0.005976674731573177, 0.006110506563722806, 0.006243877430952528, 0.006376628024616782, 0.0065085966453906005, 0.006639619514181747, 0.006769531095378266, 0.006898164431602282, 0.007025351489079015, 0.007150923512671384, 0.007274711389573353, 0.007396546020603659, 0.007516258697991907, 0.007633681488504293, 0.0077486476207162674, 0.007860991875202582, 0.007970550976385304, 0.008077163984753975, 0.00818067268815165, 0.00828092199080624, 0.008377760298776247, 0.008471039900477659, 0.008560617340960593, 0.008646353788612659, 0.008728115392981057, 0.00880577363242479, 0.008879205650335653, 0.00894829457869834, 0.009012929847798069, 0.009073007480928014, 0.009128430372997352, 0.009179108551995685, 0.009224959422328536, 0.009265907989103069, 0.009301887062511453, 0.009332837441532443, 0.00935870807624813, 0.0093794562081529, 0.009395047487914955, 0.009405456070136247, 0.009410664684745041, 0.009410664684745041, 0.009405456070136247, 0.009395047487914955, 0.0093794562081529, 0.00935870807624813, 0.009332837441532443, 0.009301887062511453, 0.009265907989103069, 0.009224959422328536, 0.009179108551995673, 0.009128430372997352, 0.009073007480928014, 0.009012929847798069, 0.00894829457869834, 0.008879205650335653, 0.00880577363242479, 0.008728115392981057, 0.008646353788612659, 0.008560617340960593, 0.008471039900477659, 0.008377760298776247, 0.00828092199080624, 0.00818067268815165, 0.008077163984753975, 0.007970550976385304, 0.007860991875202582, 0.0077486476207162674, 0.007633681488504293, 0.007516258697991907, 0.007396546020603659, 0.007274711389573353, 0.007150923512671384, 0.007025351489079015, 0.006898164431602282, 0.006769531095378266, 0.006639619514181747, 0.0065085966453906005, 0.006376628024616782, 0.006243877430952528, 0.006110506563722806, 0.005976674731573177, 0.005842538554657211, 0.005708251680622479, 0.005573964515024972, 0.0054398239667334996, 0.005305973208814569, 0.005172551455318753, 0.005039693754317577, 0.004907530797469909, 0.004776188746326735, 0.004645789075513201, 0.004516448432859853, 0.0043882785164871705, 0.004261385968783476, 0.00413587228715262, 0.004011833751348344, 0.003889361367153092, 0.0037685408261043814, 0.0036494524809194107, 0.0035321713362186703, 0.003416767054104374, 0.0033033039741057185, 0.003191841146964423, 0.0030824323816982776, 0.0029751263053478445, 0.0028699664347840337, 0.0027669912599285603, 0.002666234337718773, 0.0025677243961309097, 0.0024714854475615033, 0.002377536910857247, 0.0022858937412759063, 0.0021965665676579272, 0.0021095618360881313, 0.0020248819593294146, 0.0019425254713170382, 0.0018624871860101265, 0.001784758359908941, 0.0017093268575604616, 0.0016361773193908685, 0.0015652913312227358, 0.0014966475948546922, 0.0014302220991040896, 0.001365988290737279, 0.0013039172447372308, 0.0012439778333856323, 0.0011861368936638033, 0.0011303593925058894, 0.001076608589467171, 0.0010248461964000976, 0.0009750325337614142, 0.0009271266832039047, 0.0008810866361370585, 0.0008368694379715253, 0.0007944313277921636, 0.0007537278732348019, 0.0007147141003707094, 0.0006773446184318551, 0.000641573739237675, 0.0006073555912116153, 0.0005746442279015633, 0.0005433937309437296, 0.0005135583074336693, 0.0004850923816909944, 0.00045795068142645415, 0.00043208831834039106, 0.0004074608632011414, 0.00038402441546985037, 0.00036173566755516817, 0.0003405519637965668, 0.00032043135428928485, 0.0003013326436767946, 0.00028321543504814667, 0.00026604016908805074, 0.00024976815863643215, 0.00023436161882216627, 0.00021978369294236823, 0.00020599847426405876, 0.00019297102392962486, 0.0001806673851507228, 0.0001690545938777599, 0.00015810068613349398, 0.00014777470219979341, 0.00013804668784637316, 0.00012888769278913994, 0.00012026976656399777, 0.000112165951999467, 0.00010455027646829108 };
313 ////std::vector<double>data{ 0.00103373, 0.00406266, 0.01256227, 0.03102829, 0.06207927, 0.10191518
314 //// , 0.13893765, 0.15903557, 0.15442565, 0.12842124, 0.0922782, 0.05776894
315 //// , 0.03175181, 0.01543281, 0.00667795, 0.00258877 };
316 ////std::vector<double>data{ 0,0.5,0.5,0,0.5,0,0,0,0.5,0,0,0,0,0,0,0 };
317 ////std::vector<double>data{ 0.15311858100051695,-0.0961350374871273,0.3859320687001368,-0.5634457467385428,0.1474901012487757,-0.45185782723129864,0.32284355187278985,-0.4132085412578166 };
318 ////std::vector<double>data{ 0.6793113376921358, 0.1376859100584252, 0.720435424880283, 0.02348393561289133};
319 ////for (int i = 0; i < data.size(); ++i) {
320 //// data[i] = sqrt(data[i]);
321 ////}
322 //QProg prog;
323 //auto q = qvm->qAllocMany(dim);
324 ////auto circuit = QCircuit();
325 ////circuit << H(q[0]);
326 ////QStat q_mat(16);
327 ////q_mat[0] = (qcomplex_t)1.0;
328 ////q_mat[5]= (qcomplex_t)1.0;
329 ////q_mat[11] = (qcomplex_t)1.0;
330 ////q_mat[14] = (qcomplex_t)1.0;
331 ////circuit << QOracle(q, q_mat);
332 //
333 //Encode encode_b;
334 //auto start = chrono::system_clock::now();
335 ////std::cout << "start" << std::endl;
336 //encode_b.approx_mps_encode(q, data, 2, 1000);
337 //auto end = chrono::system_clock::now();
338 //auto duration = chrono::duration_cast<chrono::microseconds>(end - start);
339 //std::cout << double(duration.count()) * chrono::microseconds::period::num / chrono::microseconds::period::den
340 // << " s" << std::endl;

Callers

nothing calls this directly

Calls 9

EncodeClass · 0.50
QProgClass · 0.50
initMethod · 0.45
qAllocManyMethod · 0.45
approx_mps_encodeMethod · 0.45
get_circuitMethod · 0.45
get_out_qubitsMethod · 0.45
directlyRunMethod · 0.45
getQStateMethod · 0.45

Tested by

no test coverage detected