# K-body Noise Reconstruction (KNR)¶

This example illustrates how to generate k-body noise reconstruction (KNR) circuits and use them to estimate the probability distribution of stochastic Pauli errors afflicting the cycle being benchmarked. While this example uses a simulator to execute the circuits, the same procedure can be followed for hardware applications.

import trueq as tq
import trueq.simulation as tqs

# Define the cycle to benchmark using KNR.
cycle = tq.Cycle({label: tq.Gate.id for label in range(4)})

# Generate KNR circuits to benchmark the cycle, targeting only single body interactions,
# and 30 circuits for each length in [4, 32, 64].
circuits = tq.make_knr(cycle, n_random_cycles=[4, 32, 64], n_circuits=30, n_bodies=1)

# Initialize a simulator with stochastic Pauli noise, with worse noise on qubit 3.
sim = tq.Simulator()

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

# Display a table of KNR estimates:
circuits.fit()

True-Q formatting will not be loaded without trusting this notebook or rerunning the affected cells. Notebooks can be marked as trusted by clicking "File -> Trust Notebook".
 KNR Estimates K-body Noise Reconstruction Paulis (0,): Gate.id, (1,): Gate.id, (2,): Gate.id, (3,): Gate.id Cycle: (0,): Gate.id (1,): Gate.id (2,): Gate.id (3,): Gate.id Twirl: Paulis on [0, 1, 2, 3] (0,) : Gate.id Cycle: (0,): Gate.id (1,): Gate.id (2,): Gate.id (3,): Gate.id (1,) : Gate.id Cycle: (0,): Gate.id (1,): Gate.id (2,): Gate.id (3,): Gate.id (2,) : Gate.id Cycle: (0,): Gate.id (1,): Gate.id (2,): Gate.id (3,): Gate.id (3,) : Gate.id Cycle: (0,): Gate.id (1,): Gate.id (2,): Gate.id (3,): Gate.id X 9.6e-03 (7.9e-04) Subcycle: (0,): Gate.id Error Type: X Error Probability (std): 0.009580955179611661 (0.0007937469938513968) 1.1e-02 (8.6e-04) Subcycle: (1,): Gate.id Error Type: X Error Probability (std): 0.010772193381926226 (0.0008563963968684614) 1.0e-02 (9.7e-04) Subcycle: (2,): Gate.id Error Type: X Error Probability (std): 0.010037832215930215 (0.0009708087444098767) 7.9e-03 (2.1e-03) Subcycle: (3,): Gate.id Error Type: X Error Probability (std): 0.007933164708360863 (0.0020524231953520807) Y 1.0e-02 (7.9e-04) Subcycle: (0,): Gate.id Error Type: Y Error Probability (std): 0.010238101529848442 (0.0007937469938513968) 1.1e-02 (8.6e-04) Subcycle: (1,): Gate.id Error Type: Y Error Probability (std): 0.010843447823136093 (0.0008563963968684614) 1.0e-02 (9.7e-04) Subcycle: (2,): Gate.id Error Type: Y Error Probability (std): 0.010389973747328723 (0.0009708087444098767) 1.5e-02 (2.1e-03) Subcycle: (3,): Gate.id Error Type: Y Error Probability (std): 0.014873711212452179 (0.0020524231953520807) Z 9.8e-05 (7.9e-04) Subcycle: (0,): Gate.id Error Type: Z Error Probability (std): 9.831239879440345e-05 (0.0007937469938513968) -1.1e-03 (8.6e-04) Subcycle: (1,): Gate.id Error Type: Z Error Probability (std): -0.001093882491286613 (0.0008563963968684614) -4.7e-04 (9.7e-04) Subcycle: (2,): Gate.id Error Type: Z Error Probability (std): -0.0004742506994085405 (0.0009708087444098767) 1.8e-02 (2.1e-03) Subcycle: (3,): Gate.id Error Type: Z Error Probability (std): 0.01811974114180237 (0.0020524231953520807)

# Plot the results:
circuits.plot.knr_heatmap() From above, you can see that the largest single-qubit error is a $Z$ error on qubit 3, whose probability is approximately twice as large as the next leading single-qubit error. The probability of a $Z$ error on any other qubit is very low since we would have to have both an $X$ and a $Y$ error acting on that qubit for a $Z$ error to arise. This is exactly as expected given the noise defined by the simulator in this example.

In the example above KNR was ran on only single body terms, below we run KNR on two body terms, for more details see KNR.

# Generate KNR circuits to benchmark the cycle, but now targeting both single and two
# body interactions, with 30 circuits for each length in [4, 12, 32].
circuits = tq.make_knr(cycle, [4, 12, 32], n_circuits=30, n_bodies=2)

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

# Plot the results:
circuits.plot.knr_heatmap() As before, the Pauli error with the highest probability is a $Z$ error on qubit 3 and the other most-likely errors are weight 1. This is as expected based on our simple simulator model used in this example.

Total running time of the script: ( 0 minutes 10.318 seconds)

Gallery generated by Sphinx-Gallery