{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "f80596f2", "metadata": { "execution": { "iopub.execute_input": "2024-03-26T18:58:06.440095Z", "iopub.status.busy": "2024-03-26T18:58:06.439821Z", "iopub.status.idle": "2024-03-26T18:58:06.442491Z", "shell.execute_reply": "2024-03-26T18:58:06.442050Z" }, "nbsphinx": "hidden" }, "outputs": [], "source": [ "# Copyright 2024 Keysight Technologies Inc." ] }, { "cell_type": "raw", "id": "f5e2c51e", "metadata": { "raw_mimetype": "text/restructuredtext" }, "source": [ "\n", "Example: Running IRB\n", "====================\n", "\n", "This example page demonstrates how to use :py:func:`~trueq.make_irb` method to\n", "estimate the infidelity of a specific gate. This protocol differs from\n", ":doc:`cb` in several ways:\n", "\n", "- It estimates the infidelity of a specific gate (not cycle) composed with gates from\n", " the twirling group, see :doc:`../../guides/error_diagnostics/irb` for more details.\n", " Gate infidelity can then be estimated by taking into account the results of an SRB\n", " experiment.\n", "- IRB uses a different twirling group than CB, Cliffords instead of Paulis by default.\n", " Paulis being a reference group with no entangling operations and therefore usually\n", " higher fidelity, leading to less systematic uncertainty in estimates.\n", "- Typically uses fewer circuits than CB.\n", "- IRB only gives information about specific gates (possibly in the context of being\n", " simultaneously applied), and not about entire cycles like CB.\n", "\n", "We begin by defining some cycles that contain the gates we want to characterize using\n", "IRB. Next we generate IRB circuits for these cycles.\n", "Note that we could perform simultaneous two qubit IRB with a cycle such as:\n", "\n", "``{(1, 2): tq.Gate.cz, (3, 4): tq.Gate.cz}``\n", "\n", "See :py:func:`~trueq.make_irb` for more details." ] }, { "cell_type": "code", "execution_count": 2, "id": "474d4dcb", "metadata": { "execution": { "iopub.execute_input": "2024-03-26T18:58:06.444474Z", "iopub.status.busy": "2024-03-26T18:58:06.444192Z", "iopub.status.idle": "2024-03-26T18:58:08.867211Z", "shell.execute_reply": "2024-03-26T18:58:08.866737Z" } }, "outputs": [ { "data": { "text/plain": [ "270" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import trueq as tq\n", "\n", "cycle1 = {1: tq.Gate.h}\n", "cycle2 = {2: tq.Gate.h}\n", "cycle12 = {(1, 2): tq.Gate.cz}\n", "\n", "# Generate a circuit collection to run IRB on the above cycles with 30 random circuits\n", "# for each circuit length in [4, 32, 64]:\n", "n_random_cycles = [4, 32, 64]\n", "circuits = tq.make_irb(cycle1, n_random_cycles)\n", "circuits += tq.make_irb(cycle2, n_random_cycles)\n", "circuits += tq.make_irb(cycle12, n_random_cycles)\n", "len(circuits)" ] }, { "cell_type": "raw", "id": "25e53443", "metadata": { "raw_mimetype": "text/restructuredtext" }, "source": [ "We are interested in the gate fidelity of the individual gates in the cycles defined\n", "above, e.g. :math:`CZ` alone, so we also need a reference SRB experiment to translate\n", "from the average fidelity of cycles dressed with gates in the twirling group to\n", "fidelity of the undressed gates. Optionally, to tighten the bound on the infidelity\n", "estimate, we also do an XRB experiment. The double nesting ``[[1, 2]]`` is necessary\n", "to characterize the :math:`CZ` gate because just ``[1, 2]`` refers to simultaneous\n", "single-qubit gates." ] }, { "cell_type": "code", "execution_count": 3, "id": "11e0b6cf", "metadata": { "execution": { "iopub.execute_input": "2024-03-26T18:58:08.869581Z", "iopub.status.busy": "2024-03-26T18:58:08.869084Z", "iopub.status.idle": "2024-03-26T18:58:09.158326Z", "shell.execute_reply": "2024-03-26T18:58:09.157801Z" } }, "outputs": [], "source": [ "circuits += tq.make_srb([1], n_random_cycles)\n", "circuits += tq.make_srb([2], n_random_cycles)\n", "circuits += tq.make_srb([[1, 2]], n_random_cycles)\n", "circuits += tq.make_xrb([1], n_random_cycles)\n", "circuits += tq.make_xrb([2], n_random_cycles)\n", "circuits += tq.make_xrb([[1, 2]], n_random_cycles)" ] }, { "cell_type": "raw", "id": "68e62acf", "metadata": { "raw_mimetype": "text/restructuredtext" }, "source": [ "Create a noisy simulator in lieu of a physical device and populate all circuits\n", "with results." ] }, { "cell_type": "code", "execution_count": 4, "id": "897b7515", "metadata": { "execution": { "iopub.execute_input": "2024-03-26T18:58:09.160774Z", "iopub.status.busy": "2024-03-26T18:58:09.160357Z", "iopub.status.idle": "2024-03-26T18:58:12.123522Z", "shell.execute_reply": "2024-03-26T18:58:12.123022Z" } }, "outputs": [], "source": [ "sim = tq.Simulator().add_depolarizing(0.01).add_overrotation(0.04)\n", "sim.run(circuits)" ] }, { "cell_type": "raw", "id": "ba459bcb", "metadata": { "raw_mimetype": "text/restructuredtext" }, "source": [ "Print a summary of the results for the CZ gate:" ] }, { "cell_type": "code", "execution_count": 5, "id": "e0ae7a08", "metadata": { "execution": { "iopub.execute_input": "2024-03-26T18:58:12.126149Z", "iopub.status.busy": "2024-03-26T18:58:12.125799Z", "iopub.status.idle": "2024-03-26T18:58:12.219193Z", "shell.execute_reply": "2024-03-26T18:58:12.218720Z" } }, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", "\n", "
\n",
" SRB \n",
" Streamlined Randomized Benchmarking \n",
" | \n",
" \n",
" \n",
" Cliffords\n",
"\n",
" (1,) \n",
" \n",
" \n",
"
| \n",
" \n",
" \n",
" Cliffords\n",
"\n",
" (2,) \n",
" \n",
" \n",
"
| \n",
" \n",
" \n",
" Cliffords\n",
"\n",
" (1, 2) \n",
" \n",
" \n",
"
| \n",
"
\n",
" \n",
" ${e}_{F}$\n",
" \n",
" \n",
" The probability of an error acting on the targeted systems during a random gate.\n",
" \n",
" | \n",
" \n",
" \n",
" 9.2e-03 (7.7e-04)\n",
" 0.00919340714741071, 0.0007668680243293099 \n",
" | \n",
" \n",
" \n",
" 1.0e-02 (7.7e-04)\n",
" 0.010477492740741251, 0.0007720736450271823 \n",
" | \n",
" \n",
" \n",
" 1.2e-02 (7.7e-04)\n",
" 0.012223249864356661, 0.0007725652795482386 \n",
" | \n",
"
\n",
" \n",
" ${p}$\n",
" \n",
" \n",
" Decay parameter of the exponential decay $Ap^m$.\n",
" \n",
" | \n",
" \n",
" \n",
" 9.9e-01 (1.0e-03)\n",
" 0.9877421238034524, 0.0010224906991057464 \n",
" | \n",
" \n",
" \n",
" 9.9e-01 (1.0e-03)\n",
" 0.9860300096790117, 0.0010294315267029097 \n",
" | \n",
" \n",
" \n",
" 9.9e-01 (8.2e-04)\n",
" 0.9869618668113529, 0.0008240696315181213 \n",
" | \n",
"
\n",
" \n",
" ${A}$\n",
" \n",
" \n",
" SPAM parameter of the exponential decay $Ap^m$.\n",
" \n",
" | \n",
" \n",
" \n",
" 9.8e-01 (1.9e-02)\n",
" 0.9791262128257734, 0.01939431456430689 \n",
" | \n",
" \n",
" \n",
" 1.0e+00 (2.0e-02)\n",
" 1.011505384841364, 0.02015539883109549 \n",
" | \n",
" \n",
" \n",
" 9.2e-01 (2.1e-02)\n",
" 0.9213008229785502, 0.02097466571603669 \n",
" | \n",
"
\n",
" XRB \n",
" Extended Randomized Benchmarking \n",
" | \n",
" \n",
" \n",
" Cliffords\n",
"\n",
" (1,) \n",
" \n",
" \n",
"
| \n",
" \n",
" \n",
" Cliffords\n",
"\n",
" (2,) \n",
" \n",
" \n",
"
| \n",
" \n",
" \n",
" Cliffords\n",
"\n",
" (1, 2) \n",
" \n",
" \n",
"
| \n",
"
\n",
" \n",
" ${e}_{U}$\n",
" \n",
" \n",
" The process infidelity of the coherent error acting on the specifed systems during a random gate.\n",
" \n",
" | \n",
" \n",
" \n",
" 2.8e-03 (9.0e-04)\n",
" 0.0028006471540379663, 0.0009016502860689471 \n",
" | \n",
" \n",
" \n",
" 4.9e-03 (8.9e-04)\n",
" 0.00492567741442082, 0.0008913589159583955 \n",
" | \n",
" \n",
" \n",
" 6.3e-04 (8.5e-04)\n",
" 0.0006308856016022102, 0.0008489227580761288 \n",
" | \n",
"
\n",
" \n",
" ${e}_{S}$\n",
" \n",
" \n",
" The probability of a stochastic error acting on the specified systems during a random gate.\n",
" \n",
" | \n",
" \n",
" \n",
" 6.4e-03 (4.7e-04)\n",
" 0.006392759993372743, 0.0004742221753877343 \n",
" | \n",
" \n",
" \n",
" 5.6e-03 (4.5e-04)\n",
" 0.005551815326320431, 0.00044544697070803647 \n",
" | \n",
" \n",
" \n",
" 1.2e-02 (3.5e-04)\n",
" 0.011592364262754451, 0.00035187034262087704 \n",
" | \n",
"
\n",
" \n",
" ${u}$\n",
" \n",
" \n",
" The unitarity of the noise, that is, the average decrease in the purity of an initial state.\n",
" \n",
" | \n",
" \n",
" \n",
" 9.8e-01 (1.3e-03)\n",
" 0.9830071298581166, 0.0012565082315651877 \n",
" | \n",
" \n",
" \n",
" 9.9e-01 (1.2e-03)\n",
" 0.9852362560010357, 0.0011812638170373242 \n",
" | \n",
" \n",
" \n",
" 9.8e-01 (7.4e-04)\n",
" 0.9754129646759375, 0.0007419548446633719 \n",
" | \n",
"
\n",
" \n",
" ${A}$\n",
" \n",
" \n",
" SPAM parameter of the exponential decay $Au^m$.\n",
" \n",
" | \n",
" \n",
" \n",
" 1.0e+00 (2.7e-02)\n",
" 1.0344252792598974, 0.0273188402758898 \n",
" | \n",
" \n",
" \n",
" 1.0e+00 (2.8e-02)\n",
" 1.0146986360310475, 0.028005388277059805 \n",
" | \n",
" \n",
" \n",
" 1.0e+00 (1.7e-02)\n",
" 1.001627874627467, 0.016525601761212743 \n",
" | \n",
"
\n",
" IRB \n",
" Interleaved Randomized Benchmarking \n",
" | \n",
" \n",
" \n",
" Cliffords\n",
"\n",
" \n",
" (1,) : Gate.h \n", "\n",
" \n",
"
| \n",
" \n",
" \n",
" Cliffords\n",
"\n",
" \n",
" (2,) : Gate.h \n", "\n",
" \n",
"
| \n",
" \n",
" \n",
" Cliffords\n",
"\n",
" \n",
" (1, 2) : Gate.cz \n", "\n",
" \n",
"
| \n",
"
\n",
" \n",
" ${e}_{F}$\n",
" \n",
" \n",
" The probability of an error acting on the targeted systems during a dressed gate of interest.\n",
" \n",
" | \n",
" \n",
" \n",
" 2.1e-02 (3.0e-03)\n",
" 0.021149234197659544, 0.0029774877068894728 \n",
" | \n",
" \n",
" \n",
" 2.3e-02 (2.6e-03)\n",
" 0.022846945312796962, 0.002625035203982787 \n",
" | \n",
" \n",
" \n",
" 3.9e-02 (7.0e-03)\n",
" 0.03936813110062106, 0.007017317514850027 \n",
" | \n",
"
\n",
" \n",
" ${e}_{IU}$\n",
" \n",
" \n",
" An upper bound on the inferred value of $e_F$ that accounts for systematic errors in the interleaved estimate.\n",
" \n",
" | \n",
" \n",
" \n",
" 3.1e-02 (5.4e-03)\n",
" 0.030511037116578404, 0.005442010445905701 \n",
" | \n",
" \n",
" \n",
" 4.1e-02 (5.0e-03)\n",
" 0.04070728540347951, 0.004966348788425576 \n",
" | \n",
" \n",
" \n",
" 3.7e-02 (1.1e-02)\n",
" 0.0371150718361787, 0.010535962849453441 \n",
" | \n",
"
\n",
" \n",
" ${e}_{IL}$\n",
" \n",
" \n",
" A lower bound on the inferred value of $e_F$ that accounts for systematic errors in the interleaved estimate.\n",
" \n",
" | \n",
" \n",
" \n",
" 4.8e-03 (2.0e-03)\n",
" 0.004765907510900752, 0.0020111307363554396 \n",
" | \n",
" \n",
" \n",
" 3.8e-03 (1.4e-03)\n",
" 0.003814946326912705, 0.0014304578340243461 \n",
" | \n",
" \n",
" \n",
" 2.0e-02 (7.7e-03)\n",
" 0.020353404444127428, 0.007685137038462741 \n",
" | \n",
"
\n",
" \n",
" ${p}$\n",
" \n",
" \n",
" Decay parameter of the exponential decay $Ap^m$.\n",
" \n",
" | \n",
" \n",
" \n",
" 9.7e-01 (4.0e-03)\n",
" 0.9718010210697873, 0.003969983609185964 \n",
" | \n",
" \n",
" \n",
" 9.7e-01 (3.5e-03)\n",
" 0.969537406249604, 0.0035000469386437167 \n",
" | \n",
" \n",
" \n",
" 9.6e-01 (7.5e-03)\n",
" 0.9580073268260042, 0.007485138682506696 \n",
" | \n",
"
\n",
" \n",
" ${A}$\n",
" \n",
" \n",
" SPAM parameter of the exponential decay $Ap^m$.\n",
" \n",
" | \n",
" \n",
" \n",
" 9.6e-01 (6.4e-02)\n",
" 0.9621760826862992, 0.0639142193174848 \n",
" | \n",
" \n",
" \n",
" 1.0e+00 (6.2e-02)\n",
" 1.0362473590695276, 0.06211865853508233 \n",
" | \n",
" \n",
" \n",
" 1.1e+00 (1.2e-01)\n",
" 1.1328369636175255, 0.1245088648556954 \n",
" | \n",
"