Skip to content

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

python
class NoiseModel:
    def __init__() -> None

Methods

NoiseModel.is_enabled

python
is_enabled() -> bool

Check if the noise model contains any errors.

NoiseModel.add_read_out_error

python
add_read_out_error(probs: list[list[float]], qubit: int) -> None
ParameterTypeDescription
probslist[list[float]]Probabilities of readout error outcomes
qubitintQubit index to apply readout error

NoiseModel.add_all_qubit_read_out_error

python
add_all_qubit_read_out_error(probs: list[list[float]]) -> None
ParameterTypeDescription
probslist[list[float]]Probabilities of readout error outcomes

NoiseModel.add_quantum_error (specific qubits)

python
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
ParameterTypeDescription
errorQuantumErrorThe quantum error to add
gate_type(s)GateType or list[GateType]Gate type(s) where error applies
qubitslist[list[int]]Qubit index sets where error applies

NoiseModel.add_all_qubit_quantum_error

python
add_all_qubit_quantum_error(error: QuantumError, gate_type: GateType) -> None
add_all_qubit_quantum_error(error: QuantumError, gate_types: list[GateType]) -> None
ParameterTypeDescription
errorQuantumErrorThe quantum error to add
gate_type(s)GateType or list[GateType]Gate type(s) where error applies

Examples

python
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

python
class QuantumError:
    def __init__() -> None
    def __init__(kraus_matrices: list[numpy.ndarray]) -> None
    def __init__(pauli_probs: dict[str, float]) -> None
ParameterTypeDescription
kraus_matriceslist[numpy.ndarray]List of Kraus matrices
pauli_probsdict[str, float]Pauli error labels and probabilities (e.g., {"X": 0.01})

Methods

QuantumError.tensor

python
tensor(quantum_error: QuantumError) -> QuantumError
ParameterTypeDescription
quantum_errorQuantumErrorThe quantum error to tensor with

Apply tensor product operation with another quantum error.

QuantumError.expand

python
expand(quantum_error: QuantumError) -> QuantumError
ParameterTypeDescription
quantum_errorQuantumErrorThe quantum error to expand with

Expand the error to a larger qubit system.

QuantumError.compose

python
compose(quantum_error: QuantumError) -> QuantumError
ParameterTypeDescription
quantum_errorQuantumErrorThe quantum error to compose with

Compose the error with another quantum error.

QuantumError.qubit_num

python
qubit_num() -> int

Number of qubits affected by the error.

QuantumError.error_type

python
error_type() -> NoiseOpType

The type of error representation (Kraus matrices or noise circuit).

QuantumError.error_circuit

python
error_circuit(qubits: list[int]) -> QCircuit
ParameterTypeDescription
qubitslist[int]Qubit indices to apply the error circuit on

Circuit representation of the error.

QuantumError.error_karus

python
error_karus(qubits: list[int]) -> Karus
ParameterTypeDescription
qubitslist[int]Qubit indices to get the Kraus matrices for

Kraus matrix representation of the error.

NoiseOpType

Enum for noise operation representation types.

ValueDescription
KARUS_MATRIICESError represented by Kraus matrices
NOISEError represented by a noise circuit

Error Factory Functions

pauli_x_error

python
pauli_x_error(prob: float) -> QuantumError
ParameterTypeDescription
probfloatProbability of Pauli-X error

Creates a single-qubit Pauli-X (bit-flip) error channel. With probability p, an X gate is applied.

E(ρ)=(1p)ρ+pXρX

pauli_y_error

python
pauli_y_error(prob: float) -> QuantumError

Creates a Pauli-Y (bit-phase-flip) error channel.

E(ρ)=(1p)ρ+pYρY

pauli_z_error

python
pauli_z_error(prob: float) -> QuantumError

Creates a Pauli-Z (phase-flip) error channel.

E(ρ)=(1p)ρ+pZρZ

depolarizing_error

python
depolarizing_error(prob: float) -> QuantumError

Creates a depolarizing error channel. With probability p, the state is replaced by the maximally mixed state I/2.

E(ρ)=(1p)ρ+pI2

amplitude_damping_error

python
amplitude_damping_error(prob: float) -> QuantumError

Creates an amplitude damping (T1 relaxation) error channel modeling energy dissipation.

E(ρ)=E0ρE0+E1ρE1

where E0=[1001γ] and E1=[0γ00].

phase_damping_error

python
phase_damping_error(prob: float) -> QuantumError

Creates a phase damping (T2 dephasing) error channel modeling loss of phase coherence.

E(ρ)=[ρ00(1λ)ρ01(1λ)ρ10ρ11]

decoherence_error

python
decoherence_error(T1: float, T2: float, time_param: float) -> QuantumError
ParameterTypeDescription
T1floatT1 (amplitude damping) relaxation time
T2floatT2 (phase damping) dephasing time
time_paramfloatGate operation time

Creates a combined decoherence error modeling both T1 (amplitude damping) and T2 (phase damping) processes.

See Also

  • Simulator — Noise-aware quantum simulators
  • Enums — GateType for specifying gate types
  • Circuit — QCircuit and QProg

Released under the MIT License.