Noise — NoiseModel, QuantumError, NoiseOpType
API reference for noise modeling in pyqpanda3. The noise framework allows simulation of realistic quantum hardware by applying error channels to quantum operations.
NoiseModel
Manages a collection of quantum errors and readout errors applied during simulation.
Signature
class NoiseModel:
def __init__() -> NoneMethods
NoiseModel.is_enabled
is_enabled() -> boolCheck if the noise model contains any errors.
NoiseModel.add_read_out_error
add_read_out_error(probs: list[list[float]], qubit: int) -> None| Parameter | Type | Description |
|---|---|---|
| probs | list[list[float]] | Probabilities of readout error outcomes |
| qubit | int | Qubit index to apply readout error |
NoiseModel.add_all_qubit_read_out_error
add_all_qubit_read_out_error(probs: list[list[float]]) -> None| Parameter | Type | Description |
|---|---|---|
| probs | list[list[float]] | Probabilities of readout error outcomes |
NoiseModel.add_quantum_error (specific qubits)
add_quantum_error(error: QuantumError, gate_type: GateType, qubits: list[list[int]]) -> None
add_quantum_error(error: QuantumError, gate_types: list[GateType], qubits: list[list[int]]) -> None| Parameter | Type | Description |
|---|---|---|
| error | QuantumError | The quantum error to add |
| gate_type(s) | GateType or list[GateType] | Gate type(s) where error applies |
| qubits | list[list[int]] | Qubit index sets where error applies |
NoiseModel.add_all_qubit_quantum_error
add_all_qubit_quantum_error(error: QuantumError, gate_type: GateType) -> None
add_all_qubit_quantum_error(error: QuantumError, gate_types: list[GateType]) -> None| Parameter | Type | Description |
|---|---|---|
| error | QuantumError | The quantum error to add |
| gate_type(s) | GateType or list[GateType] | Gate type(s) where error applies |
Examples
from pyqpanda3.core import (
NoiseModel, QuantumError, GateType,
pauli_x_error, depolarizing_error,
CPUQVM, QProg, H, CNOT, measure
)
# Create a noise model
model = NoiseModel()
# Add single-qubit depolarizing noise to all H gates
model.add_all_qubit_quantum_error(depolarizing_error(0.01), GateType.H)
# Add two-qubit Pauli-X noise to all CNOT gates
model.add_all_qubit_quantum_error(pauli_x_error(0.02), GateType.CNOT)
# Run with noise
qvm = CPUQVM()
prog = QProg()
prog << H(0) << CNOT(0, 1) << measure(0, 0) << measure(1, 1)
qvm.run(prog, 1000, model)
print(qvm.result().get_counts())QuantumError
Represents a quantum error channel, specified either by Kraus matrices or Pauli error probabilities.
Signature
class QuantumError:
def __init__() -> None
def __init__(kraus_matrices: list[numpy.ndarray]) -> None
def __init__(pauli_probs: dict[str, float]) -> None| Parameter | Type | Description |
|---|---|---|
| kraus_matrices | list[numpy.ndarray] | List of Kraus matrices |
| pauli_probs | dict[str, float] | Pauli error labels and probabilities (e.g., {"X": 0.01}) |
Methods
QuantumError.tensor
tensor(quantum_error: QuantumError) -> QuantumError| Parameter | Type | Description |
|---|---|---|
| quantum_error | QuantumError | The quantum error to tensor with |
Apply tensor product operation with another quantum error.
QuantumError.expand
expand(quantum_error: QuantumError) -> QuantumError| Parameter | Type | Description |
|---|---|---|
| quantum_error | QuantumError | The quantum error to expand with |
Expand the error to a larger qubit system.
QuantumError.compose
compose(quantum_error: QuantumError) -> QuantumError| Parameter | Type | Description |
|---|---|---|
| quantum_error | QuantumError | The quantum error to compose with |
Compose the error with another quantum error.
QuantumError.qubit_num
qubit_num() -> intNumber of qubits affected by the error.
QuantumError.error_type
error_type() -> NoiseOpTypeThe type of error representation (Kraus matrices or noise circuit).
QuantumError.error_circuit
error_circuit(qubits: list[int]) -> QCircuit| Parameter | Type | Description |
|---|---|---|
| qubits | list[int] | Qubit indices to apply the error circuit on |
Circuit representation of the error.
QuantumError.error_karus
error_karus(qubits: list[int]) -> Karus| Parameter | Type | Description |
|---|---|---|
| qubits | list[int] | Qubit indices to get the Kraus matrices for |
Kraus matrix representation of the error.
NoiseOpType
Enum for noise operation representation types.
| Value | Description |
|---|---|
KARUS_MATRIICES | Error represented by Kraus matrices |
NOISE | Error represented by a noise circuit |
Error Factory Functions
pauli_x_error
pauli_x_error(prob: float) -> QuantumError| Parameter | Type | Description |
|---|---|---|
| prob | float | Probability of Pauli-X error |
Creates a single-qubit Pauli-X (bit-flip) error channel. With probability
pauli_y_error
pauli_y_error(prob: float) -> QuantumErrorCreates a Pauli-Y (bit-phase-flip) error channel.
pauli_z_error
pauli_z_error(prob: float) -> QuantumErrorCreates a Pauli-Z (phase-flip) error channel.
depolarizing_error
depolarizing_error(prob: float) -> QuantumErrorCreates a depolarizing error channel. With probability
amplitude_damping_error
amplitude_damping_error(prob: float) -> QuantumErrorCreates an amplitude damping (T1 relaxation) error channel modeling energy dissipation.
where
phase_damping_error
phase_damping_error(prob: float) -> QuantumErrorCreates a phase damping (T2 dephasing) error channel modeling loss of phase coherence.
decoherence_error
decoherence_error(T1: float, T2: float, time_param: float) -> QuantumError| Parameter | Type | Description |
|---|---|---|
| T1 | float | T1 (amplitude damping) relaxation time |
| T2 | float | T2 (phase damping) dephasing time |
| time_param | float | Gate operation time |
Creates a combined decoherence error modeling both T1 (amplitude damping) and T2 (phase damping) processes.