From df59afbdb01d9d24995b19f4a82e517f26f50f9a Mon Sep 17 00:00:00 2001 From: Frank Harkins Date: Fri, 19 Apr 2024 11:33:43 +0100 Subject: [PATCH 1/6] Reorganise page to get `job_id` programatically first This lets us avoid hardcoding the `job_id`, which means anyone can run the notebook successfully (rather than just Frank). --- docs/run/save-jobs.ipynb | 45 +++++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/docs/run/save-jobs.ipynb b/docs/run/save-jobs.ipynb index 27422078f5f..ae0d9e2c675 100644 --- a/docs/run/save-jobs.ipynb +++ b/docs/run/save-jobs.ipynb @@ -19,7 +19,7 @@ "\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 programmatically through its `job_id` method, or you can see all your submitted jobs and their IDs through the [Jobs dashboard](https://quantum.ibm.com/jobs).\n", "\n", - "Once you have the job ID, use the `QiskitRuntimeService.jobs` method to retrieve it." + "To find a job programatically, use the [`QiskitRuntimeService.jobs`](/api/qiskit-ibm-runtime/qiskit_ibm_runtime.QiskitRuntimeService#jobs) method. The following cell finds any jobs submitted in the last day. The `created_after` argument must be a [`datetime.datetime`](https://docs.python.org/3.8/library/datetime.html#datetime.datetime) object." ] }, { @@ -31,7 +31,10 @@ { "data": { "text/plain": [ - "PrimitiveResult([PubResult(data=DataBin(meas=BitArray()), metadata={'circuit_metadata': {}})], metadata={'version': 2})" + "[,\n", + " ,\n", + " ,\n", + " ]" ] }, "execution_count": 1, @@ -40,11 +43,13 @@ } ], "source": [ + "import datetime\n", "from qiskit_ibm_runtime import QiskitRuntimeService\n", "\n", + "one_day_ago = datetime.datetime.now() - datetime.timedelta(days=1)\n", + "\n", "service = QiskitRuntimeService()\n", - "retrieved_job = service.job(\"cogiau7imm49f6et38a0\")\n", - "retrieved_job.result()" + "service.jobs(created_after=one_day_ago)" ] }, { @@ -52,11 +57,20 @@ "id": "9aae5f5a-a543-493c-9bc5-5682ba846ab5", "metadata": {}, "source": [ - "### Programmatically find jobs\n", + "You can also select by backend, job state, session, and more. For more information, see [`QiskitRuntimeService.jobs`](/api/qiskit-ibm-runtime/qiskit_ibm_runtime.QiskitRuntimeService#jobs) in the API documentation.\n", "\n", - "If you don't have a job ID and want to find it programmatically rather than visiting the [Jobs dashboard](https://quantum.ibm.com/jobs), you can use the [`QiskitRuntimeService.jobs`](/api/qiskit-ibm-runtime/qiskit_ibm_runtime.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." + "Once you have the job ID, use the [`QiskitRuntimeService.job`](/api/qiskit-ibm-runtime/qiskit_ibm_runtime.QiskitRuntimeService#job) method to retrieve it." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# Get ID of last job for demonstration\n", + "job_id = service.jobs()[0].job_id()\n", + "print(job_id)" ] }, { @@ -80,19 +94,8 @@ } ], "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. For more information, see [`QiskitRuntimeService.jobs`](/api/qiskit-ibm-runtime/qiskit_ibm_runtime.QiskitRuntimeService#jobs) in the API documentation." + "retrieved_job = service.job(job_id)\n", + "retrieved_job.result()" ] }, { From 9b2e3f224c2f170ecc9d37930f6813fe1acaef7d Mon Sep 17 00:00:00 2001 From: Frank Harkins Date: Fri, 19 Apr 2024 11:35:43 +0100 Subject: [PATCH 2/6] Re-run notebook --- docs/run/save-jobs.ipynb | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/docs/run/save-jobs.ipynb b/docs/run/save-jobs.ipynb index ae0d9e2c675..c27bcd711fc 100644 --- a/docs/run/save-jobs.ipynb +++ b/docs/run/save-jobs.ipynb @@ -64,9 +64,18 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, + "id": "43d0f06e-f97f-4c19-b242-02cb0bd420a9", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "cogiau7imm49f6et38a0\n" + ] + } + ], "source": [ "# Get ID of last job for demonstration\n", "job_id = service.jobs()[0].job_id()\n", @@ -75,20 +84,17 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 3, "id": "90133394-3259-487f-96b2-3b50e0274064", "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "[,\n", - " ,\n", - " ,\n", - " ]" + "PrimitiveResult([PubResult(data=DataBin(meas=BitArray()), metadata={'circuit_metadata': {}})], metadata={'version': 2})" ] }, - "execution_count": 2, + "execution_count": 3, "metadata": {}, "output_type": "execute_result" } @@ -110,7 +116,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 4, "id": "3a3ff817-01c1-47e8-94c6-1ecf2215ef7c", "metadata": {}, "outputs": [], @@ -131,7 +137,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 5, "id": "316aa6f7-faee-4a05-a7b4-02d7bee4d58a", "metadata": {}, "outputs": [ @@ -150,7 +156,7 @@ " [3]], dtype=uint8)" ] }, - "execution_count": 4, + "execution_count": 5, "metadata": {}, "output_type": "execute_result" } @@ -165,7 +171,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 6, "id": "eae94b73-157b-4751-8dd3-add4cc9efec6", "metadata": { "tags": [ From 71b420f2c5969d07d23b05b907424e489be96bbc Mon Sep 17 00:00:00 2001 From: Frank Harkins Date: Fri, 19 Apr 2024 14:10:31 +0100 Subject: [PATCH 3/6] Add note for case in which user has never submitted any jobs --- docs/run/save-jobs.ipynb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/run/save-jobs.ipynb b/docs/run/save-jobs.ipynb index c27bcd711fc..abeedae07f4 100644 --- a/docs/run/save-jobs.ipynb +++ b/docs/run/save-jobs.ipynb @@ -77,7 +77,8 @@ } ], "source": [ - "# Get ID of last job for demonstration\n", + "# Get ID of last job for demonstration.\n", + "# This will not work if you've never submitted a job.\n", "job_id = service.jobs()[0].job_id()\n", "print(job_id)" ] From 3ea07e95a5be1ab1bc2b57c9a3348dce5a6f3d7b Mon Sep 17 00:00:00 2001 From: Frank Harkins Date: Fri, 19 Apr 2024 19:03:36 +0100 Subject: [PATCH 4/6] Change code to get results from last 90 days --- docs/run/save-jobs.ipynb | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/docs/run/save-jobs.ipynb b/docs/run/save-jobs.ipynb index abeedae07f4..146673566df 100644 --- a/docs/run/save-jobs.ipynb +++ b/docs/run/save-jobs.ipynb @@ -19,7 +19,7 @@ "\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 programmatically through its `job_id` method, or you can see all your submitted jobs and their IDs through the [Jobs dashboard](https://quantum.ibm.com/jobs).\n", "\n", - "To find a job programatically, use the [`QiskitRuntimeService.jobs`](/api/qiskit-ibm-runtime/qiskit_ibm_runtime.QiskitRuntimeService#jobs) method. The following cell finds any jobs submitted in the last day. The `created_after` argument must be a [`datetime.datetime`](https://docs.python.org/3.8/library/datetime.html#datetime.datetime) object." + "To find a job programatically, use the [`QiskitRuntimeService.jobs`](/api/qiskit-ibm-runtime/qiskit_ibm_runtime.QiskitRuntimeService#jobs) method. By default, this returns the most recent jobs, but you can also filter jobs by backend name, creation date, and more. The following cell finds any jobs submitted in the last year. The `created_after` argument must be a [`datetime.datetime`](https://docs.python.org/3.8/library/datetime.html#datetime.datetime) object." ] }, { @@ -46,10 +46,11 @@ "import datetime\n", "from qiskit_ibm_runtime import QiskitRuntimeService\n", "\n", - "one_day_ago = datetime.datetime.now() - datetime.timedelta(days=1)\n", + "three_months_ago = datetime.datetime.now() - datetime.timedelta(days=90)\n", "\n", "service = QiskitRuntimeService()\n", - "service.jobs(created_after=one_day_ago)" + "jobs_in_last_three_months = service.jobs(created_after=three_months_ago)\n", + "jobs_in_last_three_months[:3] # show first three jobs" ] }, { @@ -77,7 +78,7 @@ } ], "source": [ - "# Get ID of last job for demonstration.\n", + "# Get ID of most recent job for demonstration.\n", "# This will not work if you've never submitted a job.\n", "job_id = service.jobs()[0].job_id()\n", "print(job_id)" From 0671fdda9e53e97f4c58533087dd9aa511f3d9f1 Mon Sep 17 00:00:00 2001 From: Frank Harkins Date: Fri, 19 Apr 2024 19:03:44 +0100 Subject: [PATCH 5/6] re-run notebook --- docs/run/save-jobs.ipynb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/docs/run/save-jobs.ipynb b/docs/run/save-jobs.ipynb index 146673566df..5b3fd4d9af4 100644 --- a/docs/run/save-jobs.ipynb +++ b/docs/run/save-jobs.ipynb @@ -33,8 +33,7 @@ "text/plain": [ "[,\n", " ,\n", - " ,\n", - " ]" + " ]" ] }, "execution_count": 1, From d6049ec4e34443960cd959f184cf907b68c9b000 Mon Sep 17 00:00:00 2001 From: Frank Harkins Date: Fri, 19 Apr 2024 22:05:40 +0100 Subject: [PATCH 6/6] Update docs/run/save-jobs.ipynb Co-authored-by: Eric Arellano <14852634+Eric-Arellano@users.noreply.github.com> --- docs/run/save-jobs.ipynb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/run/save-jobs.ipynb b/docs/run/save-jobs.ipynb index 5b3fd4d9af4..27a2ed616e1 100644 --- a/docs/run/save-jobs.ipynb +++ b/docs/run/save-jobs.ipynb @@ -19,7 +19,7 @@ "\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 programmatically through its `job_id` method, or you can see all your submitted jobs and their IDs through the [Jobs dashboard](https://quantum.ibm.com/jobs).\n", "\n", - "To find a job programatically, use the [`QiskitRuntimeService.jobs`](/api/qiskit-ibm-runtime/qiskit_ibm_runtime.QiskitRuntimeService#jobs) method. By default, this returns the most recent jobs, but you can also filter jobs by backend name, creation date, and more. The following cell finds any jobs submitted in the last year. The `created_after` argument must be a [`datetime.datetime`](https://docs.python.org/3.8/library/datetime.html#datetime.datetime) object." + "To find a job programatically, use the [`QiskitRuntimeService.jobs`](/api/qiskit-ibm-runtime/qiskit_ibm_runtime.QiskitRuntimeService#jobs) method. By default, this returns the most recent jobs, but you can also filter jobs by backend name, creation date, and more. The following cell finds any jobs submitted in the last three months. The `created_after` argument must be a [`datetime.datetime`](https://docs.python.org/3.8/library/datetime.html#datetime.datetime) object." ] }, {