{
  "cells": [
    {
      "cell_type": "markdown",
      "id": "810fe365-8557-46b0-97e7-324b08a1c6e2",
      "metadata": {},
      "source": [
        "---\n",
        "title: Monitor or cancel a job\n",
        "description: How to monitor or cancel a job submitted to IBM Quantum Platform\n",
        "---\n",
        "\n",
        "# Monitor or cancel a job\n",
        "\n",
        "View a list of your workloads on the [Workloads page](/workloads).\n",
        "\n",
        "## View job status\n",
        "\n",
        "Go to your [Workloads table](/workloads) and check under the Status column for whether a job has completed or failed.\n",
        "\n",
        "### Why a job stays \"In progress\"\n",
        "\n",
        "You might notice that a job you expect to take only a few seconds stays in the **In progress** status (called `RUNNING` in Qiskit) for much longer. This is normal, and it does not mean the job is consuming that entire time as usage. It happens because of how jobs are scheduled onto a QPU:\n",
        "\n",
        "* Every job requires classical pre-processing before it can run on the QPU. A job moves to **In progress** (`RUNNING`) as soon as this classical processing begins — not when it starts executing on the QPU.\n",
        "* Most of this classical processing runs in parallel, so multiple jobs can be **In progress** at the same time.\n",
        "* However, only one job at a time can run on the QPU. When several jobs finish their classical processing and are ready to execute, they must wait their turn for the QPU. This is known as *QPU contention*. When contention is high, a job can remain **In progress** noticeably longer than the few seconds of QPU time it actually needs.\n",
        "* Contention can also occur when a system-maintenance task, such as calibration, is running on the QPU. Your job stays **In progress** until the maintenance task completes and the QPU becomes available.\n",
        "\n",
        "Because of this, the elapsed wall-clock time a job spends **In progress** is not the same as its usage. Both the [estimated usage](/docs/guides/estimate-job-run-time) and the [maximum execution time](/docs/guides/max-execution-time) are based only on the time the QPU is locked to execute your job, and therefore exclude the multi-threaded classical processing described above. A long **In progress** time does not increase your reported usage or cost.\n",
        "\n",
        "#### Session mode is different\n",
        "\n",
        "The preceding behavior applies to [job mode](/docs/guides/execution-modes#job-mode) and [batch mode](/docs/guides/execution-modes#batch-mode). In [session mode](/docs/guides/execution-modes#session-mode), during the session's active window the user has exclusive access of the system and no other jobs can run, which includes calibration jobs. Therefore, any QPU contention happens only among your own session jobs. In addition, session usage is measured as the elapsed time while the session remains active, because QPU capacity is reserved for the duration of the session, regardless of whether jobs are actively running. See [Workload usage](/docs/guides/estimate-job-run-time#usage) for more information.\n",
        "\n",
        "## View remaining usage\n",
        "\n",
        "Go to your [Instances table](/instances) and select the tab associated with the plan you want to view remaining usage for. Total time used and total time remaining on your plan is displayed.\n",
        "\n",
        "## View metrics on number of jobs and workloads submitted\n",
        "\n",
        "Go to the [Analytics page](/analytics) to see the total number of jobs submitted, as well as a count of batch workloads and session workloads. Note that you can only see the Analytics page for accounts that you own or manage.\n",
        "\n",
        "## Monitor a job\n",
        "\n",
        "Use the job instance to check the job status or retrieve the results by calling the appropriate command:\n",
        "\n",
        "|                               |                                                                                                                                                                                                               |\n",
        "| ----------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |\n",
        "| job.result()                  | Review job results immediately after the job completes. Job results are available after the job completes. Therefore, job.result() is a blocking call until the job completes.                                |\n",
        "| job.job\\_id()                 | Return the ID that uniquely identifies that job. Retrieving the job results at a later time requires the job ID. Therefore, it is recommended that you save the IDs of jobs you might want to retrieve later. |\n",
        "| job.status()                  | Check the job status.                                                                                                                                                                                         |\n",
        "| job = service.job(\\<job\\_id>) | Retrieve a job you previously submitted. This call requires the job ID.                                                                                                                                       |\n",
        "\n",
        "<span id=\"retrieve-later\" />\n",
        "\n",
        "## Retrieve job results at a later time\n",
        "\n",
        "Call `service.job(\\<job\\_id>)` to retrieve a job you previously submitted. If you don't have the job ID, or if you want to retrieve multiple jobs at once; including jobs from retired QPUs (quantum processing units), call `service.jobs()` with optional filters instead. See [QiskitRuntimeService.jobs](../api/qiskit-ibm-runtime/qiskit-runtime-service#jobs).\n",
        "\n",
        "<Admonition type=\"note\" title=\"Deprecated provider packages\">\n",
        "  `service.jobs()` also returns jobs run from the deprecated `qiskit-ibm-provider` package. Jobs submitted by the older (also deprecated) `qiskit-ibmq-provider` package are no longer available.\n",
        "</Admonition>\n",
        "\n",
        "### Example\n",
        "\n",
        "This example returns the 10 most recent runtime jobs that were run on `my_backend`:\n",
        "\n"
      ]
    },
    {
      "cell_type": "markdown",
      "id": "c67f78c5-a199-456a-a9e3-35c518b28f50",
      "metadata": {
        "tags": [
          "version-info"
        ]
      },
      "source": [
        "\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 2,
      "id": "03946d0d-aeac-45d7-9e8e-6af38e40e758",
      "metadata": {},
      "outputs": [
        {
          "name": "stdout",
          "output_type": "stream",
          "text": [
            "ExecutionSpans([DoubleSliceSpan(<start='2025-09-09 16:31:16', stop='2025-09-09 16:31:16', size=24>)])\n"
          ]
        }
      ],
      "source": [
        "result = job.result()\n",
        "\n",
        "\n",
        "spans = job.result().metadata[\"execution\"][\"execution_spans\"]\n",
        "print(spans)"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 3,
      "id": "897d35cb-140a-4587-a687-97982a01d846",
      "metadata": {},
      "outputs": [
        {
          "data": {
            "text/plain": [
              "array([[0.2260416 , 0.8747859 , 0.44361995],\n",
              "       [0.94700856, 0.96826017, 0.98426562]])"
            ]
          },
          "execution_count": 3,
          "metadata": {},
          "output_type": "execute_result"
        }
      ],
      "source": [
        "params = np.random.uniform(size=(2, 3))\n",
        "params"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 4,
      "id": "38176ecc-64fe-4dbb-a9fa-bd0ca2942920",
      "metadata": {},
      "outputs": [
        {
          "data": {
            "text/plain": [
              "array([[[ True,  True,  True,  True],\n",
              "        [ True,  True,  True,  True]],\n",
              "\n",
              "       [[ True,  True,  True,  True],\n",
              "        [ True,  True,  True,  True]],\n",
              "\n",
              "       [[ True,  True,  True,  True],\n",
              "        [ True,  True,  True,  True]]])"
            ]
          },
          "execution_count": 4,
          "metadata": {},
          "output_type": "execute_result"
        }
      ],
      "source": [
        "mask = spans[0].mask(0)\n",
        "mask"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "id": "4415838a-04da-4a8e-8fed-4c062d186ec7",
      "metadata": {},
      "outputs": [],
      "source": [
        "from qiskit_ibm_runtime import QiskitRuntimeService\n",
        "\n",
        "# Initialize the account first.\n",
        "service = QiskitRuntimeService()\n",
        "# Use `limit` to retrieve a specific number of jobs. The default `limit` is 10.\n",
        "service.jobs(backend_name=my_backend)"
      ]
    },
    {
      "cell_type": "markdown",
      "id": "59195a9f-8df8-46f7-9ea0-c3a9b8eb3cac",
      "metadata": {},
      "source": [
        "## Cancel a job\n",
        "\n",
        "You can cancel a job from the IBM Quantum Platform dashboard either on the Workloads page or the details page for a specific workload. On the Workloads page, click the overflow menu at the end of the row for that workload, and select Cancel. If you are on the details page for a specific workload, use the Actions dropdown at the top of the page, and select Cancel.\n",
        "\n",
        "In Qiskit, use `job.cancel()` to cancel a job.\n",
        "\n"
      ]
    },
    {
      "cell_type": "markdown",
      "id": "c2abeb3d-4e4a-4c90-be59-16ec0e1be783",
      "metadata": {},
      "source": [
        "## Next steps\n",
        "\n",
        "<Admonition type=\"tip\" title=\"Recommendations\">\n",
        "  * Try the [Grover's algorithm](/docs/tutorials/grovers-algorithm) tutorial.\n",
        "  * Learn more about [Sampler execution spans](/docs/guides/sampler-input-output#execution-spans)\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
}