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

Method PMeasure

Core/QuantumMachine/OriginQVM.cpp:747–795  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

745}
746
747prob_tuple IdealQVM::PMeasure(QVec qubit_vector, int select_max)
748{
749 if (0 == qubit_vector.size())
750 {
751 QCERR("the size of qubit_vector is zero");
752 throw invalid_argument("the size of qubit_vector is zero");
753 }
754
755 if (nullptr == _pGates)
756 {
757 QCERR("_pGates is null");
758 throw qvm_attributes_error("_pGates is null");
759 }
760 try
761 {
762 Qnum vqubit;
763 for (auto aiter = qubit_vector.begin(); aiter != qubit_vector.end(); ++aiter)
764 {
765 vqubit.push_back((*aiter)->getPhysicalQubitPtr()->getQubitAddr());
766 }
767
768 prob_tuple result_vec;
769
770 prob_vec pmeasure_vector;
771 _pGates->pMeasure(vqubit, pmeasure_vector);
772
773 for (auto i = 0; i < pmeasure_vector.size(); ++i)
774 {
775 result_vec.emplace_back(make_pair(i, pmeasure_vector[i]));
776 }
777 sort(result_vec.begin(), result_vec.end(),
778 [=](std::pair<size_t, double> a, std::pair<size_t, double> b) {return a.second > b.second; });
779
780 if ((select_max == -1) || (pmeasure_vector.size() <= select_max))
781 {
782 return result_vec;
783 }
784 else
785 {
786 result_vec.erase(result_vec.begin() + select_max, result_vec.end());
787 return result_vec;
788 }
789 }
790 catch (const std::exception& e)
791 {
792 QCERR(e.what());
793 throw result_get_fail(e.what());
794 }
795}
796
797prob_vec IdealQVM::PMeasure_no_index(QVec qubit_vector)
798{

Callers

nothing calls this directly

Calls 13

sortFunction · 0.85
result_get_failClass · 0.85
getQubitAddrMethod · 0.80
getPhysicalQubitPtrMethod · 0.80
sizeMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
push_backMethod · 0.45
pMeasureMethod · 0.45
emplace_backMethod · 0.45
eraseMethod · 0.45

Tested by

no test coverage detected