pyqpanda.OriginService.PilotOSMachine ===================================== .. py:module:: pyqpanda.OriginService.PilotOSMachine Classes ------- .. autoapisummary:: pyqpanda.OriginService.PilotOSMachine.QPilotOSMachine Module Contents --------------- .. py:class:: QPilotOSMachine(name: str) Bases: :py:obj:`QPilotOSService` This class can submit Quantum Program to PilotOS. Args ---------- PilotURL : str Connect to the target PilotOS address. PilotIp : str PilotOS IP address. PilotPort : str PilotOS port. .. py:attribute:: PilotURL :value: '' .. py:attribute:: PilotIp :value: '' .. py:attribute:: PilotPort :value: '' .. py:attribute:: APIKey :value: '' .. py:attribute:: LogCout :value: '' .. py:method:: get_expectation_result(task_id: str) -> list get expectation task result Args ---------- task_id : str expectation task id. Returns ------- list expectation task result. .. py:method:: get_qst_result(task_id: str) -> list get qst task result through task_id Args ---------- task_id : str the task_id you want to query Returns ------- list The list contains the information of qst task. .. py:method:: set_config(max_qubit: int = None, max_cbit: int = None) -> None set Quantum Machine max Qubit and Cbit number function. Args ---------- max_qubit : int The Quantum Machine max available qubits. max_cbit : int The Quantum Machine max available cbits. Returns ------- None Examples -------- >>> qm.set_config(12, 12) .. py:method:: init(url: str = None, log_cout: bool = False, api_key: str = None) -> None Init Quantum Machine and connect to PilotOS. Args ---------- url : str The Quantum Machine address you want to connnect. log_cout : bool Whether record execute log. api_key : str The unique certificate to login PilotOS, which can get from PilotOS WebSite. Returns ------- None Examples -------- >>> qm.init('PilotOS_url', True, 'your_api_key') .. py:method:: qAlloc_many(qubit_num: int = None) -> list Get Qubits to construct Quantum Circuit. Args ---------- qubit_num : int The Qubits number you need to use in circuit. Returns ------- List[Qubit] Examples -------- >>> q = qm.qAlloc_many(6) .. py:method:: cAlloc_many(cbit_num: int = None) -> list Get Cbits to construct Quantum Circuit. Args ---------- cbit_num : int The Cbits number you need to use in circuit. Returns ------- List[ClassicalCondition] Examples -------- >>> c = qm.cAlloc_many(6) .. py:method:: real_chip_measure(prog: Union[List[str], List[QProg], str, QProg], shot=1000, chip_id=None, is_amend=True, is_mapping=True, is_optimization=True, specified_block=[], describe='') -> list Using sync way to compute your Quantum Program . Args ---------- prog : Union[List[str], List[QProg], str, QProg] The quantum program you want to compute. shot : int Repeate run quantum program times. chip_id : int The quantum chip ID . is_amend : bool Whether amend task result. is_mapping : bool Whether mapping logical Qubit to Physical Qubit. is_optimization : bool Whether optimize your quantum program. specified_block : List[int] Your specifed Qubit block . describe : str The detailed infomation to describe your quantum program, such as which kind of algorithm, what can this program compute. Returns ------- list a list of every single quantum program Examples -------- >>> result = qm.real_chip_measure(prog_list, 1000, chip_id=1, is_mapping=True, describe="test1") >>> print(result) [{'00': 0.2456881582421773, '01': 0.2495193504871486, '10': 0.25044435129147546, '11': 0.25434813997919875}, {'00': 0.2456881582421773, '01': 0.2495193504871486, '10': 0.25044435129147546, '11': 0.25434813997919875}] .. py:method:: async_real_chip_measure(prog: Union[List[str], List[QProg], str, QProg], shot=1000, chip_id=None, is_amend=True, is_mapping=True, is_optimization=True, specified_block=[], describe='') -> str Using async way to compute your Quantum Program, then you need to query task result from task_id. Args ---------- prog : Union[List[str], List[QProg], str, QProg] The quantum program you want to compute. shot : int Repeate run quantum program times. chip_id : int The quantum chip ID . is_amend : bool Whether amend task result. is_mapping : bool Whether mapping logical Qubit to Physical Qubit. is_optimization : bool Whether optimize your quantum program. specified_block : List[int] Your specifed Qubit block . describe : str The detailed infomation to describe your quantum program, such as which kind of algorithm, what can this program compute. Returns ------- str your task id which can query task result Examples -------- This interface will return a string that will be used to query the results of the quantum program you just submitted. >>> task_id = qm.async_real_chip_measure(prog_list, 1000, chip_id=1, is_mapping=True, describe="test1") >>> print (task_id) 54C64205E2AF45D393FB5E6279E14984 .. py:method:: real_chip_expectation(prog: Union[QProg, str], hamiltonian: str, qubits: List[int] = None, shot: int = None, chip_id: int = None, is_amend: bool = True, is_mapping: bool = True, is_optimization: bool = True, specified_block: List[int] = [], task_describe: str = '') -> float submit Quantum expectation task, and get the expectation result. Args ---------- prog : Union[QProg, str] The quantum program you want to compute. hamiltonian : str Hamiltonian Args. qubits : List[int] measurement qubit shot : int Repeate run quantum program times. chip_id : int The quantum chip ID . is_amend : bool Whether amend task result. is_mapping : bool Whether mapping logical Qubit to Physical Qubit. is_optimization : bool Whether optimize your quantum program. specified_block : List[int] Your specifed Qubit block . task_describe : str The detailed infomation to describe your quantum program, such as which kind of algorithm, what can this program compute. Returns ------- float if success, return the expectation task result. Otherwise return empty. .. py:method:: async_real_chip_expectation(prog: Union[QProg, str], hamiltonian: str, qubits: List[int] = None, shot: int = None, chip_id: int = None, is_amend: bool = True, is_mapping: bool = True, is_optimization: bool = True, specified_block: List[int] = [], task_describe: str = '') -> str async submit Quantum expectation task, and return the task id. Args ---------- prog : Union[QProg, str] The quantum program you want to compute. hamiltonian : str Hamiltonian Args. qubits : List[int] measurement qubit shot : int Repeate run quantum program times. chip_id : int The quantum chip ID . is_amend : bool Whether amend task result. is_mapping : bool Whether mapping logical Qubit to Physical Qubit. is_optimization : bool Whether optimize your quantum program. specified_block : List[int] Your specifed Qubit block . task_describe : str The detailed infomation to describe your quantum program, such as which kind of algorithm, what can this program compute. Returns ------- str return expectation task id, you need query task result by using task id. .. py:method:: async_real_chip_qst(prog: Union[str, QProg], shot=1000, chip_id=None, is_amend=True, is_mapping=True, is_optimization=True, specified_block=[], describe='') -> list Using async way to compute QST task, then you need to query task result from task_id. Args ---------- prog : Union[str, QProg] The quantum program you want to compute. shot : int Repeate run quantum program times. chip_id : int The quantum chip ID . is_amend : bool Whether amend task result. is_mapping : bool Whether mapping logical Qubit to Physical Qubit. is_optimization : bool Whether optimize your quantum program. specified_block : List[int] Your specifed Qubit block . describe : str The detailed infomation to describe your quantum program, such as which kind of algorithm, what can this program compute. Returns ------- str your task id which can query task result .. py:method:: query_task_state(task_id: str, file_path: str = None) -> list Query task result from task_id. Args ---------- task_id : str The task id you want to query. file_path : str If the parameter is not None, task result will be saved to target path. Returns ------- list Contains task state, task result, task error code, task error info, you can decide what to do with state and error code. Examples -------- This interface will return a result list, contains: task state, probability result, error code, error info(if error code not equal to 0) You can decide whether to save the results of the task to a file by entering the second parameter or not, in particular, if you enter an empty string, the file will be saved in the current path >>> result_list = qm.query_task_state(task_id, 'D:/python_test/result/') >>> for i in result_list: print(i) ... 3 ['{"key":["0","1"],"value":[0.5,0.5]}'] 0 If you enter the second parameter a path to save task result json, the json string in file will be like: { "taskId": "2258D6B6164F4F4FA8F85D1DA2F74370", "endTime": 1700466283544, "errCode": 0, "errInfo": "", "startTime": 1700466281627, "qProg": [ "["QINIT 72\nCREG 72\nX q[0]\nH q[1]\nMEASURE q[0]", "c[0]\nMEASURE q[1]", "c[1]"", " "QINIT 72\nCREG 72\nX q[0]\nH q[1]\nMEASURE q[0]", "c[0]\nMEASURE q[1]", "c[1]"]" ], "qProgLength": 6, "configuration": "{"shot":1000,"amendFlag":false,"mappingFlag":true,"circuitOptimization":true,"IsProbCount":false,"specified_block":[]}", "taskState": "3", "convertQProg": [ "[[{"RPhi":[2,270.0,90.0,0]},{"RPhi":[3,0.0,180.0,0]},{"Measure":[[2,3],30]}],[{"RPhi":[2,270.0,90.0,0]},{"RPhi":[3,0.0,180.0,0]},{"Measure":[[2,3],30]}]]" ], "mappingQProg": [ "QINIT 72 CREG 72 X q[0] H q[1] MEASURE q[0],c[0] MEASURE q[1],c[1]", "QINIT 72 CREG 72 X q[0] H q[1] MEASURE q[0],c[0] MEASURE q[1],c[1]" ], "mappingQubit": [ "{"SrcQubits":[0,1],"TargetCbits":[0,1],"MappingQubits":[3,2]}", "{"SrcQubits":[0,1],"TargetCbits":[0,1],"MappingQubits":[3,2]}" ], "aioExecuteTime": 441, "queueTime": 0, "compileTime": 608, "totalTime": 1229, "aioCompileTime": 0, "aioPendingTime": 0, "aioMeasureTime": 0, "aioPostProcessTime": 0, "requiredCore": "0", "pulseTime": 60.0, "cirExecuteTime": 200000.0, "taskType": "0", "taskResult": [ "{"key":["00","01","10","11"],"value":[0.017,0.5,0.017,0.466]}", "{"key":["00","01","10","11"],"value":[0.018,0.474,0.025,0.483]}" ] } .. py:method:: get_task_list_result(task_id: list, file_path: str = None) -> list Get task result through task id list. Args ---------- task_id : list The list of task id you want to query. file_path : str If the parameter is not None, task result will be saved to target path. Returns ------- list This list contasins several dicts of task id and task result. Examples -------- This interface will return a list, however, this list will not necessarily contain all the tasks queried, but will only return the results of the tasks that were queried to the completion of the calculation, and if the save path is set, these results will also be saved to a file. >>> result_list = qm.get_task_list_result(task_id_list, 'D:/python_test/result/') >>> print(result_list) [{'task_id': '5D102BEED2714755B9B6AA082151F70E', 'task_result': ['{"key":["00","01","10","11"],"value":[0.25,0.25,0.25,0.25]}', '{"key":["00","01","10","11"],"value":[0.25,0.25,0.25,0.25]}']}, {'task_id': '18C163284EE043CAA691B201A9091891', 'task_result': ['{"key":["00","01","10","11"],"value":[0.25,0.25,0.25,0.25]}', '{"key":["00","01","10","11"],"value":[0.25,0.25,0.25,0.25]}']}, {'task_id': 'C929CE6E18374181A2E2297327CE6888', 'task_result': ['{"key":["00","01","10","11"],"value":[0.25,0.25,0.25,0.25]}', '{"key":["00","01","10","11"],"value":[0.25,0.25,0.25,0.25]}']}] .. py:method:: parse_probability_result(result_str: list) -> list Parse async task probability result to a list contains dict. Args ---------- result_str : str The json str contains task result key and value. Returns ------- list Examples -------- >>> result = qm.parse_probability_result(query_str) .. py:method:: quantum_chip_config_query(chip_ids: str) -> str Get quantum chip config Args ---------- chip_ids : str the json str contains chip id, it must be int or array, -1 represents all chips Returns ------- str return quantum chip configuration Examples -------- >>> chipID_1 = {"ChipID":-1} >>> chipID_2 = {"ChipID":[5,6,7]} >>> config_1 = qm.quantum_chip_config_query(chipID_1) >>> config_2 = qm.quantum_chip_config_query(chipID_2) >>> print(config_1) >>> print(config_2)