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

Function test_sparse_isometry_encoding

test/QAlg/Encode.test.cpp:102–147  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

100 return true;
101}
102static bool test_sparse_isometry_encoding()
103{
104 auto qvm = new CPUQVM();
105 qvm->init();
106 //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 };
107 //std::vector<double>data{ 0.15311858100051695,-0.0961350374871273,0.3859320687001368,-0.5634457467385428,0.1474901012487757,-0.45185782723129864,0.32284355187278985,-0.4132085412578166 };
108 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) };
109 QProg prog;
110 auto q = qvm->qAllocMany(3);
111 Encode encode_b;
112 std::map<std::string, double>mp;
113 std::map<std::string, complex<double>>mp1;
114
115 mp["000"] = -0.4012058758884066;
116 mp["001"] = 0.9121413556170931;
117 mp["111"] = 0.08385697660676902;
118 mp1["000"].real(0.11340744356593455);
119 mp1["000"].imag(0.060868874261929065);
120 mp1["100"].real(0.20777139811704742);
121 mp1["100"].imag(0.3642765242773252);
122 mp1["011"].real(0.0018744875304074278);
123 mp1["011"].imag(0.5721780883375533);
124 mp1["010"].real(0.44608846562195503);
125 mp1["010"].imag(0.5302652112262077);
126 //mp["000"] = 0.7071067811865476;
127 //mp["111"] = 0.7071067811865476;
128 //mp["100"] = 1;
129 encode_b.sparse_isometry(q, mp1);
130 prog << encode_b.get_circuit() << BARRIER(q);
131 QVec out_qubits = encode_b.get_out_qubits();
132 std::cout << prog << std::endl;
133 qvm->directlyRun(prog);
134 auto result = qvm->getQState();
135 for (auto &val : result) {
136 std::cout << "Amplitude" << ":" << val << std::endl;
137 }
138 //std::cout << result << std::endl;
139 /*auto result = qvm->probRunDict(prog, out_qubits, -1);
140 double normalization_constant = encode_b.get_normalization_constant();
141 for (auto &val : result)
142 {
143 std::cout << val.first << ":" << val.second*normalization_constant*normalization_constant << std::endl;
144 }*/
145 destroyQuantumMachine(qvm);
146 return true;
147}
148static bool test_efficient_sparse_encoding()
149{
150 auto qvm = new CPUQVM();

Callers 1

TESTFunction · 0.85

Calls 10

BARRIERClass · 0.85
initMethod · 0.45
qAllocManyMethod · 0.45
realMethod · 0.45
imagMethod · 0.45
sparse_isometryMethod · 0.45
get_circuitMethod · 0.45
get_out_qubitsMethod · 0.45
directlyRunMethod · 0.45
getQStateMethod · 0.45

Tested by

no test coverage detected