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

Function test_efficient_sparse_encoding

test/QAlg/Encode.test.cpp:148–219  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

146 return true;
147}
148static bool test_efficient_sparse_encoding()
149{
150 auto qvm = new CPUQVM();
151 qvm->init();
152 //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 };
153 //std::vector<double>data{ 0.15311858100051695,-0.0961350374871273,0.3859320687001368,-0.5634457467385428,0.1474901012487757,-0.45185782723129864,0.32284355187278985,-0.4132085412578166 };
154 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) };
155 QProg prog;
156 auto q = qvm->qAllocMany(3);
157 Encode encode_b;
158 std::map<std::string, double>mp;
159 std::map<std::string, complex<double>>mp1;
160 //std::vector<double>data{0, 0, 0, -0.5, 0.5, -0.5, 0.5, 0};
161 mp["000"] = -0.4012058758884066;
162 mp["001"] = 0.9121413556170931;
163 mp["111"] = 0.08385697660676902;
164
165 mp1["00000000"].real(0.24310913564079167);
166 mp1["00000000"].imag(0.01159058947905379);
167 mp1["00000010"].real(0.31904155866953476);
168 mp1["00000010"].imag(0.09143678216616687);
169 mp1["00100000"].real(0.0023527412511721974);
170 mp1["00100000"].imag(0.06406955746132303);
171 mp1["00000001"].real(0.03157574906272091);
172 mp1["00000001"].imag(0.10105536367098665);
173 mp1["10000000"].real(0.047173075703916816);
174 mp1["10000000"].imag(0.16531181355873065);
175 mp1["00010000"].real(0.2450898977164231);
176 mp1["00010000"].imag(0.038670570507224736);
177 mp1["00001100"].real(0.1109015505954131);
178 mp1["00001100"].imag(0.07401422543633625);
179 mp1["01100000"].real(0.013151642285606184);
180 mp1["01100000"].imag(0.17502338909204943);
181
182 mp1["00000011"].real(0.30331286890722187);
183 mp1["00000011"].imag(0.05526812310938826);
184 mp1["00001010"].real(0.3099021978658747);
185 mp1["00001010"].imag(0.2289686686845677);
186 mp1["00001011"].real(0.17504000170596018);
187 mp1["00001011"].imag(0.12856765550595634);
188 mp1["00110001"].real(0.15693304322067672);
189 mp1["00110001"].imag(0.1910842222007265);
190 mp1["01100001"].real(0.1234790138508381);
191 mp1["01100001"].imag(0.29627849886345053);
192 mp1["10010100"].real(0.09158112115755046);
193 mp1["10010100"].imag(0.12798738473764856);
194 mp1["01011100"].real(0.0183266884240271);
195 mp1["01011100"].imag(0.31960954765528116);
196 mp1["01111000"].real(0.2848150218881516);
197 mp1["01111000"].imag(0.11119291552105852);
198 //mp["000"] = 0.7071067811865476;
199 //mp["111"] = 0.7071067811865476;
200 //mp["100"] = 1;
201 encode_b.efficient_sparse(q, data);
202 prog << encode_b.get_circuit() << BARRIER(q);
203 QVec out_qubits = encode_b.get_out_qubits();
204 std::cout << prog << std::endl;
205 qvm->directlyRun(prog);

Callers 1

TESTFunction · 0.85

Calls 10

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

Tested by

no test coverage detected