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

Fit new notebooks into existing content #1160

Merged
merged 6 commits into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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
499 changes: 0 additions & 499 deletions docs/build-new/circuit-visualization.ipynb

This file was deleted.

4 changes: 4 additions & 0 deletions docs/build/_toc.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@
{
"title": "Bit-ordering in the Qiskit SDK",
"url": "/build/bit-ordering"
},
{
"title": "Save circuits to disk",
"url": "/build/save-circuits"
}
]
},
Expand Down
1,224 changes: 120 additions & 1,104 deletions docs/build/circuit-visualization.ipynb

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@
"id": "539f98fa-9ccc-472a-99da-ebe6382243dc",
"metadata": {},
"source": [
"# Save and retrieve Qiskit objects\n",
"\n",
"Quantum workflows often take a while to complete and can 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",
"## Save circuits to file\n",
"# Save circuits to disk\n",
"\n",
"Use [QPY serialization](/api/qiskit/qpy) to save your circuit to file. QPY files store the full Qiskit circuit object and will be compatible with newer versions of Qiskit (although not necessarily with older versions of Qiskit).\n",
"\n",
Expand Down Expand Up @@ -102,228 +98,6 @@
"import pathlib\n",
"pathlib.Path('test.qpy').unlink()"
]
},
{
"cell_type": "markdown",
"id": "73f23256-6519-47ae-b9e3-700f52a76711",
"metadata": {},
"source": [
"## Retrieve jobs 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 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 demonstrate, the following cell sets up the 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": [
"co24umeh1p25p1m5nu7g\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"/Users/qiskit/.venv/python3.11/site-packages/qiskit_ibm_runtime/qiskit_runtime_service.py:879: 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 that you have the job's ID, you 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(<shape=(), num_shots=10, num_bits=2>)), 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": [
"### Programmatically find jobs\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."
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "90133394-3259-487f-96b2-3b50e0274064",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[<RuntimeJob('co24umeh1p25p1m5nu7g', 'sampler')>,\n",
" <RuntimeJob('cr24smydvs8g008jejs0', 'sampler')>]"
]
},
"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. For more information, see [`QiskitRuntimeService.jobs`](/api/qiskit-ibm-runtime/qiskit_ibm_runtime.QiskitRuntimeService#jobs) in the API documentation."
]
},
{
"cell_type": "markdown",
"id": "211b8c15-5aa3-43f6-82ee-2bd1d49ae8fc",
"metadata": {},
"source": [
"## Save results to disk\n",
"\n",
"You may also want to save results to disk. To do this, use Python's built-in JSON library with Qiskit IBM Runtime's encoders."
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "3a3ff817-01c1-47e8-94c6-1ecf2215ef7c",
"metadata": {},
"outputs": [],
"source": [
"import json\n",
"from qiskit_ibm_runtime import RuntimeEncoder\n",
"with open(\"result.json\", \"w\") as file:\n",
" json.dump(job.result(), file, cls=RuntimeEncoder)"
]
},
{
"cell_type": "markdown",
"id": "40a9d8e5-c876-47a7-862e-d2ce535a6052",
"metadata": {},
"source": [
"You can then load this array from disk in a separate kernel."
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "316aa6f7-faee-4a05-a7b4-02d7bee4d58a",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([[3],\n",
" [3],\n",
" [3],\n",
" [3],\n",
" [0],\n",
" [3],\n",
" [0],\n",
" [3],\n",
" [0],\n",
" [3]], dtype=uint8)"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from qiskit_ibm_runtime import RuntimeDecoder\n",
"with open(\"result.json\", \"r\") as file:\n",
" result = json.load(file, cls=RuntimeDecoder)\n",
"\n",
"result[0].data.meas.array # access measurement data"
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "eae94b73-157b-4751-8dd3-add4cc9efec6",
"metadata": {
"tags": [
"remove-cell"
]
},
"outputs": [],
"source": [
"# Cleanup the file we created (this cell should be hidden from the user)\n",
"pathlib.Path('result.json').unlink()"
]
}
],
"metadata": {
Expand Down
10 changes: 9 additions & 1 deletion docs/run/_toc.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,21 @@
{
"title": "Maximum execution time",
"url": "/run/max-execution-time"
},
{
"title": "Save and retrieve jobs",
"url": "/run/save-jobs"
}
]
},
{
"title": "Quantum Serverless workloads",
"url": "/run/quantum-serverless"
},
{
"title": "Visualize results",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should go above quantum serverless in the side bar

"url": "/run/visualize-results"
},
{
"title": "Hardware",
"children": [
Expand Down Expand Up @@ -129,4 +137,4 @@
]
}
]
}
}
Loading
Loading