Bemerkung

This page was generated from tutorials/simulators/2_device_noise_simulation.ipynb.

Run interactively in the IBM Quantum lab.

# 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 IBMQ, transpile
from qiskit import QuantumCircuit
from qiskit.providers.aer import AerSimulator
from qiskit.tools.visualization import plot_histogram
```

## 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 probability of each qubit.

### Terra Mock Backends¶

We will use real noise data for an IBM Quantum device using the date stored in Qiskit Terra. Specifically, in this tutorial, the device is `ibmq_vigo`

.

```
[2]:
```

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

### 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 `AerSimulator`

. 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.

```
[3]:
```

```
# 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])
sim_ideal = AerSimulator()
# Execute and get counts
result = sim_ideal.run(transpile(circ, sim_ideal)).result()
counts = result.get_counts(0)
plot_histogram(counts, title='Ideal counts for 3-qubit GHZ state')
```

```
[3]:
```

## Generating a simulator that mimics a device¶

We call `from_backend`

to create a simulator for `ibmq_vigo`

:

```
[4]:
```

```
sim_vigo = AerSimulator.from_backend(device_backend)
```

By storing the device properties in `vigo_simulator`

, we ensure that the appropriate basis gates and coupling map are used when compiling circuits for simulation, thereby most closely mimicking the gates that will be executed on a real device. In addition `vigo_simulator`

contains 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`

.

Once we have created a noisy simulator backend based on a real device we can use it to run noisy simulations.

**Important:** When running noisy simulations it is *critical* to `transpile`

the circuit for the backend so that the circuit is transpiled to the correct noisy basis gate set for the backend.

```
[5]:
```

```
# Transpile the circuit for the noisy basis gates
tcirc = transpile(circ, sim_vigo)
# Execute noisy simulation and get counts
result_noise = sim_vigo.run(tcirc).result()
counts_noise = result_noise.get_counts(0)
plot_histogram(counts_noise,
title="Counts for 3-qubit GHZ state with device noise model")
```

```
[5]:
```

If transpilation is skipped noise from the device noise model will not be applied to gates in the circuit that are supported by the simulator, but not supported by the mimiced backend.

```
[6]:
```

```
import qiskit.tools.jupyter
%qiskit_version_table
%qiskit_copyright
```

### Version Information

Qiskit Software | Version |
---|---|

Qiskit | 0.25.0 |

Terra | 0.17.0 |

Aer | 0.8.0 |

Ignis | 0.6.0 |

Aqua | 0.9.0 |

IBM Q Provider | 0.12.2 |

System information | |

Python | 3.7.7 (default, May 6 2020, 04:59:01) [Clang 4.0.1 (tags/RELEASE_401/final)] |

OS | Darwin |

CPUs | 6 |

Memory (Gb) | 32.0 |

Fri Apr 02 12:01:10 2021 EDT |

### This code is a part of Qiskit

© Copyright IBM 2017, 2021.

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.

```
[ ]:
```

```
```