{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Symmetric Stabilizer Benchmarking (SSB)\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "[![Open in Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/Infleqtion/client-superstaq/blob/main/docs/source/apps/supermarq/qcvv/qcvv_xeb_css.ipynb)\n", "[![Launch Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/Infleqtion/client-superstaq/HEAD?labpath=docs/source/apps/supermarq/qcvv/qcvv_xeb_css.ipynb)\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "To demonstrate SSB consider a noise model where single and two qubit gates are independently\n", "affected by depolarising channels.\n" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "from __future__ import annotations\n", "\n", "import cirq\n", "\n", "\n", "class IndependentDepolariseNoiseModel(cirq.NoiseModel):\n", " \"\"\"Applies single and two qubit depolarising channels independently.\"\"\"\n", "\n", " def __init__(self, single_qubit_error: float, two_qubit_error: float) -> None:\n", " \"\"\"Args:\n", " single_qubit_error: Single qubit pauli error.\n", " two_qubit_error: Two qubit pauli error.\n", " \"\"\"\n", " super().__init__()\n", " self.single_qubit_error = single_qubit_error\n", " self.two_qubit_error = two_qubit_error\n", "\n", " self.single_qubit_depolarise = cirq.DepolarizingChannel(p=single_qubit_error, n_qubits=1)\n", " self.two_qubit_depolarise = cirq.DepolarizingChannel(p=two_qubit_error, n_qubits=2)\n", "\n", " def noisy_operation(self, operation: cirq.Operation) -> list[cirq.OP_TREE]:\n", " \"\"\"Produces a list of operations by applying each noise model\n", " to the provided operation depending on the number of qubits it acts on.\n", " \"\"\"\n", " if len(operation.qubits) == 1:\n", " return [operation, self.single_qubit_depolarise(*operation.qubits)]\n", "\n", " if len(operation.qubits) == 2:\n", " return [operation, self.two_qubit_depolarise(*operation.qubits)]\n", "\n", " return [operation]\n", "\n", "\n", "e_1 = 0.001\n", "e_2 = 0.025\n", "\n", "noise = IndependentDepolariseNoiseModel(single_qubit_error=e_1, two_qubit_error=e_2)\n", "simulator = cirq.DensityMatrixSimulator(noise=noise, seed=0)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now run the experiment and analyse the results." ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "e47eeb6b88bb4dceaebaeb52bf4696ee", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Building circuits: 0%| | 0/500 [00:00" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "import supermarq.qcvv\n", "\n", "experiment = supermarq.qcvv.SSB(seed=0, num_circuits=100, cycle_depths=[2, 5, 10, 15, 20])\n", "results = experiment.run_with_simulator(simulator)\n", "results.analyze(plot_results=True)" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Expected CZ gate fidelity: 0.97333\n", "Estimated CZ fidelity: 0.97377 +/- 0.0029033\n" ] } ], "source": [ "print(f\"Expected CZ gate fidelity: {1 - 16 / 15 * e_2:.5f}\")\n", "results.print_results()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "client-venv", "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.12.12" } }, "nbformat": 4, "nbformat_minor": 2 }