# qiskit.providers.aer.noise.NoiseModel¶

class NoiseModel(basis_gates=None)[código fonte]

Noise model class for Qiskit 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 the noise 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 the from_backend() method.

from qiskit import IBMQ, Aer
from qiskit.providers.aer.noise import NoiseModel

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, and ReadoutError to measure instructions.

import qiskit.providers.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()
print(noise_model)


Initialize an empty noise model.

Parâmetros

basis_gates (list[str] or None) – Specify an initial basis_gates for the noise model. If None a default value of [‘id’, ‘u3’, ‘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 the QasmSimulator 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 the add_basis_gates() method.

__init__(basis_gates=None)[código fonte]

Initialize an empty noise model.

Parâmetros

basis_gates (list[str] or None) – Specify an initial basis_gates for the noise model. If None a default value of [‘id’, ‘u3’, ‘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 the QasmSimulator 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 the add_basis_gates() method.

Methods

 __init__([basis_gates]) Initialize an empty noise model. add_all_qubit_quantum_error(error, instructions) Add a quantum error to the noise model that applies to all qubits. add_all_qubit_readout_error(error[, warnings]) Add a single-qubit readout error that applies measure on all qubits. add_basis_gates(instructions[, warnings]) Add additional gates to the noise model basis_gates. add_nonlocal_quantum_error(error, …[, …]) Add a non-local quantum error to the noise model. add_quantum_error(error, instructions, qubits) Add a quantum error to the noise model. add_readout_error(error, qubits[, warnings]) Add a readout error to the noise model. from_backend(backend[, gate_error, …]) Return a noise model derived from a devices backend properties. from_dict(noise_dict) Load NoiseModel from a dictionary. Return True if the noise model has no noise terms. Reset the noise model. to_dict([serializable]) Return the noise model as a dictionary.

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.
add_all_qubit_quantum_error(error, instructions, warnings=True)[código fonte]

Add a quantum error to the noise model that applies to all qubits.

Parâmetros
• error (QuantumError) – the quantum error object.

• (str or list[str] or (instructions) – 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).

Levanta

NoiseError – if the input parameters are invalid.

If the error object is ideal it will not be added to the model.

add_all_qubit_readout_error(error, warnings=True)[código fonte]

Parâmetros
• error (ReadoutError) – the quantum error object.

• warnings (bool) – Display warning if appending to an instruction that already has an error (Default: True)

Levanta

NoiseError – if the input parameters are invalid.

If the error object is ideal it will not be added to the model.

add_basis_gates(instructions, warnings=True)[código fonte]

This should be used to add any gates that are identified by a custom gate label in the noise model.

Parâmetros
• (list[str] or (instructions) – list[Instruction]): the instructions error applies to.

• warnings (bool) – display warning if instruction is not in QasmSimulator basis_gates (Default: True).

add_nonlocal_quantum_error(error, instructions, qubits, noise_qubits, warnings=True)[código fonte]

Add a non-local quantum error to the noise model.

Parâmetros
• error (QuantumError) – the quantum error object.

• (str or list[str] or (instructions) – Instruction or list[Instruction]): the instructions error applies to.

• qubits (list[int]) – qubits instruction error applies to.

• noise_qubits (list[int]) – Specify the exact qubits the error should be applied to if different to the instruction qubits.

• warnings (bool) – Display warning if appending to an instruction that already has an error (Default: True).

Levanta

NoiseError – if the input parameters are invalid.

If the error object is ideal it will not be added to the model.

add_quantum_error(error, instructions, qubits, warnings=True)[código fonte]

Add a quantum error to the noise model.

Parâmetros
• error (QuantumError) – the quantum error object.

• (str or list[str] or (instructions) – Instruction or list[Instruction]): the instructions error applies to.

• qubits (list[int]) – qubits instruction error applies to.

• warnings (bool) – Display warning if appending to an instruction that already has an error (Default: True).

Levanta

NoiseError – if the input parameters are invalid.

If the error object is ideal it will not be added to the model.

add_readout_error(error, qubits, warnings=True)[código fonte]

Parâmetros
• error (ReadoutError) – the quantum error object.

• qubits (list[int]) – qubits instruction error applies to.

• warnings (bool) – Display warning if appending to an instruction that already has an error [Default: True]

Levanta

NoiseError – if the input parameters are invalid.

If the error object is ideal it will not be added to the model.

property basis_gates

Return basis_gates for compiling to the noise model.

classmethod from_backend(backend, gate_error=True, readout_error=True, thermal_relaxation=True, temperature=0, gate_lengths=None, gate_length_units='ns', standard_gates=True, warnings=True)[código fonte]

Return a noise model derived from a devices backend properties.

This function generates a noise model based on:

The Error error 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.

The noise model includes the following errors:

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 with coupling_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 tuples gate_lengths=[(name, value), ...] where name is the gate name string, and value 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

Parâmetros
• backend (Backend or BackendProperties) – backend properties.

• gate_error (bool) – Include depolarizing gate errors (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’).

• standard_gates (bool) – If true return errors as standard qobj gates. If false return as unitary qobj instructions (Default: True)

• warnings (bool) – Display warnings (Default: True).

Retorna

An approximate noise model for the device backend.

Tipo de retorno

NoiseModel

Levanta

NoiseError – If the input backend is not valid.

static from_dict(noise_dict)[código fonte]

Parâmetros

noise_dict (dict) – A serialized noise model.

Retorna

the noise model.

Tipo de retorno

NoiseModel

Levanta

NoiseError – if dict cannot be converted to NoiseModel.

is_ideal()[código fonte]

Return True if the noise model has no noise terms.

property noise_instructions

Return the set of noisy instructions for this noise model.

property noise_qubits

Return the set of noisy qubits for this noise model.

reset()[código fonte]

Reset the noise model.

to_dict(serializable=False)[código fonte]

Return the noise model as a dictionary.

Parâmetros

serializable (bool) – if True, return a dict containing only types that can be serializable by the stdlib json module.

Retorna

a dictionary for a noise model.

Tipo de retorno

dict