diff --git a/docs/guides/function-template-chemistry-workflow.ipynb b/docs/guides/function-template-chemistry-workflow.ipynb index 2e7d0466cae..59cf0cf4d39 100644 --- a/docs/guides/function-template-chemistry-workflow.ipynb +++ b/docs/guides/function-template-chemistry-workflow.ipynb @@ -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", @@ -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", diff --git a/docs/guides/function-template-hamiltonian-simulation.ipynb b/docs/guides/function-template-hamiltonian-simulation.ipynb index e1558f4ca18..e930d362e68 100644 --- a/docs/guides/function-template-hamiltonian-simulation.ipynb +++ b/docs/guides/function-template-hamiltonian-simulation.ipynb @@ -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", @@ -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", diff --git a/docs/guides/serverless-first-program.ipynb b/docs/guides/serverless-first-program.ipynb index 838ef47d710..e94e2064808 100644 --- a/docs/guides/serverless-first-program.ipynb +++ b/docs/guides/serverless-first-program.ipynb @@ -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", @@ -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", + "\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", + "\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." ] @@ -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)" ] }, diff --git a/docs/guides/serverless-manage-resources.ipynb b/docs/guides/serverless-manage-resources.ipynb index 56fdf547b50..a7a61d7f451 100644 --- a/docs/guides/serverless-manage-resources.ipynb +++ b/docs/guides/serverless-manage-resources.ipynb @@ -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", "\n", "" @@ -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." ] }, { @@ -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", diff --git a/docs/guides/serverless-port-code.ipynb b/docs/guides/serverless-port-code.ipynb index 38ee69890b5..bc27907c8c5 100644 --- a/docs/guides/serverless-port-code.ipynb +++ b/docs/guides/serverless-port-code.ipynb @@ -40,6 +40,10 @@ "\n", "## Update the experiment\n", "\n", + "\n", + "In the Serverless version, create the runtime service with `get_runtime_service()` (from `qiskit_serverless`) instead of `QiskitRuntimeService()`, so that the IBM Quantum® 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", + "\n", + "\n", "\n", " \n", "```python\n", @@ -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", @@ -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", diff --git a/docs/tutorials/implicit-solvent-calculations.ipynb b/docs/tutorials/implicit-solvent-calculations.ipynb index 7dfbd2db3d9..9b4cc25e1f2 100644 --- a/docs/tutorials/implicit-solvent-calculations.ipynb +++ b/docs/tutorials/implicit-solvent-calculations.ipynb @@ -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", @@ -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", @@ -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", @@ -1741,6 +1741,7 @@ } ], "metadata": { + "hours": 1.5, "kernelspec": { "display_name": "Python 3", "language": "python", @@ -1758,7 +1759,6 @@ "pygments_lexer": "ipython3", "version": "3" }, - "hours": 1.5, "qpuSeconds": 120 }, "nbformat": 4,