pyqpanda.OriginService.QCloudMachine

Origin Quantum Computing Cloud Service ToolKit.

Module Contents

Classes

QCloud

Quantum Computing Cloud Service Utility Class.

class pyqpanda.OriginService.QCloudMachine.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[源代码]
pqc_init()[源代码]
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.

query_task_state_result(task_id: str)[源代码]
query_batch_task_state_result(task_id: str)[源代码]
estimate_price(qubit_num: int, shot: int, qprogCount: int = 1, epoch: int = 1)[源代码]
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.