Noise#

In Qibo it is possible to create a custom noise model using the class qibo.noise.NoiseModel. This enables the user to create circuits where the noise is gate and qubit dependent.

For more information on the use of qibo.noise.NoiseModel see How to perform noisy simulation?

class qibo.noise.NoiseModel[source]#

Class for the implementation of a custom noise model.

Example:

from qibo import Circuit, gates
from qibo.noise import NoiseModel, PauliError

# Build specific noise model with 2 quantum errors:
# - Pauli error on H only for qubit 1.
# - Pauli error on CNOT for all the qubits.

noise_model = NoiseModel()
noise_model.add(PauliError([("X", 0.5)]), gates.H, 1)
noise_model.add(PauliError([("Y", 0.5)]), gates.CNOT)

# Generate noiseless circuit.
circuit = Circuit(2)
circuit.add([gates.H(0), gates.H(1), gates.CNOT(0, 1)])

# Apply noise to the circuit according to the noise model.
noisy_circuit = noise_model.apply(circuit)
add(error, gate=None, qubits=None, conditions=None)[source]#

Add a quantum error for a specific gate and qubit to the noise model.

Parameters:

Example:

import numpy as np
from qibo import Circuit, gates
from qibo.noise import NoiseModel, PauliError

# Check if a gate is RX(pi/2).
def is_sqrt_x(gate):
    return np.pi/2 in gate.parameters

# Build a noise model with a Pauli error on RX(pi/2) gates.
error = PauliError(list(zip(["X", "Y", "Z"], [0.01, 0.5, 0.1])))
noise = NoiseModel()
noise.add(PauliError([("X", 0.5)]), gates.RX, conditions=is_sqrt_x)

# Generate a noiseless circuit.
circuit = Circuit(1)
circuit.add(gates.RX(0, np.pi / 2))
circuit.add(gates.RX(0, 3 * np.pi / 2))
circuit.add(gates.X(0))

# Apply noise to the circuit.
noisy_circuit = noise.apply(circuit)
apply(circuit)[source]#

Generate a noisy quantum circuit according to the noise model built.

Parameters:

circuit (qibo.models.circuit.Circuit) – quantum circuit

Returns:

initial circuit with noise gates

added according to the noise model.

Return type:

qibo.models.circuit.Circuit

Quantum errors#

The quantum errors available to build a noise model are the following:

class qibo.noise.KrausError(ops)[source]#

Quantum error associated with the qibo.gates.KrausChannel.

Parameters:

ops (list) – List of Kraus operators of type np.ndarray or tf.Tensor and of the same shape.

channel(qubits, options)[source]#

Returns the quantum channel associated to the quantum error.

class qibo.noise.UnitaryError(probabilities, unitaries)[source]#

Quantum error associated with the qibo.gates.UnitaryChannel.

Parameters:
  • probabilities (list) – List of floats that correspond to the probability that each unitary Uk is applied.

  • unitaries (list) – List of unitary matrices as np.ndarray/tf.Tensor of the same shape. Must have the same length as the given probabilities p.

channel(qubits, options)[source]#

Returns the quantum channel associated to the quantum error.

class qibo.noise.PauliError(operators)[source]#

Quantum error associated with the qibo.gates.PauliNoiseChannel.

Parameters:

operators (list) – see qibo.gates.PauliNoiseChannel

channel(qubits, options)[source]#

Returns the quantum channel associated to the quantum error.

class qibo.noise.DepolarizingError(lam)[source]#

Quantum error associated with the qibo.gates.DepolarizingChannel.

Parameters:

options (float) – see qibo.gates.DepolarizingChannel

class qibo.noise.ThermalRelaxationError(t1, t2, time, excited_population=0)[source]#

Quantum error associated with the qibo.gates.ThermalRelaxationChannel.

Parameters:

options (tuple) – see qibo.gates.ThermalRelaxationChannel

class qibo.noise.AmplitudeDampingError(gamma)[source]#

Quantum error associated with the qibo.gates.AmplitudeDampingChannel.

Parameters:

options (float) – see qibo.gates.AmplitudeDampingChannel

class qibo.noise.PhaseDampingError(gamma)[source]#

Quantum error associated with the qibo.gates.PhaseDampingChannel.

Parameters:

options (float) – see qibo.gates.PhaseDampingChannel

class qibo.noise.ReadoutError(probabilities)[source]#

Quantum error associated with :class:’qibo.gates;ReadoutErrorChannel’.

Parameters:

options (array) – see :class:’qibo.gates.ReadoutErrorChannel’

class qibo.noise.ResetError(p0, p1)[source]#

Quantum error associated with the qibo.gates.ResetChannel.

Parameters:

options (tuple) – see qibo.gates.ResetChannel

class qibo.noise.CustomError(channel)[source]#

Quantum error associated with the qibo.gates.Channel

Parameters:

channel (qibo.gates.Channel) – any channel

Example:

import numpy as np
from qibo.gates import KrausChannel
from qibo.noise import CustomError

# define |0><0|
a1 = np.array([[1, 0], [0, 0]])
# define |0><1|
a2 = np.array([[0, 1], [0, 0]])

# Create an Error associated with Kraus Channel
# rho -> |0><0| rho |0><0| + |0><1| rho |0><1|
error = CustomError(gates.KrausChannel((0,), [a1, a2]))

IBMQ noise model#

In Qibo, it is possible to build noisy circuits based on IBMQ’s reported noise model of for its quantum computer by using the qibo.noise.IBMQNoiseModel class. The noise model is built using a combination of the qibo.gates.ThermalRelaxationChannel and qibo.gates.DepolarizingChannel 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 qibo.noise.IBMQNoiseModel class, see the example on Simulating quantum hardware.

class qibo.noise.IBMQNoiseModel[source]#

Class for the implementation of a IBMQ noise model.

This noise model applies a qibo.gates.DepolarizingChannel followed by a qibo.gates.ThermalRelaxationChannel after each one- or two-qubit gate in the circuit. It also applies single-qubit qibo.gates.ReadoutErrorChannel before every measurement gate.

Example:

from qibo import Circuit, gates
from qibo.models.encodings import phase_encoder
from qibo.noise import DepolarizingError, ThermalRelaxationError, ReadoutError
from qibo.noise import IBMQNoiseModel, NoiseModel

nqubits = 4

# creating circuit
phases = list(range(nqubits))
circuit = phase_encoder(nqubits, rotation="RY", data=phases)
circuit.add(gates.CNOT(qubit, qubit + 1) for qubit in range(nqubits - 1))
circuit.add(gates.M(qubit) for qubit in range(1, nqubits - 1))

# creating noise model from dictionary
parameters = {
    "depolarizing_one_qubit" : {"0": 0.1, "2": 0.04, "3": 0.15},
    "depolarizing_two_qubit": {"0-1": 0.2},
    "t1" : {"0": 0.1, "1": 0.2, "3": 0.01},
    "t2" : {"0": 0.01, "1": 0.02, "3": 0.0001},
    "gate_times" : (0.1, 0.2),
    "excited_population" : 0.1,
    "readout_one_qubit" : {"0": (0.1, 0.1), "1": 0.1, "3": [0.1, 0.1]},
    }

noise_model = IBMQNoiseModel()
noise_model.from_dict(parameters)
noisy_circuit = noise_model.apply(circuit)
from_dict(parameters)[source]#

Method used to pass noise parameters as inside dictionary.

Parameters:

parameters (dict) –

Contains parameters necessary to initialise qibo.noise.DepolarizingError, qibo.noise.ThermalRelaxationError, and qibo.noise.ReadoutError.

The keys and values of the dictionary parameters are defined below:

  • "depolarizing_one_qubit" (int or float or dict): If int or

    float, all qubits share the same single-qubit depolarizing parameter. If dict, expects qubit indexes as keys and their respective depolarizing parameter as values. See qibo.gates.channels.DepolarizingChannel for a detailed definition of depolarizing parameter.

  • "depolarizing_two_qubit" (int or float or dict): If int or

    float, all two-qubit gates share the same two-qubit depolarizing parameter regardless in which pair of qubits the two-qubit gate is acting on. If dict, expects pair qubit indexes as keys separated by a hiphen (e.g. “0-1” for gate that has “0” as control and “1” as target) and their respective depolarizing parameter as values. See qibo.gates.channels.DepolarizingChannel for a detailed definition of depolarizing parameter.

  • "t1" (int or float or dict): If int or float, all qubits

    share the same t1. If dict, expects qubit indexes as keys and its respective t1 as values. See qibo.gates.channels.ThermalRelaxationChannel for a detailed definition of t1. Note that t1 and t2 must be passed with the same type.

  • "t2" (int or float or dict): If int or float, all qubits share

    the same t2. If dict, expects qubit indexes as keys and its respective t2 as values. See qibo.gates.channels.ThermalRelaxationChannel for a detailed definition of t2. Note that t2 and t1 must be passed with the same type.

  • "gate_times" (tuple or list): pair of gate times representing

    gate times for ThermalRelaxationError following, respectively, one- and two-qubit gates.

  • "excited_population" (int or float): See

    ThermalRelaxationChannel.

  • "readout_one_qubit" (int or float or dict): If int or float,

    \(p(0|1) = p(1|0)\), and all qubits share the same readout error probabilities. If dict, expects qubit indexes as keys and values as tuple (or list) in the format \((p(0|1),\,p(1|0))\). If values are tuple or list of length 1 or float or int, then it is assumed that \(p(0|1) = p(1|0)\).