Skip to content
Open
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
10 changes: 3 additions & 7 deletions docs/guides/function-template-chemistry-workflow.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -1185,8 +1185,8 @@
"from qiskit_addon_sqd.fermion import bitstring_matrix_to_ci_strs\n",
"from qiskit_addon_sqd.subsampling import postselect_and_subsample\n",
"\n",
"from qiskit_ibm_runtime import QiskitRuntimeService, SamplerV2\n",
"from qiskit_serverless import get_arguments, save_result, distribute_task, get, update_status, Job\n",
"from qiskit_ibm_runtime import SamplerV2\n",
"from qiskit_serverless import get_arguments, save_result, distribute_task, get, update_status, Job, get_runtime_service\n",
"\n",
"current_dir = os.path.dirname(os.path.abspath(__file__))\n",
"sys.path.insert(0, current_dir)\n",
Expand Down Expand Up @@ -1318,11 +1318,7 @@
" if testing_backend is None:\n",
" # Initialize Quantum Compute Service\n",
" logger.info(\"Starting runtime service\")\n",
" service = QiskitRuntimeService(\n",
" channel=os.environ[\"QISKIT_IBM_CHANNEL\"],\n",
" instance=os.environ[\"IBM_CLOUD_INSTANCE\"],\n",
" token=os.environ[\"your-API_KEY\"], # Use the 44-character API_KEY you created and saved from the IBM Quantum Platform Home dashboard\n",
" )\n",
" service = get_runtime_service()\n",
" backend = service.backend(backend_name)\n",
" logger.info(f\"Backend: {backend.name}\")\n",
"\n",
Expand Down
7 changes: 4 additions & 3 deletions docs/guides/function-template-hamiltonian-simulation.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -455,10 +455,10 @@
"source": [
"%%writefile --append ./source_files/template_hamiltonian_simulation.py\n",
"\n",
"from qiskit_ibm_runtime import QiskitRuntimeService\n",
"from qiskit_serverless import get_runtime_service\n",
"from qiskit.transpiler import generate_preset_pass_manager\n",
"\n",
"service = QiskitRuntimeService()\n",
"service = get_runtime_service()\n",
"backend = service.backend(backend_name)\n",
"\n",
"# Transpile PUBs (circuits and observables) to match ISA\n",
Expand Down Expand Up @@ -1339,8 +1339,9 @@
"\n",
"from qiskit.transpiler import generate_preset_pass_manager\n",
"from qiskit_ibm_catalog import QiskitFunctionsCatalog\n",
"from qiskit_serverless import get_runtime_service\n",
"\n",
"service = QiskitRuntimeService()\n",
"service = get_runtime_service()\n",
"backend = service.backend(backend_name)\n",
"\n",
"# Transpile PUBs (circuits and observables) to match ISA\n",
Expand Down
16 changes: 12 additions & 4 deletions docs/guides/serverless-first-program.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"qiskit[all]~=1.3.1\n",
"qiskit-ibm-runtime~=0.34.0\n",
"qiskit-aer~=0.15.1\n",
"qiskit-serverless~=0.18.1\n",
"qiskit-serverless~=0.27.0\n",
"qiskit-ibm-catalog~=0.2\n",
"qiskit-addon-sqd~=0.8.1\n",
"qiskit-addon-utils~=0.1.0\n",
Expand Down Expand Up @@ -192,7 +192,15 @@
"source": [
"### Add code that calls the backend\n",
"\n",
"Add the following code to your program file, which calls your backend with `QiskitRuntimeService`.\n",
"Add the following code to your program file, which gets a runtime service and uses it to select your backend.\n",
"\n",
"<Admonition type=\"note\" title=\"Use get_runtime_service inside Qiskit Serverless programs\">\n",
"Inside code that runs on Qiskit Serverless, create your runtime service with `get_runtime_service()` (imported from `qiskit_serverless`) instead of instantiating `QiskitRuntimeService()` directly.\n",
"\n",
"`get_runtime_service()` returns a drop-in wrapper around `QiskitRuntimeService` that registers every IBM Quantum primitive job and session it launches against the parent Qiskit Serverless job. This linkage is what lets the platform tie a Serverless job to the QPU jobs and sessions it spawns, for status tracking, logs, and usage and accounting. A bare `QiskitRuntimeService` submits jobs that the platform never associates with your Serverless job, so that linkage is lost.\n",
"\n",
"All arguments are optional. Inside program source, the recommended form is `get_runtime_service()` with no arguments, which pulls your authentication data from the environment. It accepts the same optional `channel`, `token`, `instance`, and `url` arguments as `QiskitRuntimeService`.\n",
"</Admonition>\n",
"\n",
"The following code assumes that you have already followed the process to save your credentials by using `QiskitRuntimeService.save_account`, and will load your default saved account unless you specify otherwise. See [Save your login credentials](/docs/guides/save-credentials) and [Initialize your IBM Quantum Compute Service account](/docs/guides/initialize-account) for more information."
]
Expand All @@ -208,9 +216,9 @@
"# If you include the preceding `%%writefile` command (visible only when you read this\n",
"# locally in a notebook), running this cell saves to disk rather than executing the code.\n",
"\n",
"from qiskit_ibm_runtime import QiskitRuntimeService\n",
"from qiskit_serverless import get_runtime_service\n",
"\n",
"service = QiskitRuntimeService()\n",
"service = get_runtime_service()\n",
"backend = service.backend(backend_name)"
]
},
Expand Down
9 changes: 4 additions & 5 deletions docs/guides/serverless-manage-resources.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"```\n",
"qiskit[all]~=2.0.0\n",
"qiskit-ibm-runtime~=0.37.0\n",
"qiskit-serverless~=0.22.0\n",
"qiskit-serverless~=0.27.0\n",
"```\n",
"</AccordionItem>\n",
"</Accordion>"
Expand Down Expand Up @@ -148,7 +148,7 @@
"\n",
"For classical tasks that can be parallelized, use the `@distribute_task` decorator to define compute requirements needed to perform a task. Start by recalling the `transpile_remote.py` example from the [Write your first Qiskit Serverless program](/docs/guides/serverless-first-program) topic with the following code.\n",
"\n",
"The following code requires that you have already [saved your credentials](/docs/guides/cloud-setup)."
"The following code requires that you have already [saved your credentials](/docs/guides/cloud-setup). As in that example, it creates the runtime service with `get_runtime_service()` so that any Qiskit Runtime jobs and sessions it launches are tracked against the parent Qiskit Serverless job. See [Write your first Qiskit Serverless program](/docs/guides/serverless-first-program) for details."
]
},
{
Expand All @@ -172,10 +172,9 @@
"# notebook), running this cell saves to disk rather than executing the code.\n",
"\n",
"from qiskit.transpiler import generate_preset_pass_manager\n",
"from qiskit_ibm_runtime import QiskitRuntimeService\n",
"from qiskit_serverless import distribute_task\n",
"from qiskit_serverless import distribute_task, get_runtime_service\n",
"\n",
"service = QiskitRuntimeService()\n",
"service = get_runtime_service()\n",
"\n",
"@distribute_task(target={\"cpu\": 1})\n",
"def transpile_remote(circuit, optimization_level, backend):\n",
Expand Down
9 changes: 6 additions & 3 deletions docs/guides/serverless-port-code.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@
"\n",
"## Update the experiment\n",
"\n",
"<Admonition type=\"note\">\n",
"In the Serverless version, create the runtime service with `get_runtime_service()` (from `qiskit_serverless`) instead of `QiskitRuntimeService()`, so that the IBM Quantum&reg; Compute Service jobs and sessions it launches are tracked against the parent Qiskit Serverless job. See [Write your first Qiskit Serverless program](/docs/guides/serverless-first-program) for details.\n",
"</Admonition>\n",
"\n",
"<Tabs>\n",
" <TabItem value=\"LocalExperiment\" label=\"Local Experiment\">\n",
"```python\n",
Expand Down Expand Up @@ -79,8 +83,7 @@
"# transpile_remote.py\n",
"\n",
"from qiskit.transpiler import generate_preset_pass_manager\n",
"from qiskit_serverless import get_arguments, save_result, distribute_task, get\n",
"from qiskit_ibm_runtime import QiskitRuntimeService\n",
"from qiskit_serverless import get_arguments, save_result, distribute_task, get, get_runtime_service\n",
"\n",
"# Get program arguments\n",
"arguments = get_arguments()\n",
Expand All @@ -102,7 +105,7 @@
"\n",
"try:\n",
" # Get backend\n",
" service = QiskitRuntimeService()\n",
" service = get_runtime_service()\n",
" backend = service.get_backend(backend_name)\n",
"\n",
" # run distributed tasks as async function\n",
Expand Down
18 changes: 9 additions & 9 deletions docs/tutorials/implicit-solvent-calculations.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,13 @@
"from functools import partial\n",
"import os\n",
"\n",
"from qiskit_ibm_runtime import QiskitRuntimeService\n",
"from qiskit_serverless import distribute_task, get_arguments, get, save_result\n",
"from qiskit_serverless import (\n",
" distribute_task,\n",
" get_arguments,\n",
" get,\n",
" save_result,\n",
" get_runtime_service,\n",
")\n",
"from qiskit_addon_sqd.fermion import (\n",
" SCIResult,\n",
" diagonalize_fermionic_hamiltonian,\n",
Expand Down Expand Up @@ -287,11 +292,7 @@
"# Instantiate Runtime Service to retrieve the\n",
"# bitstrings from the QPU job. We provided these\n",
"# credentials upon Serverless setup.\n",
"service = QiskitRuntimeService(\n",
" channel=os.environ.get(\"QISKIT_IBM_CHANNEL\"),\n",
" token=os.environ.get(\"QISKIT_IBM_TOKEN\"),\n",
" instance=os.environ.get(\"QISKIT_IBM_INSTANCE\"),\n",
")\n",
"service = get_runtime_service()\n",
"\n",
"# retrieving the QPU job data from the Serverless side\n",
"job = service.job(job_id)\n",
Expand Down Expand Up @@ -1202,7 +1203,6 @@
"outputs": [],
"source": [
"# Heartwood algorithm subroutines\n",
"import os\n",
"import numpy as np\n",
"import pyscf\n",
"from pyscf import ao2mo, cc\n",
Expand Down Expand Up @@ -1741,6 +1741,7 @@
}
],
"metadata": {
"hours": 1.5,
"kernelspec": {
"display_name": "Python 3",
"language": "python",
Expand All @@ -1758,7 +1759,6 @@
"pygments_lexer": "ipython3",
"version": "3"
},
"hours": 1.5,
"qpuSeconds": 120
},
"nbformat": 4,
Expand Down
Loading