# Extended Randomized Benchmarking (XRB)¶

The XRB protocol measures the leakage and unitarity of a qubit (see ). 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 2020 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(, [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 
--------------------------------------------------------------------------------
Name  Estimate   95% CI              Description
ru     6.242  [5.307,7.177]  e-03  Average gate infidelity of systematic coherent e..
A     0.994  [0.879,1.108]        SPAM of the exponential decay A * u ** m
u     0.975  [0.971,0.979]        Decay rate of the exponential decay A * u ** m


## Example 2¶

#
# Simultaneous extended randomized benchmarking (XRB) example.
# Copyright 2020 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 
--------------------------------------------------------------------------------
Name  Estimate   95% CI              Description
ru     5.627  [4.846,6.409]  e-03  Average gate infidelity of systematic coherent e..
A     0.962  [0.872,1.052]        SPAM of the exponential decay A * u ** m
u     0.978  [0.974,0.981]        Decay rate of the exponential decay A * u ** m

XRB on 
--------------------------------------------------------------------------------
Name  Estimate   95% CI              Description
ru     5.875  [5.162,6.589]  e-03  Average gate infidelity of systematic coherent e..
A     0.992  [0.911,1.073]        SPAM of the exponential decay A * u ** m
u     0.977  [0.974,0.979]        Decay rate of the exponential decay A * u ** m

XRB on 
--------------------------------------------------------------------------------
Name  Estimate   95% CI              Description
ru     5.919  [5.013,6.826]  e-03  Average gate infidelity of systematic coherent e..
A     0.980  [0.891,1.069]        SPAM of the exponential decay A * u ** m
u     0.976  [0.973,0.980]        Decay rate of the exponential decay A * u ** m


## Example 3¶

#
# Simultaneous extended randomized benchmarking (XRB) with incoherence example.
# Copyright 2020 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 
--------------------------------------------------------------------------------
Name  Estimate   95% CI              Description
r     6.475  [5.668,7.283]  e-03  Average gate infidelity of the error map
A     0.979  [0.957,1.001]        SPAM of the exponential decay A * p ** m
p     0.987  [0.985,0.989]        Decay rate of the exponential decay A * p ** m

SRB on 
--------------------------------------------------------------------------------
Name  Estimate   95% CI              Description
r     6.876  [6.297,7.455]  e-03  Average gate infidelity of the error map
A     0.994  [0.971,1.017]        SPAM of the exponential decay A * p ** m
p     0.986  [0.985,0.987]        Decay rate of the exponential decay A * p ** m

SRB on 
--------------------------------------------------------------------------------
Name  Estimate   95% CI              Description
r     6.628  [5.969,7.288]  e-03  Average gate infidelity of the error map
A     0.972  [0.953,0.991]        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 
--------------------------------------------------------------------------------
Name  Estimate   95% CI              Description
ru     5.435  [4.465,6.405]  e-03  Average gate infidelity of systematic coherent e..
inc     0.839  [0.657,1.022]        Incoherence, 0 indicates entirely unitary noise ..
A     0.886  [0.753,1.018]        SPAM of the exponential decay A * u ** m
u     0.978  [0.974,0.982]        Decay rate of the exponential decay A * u ** m

XRB on 
--------------------------------------------------------------------------------
Name  Estimate   95% CI              Description
ru     5.846  [5.189,6.503]  e-03  Average gate infidelity of systematic coherent e..
inc     0.850  [0.731,0.970]        Incoherence, 0 indicates entirely unitary noise ..
A     1.028  [0.977,1.079]        SPAM of the exponential decay A * u ** m
u     0.977  [0.974,0.979]        Decay rate of the exponential decay A * u ** m

XRB on 
--------------------------------------------------------------------------------
Name  Estimate   95% CI              Description
ru     5.700  [5.049,6.352]  e-03  Average gate infidelity of systematic coherent e..
inc     0.860  [0.730,0.990]        Incoherence, 0 indicates entirely unitary noise ..
A     0.968  [0.878,1.059]        SPAM of the exponential decay A * u ** m
u     0.977  [0.975,0.980]        Decay rate of the exponential decay A * u ** m