Skip to content
Draft
Show file tree
Hide file tree
Changes from all 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
142 changes: 77 additions & 65 deletions docs/guides/serverless-first-program.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "markdown",
"id": "e17b430a-ec17-4a88-9a71-9ce365059bea",
"id": "cdc8dc1e-0cff-46c1-94d0-97456d278e27",
"metadata": {},
"source": [
"---\n",
Expand All @@ -16,7 +16,7 @@
},
{
"cell_type": "markdown",
"id": "90e824fb-dcf6-4a8b-9808-d66aa9bfb3b5",
"id": "b6d632cb-d884-4963-9c8d-8f3a3acd8a7d",
"metadata": {
"tags": [
"version-info"
Expand Down Expand Up @@ -48,28 +48,16 @@
},
{
"cell_type": "markdown",
"id": "b32bff85-1760-4296-8f5b-ea6e5c942bbe",
"id": "1cc46aeb-aff6-4fab-9d78-69f2bfe98d98",
"metadata": {},
"source": [
"This example demonstrates how to use `qiskit-serverless` tools to create a parallel transpilation program, and then implement `qiskit-ibm-catalog` to deploy your program to IBM Quantum Platform to use as a reusable remote service."
]
},
{
"cell_type": "markdown",
"id": "e3603a5c-78f4-40ec-9568-7a45664acfc7",
"metadata": {},
"source": [
"## Example: remote transpilation with Qiskit Serverless\n",
"\n",
"Start with the following example that transpiles a `circuit` against a given `backend` and target `optimization_level`, and gradually add more elements to deploy your workload to Qiskit Serverless.\n",
"\n",
"Put the following code cell in the file `./source_files/transpile_remote.py`. This file is the program to upload to Qiskit Serverless."
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "21ea3269-1946-40b4-9c0f-9431003c2d0b",
"execution_count": 2,
"id": "b186515d-7686-43c3-94a6-187eba0808b9",
"metadata": {
"editable": true,
"slideshow": {
Expand All @@ -87,10 +75,36 @@
"Path(\"./source_files\").mkdir(exist_ok=True)"
]
},
{
"cell_type": "markdown",
"id": "cad16f43-8548-4849-a4b8-09059a8b747c",
"metadata": {},
"source": [
"## Example: remote transpilation with Qiskit Serverless\n",
"\n",
"Start with the following example that transpiles a `circuit` against a given `backend` and target `optimization_level`, and gradually add more elements to deploy your workload to Qiskit Serverless.\n",
"\n",
"Serverless uploads the contents of a specific directory (in this example, the `source_files` directory) to run remotely. Once these are set up, you can adjust `transpile_remote.py` to fetch inputs and return outputs.\n",
"\n",
"<Admonition type=\"tip\">\n",
"Qiskit Serverless requires setting up your workload’s `.py` files into a dedicated directory. The following structure is an example of good practice:\n",
"\n",
"```text\n",
"serverless_program\n",
"├── program_uploader.ipynb\n",
"└── source_files\n",
" ├── transpile_remote.py\n",
" └── *.py\n",
"```\n",
"</Admonition>\n",
"\n",
"First, run the following code cell to create a program file, `./source_files/transpile_remote.py`, which you will upload to Qiskit Serverless."
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "4b550093-1d73-4c15-905a-0caa12f7dcbe",
"execution_count": 3,
"id": "64722041-22ed-42bd-8d83-d8e9f5e5b55b",
"metadata": {
"editable": true,
"slideshow": {
Expand Down Expand Up @@ -124,32 +138,20 @@
},
{
"cell_type": "markdown",
"id": "ea182474-7566-4a13-96d8-cfcc8f16dd8f",
"id": "7e80b5bb-0f76-43d1-a68c-97b4b22cc88a",
"metadata": {},
"source": [
"## Set up your files\n",
"\n",
"Qiskit Serverless requires setting up your workload’s `.py` files into a dedicated directory. The following structure is an example of good practice:\n",
"\n",
"```text\n",
"serverless_program\n",
"├── program_uploader.ipynb\n",
"└── source_files\n",
" ├── transpile_remote.py\n",
" └── *.py\n",
"```\n",
"\n",
"Serverless uploads the contents of `source_files` to run remotely. Once these are set up, you can adjust `transpile_remote.py` to fetch inputs and return outputs.\n",
"\n",
"### Get program arguments\n",
"\n",
"Your initial `transpile_remote.py` has three inputs: `circuits`, `backend_name`, and `optimization_level`. Serverless is currently limited to only accept serializable inputs and outputs. For this reason, you cannot pass in `backend` directly, so use `backend_name` as a string instead."
"Your initial `transpile_remote.py` has three inputs: `circuits`, `backend_name`, and `optimization_level`. Serverless is currently limited to only accept serializable inputs and outputs. For this reason, you cannot pass in `backend` directly, so use `backend_name` as a string instead.\n",
"\n",
"The following cell appends code to your `transpile_remote.py` file."
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "54a8d2c6-a3f4-4169-9210-dd213e2273d2",
"execution_count": 4,
"id": "6819379b-d7b2-4fda-9e6b-459eec748a79",
"metadata": {},
"outputs": [
{
Expand All @@ -174,16 +176,16 @@
},
{
"cell_type": "markdown",
"id": "bf57e8a8-4f64-4933-978d-c16bda4e0c0c",
"id": "5ae9fb12-f06f-4f7d-8f37-1d872285deab",
"metadata": {},
"source": [
"At this point, you can get your backend with `QiskitRuntimeService` and add your existing program with the following code. The following code requires that you have already [saved your credentials](/docs/guides/cloud-setup)."
"At this point, you can get your backend with `QiskitRuntimeService` and add your existing program with the following code. The following code requires that you have already [saved your credentials](/docs/guides/save-credentials)."
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "7077ba00-1571-4f99-8c53-b1a9ac280987",
"execution_count": 5,
"id": "4b0c7d24-9b87-4e00-bb1d-f82aa967cb1d",
"metadata": {},
"outputs": [
{
Expand All @@ -205,16 +207,16 @@
},
{
"cell_type": "markdown",
"id": "8bd63bfc-0da5-46de-ace5-8463b5ad92f3",
"id": "61e7cb3b-6d62-4b68-817a-39c0c1d95a9b",
"metadata": {},
"source": [
"Finally, you can run `transpile_remote()` across all `circuits` passed in, and return the `transpiled_circuits` as a result:"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "afdb6896-93b8-4006-b27b-49ebb16e7c1c",
"execution_count": 6,
"id": "041e7f85-e9e8-424d-8694-d54316225cc4",
"metadata": {},
"outputs": [
{
Expand All @@ -240,22 +242,22 @@
},
{
"cell_type": "markdown",
"id": "a05fa201-aabb-43a5-8a6a-f53c5c664fc4",
"id": "dac118ab-e447-4ddd-a5f8-d13e3953db76",
"metadata": {},
"source": [
"## Deploy to IBM Quantum Platform\n",
"\n",
"The previous section created a program to be run remotely. The code cells in this section upload that program to Qiskit Serverless.\n",
"The previous section created a program to be run remotely. The following code cells upload that program to Qiskit Serverless, before running the workload (which is demonstrated in the [Run your first Qiskit Serverless workload remotely](/docs/guides/serverless-run-first-workload) guide).\n",
"\n",
"Use `qiskit-ibm-catalog` to authenticate to `QiskitServerless` with your API key, which you can find on the [IBM Quantum dashboard](https://quantum.cloud.ibm.com), and upload the program.\n",
"\n",
"You can use `save_account()` to save your credentials (See the [Set up to use IBM Cloud](/docs/guides/cloud-setup#cloud-save) section). Note that this writes your credentials to the same file as [`QiskitRuntimeService.save_account()`](/docs/api/qiskit-ibm-runtime/qiskit-runtime-service#save_account)."
"You can use `save_account()` to [save your Qiskit Serverless credentials](/docs/guides/save-credentials) in the same way you saved your Qiskit Runtime credentials. Note that this writes your credentials to the same file as [`QiskitRuntimeService.save_account()`](/docs/api/qiskit-ibm-runtime/qiskit-runtime-service#save_account)."
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "cc9d5267-8019-4543-ab6a-679583d26340",
"execution_count": 13,
"id": "8d1385c3-09a5-42c6-a5bc-53f686d8410e",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -267,16 +269,16 @@
},
{
"cell_type": "markdown",
"id": "7e8327dc-9105-4fb0-9cf0-c6e13ca32674",
"id": "a0f64820-5fb1-41b9-9cb4-5095d0b5db43",
"metadata": {},
"source": [
"Qiskit Serverless compresses the contents of `working_dir` (in this case, `source_files`) into a `tar`, which is uploaded and cleaned up after. The `entrypoint` identifies the main program executable for Qiskit Serverless to run. Additionally, if your program has custom `pip` dependencies, you can add them to a `dependencies` array:"
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@pandasa123 what does a dependencies array look like? The previous sentence implies it is included in the example.

]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "62738969-b19c-484e-8591-4f89c99990ed",
"execution_count": 8,
"id": "c1cdd46d-71e9-4711-a09b-6eca569ede6a",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -289,8 +291,8 @@
},
{
"cell_type": "code",
"execution_count": 8,
"id": "ed72ee48-a643-4d2e-b245-6e9ab3673ddb",
"execution_count": 9,
"id": "8b675d04-bde8-4b3d-b9e5-99982ef742e1",
"metadata": {},
"outputs": [
{
Expand All @@ -299,7 +301,7 @@
"QiskitFunction(transpile_remote_serverless)"
]
},
"execution_count": 8,
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -310,16 +312,16 @@
},
{
"cell_type": "markdown",
"id": "9a22d507-2489-4f2f-af78-c9249ed3fc3d",
"id": "3a840c18-3010-4d05-91cb-592e2692c1d7",
"metadata": {},
"source": [
"To check if it successfully uploaded, use `serverless.list()`:"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "ff7d8283-ee72-4167-8a8a-1f07367ba6ef",
"execution_count": 10,
"id": "afaa3935-adf7-4b28-a8f0-583a82bbe3f1",
"metadata": {},
"outputs": [
{
Expand All @@ -328,7 +330,7 @@
"QiskitFunction(transpile_remote_serverless)"
]
},
"execution_count": 9,
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -344,8 +346,8 @@
},
{
"cell_type": "code",
"execution_count": 10,
"id": "7fee3152-025d-4df6-8299-591fe0482dac",
"execution_count": 11,
"id": "484713e3-b6ac-4a7a-9425-e9ac34b1bb6e",
"metadata": {
"tags": [
"remove-cell"
Expand All @@ -359,8 +361,8 @@
},
{
"cell_type": "code",
"execution_count": 11,
"id": "f0730886-1d67-4d1b-9ab2-133cbcfc7e49",
"execution_count": 12,
"id": "413e5d94-00f6-4c47-80d0-b5c4441934fc",
"metadata": {
"tags": [
"remove-cell"
Expand Down Expand Up @@ -394,7 +396,17 @@
},
{
"cell_type": "markdown",
"id": "f8940b98-33f7-4029-ac77-60058c4aee78",
"id": "6ff556c1-64bb-41ae-9c6c-9019a3cab9ca",
"metadata": {},
"source": [
"<Admonition type=\"tip\">\n",
"Currently, the IBM Quantum workloads table only reflects Qiskit Runtime workloads. The [Run your first Qiskit Serverless workload remotely](/docs/guides/serverless-run-first-workload#serverless-job-status) guide demonstrates how to use `job.status()` to see your Qiskit Serverless workload's current status.\n",
"</Admonition>"
]
},
{
"cell_type": "markdown",
"id": "a416b143-6f70-49dc-ab2f-ad66f042cab1",
"metadata": {},
"source": [
"## Next steps\n",
Expand Down Expand Up @@ -427,5 +439,5 @@
}
},
"nbformat": 4,
"nbformat_minor": 2
"nbformat_minor": 4
}
1 change: 1 addition & 0 deletions docs/guides/serverless-run-first-workload.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@
"id": "87dbb375-cd24-4d0f-a2fc-c653db8345e3",
"metadata": {},
"source": [
"<span id=\"serverless-job-status\"></span>\n",
"## Check job status\n",
"\n",
"With your Qiskit Serverless `job_id`, you can check the status of running jobs. This includes the following statuses:\n",
Expand Down
Loading