qibocal.protocols.characterization.randomized_benchmarking package#
Submodules#
qibocal.protocols.characterization.randomized_benchmarking.circuit_tools module#
Collection of function to generate qibo circuits.
- qibocal.protocols.characterization.randomized_benchmarking.circuit_tools.embed_circuit(circuit: Circuit, nqubits: int, qubits: list) Circuit [source]#
Embeds circuit into a larger circuit of size nqubits on the qubits specified by qubits.
- qibocal.protocols.characterization.randomized_benchmarking.circuit_tools.layer_circuit(layer_gen: Callable, depth: int) Circuit [source]#
Creates a circuit of depth layers from a generator layer_gen yielding Circuit or Gate.
- Parameters
layer_gen (Callable) – Should return gates or a full circuit specifying a layer.
depth (int) – Number of layers.
- Returns
with depth many layers.
- Return type
Circuit
qibocal.protocols.characterization.randomized_benchmarking.data module#
qibocal.protocols.characterization.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.characterization.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.characterization.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.characterization.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.characterization.randomized_benchmarking.fitting.expn_func(x: Union[ndarray, list], *args) ndarray [source]#
Compute the sum of exponentials \(\sum A_i\cdot f_i^x\)
- Parameters
x (np.ndarray | list) – list of exponents.
*args – Parameters of type float in the order \(A_1\), \(A_2\), \(f_1\), \(f_2\),…
- Returns
The resulting sum of exponentials.
- qibocal.protocols.characterization.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.characterization.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.characterization.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.characterization.randomized_benchmarking.fitting.fit_expn_func(xdata: Union[ndarray, list], ydata: Union[ndarray, list], n: int = 2, **kwargs) 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.characterization.randomized_benchmarking.fitting.fit_exp2_func(xdata: Union[ndarray, list], ydata: Union[ndarray, list], **kwargs) 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.characterization.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.characterization.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).
- class qibocal.protocols.characterization.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).
qibocal.protocols.characterization.randomized_benchmarking.standard_rb module#
- class qibocal.protocols.characterization.randomized_benchmarking.standard_rb.Depthsdict[source]#
Bases:
TypedDict
dictionary used to build a list of depths as
range(start, stop, step)
.
- class qibocal.protocols.characterization.randomized_benchmarking.standard_rb.StandardRBParameters(depths: ~typing.Union[list, ~qibocal.protocols.characterization.randomized_benchmarking.standard_rb.Depthsdict], niter: int, nshots: int, uncertainties: ~typing.Union[str, float] = 95, n_bootstrap: int = 100, seed: ~typing.Optional[int] = None, noise_model: str = '', noise_params: ~typing.Optional[list] = <factory>)[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: Union[str, float] = 95#
Method of computing the error bars of the signal and uncertainties of the fit. If
None
, does not compute them. If"std"
, computes the standard deviation. Iffloat
orint
between 0 and 100, computes the corresponding confidence interval. Defaults to95
.
- n_bootstrap: int = 100#
Number of bootstrap iterations for the fit uncertainties and error bars. If
0
, gets the fit uncertainties from the fitting function and the error bars from the distribution of the measurements. Defaults to100
.
- seed: Optional[int] = None#
A fixed seed to initialize
np.random.Generator
. IfNone
, uses a random seed. Defaults isNone
.
- noise_model: str = ''#
For simulation purposes, string has to match what is in
qibocal.protocols.characterization.randomized_benchmarking.noisemodels
- class qibocal.protocols.characterization.randomized_benchmarking.standard_rb.RBData(*args, **kwargs)[source]#
Bases:
DataFrame
A pandas DataFrame child. The output of the acquisition function.
- class qibocal.protocols.characterization.randomized_benchmarking.standard_rb.StandardRBResult(fidelity: float, pulse_fidelity: float, fit_parameters: tuple[float, float, float], fit_uncertainties: tuple[float, float, float], error_bars: Optional[Union[float, list[float]]] = None)[source]#
Bases:
Results
Standard RB outputs.
- qibocal.protocols.characterization.randomized_benchmarking.standard_rb.samples_to_p0(samples_list)[source]#
Computes the probabilitiy of 0 from the list of samples.
- Parameters
samples_list (list or np.ndarray) – 3d array with
ncircuits
rows containingnshots
lists withnqubits
amount of0
and1
samples. e.g.samples_list
for 1 circuit, 3 shots and 2 qubits looks like[[[0, 0], [0, 1], [1, 0]]]
andp0=1/3
.- Returns
list of probabilities corresponding to each row.
- Return type
- qibocal.protocols.characterization.randomized_benchmarking.standard_rb.resample_p0(data, sample_size=100, homogeneous: bool = True)[source]#
- Preforms parametric resampling of shots with binomial distribution
and returns a list of “corrected” probabilites.
- qibocal.protocols.characterization.randomized_benchmarking.standard_rb.setup_scan(params: StandardRBParameters, qubits: Union[dict[Union[str, int], qibolab.qubits.Qubit], list[Union[str, int]]], nqubits: int) Iterable [source]#
Returns an iterator of single-qubit random self-inverting Clifford circuits.
- Parameters
- Returns
The iterator of circuits.
- Return type
Iterable
qibocal.protocols.characterization.randomized_benchmarking.utils module#
- qibocal.protocols.characterization.randomized_benchmarking.utils.random_clifford(qubits, seed=None)[source]#
Generates random Clifford operator(s).
- Parameters
qubits (int or list or ndarray) – if
int
, the number of qubits for the Clifford. Iflist
orndarray
, indexes of the qubits for the Clifford to act on.seed (int or
numpy.random.Generator
, optional) – Either a generator of random numbers or a fixed seed to initialize a generator. IfNone
, initializes a generator with a random seed. Default isNone
.
- Returns
Random Clifford operator(s).
- Return type
(list of
qibo.gates.Gate
)
- qibocal.protocols.characterization.randomized_benchmarking.utils.significant_digit(number: Number)[source]#
Computes the position of the first significant digit of a given number.
- Parameters
number (Number) – number for which the significant digit is computed. Can be complex.
- Returns
- position of the first significant digit. Returns
-1
if the given number is
>= 1
,= 0
orinf
.
- position of the first significant digit. Returns
- Return type
- qibocal.protocols.characterization.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.characterization.randomized_benchmarking.utils.extract_from_data(data: Union[list[dict], DataFrame], output_key: str, groupby_key: str = '', agg_type: Union[str, Callable] = '') Union[ndarray, tuple[numpy.ndarray, numpy.ndarray]] [source]#
Return wanted values from list of dictionaries via a dataframe and its properties.
If
groupby_key
given, aggregate the dataframe, extract the data by which the frame was grouped, what was calculated given theagg_type
parameter. Two arrays are returned then, the group values and the grouped (aggregated) data. If noagg_type
given use a linear function. Ifgroupby_key
not given, only return the extracted data from given key.- Parameters
- Returns
Either one or two np.ndarrays. If no grouping wanted, just the data. If grouping wanted, the values after which where grouped and the grouped data.