Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reorganise "Save jobs" page #1203

Merged
merged 6 commits into from
Apr 19, 2024
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 40 additions & 30 deletions docs/run/save-jobs.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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."
]
},
{
Expand All @@ -31,7 +31,10 @@
{
"data": {
"text/plain": [
"PrimitiveResult([PubResult(data=DataBin(meas=BitArray(<shape=(), num_shots=10, num_bits=2>)), metadata={'circuit_metadata': {}})], metadata={'version': 2})"
"[<RuntimeJob('cogiau7imm49f6et38a0', 'sampler')>,\n",
" <RuntimeJob('crgja91qzd5000886v60', 'sampler')>,\n",
" <RuntimeJob('cogi9gftcirtooeunfe0', 'sampler')>,\n",
" <RuntimeJob('cogi8qqai5rk2r0u9bu0', 'sampler')>]"
]
},
"execution_count": 1,
Expand All @@ -40,59 +43,66 @@
}
],
"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)"
]
},
{
"cell_type": "markdown",
"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": 2,
"id": "43d0f06e-f97f-4c19-b242-02cb0bd420a9",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"cogiau7imm49f6et38a0\n"
]
}
],
"source": [
"# 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)"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "90133394-3259-487f-96b2-3b50e0274064",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[<RuntimeJob('cogiau7imm49f6et38a0', 'sampler')>,\n",
" <RuntimeJob('crgja91qzd5000886v60', 'sampler')>,\n",
" <RuntimeJob('cogi9gftcirtooeunfe0', 'sampler')>,\n",
" <RuntimeJob('cogi8qqai5rk2r0u9bu0', 'sampler')>]"
"PrimitiveResult([PubResult(data=DataBin(meas=BitArray(<shape=(), num_shots=10, num_bits=2>)), metadata={'circuit_metadata': {}})], metadata={'version': 2})"
]
},
"execution_count": 2,
"execution_count": 3,
"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. 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()"
]
},
{
Expand All @@ -107,7 +117,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 4,
"id": "3a3ff817-01c1-47e8-94c6-1ecf2215ef7c",
"metadata": {},
"outputs": [],
Expand All @@ -128,7 +138,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 5,
"id": "316aa6f7-faee-4a05-a7b4-02d7bee4d58a",
"metadata": {},
"outputs": [
Expand All @@ -147,7 +157,7 @@
" [3]], dtype=uint8)"
]
},
"execution_count": 4,
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -162,7 +172,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 6,
"id": "eae94b73-157b-4751-8dd3-add4cc9efec6",
"metadata": {
"tags": [
Expand Down
Loading