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

Function test_Amplitude_encoding4

test/QAlg/Encode.test.cpp:511–546  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

509 return false;
510}
511static bool test_Amplitude_encoding4()
512{
513 auto qvm = initQuantumMachine(QMachineType::CPU);
514 auto q = qvm->allocateQubits(2);
515 auto c = qvm->allocateCBits(2);
516
517
518 QStat test_qstat{ qcomplex_t(0.406270160898181, 0.0749820103002614),
519 qcomplex_t(0.195605655043143, 0.486587726445213),
520 qcomplex_t(0.241952125812726, 0.455619712343811),
521 qcomplex_t(0.31466450344542, 0.434912822865699) };
522 //vector<double>data{ 1,2,3,4,5,6 };
523 auto prog = QProg();
524 Encode encode_b;
525 //encode_b.amplitude_encode_recursive(q, test_qstat);
526 encode_b.amplitude_encode_recursive(q, test_qstat);
527 prog << encode_b.get_circuit();
528
529 std::cout << prog << std::endl;
530 //QCircuit test_cir = amplitude_encode(q, test_qstat);
531
532 //auto prog = QProg();
533 //prog << test_cir;
534 qvm->directlyRun(prog);
535 auto stat = qvm->getQState();
536
537 std::cout << "target_stat:\n" << stat << std::endl;
538
539 destroyQuantumMachine(qvm);
540
541 if (0 == mat_compare(stat, test_qstat, MAX_COMPARE_PRECISION)) {
542 return true;
543 }
544
545 return false;
546}
547TEST(Encode_, test1)
548{
549 bool test_val = false;

Callers 1

TESTFunction · 0.85

Calls 7

allocateCBitsMethod · 0.80
QProgClass · 0.50
allocateQubitsMethod · 0.45
get_circuitMethod · 0.45
directlyRunMethod · 0.45
getQStateMethod · 0.45

Tested by

no test coverage detected