pyqpanda.OriginService.QCloudMachine ==================================== .. py:module:: pyqpanda.OriginService.QCloudMachine .. autoapi-nested-parse:: Origin Quantum Computing Cloud Service ToolKit. Classes ------- .. autoapisummary:: pyqpanda.OriginService.QCloudMachine.QCloud Module Contents --------------- .. py:class:: QCloud Bases: :py:obj:`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/ .. py:class:: CloudQMchineType Bases: :py:obj:`Enum` Generic enumeration. Derive from this class to define new enumerations. .. py:attribute:: Full_AMPLITUDE :value: 0 .. py:attribute:: NOISE_QMACHINE :value: 1 .. py:attribute:: PARTIAL_AMPLITUDE :value: 2 .. py:attribute:: SINGLE_AMPLITUDE :value: 3 .. py:attribute:: CHEMISTRY :value: 4 .. py:attribute:: REAL_CHIP :value: 5 .. py:attribute:: QST :value: 6 .. py:attribute:: FIDELITY :value: 7 .. py:class:: TaskStatus Bases: :py:obj:`Enum` Generic enumeration. Derive from this class to define new enumerations. .. py:attribute:: WAITING :value: 1 .. py:attribute:: COMPUTING :value: 2 .. py:attribute:: FINISHED :value: 3 .. py:attribute:: FAILED :value: 4 .. py:attribute:: QUEUING :value: 5 .. py:attribute:: SENT_TO_BUILD_SYSTEM :value: 6 .. py:attribute:: BUILD_SYSTEM_ERROR :value: 7 .. py:attribute:: SEQUENCE_TOO_LONG :value: 8 .. py:attribute:: BUILD_SYSTEM_RUN :value: 9.0 .. py:method:: pqc_init() .. py:method:: init_qvm(token: str, is_logged: bool = False, use_bin_or_hex=True, enable_pqc_encryption=False, random_num: Union[bytes, str] = os.urandom(96), request_time_out=100) init quantum virtual machine .. py:method:: 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. .. py:method:: query_task_state_result(task_id: str, is_real_chip_task: bool = True) .. py:method:: query_batch_task_state_result(task_id: str) .. py:method:: estimate_price(qubit_num: int, shot: int, qprogCount: int = 1, epoch: int = 1) .. py:method:: 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 .. py:method:: 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. .. py:method:: 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 .. py:method:: 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. .. py:method:: 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. .. py:method:: 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. .. py:method:: 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. .. py:method:: 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 .. py:method:: 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. .. py:method:: 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 .. py:method:: 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. .. py:method:: async_real_chip_measure(prog: Union[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 .. py:method:: 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. .. py:method:: 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. .. py:method:: 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. .. py:method:: real_chip_measure(prog: Union[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. .. py:method:: async_batch_real_chip_measure(prog_array: Union[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. Args: 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. .. py:method:: batch_real_chip_measure(prog_array: Union[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. Args: 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. .. py:method:: set_noise_model(model: pyqpanda.NoiseModel, single_gate_params: List[float], single_param_list: List[float]) Set the noise model for quantum computation. Args: 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 .. py:method:: set_qcloud_url(prefix_url: str) Set the QCloud API endpoint. Args: prefix_url (str): The prefix URL of the QCloud API. Returns: None .. py:method:: async_single_amplitude_pmeasure(prog: pyqpanda.QProg, amplitude: str, task_name: str = 'QPanda Experiment') Measure the single amplitude of a quantum state. Args: 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 .. py:method:: single_amplitude_pmeasure(prog: pyqpanda.QProg, amplitude: str, task_name: str = 'QPanda Experiment') Measure the single amplitude of a quantum state. Args: 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. .. py:method:: 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. Args: 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. .. py:method:: 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. Args: 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. .. py:method:: 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. Args: 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.