Noise models¶
The qtest.noise subpackage provides an SDK-agnostic
NoiseModel plus ready-made constructors for the common
error channels. Pass any of them to the noise_model argument of
qtest.assert_distribution_close() / qtest.assert_state_close(), or
set a preset globally with --qtest-noise / [tool.qtest] default_noise.
Public API¶
|
An SDK-agnostic description of a noise channel to apply during simulation. |
|
Depolarizing error of strength p on every gate. |
|
Bit-flip (Pauli-X) error: apply X with probability p after 1-qubit gates. |
|
Phase-flip (Pauli-Z) error: apply Z with probability p after 1-qubit gates. |
|
Thermal-relaxation (T1/T2) error applied to single-qubit gates. |
|
Measurement (readout) error. |
|
Return the |
|
Return the sorted names of the built-in noise presets. |
Reference¶
Noise models for qtest.
Real quantum hardware is noisy, and a test that only ever runs on an ideal
simulator says nothing about how a circuit behaves under decoherence and gate
error. This module provides a small, SDK-agnostic NoiseModel wrapper
plus a handful of ready-made constructors so tests can opt into noisy
simulation with a single argument:
from qtest import assert_distribution_close
from qtest.noise import depolarizing
assert_distribution_close(qc, expected, noise_model=depolarizing(0.01))
Design¶
A NoiseModel is a lightweight, immutable description of the noise to
apply — it stores a list of error specs and nothing else. The heavy Qiskit
Aer objects are built lazily in NoiseModel.to_qiskit(), so constructing a
NoiseModel (and importing this module) never requires qiskit-aer.
The import is only triggered when a noisy assertion actually runs.
Models compose with + so several error channels can be layered:
combined = depolarizing(0.01) + readout_error(0.02)
- class qtest.noise.models.NoiseModel(specs=None, label='custom')[source]¶
Bases:
objectAn SDK-agnostic description of a noise channel to apply during simulation.
Instances are immutable value objects: the recommended way to build one is via the module-level constructors (
depolarizing(),bit_flip(),phase_flip(),thermal_relaxation(),readout_error()) and to layer channels with+.- Parameters:
- to_qiskit()[source]¶
Build and return a
qiskit_aer.noise.NoiseModel.- Raises:
ImportError – If
qiskit-aeris not installed.- Return type:
- qtest.noise.models.depolarizing(p)[source]¶
Depolarizing error of strength p on every gate.
With probability p the qubit(s) acted on by a gate are replaced by the maximally mixed state. Applied as a 1-qubit channel to single-qubit gates and a 2-qubit channel to two-qubit gates.
- Parameters:
p (float) – Depolarizing probability in
[0, 1].- Return type:
- qtest.noise.models.bit_flip(p)[source]¶
Bit-flip (Pauli-X) error: apply X with probability p after 1-qubit gates.
- Parameters:
p (float)
- Return type:
- qtest.noise.models.phase_flip(p)[source]¶
Phase-flip (Pauli-Z) error: apply Z with probability p after 1-qubit gates.
- Parameters:
p (float)
- Return type:
- qtest.noise.models.thermal_relaxation(t1, t2, time)[source]¶
Thermal-relaxation (T1/T2) error applied to single-qubit gates.
- Parameters:
- Return type:
- qtest.noise.models.readout_error(p01, p10=None)[source]¶
Measurement (readout) error.
- Parameters:
- Return type:
- qtest.noise.models.available_presets()[source]¶
Return the sorted names of the built-in noise presets.
- qtest.noise.models.from_preset(name)[source]¶
Return the
NoiseModelfor a built-in preset name.- Raises:
ValueError – If name is not a known preset.
- Parameters:
name (str)
- Return type: