{
  "cells": [
    {
      "cell_type": "markdown",
      "id": "b40b58ca-20e6-411f-8707-80ab3edf414d",
      "metadata": {},
      "source": [
        "---\n",
        "title: Configure noise management with Sampler\n",
        "description: How to configure noise management with the Qiskit Runtime Estimator primitive.\n",
        "---\n",
        "\n",
        "# Configure noise management with Sampler\n",
        "\n"
      ]
    },
    {
      "cell_type": "markdown",
      "id": "9dc0196d-5180-433b-8fbc-8f937330a0ea",
      "metadata": {
        "tags": [
          "version-info"
        ]
      },
      "source": [
        "{/*\n",
        "  DO NOT EDIT THIS CELL!!!\n",
        "  This cell's content is generated automatically by a script. Anything you add\n",
        "  here will be removed next time the notebook is run. To add new content, create\n",
        "  a new cell before or after this one.\n",
        "  */}\n",
        "\n",
        "<Accordion>\n",
        "  <AccordionItem title=\"Package versions\">\n",
        "    The code on this page was developed using the following requirements.\n",
        "    We recommend using these versions or newer.\n",
        "\n",
        "    ```\n",
        "    qiskit-ibm-runtime~=0.45.1\n",
        "    ```\n",
        "  </AccordionItem>\n",
        "</Accordion>\n",
        "\n"
      ]
    },
    {
      "cell_type": "markdown",
      "id": "eaa0b874-f0e6-4fc9-82f7-e993770ebf47",
      "metadata": {},
      "source": [
        "There are several ways to manage noise, typically by using various error mitigation and error suppression techniques to avoid errors before they happen.  These techniques usually cause pre-processing overhead.  Therefore, it is important to achieve a balance between perfecting your results and ensuring that your job completes in a reasonable amount of time.\n",
        "\n",
        "Sampler supports the following noise management techniques. See [Error mitigation and suppression techniques](error-mitigation-and-suppression-techniques) for an explanation of each.\n",
        "\n",
        "* [dynamical decoupling](/docs/api/qiskit-ibm-runtime/options-dynamical-decoupling-options#dynamicaldecouplingoptions)\n",
        "* [Pauli twirling](/docs/api/qiskit-ibm-runtime/options-twirling-options)\n",
        "\n",
        "<Admonition type=\"note\">\n",
        "  Not all options work together on all types of circuits. See the [feature compatibility table](/docs/guides/sampler-options#options-compatibility-table) guide for full details.\n",
        "</Admonition>\n",
        "\n",
        "Example\n",
        "\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 3,
      "id": "ca9a0d48-34a2-4a22-a24c-46327c622a93",
      "metadata": {},
      "outputs": [
        {
          "name": "stdout",
          "output_type": "stream",
          "text": [
            ">>> dynamical decoupling sequence to use: XpXm\n",
            ">>> gate twirling is turned on: True\n"
          ]
        }
      ],
      "source": [
        "from qiskit_ibm_runtime import QiskitRuntimeService\n",
        "from qiskit_ibm_runtime import SamplerV2 as Sampler\n",
        "\n",
        "service = QiskitRuntimeService()\n",
        "backend = service.least_busy(operational=True, simulator=False)\n",
        "\n",
        "sampler = Sampler(backend)\n",
        "\n",
        "# Turn on dynamical decoupling with sequence XpXm.\n",
        "sampler.options.dynamical_decoupling.enable = True\n",
        "sampler.options.dynamical_decoupling.sequence_type = \"XpXm\"\n",
        "# Turn on gate twirling. Requires qiskit_ibm_runtime 0.23.0 or later.\n",
        "sampler.options.twirling.enable_gates = True\n",
        "\n",
        "print(\n",
        "    f\">>> dynamical decoupling sequence to use: {sampler.options.dynamical_decoupling.sequence_type}\"\n",
        ")\n",
        "print(\n",
        "    f\">>> gate twirling is turned on: {sampler.options.twirling.enable_gates}\"\n",
        ")"
      ]
    },
    {
      "cell_type": "markdown",
      "id": "db285d76-0e96-4ae4-a65c-3fdae1407bee",
      "metadata": {},
      "source": [
        "<CodeAssistantAdmonition\n",
        "  tagLine=\"Can't remember the right attributes? Try asking Qiskit Code Assistant.\"\n",
        "  prompts={[\n",
        "  \"# Enable dynamic decoupling for Sampler with the 'XpXm' sequence type\"\n",
        "]}\n",
        "/>\n",
        "\n",
        "## Next steps\n",
        "\n",
        "<Admonition type=\"tip\" title=\"Recommendations\">\n",
        "  * Learn more about [error mitigation and error suppression techniques](error-mitigation-and-suppression-techniques).\n",
        "  * Explore Sampler [options](/docs/guides/sampler-options).\n",
        "  * Decide what [execution mode](execution-modes) to run your job in.\n",
        "</Admonition>\n",
        "\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "id": "a1b8767d",
      "source": "© IBM Corp., 2017-2026"
    }
  ],
  "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"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 4
}