pyqpanda.OriginService.PilotOSMachine

Module Contents

Classes

QPilotOSMachine

This class can submit Quantum Program to PilotOS.

class pyqpanda.OriginService.PilotOSMachine.QPilotOSMachine(name: str)[源代码]

Bases: QPilotOSService

This class can submit Quantum Program to PilotOS.

Attributes

PilotURLstr

Connect to the target PilotOS address.

PilotIpstr

PilotOS IP address.

PilotPortstr

PilotOS port.

get_expectation_result(task_id: str) list[源代码]

get expectation task result

Parameters
task_idstr

expectation task id.

Returns
list

expectation task result.

get_qst_result(task_id: str) list[源代码]

get qst task result through task_id

Parameters
task_idstr

the task_id you want to query

Returns
list

The list contains the information of qst task.

set_config(max_qubit: int = None, max_cbit: int = None) None[源代码]

set Quantum Machine max Qubit and Cbit number function.

Parameters
max_qubitint

The Quantum Machine max available qubits.

max_cbitint

The Quantum Machine max available cbits.

Returns

None

Examples
>>> qm.set_config(12, 12)
init(url: str = None, log_cout: bool = False, api_key: str = None) None[源代码]

Init Quantum Machine and connect to PilotOS.

Parameters
urlstr

The Quantum Machine address you want to connnect.

log_coutbool

Whether record execute log.

api_keystr

The unique certificate to login PilotOS, which can get from PilotOS WebSite.

Returns

None

Examples
>>> qm.init('PilotOS_url', True, 'your_api_key')
qAlloc_many(qubit_num: int = None) list[源代码]

Get Qubits to construct Quantum Circuit.

Parameters
qubit_numint

The Qubits number you need to use in circuit.

Returns

List[Qubit]

Examples
>>> q = qm.qAlloc_many(6)
cAlloc_many(cbit_num: int = None) list[源代码]

Get Cbits to construct Quantum Circuit.

Parameters
cbit_numint

The Cbits number you need to use in circuit.

Returns

List[ClassicalCondition]

Examples
>>> c = qm.cAlloc_many(6)
real_chip_measure(prog: List[str] | List[pyqpanda.QProg] | str | pyqpanda.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 .

Parameters
progUnion[List[str], List[QProg], str, QProg]

The quantum program you want to compute.

shotint

Repeate run quantum program times.

chip_idint

The quantum chip ID .

is_amendbool

Whether amend task result.

is_mappingbool

Whether mapping logical Qubit to Physical Qubit.

is_optimizationbool

Whether optimize your quantum program.

specified_blockList[int]

Your specifed Qubit block .

describestr

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}]
async_real_chip_measure(prog: List[str] | List[pyqpanda.QProg] | str | pyqpanda.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.

Parameters
progUnion[List[str], List[QProg], str, QProg]

The quantum program you want to compute.

shotint

Repeate run quantum program times.

chip_idint

The quantum chip ID .

is_amendbool

Whether amend task result.

is_mappingbool

Whether mapping logical Qubit to Physical Qubit.

is_optimizationbool

Whether optimize your quantum program.

specified_blockList[int]

Your specifed Qubit block .

describestr

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
real_chip_expectation(prog: pyqpanda.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.

Parameters
progUnion[QProg, str]

The quantum program you want to compute.

hamiltonianstr

Hamiltonian parameters.

qubitsList[int]

measurement qubit

shotint

Repeate run quantum program times.

chip_idint

The quantum chip ID .

is_amendbool

Whether amend task result.

is_mappingbool

Whether mapping logical Qubit to Physical Qubit.

is_optimizationbool

Whether optimize your quantum program.

specified_blockList[int]

Your specifed Qubit block .

task_describestr

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.

async_real_chip_expectation(prog: pyqpanda.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.

Parameters
progUnion[QProg, str]

The quantum program you want to compute.

hamiltonianstr

Hamiltonian parameters.

qubitsList[int]

measurement qubit

shotint

Repeate run quantum program times.

chip_idint

The quantum chip ID .

is_amendbool

Whether amend task result.

is_mappingbool

Whether mapping logical Qubit to Physical Qubit.

is_optimizationbool

Whether optimize your quantum program.

specified_blockList[int]

Your specifed Qubit block .

task_describestr

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.

async_real_chip_qst(prog: str | pyqpanda.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.

Parameters
progUnion[str, QProg]

The quantum program you want to compute.

shotint

Repeate run quantum program times.

chip_idint

The quantum chip ID .

is_amendbool

Whether amend task result.

is_mappingbool

Whether mapping logical Qubit to Physical Qubit.

is_optimizationbool

Whether optimize your quantum program.

specified_blockList[int]

Your specifed Qubit block .

describestr

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

query_task_state(task_id: str, file_path: str = None) list[源代码]

Query task result from task_id.

task_idstr

The task id you want to query.

file_pathstr

If the parameter is not None, task result will be saved to target path.

list

Contains task state, task result, task error code, task error info, you can decide what to do with state and error code.

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 72nCREG 72nX q[0]nH q[1]nMEASURE q[0]", "c[0]nMEASURE q[1]", "c[1]"", " "QINIT 72nCREG 72nX 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]}"

]

}

get_task_list_result(task_id: list, file_path: str = None) list[源代码]

Get task result through task id list.

Parameters
task_idlist

The list of task id you want to query.

file_pathstr

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]}']}]
parse_probability_result(result_str: list) list[源代码]

Parse async task probability result to a list contains dict.

Parameters
result_strstr

The json str contains task result key and value.

Returns

list

Examples
>>> result = qm.parse_probability_result(query_str)
quantum_chip_config_query(chip_ids: str) str[源代码]

Get quantum chip config

Parameters
chip_idsstr

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)