| 484 | } |
| 485 | |
| 486 | void QVM::run(QProg& qprog, const NoiseModel& noise_model) |
| 487 | { |
| 488 | try |
| 489 | { |
| 490 | TraversalConfig config(noise_model.rotation_error()); |
| 491 | config.m_can_optimize_measure = false; |
| 492 | |
| 493 | std::shared_ptr<AbstractQuantumProgram> qp = nullptr; |
| 494 | if (noise_model.enabled()) |
| 495 | { |
| 496 | /* generate simulate prog contains virtual noise gate */ |
| 497 | auto noise_qprog = NoiseProgGenerator().generate_noise_prog(noise_model, qprog.getImplementationPtr()); |
| 498 | qp = noise_qprog.getImplementationPtr(); |
| 499 | } |
| 500 | else { |
| 501 | QVec used_qv; |
| 502 | this->get_allocate_qubits(used_qv); |
| 503 | if (used_qv.size() > 18) |
| 504 | { |
| 505 | QProg prog = deepCopy(qprog); |
| 506 | merge_QGate(prog); |
| 507 | qp = prog.getImplementationPtr(); |
| 508 | } |
| 509 | else |
| 510 | { |
| 511 | qp = qprog.getImplementationPtr(); |
| 512 | } |
| 513 | } |
| 514 | QPANDA_ASSERT(qp == nullptr, "Error: not valid quantum program"); |
| 515 | |
| 516 | //_pGates->initState(0, 1, _Qubit_Pool->get_max_usedqubit_addr() + 1); |
| 517 | _pGates->initState(0, 1, qp->get_max_qubit_addr() + 1); |
| 518 | |
| 519 | QProgExecution prog_exec; |
| 520 | /* use QProgExecution object address(uniqe in process) as qprog process id _ExecId for recording execute progress */ |
| 521 | _ExecId = uint64_t(&prog_exec); |
| 522 | QProgProgress::getInstance().prog_start(_ExecId); |
| 523 | prog_exec.execute(qp, nullptr, config, _pGates); |
| 524 | QProgProgress::getInstance().prog_end(_ExecId); |
| 525 | std::map<string, bool>result; |
| 526 | prog_exec.get_return_value(result); |
| 527 | |
| 528 | /* add readout error */ |
| 529 | if (noise_model.readout_error_enabled()) |
| 530 | { |
| 531 | NoiseReadOutGenerator::append_noise_readout(noise_model, result); |
| 532 | } |
| 533 | |
| 534 | /* aiter has been used in line 120 */ |
| 535 | for (auto aiter : result) |
| 536 | { |
| 537 | _QResult->append(aiter); |
| 538 | } |
| 539 | } |
| 540 | catch (const std::exception& e) |
| 541 | { |
| 542 | QCERR(e.what()); |
| 543 | throw run_fail(e.what()); |
no test coverage detected