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

Method QST_simulation

Core/Utilities/Tools/QSTsimulation.cpp:25–140  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

23
24
25std::vector<double> QPanda::QST_simulation(QCircuit& cir, QVec& qvec, size_t shots)
26{
27 auto encoding_circuit = [](QVec& qubits, vector<double>& prob)->QCircuit
28 {
29 QCircuit prob_cir = amplitude_encode(qubits, prob);
30 return prob_cir;
31 };
32
33 auto Tomography_cir = [](QCircuit source_cir, QCircuit prob_cir, Qubit* control_bit)->QCircuit
34 {
35 QCircuit tomo_cir = QCircuit();
36 tomo_cir << H(control_bit)
37 << X(control_bit)
38 << source_cir.control(control_bit)
39 << X(control_bit)
40 << prob_cir.control(control_bit)
41 << H(control_bit);
42 return tomo_cir;
43 };
44
45 QSTSIM qst_sim(cir);
46 QCircuit source_cir = qst_sim.get_source_circuit();
47 size_t bits_number = source_cir.get_used_qubits(qvec);
48
49 int dim = 1 << bits_number;
50 double measure_num = shots * dim * std::log(dim) / threshold / threshold;
51 long long N = ceil(measure_num);
52 auto machine = shared_ptr<CPUQVM>(new CPUQVM());
53 machine->init();
54 auto qubits = machine->qAllocMany(bits_number + 1);
55 auto cbits = machine->cAllocMany(bits_number + 1);
56
57 QVec main_qubits(qubits.begin(), qubits.end() - 1);
58 std::vector<QPanda::ClassicalCondition> main_cbits(cbits.begin(), cbits.end() - 1);
59 Qubit* control_bit = qubits[bits_number];
60
61 std::vector<double> prob_result;
62 std::vector<string> source_state;
63 QProg source_prog = QProg(cir);
64 source_prog << MeasureAll(qubits, cbits);
65 auto source_results = machine->runWithConfiguration(source_prog, cbits, N);
66 int item = 1 << bits_number;
67 int source_item_flag;
68 for (int i = 0; i < item; i++)
69 {
70 source_item_flag = 0;
71 bitset<16> bs(i);
72 string present_i_bin = bs.to_string().substr(bs.size() - bits_number, bs.size());
73 for (auto& ele : source_results)
74 {
75 if (stoi(ele.first, nullptr, 2) == i)
76 {
77 source_state.push_back(ele.first);
78 prob_result.push_back(sqrt(double(ele.second) / double(N)));
79 source_item_flag = 1;
80 break;
81 }
82 }

Callers

nothing calls this directly

Calls 15

HClass · 0.85
XClass · 0.85
get_source_circuitMethod · 0.80
amplitude_encodeFunction · 0.50
QCircuitClass · 0.50
logFunction · 0.50
ceilFunction · 0.50
QProgClass · 0.50
sqrtFunction · 0.50
controlMethod · 0.45
get_used_qubitsMethod · 0.45
initMethod · 0.45

Tested by

no test coverage detected