pyqpanda.OriginService
QPanda Python
Copyright (C) Origin Quantum 2017-2020
Licensed Under Apache Licence 2.0
Submodules
Package Contents
Classes
Quantum Computing Cloud Service Utility Class. |
|
This class can submit Quantum Program to PilotOS. |
- class pyqpanda.OriginService.QCloud[源代码]
Bases:
pyqpanda.QCloudService
Quantum Computing Cloud Service Utility Class.
The primary function of this utility class for the Origin Quantum Computing Cloud Service is to package and send quantum circuits to the remote computing service (Quantum Cloud). It then queries the computation results through polling, supporting various simulators and real hardware.
User API key authentication is required for computations. Please obtain it here : http://qcloud.originqc.com.cn/
- class CloudQMchineType
Bases:
Enum
Generic enumeration.
Derive from this class to define new enumerations.
- Full_AMPLITUDE = 0
- NOISE_QMACHINE = 1
- PARTIAL_AMPLITUDE = 2
- SINGLE_AMPLITUDE = 3
- CHEMISTRY = 4
- REAL_CHIP = 5
- QST = 6
- FIDELITY = 7
- class TaskStatus
Bases:
Enum
Generic enumeration.
Derive from this class to define new enumerations.
- WAITING = 1
- COMPUTING = 2
- FINISHED = 3
- FAILED = 4
- QUEUING = 5
- SENT_TO_BUILD_SYSTEM = 6
- BUILD_SYSTEM_ERROR = 7
- SEQUENCE_TOO_LONG = 8
- BUILD_SYSTEM_RUN = 9.0
- init_qvm(token: str, is_logged: bool = False, use_bin_or_hex=True, enable_pqc_encryption=False, random_num: bytes | str = os.urandom(96), request_time_out=100)[源代码]
init quantum virtual machine
- convert_result_format(input_dict: dict, binary_size: int)[源代码]
convert result format from binary to hex
- Args:
input_dict (dict): origin result dict use_bin_or_hex (bool): True -> use binary result format, False -> Hex
- Returns:
result: dict.
- async_full_amplitude_measure(prog: pyqpanda.QProg, shot: int, task_name: str = 'QPanda Experiment')[源代码]
Execute a full amplitude measurement on the Quantum Cloud Service.
- Args:
prog (QProg): Quantum program containing the circuit to be measured. shot (int): Number of measurements to perform. task_name (str, optional): Task name for identification. Defaults to 'QPanda Experiment'.
- Returns:
Task_id[str]: A task id for current task
- full_amplitude_measure(prog: pyqpanda.QProg, shot: int, task_name: str = 'QPanda Experiment')[源代码]
Execute a full amplitude measurement on the Quantum Cloud Service.
- Args:
prog (QProg): Quantum program containing the circuit to be measured. shot (int): Number of measurements to perform. task_name (str, optional): Task name for identification. Defaults to 'QPanda Experiment'.
- Returns:
Dict[str, float]: Dictionary containing probabilities of measurement outcomes.
- async_full_amplitude_pmeasure(prog: pyqpanda.QProg, qvec: List[int], task_name: str = 'QPanda Experiment')[源代码]
Execute a full amplitude probability measurement on the Quantum Cloud Service.
- Args:
prog (QProg): Quantum program containing the circuit to be measured. shot (int): Number of measurements to perform. task_name (str, optional): Task name for identification. Defaults to 'QPanda Experiment'.
- Returns:
Task_id[str]: A task id for current task
- full_amplitude_pmeasure(prog: pyqpanda.QProg, qvec: List[int], task_name: str = 'QPanda Experiment')[源代码]
Execute a full amplitude probability measurement on the Quantum Cloud Service.
- Args:
prog (QProg): Quantum program containing the circuit to be measured. qvec (List[int]): List of qubits to be measured. task_name (str, optional): Task name for identification. Defaults to 'QPanda Experiment'.
- Returns:
Dict[str, float]: Dictionary containing probabilities of measurement outcomes.
- get_expectation(prog: pyqpanda.QProg, hamiltonian: List[Tuple[Dict[int, str], float]], qvec: pyqpanda.QVec, task_name: str = 'QPanda Experiment')[源代码]
Calculate the expectation value of a Hamiltonian on the Quantum Cloud Service.
- Args:
prog (QProg): Quantum program containing the circuit for state preparation. hamiltonian (List[Tuple[Dict[int, str], float]]): List of terms in the Hamiltonian along with their coefficients. qvec (QVec): List of qubits representing the quantum state. task_name (str, optional): Task name for identification. Defaults to 'QPanda Experiment'.
- Returns:
float: Expectation value of the Hamiltonian.
- get_state_fidelity(prog: pyqpanda.QProg, shot: int, chip_id: int = 2, is_amend: bool = True, is_mapping: bool = True, is_optimization: bool = True, task_name: str = 'QPanda Experiment')[源代码]
Get the state fidelity of the Quantum Real Chip.
- Args:
prog (QProg): Quantum program containing the circuit for state preparation. shot (int): Number of measurements to perform. chip_id (int, optional): ID of the quantum chip. Defaults to 2. is_amend (bool, optional): Flag for amplitude amplification. Defaults to True. is_mapping (bool, optional): Flag for qubit mapping. Defaults to True. is_optimization (bool, optional): Flag for gate optimization. Defaults to True. task_name (str, optional): Task name for identification. Defaults to 'QPanda Experiment'.
- Returns:
float: State fidelity value.
- get_state_tomography_density(prog: pyqpanda.QProg, shot: int, chip_id: int = 2, is_amend: bool = True, is_mapping: bool = True, is_optimization: bool = True, task_name: str = 'QPanda Experiment')[源代码]
Get the density matrix for state tomography on the Quantum Cloud Service.
- Args:
prog (QProg): Quantum program containing the circuit for state preparation. shot (int): Number of measurements to perform. chip_id (int, optional): ID of the quantum chip. Defaults to 2. is_amend (bool, optional): Flag for amplitude amplification. Defaults to True. is_mapping (bool, optional): Flag for qubit mapping. Defaults to True. is_optimization (bool, optional): Flag for gate optimization. Defaults to True. task_name (str, optional): Task name for identification. Defaults to 'QPanda Experiment'.
- Returns:
List[List[complex]]: Density matrix representing the quantum state.
- async_noise_measure(prog: pyqpanda.QProg, shot: int, task_name: str = 'QPanda Experiment')[源代码]
Measure noise in the quantum computation.
- Args:
prog (QProg): The quantum circuit to be executed. shot (int): The number of shots (measurement repetitions). task_name (str, optional): The name of the QPanda Experiment task. Defaults to 'QPanda Experiment'.
- Returns:
Task_id[str]: A task id for current task
- noise_measure(prog: pyqpanda.QProg, shot: int, task_name: str = 'QPanda Experiment')[源代码]
Measure noise in the quantum computation.
- Args:
prog (QProg): The quantum circuit to be executed. shot (int): The number of shots (measurement repetitions). task_name (str, optional): The name of the QPanda Experiment task. Defaults to 'QPanda Experiment'.
- Returns:
Dict[str, float]: A dictionary containing measurement results.
- async_partial_amplitude_pmeasure(prog: pyqpanda.QProg, amp_vec: List[str], task_name: str = 'QPanda Experiment')[源代码]
Perform partial amplitude measurement in the quantum computation.
- Args:
prog (QProg): The quantum circuit to be executed. amp_vec (List[str]): List of amplitude vectors to be measured. task_name (str, optional): The name of the QPanda Experiment task. Defaults to 'QPanda Experiment'.
- Returns:
Task_id[str]: A task id for current task
- partial_amplitude_pmeasure(prog: pyqpanda.QProg, amp_vec: List[str], task_name: str = 'QPanda Experiment')[源代码]
Perform partial amplitude measurement in the quantum computation.
- Args:
prog (QProg): The quantum circuit to be executed. amp_vec (List[str]): List of amplitude vectors to be measured. task_name (str, optional): The name of the QPanda Experiment task. Defaults to 'QPanda Experiment'.
- Returns:
Dict[str, complex]: A dictionary containing complex-valued measurement results.
- async_real_chip_measure(prog: pyqpanda.QProg | str, shot: int, chip_id: int = 2, is_amend: bool = True, is_mapping: bool = True, is_optimization: bool = True, task_name: str = 'QPanda Experiment', task_from=4)[源代码]
Perform measurements on a real quantum chip.
- Args:
prog (QProg): The quantum circuit to be executed. shot (int): The number of shots (measurement repetitions). chip_id (int, optional): Identifier for the specific quantum chip. Defaults to 2. is_amend (bool, optional): Flag indicating whether to perform amendments. Defaults to True. is_mapping (bool, optional): Flag indicating whether to perform qubit mapping. Defaults to True. is_optimization (bool, optional): Flag indicating whether to perform optimization. Defaults to True. task_name (str, optional): The name of the QPanda Experiment task. Defaults to 'QPanda Experiment'. task_from (int): Task source identifier (default is 4, represented by QPanda/pyqpanda).
- Returns:
taskid[str]: real chip task id
- pqc_encrypt(data: str)[源代码]
Encrypts the given data using the pqc encryption algorithm.
- Args:
data (str): The data to be encrypted.
- Returns:
str: The encrypted data.
- pqc_encrypt_and_combine_json(json_str: str)[源代码]
Encrypts the 'code' field and the remaining JSON data, and combines them into a new JSON string.
- Args:
json_str (str): The original JSON string.
- Returns:
str: The new JSON string with encrypted 'code' field and remaining JSON data.
- pqc_encrypt_and_combine_batch_json(json_str: str)[源代码]
Encrypts the 'code' field and the remaining JSON data, and combines them into a new JSON string.
- Args:
json_str (str): The original JSON string.
- Returns:
str: The new JSON string with encrypted 'code' field and remaining JSON data.
- real_chip_measure(prog: pyqpanda.QProg | str, shot: int, chip_id: int = 2, is_amend: bool = True, is_mapping: bool = True, is_optimization: bool = True, task_name: str = 'QPanda Experiment', task_from=4)[源代码]
Perform measurements on a real quantum chip.
- Args:
prog (QProg): The quantum circuit to be executed. shot (int): The number of shots (measurement repetitions). chip_id (int, optional): Identifier for the specific quantum chip. Defaults to 2. is_amend (bool, optional): Flag indicating whether to perform amendments. Defaults to True. is_mapping (bool, optional): Flag indicating whether to perform qubit mapping. Defaults to True. is_optimization (bool, optional): Flag indicating whether to perform optimization. Defaults to True. task_name (str, optional): The name of the QPanda Experiment task. Defaults to 'QPanda Experiment'. task_from (int): Task source identifier (default is 4, represented by QPanda/pyqpanda).
- Returns:
Dict[str, float]: A dictionary containing measurement results.
- async_batch_real_chip_measure(prog_array: List[pyqpanda.QProg] | List[str], shot: int, chip_id: pyqpanda.real_chip_type = real_chip_type.origin_72, is_amend: bool = True, is_mapping: bool = True, is_optimization: bool = True, batch_id: str = '', task_from=4)[源代码]
Measure a batch of quantum programs on a real quantum chip.
Parameters: - prog_array (List[QProg]): List of quantum programs to be executed. - shot (int): Number of shots (measurements) to perform for each program. - chip_id (real_chip_type, optional): ID of the real quantum chip to use (default is real_chip_type.origin_72). - is_amend (bool, optional): Whether to perform amendment on the programs (default is True). - is_mapping (bool, optional): Whether to perform qubit mapping (default is True). - is_optimization (bool, optional): Whether to perform gate fusion optimization (default is True). - task_from (int): Task source identifier (default is 4, represented by QPanda/pyqpanda). - batch_id (str): The current batch number information for batch tasks, default to empty
Returns: batch_task_id[str]: batch task id
Note: The function submits a batch of quantum programs for execution on a real quantum chip, retrieves the results, and returns the probabilities of measurement outcomes for each program.
- batch_real_chip_measure(prog_array: List[pyqpanda.QProg] | List[str], shot: int, chip_id: pyqpanda.real_chip_type = real_chip_type.origin_72, is_amend: bool = True, is_mapping: bool = True, is_optimization: bool = True, batch_id: str = '', task_from=4)[源代码]
Measure a batch of quantum programs on a real quantum chip.
Parameters: - prog_array (List[QProg]): List of quantum programs to be executed. - shot (int): Number of shots (measurements) to perform for each program. - chip_id (real_chip_type, optional): ID of the real quantum chip to use (default is real_chip_type.origin_72). - is_amend (bool, optional): Whether to perform amendment on the programs (default is True). - is_mapping (bool, optional): Whether to perform qubit mapping (default is True). - is_optimization (bool, optional): Whether to perform gate fusion optimization (default is True). - task_from (int): Task source identifier (default is 4, represented by QPanda/pyqpanda). - batch_id (str): The current batch number information for batch tasks, default to empty
Returns: List[Dict[str, float]]: A list of dictionaries containing the probabilities of measurement outcomes for each program.
Note: The function submits a batch of quantum programs for execution on a real quantum chip, retrieves the results, and returns the probabilities of measurement outcomes for each program.
- set_noise_model(model: pyqpanda.NoiseModel, single_gate_params: List[float], single_param_list: List[float])[源代码]
Set the noise model for quantum computation.
Parameters: - model (NoiseModel): The noise model to be set. - single_gate_params (List[float]): List of parameters for single-qubit gates. - single_param_list (List[float]): List of parameters for single-qubit gates.
Returns: None
- set_qcloud_url(prefix_url: str)[源代码]
Set the QCloud API endpoint.
Parameters: - prefix_url (str): The prefix URL of the QCloud API.
Returns: None
- async_single_amplitude_pmeasure(prog: pyqpanda.QProg, amplitude: str, task_name: str = 'QPanda Experiment')[源代码]
Measure the single amplitude of a quantum state.
Parameters: - prog (QProg): The quantum program containing the state. - amplitude (str): The amplitude to measure. - task_name (str): Name of the QPanda Experiment task.
- Returns:
Task_id[str]: A task id for current task
- single_amplitude_pmeasure(prog: pyqpanda.QProg, amplitude: str, task_name: str = 'QPanda Experiment')[源代码]
Measure the single amplitude of a quantum state.
Parameters: - prog (QProg): The quantum program containing the state. - amplitude (str): The amplitude to measure. - task_name (str): Name of the QPanda Experiment task.
Returns: complex: The measured amplitude.
- pec_error_mitigation(prog: pyqpanda.QProg, shot: int, expectations: List[str], chip_id: int = 72, task_name: str = 'QPanda Experiment')[源代码]
Apply PEC error mitigation to correct measurement errors.
Parameters: - prog (QProg): The quantum program to apply error mitigation. - shot (int): Number of shots for measurements. - expectations (List[str]): List of measurement expectations. - chip_id (int): Chip identifier. - task_name (str): Name of the QPanda Experiment task.
Returns: List[float]: List of corrected expectation values.
- read_out_error_mitigation(prog: pyqpanda.QProg, shot: int, expectations: List[str], chip_id: int = 72, task_name: str = 'QPanda Experiment')[源代码]
Apply readout error mitigation to correct measurement errors.
Parameters: - prog (QProg): The quantum program to apply error mitigation. - shot (int): Number of shots for measurements. - expectations (List[str]): List of measurement expectations. - chip_id (int): Chip identifier. - task_name (str): Name of the QPanda Experiment task.
- Returns:
Dict[str, float]: Dictionary of corrected expectation values.
- zne_error_mitigation(prog: pyqpanda.QProg, shot: int, expectations: List[str], noise_strength: List[float], chip_id: int = 72, task_name: str = 'QPanda Experiment')[源代码]
Apply zero-noise extrapolation (ZNE) error mitigation to correct measurement errors.
Parameters: - prog (QProg): The quantum program to apply error mitigation. - shot (int): Number of shots for measurements. - expectations (List[str]): List of measurement expectations. - noise_strength (List[float]): List of noise strengths. - chip_id (int): Chip identifier. - task_name (str): Name of the QPanda Experiment task.
Returns: List[float]: List of corrected expectation values.
- class pyqpanda.OriginService.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)