Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify structure of aer.noise and aer.utils modules #568

Merged
merged 8 commits into from
Jan 31, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,19 @@ Added

Changed
-------
- Moved the location of several functions (\#568):
- Moved contents of `qiskit.provider.aer.noise.errors` into the `qiskit.providers.noise` module
- Moved contents of `qiskit.provider.aer.noise.device` into the `qiskit.providers.noise` module.
- Moved contents of `qiskit.provider.aer.noise.utils` into the `qiskit.provider.aer.utils` module.

Deprecated
----------
- Deprecated `utils.qobj_utils` functions (\#568)

Removed
-------
- Removed `NoiseModel.as_dict`, `QuantumError.as_dict`, `ReadoutError.as_dict`, and
`QuantumError.kron` methods that were deprecated in 0.3 (\#568).

Fixed
-----
Expand Down
37 changes: 18 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,42 +26,41 @@ $ python
```

```python
from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit, execute
from qiskit import QuantumCircuit, execute
from qiskit import Aer, IBMQ # import the Aer and IBMQ providers
from qiskit.providers.aer import noise # import Aer noise models
from qiskit.providers.aer import noise # import Aer noise module

# Choose a real device to simulate
provider = IBMQ.load_account()
device = provider.get_backend('ibmq_16_melbourne')
device = provider.get_backend('ibmq_vigo')
properties = device.properties()
coupling_map = device.configuration().coupling_map

# Generate an Aer noise model for device
noise_model = noise.device.basic_device_noise_model(properties)
noise_model = noise.basic_device_noise_model(properties)
basis_gates = noise_model.basis_gates

# Generate a quantum circuit
q = QuantumRegister(2)
c = ClassicalRegister(2)
qc = QuantumCircuit(q, c)

qc.h(q[0])
qc.cx(q[0], q[1])
qc.measure(q, c)
# Generate 3-qubit GHZ state
num_qubits = 3
circ = QuantumCircuit(3, 3)
circ.h(0)
circ.cx(0, 1)
circ.cx(1, 2)
circ.measure([0, 1, 2], [0, 1 ,2])

# Perform noisy simulation
backend = Aer.get_backend('qasm_simulator')
job_sim = execute(qc, backend,
coupling_map=coupling_map,
noise_model=noise_model,
basis_gates=basis_gates)
sim_result = job_sim.result()
job = execute(circ, backend,
coupling_map=coupling_map,
noise_model=noise_model,
basis_gates=basis_gates)
result = job.result()

print(sim_result.get_counts(qc))
print(result.get_counts(0))
```

```python
{'11': 412, '00': 379, '10': 117, '01': 116}
{'000': 495, '001': 18, '010': 8, '011': 18, '100': 2, '101': 14, '110': 28, '111': 441}
```


Expand Down
6 changes: 0 additions & 6 deletions docs/apidocs/aer_noise_device.rst

This file was deleted.

6 changes: 0 additions & 6 deletions docs/apidocs/aer_noise_errors.rst

This file was deleted.

6 changes: 0 additions & 6 deletions docs/apidocs/aer_noise_utils.rst

This file was deleted.

6 changes: 6 additions & 0 deletions docs/apidocs/aer_utils.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.. _aer-utils:

.. automodule:: qiskit.providers.aer.utils
:no-members:
:no-inherited-members:
:no-special-members:
6 changes: 2 additions & 4 deletions docs/apidocs/qiskit_aer.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ API Documentation

aer_provider
aer_extensions
aer_pulse
aer_noise
aer_noise_errors
aer_noise_device
aer_noise_utils
aer_pulse
aer_utils
4 changes: 2 additions & 2 deletions qiskit/providers/aer/backends/pulse_simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ class PulseSimulator(AerBackend):
'conditional': True,
'open_pulse': True,
'memory': False,
'max_shots': 10**6,
'description': 'A pulse-based Hamiltonian simulator',
'max_shots': int(1e6),
'description': 'A pulse-based Hamiltonian simulator for Pulse Qobj files',
'gates': [],
'basis_gates': []
}
Expand Down
4 changes: 2 additions & 2 deletions qiskit/providers/aer/backends/qasm_simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,8 @@ class QasmSimulator(AerBackend):
'conditional': True,
'open_pulse': False,
'memory': True,
'max_shots': 100000,
'description': 'A C++ simulator with realistic noise for qobj files',
'max_shots': int(1e6),
'description': 'A C++ simulator with realistic noise for QASM Qobj files',
'coupling_map': None,
'basis_gates': [
'u1', 'u2', 'u3', 'cx', 'cz', 'id', 'x', 'y', 'z', 'h', 's', 'sdg',
Expand Down
8 changes: 6 additions & 2 deletions qiskit/providers/aer/backends/statevector_simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,12 @@ class StatevectorSimulator(AerBackend):
'conditional': True,
'open_pulse': False,
'memory': True,
'max_shots': 1,
'description': 'A C++ statevector simulator for qobj files',
'max_shots': int(1e6), # Note that this backend will only ever
# perform a single shot. This value is just
# so that the default shot value for execute
# will not raise an error when trying to run
# a simulation
'description': 'A C++ statevector simulator for QASM Qobj files',
'coupling_map': None,
'basis_gates': [
'u1', 'u2', 'u3', 'cx', 'cz', 'id', 'x', 'y', 'z', 'h', 's', 'sdg',
Expand Down
9 changes: 6 additions & 3 deletions qiskit/providers/aer/backends/unitary_simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,12 @@ class UnitarySimulator(AerBackend):
'conditional': False,
'open_pulse': False,
'memory': False,
'max_shots': 1,
'description': 'A Python simulator for computing the unitary'
'matrix for experiments in qobj files',
'max_shots': int(1e6), # Note that this backend will only ever
# perform a single shot. This value is just
# so that the default shot value for execute
# will not raise an error when trying to run
# a simulation
'description': 'A C++ unitary simulator for QASM Qobj files',
'coupling_map': None,
'basis_gates': [
'u1', 'u2', 'u3', 'cx', 'cz', 'id', 'x', 'y', 'z', 'h', 's', 'sdg',
Expand Down
67 changes: 52 additions & 15 deletions qiskit/providers/aer/noise/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,38 +24,75 @@
Classes
=======

The following are the classes used to represented noise and error terms.

.. autosummary::
:toctree: ../stubs/

NoiseModel
QuantumError
ReadoutError


Submodules
==========
Quantum Error Functions
=======================

Errors for Noise Models
-----------------------
The following functions can be used to generate many common types of
:class:`QuantumError` objects for inclusion in a :class:`NoiseModel`.

The :mod:`qiskit.providers.aer.noise.errors` submodule contains classes
and functions for constructing generating errors for custom noise models.
.. autosummary::
:toctree: ../stubs/

pauli_error
depolarizing_error
pauli_error
mixed_unitary_error
coherent_unitary_error
reset_error
amplitude_damping_error
phase_damping_error
phase_amplitude_damping_error
thermal_relaxation_error
kraus_error

Device Noise Models
-------------------

The :mod:`qiskit.providers.aer.noise.device` submodule contains functions
for generating approximate noise models for a hardware device.
Noise Model Functions
=====================

The following functions can be used to generate approximate noise models for
IBMQ hardware devices based on the parameters in their backend properties.

Noise Utilities
---------------
.. autosummary::
:toctree: ../stubs/

The :mod:`qiskit.providers.aer.noise.utils` submodule contains utilities
for remapping and approximating noise models, and inserting noise into
quantum circuits.
basic_device_noise_model
basic_device_readout_errors
basic_device_gate_errors
"""

# Noise and Error classes
from .noise_model import NoiseModel
from .errors import QuantumError
from .errors import ReadoutError

# Error generating functions
from .errors import kraus_error
from .errors import mixed_unitary_error
from .errors import coherent_unitary_error
from .errors import pauli_error
from .errors import depolarizing_error
from .errors import reset_error
from .errors import thermal_relaxation_error
from .errors import phase_amplitude_damping_error
from .errors import amplitude_damping_error
from .errors import phase_damping_error

# Noise model generating functions
from .device.models import basic_device_noise_model
from .device.models import basic_device_readout_errors
from .device.models import basic_device_gate_errors

# Submodules
from . import errors
from . import device
from . import utils
54 changes: 1 addition & 53 deletions qiskit/providers/aer/noise/device/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,59 +11,7 @@
# that they have been altered from the originals.

"""
=============================================================
Device Noise Model (:mod:`qiskit.providers.aer.noise.device`)
=============================================================

.. currentmodule:: qiskit.providers.aer.noise.device

Approximate noise models for a hardware device can be generated from the
device properties using the functions in this module.

Basic device noise model
========================

The :func:`basic_device_noise_model` function generates a noise model
based on:

* 1 and 2 qubit gate errors consisting of a
:func:`~qiskit.providers.aer.noise.errors.depolarizing_error` followed
by a :func:`~qiskit.providers.aer.noise.errors.thermal_relaxation_error`.

* Single qubit :class:`~qiskit.providers.aer.noise.errors.ReadoutError` on
all measurements.

The Error error parameters are tuned for each individual qubit based on
the :math:`T_1`, :math:`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.


Functions
=========

.. autosummary::
:toctree: ../stubs/

basic_device_noise_model
basic_device_readout_errors
basic_device_gate_errors


Helper functions
================

The following helper functions can be used to extract parameters from
a device ``BackendProperties`` object.

.. autosummary::
:toctree: ../stubs/

parameters.gate_param_values
parameters.gate_error_values
parameters.gate_length_values
parameters.readout_error_values
parameters.thermal_relaxation_values
Functions for building noise models from backend properties.
"""

from .models import basic_device_noise_model
Expand Down
Loading