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

Creates IBMQNoiseModel #1227

Merged
merged 27 commits into from
Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
521469c
first commit
renatomello Feb 26, 2024
2d45a44
backup
renatomello Feb 27, 2024
60cf580
fix bug
renatomello Feb 27, 2024
891051f
Merge branch 'master' into composite_noise_model
renatomello Feb 27, 2024
299a5c3
api doc
renatomello Feb 27, 2024
fddda42
improving docstring
renatomello Feb 27, 2024
29f7791
docstring
renatomello Feb 27, 2024
fefa70e
fix docstring
renatomello Feb 27, 2024
a6bf79b
fix docstring
renatomello Feb 27, 2024
d893d76
remove outdated test
renatomello Feb 27, 2024
e68c9f7
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 27, 2024
ae7ab1b
`pylint` improvements
renatomello Feb 27, 2024
8039ec9
Merge branch 'composite_noise_model' of github.com:qiboteam/qibo into…
renatomello Feb 27, 2024
21908e3
fix tests
renatomello Feb 27, 2024
05bab4b
fix bug
renatomello Feb 27, 2024
cc3a33a
test
renatomello Feb 28, 2024
122a8df
fix test
renatomello Feb 28, 2024
a18e545
fix tests in doc
renatomello Feb 28, 2024
5fc1db6
fix coverage
renatomello Feb 28, 2024
c95b0bd
update poetry
renatomello Feb 28, 2024
84882a8
upper bound on tensorflow version
renatomello Feb 29, 2024
c99199f
Merge branch 'master' into composite_noise_model
renatomello Feb 29, 2024
aa8100a
fix merge issue
renatomello Feb 29, 2024
b250fe7
fix test and reduce runtime of another test
renatomello Feb 29, 2024
404407f
fix test seed
renatomello Feb 29, 2024
b23eb69
test omission
renatomello Feb 29, 2024
3bcec1b
Merge branch 'master' into composite_noise_model
renatomello Feb 29, 2024
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
18 changes: 11 additions & 7 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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there might be a typo here in "reported noise model of for its quantum computer".

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