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

Method runWithConfiguration

Core/VirtualQuantumProcessor/SparesQVM/SparseQVM.cpp:900–983  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

898}
899
900std::map<std::string, size_t> SparseSimulator::runWithConfiguration(QProg& prog, std::vector<ClassicalCondition>& cbits, int shots)
901{
902
903 handle_prog_to_queue(prog);
904 _execute_queued_ops();
905
906 auto m_state = _quantum_state->get_universal_wavefunction();
907
908 TraversalConfig traver_param;
909 QProgCheck prog_check;
910 prog_check.execute(prog.getImplementationPtr(), nullptr, traver_param);
911
912 if (0 == traver_param.m_measure_qubits.size())
913 {
914 return std::map<std::string, size_t>();
915 }
916
917 if (shots < 1)
918 QCERR_AND_THROW(run_fail, "shots data error");
919 std::map<std::string, size_t> result_map;
920 std::vector<double> random_nums(shots, 0);
921 for (size_t i = 0; i < shots; i++)
922 {
923 random_nums[i] = random_generator19937();
924 }
925 std::sort(random_nums.begin(), random_nums.end(), [](double& a, double b) { return a > b; });
926 prob_vec probs;
927 Qnum qubits_nums = traver_param.m_measure_qubits;
928
929 std::unordered_multimap<size_t, CBit*> qubit_cbit_map;
930 for (size_t i = 0; i < traver_param.m_measure_cc.size(); i++)
931 {
932 qubit_cbit_map.insert({ traver_param.m_measure_qubits[i], traver_param.m_measure_cc[i] });
933 }
934
935 prob_vec probs_tmp;
936 std::map<std::string, double> prob_map;
937 std::vector<std::string> key_data;
938 for (auto current_state = (m_state).begin(); current_state != (m_state).end(); ++current_state) {
939 double square_amplitude = std::norm(current_state->second);
940 probs.push_back(square_amplitude);
941 std::string str = current_state->first;
942 std::reverse(str.begin(), str.end());
943 key_data.push_back(str);
944
945 }
946
947 std::vector<int> key_count;
948 for (int i = 0; i < key_data.size(); i++)
949 {
950 key_data[i] = key_data[i].substr(0, cbits.size());
951 prob_map.insert(std::pair<std::string, double>(key_data[i], probs[i]));
952 }
953
954 double p_sum = 0;
955
956 for (auto current_prob = prob_map.begin(); current_prob != prob_map.end(); ++current_prob)
957 {

Callers

nothing calls this directly

Calls 15

random_generator19937Function · 0.85
sortFunction · 0.85
normFunction · 0.85
executeMethod · 0.45
getImplementationPtrMethod · 0.45
sizeMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
insertMethod · 0.45
push_backMethod · 0.45
rbeginMethod · 0.45

Tested by

no test coverage detected