qibocal.protocols.randomized_benchmarking package#

Submodules#

qibocal.protocols.randomized_benchmarking.dict_utils module#

qibocal.protocols.randomized_benchmarking.dict_utils.find_cliffords(cz_list)[source]#

Splits a clifford (list of gates) into sublists based on the occurrence of the “CZ” gate.

qibocal.protocols.randomized_benchmarking.dict_utils.separator(clifford)[source]#

Separates values in the given clifford sublist based on certain conditions.

Returns:

A tuple containing three elements:
  • values_with_1 (str): A comma-separated string of values containing ‘1’.

  • values_with_2 (str): A comma-separated string of values containing ‘2’.

  • value_with_CZ (bool): True if ‘CZ’ is present in the clifford list, False otherwise.

Return type:

tuple

qibocal.protocols.randomized_benchmarking.dict_utils.clifford2gates(clifford)[source]#

Converts a Clifford string into a list of gates.

Parameters:

clifford (str) – A comma-separated string representing a sequence of gates that represent a Clifford gate.

qibocal.protocols.randomized_benchmarking.dict_utils.clifford_to_matrix(clifford)[source]#

Converts a Clifford gate as a string to its corresponding unitary matrix representation.

qibocal.protocols.randomized_benchmarking.dict_utils.generate_inv_dict_cliffords_file(two_qubit_cliffords, output_file=None)[source]#

Generate an inverse dictionary of Clifford matrices and save it to a npz file.

Parameters: two_qubit_cliffords (dict): A dictionary of two-qubit Cliffords. output_file (str): The path to the output npz file.

qibocal.protocols.randomized_benchmarking.dict_utils.clifford_to_pulses(clifford)[source]#

From a Clifford gate sequence into the number of pulses required to implement it.

Parameters:

clifford (str) – A comma-separated string representing the Clifford gate sequence.

Returns:

The number of pulses required to implement the given Clifford gate sequence.

Return type:

int

qibocal.protocols.randomized_benchmarking.dict_utils.calculate_pulses_clifford(cliffords)[source]#

Calculate the average number of pulses per Clifford operation.

Parameters: - cliffords (dict): A dictionary of Clifford operations.

Returns: - pulses_per_clifford (float): The average number of pulses per Clifford operation.

qibocal.protocols.randomized_benchmarking.dict_utils.load_inverse_cliffords(file_inv)[source]#
qibocal.protocols.randomized_benchmarking.dict_utils.load_cliffords(file_cliffords)[source]#

qibocal.protocols.randomized_benchmarking.filtered_rb module#

class qibocal.protocols.randomized_benchmarking.filtered_rb.FilteredRBParameters(depths: ~typing.Union[list, ~qibocal.protocols.randomized_benchmarking.standard_rb.Depthsdict], niter: int, uncertainties: ~typing.Optional[float] = None, unrolling: bool = False, seed: ~typing.Optional[int] = None, noise_model: ~typing.Optional[str] = None, noise_params: ~typing.Optional[list] = <factory>, nshots: int = 10)[source]#

Bases: StandardRBParameters

Filtered Randomized Benchmarking runcard inputs.

hardware_average: bool = False#

By default hardware average will be performed.

noise_model: Optional[str] = None#

For simulation purposes, string has to match what is in qibocal.protocols.randomized_benchmarking.noisemodels

nshots: int = 10#

Just to add the default value.

seed: Optional[int] = None#

A fixed seed to initialize np.random.Generator.

If None, uses a random seed. Defaults is None.

uncertainties: Optional[float] = None#

Method of computing the error bars of the signal and uncertainties of the fit.

If None, it computes the standard deviation. Otherwise it computes the corresponding confidence interval. Defaults None.

unrolling: bool = False#

If True it uses sequence unrolling to deploy multiple circuits in a single instrument call.

Defaults to False.

depths: Union[list, Depthsdict]#

A list of depths/sequence lengths.

If a dictionary is given the list will be build.

niter: int#

Sets how many iterations over the same depth value.

noise_params: Optional[list]#

With this the noise model will be initialized, if not given random values will be used.

relaxation_time: float#

Wait time for the qubit to decohere back to the gnd state.

class qibocal.protocols.randomized_benchmarking.filtered_rb.FilteredRBResult[source]#

Bases: Results

Filtered RB outputs.

_to_json(path: Path, filename: str)#

Helper function to dump to json.

_to_npz(path: Path, filename: str)#

Helper function to use np.savez while converting keys into strings.

static load_data(path: Path, filename: str)#

Load data stored in a npz file.

static load_params(path: Path, filename: str)#

Load parameters stored in a json file.

property params: dict#

Convert non-arrays attributes into dict.

save(path: Path)#

Store results to file.

qibocal.protocols.randomized_benchmarking.filtered_rb._acquisition(params: FilteredRBParameters, platform: Platform, targets: list[Union[str, int]]) RBData[source]#

The data acquisition stage of Filtered Randomized Benchmarking.

  1. Set up the scan

  2. Execute the scan

  3. Post process the data and initialize a filtered rb data object with it.

Parameters:
  • params – All parameters in one object.

  • platform – Platform the experiment is executed on.

  • target – list of qubits the experiment is executed on.

Returns:

The depths, samples and ground state probability of each experiment in the scan.

Return type:

RBData

qibocal.protocols.randomized_benchmarking.filtered_rb._fit(data: RBData) FilteredRBResult[source]#

Takes a data frame, extracts the depths and the signal and fits it with an exponential function y = Ap^x+B.

Parameters:

data (RBData) – Data from the data acquisition stage.

Returns:

Aggregated and processed data.

Return type:

FilteredRBResult

qibocal.protocols.randomized_benchmarking.filtered_rb._plot(data: RBData, fit: FilteredRBResult, target: Union[str, int]) tuple[list[plotly.graph_objs._figure.Figure], str][source]#

Builds the table for the qq pipe, calls the plot function of the result object and returns the figure es list.

Parameters:
  • data (RBData) – Data object used for the table.

  • fit (FilteredRBResult) – Is called for the plot.

  • target (_type_) – Not used yet.

Return type:

tuple[list[go.Figure], str]

qibocal.protocols.randomized_benchmarking.fitting module#

In this python script the fitting methods for the gate set protocols are defined. They consist mostly of exponential decay fitting.

qibocal.protocols.randomized_benchmarking.fitting.exp1_func(x: ndarray, A: float, f: float) ndarray[source]#

Return \(A\cdot f^x\) where x is an np.ndarray and A, f are floats

qibocal.protocols.randomized_benchmarking.fitting.exp1B_func(x: ndarray, A: float, f: float, B: float) ndarray[source]#

Return \(A\cdot f^x+B\) where x is an np.ndarray and A, f, B are floats

qibocal.protocols.randomized_benchmarking.fitting.exp2_func(x: ndarray, A1: float, A2: float, f1: float, f2: float) ndarray[source]#

Return \(A_1\cdot f_1^x+A_2\cdot f_2^x\) where x is an np.ndarray and A1, f1, A2, f2 are floats. There is no linear offsett B.

qibocal.protocols.randomized_benchmarking.fitting.esprit(xdata: ndarray, ydata: ndarray, num_decays: int, hankel_dim: Optional[int] = None) ndarray[source]#

Implements the ESPRIT algorithm for peak detection.

Parameters:
  • xdata (np.ndarray) – Labels of data. Has to be equally spaced.

  • ydata (np.ndarray) – The data where multiple decays are fitted in.

  • num_decays (int) – How many decays should be fitted.

  • hankel_dim (int | None, optional) – The Hankel dimension. Defaults to None.

Returns:

The decay parameters.

Return type:

np.ndarray

Raises:

ValueError – When the x-labels are not equally spaced the algorithm does not work.

qibocal.protocols.randomized_benchmarking.fitting.fit_exp1B_func(xdata: Union[ndarray, list], ydata: Union[ndarray, list], **kwargs) tuple[tuple, tuple][source]#

Calculate an single exponential A*p^m+B fit to the given ydata.

Parameters:
  • xdata (Union[np.ndarray, list]) – The x-labels.

  • ydata (Union[np.ndarray, list]) – The data to be fitted.

Returns:

The fitting parameters (A, p, B) and the estimated error

(A_err, p_err, B_err)

Return type:

tuple[tuple, tuple]

qibocal.protocols.randomized_benchmarking.fitting.fit_exp1_func(xdata: Union[ndarray, list], ydata: Union[ndarray, list], **kwargs) tuple[tuple, tuple][source]#

Calculate an single exponential A*p^m fit to the given ydata, no linear offset.

Parameters:
  • xdata (Union[np.ndarray, list]) – The x-labels.

  • ydata (Union[np.ndarray, list]) – The data to be fitted.

Returns:

The fitting parameters (A, p) and the estimated error (A_err, p_err).

Return type:

tuple[tuple, tuple]

qibocal.protocols.randomized_benchmarking.fitting.fit_expn_func(xdata: Union[ndarray, list], ydata: Union[ndarray, list], n: int = 2) tuple[tuple, tuple][source]#

Calculate n exponentials on top of each other, fit to the given ydata. No linear offset, the ESPRIT algorithm is used to identify n exponential decays.

Parameters:
  • xdata (Union[np.ndarray, list]) – The x-labels.

  • ydata (Union[np.ndarray, list]) – The data to be fitted.

  • n (int) – number of decays to fit. Default is 2.

Returns:

(A1, …, An, f1, …, fn) with f* the decay parameters.

Return type:

tuple[tuple, tuple]

qibocal.protocols.randomized_benchmarking.fitting.fit_exp2_func(xdata: Union[ndarray, list], ydata: Union[ndarray, list]) tuple[tuple, tuple][source]#

Calculate 2 exponentials on top of each other, fit to the given ydata.

No linear offset, the ESPRIT algorithm is used to identify the two exponential decays.

Parameters:
  • xdata (Union[np.ndarray, list]) – The x-labels.

  • ydata (Union[np.ndarray, list]) – The data to be fitted

Returns:

(A1, A2, f1, f2) with f* the decay parameters.

Return type:

tuple[tuple, tuple]

qibocal.protocols.randomized_benchmarking.noisemodels module#

Custom error models are build here for making it possible to pass strings describing the error model via runcards in qibocal. They inherit from the qibo noise NoiseModel module and are prebuild.

class qibocal.protocols.randomized_benchmarking.noisemodels.PauliErrorOnAll(probabilities: Optional[list] = None)[source]#

Bases: NoiseModel

Builds a noise model with pauli flips acting on all gates in a Circuit. If no initial parameters for px, py, pz are given, random values are drawn (in sum not bigger than 1).

build()[source]#
add(error, gate: Optional[Gate] = None, qubits: Optional[Union[int, tuple]] = None, conditions=None)#

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, and qibo.noise.CustomError.

  • gate (qibo.gates.Gate, optional) – gate after which the noise will be added. If None, the noise will be added after each gate except qibo.gates.Channel and qibo.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 to None.

  • condition (callable, optional) – function that takes qibo.gates.Gate object as an input and returns True if 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)#

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

class qibocal.protocols.randomized_benchmarking.noisemodels.PauliErrorOnX(probabilities: Optional[list] = None)[source]#

Bases: PauliErrorOnAll

Builds a noise model with pauli flips acting on X gates. Inherited from PauliErrorOnAll but the build method is overwritten to act on X gates. If no initial parameters for px, py, pz are given, random values are drawn (in sum not bigger than 1).

add(error, gate: Optional[Gate] = None, qubits: Optional[Union[int, tuple]] = None, conditions=None)#

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, and qibo.noise.CustomError.

  • gate (qibo.gates.Gate, optional) – gate after which the noise will be added. If None, the noise will be added after each gate except qibo.gates.Channel and qibo.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 to None.

  • condition (callable, optional) – function that takes qibo.gates.Gate object as an input and returns True if 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)#

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

build()[source]#

qibocal.protocols.randomized_benchmarking.standard_rb module#

class qibocal.protocols.randomized_benchmarking.standard_rb.Depthsdict[source]#

Bases: TypedDict

Dictionary used to build a list of depths as range(start, stop, step).

start: int#
stop: int#
step: int#
clear() None.  Remove all items from D.#
copy() a shallow copy of D#
fromkeys(value=None, /)#

Create a new dictionary with keys from iterable and values set to value.

get(key, default=None, /)#

Return the value for key if key is in the dictionary, else default.

items() a set-like object providing a view on D's items#
keys() a set-like object providing a view on D's keys#
pop(k[, d]) v, remove specified key and return the corresponding value.#

If the key is not found, return the default if given; otherwise, raise a KeyError.

popitem()#

Remove and return a (key, value) pair as a 2-tuple.

Pairs are returned in LIFO (last-in, first-out) order. Raises KeyError if the dict is empty.

setdefault(key, default=None, /)#

Insert key with a value of default if key is not in the dictionary.

Return the value for key if key is in the dictionary, else default.

update([E, ]**F) None.  Update D from dict/iterable E and F.#

If E is present and has a .keys() method, then does: for k in E: D[k] = E[k] If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v In either case, this is followed by: for k in F: D[k] = F[k]

values() an object providing a view on D's values#
class qibocal.protocols.randomized_benchmarking.standard_rb.StandardRBParameters(depths: ~typing.Union[list, ~qibocal.protocols.randomized_benchmarking.standard_rb.Depthsdict], niter: int, uncertainties: ~typing.Optional[float] = None, unrolling: bool = False, seed: ~typing.Optional[int] = None, noise_model: ~typing.Optional[str] = None, noise_params: ~typing.Optional[list] = <factory>, nshots: int = 10)[source]#

Bases: Parameters

Standard Randomized Benchmarking runcard inputs.

depths: Union[list, Depthsdict]#

A list of depths/sequence lengths.

If a dictionary is given the list will be build.

niter: int#

Sets how many iterations over the same depth value.

uncertainties: Optional[float] = None#

Method of computing the error bars of the signal and uncertainties of the fit.

If None, it computes the standard deviation. Otherwise it computes the corresponding confidence interval. Defaults None.

unrolling: bool = False#

If True it uses sequence unrolling to deploy multiple circuits in a single instrument call.

Defaults to False.

seed: Optional[int] = None#

A fixed seed to initialize np.random.Generator.

If None, uses a random seed. Defaults is None.

noise_model: Optional[str] = None#

For simulation purposes, string has to match what is in qibocal.protocols.randomized_benchmarking.noisemodels

hardware_average: bool = False#

By default hardware average will be performed.

noise_params: Optional[list]#

With this the noise model will be initialized, if not given random values will be used.

relaxation_time: float#

Wait time for the qubit to decohere back to the gnd state.

nshots: int = 10#

Just to add the default value.

qibocal.protocols.randomized_benchmarking.standard_rb._acquisition(params: StandardRBParameters, platform: Platform, targets: list[Union[str, int]]) RBData[source]#

The data acquisition stage of Standard Randomized Benchmarking.

  1. Set up the scan

  2. Execute the scan

  3. Post process the data and initialize a standard rb data object with it.

Parameters:
  • params – All parameters in one object.

  • platform – Platform the experiment is executed on.

  • target – list of qubits the experiment is executed on.

Returns:

The depths, samples and ground state probability of each experiment in the scan.

Return type:

RBData

qibocal.protocols.randomized_benchmarking.standard_rb._fit(data: RBData) StandardRBResult[source]#

Takes a data frame, extracts the depths and the signal and fits it with an exponential function y = Ap^x+B.

Parameters:

data (RBData) – Data from the data acquisition stage.

Returns:

Aggregated and processed data.

Return type:

StandardRBResult

qibocal.protocols.randomized_benchmarking.standard_rb._plot(data: RBData, fit: StandardRBResult, target: Union[str, int]) tuple[list[plotly.graph_objs._figure.Figure], str][source]#

Builds the table for the qq pipe, calls the plot function of the result object and returns the figure es list.

Parameters:
  • data (RBData) – Data object used for the table.

  • fit (StandardRBResult) – Is called for the plot.

  • target (_type_) – Not used yet.

Return type:

tuple[list[go.Figure], str]

qibocal.protocols.randomized_benchmarking.standard_rb_2q module#

class qibocal.protocols.randomized_benchmarking.standard_rb_2q.StandardRB2QParameters(depths: ~typing.Union[list, ~qibocal.protocols.randomized_benchmarking.standard_rb.Depthsdict], niter: int, uncertainties: ~typing.Optional[float] = None, unrolling: bool = False, seed: ~typing.Optional[int] = None, noise_model: ~typing.Optional[str] = None, noise_params: ~typing.Optional[list] = <factory>, nshots: int = 10, file: str = '2qubitCliffs.json', file_inv: str = '2qubitCliffsInv.npz')[source]#

Bases: StandardRBParameters

Parameters for the standard 2q randomized benchmarking protocol.

file: str = '2qubitCliffs.json'#

File with the cliffords to be used.

file_inv: str = '2qubitCliffsInv.npz'#

File with the cliffords to be used in an inverted dict.

hardware_average: bool = False#

By default hardware average will be performed.

noise_model: Optional[str] = None#

For simulation purposes, string has to match what is in qibocal.protocols.randomized_benchmarking.noisemodels

nshots: int = 10#

Just to add the default value.

seed: Optional[int] = None#

A fixed seed to initialize np.random.Generator.

If None, uses a random seed. Defaults is None.

uncertainties: Optional[float] = None#

Method of computing the error bars of the signal and uncertainties of the fit.

If None, it computes the standard deviation. Otherwise it computes the corresponding confidence interval. Defaults None.

unrolling: bool = False#

If True it uses sequence unrolling to deploy multiple circuits in a single instrument call.

Defaults to False.

depths: Union[list, Depthsdict]#

A list of depths/sequence lengths.

If a dictionary is given the list will be build.

niter: int#

Sets how many iterations over the same depth value.

noise_params: Optional[list]#

With this the noise model will be initialized, if not given random values will be used.

relaxation_time: float#

Wait time for the qubit to decohere back to the gnd state.

qibocal.protocols.randomized_benchmarking.standard_rb_2q._acquisition(params: StandardRB2QParameters, platform: Platform, targets: list[Tuple[Union[str, int], Union[str, int]]]) RB2QData[source]#

Data acquisition for two qubit Standard Randomized Benchmarking.

qibocal.protocols.randomized_benchmarking.standard_rb_2q._fit(data: RB2QData) StandardRBResult[source]#

qibocal.protocols.randomized_benchmarking.standard_rb_2q_inter module#

class qibocal.protocols.randomized_benchmarking.standard_rb_2q_inter.StandardRB2QInterParameters(depths: ~typing.Union[list, ~qibocal.protocols.randomized_benchmarking.standard_rb.Depthsdict], niter: int, uncertainties: ~typing.Optional[float] = None, unrolling: bool = False, seed: ~typing.Optional[int] = None, noise_model: ~typing.Optional[str] = None, noise_params: ~typing.Optional[list] = <factory>, nshots: int = 10, file: str = '2qubitCliffs.json', file_inv: str = '2qubitCliffsInv.npz', interleave: str = 'CZ')[source]#

Bases: StandardRB2QParameters

Parameters for the standard 2q randomized benchmarking protocol.

interleave: str = 'CZ'#

Gate to interleave

file: str = '2qubitCliffs.json'#

File with the cliffords to be used.

file_inv: str = '2qubitCliffsInv.npz'#

File with the cliffords to be used in an inverted dict.

hardware_average: bool = False#

By default hardware average will be performed.

noise_model: Optional[str] = None#

For simulation purposes, string has to match what is in qibocal.protocols.randomized_benchmarking.noisemodels

nshots: int = 10#

Just to add the default value.

seed: Optional[int] = None#

A fixed seed to initialize np.random.Generator.

If None, uses a random seed. Defaults is None.

uncertainties: Optional[float] = None#

Method of computing the error bars of the signal and uncertainties of the fit.

If None, it computes the standard deviation. Otherwise it computes the corresponding confidence interval. Defaults None.

unrolling: bool = False#

If True it uses sequence unrolling to deploy multiple circuits in a single instrument call.

Defaults to False.

depths: Union[list, Depthsdict]#

A list of depths/sequence lengths.

If a dictionary is given the list will be build.

niter: int#

Sets how many iterations over the same depth value.

noise_params: Optional[list]#

With this the noise model will be initialized, if not given random values will be used.

relaxation_time: float#

Wait time for the qubit to decohere back to the gnd state.

class qibocal.protocols.randomized_benchmarking.standard_rb_2q_inter.StandardRB2QInterResult(fidelity: dict[typing.Union[str, int], float], pulse_fidelity: dict[typing.Union[str, int], float], fit_parameters: dict[typing.Union[str, int], list[float]], fit_uncertainties: dict[typing.Union[str, int], list[float]], error_bars: dict[typing.Union[str, int], typing.Union[float, list[float], NoneType]] = <factory>, fidelity_cz: ~typing.Optional[dict[typing.Tuple[typing.Union[str, int], typing.Union[str, int]], list]] = None)[source]#

Bases: StandardRBResult

Standard RB outputs.

fidelity_cz: dict[Tuple[Union[str, int], Union[str, int]], list] = None#

The overall fidelity for the CZ gate and its uncertainty.

_to_json(path: Path, filename: str)#

Helper function to dump to json.

_to_npz(path: Path, filename: str)#

Helper function to use np.savez while converting keys into strings.

static load_data(path: Path, filename: str)#

Load data stored in a npz file.

static load_params(path: Path, filename: str)#

Load parameters stored in a json file.

property params: dict#

Convert non-arrays attributes into dict.

save(path: Path)#

Store results to file.

fidelity: dict[QubitId, float]#

The overall fidelity of this qubit.

pulse_fidelity: dict[QubitId, float]#

The pulse fidelity of the gates acting on this qubit.

fit_parameters: dict[QubitId, list[float]]#

Raw fitting parameters.

fit_uncertainties: dict[QubitId, list[float]]#

Fitting parameters uncertainties.

error_bars: dict[QubitId, Optional[Union[float, list[float]]]]#

Error bars for y.

qibocal.protocols.randomized_benchmarking.standard_rb_2q_inter._acquisition(params: StandardRB2QInterParameters, platform: Platform, targets: list[Tuple[Union[str, int], Union[str, int]]]) RB2QInterData[source]#

Data acquisition for two qubit Interleaved Randomized Benchmarking.

qibocal.protocols.randomized_benchmarking.standard_rb_2q_inter._fit(data: RB2QInterData) StandardRB2QInterResult[source]#

Takes a data frame, extracts the depths and the signal and fits it with an exponential function y = Ap^x+B.

Parameters:

data – Data from the data acquisition stage.

Returns:

Aggregated and processed data.

Return type:

StandardRB2QInterResult

qibocal.protocols.randomized_benchmarking.utils module#

qibocal.protocols.randomized_benchmarking.utils.NPULSES_PER_CLIFFORD = 1.875#

Global phases that could appear in the Clifford group we defined in the “2q_cliffords.json” file due to the gates we selected to generate the Clifford group.

qibocal.protocols.randomized_benchmarking.utils.RBType = dtype([('samples', '<i4')])#

Custom dtype for RB.

qibocal.protocols.randomized_benchmarking.utils.random_clifford(random_index_gen)[source]#

Generates random Clifford operator.

qibocal.protocols.randomized_benchmarking.utils.random_2q_clifford(random_index_gen, two_qubit_cliffords)[source]#

Generates random two qubit Clifford operator.

qibocal.protocols.randomized_benchmarking.utils.random_circuits(depth: int, targets: list[Union[str, int, Tuple[Union[str, int], Union[str, int]]]], niter, rb_gen, noise_model=None, inverse_layer=True, single_qubit=True, file_inv=PosixPath('.'), interleave=None) Iterable[source]#

Returns random (self-inverting) Clifford circuits.

qibocal.protocols.randomized_benchmarking.utils.number_to_str(value: Number, uncertainty: Optional[Union[Number, list, tuple, ndarray]] = None, precision: Optional[int] = None)[source]#

Converts a number into a string.

Parameters:
  • value (Number) – the number to display

  • uncertainty (Number or list or tuple or np.ndarray, optional) – number or 2-element interval with the low and high uncertainties of value. Defaults to None.

  • precision (int, optional) – nonnegative number of floating points of the displayed value. If None, defaults to the second significant digit of uncertainty or 3 if uncertainty is None. Defaults to None.

Returns:

The number expressed as a string, with the uncertainty if given.

Return type:

str

qibocal.protocols.randomized_benchmarking.utils.data_uncertainties(data, method=None, data_median=None, homogeneous=True)[source]#

Compute the uncertainties of the median (or specified) values.

Parameters:
  • data (list or np.ndarray) – 2d array with rows containing data points from which the median value is extracted.

  • method (float, optional) – method of computing the method. If it is None, computes the standard deviation, otherwise it computes the corresponding confidence interval using np.percentile. Defaults to None.

  • data_median (list or np.ndarray, optional) – 1d array for computing the errors from the confidence interval. If None, the median values are computed from data.

  • homogeneous (bool) – if True, assumes that all rows in data are of the same size and returns np.ndarray. Default is True.

Returns:

uncertainties of the data.

Return type:

np.ndarray

class qibocal.protocols.randomized_benchmarking.utils.RB_Generator(seed, file=None)[source]#

Bases: object

This class generates random two qubit cliffords for randomized benchmarking.

random_index(gate_dict)[source]#

Generates a random index within the range of the given file len.

layer_gen_single_qubit()[source]#

Generates a random single-qubit clifford gate.

layer_gen_two_qubit()[source]#

Generates a random two-qubit clifford gate.

calculate_average_pulses()[source]#

Average number of pulses per clifford.

class qibocal.protocols.randomized_benchmarking.utils.RBData(depths: list, uncertainties: ~typing.Optional[float], seed: ~typing.Optional[int], nshots: int, niter: int, data: dict[typing.Union[str, int, typing.Tuple[typing.Union[str, int], typing.Union[str, int]]], numpy.ndarray[typing.Any, numpy.dtype[dtype([('samples', '<i4')])]]] = <factory>, circuits: dict[typing.Union[str, int, typing.Tuple[typing.Union[str, int], typing.Union[str, int]]], list[list[int]]] = <factory>, npulses_per_clifford: float = 1.875)[source]#

Bases: Data

The output of the acquisition function.

depths: list#

Circuits depths.

uncertainties: Optional[float]#

Parameters uncertainties.

seed: Optional[int]#
nshots: int#

Number of shots.

niter: int#

Number of iterations for each depth.

data: dict[typing.Union[str, int, typing.Tuple[typing.Union[str, int], typing.Union[str, int]]], numpy.ndarray[typing.Any, numpy.dtype[dtype([('samples', '<i4')])]]]#

Raw data acquired.

circuits: dict[Union[str, int, Tuple[Union[str, int], Union[str, int]]], list[list[int]]]#

Clifford gate indexes executed.

npulses_per_clifford: float = 1.875#

Number of pulses for an average clifford.

extract_probabilities(qubit)[source]#

Extract the probabilities given qubit

_to_json(path: Path, filename: str)#

Helper function to dump to json.

_to_npz(path: Path, filename: str)#

Helper function to use np.savez while converting keys into strings.

static load_data(path: Path, filename: str)#

Load data stored in a npz file.

static load_params(path: Path, filename: str)#

Load parameters stored in a json file.

property pairs#

Access qubit pairs ordered alphanumerically from data structure.

property params: dict#

Convert non-arrays attributes into dict.

property qubits#

Access qubits from data structure.

register_qubit(dtype, data_keys, data_dict)#

Store output for single qubit.

Parameters:
  • data_keys (tuple) – Keys of Data.data.

  • data_dict (dict) – The keys are the fields of dtype and

  • arrays. (the values are the related) –

save(path: Path)#

Store data to file.

class qibocal.protocols.randomized_benchmarking.utils.RB2QData(depths: list, uncertainties: ~typing.Optional[float], seed: ~typing.Optional[int], nshots: int, niter: int, data: dict[typing.Union[str, int, typing.Tuple[typing.Union[str, int], typing.Union[str, int]]], numpy.ndarray[typing.Any, numpy.dtype[dtype([('samples', '<i4')])]]] = <factory>, circuits: dict[typing.Union[str, int, typing.Tuple[typing.Union[str, int], typing.Union[str, int]]], list[list[int]]] = <factory>, npulses_per_clifford: float = 8.6)[source]#

Bases: RBData

The output of the acquisition function.

npulses_per_clifford: float = 8.6#

Number of pulses for an average clifford.

extract_probabilities(qubits)[source]#

Extract the probabilities given (qubit, qubit)

_to_json(path: Path, filename: str)#

Helper function to dump to json.

_to_npz(path: Path, filename: str)#

Helper function to use np.savez while converting keys into strings.

static load_data(path: Path, filename: str)#

Load data stored in a npz file.

static load_params(path: Path, filename: str)#

Load parameters stored in a json file.

property pairs#

Access qubit pairs ordered alphanumerically from data structure.

property params: dict#

Convert non-arrays attributes into dict.

property qubits#

Access qubits from data structure.

register_qubit(dtype, data_keys, data_dict)#

Store output for single qubit.

Parameters:
  • data_keys (tuple) – Keys of Data.data.

  • data_dict (dict) – The keys are the fields of dtype and

  • arrays. (the values are the related) –

save(path: Path)#

Store data to file.

depths: list#

Circuits depths.

uncertainties: Optional[float]#

Parameters uncertainties.

seed: Optional[int]#
nshots: int#

Number of shots.

niter: int#

Number of iterations for each depth.

data: dict[typing.Union[str, int, typing.Tuple[typing.Union[str, int], typing.Union[str, int]]], numpy.ndarray[typing.Any, numpy.dtype[dtype([('samples', '<i4')])]]]#

Raw data acquired.

circuits: dict[Union[str, int, Tuple[Union[str, int], Union[str, int]]], list[list[int]]]#

Clifford gate indexes executed.

class qibocal.protocols.randomized_benchmarking.utils.RB2QInterData(depths: list, uncertainties: ~typing.Optional[float], seed: ~typing.Optional[int], nshots: int, niter: int, data: dict[typing.Union[str, int, typing.Tuple[typing.Union[str, int], typing.Union[str, int]]], numpy.ndarray[typing.Any, numpy.dtype[dtype([('samples', '<i4')])]]] = <factory>, circuits: dict[typing.Union[str, int, typing.Tuple[typing.Union[str, int], typing.Union[str, int]]], list[list[int]]] = <factory>, npulses_per_clifford: float = 8.6, fidelity: dict[typing.Tuple[typing.Union[str, int], typing.Union[str, int]], list] = <factory>)[source]#

Bases: RB2QData

The output of the acquisition function.

fidelity: dict[Tuple[Union[str, int], Union[str, int]], list]#

The interleaved fidelity of this qubit.

_to_json(path: Path, filename: str)#

Helper function to dump to json.

_to_npz(path: Path, filename: str)#

Helper function to use np.savez while converting keys into strings.

extract_probabilities(qubits)#

Extract the probabilities given (qubit, qubit)

static load_data(path: Path, filename: str)#

Load data stored in a npz file.

static load_params(path: Path, filename: str)#

Load parameters stored in a json file.

npulses_per_clifford: float = 8.6#

Number of pulses for an average clifford.

property pairs#

Access qubit pairs ordered alphanumerically from data structure.

property params: dict#

Convert non-arrays attributes into dict.

property qubits#

Access qubits from data structure.

register_qubit(dtype, data_keys, data_dict)#

Store output for single qubit.

Parameters:
  • data_keys (tuple) – Keys of Data.data.

  • data_dict (dict) – The keys are the fields of dtype and

  • arrays. (the values are the related) –

save(path: Path)#

Store data to file.

depths: list#

Circuits depths.

uncertainties: Optional[float]#

Parameters uncertainties.

seed: Optional[int]#
nshots: int#

Number of shots.

niter: int#

Number of iterations for each depth.

data: dict[typing.Union[str, int, typing.Tuple[typing.Union[str, int], typing.Union[str, int]]], numpy.ndarray[typing.Any, numpy.dtype[dtype([('samples', '<i4')])]]]#

Raw data acquired.

circuits: dict[Union[str, int, Tuple[Union[str, int], Union[str, int]]], list[list[int]]]#

Clifford gate indexes executed.

class qibocal.protocols.randomized_benchmarking.utils.StandardRBResult(fidelity: dict[typing.Union[str, int], float], pulse_fidelity: dict[typing.Union[str, int], float], fit_parameters: dict[typing.Union[str, int], list[float]], fit_uncertainties: dict[typing.Union[str, int], list[float]], error_bars: dict[typing.Union[str, int], typing.Union[float, list[float], NoneType]] = <factory>)[source]#

Bases: Results

Standard RB outputs.

fidelity: dict[Union[str, int], float]#

The overall fidelity of this qubit.

_to_json(path: Path, filename: str)#

Helper function to dump to json.

_to_npz(path: Path, filename: str)#

Helper function to use np.savez while converting keys into strings.

static load_data(path: Path, filename: str)#

Load data stored in a npz file.

static load_params(path: Path, filename: str)#

Load parameters stored in a json file.

property params: dict#

Convert non-arrays attributes into dict.

save(path: Path)#

Store results to file.

pulse_fidelity: dict[Union[str, int], float]#

The pulse fidelity of the gates acting on this qubit.

fit_parameters: dict[Union[str, int], list[float]]#

Raw fitting parameters.

fit_uncertainties: dict[Union[str, int], list[float]]#

Fitting parameters uncertainties.

error_bars: dict[Union[str, int], Union[float, list[float], NoneType]]#

Error bars for y.

qibocal.protocols.randomized_benchmarking.utils.setup(params: Parameters, platform: Platform, single_qubit: bool = True, interleave: Optional[str] = None)[source]#

Set up the randomized benchmarking experiment backend, noise model and data class.

Parameters:
  • params (Parameters) – The parameters for the experiment.

  • single_qubit (bool, optional) – Flag indicating whether the experiment is for a single qubit or two qubits. Defaults to True.

  • interleave – (str, optional): The type of interleaving to apply. Defaults to None.

Returns:

A tuple containing the experiment data, noise model, and backend.

Return type:

tuple

qibocal.protocols.randomized_benchmarking.utils.get_circuits(params, targets, add_inverse_layer, interleave, noise_model, single_qubit=True)[source]#

Generate randomized benchmarking circuits.

Parameters:
  • params (Parameters) – Experiment parameters.

  • targets (list) – List of target qubit IDs.

  • add_inverse_layer (bool) – Flag indicating whether to add an inverse layer to the circuits.

  • interleave (str) – String indicating whether to interleave the circuits with the given gate.

  • noise_model (str) – Noise model string.

  • single_qubit (bool, optional) – Flag indicating whether to generate single qubit circuits.

Returns:

A tuple containing the generated circuits, indexes, and the number of pulses per Clifford.
  • circuits (list): List of generated circuits.

  • indexes (dict): Dictionary containing the random indexes for each qubit and depth.

  • npulses_per_clifford (float): Number of pulses per Clifford.

Return type:

tuple

qibocal.protocols.randomized_benchmarking.utils.execute_circuits(circuits, targets, params, backend, single_qubit=True)[source]#

Executes a list of circuits on a given backend.

Parameters:
  • circuits (list) – List of quantum circuits to be executed.

  • targets (list) – List of target qubits for each circuit.

  • params (Parameters) – Experiment parameters.

  • backend (object) – Backend to execute the circuits on.

  • single_qubit (bool) – Flag indicating whether the circuits are single-qubit or multi-qubit.

Returns:

List of executed circuits.

Return type:

list

qibocal.protocols.randomized_benchmarking.utils.rb_acquisition(params: Parameters, platform: Platform, targets: list[Union[str, int]], add_inverse_layer: bool = True, interleave: Optional[str] = None) RBData[source]#

RB data acquisition function.

This function performs data acquisition for randomized benchmarking experiments.

Parameters:
  • params (RBParameters) – All parameters in one object.

  • targets (dict[int, Union[str, int]] or list[Union[str, int]]) – List of qubits the experiment is executed on.

  • add_inverse_layer (bool, optional) – Whether to add an inverse layer to the circuits. Defaults to True.

  • interleave (str, optional) – Interleaving pattern for the circuits. Defaults to None.

Returns:

The depths, samples, and ground state probability of each experiment in the scan.

Return type:

RBData

qibocal.protocols.randomized_benchmarking.utils.twoq_rb_acquisition(params: Parameters, platform: Platform, targets: list[Tuple[Union[str, int], Union[str, int]]], add_inverse_layer: bool = True, interleave: Optional[str] = None) Union[RB2QData, RB2QInterData][source]#

The data acquisition stage of two qubit Standard Randomized Benchmarking.

Parameters:
  • params (RB2QParameters) – The parameters for the randomized benchmarking experiment.

  • targets (list[QubitPairId]) – The list of qubit pair IDs on which to perform the benchmarking.

  • add_inverse_layer (bool, optional) – Whether to add an inverse layer to the circuits. Defaults to True.

  • interleave (str, optional) – The type of interleaving to apply. Defaults to None.

Returns:

The acquired data for two qubit randomized benchmarking.

Return type:

RB2QData

qibocal.protocols.randomized_benchmarking.utils.layer_circuit(rb_gen: Callable, depth: int, target, interleave: Optional[str] = None) tuple[qibo.models.circuit.Circuit, list][source]#

Creates a circuit of depth layers from a generator layer_gen yielding Circuit or Gate and a dictionary with random indexes used to select the clifford gates.

Parameters:
  • layer_gen (Callable) – Should return gates or a full circuit specifying a layer.

  • depth (int) – Number of layers.

  • interleave (str, optional) – Interleaving pattern for the circuits. Defaults to None.

Returns:

with depth many layers.

Return type:

Circuit

qibocal.protocols.randomized_benchmarking.utils.add_inverse_layer(circuit: Circuit, rb_gen: RB_Generator, single_qubit=True, file_inv=PosixPath('.'))[source]#

Adds an inverse gate/inverse gates at the end of a circuit (in place).

Parameters:

circuit (Circuit) – circuit

qibocal.protocols.randomized_benchmarking.utils.add_measurement_layer(circuit: Circuit)[source]#

Adds a measurement layer at the end of the circuit.

Parameters:

circuit (Circuit) – Measurement gates added in place to end of this circuit.

qibocal.protocols.randomized_benchmarking.utils.fit(qubits, data)[source]#

Takes data, extracts the depths and the signal and fits it with an exponential function y = Ap^x+B.