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:
error – quantum error to associate with the gate. Possible choices are
qibo.noise.PauliError,qibo.noise.DepolarizingError,qibo.noise.ThermalRelaxationError,qibo.noise.AmplitudeDampingError,qibo.noise.PhaseDampingError,qibo.noise.ReadoutError,qibo.noise.ResetError,qibo.noise.UnitaryError,qibo.noise.KrausError, andqibo.noise.CustomError.gate (
qibo.gates.Gate, optional) – gate after which the noise will be added. IfNone, the noise will be added after each gate exceptqibo.gates.Channelandqibo.gates.M.qubits (int or tuple, optional) – qubits where the noise will be applied. If
None, the noise will be added after every instance of the gate. Defaults toNone.condition (callable, optional) – function that takes
qibo.gates.Gateobject as an input and returnsTrueif noise should be added to it.
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:
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.ndarrayortf.Tensorand of the same shape.
- class qibo.noise.UnitaryError(probabilities, unitaries)[source]#
Quantum error associated with the
qibo.gates.UnitaryChannel.- Parameters:
- class qibo.noise.PauliError(operators)[source]#
Quantum error associated with the
qibo.gates.PauliNoiseChannel.- Parameters:
operators (list) – see
qibo.gates.PauliNoiseChannel
- 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.DepolarizingChannelfollowed by aqibo.gates.ThermalRelaxationChannelafter each one- or two-qubit gate in the circuit. It also applies single-qubitqibo.gates.ReadoutErrorChannelbefore 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
parametersas inside dictionary.- Parameters:
parameters (dict) –
Contains parameters necessary to initialise
qibo.noise.DepolarizingError,qibo.noise.ThermalRelaxationError, andqibo.noise.ReadoutError.The keys and values of the dictionary parameters are defined below:
"depolarizing_one_qubit"(int or float or dict): Ifintorfloat, all qubits share the same single-qubit depolarizing parameter. Ifdict, expects qubit indexes as keys and their respective depolarizing parameter as values. Seeqibo.gates.channels.DepolarizingChannelfor a detailed definition of depolarizing parameter.
"depolarizing_two_qubit"(int or float or dict): Ifintorfloat, all two-qubit gates share the same two-qubit depolarizing parameter regardless in which pair of qubits the two-qubit gate is acting on. Ifdict, 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. Seeqibo.gates.channels.DepolarizingChannelfor a detailed definition of depolarizing parameter.
"t1"(int or float or dict): Ifintorfloat, all qubitsshare the same
t1. Ifdict, expects qubit indexes as keys and its respectivet1as values. Seeqibo.gates.channels.ThermalRelaxationChannelfor a detailed definition oft1. Note thatt1andt2must be passed with the same type.
"t2"(int or float or dict): Ifintorfloat, all qubits sharethe same
t2. Ifdict, expects qubit indexes as keys and its respectivet2as values. Seeqibo.gates.channels.ThermalRelaxationChannelfor a detailed definition oft2. Note thatt2andt1must be passed with the same type.
"gate_times"(tuple or list): pair of gate times representinggate times for
ThermalRelaxationErrorfollowing, respectively, one- and two-qubit gates.
"excited_population"(int or float): SeeThermalRelaxationChannel.
"readout_one_qubit"(int or float or dict): Ifintorfloat,\(p(0|1) = p(1|0)\), and all qubits share the same readout error probabilities. If
dict, expects qubit indexes as keys and values astuple(orlist) in the format \((p(0|1),\,p(1|0))\). If values aretupleorlistof length 1 orfloatorint, then it is assumed that \(p(0|1) = p(1|0)\).