pyqpanda.utils

QPanda Utilities

Copyright (C) Origin Quantum 2017-2024

Licensed Under Apache Licence 2.0

Functions

single_gate_apply_to_all(gate, qubit_list)

Applies a specified quantum gate to each qubit within the provided list.

single_gate(gate, qubit[, angle])

Constructs a quantum gate operation on a specified qubit.

meas_all(qubits, cbits)

Constructs a quantum program by measuring specified qubits and mapping their outcomes to classical bits.

get_fidelity(result, shots, target_result)

Calculate the fidelity between a given quantum state and a target state.

Module Contents

pyqpanda.utils.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.

pyqpanda.utils.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.

pyqpanda.utils.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.

pyqpanda.utils.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.