NoiseModel#
- class NoiseModel(basis_gates=None)[source]#
Bases:
object
Noise model class for Aer simulators.
This class is used to represent noise model for the
QasmSimulator
. It can be used to construct custom noise models for simulator, or to automatically generate a basic device noise model for an IBMQ backend. See thenoise
module documentation for additional information.Example: Basic device noise model
An approximate
NoiseModel
can be generated automatically from the properties of real device backends from the IBMQ provider using thefrom_backend()
method.from qiskit import IBMQ, Aer from qiskit_aer.noise import NoiseModel provider = IBMQ.load_account() backend = provider.get_backend('ibmq_vigo') noise_model = NoiseModel.from_backend(backend) print(noise_model)
Example: Custom noise model
Custom noise models can be used by adding
QuantumError
to circuit gate, reset or measure instructions, andReadoutError
to measure instructions.import qiskit_aer.noise as noise # Error probabilities prob_1 = 0.001 # 1-qubit gate prob_2 = 0.01 # 2-qubit gate # Depolarizing quantum errors error_1 = noise.depolarizing_error(prob_1, 1) error_2 = noise.depolarizing_error(prob_2, 2) # Add errors to noise model noise_model = noise.NoiseModel() noise_model.add_all_qubit_quantum_error(error_1, ['rz', 'sx', 'x']) noise_model.add_all_qubit_quantum_error(error_2, ['cx']) print(noise_model)
Initialize an empty noise model.
- Parameters:
basis_gates (list[str] or None) – Specify an initial basis_gates for the noise model. If None a default value of [‘id’, ‘rz’, ‘sx’, ‘cx’] is used (Default: None).
Additional Information: Errors added to the noise model will have their instruction appended to the noise model basis_gates if the instruction is in the
QasmSimulator
basis_gates. If the instruction is not in theQasmSimulator
basis_gates it is assumed to be a label for a standard gate, and that gate should be added to the NoiseModel basis_gates either using the init method, or theadd_basis_gates()
method.Attributes
- basis_gates#
Return basis_gates for compiling to the noise model.
- noise_instructions#
Return the set of noisy instructions for this noise model.
- noise_qubits#
Return the set of noisy qubits for this noise model.
Methods
- add_all_qubit_quantum_error(error, instructions, warnings=True)[source]#
Add a quantum error to the noise model that applies to all qubits.
- Parameters:
error (QuantumError) – the quantum error object.
or (instructions (str or list[str]) – Instruction or list[Instruction]): the instructions error applies to.
warnings (bool) – Display warning if appending to an instruction that already has an error (Default: True).
- Raises:
NoiseError – if the input parameters are invalid.
- Additional Information:
If the error object is ideal it will not be added to the model.
- add_all_qubit_readout_error(error, warnings=True)[source]#
Add a single-qubit readout error that applies measure on all qubits.
- Parameters:
error (ReadoutError) – the quantum error object.
warnings (bool) – Display warning if appending to an instruction that already has an error (Default: True)
- Raises:
NoiseError – if the input parameters are invalid.
- Additional Information:
If the error object is ideal it will not be added to the model.
- add_basis_gates(instructions)[source]#
Add additional gates to the noise model basis_gates.
This should be used to add any gates that are identified by a custom gate label in the noise model.
- Parameters:
or (instructions (list[str]) – list[Instruction]): the instructions error applies to.
- add_quantum_error(error, instructions, qubits, warnings=True)[source]#
Add a quantum error to the noise model.
- Parameters:
error (QuantumError) – the quantum error object.
or (instructions (str or list[str]) – Instruction or list[Instruction]): the instructions error applies to.
qubits (Sequence[int]) – qubits instruction error applies to.
warnings (bool) – Display warning if appending to an instruction that already has an error (Default: True).
- Raises:
NoiseError – if the input parameters are invalid.
- Additional Information:
If the error object is ideal it will not be added to the model.
- add_readout_error(error, qubits, warnings=True)[source]#
Add a readout error to the noise model.
- Parameters:
error (ReadoutError) – the quantum error object.
qubits (list[int] or tuple[int]) – qubits instruction error applies to.
warnings (bool) – Display warning if appending to an instruction that already has an error [Default: True]
- Raises:
NoiseError – if the input parameters are invalid.
- Additional Information:
If the error object is ideal it will not be added to the model.
- classmethod from_backend(backend, gate_error=True, readout_error=True, thermal_relaxation=True, temperature=0, gate_lengths=None, gate_length_units='ns', warnings=None)[source]#
Return a noise model derived from a devices backend properties.
This function generates a noise model based on:
1 and 2 qubit gate errors consisting of a
depolarizing_error()
followed by athermal_relaxation_error()
.Single qubit
ReadoutError
on all measurements.
The error (noise) parameters are tuned for each individual qubit based on the \(T_1\), \(T_2\), frequency and readout error parameters for each qubit, and the gate error and gate time parameters for each gate obtained from the device backend properties.
Note that if un-physical parameters are supplied, they are internally truncated to the theoretical bound values. For example, if \(T_2 > 2 T_1\), \(T_2\) parameter will be truncated to \(2 T_1\).
Additional Information
The noise model includes the following errors:
If
readout_error=True
include single qubit readout errors on measurements.If
gate_error=True
andthermal_relaxation=True
include:Single-qubit gate errors consisting of a
depolarizing_error()
followed by athermal_relaxation_error()
for the qubit the gate acts on.Two-qubit gate errors consisting of a 2-qubit
depolarizing_error()
followed by single qubitthermal_relaxation_error()
on each qubit participating in the gate.
If
gate_error=True
isTrue
andthermal_relaxation=False
:An N-qubit
depolarizing_error()
on each N-qubit gate.
If
gate_error=False
andthermal_relaxation=True
include single-qubitthermal_relaxation_errors()
on each qubits participating in a multi-qubit gate.
For best practice in simulating a backend make sure that the circuit is compiled using the set of basis gates in the noise module by setting
basis_gates=noise_model.basis_gates
and using the device coupling map withcoupling_map=backend.configuration().coupling_map
Specifying custom gate times
The
gate_lengths
kwarg can be used to specify custom gate times to add gate errors using the \(T_1\) and \(T_2\) values from the backend properties. This should be passed as a list of tuplesgate_lengths=[(name, value), ...]
wherename
is the gate name string, andvalue
is the gate time in nanoseconds.If a custom gate is specified that already exists in the backend properties, the
gate_lengths
value will override the gate time value from the backend properties. If non-default values are used gate_lengths should be a list- Parameters:
backend (Backend) – backend. For BackendV2, warnings options are ignored, and their default values are used.
gate_error (bool) – Include depolarizing gate errors (Default: True).
readout_error (Bool) – Include readout errors in model (Default: True).
thermal_relaxation (Bool) – Include thermal relaxation errors (Default: True).
temperature (double) – qubit temperature in milli-Kelvin (mK) for thermal relaxation errors (Default: 0).
gate_lengths (list) – Custom gate times for thermal relaxation errors. Used to extend or override the gate times in the backend properties (Default: None))
gate_length_units (str) – Time units for gate length values in gate_lengths. Can be ‘ns’, ‘ms’, ‘us’, or ‘s’ (Default: ‘ns’).
warnings (bool) – DEPRECATED, Display warnings (Default: None).
- Returns:
An approximate noise model for the device backend.
- Return type:
- Raises:
NoiseError – If the input backend is not valid.
- classmethod from_backend_properties(backend_properties: BackendProperties, gate_error: bool = True, readout_error: bool = True, thermal_relaxation: bool = True, temperature: float = 0, gate_lengths: list | None = None, gate_length_units: str = 'ns', dt: float | None = None)[source]#
Return a noise model derived from a backend properties.
This method basically generates a noise model in the same way as
from_backend()
. One small difference is that thedt
option is required to be set manually if you want to add thermal relaxation noises to delay instructions with durations indt
time unit. Because it is not supplied by aBackendProperties
object unlike aBackend
object. Note that the resulting noise model is the same as described infrom_backend()
so please refer to it for the details.- Parameters:
backend_properties (BackendProperties) – The property of backend.
gate_error (Bool) – Include depolarizing gate errors (Default: True).
readout_error (Bool) – Include readout errors in model (Default: True).
thermal_relaxation (Bool) – Include thermal relaxation errors (Default: True). If no
t1
andt2
values are provided (i.e. None) intarget
for a qubit, an identityQuantumError` (i.e. effectively no thermal relaxation error) will be added to the qubit even if this flag is set to True. If no ``frequency
is not defined (i.e. None) intarget
for a qubit, no excitation is considered in the thermal relaxation error on the qubit even with non-zerotemperature
.temperature (double) – qubit temperature in milli-Kelvin (mK) for thermal relaxation errors (Default: 0).
gate_lengths (Optional[list]) – Custom gate times for thermal relaxation errors. Used to extend or override the gate times in the backend properties (Default: None))
gate_length_units (str) – Time units for gate length values in gate_lengths. Can be ‘ns’, ‘ms’, ‘us’, or ‘s’ (Default: ‘ns’).
dt (Optional[float]) – Backend sample time (resolution) in seconds (Default: None). Required to convert time unit of durations to seconds if including thermal relaxation errors on delay instructions.
- Returns:
An approximate noise model for the device backend.
- Return type:
- Raises:
NoiseError – If the input backend properties are not valid.