{
  "cells": [
    {
      "cell_type": "markdown",
      "id": "2e2023d1",
      "metadata": {},
      "source": [
        "---\n",
        "title: Quickstart\n",
        "description: Build and visualize a quantum circuit in under two minutes, no sign-in or API key necessary.\n",
        "---\n",
        "\n",
        "{/* cspell:ignore miniconda */}\n",
        "\n",
        "# Quickstart\n",
        "\n"
      ]
    },
    {
      "cell_type": "markdown",
      "id": "a82fbaaa",
      "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[all]~=2.3.0\n",
        "    ```\n",
        "  </AccordionItem>\n",
        "</Accordion>\n",
        "\n"
      ]
    },
    {
      "cell_type": "markdown",
      "id": "7bbbdb4b",
      "metadata": {
        "jp-MarkdownHeadingCollapsed": true
      },
      "source": [
        "Build your first quantum circuit in under two minutes, on your local environment - no sign-in or API key necessary.\n",
        "\n",
        "<Admonition type=\"note\" title=\"New to Python and virtual environments?\">\n",
        "  * Download Python and use a virtual environment with Qiskit (recommended).\n",
        "\n",
        "  <details>\n",
        "    <summary>Click to expand for more information about **Python**.</summary>\n",
        "\n",
        "    * To install Python, first check the \"Programming Language\" section on the [Qiskit PyPI project page](https://pypi.org/project/qiskit/) to determine which Python versions are supported by the most recent release. For download instructions, see the [Python Beginners Guide.](https://wiki.python.org/moin/BeginnersGuide/Download)\n",
        "\n",
        "    <Admonition type=\"note\">\n",
        "      These instructions use the standard Python distribution from [pypi.org](https://pypi.org/). However, you can use other Python distributions, such as [Anaconda](https://docs.anaconda.com/anaconda/) or [miniconda](https://docs.anaconda.com/miniconda/), along with other dependency management workflows like [Poetry](https://python-poetry.org/docs/).\n",
        "    </Admonition>\n",
        "  </details>\n",
        "\n",
        "  <details>\n",
        "    <summary>\n",
        "      Click to expand for more information on **virtual environments**.\n",
        "    </summary>\n",
        "\n",
        "    * Use [Python virtual environments](https://docs.python.org/3.10/tutorial/venv.html) to separate Qiskit from other applications.\n",
        "      A Python virtual environment is an isolated space to work with Python for a specific purpose — so you can install whatever packages you wish, and set up libraries, dependencies, and so on, without affecting the \"base\" Python environment on your machine.\n",
        "\n",
        "    One important advantage of a virtual environment is that if your Python environment becomes corrupted, you can easily delete it and start over!\n",
        "\n",
        "    Choose a preferred location in which to store information about your virtual environments. Typically they're stored in a directory named `.venv` within each project directory.\n",
        "\n",
        "    To set up a virtual environment, navigate to your project directory and create a minimal environment with only Python installed in it.\n",
        "\n",
        "    <OperatingSystemTabs>\n",
        "      <TabItem value=\"mac\" label=\"macOS\">\n",
        "        ```shell\n",
        "        python3 -m venv .venv\n",
        "        ```\n",
        "      </TabItem>\n",
        "\n",
        "      <TabItem value=\"linux\" label=\"Linux\">\n",
        "        ```shell\n",
        "        python3 -m venv .venv\n",
        "        ```\n",
        "      </TabItem>\n",
        "\n",
        "      <TabItem value=\"win\" label=\"Windows\">\n",
        "        ```text\n",
        "        python -m venv .venv\n",
        "        ```\n",
        "      </TabItem>\n",
        "    </OperatingSystemTabs>\n",
        "\n",
        "    Next, activate your new environment.\n",
        "\n",
        "    <OperatingSystemTabs>\n",
        "      <TabItem value=\"mac\" label=\"macOS\">\n",
        "        ```shell\n",
        "        source .venv/bin/activate\n",
        "        ```\n",
        "      </TabItem>\n",
        "\n",
        "      <TabItem value=\"linux\" label=\"Linux\">\n",
        "        ```shell\n",
        "        source .venv/bin/activate\n",
        "        ```\n",
        "      </TabItem>\n",
        "\n",
        "      <TabItem value=\"win\" label=\"Windows\">\n",
        "        If using PowerShell:\n",
        "\n",
        "        ```text\n",
        "        .venv\\Scripts\\Activate.ps1\n",
        "        ```\n",
        "\n",
        "        If using Git Bash:\n",
        "\n",
        "        ```text\n",
        "        source .venv/scripts/activate\n",
        "        ```\n",
        "\n",
        "        If using command prompt:\n",
        "\n",
        "        ```text\n",
        "        .venv\\Scripts\\activate\n",
        "        ```\n",
        "      </TabItem>\n",
        "    </OperatingSystemTabs>\n",
        "  </details>\n",
        "</Admonition>\n",
        "\n",
        "## 1. Install Qiskit\n",
        "\n",
        "Install the following with your preferred package manager (such as `pip`):\n",
        "\n",
        "* [`qiskit`](/docs/guides/install-qiskit)\n",
        "* [`matplotlib`](https://matplotlib.org/stable/users/explain/quick_start.html)\n",
        "* [`qiskit[visualization]`](/docs/api/qiskit/visualization)\n",
        "\n"
      ]
    },
    {
      "cell_type": "markdown",
      "id": "c8da788c",
      "metadata": {},
      "source": [
        "## 2. Build your circuit\n",
        "\n",
        "Open a Python environment, then run this code to build a Bell state (two entangled qubits).\n",
        "\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 1,
      "id": "86784142",
      "metadata": {},
      "outputs": [
        {
          "name": "stdout",
          "output_type": "stream",
          "text": [
            "{'11': 472, '00': 552}\n"
          ]
        }
      ],
      "source": [
        "from qiskit import QuantumCircuit\n",
        "from qiskit.primitives import StatevectorSampler\n",
        "\n",
        "qc = QuantumCircuit(2)\n",
        "qc.h(0)\n",
        "qc.cx(0, 1)\n",
        "qc.measure_all()\n",
        "\n",
        "sampler = StatevectorSampler()\n",
        "result = sampler.run([qc], shots=1024).result()\n",
        "print(result[0].data.meas.get_counts())"
      ]
    },
    {
      "cell_type": "markdown",
      "id": "9a3180c2-56d7-4224-91fa-13d8cb87d93d",
      "metadata": {},
      "source": [
        "The expected output is a near-even split between '00' and '11'.\n",
        "\n"
      ]
    },
    {
      "cell_type": "markdown",
      "id": "a110ac90",
      "metadata": {},
      "source": [
        "## 3. Visualize your results\n",
        "\n",
        "To get a histogram of your results, add the following code to your program.\n",
        "\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 2,
      "id": "dc4ff012",
      "metadata": {},
      "outputs": [
        {
          "data": {
            "text/plain": [
              "<Image src=\"/docs/images/guides/quick-start/extracted-outputs/dc4ff012-0.svg\" alt=\"Output of the previous code cell\" />"
            ]
          },
          "execution_count": 2,
          "metadata": {},
          "output_type": "execute_result"
        }
      ],
      "source": [
        "# Uncomment lines 2 and 8 if you are not using Python in a Jupyter notebook\n",
        "# import matplotlib.pyplot as plt\n",
        "from qiskit.visualization import plot_histogram\n",
        "\n",
        "counts = result[0].data.meas.get_counts()\n",
        "plot_histogram(counts)\n",
        "\n",
        "# plt.show()"
      ]
    },
    {
      "cell_type": "markdown",
      "id": "738d4fc4-29c9-46ab-9879-3365e2149d04",
      "metadata": {},
      "source": [
        "This result is a signature of quantum entanglement.\n",
        "\n",
        "## 4. See what happens\n",
        "\n",
        "Try changing the code to see how it affects the results. For example:\n",
        "\n",
        "* Add a third qubit by changing to `QuantumCircuit(3)`, and add a second CX gate with `qc.cx(1,2)`. The measurements should then change to 000 and 111, which means all three of these qubits have been entangled.\n",
        "\n",
        "* See your results shift by adding `qc.x(1)` to the end of the circuit.\n",
        "\n"
      ]
    },
    {
      "cell_type": "markdown",
      "id": "b6062a16",
      "metadata": {},
      "source": [
        "## Next steps\n",
        "\n",
        "<Admonition type=\"tip\" title=\"Recommendations\">\n",
        "  * Follow the steps in the [Run your first circuit on hardware](/docs/guides/hello-world) guide to run a circuit on real quantum hardware.\n",
        "  * Not ready to run on hardware? Start your quantum journey with the [Basics of quantum information](/learning/courses/basics-of-quantum-information) course.\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
}