![]() |
QPanda3
Supported by OriginQ
|
This class can submit Quantum Program to PilotOS. More...
Public Member Functions | |
None | __init__ (self, str name) |
Create QPilotOSMMachine object. | |
list | get_expectation_result (self, str task_id) |
get expectation task result | |
list | get_qst_result (self, str task_id) |
get qst task result through task_id | |
None | set_config (self, int max_qubit=None, int max_cbit=None) |
set Quantum Machine max Qubit and Cbit number function. | |
None | init (self, str url=None, bool log_cout=False, str api_key=None) |
Init Quantum Machine and connect to PilotOS. | |
list | run (self, Union[List[str], List[QProg], str, QProg] prog, shot=1000, chip_id=None, is_amend=True, is_mapping=True, is_optimization=True, specified_block=[], describe='', point_label=0, priority=0) |
Using sync way to compute your Quantum Program . | |
list | real_chip_measure_proto (self, Union[List[str], List[QProg], str, QProg] prog, shot=1000, chip_id=None, is_amend=True, is_mapping=True, is_optimization=True, specified_block=[], describe='', point_label=0, priority=0) |
Using sync way to compute your Quantum Program. | |
str | async_run (self, Union[List[str], List[QProg], str, QProg] prog, shot=1000, chip_id=None, is_amend=True, is_mapping=True, is_optimization=True, specified_block=[], describe='', point_label=0, priority=0) |
Using async way to compute your Quantum Program, then you need to query task result from task_id. | |
str | async_real_chip_measure_proto (self, Union[List[str], List[QProg], str, QProg] prog, shot=1000, chip_id=None, is_amend=True, is_mapping=True, is_optimization=True, specified_block=[], describe='', point_label=0, priority=0) |
Using async way to compute your Quantum Program, then you need to query task result from task_id. | |
float | real_chip_expectation (self, Union[QProg, str] prog, str hamiltonian, List[int] qubits=None, int shot=None, str chip_id=None, bool is_amend=True, bool is_mapping=True, bool is_optimization=True, List[int] specified_block=[], str task_describe='') |
submit Quantum expectation task, and get the expectation result. | |
str | async_real_chip_expectation (self, Union[QProg, str] prog, str hamiltonian, List[int] qubits=None, int shot=None, int chip_id=None, bool is_amend=True, bool is_mapping=True, bool is_optimization=True, List[int] specified_block=[], str task_describe='') |
async submit Quantum expectation task, and return the task id. | |
list | async_real_chip_qst (self, Union[str, QProg] prog, shot=1000, chip_id=None, is_amend=True, is_mapping=True, is_optimization=True, specified_block=[], describe='') |
Using async way to compute QST task, then you need to query task result from task_id. | |
dict | query_result (self, str task_id, str file_path=None) |
Query task result from task_id. | |
list | get_task_list_result (self, list task_id, str file_path=None) |
Get task result through task id list. | |
list | parse_probability_result (self, list result_str) |
Parse async task probability result to a list contains dict. | |
str | quantum_chip_config_query (self, str chip_ids) |
Get quantum chip config. | |
Public Attributes | |
str | PilotURL = '' |
str | PilotIp = '' |
str | PilotPort = '' |
str | APIKey = '' |
str | LogCout = '' |
Protected Member Functions | |
str | _build_task_msg (self, List[QProg] prog=None, int shot=None, str chip_id=None, bool is_amend=True, bool is_mapping=True, bool is_optimization=True, List[int] specified_block=[], str task_describe='', point_label=0, priority=0) |
Build submit Quantum compute task request json str, however this is a private method. | |
str | _build_task_proto_msg (self, int shot=None, str chip_id=None, bool is_amend=True, bool is_mapping=True, bool is_optimization=True, List[int] specified_block=[], str task_describe='', point_label=0, priority=0) |
Build submit Quantum compute task request json str, however this is a private method. | |
str | _build_expectation_task_msg (self, Union[QProg, str] prog, str hamiltonian, List[int] qubits=None, int shot=None, str chip_id=None, bool is_amend=True, bool is_mapping=True, bool is_optimization=True, List[int] specified_block=[], str task_describe='') |
call C++ function to build expectation task message | |
str | _build_qst_task_msg (self, QProg prog, int shot=None, int chip_id=None, bool is_amend=True, bool is_mapping=True, bool is_optimization=True, List[int] specified_block=[], str task_describe='') |
call C++ function to build qst task message | |
str | _build_query_msg (self, str task_id) |
Build Query Quantum compute task result request json str, however this is a private method. | |
list | _retry_get_measure_result (self, task_id) |
if tcp connection is closed, use query_result to get measure result | |
float | _retry_get_expectation_result (self, task_id) |
if tcp connection is closed, use query_result to get expextion result | |
list | _tcp_recv (self, str ip, int port, str task_id) |
Receive task result message, if success, use tcp protocol, otherwise retry with http protocol. | |
list | _parser_sync_result (self, json_str) |
Parse sync compute task result to list, however this is a private method. | |
float | _parser_expectation_result (self, json_str) |
Parse expectation result, however this is a private method. | |
bool | _send_request (self, str str_url=None, str req=None, list resp=None) |
Send request to PilotOS, however this is a private method. | |
bool | _send_proto_request (self, str str_url=None, str config=None, str proto_data=None, list resp=None) |
Send request to PilotOS, however this is a private method. | |
list | _get_prog (self, Union[List[str], List[QProg], str, QProg] prog) |
Get QProg list from user input, however this is a private method. | |
This class can submit Quantum Program to PilotOS.
Version: 1.0.0
PilotURL : str Connect to the target PilotOS address. PilotIp : str PilotOS IP address. PilotPort : str PilotOS port.
None QPilotService.QPilotService.__init__ | ( | self, | |
str | name ) |
Create QPilotOSMMachine object.
Do not include the self
parameter in the Args
section.
name : str Quantum Machine type name.
QuantumMachine Always return a Quantum Machine.
qm = QPilotService('Pilot')
|
protected |
call C++ function to build expectation task message
prog : QProg The quantum program you want to compute. hamiltonian : Hamiltonian Args. qubits : measurement qubit. shot : int Repeate run quantum program times. chip_id : str 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.
string if success, return expectation task message.
|
protected |
call C++ function to build qst task message
prog : QProg The quantum program you want to compute. shot : int Repeate run quantum program times. chip_id : str 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.
string if success, return qst task message.
|
protected |
|
protected |
Build submit Quantum compute task request json str, however this is a private method.
prog : List[QProg] The quantum program you want to compute. shot : int Repeate run quantum program times. chip_id : str 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. point_label : int Describe the operating point label mode of the chip. priority : int Describe the priority of chip computing tasks, ranging from 0 to 10.
str
|
protected |
Build submit Quantum compute task request json str, however this is a private method.
prog : List[QProg] The quantum program you want to compute. shot : int Repeate run quantum program times. chip_id : str 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. point_label : int Describe the operating point label mode of the chip. priority : int Describe the priority of chip computing tasks, ranging from 0 to 10.
str
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
str QPilotService.QPilotService.async_real_chip_expectation | ( | self, | |
Union[QProg, str] | prog, | ||
str | hamiltonian, | ||
List[int] | qubits = None, | ||
int | shot = None, | ||
int | chip_id = None, | ||
bool | is_amend = True, | ||
bool | is_mapping = True, | ||
bool | is_optimization = True, | ||
List[int] | specified_block = [], | ||
str | task_describe = '' ) |
async submit Quantum expectation task, and return the task id.
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 : str 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.
str return expectation task id, you need query task result by using task id.
str QPilotService.QPilotService.async_real_chip_measure_proto | ( | self, | |
Union[List[str], List[QProg], str, QProg] | prog, | ||
shot = 1000, | |||
chip_id = None, | |||
is_amend = True, | |||
is_mapping = True, | |||
is_optimization = True, | |||
specified_block = [], | |||
describe = '', | |||
point_label = 0, | |||
priority = 0 ) |
Using async way to compute your Quantum Program, then you need to query task result from task_id.
prog : Union[List[str], List[QProg], str, QProg] The quantum program you want to compute. shot : int Repeate run quantum program times. chip_id : str 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. point_label : int Describe the operating point label mode of the chip. priority : int Describe the priority of chip computing tasks, ranging from 0 to 10, the default is 0
str your task id which can query task result
This interface will return a string that will be used to query the results of the quantum program you just submitted.
task_id = self.async_run(prog_list, 1000, chip_id=1, is_mapping=True, describe="test1") print (task_id) 54C64205E2AF45D393FB5E6279E14984
list QPilotService.QPilotService.async_real_chip_qst | ( | self, | |
Union[str, QProg] | prog, | ||
shot = 1000, | |||
chip_id = None, | |||
is_amend = True, | |||
is_mapping = True, | |||
is_optimization = True, | |||
specified_block = [], | |||
describe = '' ) |
Using async way to compute QST task, then you need to query task result from task_id.
prog : Union[str, QProg] The quantum program you want to compute. shot : int Repeate run quantum program times. chip_id : str 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.
str your task id which can query task result
str QPilotService.QPilotService.async_run | ( | self, | |
Union[List[str], List[QProg], str, QProg] | prog, | ||
shot = 1000, | |||
chip_id = None, | |||
is_amend = True, | |||
is_mapping = True, | |||
is_optimization = True, | |||
specified_block = [], | |||
describe = '', | |||
point_label = 0, | |||
priority = 0 ) |
Using async way to compute your Quantum Program, then you need to query task result from task_id.
prog : Union[List[str], List[QProg], str, QProg] The quantum program you want to compute. shot : int Repeate run quantum program times. chip_id : str 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. point_label : int Describe the operating point label mode of the chip. priority : int Describe the priority of chip computing tasks, ranging from 0 to 10, the default is 0
str your task id which can query task result
This interface will return a string that will be used to query the results of the quantum program you just submitted.
task_id = self.async_run(prog_list, 1000, chip_id=1, is_mapping=True, describe="test1") print (task_id) 54C64205E2AF45D393FB5E6279E14984
list QPilotService.QPilotService.get_expectation_result | ( | self, | |
str | task_id ) |
list QPilotService.QPilotService.get_qst_result | ( | self, | |
str | task_id ) |
list QPilotService.QPilotService.get_task_list_result | ( | self, | |
list | task_id, | ||
str | file_path = None ) |
Get task result through task id list.
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.
list This list contasins several dicts of task id and task result.
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 = self.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]}']}]
None QPilotService.QPilotService.init | ( | self, | |
str | url = None, | ||
bool | log_cout = False, | ||
str | api_key = None ) |
Init Quantum Machine and connect to PilotOS.
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.
None
self.init('PilotOS_url', True, 'your_api_key')
list QPilotService.QPilotService.parse_probability_result | ( | self, | |
list | result_str ) |
str QPilotService.QPilotService.quantum_chip_config_query | ( | self, | |
str | chip_ids ) |
Get quantum chip config.
chip_ids : str the json str contains chip id, it must be int or array, -1 represents all chips
str return quantum chip configuration
chipID_1 = {"ChipID":-1} chipID_2 = {"ChipID":[5,6,7]} config_1 = self.quantum_chip_config_query(chipID_1) config_2 = self.quantum_chip_config_query(chipID_2) print(config_1) print(config_2)
dict QPilotService.QPilotService.query_result | ( | self, | |
str | task_id, | ||
str | file_path = None ) |
Query task result from task_id.
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.
dict Contains task state, task error code, task error info, task result, prob count you can decide what to do with state and error code.
This interface will return a task info dict, contains: task state, error code, error info(if error code not equal to 0), probability result, collapses counts 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_dict = self.query_result(task_id, 'D:/Tong/python_test/result') print(result_dict['taskState']) print(result_dict['errCode']) print(result_dict['errInfo']) print(result_dict['taskResult']) print(result_dict['probCount']) ... 3 0 '' ['{"key":["0", "1"], "value":[0.5, 0.5]}'] ['{"key":["0", "1"], "value":[500, 500]}']
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\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]" ], "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]}" ] }
float QPilotService.QPilotService.real_chip_expectation | ( | self, | |
Union[QProg, str] | prog, | ||
str | hamiltonian, | ||
List[int] | qubits = None, | ||
int | shot = None, | ||
str | chip_id = None, | ||
bool | is_amend = True, | ||
bool | is_mapping = True, | ||
bool | is_optimization = True, | ||
List[int] | specified_block = [], | ||
str | task_describe = '' ) |
submit Quantum expectation task, and get the expectation result.
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 : str 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 specified Qubit block . task_describe : str The detailed information to describe your quantum program, such as which kind of algorithm, what can this program compute.
float if success, return the expectation task result. Otherwise return empty.
list QPilotService.QPilotService.real_chip_measure_proto | ( | self, | |
Union[List[str], List[QProg], str, QProg] | prog, | ||
shot = 1000, | |||
chip_id = None, | |||
is_amend = True, | |||
is_mapping = True, | |||
is_optimization = True, | |||
specified_block = [], | |||
describe = '', | |||
point_label = 0, | |||
priority = 0 ) |
Using sync way to compute your Quantum Program.
prog : Union[List[str], List[QProg], str, QProg] The quantum program you want to compute. shot : int Repeate run quantum program times. chip_id : str 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. point_label : int Describe the operating point label mode of the chip. priority : int Describe the priority of chip computing tasks, ranging from 0 to 10, the default is 0
list a list of every single quantum program
result = self.run(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}]
list QPilotService.QPilotService.run | ( | self, | |
Union[List[str], List[QProg], str, QProg] | prog, | ||
shot = 1000, | |||
chip_id = None, | |||
is_amend = True, | |||
is_mapping = True, | |||
is_optimization = True, | |||
specified_block = [], | |||
describe = '', | |||
point_label = 0, | |||
priority = 0 ) |
Using sync way to compute your Quantum Program .
prog : Union[List[str], List[QProg], str, QProg] The quantum program you want to compute. shot : int Repeate run quantum program times. chip_id : str 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. point_label : int Describe the operating point label mode of the chip. priority : int Describe the priority of chip computing tasks, ranging from 0 to 10, the default is 0
list a list of every single quantum program
result = self.run(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}]
None QPilotService.QPilotService.set_config | ( | self, | |
int | max_qubit = None, | ||
int | max_cbit = None ) |
str QPilotService.QPilotService.APIKey = '' |
str QPilotService.QPilotService.LogCout = '' |
str QPilotService.QPilotService.PilotIp = '' |
str QPilotService.QPilotService.PilotPort = '' |
str QPilotService.QPilotService.PilotURL = '' |