diff --git a/docs/analyze/saving-and-retrieving.ipynb b/docs/analyze/saving-and-retrieving.ipynb new file mode 100644 index 00000000000..1a7ccaefd5b --- /dev/null +++ b/docs/analyze/saving-and-retrieving.ipynb @@ -0,0 +1,269 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "539f98fa-9ccc-472a-99da-ebe6382243dc", + "metadata": {}, + "source": [ + "# Saving circuits and retrieving results\n", + "\n", + "Quantum workflows often take a while to complete so must run over many sessions. Restarting your Python kernel means you'll lose any circuits or results stored in memory. To avoid loss of data, you can save quantum circuits to file and retrieve results of past jobs from IBM Quantum so your next session can continue where you left off.\n", + "\n", + "## Saving circuits to file\n", + "\n", + "Use [QPY serialization](/api/qiskit/qpy) to save your circuit to file. QPY files save the full Qiskit circuit object and are forwards-compatible, meaning they'll be understood by newer versions of Qiskit.\n", + "\n", + "To demonstrate, the following cell creates a simple quantum circuit." + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "id": "fa58c6e1-1102-4409-80b8-01b02e4e6ee5", + "metadata": {}, + "outputs": [], + "source": [ + "from qiskit import QuantumCircuit\n", + "\n", + "qc = QuantumCircuit(2)\n", + "qc.h(0)\n", + "qc.cx(0,1)\n", + "qc.measure_all()" + ] + }, + { + "cell_type": "markdown", + "id": "d208d7a6-d465-4f08-909e-fd6803577700", + "metadata": {}, + "source": [ + "To save this file to disk, use the `qpy.dump` function. You can also save a list of circuits." + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "e02f1f2a-2705-4406-bb1c-c80d436b5110", + "metadata": {}, + "outputs": [], + "source": [ + "from qiskit import qpy\n", + "\n", + "with open('test.qpy', 'wb') as file:\n", + " qpy.dump(qc, file)" + ] + }, + { + "cell_type": "markdown", + "id": "3af68772-b488-411d-9084-14129b9a9f1d", + "metadata": {}, + "source": [ + "This circuit is now saved to the file `test.qpy`. If you restart your Python kernel, you can re-load the circuit using the `qpy.load` function. Note that this always returns a list of circuits, even if you only serialized one circuit." + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "210d05c8-c9eb-4135-bb3f-94c281708f4b", + "metadata": {}, + "outputs": [ + { + "data": { + "image/png": "iVBORw0KGgoAAAANSUhEUgAAAdIAAADuCAYAAACNr4ZUAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjguMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/H5lhTAAAACXBIWXMAAA9hAAAPYQGoP6dpAAAnnUlEQVR4nO3deVxU9f4/8NcswLAqAyibsqgoIu4bSpqGJiiSW2ne9F4rq5tG5VX6mbeyr9fcbna1bLl9Xa63yIq64VoupailqOFXAXEDE2HkDvsgIAzn9wcXrsg6c2bmMPh6Ph49ZM76nlhe8zmfz/kcmSAIAoiIiMgocqkLICIismYMUiIiIhEYpERERCIwSImIiERgkBIREYnAICUiIhKBQUpERCQCg5SIiEgEBikREZEIDFIiIiIRGKREREQiMEiJiIhEYJASERGJwCAlIiISgUFKREQkAoOUiIhIBAYpERGRCAxSIiIiERikREREIjBIiYiIRGCQEhERicAgJSIiEoFBSkREJAKDlIiISAQGKRERkQgMUiIiIhEYpERERCIopS6AiKxbcnKyQdtrtVp88803mD59Otzd3du0z7Bhw4wpjcgi2CIlIovSarX49NNPodVqpS6FyCQYpERERCIwSImIiERgkBIREYnAICUii3J2dsakSZPg7OwsdSlEJiETBEGQuggisl6Gjto1BkftUnvGFikRWVRlZSVu3ryJyspKqUshMgkGKRFZVGZmJmbMmIHMzEypSyEyCQYpERGRCJzZiJokCAJgbZfe7Owgk8mkroI6CEEQoNfrpS7DIAqFgr8DEmCQUtMqK1H9+HypqzCI8ssdgEoldRnUQej1eiQkJEhdhkFmzJgBpZJ/1i2Nl3aJiIhE4EcXIrKoPn364PTp01KXQWQybJESERGJwCAlIou6ceMGFixYgBs3bkhdCpFJMEiJyKLKy8tx8eJFlJeXS10KkUkwSImIiERgkBIREYnAICUiIhKBQUpEFuXl5YWVK1fCy8tL6lKITIL3kRKRRXXq1AmRkZFSl0F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uHr1KmxsbNC7d2/U1NQgPT0dXl5e+OMf/4gVK1Y0GGyUkpKCQYMGAQCcnZ3Ro0cPKBQKZGVl1fepbtmyBS+88IJR/38MxdYoEVHbsEXaCnd3dxw9ehTbt2/HhAkTUFZWhjNnziAzMxM9e/ZEbGwsjh49iqCgoPp9nJ2dcfz4cSxYsACurq7IyMiATqfDc889h3PnzsHHx6fReYKCgvDpp5/iiSeegJeXF65fv47z589DpVJh1qxZSEpKsliIAkCfHn6YPD6MIUpE1IoO0yIlIiKSAlukREREIjBIiYiIRGCQEhERicAgJSIiEoFBSkREJAKDlIiISAQGKRERkQgMUiIiIhEYpERERCIwSImIiERgkBIREYnAICUiIhKBQUpERCQCg5SIiEgEBikREZEIDFIiIiIRGKREREQiMEiJiIhEYJASERGJwCAlIiISgUFKREQkAoOUiIhIBAYpERGRCAxSIiIiERikREREIjBIiYiIRGCQEhERicAgJSIiEoFBSkREJAKDlIiISAQGKRERkQgMUiIiIhEYpERERCIwSImIiERgkBIREYnAICUiIhKBQUpERCQCg5SIiEgEBikREZEIDFIiIiIR/j8v9J0zDlKd+gAAAABJRU5ErkJggg==", + "text/plain": [ + "
" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "with open('test.qpy', 'rb') as handle:\n", + " qc = qpy.load(handle)\n", + "\n", + "qc[0].draw('mpl')" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "55d34ab2-1031-49e1-8aea-9794adabd0fc", + "metadata": { + "tags": [ + "remove-cell" + ] + }, + "outputs": [], + "source": [ + "# Cleanup the file we created (this cell should be hidden from the user)\n", + "import pathlib\n", + "pathlib.Path('test.qpy').unlink()" + ] + }, + { + "cell_type": "markdown", + "id": "73f23256-6519-47ae-b9e3-700f52a76711", + "metadata": {}, + "source": [ + "## Retrieving past results from IBM Quantum\n", + "\n", + "IBM Quantum automatically stores results from every job for you to retrieve at a later date. Use this feature to continue quantum programs across kernel restarts and review past results. You can get the ID of a job programatically through its `job_id` method, or you can see all your submitted jobs (and their IDs) at https://quantum.ibm.com/jobs.\n", + "\n", + "To demonstrate, the following cell sets up our Qiskit Runtime service and selects a backend." + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "id": "5f5aaa14-910f-401c-b109-73ffc2450f3c", + "metadata": {}, + "outputs": [], + "source": [ + "from qiskit_ibm_runtime import QiskitRuntimeService, SamplerV2 as Sampler\n", + "service = QiskitRuntimeService()\n", + "backend = service.least_busy(operational=True, min_num_qubits=2)\n", + "sampler = Sampler(backend=backend)" + ] + }, + { + "cell_type": "markdown", + "id": "02623345-c252-4963-be89-a074d4a10f54", + "metadata": {}, + "source": [ + "The following cell submits the job and prints its ID." + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "id": "721a5198-a650-4db9-b041-b3a569c6dc20", + "metadata": { + "tags": [ + "ignore-warnings" + ] + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "co21d77lmtfr37r4dphg\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "python3.11/site-packages/qiskit_ibm_runtime/qiskit_runtime_service.py:878: UserWarning: Cloud simulators will be deprecated on 15 May 2024. Use the new local testing mode in qiskit-ibm-runtime version 0.22.0 or later to meet your debugging needs.\n", + " warnings.warn(warning_message)\n" + ] + } + ], + "source": [ + "from qiskit import transpile\n", + "job = sampler.run(transpile(qc, backend), shots=10)\n", + "my_id = job.job_id()\n", + "print(my_id)" + ] + }, + { + "cell_type": "markdown", + "id": "fb271ce3-3e86-476c-ae4e-66df36ba7406", + "metadata": {}, + "source": [ + "Now we have the job's ID, we can retrieve it in a different session or at a later date using the `service.job` method." + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "id": "da02c7ca-803a-4426-8dd0-bbe062c0e9e1", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "PrimitiveResult([PubResult(data=DataBin<>(meas=BitArray()), metadata={'circuit_metadata': {}})], metadata={'version': 2})" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "retrieved_job = service.job(my_id)\n", + "retrieved_job.result()" + ] + }, + { + "cell_type": "markdown", + "id": "9aae5f5a-a543-493c-9bc5-5682ba846ab5", + "metadata": {}, + "source": [ + "### Programatically finding jobs\n", + "\n", + "If you don't have a job ID and want to find it programatically rather than visiting https://quantum.ibm.com/jobs, you can use the `QiskitRuntimeService.jobs` method.\n", + "\n", + "The following cell finds any jobs submitted in the last hour. The `created_after` argument must be a [`datetime.datetime`](https://docs.python.org/3.8/library/datetime.html#datetime.datetime) object." + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "id": "90133394-3259-487f-96b2-3b50e0274064", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[,\n", + " ,\n", + " ]" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "import datetime\n", + "one_hour_ago = datetime.datetime.now() - datetime.timedelta(hours=1)\n", + "\n", + "service = QiskitRuntimeService()\n", + "service.jobs(created_after=one_hour_ago)" + ] + }, + { + "cell_type": "markdown", + "id": "60405a95-8d79-4ece-9f36-47299cfa3311", + "metadata": {}, + "source": [ + "You can also select by backend, job state, session, and more. See the [API documentation](/api/qiskit-ibm-runtime/qiskit_ibm_runtime.QiskitRuntimeService#jobs) for more information." + ] + } + ], + "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": 2 +} diff --git a/docs/run/monitor-job.mdx b/docs/run/monitor-job.mdx index b09a97d26f0..4ae3d91a3db 100644 --- a/docs/run/monitor-job.mdx +++ b/docs/run/monitor-job.mdx @@ -23,7 +23,7 @@ Use the job instance to check the job status or retrieve the results by calling ## Retrieve job results at a later time -Call `service.job(\)` 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 systems, call `service.jobs()` with optional filters instead. See [QiskitRuntimeService.jobs](../api/qiskit-ibm-runtime/qiskit_ibm_runtime.QiskitRuntimeService#jobs). +Call `service.job(\)` 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 systems, call `service.jobs()` with optional filters instead. See [QiskitRuntimeService.jobs](../api/qiskit-ibm-runtime/qiskit_ibm_runtime.QiskitRuntimeService#jobs). service.jobs() returns only Qiskit Runtime jobs. To retrieve other jobs, use [qiskit-ibm-provider](../api/qiskit-ibm-provider/qiskit_ibm_provider.IBMBackend#ibmbackend) instead. diff --git a/scripts/nb-tester/test-notebook.py b/scripts/nb-tester/test-notebook.py index eef1864b5b0..64d9657b98e 100644 --- a/scripts/nb-tester/test-notebook.py +++ b/scripts/nb-tester/test-notebook.py @@ -32,6 +32,7 @@ ] NOTEBOOKS_THAT_SUBMIT_JOBS = [ "docs/start/hello-world.ipynb", + "docs/analyze/saving-and-retrieving.ipynb", ]