{
  "cells": [
    {
      "cell_type": "markdown",
      "id": "33f4bb3c",
      "metadata": {},
      "source": [
        "---\n",
        "title: \"回路のタイミングを可視化する\"\n",
        "description: \"生成された回路のタイミングを可視化するため、閲覧・ダウンロード可能な図を生成します。\"\n",
        "---\n",
        "\n",
        "{/* cspell:ignore mactex, backgroundcolor, lightgreen */}\n",
        "\n",
        "<span id=\"visualize-circuit-timing\" />\n",
        "\n",
        "# 回路のタイミングを可視化する\n",
        "\n"
      ]
    },
    {
      "cell_type": "markdown",
      "id": "bfada4f0",
      "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=\"パッケージ・バージョン\">\n",
        "    このページ上のコードは、以下の要件に基づいて開発されました。\n",
        "    これらのバージョンまたはそれ以降のバージョンを使用することを推奨します。\n",
        "\n",
        "    ```\n",
        "    qiskit[all]~=2.5.1\n",
        "    ```\n",
        "  </AccordionItem>\n",
        "</Accordion>\n",
        "\n"
      ]
    },
    {
      "cell_type": "markdown",
      "id": "c3240c62",
      "metadata": {},
      "source": [
        "[回路に関する指示を可視化する](/docs/guides/visualize-circuits)だけでなく、Qiskit の [`timeline_drawer`](/docs/api/qiskit/qiskit.visualization.timeline_drawer) メソッドを使用して回路のスケジューリングを可視化することもできます。 この可視化により、例えば、量子ビットのアイドル時間を素早く特定するのに役立つ可能性があります。 ただし、この手法では、動的な回路については正確な結果が得られません。  動的な回線スケジューリングを可視化するには、「 [回線タイミングの可視化](/docs/guides/qiskit-runtime-circuit-timing)」 ガイドに記載されている メソッド `draw_circuit_schedule_timing` を使用してください。\n",
        "\n",
        "<span id=\"examples\" />\n",
        "\n",
        "## 例\n",
        "\n",
        "スケジュールされた回路プログラムを視覚化するには、制御引数のセットでこの関数を呼び出すことができる。 出力画像の外観のほとんどはスタイルシートで変更できるが、これは必須ではない。\n",
        "\n",
        "<span id=\"draw-with-the-default-stylesheet\" />\n",
        "\n",
        "### デフォルトのスタイルシートで描画する\n",
        "\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 1,
      "id": "5b21b8c1",
      "metadata": {},
      "outputs": [
        {
          "data": {
            "text/plain": [
              "<Image src=\"/docs/images/guides/visualize-circuit-timing/extracted-outputs/5b21b8c1-0.svg\" alt=\"Output of the previous code cell\" />"
            ]
          },
          "execution_count": 1,
          "metadata": {},
          "output_type": "execute_result"
        }
      ],
      "source": [
        "from qiskit import QuantumCircuit\n",
        "from qiskit.visualization.timeline import draw\n",
        "from qiskit.providers.fake_provider import GenericBackendV2\n",
        "from qiskit.transpiler import generate_preset_pass_manager\n",
        "\n",
        "qc = QuantumCircuit(2)\n",
        "qc.h(0)\n",
        "qc.cx(0, 1)\n",
        "\n",
        "backend = GenericBackendV2(5)\n",
        "\n",
        "pm = generate_preset_pass_manager(backend=backend, optimization_level=1)\n",
        "isa_circuit = pm.run(qc)\n",
        "\n",
        "draw(isa_circuit, target=backend.target)"
      ]
    },
    {
      "cell_type": "markdown",
      "id": "37f62ecd",
      "metadata": {},
      "source": [
        "<span id=\"draw-with-a-stylesheet-suited-for-program-debugging\" />\n",
        "\n",
        "### プログラムのデバッグに適したスタイルシートで描画する\n",
        "\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 2,
      "id": "907dc46c",
      "metadata": {},
      "outputs": [
        {
          "data": {
            "text/plain": [
              "<Image src=\"/docs/images/guides/visualize-circuit-timing/extracted-outputs/907dc46c-0.svg\" alt=\"Output of the previous code cell\" />"
            ]
          },
          "execution_count": 2,
          "metadata": {},
          "output_type": "execute_result"
        }
      ],
      "source": [
        "from qiskit import QuantumCircuit\n",
        "from qiskit.visualization.timeline import draw, IQXDebugging\n",
        "from qiskit.providers.fake_provider import GenericBackendV2\n",
        "from qiskit.transpiler import generate_preset_pass_manager\n",
        "\n",
        "qc = QuantumCircuit(2)\n",
        "qc.h(0)\n",
        "qc.cx(0, 1)\n",
        "qc.measure_all()\n",
        "\n",
        "backend = GenericBackendV2(5)\n",
        "pm = generate_preset_pass_manager(backend=backend, optimization_level=1)\n",
        "isa_circuit = pm.run(qc)\n",
        "draw(isa_circuit, style=IQXDebugging(), target=backend.target)"
      ]
    },
    {
      "cell_type": "markdown",
      "id": "5406fe18",
      "metadata": {},
      "source": [
        "カスタムジェネレーターやカスタムレイアウト関数を作成し、既存のスタイルシートをカスタム関数で更新することができます。 こうすることで、予定されているサーキットドロワーのコードベースを変更することなく、出力画像の外観のほとんどをコントロールすることができる。  詳細は [`timeline_drawer`](/docs/api/qiskit/qiskit.visualization.timeline_drawer) APIリファレンスを参照のこと。\n",
        "\n"
      ]
    },
    {
      "cell_type": "markdown",
      "id": "9daa7cf7",
      "metadata": {},
      "source": [
        "<span id=\"next-steps\" />\n",
        "\n",
        "## 次のステップ\n",
        "\n",
        "<Admonition type=\"tip\" title=\"推奨事項\">\n",
        "  * IBM Quantum Compute Service を使用する際の[回路タイミングを可視化する](/docs/guides/qiskit-runtime-circuit-timing)\n",
        "  * [回路を視覚化する](/docs/guides/visualize-circuits)\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": 5
}