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

Function test_Amplitude_encoding1

test/QAlg/Encode.test.cpp:425–460  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

423}
424
425static bool test_Amplitude_encoding1()
426{
427 auto qvm = new CPUQVM();
428 qvm->init();
429 //std::vector<double>data{ -0.33164128327780906,-0.23433373435840027,-0.00022877626650846954,0.3466895582845477,0.36968371696590785,-0.21966111818142703,-0.28122454968118343,0.2954805505078439,0.2060812114310625,0.28816304973225565,0.13470785340813266,0.06207383012753573,-0.14157790059772607,0.15044744783305566,-0.28050173370498876,-0.3077795693383025 };
430 //std::vector<double>data{ 0.15311858100051695,-0.0961350374871273,0.3859320687001368,-0.5634457467385428,0.1474901012487757,-0.45185782723129864,0.32284355187278985,-0.4132085412578166 };
431 //std::vector<complex<double>>data{qcomplex_t(0.33510517, 0.29640703), qcomplex_t(-0.11504671, -0.05932087), qcomplex_t(-0.11146904, 0.11053713), qcomplex_t(0.18010564, 0.15731823), qcomplex_t(-0.3284375, 0.40864014), qcomplex_t(-0.19391152, 0.2075545), qcomplex_t(-0.30391936, 0.36735511), qcomplex_t(0.32367291, 0.11680073)};
432 //std::vector<complex<double>>data{ qcomplex_t(-0.13792979841421985, 0.14135138210029866),qcomplex_t(-0.1390065521329917, 0.027905778367451294), qcomplex_t(0.1408303661581104, 0.1904935417178447), qcomplex_t(-0.413408661519566, 0.39732552760462225), qcomplex_t(-0.451018978400839, 0.05084981631268899), qcomplex_t(-0.28129960014056354, 0.28003182131256205), qcomplex_t(-0.15455196636034582, 0.0831192522241199), qcomplex_t(-0.18327917974198926, 0.35785589125336675) };
433 QStat test_qstat{ qcomplex_t(0.406270160898181, 0.0749820103002614),
434 qcomplex_t(0.195605655043143, 0.486587726445213),
435 qcomplex_t(0.241952125812726, 0.455619712343811),
436 qcomplex_t(0.31466450344542, 0.434912822865699) };
437 //std::vector<double>data{ -11,-22,-3,4,5,6 };
438 auto prog = QProg();
439 auto q = qvm->qAllocMany(4);
440 Encode encode_b;
441 encode_b.amplitude_encode(q, test_qstat);
442 prog << encode_b.get_circuit();
443 std::cout << prog << std::endl;
444 QVec out_qubits = encode_b.get_out_qubits();
445 qvm->directlyRun(prog);
446 auto result = qvm->getQState();
447 //auto result = qvm->probRunDict(prog, q, -1);
448 int k = 0;
449 for (auto &val : result) {
450 std::cout << "Amplitude:" << val << std::endl;
451 }
452 /*for (auto &val : result)
453 {
454 double temp = k >= (int)data.size() ? 0 : data[k];
455 std::cout << "Amplitude:" << val.first << ":" << val.second*normalization_constant*normalization_constant << "," << "Originial value:" << temp * temp << std::endl;
456 ++k;
457 }*/
458 destroyQuantumMachine(qvm);
459 return true;
460}
461static bool test_Amplitude_encoding2()
462{
463 auto qvm = new CPUQVM();

Callers 1

TESTFunction · 0.85

Calls 8

QProgClass · 0.50
initMethod · 0.45
qAllocManyMethod · 0.45
amplitude_encodeMethod · 0.45
get_circuitMethod · 0.45
get_out_qubitsMethod · 0.45
directlyRunMethod · 0.45
getQStateMethod · 0.45

Tested by

no test coverage detected