# Extended Randomized Benchmarking (XRB)¶

The XRB protocol measures the leakage and unitarity of a qubit (see [3][4]). The unitarity is a measure of how close the noise channel is to a unitary channel. In particular, the unitarity is $$1$$ when noise is entirely unitary, and $$0$$ when the noise is depolarizing.

## Example 1¶

#
# Extended randomized benchmarking (XRB) example.
# Copyright 2019 Quantum Benchmark Inc.
#

import trueq as tq

# Generate a circuit collection to run one-qubit XRB on qubit 0 with 30 random circuits
# for each circuit length in [4, 32, 64].
circuits = tq.make_xrb([0], [4, 32, 64], 30)

# Initialize a simulator with stochastic pauli noise.

# Run the circuits on the simulator to populate the results.
sim.run(circuits)

# Plot the results.
circuits.plot.raw()

# Print summary of the results.
circuits.fit().summarize()

XRB on [0]
--------------------------------------------------------------------------------
Name  Estimate   95% CI              Description
ru     6.295  [5.575,7.014]  e-03  Average gate infidelity of systematic coherent e..
A     0.989  [0.906,1.072]        SPAM of the exponential decay A * u ** m
u     0.975  [0.972,0.978]        Decay rate of the exponential decay A * u ** m


## Example 2¶

#
# Simultaneous extended randomized benchmarking (XRB) example.
# Copyright 2019 Quantum Benchmark Inc.
#

import trueq as tq

# Generate a circuit collection to run simultaneous XRB on qubits [0, 1, 2] with
# 30 random circuits for each circuit length in [4, 32, 64].
circuits = tq.make_xrb([0, 1, 2], [4, 32, 64], 30)

# Initialize a simulator with stochastic pauli noise.

# Run the circuits on the simulator to populate the results.
sim.run(circuits)

# Plot the results.
circuits.plot.raw()

# Print summary of the results.
circuits.fit().summarize()

XRB on [0]
--------------------------------------------------------------------------------
Name  Estimate   95% CI              Description
ru     6.075  [5.320,6.830]  e-03  Average gate infidelity of systematic coherent e..
A     1.037  [0.977,1.097]        SPAM of the exponential decay A * u ** m
u     0.976  [0.973,0.979]        Decay rate of the exponential decay A * u ** m

XRB on [1]
--------------------------------------------------------------------------------
Name  Estimate   95% CI              Description
ru     5.662  [4.741,6.583]  e-03  Average gate infidelity of systematic coherent e..
A     0.971  [0.845,1.097]        SPAM of the exponential decay A * u ** m
u     0.977  [0.974,0.981]        Decay rate of the exponential decay A * u ** m

XRB on [2]
--------------------------------------------------------------------------------
Name  Estimate   95% CI              Description
ru     5.972  [5.190,6.755]  e-03  Average gate infidelity of systematic coherent e..
A     0.961  [0.882,1.040]        SPAM of the exponential decay A * u ** m
u     0.976  [0.973,0.979]        Decay rate of the exponential decay A * u ** m


## Example 3¶

#
# Simultaneous extended randomized benchmarking (XRB) with incoherence example.
# Copyright 2019 Quantum Benchmark Inc.
#

import trueq as tq

# Generate a circuit collection to run simultaneous XRB on qubits [0, 1, 2] with
# 30 random circuits for each circuit length in [4, 32, 64].
circuits = tq.make_xrb([0, 1, 2], [4, 32, 64], 30)

# Generate a circuit collection to run simultaneous SRB on qubits [0, 1, 2] with
# 30 random circuits for each circuit length in [4, 32, 64].
srb_circuits = tq.make_srb([0, 1, 2], [4, 32, 64], 30)

# Append SRB circuits to the XRB circuit collection to analyze incoherence.
for circuit in srb_circuits:
circuits.append(circuit)

# Initialize a simulator with stochastic pauli noise.

# Run the circuits on the simulator to populate the results.
sim.run(circuits)

# Plot the results.
circuits.plot.raw()

# Print summary of the results.
circuits.fit().summarize()

SRB on [0]
--------------------------------------------------------------------------------
Name  Estimate   95% CI              Description
r     6.083  [5.319,6.847]  e-03  Average gate infidelity of the error map
A     0.963  [0.941,0.986]        SPAM of the exponential decay A * p ** m
p     0.988  [0.986,0.989]        Decay rate of the exponential decay A * p ** m

SRB on [1]
--------------------------------------------------------------------------------
Name  Estimate   95% CI              Description
r     6.850  [6.098,7.603]  e-03  Average gate infidelity of the error map
A     0.967  [0.942,0.992]        SPAM of the exponential decay A * p ** m
p     0.986  [0.985,0.988]        Decay rate of the exponential decay A * p ** m

SRB on [2]
--------------------------------------------------------------------------------
Name  Estimate   95% CI              Description
r     6.580  [5.786,7.375]  e-03  Average gate infidelity of the error map
A     0.967  [0.947,0.988]        SPAM of the exponential decay A * p ** m
p     0.987  [0.985,0.988]        Decay rate of the exponential decay A * p ** m

XRB on [0]
--------------------------------------------------------------------------------
Name  Estimate   95% CI              Description
ru     6.287  [5.387,7.187]  e-03  Average gate infidelity of systematic coherent e..
inc     1.034  [0.837,1.230]        Incoherence, 0 indicates entirely unitary noise ..
A     0.967  [0.847,1.088]        SPAM of the exponential decay A * u ** m
u     0.975  [0.971,0.979]        Decay rate of the exponential decay A * u ** m

XRB on [1]
--------------------------------------------------------------------------------
Name  Estimate   95% CI              Description
ru     6.673  [5.960,7.386]  e-03  Average gate infidelity of systematic coherent e..
inc     0.974  [0.825,1.123]        Incoherence, 0 indicates entirely unitary noise ..
A     1.041  [0.967,1.115]        SPAM of the exponential decay A * u ** m
u     0.973  [0.971,0.976]        Decay rate of the exponential decay A * u ** m

XRB on [2]
--------------------------------------------------------------------------------
Name  Estimate   95% CI              Description
ru     5.320  [4.655,5.985]  e-03  Average gate infidelity of systematic coherent e..
inc     0.808  [0.668,0.949]        Incoherence, 0 indicates entirely unitary noise ..
A     0.941  [0.862,1.021]        SPAM of the exponential decay A * u ** m
u     0.979  [0.976,0.981]        Decay rate of the exponential decay A * u ** m