# `pygsti.tools.rbtools`

Tools for analyzing RB data

## Module Contents

### Functions

 `p_to_r`(p, d[, rtype]) Converts an RB decay constant (p) to the RB error rate (r). `r_to_p`(r, d[, rtype]) Inverse of the p_to_r function. `adjusted_success_probability`(hamming_distance_pdf) The success probabilitys adjusted by hamming weights. `marginalized_success_counts`(dsrow, circ, target, qubits) Marginalize the success counts over qubits. `hamming_distance`(bs1, bs2) TODO: docstring `marginalized_hamming_distance_counts`(dsrow, circ, ...) TODO: docstring `rescaling_factor`(lengths, quantity[, offset]) Finds a rescaling value alpha that maps the Clifford RB decay constant p to p_(rescaled) = p^(1/alpha).
pygsti.tools.rbtools.p_to_r(p, d, rtype='EI')

Converts an RB decay constant (p) to the RB error rate (r).

Here p is (normally) obtained from fitting data to A + Bp^m. There are two ‘types’ of RB error rate corresponding to different rescalings of 1 - p. These are the entanglement infidelity (EI) type r and the average gate infidelity (AGI) type r. The EI-type r is given by:

r = (d^2 - 1)(1 - p)/d^2,

where d is the dimension of the system (i.e., 2^n for n qubits). The AGI-type r is given by

r = (d - 1)(1 - p)/d.

For RB on gates whereby every gate is followed by an n-qubit uniform depolarizing channel (the most idealized RB scenario) then the EI-type (AGI-type) r corresponds to the EI (AGI) of the depolarizing channel to the identity channel.

The default (EI) is the convention used in direct RB, and is perhaps the most well-motivated as then r corresponds to the error probablity of the gates (in the idealized pauli-errors scenario). AGI is the convention used throughout Clifford RB theory.

#### Parameters

pfloat

Fit parameter p from P_m = A + B*p**m.

dint

Number of dimensions of the Hilbert space

rtype{‘EI’,’AGI’}, optional

The RB error rate rescaling convention.

#### Returns

rfloat

The RB error rate

pygsti.tools.rbtools.r_to_p(r, d, rtype='EI')

Inverse of the p_to_r function.

#### Parameters

rfloat

The RB error rate

dint

Number of dimensions of the Hilbert space

rtype{‘EI’,’AGI’}, optional

The RB error rate rescaling convention.

#### Returns

pfloat

The RB decay constant

The success probabilitys adjusted by hamming weights.

TODO: docstring - more explanation

#### Parameters

hamming_distance_pdf<TODO typ>

<TODO description>

#### Returns

numpy.ndarray

pygsti.tools.rbtools.marginalized_success_counts(dsrow, circ, target, qubits)

Marginalize the success counts over qubits.

#### Parameters

dsrow_DataSetRow

The circuit outcome data to marginalize.

circCircuit

The circuit.

targetstr

The ideal outcome, e.g. “0010”.

qubitstuple

The qubit labels that are retained after the marginalization.

#### Returns

int

The number of success counts.

pygsti.tools.rbtools.hamming_distance(bs1, bs2)

TODO: docstring

#### Parameters

bs1<TODO typ>

<TODO description>

bs2<TODO typ>

<TODO description>

#### Returns

<TODO typ>

pygsti.tools.rbtools.marginalized_hamming_distance_counts(dsrow, circ, target, qubits)

TODO: docstring

#### Parameters

dsrow_DataSetRow

The circuit outcome data to marginalize.

circCircuit

The circuit.

targetstr

The ideal outcome, e.g. “0010”.

qubitstuple

The qubit labels that are retained after the marginalization.

#### Returns

list

pygsti.tools.rbtools.rescaling_factor(lengths, quantity, offset=2)

Finds a rescaling value alpha that maps the Clifford RB decay constant p to p_(rescaled) = p^(1/alpha).

This can be used for finding, e.g., a “CRB r per CNOT” or a “CRB r per compiled Clifford depth”.

#### Parameters

lengthslist

A list of the RB lengths, which each value in ‘quantity’ will be rescaled by.

quantitylist

A list, of the same length as lengths, that contains lists of values of the quantity that the rescaling factor is extracted from.

offsetint, optional

A constant offset to add to lengths.

float