# Device backend noise model simulations¶

## Introduction¶

This notebook shows how to use the Qiskit Aer noise module to automatically generate a basic noise model for an IBMQ hardware device, and use this model to do noisy simulations of QuantumCircuits to study the effects of errors which occur on real devices.

Note, that these automatic models are only an approximation of the real errors that occur on actual devices, due to the fact that they must be build from a limited set of input parameters related to average error rates on gates. The study of quantum errors on real devices is an active area of research and we discuss the Qiskit Aer tools for configuring more detailed noise models in another notebook.

[1]:

%matplotlib inline
from qiskit import Aer, IBMQ, execute
from qiskit import QuantumCircuit, QuantumRegister, ClassicalRegister
from qiskit.tools.visualization import plot_histogram
from qiskit.tools.monitor import job_monitor

from qiskit.providers.aer.noise import NoiseModel


## Device Backend Noise Model¶

The Qiskit Aer device noise model automatically generates a simplified noise model for a real device. This model is generated using the calibration information reported in the BackendProperties of a device and takes into account

• The gate_error probability of each basis gate on each qubit.

• The gate_length of each basis gate on each qubit.

• The $$T_1$$, $$T_2$$ relaxation time constants of each qubit.

• The readout error probabilies of each qubit.

### Terra Mock Backends¶

We will use real noise data for an IBM Quantum device using the date stored in Qiskit Terra

We will use the ibmq_vigo device for this tutorial. We will also want to get the coupling_map for the device from its configuration to use when compiling circuits for simulation to most closely mimic the gates that will be executed on a real device.

[5]:

from qiskit.test.mock import FakeVigo
device_backend = FakeVigo()

# The device coupling map is needed for transpiling to correct
# CNOT gates before simulation
coupling_map = device_backend.configuration().coupling_map


### Test circuit for device and simulation comparison¶

Now we construct a test circuit to compare the output of the real device with the noisy output simulated on the Qiskit Aer QasmSimulator. We will prepare a 3-qubit GHZ state $$\frac{1}{2}(|0,0,0\rangle + |1,1,1\rangle)$$ on qubits 0, 1 and 2. Before running with noise or on the device we show the ideal expected output with no noise.

[6]:

# Construct quantum circuit
circ = QuantumCircuit(3, 3)
circ.h(0)
circ.cx(0, 1)
circ.cx(1, 2)
circ.measure([0, 1, 2], [0, 1, 2])

# Select the QasmSimulator from the Aer provider
simulator = Aer.get_backend('qasm_simulator')

# Execute and get counts
result = execute(circ, simulator).result()
counts = result.get_counts(circ)
plot_histogram(counts, title='Ideal counts for 3-qubit GHZ state')

[6]:


## Generating a device backend noise model¶

Noise models in Qiskit Aer are presented using the NoiseModel object from the noise module. The NoiseModel class has a from_backend method which will return a basic approximate NoiseModel object configured from a devices BackendProperties.

### Backend noise model¶

The NoiseModel.from_backend method constructs an approximate noise model consisting of:

• Single-qubit gate errors consisting of a single qubit depolarizing error followed by a single qubit thermal relaxation error.

• Two-qubit gate errors consisting of a two-qubit depolarizing error followed by single-qubit thermal relaxation errors on both qubits in the gate.

• Single-qubit readout errors on the classical bit value obtained from measurements on individual qubits.

For the gate errors the error parameter of the thermal relaxation errors is derived using the thermal_relaxation_error function from aer.noise.errors module, along with the individual qubit $$T_1$$ and $$T_2$$ parameters, and the gate_time parameter from the device backend properties. The probability of the depolarizing error is then set so that the combined average gate infidelity from the depolarizing error followed by the thermal relaxation is equal to the gate_error value from the backend properties.

For the readout errors the probability that the recorded classical bit value will be flipped from the true outcome after a measurement is given by the qubit readout_errors.

Let us construct the device noise model.

[7]:

# Construct the noise model from backend properties
noise_model = NoiseModel.from_backend(device_backend)
print(noise_model)

NoiseModel:
Basis gates: ['cx', 'id', 'u2', 'u3']
Instructions with noise: ['id', 'cx', 'u2', 'measure', 'u3']
Qubits with noise: [0, 1, 2, 3, 4]
Specific qubit errors: [('id', [0]), ('id', [1]), ('id', [2]), ('id', [3]), ('id', [4]), ('u2', [0]), ('u2', [1]), ('u2', [2]), ('u2', [3]), ('u2', [4]), ('u3', [0]), ('u3', [1]), ('u3', [2]), ('u3', [3]), ('u3', [4]), ('cx', [0, 1]), ('cx', [1, 0]), ('cx', [1, 2]), ('cx', [1, 3]), ('cx', [2, 1]), ('cx', [3, 1]), ('cx', [3, 4]), ('cx', [4, 3]), ('measure', [0]), ('measure', [1]), ('measure', [2]), ('measure', [3]), ('measure', [4])]


## Simulating a quantum circuit with noise¶

To use this noise model we must make use of several keyword arguments in the execute function. These are:

• noise_model: This passes the noise model to the QasmSimulator.run method for noisy simulation.

• basis_gates: A noise model is defined with respect to specific gates, we must pass these basis gates to the Qiskit compiler so that it compiles the circuit to the correct gates for the noise model. The basis gates of a noise model may be obtained from the NoiseModel.basis_gates property.

• coupling_map: We also must make sure we provide the coupling_map for the real device so that the compiler will produce a Qobj for the simulator that will match the compiled experiment that can be executed on the real device.

### Local Simulator¶

[8]:

# Get the basis gates for the noise model
basis_gates = noise_model.basis_gates

# Select the QasmSimulator from the Aer provider
simulator = Aer.get_backend('qasm_simulator')

# Execute noisy simulation and get counts
result_noise = execute(circ, simulator,
noise_model=noise_model,
coupling_map=coupling_map,
basis_gates=basis_gates).result()
counts_noise = result_noise.get_counts(circ)
plot_histogram(counts_noise, title="Counts for 3-qubit GHZ state with depolarizing noise model")

[8]:

[12]:

import qiskit.tools.jupyter
%qiskit_version_table
%qiskit_copyright


### Version Information

Qiskit SoftwareVersion
QiskitNone
Terra0.12.0.dev0+62adde9
Aer0.4.0
Ignis0.3.0.dev0+829207f
Aqua0.7.0.dev0+2776c5d
IBM Q Provider0.4.6rc1
System information
Python3.7.3 | packaged by conda-forge | (default, Jul 1 2019, 14:38:56) [Clang 4.0.1 (tags/RELEASE_401/final)]
OSDarwin
CPUs6
Memory (Gb)32.0
Thu Feb 06 16:19:40 2020 PST

### This code is a part of Qiskit

© Copyright IBM 2017, 2020.

This code is licensed under the Apache License, Version 2.0. You may
obtain a copy of this license in the LICENSE.txt file in the root directory
of this source tree or at http://www.apache.org/licenses/LICENSE-2.0.

Any modifications or derivative works of this code must retain this
copyright notice, and modified files need to carry a notice indicating
that they have been altered from the originals.

[ ]: