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

Function test_em_compute_async

test/Core/QPilotOSMachine.test.cpp:479–543  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

477}
478
479static bool test_em_compute_async(QPilotOSMachine& qvm, const CaseConf& conf)
480{
481 size_t bit_num = 6;
482 auto q = qvm.allocateQubits(bit_num);
483 auto c = qvm.allocateCBits(bit_num);
484
485 std::string param_json;
486 size_t loop{ 1 };
487 if (conf.m_default) {
488 param_json = R"({"ir":"QINIT 72\nCREG 72\nCZ q[45],q[46]\nCZ q[52],q[53]\nCZ q[46],q[52]\nCZ q[53],q[54]\nCZ q[54],q[48]",
489"pattern": 0,
490"file": "common_generator.py",
491"samples": 40,
492"nl_shots": 256,
493"depths": [2, 4, 8, 16, 32],
494"expectations": ["IZI", "IIZ"],
495"qem_method": 0,
496"qem_base_method": 0,
497"noise_model_file": "",
498"qem_samples": 300,
499"qem_shots": 256,
500"noise_strength": [0.0, 1.0, 2.0] })";
501 }
502 else {
503 JsonMsg::JsonBuilder json_builder;
504 json_builder.add_member("ir", conf.m_originir.at(0));
505 json_builder.add_member("pattern", conf.m_em_compute_conf.m_pattern);
506 json_builder.add_member("file", conf.m_em_compute_conf.m_file);
507 json_builder.add_member("noise_model_file", conf.m_em_compute_conf.m_noise_model_file);
508 json_builder.add_member("samples", conf.m_em_compute_conf.m_samples);
509 json_builder.add_member("nl_shots", conf.m_em_compute_conf.m_nl_shots);
510 json_builder.add_array("depths", conf.m_em_compute_conf.m_depths);
511 json_builder.add_member("qem_base_method", conf.m_em_compute_conf.m_qem_base_method);
512
513 json_builder.add_array("expectations", conf.m_em_compute_conf.m_expectations);
514 json_builder.add_member("qem_method", conf.m_em_compute_conf.m_qem_method);
515 json_builder.add_member("qem_samples", conf.m_em_compute_conf.m_qem_samples);
516 json_builder.add_member("qem_shots", conf.m_em_compute_conf.m_qem_shots);
517 json_builder.add_array("noise_strength", conf.m_em_compute_conf.m_noise_strength);
518 param_json = json_builder.get_json_str(true);
519 loop = conf.m_loop;
520 }
521
522 for (size_t test_cnt = 0; test_cnt < loop; test_cnt++)
523 {
524 std::string task_id = qvm.async_em_compute(param_json);
525 std::cout << "get task_id for noise em_compute, task_id: " << task_id << endl;
526
527 PilotQVM::PilotTaskQueryResult res;
528 do {
529 qvm.query_task_state(task_id, res);
530 std::this_thread::sleep_for(std::chrono::seconds(2));
531 std::cout << "state:" << res.m_state << std::endl;
532 } while ((res.m_state != SUCCESS_STATE) && (res.m_state != FAILED_STATE) && (res.m_state != CANCELED_STATE));
533 cout << "[";
534 for (auto& ele : res.m_result_vec) {
535 cout << ele << " ";
536 }

Callers

nothing calls this directly

Calls 10

allocateCBitsMethod · 0.80
add_memberMethod · 0.80
add_arrayMethod · 0.80
get_json_strMethod · 0.80
async_em_computeMethod · 0.80
Free_QubitsMethod · 0.80
Free_CBitsMethod · 0.80
allocateQubitsMethod · 0.45
atMethod · 0.45
query_task_stateMethod · 0.45

Tested by

no test coverage detected