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

Method pmeasure_subset

Extensions/PilotOSMachine/QPilotOSMachine.cpp:464–507  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

462}
463
464std::unordered_map<std::string, std::complex<double>> QPilotOSMachine::pmeasure_subset(QProg& prog,
465 const std::vector<std::string>& amplitude, int backendID)
466{
467 try
468 {
469 QPanda::QVec qubit_vector;
470 auto m_qubit_size = get_all_used_qubits(prog, qubit_vector);
471 for (auto m_values : amplitude)
472 {
473 auto m_value = std::atoll(m_values.c_str());
474 if (m_value >= std::pow(2, qubit_vector.size())|| m_value<0)
475 {
476 throw std::runtime_error("pmeasure_subset parms error:" + m_value);
477 }
478 }
479 if (m_machine_type == "Pilot")
480 {
481 std::map<std::string, std::complex<double>> result;
482 std::unordered_map<std::string, std::complex<double>> m_result;
483 PilotQVM::ErrorCode err_code;
484 if ((err_code = m_pilot_machine->execute_partial_amplitude_task(
485 convert_qprog_to_originir(prog, this), amplitude, result, backendID))
486 != PilotQVM::ErrorCode::NO_ERROR_FOUND)
487 {
488 throw std::runtime_error("pmeasure_subset run error,please check the parms,error code:"
489 + std::to_string(int(err_code)));
490 }
491 for (auto rest : result)
492 {
493 m_result[rest.first] = rest.second;
494 }
495 return m_result;
496 }
497 QPanda::PartialAmplitudeQVM m_partial_amplitude_machine;
498 m_partial_amplitude_machine.init();
499 m_partial_amplitude_machine.qAllocMany(m_qubit_size);
500 m_partial_amplitude_machine.run(prog);
501 return m_partial_amplitude_machine.pmeasure_subset(amplitude);
502 }
503 catch (const std::exception& e)
504 {
505 PTraceInfo("Catch unknow exception" << e.what());
506 }
507}
508
509std::map<std::string, double> QPilotOSMachine::probRunDict(QProg& prog,
510 const std::vector<uint32_t>& qubit_vec, int backendID)

Callers

nothing calls this directly

Calls 8

powFunction · 0.50
sizeMethod · 0.45
initMethod · 0.45
qAllocManyMethod · 0.45
runMethod · 0.45
whatMethod · 0.45

Tested by

no test coverage detected