{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "%matplotlib inline" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n# K-body Noise Reconstruction (KNR)\n\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This example illustrates how to generate k-body noise reconstruction (:tqdoc:`KNR`\\)\ncircuits and use them to estimate the probability distribution of stochastic Pauli\nerrors afflicting the cycle being benchmarked. While this example uses a\n:doc:`simulator<../../guides/run/simulator>` to execute the circuits, the same\nprocedure can be followed for hardware applications.\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import trueq as tq\nimport trueq.simulation as tqs\n\n# Define the cycle to benchmark using KNR.\ncycle = tq.Cycle({label: tq.Gate.id for label in range(4)})\n\n# Generate KNR circuits to benchmark the cycle, targeting only single body interactions,\n# and 30 circuits for each length in [4, 32, 64].\ncircuits = tq.make_knr(cycle, n_random_cycles=[4, 32, 64], n_circuits=30, n_bodies=1)\n\n# Initialize a simulator with stochastic Pauli noise, with worse noise on qubit 3.\nsim = tq.Simulator()\nsim.add_stochastic_pauli(px=0.005, py=0.005)\nsim.add_stochastic_pauli(pz=0.01, match=tqs.LabelMatch(3))\n\n# Run the circuits on the simulator to populate the results.\nsim.run(circuits)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "# Display a table of KNR estimates:\ncircuits.fit()" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "# Plot the results:\ncircuits.plot.knr_heatmap()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "From above, you can see that the largest single-qubit error is a $Z$ error on\nqubit ``3``, whose probability is approximately twice as large as the next leading\nsingle-qubit error. The probability of a $Z$ error on any other qubit is very\nlow since we would have to have both an $X$ and a $Y$ error acting on\nthat qubit for a $Z$ error to arise. This is exactly as expected given the\nnoise defined by the simulator in this example.\n\nIn the example above KNR was ran on only single body terms, below we run KNR on two\nbody terms, for more details see :tqdoc:`KNR`\\.\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "# Generate KNR circuits to benchmark the cycle, but now targeting both single and two\n# body interactions, with 30 circuits for each length in [4, 12, 32].\ncircuits = tq.make_knr(cycle, [4, 12, 32], n_circuits=30, n_bodies=2)\n\n# Run the circuits on the simulator to populate the results.\nsim.run(circuits)\n\n# Plot the results:\ncircuits.plot.knr_heatmap()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "As before, the Pauli error with the highest probability is a $Z$ error on qubit\n``3`` and the other most-likely errors are weight 1. This is as expected based on our\nsimple simulator model used in this example.\n\n" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.6.8" } }, "nbformat": 4, "nbformat_minor": 0 }