# Noise Reconstruction (NR)¶

The effective noise under any cycle, under both Cycle Benchmarking (CB) and Randomized Compiling (RC) protocols, is a stochastic channel of the form,

$\mathcal{E}(\rho) = \sum_P \mu(P) P \rho P^\dagger$

for some probability distribution $$\mu$$ over the $$N$$-qubit Pauli group.

Through noise reconstruction (NR), we can reconstruct the probability distribution $$\mu$$ using carefully targeted Cycle Benchmarking (CB) diagnostic sequences with additional post-processing.

We have two noise reconstruction protocols:

K-body Noise Reconstruction (KNR)

Performs noise reconstruction on various subsets of qudits which are most relevant to the cycle being benchmarked, returning error probabilities for every Pauli in each subset. See make_knr() for details.

Targeted Noise Reconstruction (TMR)

Performs noise reconstruction for a targeted set of Pauli errors, returning error probabilities for user-specified Pauli errors. See make_tnr() for details.

## KNR Example¶

#
# K-body noise reconstruction (KNR) example.
# Copyright 2020 Quantum Benchmark Inc.
#

import trueq as tq

# Define the cycle we wish to do noise reconstruction on.
cycle = {(label,): tq.Gate.id for label in range(4)}

# Generate a circuit collection to measure noise.
circuits = tq.make_knr(cycle, [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().nr_bar()


## TNR Example¶

#
# Targeted noise reconstruction (TNR) example.
# Copyright 2020 Quantum Benchmark Inc.
#

import trueq as tq

# Define the cycle we wish to do noise reconstruction on.
cycle = {(label,): tq.Gate.id for label in range(4)}

# Generate a circuit collection to measure noise.
circuits = tq.make_tnr(cycle, [4, 32, 64], 30, targeted_errors={"XXXX", "XYXY", "YYZZ"})

# Initialize a simulator with stochastic pauli noise.

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

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

Key(cycle=Cycle((0,): Gate.id, (1,): Gate.id, (2,): Gate.id, (3,): Gate.id, immutable=True), labels=(0,), order=10, protocol='TNR', twirl=(('P', 0), ('P', 1), ('P', 2), ('P', 3)))
--------------------------------------------------------------------------------
Name  Estimate   95% CI              Description
p_Y     9.607  [9.034,10.2]   e-03  Probability of Pauli error Y
p_X     1.001  [0.944,1.058]  e-02  Probability of Pauli error X

Key(cycle=Cycle((0,): Gate.id, (1,): Gate.id, (2,): Gate.id, (3,): Gate.id, immutable=True), labels=(1,), order=10, protocol='TNR', twirl=(('P', 0), ('P', 1), ('P', 2), ('P', 3)))
--------------------------------------------------------------------------------
Name  Estimate   95% CI              Description
p_Y     1.010  [0.949,1.071]  e-02  Probability of Pauli error Y
p_X     1.012  [0.951,1.073]  e-02  Probability of Pauli error X

Key(cycle=Cycle((0,): Gate.id, (1,): Gate.id, (2,): Gate.id, (3,): Gate.id, immutable=True), labels=(2,), order=10, protocol='TNR', twirl=(('P', 0), ('P', 1), ('P', 2), ('P', 3)))
--------------------------------------------------------------------------------
Name  Estimate   95% CI              Description
p_Z    -3.036  [-9.559,3.4..  e-04  Probability of Pauli error Z
p_X     9.946  [9.294,10.6]   e-03  Probability of Pauli error X

Key(cycle=Cycle((0,): Gate.id, (1,): Gate.id, (2,): Gate.id, (3,): Gate.id, immutable=True), labels=(3,), order=10, protocol='TNR', twirl=(('P', 0), ('P', 1), ('P', 2), ('P', 3)))
--------------------------------------------------------------------------------
Name  Estimate   95% CI              Description
p_X     9.459  [8.881,10.0]   e-03  Probability of Pauli error X
p_Y     9.719  [9.141,10.3]   e-03  Probability of Pauli error Y
p_Z     4.839  [-0.945,10.6]  e-04  Probability of Pauli error Z