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:
- 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.
- 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.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.
- noise_model: Optional[str] = None#
For simulation purposes, string has to match what is in
qibocal.protocols.randomized_benchmarking.noisemodels
- seed: Optional[int] = None#
A fixed seed to initialize
np.random.Generator
.If
None
, uses a random seed. Defaults isNone
.
- 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.
- class qibocal.protocols.randomized_benchmarking.filtered_rb.FilteredRBResult[source]#
Bases:
Results
Filtered RB outputs.
- 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.
Set up the scan
Execute the scan
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:
- 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:
- 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:
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 annp.ndarray
andA
,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 annp.ndarray
andA
,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 annp.ndarray
andA1
,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:
- 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.
- 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.
- 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.
- 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.
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).
- 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
, 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.Channel
andqibo.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.Gate
object as an input and returnsTrue
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 thebuild
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
, 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.Channel
andqibo.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.Gate
object as an input and returnsTrue
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
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)
.- 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.
- 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 isNone
.
- noise_model: Optional[str] = None#
For simulation purposes, string has to match what is in
qibocal.protocols.randomized_benchmarking.noisemodels
- 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.
Set up the scan
Execute the scan
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:
- 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:
- 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:
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.
- noise_model: Optional[str] = None#
For simulation purposes, string has to match what is in
qibocal.protocols.randomized_benchmarking.noisemodels
- seed: Optional[int] = None#
A fixed seed to initialize
np.random.Generator
.If
None
, uses a random seed. Defaults isNone
.
- 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.
- 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.
- noise_model: Optional[str] = None#
For simulation purposes, string has to match what is in
qibocal.protocols.randomized_benchmarking.noisemodels
- seed: Optional[int] = None#
A fixed seed to initialize
np.random.Generator
.If
None
, uses a random seed. Defaults isNone
.
- 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.
- 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.
- 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:
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 toNone
.precision (int, optional) – nonnegative number of floating points of the displayed value. If
None
, defaults to the second significant digit ofuncertainty
or3
ifuncertainty
isNone
. Defaults toNone
.
- Returns:
The number expressed as a string, with the uncertainty if given.
- Return type:
- 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 toNone
.data_median (list or np.ndarray, optional) – 1d array for computing the errors from the confidence interval. If
None
, the median values are computed fromdata
.homogeneous (bool) – if
True
, assumes that all rows indata
are of the same size and returnsnp.ndarray
. Default isTrue
.
- 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.
- 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.
- 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.
- _to_npz(path: Path, filename: str)#
Helper function to use np.savez while converting keys into strings.
- property pairs#
Access qubit pairs ordered alphanumerically from data structure.
- property qubits#
Access qubits from data structure.
- register_qubit(dtype, data_keys, data_dict)#
Store output for single qubit.
- 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.
- _to_npz(path: Path, filename: str)#
Helper function to use np.savez while converting keys into strings.
- property pairs#
Access qubit pairs ordered alphanumerically from data structure.
- property qubits#
Access qubits from data structure.
- register_qubit(dtype, data_keys, data_dict)#
Store output for single qubit.
- 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.
- 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_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)
- property pairs#
Access qubit pairs ordered alphanumerically from data structure.
- property qubits#
Access qubits from data structure.
- register_qubit(dtype, data_keys, data_dict)#
Store output for single qubit.
- 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.
- 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.
- 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:
- 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:
- 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:
- 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:
- 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:
- 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.
- 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