{ "cells": [ { "cell_type": "markdown", "id": "3e9d9e57-7928-46d6-a91b-b478b81676db", "metadata": {}, "source": [ "# Preliminary tests about the decoding accuracy, etc.\n", "\n", "This notebook contains several small tests of the decoding accuracy of various decoders to help me understand the pros and cons." ] }, { "cell_type": "code", "execution_count": 1, "id": "c3a64b14-939b-467b-9051-e76eb9a5d9f4", "metadata": {}, "outputs": [], "source": [ "%load_ext autoreload\n", "%autoreload 2" ] }, { "cell_type": "code", "execution_count": 2, "id": "43f5c5d6-7b96-4c9d-9726-c4ebf4b5f9a6", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "using 9 workers in simulation\n" ] } ], "source": [ "from qec_lego_bench.cli.logical_error_rate import *\n", "from qec_lego_bench.stats import Stats\n", "import os\n", "\n", "num_workers = os.cpu_count() - 1\n", "print(f\"using {num_workers} workers in simulation\")\n", "def resume_filepath(name: str) -> str:\n", " return f\"preliminary-decoder-compare-{name}.csv\"\n", "\n", "global_kwargs = dict( \n", " max_shots = 1_000_000_000,\n", " max_errors = 10_000,\n", " num_workers = num_workers,\n", " no_print = True,\n", ")" ] }, { "cell_type": "markdown", "id": "74aeedb0-fcbe-46c8-803a-c82784229f32", "metadata": {}, "source": [ "## Bivariate Bicycle Code $[[72, 12, 6]]$ with $p = 0.01$ depolarizing noise on data qubits" ] }, { "cell_type": "code", "execution_count": 3, "id": "5bc2ebed-0410-4b43-a284-609659dbd884", "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "/Users/wuyue/Documents/GitHub/qec-lego-bench/src/qec_lego_bench/cli/logical_error_rate.py:70: TqdmExperimentalWarning: Using `tqdm.autonotebook.tqdm` in notebook mode. Use `tqdm.tqdm` instead to force console mode (e.g. in jupyter console)\n", " from tqdm.autonotebook import tqdm # type: ignore\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "mwpf: Stats{ pL = 4291/105863577= 4.1(2)e-05, speed=9.74e-05s/S }, duration = 171.0 min\n", "huf: Stats{ pL = 10035/146322841= 6.9(2)e-05, speed=3.34e-05s/S }, duration = 81.0 min\n", "mwpf(cluster_node_limit=1000): Stats{ pL = 1177/30319001= 3.9(3)e-05, speed=1.31e-04s/S }, duration = 66.0 min\n", "bposd: Stats{ pL = 11023/1312153= 0.0084(2), speed=5.55e-05s/S }, duration = 1.0 min\n", "bposd(max_iter=5): Stats{ pL = 11600/133337497= 8.7(2)e-05, speed=3.66e-05s/S }, duration = 81.0 min\n", "bposd(max_iter=5,osd_order=10,osd_method=osd_e): Stats{ pL = 1023/26121625= 3.9(3)e-05, speed=2.31e-04s/S }, duration = 100.0 min\n", "bplsd: Stats{ pL = 12722/1524121= 0.0083(2), speed=6.53e-05s/S }, duration = 1.0 min\n", "bplsd(max_iter=5): Stats{ pL = 1054/12387737= 8.5(7)e-05, speed=4.13e-05s/S }, duration = 8.0 min\n", "bpuf: Stats{ pL = 4101/30652825= 0.000134(5), speed=6.43e-05s/S }, duration = 32.0 min\n", "bpuf(max_iter=5): Stats{ pL = 4392/57984409= 7.6(3)e-05, speed=4.74e-05s/S }, duration = 45.0 min\n" ] } ], "source": [ "default_kwargs = {\n", " **global_kwargs,\n", " **dict(\n", " code = \"bb(n=72,k=12,d=6)\",\n", " noise = \"depolarize(p=0.01)\",\n", " save_resume_filepath = resume_filepath(\"bb\"),\n", " )\n", "}\n", "custom_kwargs = [\n", " dict(decoder=\"mwpf\", max_errors=4000),\n", " dict(decoder=\"huf\"),\n", " dict(decoder=\"mwpf(cluster_node_limit=1000)\", max_errors=1000),\n", " dict(decoder=\"bposd\"),\n", " dict(decoder=\"bposd(max_iter=5)\"),\n", " dict(decoder=\"bposd(max_iter=5,osd_order=10,osd_method=osd_e)\", max_errors=1000),\n", " dict(decoder=\"bplsd\"),\n", " dict(decoder=\"bplsd(max_iter=5)\", max_errors=1000),\n", " dict(decoder=\"bpuf\", max_errors=4000),\n", " dict(decoder=\"bpuf(max_iter=5)\", max_errors=4000),\n", "]\n", "\n", "for custom in custom_kwargs:\n", " kwargs = { **default_kwargs, **custom }\n", " stats = logical_error_rate(**kwargs)\n", " print(f\"{kwargs['decoder']}: {stats}, duration = {stats.duration // 60} min\")" ] }, { "cell_type": "markdown", "id": "2adc3c75-8cec-47f1-89a0-9cab5a5a5ed8", "metadata": {}, "source": [ "## Circuit-level Rotated Surface Code, $d=3, r=3, p=0.001$" ] }, { "cell_type": "code", "execution_count": 4, "id": "566c4222-25d9-4b5c-8632-cf043836328d", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "mwpf: Stats{ pL = 13458/21087505= 0.00064(1), speed=3.40e-05s/S }, duration = 11.0 min\n", "huf: Stats{ pL = 11067/15830425= 0.00070(2), speed=1.63e-05s/S }, duration = 4.0 min\n", "mwpf(cluster_node_limit=1000): Stats{ pL = 12646/19796377= 0.00064(1), speed=3.63e-05s/S }, duration = 11.0 min\n", "bposd: Stats{ pL = 13572/18673049= 0.00073(2), speed=3.83e-05s/S }, duration = 11.0 min\n", "bposd(max_iter=5): Stats{ pL = 11744/16232857= 0.00072(2), speed=1.57e-05s/S }, duration = 4.0 min\n", "bposd(max_iter=5,osd_order=10,osd_method=osd_e): Stats{ pL = 11100/17798553= 0.00062(2), speed=4.03e-05s/S }, duration = 11.0 min\n", "bplsd: Stats{ pL = 10384/14387609= 0.00072(2), speed=5.01e-05s/S }, duration = 12.0 min\n", "bplsd(max_iter=5): Stats{ pL = 12762/17908121= 0.00071(2), speed=2.84e-05s/S }, duration = 8.0 min\n", "bpuf: Stats{ pL = 11865/14052761= 0.00084(2), speed=5.12e-05s/S }, duration = 11.0 min\n", "bpuf(max_iter=5): Stats{ pL = 10779/12746137= 0.00085(2), speed=2.85e-05s/S }, duration = 6.0 min\n", "pymatching: Stats{ pL = 1200718/994704456= 0.001207(3), speed=1.77e-07s/S }, duration = 2.0 min\n" ] } ], "source": [ "default_kwargs = {\n", " **global_kwargs,\n", " **dict(\n", " code = CodeCli(\"rsc(d=3,p=0.001)\"),\n", " max_errors = 10000,\n", " save_resume_filepath = resume_filepath(\"rsc\"),\n", " )\n", "}\n", "custom_kwargs = [\n", " dict(decoder=\"mwpf\"),\n", " dict(decoder=\"huf\"),\n", " dict(decoder=\"mwpf(cluster_node_limit=1000)\"),\n", " dict(decoder=\"bposd\"),\n", " dict(decoder=\"bposd(max_iter=5)\"),\n", " dict(decoder=\"bposd(max_iter=5,osd_order=10,osd_method=osd_e)\"),\n", " dict(decoder=\"bplsd\"),\n", " dict(decoder=\"bplsd(max_iter=5)\"),\n", " dict(decoder=\"bpuf\"),\n", " dict(decoder=\"bpuf(max_iter=5)\"),\n", " dict(decoder=\"pymatching\", max_errors=1000000),\n", "]\n", "\n", "for custom in custom_kwargs:\n", " kwargs = { **default_kwargs, **custom }\n", " stats = logical_error_rate(**kwargs)\n", " print(f\"{kwargs['decoder']}: {stats}, duration = {stats.duration // 60} min\")" ] }, { "cell_type": "markdown", "id": "b478f8cc-8b83-44cb-89ea-92182b0abe66", "metadata": {}, "source": [ "## Circuit-level Unrotated Surface Code, $d=3, r=3, p=0.001$" ] }, { "cell_type": "code", "execution_count": 5, "id": "90bee6b1-6760-4763-a558-4d19c8cb2b5b", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "mwpf: Stats{ pL = 10876/21749145= 0.00050(1), speed=9.14e-05s/S }, duration = 33.0 min\n", "huf: Stats{ pL = 10043/18809241= 0.00053(1), speed=2.71e-05s/S }, duration = 8.0 min\n", "mwpf(cluster_node_limit=1000): Stats{ pL = 13000/25708185= 0.00051(1), speed=1.52e-04s/S }, duration = 65.0 min\n", "bposd: Stats{ pL = 13651/21214617= 0.00064(1), speed=1.31e-04s/S }, duration = 46.0 min\n", "bposd(max_iter=5): Stats{ pL = 13095/19354009= 0.00068(2), speed=2.62e-05s/S }, duration = 8.0 min\n", "bposd(max_iter=5,osd_order=10,osd_method=osd_e): Stats{ pL = 12906/23934361= 0.00054(1), speed=8.27e-05s/S }, duration = 32.0 min\n", "bplsd: Stats{ pL = 11858/18024857= 0.00066(2), speed=1.55e-04s/S }, duration = 46.0 min\n", "bplsd(max_iter=5): Stats{ pL = 10545/15582617= 0.00068(2), speed=4.62e-05s/S }, duration = 11.0 min\n", "bpuf: Stats{ pL = 13112/17836441= 0.00074(2), speed=1.56e-04s/S }, duration = 46.0 min\n", "bpuf(max_iter=5): Stats{ pL = 11286/15084953= 0.00075(2), speed=4.76e-05s/S }, duration = 11.0 min\n", "pymatching: Stats{ pL = 805537/1000000000= 0.000806(2), speed=2.53e-07s/S }, duration = 4.0 min\n" ] } ], "source": [ "default_kwargs = {\n", " **global_kwargs,\n", " **dict(\n", " code = CodeCli(\"usc(d=3,p=0.001)\"),\n", " max_errors = 10000,\n", " save_resume_filepath = resume_filepath(\"usc\"),\n", " )\n", "}\n", "custom_kwargs = [\n", " dict(decoder=\"mwpf\"),\n", " dict(decoder=\"huf\"),\n", " dict(decoder=\"mwpf(cluster_node_limit=1000)\"),\n", " dict(decoder=\"bposd\"),\n", " dict(decoder=\"bposd(max_iter=5)\"),\n", " dict(decoder=\"bposd(max_iter=5,osd_order=10,osd_method=osd_e)\"),\n", " dict(decoder=\"bplsd\"),\n", " dict(decoder=\"bplsd(max_iter=5)\"),\n", " dict(decoder=\"bpuf\"),\n", " dict(decoder=\"bpuf(max_iter=5)\"),\n", " dict(decoder=\"pymatching\", max_errors=1000000),\n", "]\n", "\n", "for custom in custom_kwargs:\n", " kwargs = { **default_kwargs, **custom }\n", " stats = logical_error_rate(**kwargs)\n", " print(f\"{kwargs['decoder']}: {stats}, duration = {stats.duration // 60} min\")" ] }, { "cell_type": "markdown", "id": "b62e4487-8b0c-45ed-b1b1-08e6dc14bb11", "metadata": {}, "source": [ "## Circuit-level Repetition Code, $d=3, r=3, p=0.001$" ] }, { "cell_type": "code", "execution_count": 6, "id": "21f2ea83-3d45-413d-88ce-2c05ce5b63dc", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "mwpf: Stats{ pL = 10415/141988249= 7.3(2)e-05, speed=9.46e-06s/S }, duration = 22.0 min\n", "huf: Stats{ pL = 11731/158684569= 7.4(2)e-05, speed=8.51e-06s/S }, duration = 22.0 min\n", "mwpf(cluster_node_limit=1000): Stats{ pL = 10868/148964761= 7.3(2)e-05, speed=9.13e-06s/S }, duration = 22.0 min\n", "bposd: Stats{ pL = 10997/125032857= 8.8(2)e-05, speed=7.63e-06s/S }, duration = 15.0 min\n", "bposd(max_iter=5): Stats{ pL = 10349/118183321= 8.8(2)e-05, speed=7.95e-06s/S }, duration = 15.0 min\n", "bposd(max_iter=5,osd_order=10,osd_method=osd_e): Stats{ pL = 10047/136994201= 7.3(2)e-05, speed=9.78e-06s/S }, duration = 22.0 min\n", "bplsd: Stats{ pL = 10805/125996235= 8.6(2)e-05, speed=8.65e-06s/S }, duration = 18.0 min\n", "bplsd(max_iter=5): Stats{ pL = 13632/154425753= 8.8(2)e-05, speed=8.71e-06s/S }, duration = 22.0 min\n", "bpuf: Stats{ pL = 10618/111846809= 9.5(2)e-05, speed=8.65e-06s/S }, duration = 16.0 min\n", "bpuf(max_iter=5): Stats{ pL = 10726/114816409= 9.3(2)e-05, speed=8.49e-06s/S }, duration = 16.0 min\n", "pymatching: Stats{ pL = 73449/1000000000= 7.34(7)e-05, speed=7.30e-08s/S }, duration = 1.0 min\n" ] } ], "source": [ "default_kwargs = {\n", " **global_kwargs,\n", " **dict(\n", " code = CodeCli(\"rep(d=3,p=0.001)\"),\n", " max_errors = 10000,\n", " save_resume_filepath = resume_filepath(\"rep\"),\n", " )\n", "}\n", "custom_kwargs = [\n", " dict(decoder=\"mwpf\"),\n", " dict(decoder=\"huf\"),\n", " dict(decoder=\"mwpf(cluster_node_limit=1000)\"),\n", " dict(decoder=\"bposd\"),\n", " dict(decoder=\"bposd(max_iter=5)\"),\n", " dict(decoder=\"bposd(max_iter=5,osd_order=10,osd_method=osd_e)\"),\n", " dict(decoder=\"bplsd\"),\n", " dict(decoder=\"bplsd(max_iter=5)\"),\n", " dict(decoder=\"bpuf\"),\n", " dict(decoder=\"bpuf(max_iter=5)\"),\n", " dict(decoder=\"pymatching\", max_errors=1000000),\n", "]\n", "\n", "for custom in custom_kwargs:\n", " kwargs = { **default_kwargs, **custom }\n", " stats = logical_error_rate(**kwargs)\n", " print(f\"{kwargs['decoder']}: {stats}, duration = {stats.duration // 60} min\")" ] }, { "cell_type": "markdown", "id": "9102e48f-93b0-4beb-809a-41df4fccac2f", "metadata": {}, "source": [ "## Circuit-level Color Code, $d=3, r=3, p=0.001$" ] }, { "cell_type": "code", "execution_count": 7, "id": "ccad7a3f-aa5a-4722-9186-eb36faafca7a", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "mwpf: Stats{ pL = 12378/4480409= 0.00276(6), speed=2.14e-05s/S }, duration = 1.0 min\n", "huf: Stats{ pL = 11606/3926425= 0.00296(7), speed=1.25e-05s/S }, duration = 0.0 min\n", "mwpf(cluster_node_limit=1000): Stats{ pL = 12399/4476313= 0.00277(6), speed=2.16e-05s/S }, duration = 1.0 min\n", "bposd: Stats{ pL = 12702/785817= 0.0162(4), speed=1.15e-05s/S }, duration = 0.0 min\n", "bposd(max_iter=5): Stats{ pL = 11095/710041= 0.0156(4), speed=9.11e-06s/S }, duration = 0.0 min\n", "bposd(max_iter=5,osd_order=10,osd_method=osd_e): Stats{ pL = 11249/717209= 0.0157(4), speed=1.89e-05s/S }, duration = 0.0 min\n", "bplsd: Stats{ pL = 10507/658841= 0.0159(4), speed=1.44e-05s/S }, duration = 0.0 min\n", "bplsd(max_iter=5): Stats{ pL = 11477/732569= 0.0157(4), speed=1.27e-05s/S }, duration = 0.0 min\n", "bpuf: Stats{ pL = 10843/676249= 0.0160(4), speed=1.43e-05s/S }, duration = 0.0 min\n", "bpuf(max_iter=5): Stats{ pL = 11300/705945= 0.0160(4), speed=1.35e-05s/S }, duration = 0.0 min\n", "bposd(max_iter=5,osd_order=15,osd_method=osd_e): Stats{ pL = 10721/686489= 0.0156(4), speed=3.46e-04s/S }, duration = 3.0 min\n" ] } ], "source": [ "# default_kwargs = {\n", " **global_kwargs,\n", " **dict(\n", " code = CodeCli(\"color(d=3,p=0.001)\"),\n", " max_errors = 10000,\n", " save_resume_filepath = resume_filepath(\"color\"),\n", " )\n", "}\n", "custom_kwargs = [\n", " dict(decoder=\"mwpf\"),\n", " dict(decoder=\"huf\"),\n", " dict(decoder=\"mwpf(cluster_node_limit=1000)\"),\n", " dict(decoder=\"bposd\"),\n", " dict(decoder=\"bposd(max_iter=5)\"),\n", " dict(decoder=\"bposd(max_iter=5,osd_order=10,osd_method=osd_e)\"),\n", " dict(decoder=\"bplsd\"),\n", " dict(decoder=\"bplsd(max_iter=5)\"),\n", " dict(decoder=\"bpuf\"),\n", " dict(decoder=\"bpuf(max_iter=5)\"),\n", " dict(decoder=\"bposd(max_iter=5,osd_order=15,osd_method=osd_e)\"),\n", "]\n", "\n", "for custom in custom_kwargs:\n", " kwargs = { **default_kwargs, **custom }\n", " stats = logical_error_rate(**kwargs)\n", " print(f\"{kwargs['decoder']}: {stats}, duration = {stats.duration // 60} min\")" ] }, { "cell_type": "code", "execution_count": 8, "id": "60a19722-8adc-423b-bbd9-8fae20105ada", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "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.11.6" } }, "nbformat": 4, "nbformat_minor": 5 }