Skip to content

Commit

Permalink
Merge branch 'master' into Gate-set-tomography
Browse files Browse the repository at this point in the history
  • Loading branch information
renatomello committed Mar 6, 2024
2 parents 0dd59a0 + 62c4dfd commit b763b3d
Show file tree
Hide file tree
Showing 31 changed files with 2,411 additions and 1,880 deletions.
48 changes: 38 additions & 10 deletions doc/source/api-reference/qibo.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1128,22 +1128,26 @@ The quantum errors available to build a noise model are the following:
:member-order: bysource


Realistic noise model
^^^^^^^^^^^^^^^^^^^^^
IBMQ noise model
^^^^^^^^^^^^^^^^

In Qibo, it is possible to build a realistic noise model of a real quantum computer
by using the :meth:`qibo.noise.NoiseModel.composite()` method.
In Qibo, it is possible to build noisy circuits based on IBMQ's reported noise model of
for its quantum computer by using the :class:`qibo.noise.IBMQNoiseModel` class.
The noise model is built using a combination of the
:class:`qibo.gates.ThermalRelaxationChannel` and :class:`qibo.gates.DepolarizingChannel`
channels. After each gate of the original circuit, the function applies a depolarizing
and a thermal relaxation channel. At the end of the circuit, if the qubit is measured,
channels. . At the end of the circuit, if the qubit is measured,
bitflips errors are set. Moreover, the model handles idle qubits by applying a thermal
relaxation channel for the duration of the idle-time.

For more information on the :meth:`qibo.noise.NoiseModel.composite()` method, see the
For more information on the :class:`qibo.noise.IBMQNoiseModel` class, see the
example on :ref:`Simulating quantum hardware <noise-hardware-example>`.


.. autoclass:: qibo.noise.IBMQNoiseModel
:members:
:member-order: bysource


_______________________

.. _Hamiltonians:
Expand Down Expand Up @@ -1592,12 +1596,12 @@ passing a symplectic matrix to the constructor.
.. testsetup::

from qibo.quantum_info import Clifford
from qibo.backends import CliffordBackend, NumpyBackend
from qibo.backends import CliffordBackend

# construct the |00...0> state
backend = CliffordBackend(NumpyBackend())
backend = CliffordBackend("numpy")
symplectic_matrix = backend.zero_state(nqubits=3)
clifford = Clifford(symplectic_matrix, engine=NumpyBackend())
clifford = Clifford(symplectic_matrix, engine="numpy")
The generators of the stabilizers can be extracted with the
:meth:`qibo.quantum_info.clifford.Clifford.generators` method,
Expand All @@ -1611,6 +1615,23 @@ or the complete set of :math:`d = 2^{n}` stabilizers operators can be extracted

The destabilizers can be extracted analogously with :meth:`qibo.quantum_info.clifford.Clifford.destabilizers`.

We provide integration with the `stim <https://github.com/quantumlib/Stim>`_ package.
It is possible to run Clifford circuits using `stim` as an engine:

.. code-block:: python
from qibo.backends import CliffordBackend
from qibo.quantum_info import Clifford, random_clifford
clifford_backend = CliffordBackend(engine="stim")
circuit = random_clifford(nqubits)
result = clifford_backend.execute_circuit(circuit)
## Note that the execution above is equivalent to the one below
result = Clifford.from_circuit(circuit, engine="stim")
.. autoclass:: qibo.quantum_info.clifford.Clifford
:members:
:member-order: bysource
Expand Down Expand Up @@ -2366,6 +2387,8 @@ variable.
:members:
:member-order: bysource

.. _Clifford:

Clifford Simulation
^^^^^^^^^^^^^^^^^^^

Expand Down Expand Up @@ -2547,3 +2570,8 @@ indexed by :math:`j` and :math:`k` given respectively as
.. autoclass:: qibo.tomography.gate_set_tomography
:members:
:member-order: bysource

Cloud Backends
^^^^^^^^^^^^^^

Additional backends, that support the remote execution of quantum circuits through cloud service providers, such as IBM and QRC-TII, are provided by the optional qibo plugin `qibo-cloud-backends <https://github.com/qiboteam/qibo-cloud-backends>`_. For more information please refer to the `official documentation <https://qibo.science/qibo-cloud-backends/stable/>`_.
102 changes: 62 additions & 40 deletions doc/source/code-examples/advancedexamples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -999,7 +999,7 @@ Here is an example on how to use a noise model:
noise.add(PauliError([("X", 0.5)]), gates.H, 1)
noise.add(PauliError([("Y", 0.5)]), gates.CNOT)
is_sqrt_x = (lambda g: np.pi/2 in g.parameters)
noise.add(PauliError([("X", 0.5)]), gates.RX, qubits=0, condition=is_sqrt_x)
noise.add(PauliError([("X", 0.5)]), gates.RX, qubits=0, conditions=is_sqrt_x)

# Generate noiseless circuit.
c = models.Circuit(2)
Expand Down Expand Up @@ -1115,68 +1115,90 @@ be used for both errors.

.. _noise-hardware-example:

Simulating quantum hardware
^^^^^^^^^^^^^^^^^^^^^^^^^^^
Simulating IBMQ's quantum hardware
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Qibo can perform a simulation of a real quantum computer using the :meth:`qibo.noise.NoiseModel.composite` method of the :class:`qibo.noise.NoiseModel` class. This is possible by passing the circuit instance that we want to simulate and the noise channels' parameters as a dictionary.
In this model, the user must set the relaxation times ``t1`` and ``t2`` for each qubit, an approximated `gate time` and `depolarizing error` for each one-qubit gate and two-qubits gate and bitflips probabilities for each qubit which is measured.
Qibo can perform a simulation of a real quantum computer using the
:class:`qibo.noise.IBMQNoiseModel` class.
It is possible by passing the circuit instance that we want to simulate
and the noise channels' parameters as a dictionary.
In this model, the user must set the relaxation times ``t1`` and ``t2`` for each qubit,
an approximated `gate times`, and depolarizing errors for each one-qubit (`depolarizing_one_qubit`)
and two-qubit (`depolarizing_two_qubit`) gates.
Additionally, one can also pass single-qubit readout error probabilities (`readout_one_qubit`).

.. testcode::

from qibo import gates, models
from qibo.noise import NoiseModel
from qibo import Circuit, gates
from qibo.noise import IBMQNoiseModel

nqubits = 2
circuit = Circuit(2, density_matrix=True)
circuit.add(
[
gates.H(0),
gates.X(1),
gates.Z(0),
gates.X(0),
gates.CNOT(0,1),
gates.CNOT(1, 0),
gates.X(1),
gates.Z(1),
gates.M(0),
gates.M(1),
]
)

c = models.Circuit(2,density_matrix=True)
c.add([gates.H(0), gates.X(1) ,gates.Z(0), gates.X(0), gates.CNOT(0,1),
gates.CNOT(1, 0),gates.X(1),gates.Z(1), gates.M(0,1)])
print("raw circuit:")
print(circuit.draw())

print("raw circuit:")
print(c.draw())
parameters = {
"t1": {"0": 250*1e-06, "1": 240*1e-06},
"t2": {"0": 150*1e-06, "1": 160*1e-06},
"gate_times" : (200*1e-9, 400*1e-9),
"excited_population" : 0,
"depolarizing_one_qubit" : 4.000e-4,
"depolarizing_two_qubit": 1.500e-4,
"readout_one_qubit" : {"0": (0.022, 0.034), "1": (0.015, 0.041)},
}

par = {"t1" : (250*1e-06, 240*1e-06),
"t2" : (150*1e-06, 160*1e-06),
"gate_time" : (200*1e-9, 400*1e-9),
"excited_population" : 0,
"depolarizing_error" : (4.000e-4, 1.500e-4),
"bitflips_error" : ([0.022, 0.015], [0.034, 0.041]),
"idle_qubits" : 1
}
noise= NoiseModel()
noise.composite(par)
noisy_circ=noise.apply(c)
noise_model = IBMQNoiseModel()
noise_model.from_dict(parameters)
noisy_circuit = noise_model.apply(circuit)

print("noisy circuit:")
print(noisy_circ.draw())
print("noisy circuit:")
print(noisy_circuit.draw())

.. testoutput::
:hide:

...

``noisy_circ`` is the new circuit containing the error gate channels.
``noisy_circuit`` is the new circuit containing the error gate channels.

It is possible to learn the parameters of the noise model that best describe a frequency distribution obtained by running a circuit on quantum hardware. To do this,
assuming we have a ``result`` object after running a circuit with a certain number of shots,
.. #TODO: rewrite this optimization example after the fit function is moded to `qibo.optimizers`
.. It is possible to learn the parameters of the noise model that best describe a frequency distribution obtained by running a circuit on quantum hardware. To do this,
.. assuming we have a ``result`` object after running a circuit with a certain number of shots,
.. testcode::
.. .. testcode::

noise = NoiseModel()
params = {"idle_qubits" : True}
noise.composite(params)
.. noise = NoiseModel()
.. params = {"idle_qubits" : True}
.. noise.composite(params)
result = noisy_circ(nshots=1000)
.. result = noisy_circ(nshots=1000)
noise.noise_model.fit(c, result)
.. noise.noise_model.fit(c, result)
print(noise.noise_model.params)
print(noise.noise_model.hellinger)
.. print(noise.noise_model.params)
.. print(noise.noise_model.hellinger)
.. testoutput::
:hide:
.. .. testoutput::
.. :hide:
...
.. ...
where ``noise.params`` is a dictionary with the parameters obatined after the optimization and ``noise.hellinger`` is the corresponding Hellinger fidelity.
.. where ``noise.params`` is a dictionary with the parameters obatined after the optimization and ``noise.hellinger`` is the corresponding Hellinger fidelity.
How to perform error mitigation?
Expand Down
Binary file added doc/source/getting-started/backends.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 9 additions & 2 deletions doc/source/getting-started/backends.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Qibo provides backends for quantum simulation on classical
hardware and quantum hardware management and control. In the image below we
present a schematic view of the currently supported backends.

.. image:: backends.svg
.. image:: backends.png

Quantum simulation is proposed through dedicated backends for single node
multi-GPU and multi-threading CPU setups. Quantum hardware control is supported
Expand All @@ -34,9 +34,12 @@ Simulation backends
We provide multiple simulation backends for Qibo, which are automatically loaded
if the corresponding packages are installed, following the hierarchy below:

* :ref:`installing-numpy`: a lightweight quantum simulator shipped with the :ref:`installing-qibo` base package. Use this simulator if your CPU architecture is not supported by the other backends. Please note that the simulation performance is quite poor in comparison to other backends.
* :ref:`installing-qibojit`: an efficient simulation backend for CPU, GPU and multi-GPU based on just-in-time (JIT) compiled custom operators. Install this package if you need to simulate quantum circuits with large number of qubits or complex quantum algorithms which may benefit from computing parallelism.
* `qibotn <https://qibo.science/qibotn/stable/>`_: an interface to Tensor Networks simulation algorithms designed for GPUs and multi-node CPUs. This backend makes possible scaling quantum circuit simulation to a larger number of qubits.
* :ref:`installing-tensorflow`: a pure TensorFlow implementation for quantum simulation which provides access to gradient descent optimization and the possibility to implement classical and quantum architectures together. This backend is not optimized for memory and speed, use :ref:`installing-qibojit` instead.
* :ref:`installing-numpy`: a lightweight quantum simulator shipped with the :ref:`installing-qibo` base package. Use this simulator if your CPU architecture is not supported by the other backends. Please note that the simulation performance is quite poor in comparison to other backends.
* :ref:`installing-pytorch`: a pure PyTorch implementation for quantum simulation which provides access to gradient descent optimization and the possibility to implement classical and quantum architectures together. This backend is not optimized for memory and speed, use :ref:`installing-qibojit` instead.
* :ref:`clifford <Clifford>`: a specialized backend for the simulation of quantum circuits with Clifford gates. This backend uses :ref:`installing-qibojit` and/or :ref:`installing-numpy`.

The default backend that is used is the first available from the above list.
The user can switch to a different using the ``qibo.set_backend`` method
Expand Down Expand Up @@ -77,3 +80,7 @@ We provide the following hardware control backends for Qibo:
* `qibosoq <https://qibo.science/qibosoq/stable/>`_: is the server that
integrates `Qick <https://github.com/openquantumhardware/qick>`_ in the
Qibolab ecosystem for executing arbitrary circuits and pulse sequences.

* `qibo-cloud-backends <https://qibo.science/qibo-cloud-backends/stable/>`_:
provides access to cloud quantum hardware. This module is compatible with labs
using Qibo for control and calibration and external vendors.
6 changes: 0 additions & 6 deletions doc/source/getting-started/backends.svg

This file was deleted.

35 changes: 16 additions & 19 deletions doc/source/getting-started/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ distributed with pypi* for the packages listed above.
+------------------+------+---------+------------+

.. note::
All packages are supported for Python >= 3.7.
All packages are supported for Python >= 3.9.


Backend installation
Expand All @@ -38,7 +38,7 @@ Installing with pip
"""""""""""""""""""

The installation using ``pip`` is the recommended approach to install Qibo.
Make sure you have Python 3.7 or greater, then use ``pip`` to install ``qibo`` with:
Make sure you have Python 3.9 or greater, then use ``pip`` to install ``qibo`` with:

.. code-block:: bash
Expand Down Expand Up @@ -237,30 +237,27 @@ please do:
_______________________

.. _docker:

Using the code with docker
--------------------------
.. _installing-pytorch:

We provide docker images for tag release of the code using GitHub Packages. The
docker images contain a pre-configured linux environment with the Qibo
framework installed with the specific tag version.
pytorch
^^^^^^^

Please refer to the download and authentication instructions from the `Qibo GitHub Packages`_.
If the `PyTorch <https://pytorch.org/>`_ package is installed Qibo
will detect and provide to the user the possibility to use ``pytorch``
backend.

In order to start the docker image in interactive mode please use docker
standard syntax, for example:
In order to switch to the ``pytorch`` backend please do:

.. code::
.. code-block:: python
docker run -it ghcr.io/qiboteam/qibo:<tag_version> bash
import qibo
qibo.set_backend("pytorch")
This will open a bash shell with the Qibo environment already activated, with
all binaries and scripts from the Qibo framework.
In order to install the package, we recommend the installation using:

.. _Qibo GitHub Packages: https://github.com/qiboteam/qibo/pkgs/container/qibo
.. code-block:: bash
pip install qibo torch
.. note::
The docker image contains the basic ``qibo`` package with the lightweight
``numpy`` backend for simulation.
_______________________
6 changes: 4 additions & 2 deletions doc/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Components

The main components of ``Qibo`` are presented in :doc:`getting-started/index`

.. image:: qibo_ecosystem.svg
.. image:: qibo_ecosystem.png

Key features
------------
Expand Down Expand Up @@ -88,7 +88,9 @@ Contents
Qibolab docs <https://qibo.science/qibolab/stable/>
Qibocal docs <https://qibo.science/qibocal/stable/>
Qibosoq docs <https://qibo.science/qibosoq/stable/>

Qibochem docs <https://qibo.science/qibochem/stable/>
Qibotn docs <https://qibo.science/qibotn/stable/>
Qibo-cloud-backends docs <https://qibo.science/qibo-cloud-backends/stable/>

Indices and tables
==================
Expand Down
Binary file added doc/source/qibo_ecosystem.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 0 additions & 13 deletions doc/source/qibo_ecosystem.svg

This file was deleted.

Loading

0 comments on commit b763b3d

Please sign in to comment.