pyqpanda.utils ============== .. py:module:: pyqpanda.utils .. autoapi-nested-parse:: QPanda Utilities Copyright (C) Origin Quantum 2017-2024 Licensed Under Apache Licence 2.0 Functions --------- .. autoapisummary:: pyqpanda.utils.single_gate_apply_to_all pyqpanda.utils.single_gate pyqpanda.utils.meas_all pyqpanda.utils.get_fidelity Module Contents --------------- .. py:function:: single_gate_apply_to_all(gate, qubit_list) Applies a specified quantum gate to each qubit within the provided list. This function is intended for use within the pyQPanda package, which facilitates quantum computing with quantum circuits and gates. It operates on a quantum circuit simulator or a quantum cloud service. Args: gate (pywrap.QGate): The quantum gate instance to be applied to each qubit. qubit_list (list of pyQPanda.Qubit): A list of qubits to which the gate will be applied. Returns: pywrap.QCircuit: A quantum circuit object with the applied gates. .. py:function:: single_gate(gate, qubit, angle=None) Constructs a quantum gate operation on a specified qubit. This function applies a quantum gate to a qubit, optionally rotating the gate's action around a specified angle for rotation gates. Args: gate (callable): A quantum gate represented as a callable that takes a qubit and an optional angle. qubit (int): The index of the qubit to which the gate will be applied. angle (float, optional): The rotation angle for rotation gates. Defaults to None, which means no rotation is applied. Returns: pyqpanda.QGate: The resulting quantum gate operation after applying to the qubit. Raises: pyqpanda.run_fail: If an error occurs while constructing the single gate node. .. py:function:: meas_all(qubits, cbits) Constructs a quantum program by measuring specified qubits and mapping their outcomes to classical bits. Args: qubits (list): A list of qubits to be measured. cbits (list): A list of classical bits where the measurement outcomes will be stored. Returns: QProg: A quantum program object representing the measurement operation. Raises: run_fail: If an error occurs while constructing the measure all node within the quantum program. .. py:function:: get_fidelity(result, shots, target_result) Calculate the fidelity between a given quantum state and a target state. Args: result (dict): A dictionary representing the current quantum state, with terms as keys and probabilities as values. shots (int): The number of measurement shots taken to observe the current state. target_result (dict): A dictionary representing the target quantum state, with terms as keys and probabilities as values. Returns: float: The fidelity between the current and target states, ranging from 0 to 1. Raises: run_fail: An error is encountered during the computation of fidelity.